From cbf4770326dafebdc7cbc0ba9f50212de614d3dd Mon Sep 17 00:00:00 2001 From: z80 Date: Wed, 13 Dec 2023 15:31:20 -0500 Subject: [PATCH] fix: properly handle bytes and ints --- ape_frame/accounts.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ape_frame/accounts.py b/ape_frame/accounts.py index 18b9533..0f9cc1a 100644 --- a/ape_frame/accounts.py +++ b/ape_frame/accounts.py @@ -6,6 +6,7 @@ from eth_account._utils.legacy_transactions import serializable_unsigned_transaction_from_dict from eth_account.messages import encode_defunct from eth_utils.curried import keccak +from hexbytes import HexBytes from web3 import HTTPProvider, Web3 @@ -51,6 +52,20 @@ def sign_message(self, msg: Any) -> Optional[MessageSignature]: if not e.args[0]["message"] == "User declined transaction": raise return None + if isinstance(msg, int): + try: + raw_signature = self.web3.eth.sign(self.address, hexstr=HexBytes(msg).hex()) + except ValueError as e: + if not e.args[0]["message"] == "User declined transaction": + raise + return None + if isinstance(msg, bytes): + try: + raw_signature = self.web3.eth.sign(self.address, hexstr=msg.hex()) + except ValueError as e: + if not e.args[0]["message"] == "User declined transaction": + raise + return None if isinstance(msg, SignableMessage): try: @@ -105,6 +120,8 @@ def check_signature( ) -> bool: if isinstance(data, str): data = encode_defunct(text=data) + elif isinstance(data, bytes): + data = encode_defunct(primitive=data) if isinstance(data, EIP712Message): data = data.signable_message return super().check_signature(data, signature)