Skip to content
Lattice

ERC1271SignatureLib

Git Source

Title: ERC1271SignatureLib

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

Logic for the ERC-1271 contract-signature facet. Stateless — delegates verification to the configured owner via AccountSignerLib.

Implements ERC-7739: isValidSignature accepts only a nested TypedDataSign (EIP-712) or PersonalSign envelope bound to this account's EIP-712 domain, so a signature is never valid for a different account that shares the owner key. A plain signature over the raw hash is rejected. The hashing is delegated to ERC7739Lib (ported from audited OZ/Solady), composed over EIP712Lib.

Functions

__ERC1271Signature_init

Registers the IERC1271 ERC-165 id so dapps can discover contract-signature support.

function __ERC1271Signature_init() internal;

registerInterface

Writes true to the ERC-165 map slot for IERC1271.

function registerInterface() internal;

isValidSignature

ERC-7739 isValidSignature. Returns 0x1626ba7e for a valid nested TypedDataSign / PersonalSign signature, 0x77390001 for the support-detection probe, else 0xffffffff.

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

Parameters

NameTypeDescription
hashbytes32
signaturebytes

Returns

NameTypeDescription
<none>bytes4

_isValidNestedPersonalSignSignature

personal_sign path: the owner must have signed hash wrapped in this account's domain.

function _isValidNestedPersonalSignSignature(bytes32 hash, bytes calldata signature) private view returns (bool);

Parameters

NameTypeDescription
hashbytes32
signaturebytes

Returns

NameTypeDescription
<none>bool

_isValidNestedTypedDataSignature

eth_signTypedData path: the outer hash must equal the app's typed-data hash, and the owner must have signed the TypedDataSign struct (contents + this account's domain) under the app's separator. The inner signature, app separator, contents hash, and descriptor are read from the appended wire envelope.

function _isValidNestedTypedDataSignature(bytes32 hash, bytes calldata encodedSignature)
        private
        view
        returns (bool);

Parameters

NameTypeDescription
hashbytes32
encodedSignaturebytes

Returns

NameTypeDescription
<none>bool

_toTypedDataHash

keccak256("\x19\x01" || separator || structHash). Used here with the APP's separator; EIP712Lib.hashTypedDataV4 wraps with THIS account's separator (the PersonalSign path).

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

Parameters

NameTypeDescription
separatorbytes32
structHashbytes32

Returns

NameTypeDescription
<none>bytes32