|
7 | 7 | from ape.api import AccountAPI, AccountContainerAPI, TransactionAPI |
8 | 8 | from ape.types import AddressType, MessageSignature, TransactionSignature |
9 | 9 | from ape_ethereum.transactions import DynamicFeeTransaction, StaticFeeTransaction |
10 | | -from dataclassy import asdict |
11 | | -from eip712 import EIP712Message, EIP712Type |
| 10 | +from eip712 import EIP712Message |
12 | 11 | from eth_account.messages import SignableMessage, encode_defunct |
13 | 12 | from eth_pydantic_types import HexBytes |
14 | 13 | from eth_utils import is_0x_prefixed, to_bytes |
@@ -71,27 +70,16 @@ def delete_account(self, alias: str): |
71 | 70 |
|
72 | 71 |
|
73 | 72 | 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) |
76 | 75 |
|
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()}") |
93 | 81 |
|
94 | | - rich.print(f"{message_str}\n{suffix}") |
| 82 | + rich.print("Please follow the prompts on your device.") |
95 | 83 |
|
96 | 84 |
|
97 | 85 | class LedgerAccount(AccountAPI): |
|
0 commit comments