Is It Possible To Sign Interface.encodeFunctionData() With _signTypedData #1981
-
Hello 👋. I have been trying to implement a Forwarder smart contract that calls a function on a target contract. This Forwarder contract requires that the users to sign an EIP 712 message that contains the encoded function signature with parameters, essentially a The following snippets are my current implementation. Smart Contractbytes32 eip712_hashedMessage = keccak256(
abi.encode(
keccak256("Forwarder(bytes functionSig)"), // typehash
keccak256(functionSig) // functionSig is of bytes type, can be obtained using encodeFunctionData() from ethers.js
)
) After the EIP712 message has been verified, the contract simply does a (bool success, bytes memory data) = address(target).call(abi.encodePacked(functionSig)) Ethers.jsconst setGreeterSig = ['function setGreeting(string memory _greeting)']
const setGreeterIFace= new utils.Interface(setGreeterSig);
function encodeSetGreeter(greeting: string): string {
return setGreeterIFace.encodeFunctionData('setGreeting', [greeting]);
}
const type = {
Forwarder: [
{name: "functionSig", type: "bytes"}
]
}
const value = {
functionSig: encodeSetGreeter("Hello, World!")
}
const signature = signer._signTypedData(domain, type, value); The contract couldn't recover the correct signer address. I am not sure what I am doing wrong here, I would really appreciate anyone pointing out my possible mistakes here. I have also tried using |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Never mind it turns out it was a mistake on my part. FYI, we can pass in the encoded function signature as it is, no |
Beta Was this translation helpful? Give feedback.
Never mind it turns out it was a mistake on my part. FYI, we can pass in the encoded function signature as it is, no
toUtf8Bytes
conversion necessary. :)