Пример #1
0
 def _make_node_path(self, xpub, address_n):
     _, depth, fingerprint, child_num, chain_code, key = deserialize_xpub(xpub)
     node = self.types.HDNodeType(
         depth=depth,
         fingerprint=int.from_bytes(fingerprint, 'big'),
         child_num=int.from_bytes(child_num, 'big'),
         chain_code=chain_code,
         public_key=key,
     )
     return self.types.HDNodePathType(node=node, address_n=address_n)
Пример #2
0
 def get_xpub(self, bip32_path, xtype):
     assert xtype in self.plugin.SUPPORTED_XTYPES
     reply = self._get_xpub(bip32_path)
     if reply:
         xpub = reply['xpub']
         # Change type of xpub to the requested type. The firmware
         # only ever returns the mainnet standard type, but it is agnostic
         # to the type when signing.
         if xtype != 'standard' or constants.net.TESTNET:
             _, depth, fingerprint, child_number, c, cK = deserialize_xpub(xpub, net=constants.BitcoinMainnet)
             xpub = serialize_xpub(xtype, c, cK, depth, fingerprint, child_number)
         return xpub
     else:
         raise Exception('no reply')
Пример #3
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.
            from electrum_ltc.ecc import ECPubkey

            xtype, depth, parent_fingerprint, child_number, chain_code, K_or_k \
                = bitcoin.deserialize_xpub(expect_xpub)

            pubkey = ECPubkey(K_or_k)
            try:
                pubkey.verify_message_hash(sig[1:65], self.session_key)
                return True
            except:
                return False
Пример #4
0
 def get_xpub(self, bip32_path, xtype):
     assert xtype in ('standard', 'p2wpkh-p2sh')
     reply = self._get_xpub(bip32_path)
     if reply:
         xpub = reply['xpub']
         # Change type of xpub to the requested type. The firmware
         # only ever returns the standard type, but it is agnostic
         # to the type when signing.
         if xtype != 'standard':
             _, depth, fingerprint, child_number, c, cK = deserialize_xpub(
                 xpub)
             xpub = serialize_xpub(xtype, c, cK, depth, fingerprint,
                                   child_number)
         return xpub
     else:
         raise BaseException('no reply')
Пример #5
0
 def get_xpub(self, bip32_path, xtype):
     assert xtype in ColdcardPlugin.SUPPORTED_XTYPES
     print_error('[coldcard]', 'Derive xtype = %r' % xtype)
     xpub = self.dev.send_recv(CCProtocolPacker.get_xpub(bip32_path),
                               timeout=5000)
     # TODO handle timeout?
     # change type of xpub to the requested type
     try:
         __, depth, fingerprint, child_number, c, cK = deserialize_xpub(
             xpub)
     except InvalidMasterKeyVersionBytes:
         raise Exception(
             _('Invalid xpub magic. Make sure your {} device is set to the correct chain.'
               ).format(self.device)) from None
     if xtype != 'standard':
         xpub = serialize_xpub(xtype, c, cK, depth, fingerprint,
                               child_number)
     return xpub
Пример #6
0
 def update(self, window):
     wallet = window.wallet
     if type(wallet) != Multisig_Wallet:
         return
     if self.listener is None:
         self.print_error("starting listener")
         self.listener = Listener(self)
         self.listener.start()
     elif self.listener:
         self.print_error("shutting down listener")
         self.listener.stop()
         self.listener = None
     self.keys = []
     self.cosigner_list = []
     for key, keystore in wallet.keystores.items():
         xpub = keystore.get_master_public_key()
         K = bitcoin.deserialize_xpub(xpub)[-1]
         _hash = bh2u(bitcoin.Hash(K))
         if not keystore.is_watching_only():
             self.keys.append((key, _hash, window))
         else:
             self.cosigner_list.append((window, xpub, K, _hash))
     if self.listener:
         self.listener.set_keyhashes([t[1] for t in self.keys])