Skip to content
Lattice

ERC6900SignatureLib

Git Source

Title: ERC6900SignatureLib

Authors: David Dada <daveproxy80@gmail.com> (https://github.com/dadadave80), Modified from ERC-6900 reference implementation (https://github.com/erc6900/reference-implementation)

The ERC-6900 ERC-1271 signature-validation path: decodes the validation ModuleEntity from the signature prefix, runs pre-signature-validation hooks (sparse-segmented), gates on the isSignatureValidation flag, and routes to the validation module's validateSignature.

Re-implemented FRESH from the ERC-6900 reference (erc6900/reference-implementation @ 65892c2). Two Lattice additions over the reference: (1) the 1271 hash is first rehashed via ERC-7739 (a nested TypedDataSign / PersonalSign envelope bound to this account's EIP-712 domain) so a signature can never be replayed against a different account sharing the same signer — the module sees the domain-bound digest, not the raw hash; (2) the ERC-7739 support-detection probe (isValidSignature(0x7739…, "")) is answered. The reference 1271 signature layout has NO global flag byte: signature[0:24] is the ModuleEntity and the sparse-segment blob begins at [24:] (vs the userOp path's flag byte at [24] and blob at [25:]).

Functions

__ERC6900Signature_init

Registers the IERC1271 ERC-165 id.

function __ERC6900Signature_init() internal;

registerInterface

function registerInterface() internal;

isValidSignature

ERC-1271 isValidSignature. Returns 0x1626ba7e for a valid (ERC-7739-bound) signature, the 0x77390001 support sentinel for the probe, else 0xffffffff.

function isValidSignature(bytes32 hash, bytes calldata signature) internal view returns (bytes4);

Parameters

NameTypeDescription
hashbytes32
signaturebytes

Returns

NameTypeDescription
<none>bytes4

_runPreSignatureHooks

Runs the validation's pre-signature hooks (each given its sparse segment; a hook revert bubbles), then returns the validation function's own (final) signature segment.

function _runPreSignatureHooks(ModuleEntity vf, bytes32 hash, bytes calldata sig)
        private
        view
        returns (bytes calldata);

Parameters

NameTypeDescription
vfModuleEntity
hashbytes32
sigbytes

Returns

NameTypeDescription
<none>bytes

_exec1271Validation

function _exec1271Validation(ModuleEntity vf, bytes32 hash, bytes calldata finalSig) private view returns (bytes4);

Parameters

NameTypeDescription
vfModuleEntity
hashbytes32
finalSigbytes

Returns

NameTypeDescription
<none>bytes4

_validNestedPersonalSign

personal_sign: the module must accept the owner's signature over hash wrapped in this account's domain. The whole final segment is the module signature.

function _validNestedPersonalSign(ModuleEntity vf, bytes32 hash, bytes calldata signature)
        private
        view
        returns (bool);

Parameters

NameTypeDescription
vfModuleEntity
hashbytes32
signaturebytes

Returns

NameTypeDescription
<none>bool

_validNestedTypedDataSign

eth_signTypedData: the outer hash must equal the app's typed-data hash, and the module must accept the inner signature over the TypedDataSign struct (contents + this account's domain). On a plain (non-envelope) signature, decodeTypedDataSig fails closed, the hash check is false, and the module is not called (falling through to the PersonalSign path).

function _validNestedTypedDataSign(ModuleEntity vf, bytes32 hash, bytes calldata encodedSignature)
        private
        view
        returns (bool);

Parameters

NameTypeDescription
vfModuleEntity
hashbytes32
encodedSignaturebytes

Returns

NameTypeDescription
<none>bool

_moduleValidates

Routes the domain-bound digest + inner signature to the validation module's validateSignature.

function _moduleValidates(ModuleEntity vf, bytes32 digest, bytes calldata signature) private view returns (bool);

Parameters

NameTypeDescription
vfModuleEntity
digestbytes32
signaturebytes

Returns

NameTypeDescription
<none>bool

_domainBytes

This account's EIP-712 domain, abi-encoded for ERC7739Lib.typedDataSignStructHash.

function _domainBytes() private view returns (bytes memory);

Returns

NameTypeDescription
<none>bytes

_toTypedDataHash

keccak256("\x19\x01" || separator || structHash) with the APP's separator.

function _toTypedDataHash(bytes32 separator, bytes32 structHash) private pure returns (bytes32);

Parameters

NameTypeDescription
separatorbytes32
structHashbytes32

Returns

NameTypeDescription
<none>bytes32

_moduleEntityOf

function _moduleEntityOf(bytes calldata sig) private pure returns (ModuleEntity me);

Parameters

NameTypeDescription
sigbytes

Returns

NameTypeDescription
meModuleEntity