commit 9c5e49f432a4310aa4aec2f7985b52f032210b7e
parent 08453001507c783139bea943f0607a3a2f13cd35
Author: SomberNight <somber.night@protonmail.com>
Date: Wed, 19 Feb 2020 00:40:33 +0100
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
Diffstat:
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/electrum/ecc.py b/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]:
+ assert isinstance(pubkey, bytes), f'pubkey must be bytes, not {type(pubkey)}'
pubkey_ptr = create_string_buffer(64)
ret = _libsecp256k1.secp256k1_ec_pubkey_parse(
_libsecp256k1.ctx, pubkey_ptr, pubkey, len(pubkey))
@@ -141,7 +142,9 @@ class ECPubkey(object):
def __init__(self, b: Optional[bytes]):
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)
else:
self._x, self._y = None, None
diff --git a/electrum/plugins/ledger/ledger.py b/electrum/plugins/ledger/ledger.py
@@ -121,7 +121,7 @@ class Ledger_Client(HardwareClientBase):
publicKey = compress_public_key(nodeData['publicKey'])
depth = len(bip32_intpath)
return BIP32Node(xtype=xtype,
- eckey=ecc.ECPubkey(publicKey),
+ eckey=ecc.ECPubkey(bytes(publicKey)),
chaincode=nodeData['chainCode'],
depth=depth,
fingerprint=fingerprint_bytes,