コード例 #1
0
ファイル: test_bitcoin.py プロジェクト: lavajumper/vialectrum
    def _do_test_bip32(self, seed: str, sequence):
        node = BIP32Node.from_rootseed(bfh(seed), xtype='standard')
        xprv, xpub = node.to_xprv(), node.to_xpub()
        self.assertEqual("m/", sequence[0:2])
        sequence = sequence[2:]
        for n in sequence.split('/'):
            if n[-1] != "'":
                xpub2 = BIP32Node.from_xkey(xpub).subkey_at_public_derivation(n).to_xpub()
            node = BIP32Node.from_xkey(xprv).subkey_at_private_derivation(n)
            xprv, xpub = node.to_xprv(), node.to_xpub()
            if n[-1] != "'":
                self.assertEqual(xpub, xpub2)

        return xpub, xprv
コード例 #2
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()
         pubkey = BIP32Node.from_xkey(xpub).eckey.get_public_key_bytes(
             compressed=True)
         _hash = bh2u(crypto.sha256d(pubkey))
         if not keystore.is_watching_only():
             self.keys.append((key, _hash, window))
         else:
             self.cosigner_list.append((window, xpub, pubkey, _hash))
     if self.listener:
         self.listener.set_keyhashes([t[1] for t in self.keys])
コード例 #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.
     pubkey = BIP32Node.from_xkey(expect_xpub).eckey
     try:
         pubkey.verify_message_hash(sig[1:65], self.session_key)
         return True
     except:
         return False
コード例 #4
0
 def _make_node_path(self, xpub, address_n):
     bip32node = BIP32Node.from_xkey(xpub)
     node = self.types.HDNodeType(
         depth=bip32node.depth,
         fingerprint=int.from_bytes(bip32node.fingerprint, 'big'),
         child_num=int.from_bytes(bip32node.child_number, 'big'),
         chain_code=bip32node.chaincode,
         public_key=bip32node.eckey.get_public_key_bytes(compressed=True),
     )
     return self.types.HDNodePathType(node=node, address_n=address_n)
コード例 #5
0
ファイル: trezor.py プロジェクト: vialectrum/vialectrum
 def _make_node_path(self, xpub, address_n):
     bip32node = BIP32Node.from_xkey(xpub)
     node = HDNodeType(
         depth=bip32node.depth,
         fingerprint=int.from_bytes(bip32node.fingerprint, 'big'),
         child_num=int.from_bytes(bip32node.child_number, 'big'),
         chain_code=bip32node.chaincode,
         public_key=bip32node.eckey.get_public_key_bytes(compressed=True),
     )
     return HDNodePathType(node=node, address_n=address_n)
コード例 #6
0
 def get_xpub(self, bip32_path, xtype):
     assert xtype in ColdcardPlugin.SUPPORTED_XTYPES
     _logger.info('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:
         node = BIP32Node.from_xkey(xpub)
     except InvalidMasterKeyVersionBytes:
         raise UserFacingException(_('Invalid xpub magic. Make sure your {} device is set to the correct chain.')
                                   .format(self.device)) from None
     if xtype != 'standard':
         xpub = node._replace(xtype=xtype).to_xpub()
     return xpub
コード例 #7
0
ファイル: digitalbitbox.py プロジェクト: vcgato29/vialectrum
 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:
             node = BIP32Node.from_xkey(xpub, net=constants.BitcoinMainnet)
             xpub = node._replace(xtype=xtype).to_xpub()
         return xpub
     else:
         raise Exception('no reply')
コード例 #8
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:
             node = BIP32Node.from_xkey(xpub, net=constants.BitcoinMainnet)
             xpub = node._replace(xtype=xtype).to_xpub()
         return xpub
     else:
         raise Exception('no reply')
コード例 #9
0
    def on_receive(self, keyhash, message):
        self.print_error("signal arrived for", keyhash)
        for key, _hash, window in self.keys:
            if _hash == keyhash:
                break
        else:
            self.print_error("keyhash not found")
            return

        wallet = window.wallet
        if isinstance(wallet.keystore, keystore.Hardware_KeyStore):
            window.show_warning(
                _('An encrypted transaction was retrieved from cosigning pool.'
                  ) + '\n' +
                _('However, hardware wallets do not support message decryption, '
                  'which makes them not compatible with the current design of cosigner pool.'
                  ))
            return
        elif wallet.has_keystore_encryption():
            password = window.password_dialog(
                _('An encrypted transaction was retrieved from cosigning pool.'
                  ) + '\n' + _('Please enter your password to decrypt it.'))
            if not password:
                return
        else:
            password = None
            if not window.question(
                    _("An encrypted transaction was retrieved from cosigning pool."
                      ) + '\n' + _("Do you want to open it now?")):
                return

        xprv = wallet.keystore.get_master_private_key(password)
        if not xprv:
            return
        try:
            privkey = BIP32Node.from_xkey(xprv).eckey
            message = bh2u(privkey.decrypt_message(message))
        except Exception as e:
            traceback.print_exc(file=sys.stdout)
            window.show_error(_('Error decrypting message') + ':\n' + str(e))
            return

        self.listener.clear(keyhash)
        tx = transaction.Transaction(message)
        show_transaction(tx, window, prompt_if_unsaved=True)