EIP712Lib
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
| Name | Type | Description |
|---|---|---|
| $ | 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
| Name | Type | Description |
|---|---|---|
| name | string | The human-readable name of the signing domain. |
| version | string | The 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
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 | The 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
| Name | Type | Description |
|---|---|---|
| structHash | bytes32 | The hash of the typed data struct. |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 | The 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
| Name | Type | Description |
|---|---|---|
| fields | bytes1 | Active field bitmask (0x0f = name, version, chainId, verifyingContract). |
| name | string | The signing domain name. |
| version | string | The signing domain version. |
| chainId | uint256 | The current chain ID. |
| verifyingContract | address | This contract's address. |
| salt | bytes32 | Empty (not used). |
| extensions | uint256[] | 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
| Name | Type | Description |
|---|---|---|
| hashedName | bytes32 | |
| hashedVersion | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |