|
7 | 7 |
|
8 | 8 | from eth_account import Account |
9 | 9 | from eth_account.messages import encode_typed_data |
| 10 | +from eth_utils.crypto import keccak |
10 | 11 | from web3 import Web3 |
11 | 12 |
|
12 | 13 | from virtuals_acp.alchemy import AlchemyAccountKit |
13 | 14 | from virtuals_acp.configs.configs import ACPContractConfig, BASE_MAINNET_CONFIG |
14 | 15 | from virtuals_acp.contract_clients.base_contract_client import BaseAcpContractClient |
| 16 | +from virtuals_acp.constants import SINGLE_SIGNER_VALIDATION_MODULE_ADDRESS |
15 | 17 | from virtuals_acp.exceptions import ACPError |
16 | 18 | from virtuals_acp.models import ( |
17 | 19 | ACPJobPhase, |
@@ -241,10 +243,24 @@ def get_asset_manager_address(self) -> str: |
241 | 243 | raise ACPError("Not Supported") |
242 | 244 |
|
243 | 245 | def sign_typed_data(self, typed_data: dict[str, Any]) -> str: |
244 | | - signable = encode_typed_data(full_message=typed_data) |
| 246 | + encoded = encode_typed_data(full_message=typed_data) |
| 247 | + typed_data_hash = keccak(b"\x19\x01" + encoded.header + encoded.body) |
| 248 | + |
| 249 | + replay_safe_typed_data = { |
| 250 | + "domain": { |
| 251 | + "chainId": self.config.chain_id, |
| 252 | + "verifyingContract": SINGLE_SIGNER_VALIDATION_MODULE_ADDRESS, |
| 253 | + "salt": "0x" + "00" * 12 + self.agent_wallet_address[2:], |
| 254 | + }, |
| 255 | + "types": {"ReplaySafeHash": [{"name": "hash", "type": "bytes32"}]}, |
| 256 | + "message": {"hash": "0x" + typed_data_hash.hex()}, |
| 257 | + "primaryType": "ReplaySafeHash", |
| 258 | + } |
| 259 | + |
| 260 | + signable = encode_typed_data(full_message=replay_safe_typed_data) |
245 | 261 | signed = self.account.sign_message(signable) |
246 | 262 | raw_signature = signed.signature.hex() |
247 | | - return f"0x{self._pack_1271_eoa_signature(raw_signature)}" |
| 263 | + return self._pack_1271_eoa_signature(raw_signature) |
248 | 264 |
|
249 | 265 | def _pack_1271_eoa_signature(self, validation_signature: str) -> str: |
250 | 266 | if validation_signature.startswith("0x"): |
|
0 commit comments