Skip to content

[Naive Receiver] How do I sign data in Foundry? #64

Discussion options

You must be logged in to vote

You can get the signature from the forge cheat code vm.sign() as explained here: https://book.getfoundry.sh/cheatcodes/sign.

So basically you would do the following to obtain the signature:

(uint8 v, bytes32 r, bytes32 s) = vm.sign(playerPk, eip712Hash);
bytes memory signature = abi.encodePacked(r, s, v);

In addition make sure to supply the hash in a EIP721 compliant format. That means to use your dataHash and hash it again with the following parameters:

bytes32 eip712Hash = keccak256(
            abi.encodePacked("\x19\x01", forwarder.domainSeparator(), dataHash)
        );

For more information have a look at the EIP712: https://eips.ethereum.org/EIPS/eip-712

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by AlexGorgut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
2 participants