Skip to content

Commit 7120bf3

Browse files
committed
fix(Deps): use pydantic model rich.print support; display eip712 hashes
1 parent 6d1c75e commit 7120bf3

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

ape_ledger/accounts.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
from ape.api import AccountAPI, AccountContainerAPI, TransactionAPI
88
from ape.types import AddressType, MessageSignature, TransactionSignature
99
from ape_ethereum.transactions import DynamicFeeTransaction, StaticFeeTransaction
10-
from dataclassy import asdict
11-
from eip712 import EIP712Message, EIP712Type
10+
from eip712 import EIP712Message
1211
from eth_account.messages import SignableMessage, encode_defunct
1312
from eth_pydantic_types import HexBytes
1413
from eth_utils import is_0x_prefixed, to_bytes
@@ -71,27 +70,16 @@ def delete_account(self, alias: str):
7170

7271

7372
def _echo_object_to_sign(obj: Any):
74-
suffix = "Please follow the prompts on your device."
75-
if isinstance(obj, EIP712Message):
73+
# NOTE: pydantic models actually have very nice `rich.print` support
74+
rich.print(obj)
7675

77-
def make_str(val) -> str:
78-
if isinstance(val, dict):
79-
return ", ".join([f"{k}={make_str(v)}" for k, v in val.items()])
80-
elif isinstance(val, EIP712Type):
81-
subfields_str = make_str(asdict(val))
82-
return f"{repr(val)}({subfields_str})"
83-
elif isinstance(val, (tuple, list, set)):
84-
inner = ", ".join([make_str(x) for x in val])
85-
return f"[{inner}]"
86-
else:
87-
return f"{val}"
88-
89-
fields_str = make_str(obj._body_["message"])
90-
message_str = f"{repr(obj)}({fields_str})"
91-
else:
92-
message_str = f"{obj}"
76+
if isinstance(obj, EIP712Message):
77+
# NOTE: Ledger Nano devices only show domain hash and message hash for EIP712
78+
_, domain_hash, message_hash = obj.signable_message
79+
rich.print(f"Domain Hash: 0x{domain_hash.hex().upper()}")
80+
rich.print(f"Message Hash: 0x{message_hash.hex().upper()}")
9381

94-
rich.print(f"{message_str}\n{suffix}")
82+
rich.print("Please follow the prompts on your device.")
9583

9684

9785
class LedgerAccount(AccountAPI):

0 commit comments

Comments
 (0)