Skip to content

Commit

Permalink
fix: properly handle bytes and ints
Browse files Browse the repository at this point in the history
  • Loading branch information
z80dev committed Dec 13, 2023
1 parent f1e7a60 commit cbf4770
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ape_frame/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

0 comments on commit cbf4770

Please sign in to comment.