Im writing a test in solidity to emulate this behaviour:
import "@openzeppelin/contracts-upgradeable/utils/cryptography/EIP712Upgradeable.sol";
...
bytes32 constant ORGPROXY_TYPEHASH = keccak256(
"TempOrgProxy(string organizationName,address creator)");
// Creates a bytes32 hash of the inputs
function getOrgStructHash(
TempOrgProxy memory structToHash
) external pure returns (bytes32) {
bytes32 _typeHash = keccak256(abi.encode(ORGPROXY_TYPEHASH,keccak256(abi.encodePacked(structToHash.organizationName)),structToHash.creator));
return _typeHash;
}
...
function checkHashSignature(RegistryLibrary.TempOrgProxy memory _structToHash, bytes memory signature) public view returns (bytes32) {
bytes32 structTypedHash = RegistryLibrary.getOrgStructHash(_structToHash);
console.logBytes32(structTypedHash); //SHOULD BE EQUAL TO `beforeWithFunction` IN THE TEST BELOW AND IT IS 0xa837c2cd5ee7a066ca17f66d1cd879966ed39de4df8fabdb0948fd6504a54a1f
bytes32 finalStructHash = EIP712Upgradeable._hashTypedDataV4(structTypedHash);
console.logBytes32(finalStructHash); // THIS SHOULD BE THE SAME AS `digest` IN THE TEST BELOW BUT ITS NOT 0x1be58dfbb7c35e233d206ca2577c6f73d7742a1fd1494c6e5ce52d348a92e981
...
And here the test to reproduce it:
bytes32 beforeWithFunction = RegistryLibrary.getOrgStructHash(organizerStruct);
console.logBytes32(beforeWithFunction); //SHOULD BE EQUAL TO `structTypedHash` IN THE CODE ABOVE AND IT IS 0xa837c2cd5ee7a066ca17f66d1cd879966ed39de4df8fabdb0948fd6504a54a1f
bytes32 digest = EIP712Upgradeable._hashTypedDataV4(beforeWithFunction);
console.logBytes32(digest); // THIS SHOULD BE THE SAME AS `finalStructHash` IN THE CODE ABOVE BUT ITS NOT: 0xe03282d64c5fc659089647b70d111f5721dd9414cc7127f7e25df2178f51ccc6
Im importing the same implementation of EIP712Upgradeable so Im literally out of clue. Any guidance will be much appreciated!
Environment
Foundry