def _public_from_signature(self, tx):
     s = self.w3.eth.account._keys.Signature(vrs=(to_standard_v(extract_chain_id(tx.v)[1]), self.w3.toInt(tx.r), self.w3.toInt(tx.s)))
     tt = {k: tx[k] for k in ALLOWED_TRANSACTION_KEYS - {'chainId', 'data'}}
     tt['data'] = tx.input
     tt['chainId'] = extract_chain_id(tx.v)[0]
     ut = serializable_unsigned_transaction_from_dict(tt)
     return s.recover_public_key_from_msg_hash(ut.hash()).to_hex()[2:]
Exemple #2
0
 def _recover_hash(self, message_hash, vrs=None, signature=None):
     hash_bytes = HexBytes(message_hash)
     if len(hash_bytes) != 32:
         raise ValueError("The message hash must be exactly 32-bytes")
     if vrs is not None:
         v, r, s = map(hexstr_if_str(to_int), vrs)
         v_standard = to_standard_v(v)
         signature_obj = self._keys.Signature(vrs=(v_standard, r, s))
     elif signature is not None:
         signature_bytes = HexBytes(signature)
         signature_bytes_standard = to_standard_signature_bytes(signature_bytes)
         signature_obj = self._keys.Signature(signature_bytes=signature_bytes_standard)
     else:
         raise TypeError("You must supply the vrs tuple or the signature bytes")
     pubkey = signature_obj.recover_public_key_from_msg_hash(hash_bytes)
     return pubkey.to_checksum_address()