Problem with creating a signature following EIP712 and using ethers signTypedData for wagmi.sh #4494
-
Hi everyone! A brief overview of the problem copy and pasted from discord:
So here are some code snippets: test.js:
helper.js:
Wagmi.sh (using ethers v6 adapter):
The forwarder contract is inherited from Openzeppelin's v5 ERC2771Forwarder.sol here: https://docs.openzeppelin.com/contracts/5.x/api/metatx#ERC2771Forwarder The "verify" function in the forwarder contract is used to verify the signature generated by signTypedData. Most of the signature generation is adapted from openzeppelin's tests here: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/test/metatx/ERC2771Forwarder.test.js In hardhat test, the signature generated can be verified and signer matches the recovered address, but in Wagmi.sh, it recovers a different address which doesn't match the signer. The signature generated in Wagmi.sh using MetaMask is also different from hardhat generated one. It would be great if I could get some pointers on where the problem might be and if anyone else has encountered something similar. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi all, just going to answer it myself here as I have found the problem. It seems to be a JS/TS problem on the frontend side due to an incorrect domain being generated from the mismatch in code formats and inference from openzeppelin's test unit. After fixing the issue, it now generates the correct signature, and on-chain verification works. Will be closing this discussion and thanks to those who have taken a look at the issue! |
Beta Was this translation helpful? Give feedback.
Hi all, just going to answer it myself here as I have found the problem.
It seems to be a JS/TS problem on the frontend side due to an incorrect domain being generated from the mismatch in code formats and inference from openzeppelin's test unit. After fixing the issue, it now generates the correct signature, and on-chain verification works.
Will be closing this discussion and thanks to those who have taken a look at the issue!
Bunny