Exemplo n.º 1
0
 def get_xpub(self, bip32_path, xtype, creating=False):
     address_n = parse_path(bip32_path)
     with self.run_flow(creating_wallet=creating):
         node = trezorlib.btc.get_public_node(self.client, address_n).node
     return BIP32Node(xtype=xtype,
                      eckey=ecc.ECPubkey(node.public_key),
                      chaincode=node.chain_code,
                      depth=node.depth,
                      fingerprint=self.i4b(node.fingerprint),
                      child_number=self.i4b(node.child_num)).to_xpub()
Exemplo n.º 2
0
 def get_xpub(self, bip32_path, xtype):
     address_n = self.expand_path(bip32_path)
     creating = False
     node = self.get_public_node(address_n, creating).node
     return BIP32Node(xtype=xtype,
                      eckey=ecc.ECPubkey(node.public_key),
                      chaincode=node.chain_code,
                      depth=node.depth,
                      fingerprint=self.i4b(node.fingerprint),
                      child_number=self.i4b(node.child_num)).to_xpub()
Exemplo n.º 3
0
def make_xpub(xpub, s) -> str:
    rootnode = BIP32Node.from_xkey(xpub)
    child_pubkey, child_chaincode = bip32._CKD_pub(
        parent_pubkey=rootnode.eckey.get_public_key_bytes(compressed=True),
        parent_chaincode=rootnode.chaincode,
        child_index=s)
    child_node = BIP32Node(xtype=rootnode.xtype,
                           eckey=ecc.ECPubkey(child_pubkey),
                           chaincode=child_chaincode)
    return child_node.to_xpub()
Exemplo n.º 4
0
 def get_xpub(self, bip32_path, xtype):
     self.checkDevice()
     # bip32_path is of the form 44'/0'/1'
     # S-L-O-W - we don't handle the fingerprint directly, so compute
     # it manually from the previous node
     # This only happens once so it's bearable
     #self.get_client() # prompt for the PIN before displaying the dialog if necessary
     #self.handler.show_message("Computing master public key")
     if xtype in ['p2wpkh', 'p2wsh'] and not self.supports_native_segwit():
         raise UserFacingException(MSG_NEEDS_FW_UPDATE_SEGWIT)
     if xtype in ['p2wpkh-p2sh', 'p2wsh-p2sh'
                  ] and not self.supports_segwit():
         raise UserFacingException(MSG_NEEDS_FW_UPDATE_SEGWIT)
     splitPath = bip32_path.split('/')
     if splitPath[0] == 'm':
         splitPath = splitPath[1:]
         bip32_path = bip32_path[2:]
     fingerprint = 0
     if len(splitPath) > 1:
         prevPath = "/".join(splitPath[0:len(splitPath) - 1])
         nodeData = self.dongleObject.getWalletPublicKey(prevPath)
         publicKey = compress_public_key(nodeData['publicKey'])
         h = hashlib.new('ripemd160')
         h.update(hashlib.sha256(publicKey).digest())
         fingerprint = unpack(">I", h.digest()[0:4])[0]
     nodeData = self.dongleObject.getWalletPublicKey(bip32_path)
     publicKey = compress_public_key(nodeData['publicKey'])
     depth = len(splitPath)
     lastChild = splitPath[len(splitPath) - 1].split('\'')
     childnum = int(lastChild[0]) if len(
         lastChild) == 1 else 0x80000000 | int(lastChild[0])
     return BIP32Node(xtype=xtype,
                      eckey=ecc.ECPubkey(publicKey),
                      chaincode=nodeData['chainCode'],
                      depth=depth,
                      fingerprint=self.i4b(fingerprint),
                      child_number=self.i4b(childnum)).to_xpub()