ERC7739Lib
Title: ERC7739Lib
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)
Cross-checked against Solady src/accounts/ERC1271.sol for the wire layout.
Pure ERC-7739 ("defensive rehashing") helpers: nested EIP-712 (TypedDataSign) and PersonalSign
struct hashing + wire decoding. No state, no assembly. Consumed by ERC1271SignatureLib.
These rebind an incoming signature to a specific EIP-712 domain so a signature valid for one account cannot be replayed against another account that shares the same owner key.
Constants
PERSONAL_SIGN_TYPEHASH
keccak256("PersonalSign(bytes prefixed)").
bytes32 internal constant PERSONAL_SIGN_TYPEHASH =
0x983e65e5148e570cd828ead231ee759a8d7958721a768f93bc4483ba005c32de;Functions
personalSignStructHash
keccak256(abi.encode(PERSONAL_SIGN_TYPEHASH, contents)).
function personalSignStructHash(bytes32 contents) internal pure returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| contents | bytes32 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |
typedDataSignTypehash
TypedDataSign(contentsName contents,string name,string version,uint256 chainId,address verifyingContract,bytes32 salt)contentsType``.
function typedDataSignTypehash(string calldata contentsName, string calldata contentsType)
internal
pure
returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| contentsName | string | |
| contentsType | string |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |
typedDataSignStructHash
keccak256(typehash || contentsHash || domainBytes); an empty contents name yields bytes32(0),
which can never match a real outer hash (so a malformed descriptor fails closed).
function typedDataSignStructHash(
string calldata contentsName,
string calldata contentsType,
bytes32 contentsHash,
bytes memory domainBytes
) internal pure returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| contentsName | string | |
| contentsType | string | |
| contentsHash | bytes32 | |
| domainBytes | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |
typedDataSignStructHash
Overload that splits contentsDescr into name + type first.
function typedDataSignStructHash(string calldata contentsDescr, bytes32 contentsHash, bytes memory domainBytes)
internal
pure
returns (bytes32);Parameters
| Name | Type | Description |
|---|---|---|
| contentsDescr | string | |
| contentsHash | bytes32 | |
| domainBytes | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bytes32 |
decodeTypedDataSig
Layout: signature ‖ appSeparator(32) ‖ contentsHash(32) ‖ contentsDescr(N) ‖ uint16(N).
A too-short / inconsistent envelope decodes to empty values (which then fail validation).
function decodeTypedDataSig(bytes calldata encodedSignature)
internal
pure
returns (bytes calldata signature, bytes32 appSeparator, bytes32 contentsHash, string calldata contentsDescr);Parameters
| Name | Type | Description |
|---|---|---|
| encodedSignature | bytes |
Returns
| Name | Type | Description |
|---|---|---|
| signature | bytes | |
| appSeparator | bytes32 | |
| contentsHash | bytes32 | |
| contentsDescr | string |
decodeContentsDescr
Splits a contents descriptor into (contentsName, contentsType).
- Implicit form (descriptor ends with
)): type == descriptor, name = prefix up to the first(. - Explicit form: the name is appended after the type's closing
). Returns empty strings on any malformed descriptor (which then fails closed).
function decodeContentsDescr(string calldata contentsDescr)
internal
pure
returns (string calldata contentsName, string calldata contentsType);Parameters
| Name | Type | Description |
|---|---|---|
| contentsDescr | string |
Returns
| Name | Type | Description |
|---|---|---|
| contentsName | string | |
| contentsType | string |
_isForbiddenChar
function _isForbiddenChar(bytes1 c) private pure returns (bool);Parameters
| Name | Type | Description |
|---|---|---|
| c | bytes1 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | bool |
_emptyBytes
function _emptyBytes() private pure returns (bytes calldata r);Returns
| Name | Type | Description |
|---|---|---|
| r | bytes |
_emptyString
function _emptyString() private pure returns (string calldata r);Returns
| Name | Type | Description |
|---|---|---|
| r | string |