예제 #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 _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)
예제 #3
0
def make_billing_address(wallet, num, addr_type):
    long_id, short_id = wallet.get_user_id()
    xpub = make_xpub(get_billing_xpub(), long_id)
    version, _, _, _, c, cK = deserialize_xpub(xpub)
    cK, c = CKD_pub(cK, c, num)
    if addr_type == 'legacy':
        return bitcoin.public_key_to_p2pkh(cK)
    elif addr_type == 'segwit':
        return bitcoin.public_key_to_p2wpkh(cK)
    else:
        raise ValueError(f'unexpected billing type: {addr_type}')
예제 #4
0
def make_billing_address(wallet, num, addr_type):
    long_id, short_id = wallet.get_user_id()
    xpub = make_xpub(get_billing_xpub(), long_id)
    version, _, _, _, c, cK = deserialize_xpub(xpub)
    cK, c = CKD_pub(cK, c, num)
    if addr_type == 'legacy':
        return bitcoin.public_key_to_p2pkh(cK)
    elif addr_type == 'segwit':
        return bitcoin.public_key_to_p2wpkh(cK)
    else:
        raise ValueError(f'unexpected billing type: {addr_type}')
예제 #5
0
def get_signing_xpub(xtype):
    if not constants.net.TESTNET:
        xpub = "xpub661MyMwAqRbcGnMkaTx2594P9EDuiEqMq25PM2aeG6UmwzaohgA6uDmNsvSUV8ubqwA3Wpste1hg69XHgjUuCD5HLcEp2QPzyV1HMrPppsL"
    else:
        xpub = "tpubD6NzVbkrYhZ4XdmyJQcCPjQfg6RXVUzGFhPjZ7uvRC8JLcS7Hw1i7UTpyhp9grHpak4TyK2hzBJrujDVLXQ6qB5tNpVx9rC6ixijUXadnmY"
    if xtype not in ('standard', 'p2wsh'):
        raise NotImplementedError('xtype: {}'.format(xtype))
    if xtype == 'standard':
        return xpub
    _, depth, fingerprint, child_number, c, cK = bip32.deserialize_xpub(xpub)
    xpub = bip32.serialize_xpub(xtype, c, cK, depth, fingerprint, child_number)
    return xpub
예제 #6
0
def get_signing_xpub(xtype):
    if not constants.net.TESTNET:
        xpub = "xpub661MyMwAqRbcGnMkaTx2594P9EDuiEqMq25PM2aeG6UmwzaohgA6uDmNsvSUV8ubqwA3Wpste1hg69XHgjUuCD5HLcEp2QPzyV1HMrPppsL"
    else:
        xpub = "tpubD6NzVbkrYhZ4XdmyJQcCPjQfg6RXVUzGFhPjZ7uvRC8JLcS7Hw1i7UTpyhp9grHpak4TyK2hzBJrujDVLXQ6qB5tNpVx9rC6ixijUXadnmY"
    if xtype not in ('standard', 'p2wsh'):
        raise NotImplementedError('xtype: {}'.format(xtype))
    if xtype == 'standard':
        return xpub
    _, depth, fingerprint, child_number, c, cK = bip32.deserialize_xpub(xpub)
    xpub = bip32.serialize_xpub(xtype, c, cK, depth, fingerprint, child_number)
    return xpub
예제 #7
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')
예제 #8
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.ecc import ECPubkey

            xtype, depth, parent_fingerprint, child_number, chain_code, K_or_k \
                = 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
예제 #9
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.ecc import ECPubkey

            xtype, depth, parent_fingerprint, child_number, chain_code, K_or_k \
                = 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
예제 #10
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')
예제 #11
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
예제 #12
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 UserFacingException(_('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
예제 #13
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 = bip32.deserialize_xpub(xpub)[-1]
         _hash = bh2u(crypto.sha256d(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])
예제 #14
0
파일: qt.py 프로젝트: ahmedbodi/electrum
 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 = bip32.deserialize_xpub(xpub)[-1]
         _hash = bh2u(crypto.sha256d(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])
예제 #15
0
def make_billing_address(wallet, num):
    long_id, short_id = wallet.get_user_id()
    xpub = make_xpub(get_billing_xpub(), long_id)
    version, _, _, _, c, cK = deserialize_xpub(xpub)
    cK, c = CKD_pub(cK, c, num)
    return public_key_to_p2pkh(cK)
예제 #16
0
def make_xpub(xpub, s):
    version, _, _, _, c, cK = deserialize_xpub(xpub)
    cK2, c2 = bip32._CKD_pub(cK, c, s)
    return serialize_xpub(version, c2, cK2)
예제 #17
0
def make_xpub(xpub, s):
    version, _, _, _, c, cK = deserialize_xpub(xpub)
    cK2, c2 = bip32._CKD_pub(cK, c, s)
    return serialize_xpub(version, c2, cK2)
예제 #18
0
if args.gen_master:
    key_type = args.gen_master if args.gen_master != "p2pkh" else "standard"
    entropy = ecdsa.util.randrange( pow( 2, entropy_size * 8 ) )
    entropy_in_bytes = entropy.to_bytes( entropy_size , sys.byteorder )
    xprv,xpub = bip32.bip32_root( entropy_in_bytes, key_type )
    master_key = xprv
elif args.master_key == "-":
    master_key = sys.stdin.readline().strip()

if args.convert:
    if args.gen_master:
        sys.exit( "Convert option cannot be used with generate master option" )
    else:
        convert_type = args.convert if args.convert !="p2pkh" else "standard"
        if bip32.is_xpub(master_key):
            xtype, depth, fingerprint, child_number, c, K_or_k = bip32.deserialize_xpub( master_key )
            master_key = bip32.serialize_xpub( convert_type, c,  K_or_k, depth, fingerprint, child_number )
        elif bip32.is_xprv(master_key):
            xtype, depth, fingerprint, child_number, c, K_or_k = bip32.deserialize_xprv( master_key )
            master_key = bip32.serialize_xprv( convert_type, c,  K_or_k, depth, fingerprint, child_number )
        else:
            sys.exit( "Master key is not a valid extended key" )

derivation_path = args.derivation_path if args.derivation_path != "m" else "m/"
if bip32.is_bip32_derivation( derivation_path ):
	if bip32.is_xpub(master_key):
		if args.output_xprv:
				sys.exit( "Cannot derive extended private key from extended public key\n" )
		if derivation_path == "m/":
			print( master_key )
		else:
예제 #19
0
def make_billing_address(wallet, num):
    long_id, short_id = wallet.get_user_id()
    xpub = make_xpub(get_billing_xpub(), long_id)
    version, _, _, _, c, cK = deserialize_xpub(xpub)
    cK, c = CKD_pub(cK, c, num)
    return public_key_to_p2pkh(cK)