Skip to content

Commit 674d6c4

Browse files
Fix signing of typed data for v1 too
1 parent 7929ca4 commit 674d6c4

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

virtuals_acp/contract_clients/contract_client.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77

88
from eth_account import Account
99
from eth_account.messages import encode_typed_data
10+
from eth_utils.crypto import keccak
1011
from web3 import Web3
1112

1213
from virtuals_acp.alchemy import AlchemyAccountKit
1314
from virtuals_acp.configs.configs import ACPContractConfig, BASE_MAINNET_CONFIG
1415
from virtuals_acp.contract_clients.base_contract_client import BaseAcpContractClient
16+
from virtuals_acp.constants import SINGLE_SIGNER_VALIDATION_MODULE_ADDRESS
1517
from virtuals_acp.exceptions import ACPError
1618
from virtuals_acp.models import (
1719
ACPJobPhase,
@@ -241,10 +243,24 @@ def get_asset_manager_address(self) -> str:
241243
raise ACPError("Not Supported")
242244

243245
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)
245261
signed = self.account.sign_message(signable)
246262
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)
248264

249265
def _pack_1271_eoa_signature(self, validation_signature: str) -> str:
250266
if validation_signature.startswith("0x"):

0 commit comments

Comments
 (0)