From 1a18e70d92357a42d3591e87fab257b3ed1ae57a Mon Sep 17 00:00:00 2001 From: kodxana Date: Wed, 19 Feb 2020 14:43:00 +0100 Subject: [PATCH] ecc.ECPubkey: also accept bytearray in __init__ --- electrum/ecc.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/electrum/ecc.py b/electrum/ecc.py index 28e66db97..43f1d5e61 100644 --- a/electrum/ecc.py +++ b/electrum/ecc.py @@ -116,6 +116,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]: pubkey_ptr = create_string_buffer(64) + assert isinstance(pubkey, bytes), f'pubkey must be bytes, not {type(pubkey)}' ret = _libsecp256k1.secp256k1_ec_pubkey_parse( _libsecp256k1.ctx, pubkey_ptr, pubkey, len(pubkey)) if not ret: @@ -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