ERC6900SignatureLib
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
| Name | Type | Description |
|---|---|---|
| hash | bytes32 | |
| signature | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| vf | ModuleEntity | |
| hash | bytes32 | |
| sig | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes |
_exec1271Validation
function _exec1271Validation(ModuleEntity vf, bytes32 hash, bytes calldata finalSig) private view returns (bytes4);Parameters
| Name | Type | Description |
|---|---|---|
| vf | ModuleEntity | |
| hash | bytes32 | |
| finalSig | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| vf | ModuleEntity | |
| hash | bytes32 | |
| signature | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| vf | ModuleEntity | |
| hash | bytes32 | |
| encodedSignature | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <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
| Name | Type | Description |
|---|---|---|
| vf | ModuleEntity | |
| digest | bytes32 | |
| signature | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
_domainBytes
This account's EIP-712 domain, abi-encoded for ERC7739Lib.typedDataSignStructHash.
function _domainBytes() private view returns (bytes memory);Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes |
_toTypedDataHash
keccak256("\x19\x01" || separator || structHash) with the APP's separator.
function _toTypedDataHash(bytes32 separator, bytes32 structHash) private pure returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| separator | bytes32 | |
| structHash | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |
_moduleEntityOf
function _moduleEntityOf(bytes calldata sig) private pure returns (ModuleEntity me);Parameters
| Name | Type | Description |
|---|---|---|
| sig | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| me | ModuleEntity |