Exemple #1
0
 def get_pubkey_derivation(self, x_pubkey):
     if x_pubkey[0:2] in ['02', '03', '04']:
         if x_pubkey in self.keypairs.keys():
             return x_pubkey
     elif x_pubkey[0:2] == 'fd':
         # fixme: this assumes p2pkh
         _, addr = xpubkey_to_address(x_pubkey)
         for pubkey in self.keypairs.keys():
             if public_key_to_bc_address(pubkey.decode('hex')) == addr:
                 return pubkey
Exemple #2
0
def xpubkey_to_address(x_pubkey):
    if x_pubkey[0:2] in ['02', '03', '04']:
        pubkey = x_pubkey
    elif x_pubkey[0:2] == 'ff':
        xpub, s = BIP32_KeyStore.parse_xpubkey(x_pubkey)
        pubkey = BIP32_KeyStore.get_pubkey_from_xpub(xpub, s)
    elif x_pubkey[0:2] == 'fe':
        mpk, s = Old_KeyStore.parse_xpubkey(x_pubkey)
        pubkey = Old_KeyStore.get_pubkey_from_mpk(mpk, s[0], s[1])
    elif x_pubkey[0:2] == 'fd':
        addrtype = ord(x_pubkey[2:4].decode('hex'))
        hash160 = x_pubkey[4:].decode('hex')
        pubkey = None
        address = hash_160_to_bc_address(hash160, addrtype)
    else:
        raise BaseException("Cannnot parse pubkey")
    if pubkey:
        address = public_key_to_bc_address(pubkey.decode('hex'))
    return pubkey, address
Exemple #3
0
 def get_address(self, for_change, n):
     pubkey = self.get_pubkey(for_change, n)
     address = public_key_to_bc_address(pubkey.decode('hex'))
     return address