|
4 | 4 |
|
5 | 5 | from eth_typing import ChecksumAddress, Hash32, HexStr |
6 | 6 | from eth_utils import keccak |
7 | | -from safe_eth.eth.eip712 import eip712_encode_hash |
| 7 | +from safe_eth.eth.eip712 import eip712_encode, eip712_encode_hash |
| 8 | +from safe_eth.eth.utils import fast_keccak |
8 | 9 |
|
9 | 10 | from safe_transaction_service.history.models import TransferDict |
10 | 11 | from safe_transaction_service.tokens.models import Token |
@@ -81,19 +82,19 @@ def calculate_hash( |
81 | 82 |
|
82 | 83 | class DelegateSignatureHelperV2(TemporarySignatureHelper): |
83 | 84 | @classmethod |
84 | | - def calculate_hash( |
| 85 | + def calculate_hash_and_preimage( |
85 | 86 | cls, |
86 | 87 | delegate_address: ChecksumAddress, |
87 | 88 | chain_id: Optional[int], |
88 | 89 | previous_totp: bool = False, |
89 | | - ) -> Hash32: |
| 90 | + ) -> tuple[Hash32, bytes]: |
90 | 91 | """ |
91 | 92 | Builds a EIP712 object and calculates its hash |
92 | 93 |
|
93 | 94 | :param delegate_address: |
94 | 95 | :param chain_id: |
95 | 96 | :param previous_totp: |
96 | | - :return: Hash for the EIP712 generated object from the provided parameters |
| 97 | + :return: Hash for the EIP712 generated object from the provided parameters with the preimage |
97 | 98 | """ |
98 | 99 | totp = cls.calculate_totp(previous=previous_totp) |
99 | 100 |
|
@@ -125,7 +126,8 @@ def calculate_hash( |
125 | 126 | ) |
126 | 127 | payload["domain"]["chainId"] = chain_id |
127 | 128 |
|
128 | | - return eip712_encode_hash(payload) |
| 129 | + preimage = b"".join(eip712_encode(payload)) |
| 130 | + return fast_keccak(preimage), preimage |
129 | 131 |
|
130 | 132 |
|
131 | 133 | def is_valid_unique_transfer_id(unique_transfer_id: str) -> bool: |
|
0 commit comments