ecc.ECPubkey: also accept bytearray in __init__

This commit is contained in:
kodxana 2020-02-19 14:43:00 +01:00 committed by GitHub
parent 9350f9f26a
commit 1a18e70d92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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]: def _x_and_y_from_pubkey_bytes(pubkey: bytes) -> Tuple[int, int]:
pubkey_ptr = create_string_buffer(64) pubkey_ptr = create_string_buffer(64)
assert isinstance(pubkey, bytes), f'pubkey must be bytes, not {type(pubkey)}'
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))
if not ret: if not ret:
@ -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