Testing repo for showing how to properly encode and hash a message that contains a struct array in accordance to EIP712 using Viem.
Viem Setup
- clone repo:
git clone https://github.com/0xFloop/eip712-struct-array.git
- cd into the viem folder:
cd eip712-struct-array/viemTest
- install dep:
npm install
- run viem script:
npm run start
- copy the hash that is console.logged out
Sol Setup \n
- cd to root:
cd ../
- open
~/test/EIP712SigConsumer.t.sol
and paste the copied viem generated hash into theviemGeneratedDigest
on line 15 - run
forge test -v
This contract operates as a simple EIP712 sig consumer.
This function hashes the SubStruct[]
in accordance to EIP712. Essentially using hashStruct
on all the indices of the SubStruct[]
and then hashing them all together.
This function compares a hash ViemHash
generate using viem to that which is generated by the hashStruct function in the contract and checks if they match.
This is the test to check your viem hash vs that generated in the contract. Just save the viem hash to the viemGeneratedDigest
var on line 15 to test.
This folder contains simple script for generating a EIP712 hash using viems hashTypedData
The eip712 domains in Viem and in the Sol both use static data for the comparison, namely the chain id and the verifyingContract address