Skip to content
Lattice

EIP712Lib

Git Source

Title: EIP712Lib

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from OpenZeppelin (https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/cryptography/EIP712.sol)

Library implementing EIP-712 typed structured data hashing. Supports ERC-5267 domain discovery and caches the domain separator for the current chain ID + contract address to save gas.

Functions

eip712Storage

function eip712Storage() internal pure returns (EIP712Storage storage $);

Returns

NameTypeDescription
$EIP712Storage

__EIP712_init

Initializes the EIP-712 module with the given name and version.

Must be called inside a pre/postInitializer block. Caches the domain separator, chain ID, and contract address. Registers the IEIP712 interface for ERC-165 discovery.

function __EIP712_init(string memory name, string memory version) internal;

Parameters

NameTypeDescription
namestringThe human-readable name of the signing domain.
versionstringThe version of the signing domain.

registerInterface

Registers support for the IEIP712 interface via ERC-165.

function registerInterface() internal;

domainSeparatorV4

Returns the EIP-712 domain separator.

Returns the cached value if chain ID and this address match; otherwise recomputes.

function domainSeparatorV4() internal view returns (bytes32);

Returns

NameTypeDescription
<none>bytes32The current domain separator.

hashTypedDataV4

Returns the hash of an EIP-712 typed data message.

Prefixes the struct hash with the EIP-712 domain separator.

function hashTypedDataV4(bytes32 structHash) internal view returns (bytes32);

Parameters

NameTypeDescription
structHashbytes32The hash of the typed data struct.

Returns

NameTypeDescription
<none>bytes32The final digest: keccak256("\x19\x01" + domainSeparator + structHash).

eip712Domain

Returns the ERC-5267 domain descriptor.

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

Returns

NameTypeDescription
fieldsbytes1Active field bitmask (0x0f = name, version, chainId, verifyingContract).
namestringThe signing domain name.
versionstringThe signing domain version.
chainIduint256The current chain ID.
verifyingContractaddressThis contract's address.
saltbytes32Empty (not used).
extensionsuint256[]Empty array.

_buildDomainSeparator

Builds the EIP-712 domain separator from hashed name and version.

function _buildDomainSeparator(bytes32 hashedName, bytes32 hashedVersion) private view returns (bytes32);

Parameters

NameTypeDescription
hashedNamebytes32
hashedVersionbytes32

Returns

NameTypeDescription
<none>bytes32