Skip to content
Lattice

ERC6538RegistryLib

Git Source

Title: ERC6538RegistryLib

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from ScopeLift (https://github.com/ScopeLift/stealth-address-erc-contracts), Conforms to ERC-6538 (https://eips.ethereum.org/EIPS/eip-6538)

Library implementing the ERC-6538 stealth meta-address registry.

Reuses the shared EIP712 module for the domain separator + typed-data hashing, and SignatureChecker for ECDSA + ERC-1271 verification — mirroring the canonical reference's registerKeysOnBehalf exactly. The nonce is registry-local (this module's own storage), so nonceOf is independent of any token permit / vote-delegation nonce in the same diamond. The EIP-712 domain is the host diamond's shared domain; initialize EIP712 with name "ERC6538Registry" / version "1.0" for canonical ERC-6538 signer compatibility.

Functions

erc6538RegistryStorage

function erc6538RegistryStorage() internal pure returns (ERC6538RegistryStorage storage $);

Returns

NameTypeDescription
$ERC6538RegistryStorage

__ERC6538Registry_init

Initializes the ERC6538Registry module.

Must be called inside a pre/postInitializer block. Registers IERC6538Registry for ERC-165. EIP712 must be initialized separately (the registry reuses its domain for hashing).

function __ERC6538Registry_init() internal;

registerInterface

Registers support for the IERC6538Registry interface via ERC-165.

function registerInterface() internal;

registerKeys

Registers the caller's stealth meta-address for schemeId (last-write-wins).

function registerKeys(uint256 schemeId, bytes calldata stealthMetaAddress) internal;

Parameters

NameTypeDescription
schemeIduint256The stealth-address scheme id.
stealthMetaAddressbytesThe caller's stealth meta-address bytes.

registerKeysOnBehalf

Registers registrant's stealth meta-address from an EIP-712 signature.

Consumes the registrant's nonce BEFORE verifying, so a failed verification reverts the whole call and rolls the consumed nonce back (no griefing). Supports EOA + ERC-1271 signers.

function registerKeysOnBehalf(
        address registrant,
        uint256 schemeId,
        bytes calldata signature,
        bytes calldata stealthMetaAddress
    ) internal;

Parameters

NameTypeDescription
registrantaddressThe account authorizing the registration.
schemeIduint256The stealth-address scheme id.
signaturebytesThe registrant's EIP-712 signature.
stealthMetaAddressbytesThe stealth meta-address bytes to store.

incrementNonce

Advances the caller's nonce, invalidating outstanding on-behalf signatures.

function incrementNonce() internal;

stealthMetaAddressOf

Returns the stealth meta-address registered by registrant for schemeId.

function stealthMetaAddressOf(address registrant, uint256 schemeId) internal view returns (bytes memory);

Parameters

NameTypeDescription
registrantaddressThe account to query.
schemeIduint256The stealth-address scheme id.

Returns

NameTypeDescription
<none>bytesThe registered stealth meta-address bytes (empty if unset).

nonceOf

Returns the current on-behalf-registration nonce for registrant.

function nonceOf(address registrant) internal view returns (uint256);

Parameters

NameTypeDescription
registrantaddressThe account to query.

Returns

NameTypeDescription
<none>uint256The current nonce.

entryTypeHash

Returns the EIP-712 type hash used in registerKeysOnBehalf.

function entryTypeHash() internal pure returns (bytes32);

Returns

NameTypeDescription
<none>bytes32