Skip to content

Commit 328a1c8

Browse files
committed
Add recovering pub key from signature
1 parent 5010494 commit 328a1c8

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

celo_sdk/celo_account/account.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,25 @@ def _recover_hash(self, message_hash, vrs=None, signature=None):
442442
pubkey = signature_obj.recover_public_key_from_msg_hash(hash_bytes)
443443
return pubkey.to_checksum_address()
444444

445+
@combomethod
446+
def recover_hash_to_pub(self, signable_message, vrs=None, signature=None):
447+
message_hash = _hash_eip191_message(signable_message)
448+
hash_bytes = HexBytes(message_hash)
449+
if len(hash_bytes) != 32:
450+
raise ValueError("The message hash must be exactly 32-bytes")
451+
if vrs is not None:
452+
v, r, s = map(hexstr_if_str(to_int), vrs)
453+
v_standard = to_standard_v(v)
454+
signature_obj = self._keys.Signature(vrs=(v_standard, r, s))
455+
elif signature is not None:
456+
signature_bytes = HexBytes(signature)
457+
signature_bytes_standard = to_standard_signature_bytes(signature_bytes)
458+
signature_obj = self._keys.Signature(signature_bytes=signature_bytes_standard)
459+
else:
460+
raise TypeError("You must supply the vrs tuple or the signature bytes")
461+
pubkey = signature_obj.recover_public_key_from_msg_hash(hash_bytes)
462+
return pubkey
463+
445464
@combomethod
446465
def recoverTransaction(self, serialized_transaction):
447466
"""

0 commit comments

Comments
 (0)