def serialize_header(self, res): s = int_to_hex(res.get('version'), 4) \ + rev_hex(self.get_block_hash(res)) \ + rev_hex(res.get('merkle_root')) \ + rev_hex(res.get('claim_trie_root')) \ + int_to_hex(int(res.get('timestamp')), 4) \ + int_to_hex(int(res.get('bits')), 4) \ + int_to_hex(int(res.get('nonce')), 4) return s
def get_claim_id(self, nout): if nout < 0: raise IndexError if not self._outputs[nout][0] & TYPE_CLAIM: raise ValueError tx_hash = rev_hex(self.hash()).decode('hex') return encode_claim_id_hex(claim_id_hash(tx_hash, nout))
def parse_xpubkey(cls, pubkey): assert is_extended_pubkey(pubkey) pk = pubkey.decode('hex') pk = pk[1:] xkey = EncodeBase58Check(pk[0:78]) dd = pk[78:] s = [] while dd: n = int(rev_hex(dd[0:2].encode('hex')), 16) dd = dd[2:] s.append(n) assert len(s) == 2 return xkey, s
def parse_xpubkey(cls, pubkey): assert is_extended_pubkey(pubkey) pk = pubkey.decode('hex') pk = pk[1:] xkey = b58encode_with_checksum(pk[0:78]) dd = pk[78:] s = [] while dd: n = int(rev_hex(dd[0:2].encode('hex')), 16) dd = dd[2:] s.append(n) assert len(s) == 2 return xkey, s
def test_claimid_hash(self): txid = "4d08012feefec192bdb45495dcedc171a56d369539ce2d589e3e1ec81a882bb4" nout = 1 claim_id = "a438fc7701e10e0e5c41d7a342be1190d9bed57b" out = claim_id_hash(rev_hex(txid).decode('hex'), nout) self.assertEqual(claim_id, rev_hex(out.encode('hex')))
def CKD_pub(cK, c, n): if n & BIP32_PRIME: raise Exception("CKD pub error") return _CKD_pub(cK, c, rev_hex(int_to_hex(n, 4)).decode('hex'))
def CKD_priv(k, c, n): is_prime = n & BIP32_PRIME return _CKD_priv(k, c, rev_hex(int_to_hex(n, 4)).decode('hex'), is_prime)
def encode_claim_id_hex(claim_id): return rev_hex(claim_id.encode('hex'))
def decode_claim_id_hex(claim_id_hex): return rev_hex(claim_id_hex).decode('hex')
def decode_claim_id_hex(claim_id_hex): claim_id = rev_hex(claim_id_hex).decode('hex') if len(claim_id) != CLAIM_ID_SIZE: raise InvalidClaimId() return claim_id