示例#1
0
 def get_xpubkeys(self, for_change, n):
     # unsorted
     s = ''.join(map(lambda x: bitcoin.int_to_hex(x, 2), (for_change, n)))
     xpubs = self.get_master_pubkeys()
     return map(
         lambda xpub: 'ff' + bitcoin.DecodeBase58Check(xpub).encode('hex') +
         s, xpubs)
示例#2
0
 def from_xpub(cls, xpub):
     decoded = bitcoin.DecodeBase58Check(xpub)
     if decoded == None: raise Exception('BIP32.from_xpub: invalid xpub')
     if decoded[:4] != '0488b21e'.decode('hex'):
         raise Exception('BIP32.from_xpub: not proper xpub')
     depth = int(decoded[4:5].encode('hex'), 16)
     fingerprint = decoded[5:9]
     child_num = int(decoded[9:13].encode('hex'), 16)
     if child_num & 2**31:
         is_hard = True
         child_num = child_num & ((2**31) - 1)
     else:
         is_hard = False
     chaincode = decoded[13:45]
     privkey = None
     pubkey = decoded[45:]
     is_private = False
     return cls(privkey, pubkey, chaincode, depth, fingerprint, child_num,
                is_private, is_hard)
示例#3
0
def DeserializeExtendedKey(s):
    """Decode 78-byte binary blob corresponding to this node."""

    data = bitcoin.DecodeBase58Check(s)
    (is_private, is_test) = VERSION__PRIVATE_TEST_LOOKUP[data[0:4]]
    parent_fingerprint = data[5:9]
    child_number, = struct.unpack(">L", data[9:13])
    d = dict(is_private=is_private,
             is_test=is_test,
             chain_code=data[13:45],
             depth=ord(data[4]),
             parent_fingerprint=parent_fingerprint,
             child_number=child_number)
    if is_private:
        if ord(data[45]) != 0:
            raise Exception("incorrect private key encoding")
        d['secret'] = data[46:]
    else:
        Q = bitcoin.ser_to_point(data[45:])
        pubkey = ecdsa.VerifyingKey.from_public_point(Q, curve=SECP256k1)
        d['K'] = pubkey.to_string()
        d['cK'] = bitcoin.GetPubKey(pubkey.pubkey, True)
    return d
示例#4
0
 def get_xpubkey(self, c, i):
     s = ''.join(map(lambda x: bitcoin.int_to_hex(x, 2), (c, i)))
     return 'ff' + bitcoin.DecodeBase58Check(self.xpub).encode('hex') + s