Skip to main content

EIP712

https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data. The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible, thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in their contracts using a combination of abi.encode and keccak256. This contract implements the EIP 712 domain separator ({domainSeparatorV4}) that is used as part of the encoding scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA ({_hashTypedDataV4}). The implementation of the domain separator was designed to be as efficient as possible while still properly updating the chain id to protect against replay attacks on an eventual fork of the chain. NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask]. NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain separator of the implementation contract. This will cause the _domainSeparatorV4 function to always rebuild the separator from the immutable values, which is cheaper than accessing a cached version in cold storage. _Available since v3.4.

Methods

eip712Domain

function eip712Domain() external view returns (bytes1 fields, string name, string version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] extensions)

See {EIP-5267}. Available since v4.9.

Returns

NameTypeDescription
fieldsbytes1undefined
namestringundefined
versionstringundefined
chainIduint256undefined
verifyingContractaddressundefined
saltbytes32undefined
extensionsuint256[]undefined

Events

EIP712DomainChanged

event EIP712DomainChanged()

MAY be emitted to signal that the domain could have changed.

Errors

InvalidShortString

error InvalidShortString()

StringTooLong

error StringTooLong(string str)

Parameters

NameTypeDescription
strstringundefined