Example #1
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)
     bip32_path = bip32.normalize_bip32_derivation(bip32_path)
     bip32_intpath = bip32.convert_bip32_path_to_list_of_uint32(bip32_path)
     bip32_path = bip32_path[2:]  # cut off "m/"
     if len(bip32_intpath) >= 1:
         prevPath = bip32.convert_bip32_intpath_to_strpath(
             bip32_intpath[:-1])[2:]
         nodeData = self.dongleObject.getWalletPublicKey(prevPath)
         publicKey = compress_public_key(nodeData['publicKey'])
         fingerprint_bytes = hash_160(publicKey)[0:4]
         childnum_bytes = bip32_intpath[-1].to_bytes(length=4,
                                                     byteorder="big")
     else:
         fingerprint_bytes = bytes(4)
         childnum_bytes = bytes(4)
     nodeData = self.dongleObject.getWalletPublicKey(bip32_path)
     publicKey = compress_public_key(nodeData['publicKey'])
     depth = len(bip32_intpath)
     return BIP32Node(xtype=xtype,
                      eckey=ecc.ECPubkey(bytes(publicKey)),
                      chaincode=nodeData['chainCode'],
                      depth=depth,
                      fingerprint=fingerprint_bytes,
                      child_number=childnum_bytes).to_xpub()
Example #2
0
 def get_account_xpub(account_path):
     root_seed = bip39_to_seed(mnemonic, passphrase)
     root_node = BIP32Node.from_rootseed(root_seed, xtype="standard")
     account_node = root_node.subkey_at_private_derivation(account_path)
     account_xpub = account_node.to_xpub()
     return account_xpub
Example #3
0
 def request_root_fingerprint_from_device(self) -> str:
     # digitalbitbox (at least) does not reveal xpubs corresponding to unhardened paths
     # so ask for a direct child, and read out fingerprint from that:
     child_of_root_xpub = self.get_xpub("m/0'", xtype='standard')
     root_fingerprint = BIP32Node.from_xkey(child_of_root_xpub).fingerprint.hex().lower()
     return root_fingerprint
Example #4
0
 def mitm_verify(self, sig, expect_xpub):
     # verify a signature (65 bytes) over the session key, using the master bip32 node
     # - customized to use specific EC library of Electrum.
     pubkey = BIP32Node.from_xkey(expect_xpub).eckey
     return pubkey.verify_message_hash(sig[1:65], self.session_key)