Browse Source

ecc.ECPubkey: also accept bytearray in __init__

regression since #5947

Traceback (most recent call last):
  File "...\electrum\electrum\base_wizard.py", line 339, in on_device
    self.plugin.setup_device(device_info, self, purpose)
  File "...\electrum\electrum\plugins\ledger\ledger.py", line 598, in setup_device
    client.get_xpub("m/44'/0'", 'standard') # TODO replace by direct derivation once Nano S > 1.1
  File "...\electrum\electrum\plugins\ledger\ledger.py", line 55, in catch_exception
    return func(self, *args, **kwargs)
  File "...\electrum\electrum\plugins\ledger\ledger.py", line 124, in get_xpub
    eckey=ecc.ECPubkey(publicKey),
  File "...\electrum\electrum\ecc.py", line 145, in __init__
    self._x, self._y = _x_and_y_from_pubkey_bytes(b)
  File "...\electrum\electrum\ecc.py", line 119, in _x_and_y_from_pubkey_bytes
    ret = _libsecp256k1.secp256k1_ec_pubkey_parse(
ctypes.ArgumentError: argument 3: <class 'TypeError'>: wrong type
master
SomberNight 6 years ago
parent
commit
9c5e49f432
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 5
      electrum/ecc.py
  2. 2
      electrum/plugins/ledger/ledger.py

5
electrum/ecc.py

@ -115,6 +115,7 @@ def sig_string_from_r_and_s(r: int, s: int) -> bytes:
def _x_and_y_from_pubkey_bytes(pubkey: bytes) -> Tuple[int, int]: def _x_and_y_from_pubkey_bytes(pubkey: bytes) -> Tuple[int, int]:
assert isinstance(pubkey, bytes), f'pubkey must be bytes, not {type(pubkey)}'
pubkey_ptr = create_string_buffer(64) pubkey_ptr = create_string_buffer(64)
ret = _libsecp256k1.secp256k1_ec_pubkey_parse( ret = _libsecp256k1.secp256k1_ec_pubkey_parse(
_libsecp256k1.ctx, pubkey_ptr, pubkey, len(pubkey)) _libsecp256k1.ctx, pubkey_ptr, pubkey, len(pubkey))
@ -141,7 +142,9 @@ class ECPubkey(object):
def __init__(self, b: Optional[bytes]): def __init__(self, b: Optional[bytes]):
if b is not None: if b is not None:
assert_bytes(b) assert isinstance(b, (bytes, bytearray)), f'pubkey must be bytes-like, not {type(b)}'
if isinstance(b, bytearray):
b = bytes(b)
self._x, self._y = _x_and_y_from_pubkey_bytes(b) self._x, self._y = _x_and_y_from_pubkey_bytes(b)
else: else:
self._x, self._y = None, None self._x, self._y = None, None

2
electrum/plugins/ledger/ledger.py

@ -121,7 +121,7 @@ class Ledger_Client(HardwareClientBase):
publicKey = compress_public_key(nodeData['publicKey']) publicKey = compress_public_key(nodeData['publicKey'])
depth = len(bip32_intpath) depth = len(bip32_intpath)
return BIP32Node(xtype=xtype, return BIP32Node(xtype=xtype,
eckey=ecc.ECPubkey(publicKey), eckey=ecc.ECPubkey(bytes(publicKey)),
chaincode=nodeData['chainCode'], chaincode=nodeData['chainCode'],
depth=depth, depth=depth,
fingerprint=fingerprint_bytes, fingerprint=fingerprint_bytes,

Loading…
Cancel
Save