Contract for EIP-712 typed structured data hashing and signing.
Note, this implementation:
- Uses
address(this)for theverifyingContractfield. - Does NOT use the optional EIP-712 salt.
- Does NOT use any EIP-712 extensions. This is for simplicity and to save gas. If you need to customize, please fork / modify accordingly.
bytes32 internal constant _DOMAIN_TYPEHASH =
0x8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400fkeccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)").
bytes32 internal constant _DOMAIN_TYPEHASH_SANS_CHAIN_ID =
0x91ab3d17e3a50a9d89e63fd30b92be7f5336b03b287bb946787a83a9d62a2766keccak256("EIP712Domain(string name,string version,address verifyingContract)").
This is only used in _hashTypedDataSansChainId.
bytes32 internal constant
_DOMAIN_TYPEHASH_SANS_CHAIN_ID_AND_VERIFYING_CONTRACT =
0xb03948446334eb9b2196d5eb166f69b9d49403eb4a12f36de8d3f9f3cb8e15c3keccak256("EIP712Domain(string name,string version)").
This is only used in _hashTypedDataSansChainIdAndVerifyingContract.
bytes32 internal constant _DOMAIN_TYPEHASH_SANS_VERIFYING_CONTRACT =
0xc2f8787176b8ac6bf7215b4adcc1e069bf4ab82d9ab1df05a57a91d425935b6ekeccak256("EIP712Domain(string name,string version,uint256 chainId)").
This is only used in _hashTypedDataSansVerifyingContract.
function _domainSeparator()
internal
view
virtual
returns (bytes32 separator)Returns the EIP-712 domain separator.
function _hashTypedData(bytes32 structHash)
internal
view
virtual
returns (bytes32 digest)Returns the hash of the fully encoded EIP-712 message for this domain,
given structHash, as defined in
https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct.
The hash can be used together with ECDSA-recover to obtain the signer of a message:
bytes32 digest = _hashTypedData(keccak256(abi.encode(
keccak256("Mail(address to,string contents)"),
mailTo,
keccak256(bytes(mailContents))
)));
address signer = ECDSA.recover(digest, signature); function _hashTypedDataSansChainId(bytes32 structHash)
internal
view
virtual
returns (bytes32 digest)Variant of _hashTypedData that excludes the chain ID.
Included for the niche use case of cross-chain workflows.
function _hashTypedDataSansChainIdAndVerifyingContract(bytes32 structHash)
internal
view
virtual
returns (bytes32 digest)Variant of _hashTypedData that excludes the chain ID and verifying contract.
Included for the niche use case of cross-chain and multi-verifier workflows.
function _hashTypedDataSansVerifyingContract(bytes32 structHash)
internal
view
virtual
returns (bytes32 digest)Variant of _hashTypedData that excludes the chain ID and verifying contract.
Included for the niche use case of multi-verifier workflows.
function eip712Domain()
public
view
virtual
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
)