SignatureChecker

Git Source

Author: M^0 Labs

Functions

isValidSignature

Returns whether a signature is valid (ECDSA/secp256k1 or ERC1271) for a signer and digest.

Signatures must not be used as unique identifiers since the ecrecover EVM opcode allows for malleable (non-unique) signatures. See https://github.com/OpenZeppelin/openzeppelin-contracts/security/advisories/GHSA-4h98-2769-gh6h

function isValidSignature(address signer, bytes32 digest, bytes memory signature) internal view returns (bool);

Parameters

NameTypeDescription

signer

address

The address of the account purported to have signed.

digest

bytes32

The hash of the data that was signed.

signature

bytes

A byte array signature.

Returns

NameTypeDescription

<none>

bool

Whether the signature is valid or not.

isValidERC1271Signature

Returns whether an ERC1271 signature is valid for a signer and digest.

function isValidERC1271Signature(address signer, bytes32 digest, bytes memory signature) internal view returns (bool);

Parameters

NameTypeDescription

signer

address

The address of the account purported to have signed.

digest

bytes32

The hash of the data that was signed.

signature

bytes

A byte array ERC1271 signature.

Returns

NameTypeDescription

<none>

bool

Whether the signature is valid or not.

decodeECDSASignature

Decodes an ECDSA/secp256k1 signature from a byte array to standard v, r, and s parameters.

function decodeECDSASignature(bytes memory signature) internal pure returns (uint8 v, bytes32 r, bytes32 s);

Parameters

NameTypeDescription

signature

bytes

A byte array ECDSA/secp256k1 signature.

Returns

NameTypeDescription

v

uint8

An ECDSA/secp256k1 signature parameter.

r

bytes32

An ECDSA/secp256k1 signature parameter.

s

bytes32

An ECDSA/secp256k1 signature parameter.

decodeShortECDSASignature

Decodes an ECDSA/secp256k1 short signature as defined by EIP2098 from a byte array to standard v, r, and s parameters.

function decodeShortECDSASignature(bytes memory signature) internal pure returns (bytes32 r, bytes32 vs);

Parameters

NameTypeDescription

signature

bytes

A byte array ECDSA/secp256k1 short signature.

Returns

NameTypeDescription

r

bytes32

An ECDSA/secp256k1 signature parameter.

vs

bytes32

An ECDSA/secp256k1 short signature parameter.

isValidECDSASignature

Returns whether an ECDSA/secp256k1 signature is valid for a signer and digest.

function isValidECDSASignature(address signer, bytes32 digest, bytes memory signature) internal pure returns (bool);

Parameters

NameTypeDescription

signer

address

The address of the account purported to have signed.

digest

bytes32

The hash of the data that was signed.

signature

bytes

A byte array ECDSA/secp256k1 signature (encoded r, s, v).

Returns

NameTypeDescription

<none>

bool

Whether the signature is valid or not.

isValidECDSASignature

Returns whether an ECDSA/secp256k1 short signature is valid for a signer and digest.

function isValidECDSASignature(address signer, bytes32 digest, bytes32 r, bytes32 vs) internal pure returns (bool);

Parameters

NameTypeDescription

signer

address

The address of the account purported to have signed.

digest

bytes32

The hash of the data that was signed.

r

bytes32

An ECDSA/secp256k1 signature parameter.

vs

bytes32

An ECDSA/secp256k1 short signature parameter.

Returns

NameTypeDescription

<none>

bool

Whether the signature is valid or not.

recoverECDSASigner

Returns the signer of an ECDSA/secp256k1 signature for some digest.

function recoverECDSASigner(bytes32 digest, bytes memory signature) internal pure returns (Error, address);

Parameters

NameTypeDescription

digest

bytes32

The hash of the data that was signed.

signature

bytes

A byte array ECDSA/secp256k1 signature.

Returns

NameTypeDescription

<none>

Error

An error, if any, that occurred during the signer recovery.

<none>

address

The address of the account recovered form the signature (0 if error).

recoverECDSASigner

Returns the signer of an ECDSA/secp256k1 short signature for some digest.

See https://eips.ethereum.org/EIPS/eip-2098

function recoverECDSASigner(bytes32 digest, bytes32 r, bytes32 vs) internal pure returns (Error, address);

Parameters

NameTypeDescription

digest

bytes32

The hash of the data that was signed.

r

bytes32

An ECDSA/secp256k1 signature parameter.

vs

bytes32

An ECDSA/secp256k1 short signature parameter.

Returns

NameTypeDescription

<none>

Error

An error, if any, that occurred during the signer recovery.

<none>

address

The address of the account recovered form the signature (0 if error).

recoverECDSASigner

Returns the signer of an ECDSA/secp256k1 signature for some digest.

function recoverECDSASigner(bytes32 digest, uint8 v, bytes32 r, bytes32 s)
    internal
    pure
    returns (Error, address signer);

Parameters

NameTypeDescription

digest

bytes32

The hash of the data that was signed.

v

uint8

An ECDSA/secp256k1 signature parameter.

r

bytes32

An ECDSA/secp256k1 signature parameter.

s

bytes32

An ECDSA/secp256k1 signature parameter.

Returns

NameTypeDescription

<none>

Error

An error, if any, that occurred during the signer recovery.

signer

address

The address of the account recovered form the signature (0 if error).

validateECDSASignature

Returns an error, if any, in validating an ECDSA/secp256k1 signature for a signer and digest.

function validateECDSASignature(address signer, bytes32 digest, bytes memory signature) internal pure returns (Error);

Parameters

NameTypeDescription

signer

address

The address of the account purported to have signed.

digest

bytes32

The hash of the data that was signed.

signature

bytes

A byte array ERC1271 signature.

Returns

NameTypeDescription

<none>

Error

An error, if any, that occurred during the signer recovery.

validateECDSASignature

Returns an error, if any, in validating an ECDSA/secp256k1 short signature for a signer and digest.

function validateECDSASignature(address signer, bytes32 digest, bytes32 r, bytes32 vs) internal pure returns (Error);

Parameters

NameTypeDescription

signer

address

The address of the account purported to have signed.

digest

bytes32

The hash of the data that was signed.

r

bytes32

An ECDSA/secp256k1 signature parameter.

vs

bytes32

An ECDSA/secp256k1 short signature parameter.

Returns

NameTypeDescription

<none>

Error

An error, if any, that occurred during the signer recovery.

validateECDSASignature

Returns an error, if any, in validating an ECDSA/secp256k1 signature for a signer and digest.

function validateECDSASignature(address signer, bytes32 digest, uint8 v, bytes32 r, bytes32 s)
    internal
    pure
    returns (Error);

Parameters

NameTypeDescription

signer

address

The address of the account purported to have signed.

digest

bytes32

The hash of the data that was signed.

v

uint8

An ECDSA/secp256k1 signature parameter.

r

bytes32

An ECDSA/secp256k1 signature parameter.

s

bytes32

An ECDSA/secp256k1 signature parameter.

Returns

NameTypeDescription

<none>

Error

An error, if any, that occurred during the signer recovery.

validateRecoveredSigner

Returns an error if signer is not recoveredSigner.

function validateRecoveredSigner(address signer, address recoveredSigner) internal pure returns (Error);

Parameters

NameTypeDescription

signer

address

The address of the some signer.

recoveredSigner

address

The address of the some recoveredSigner.

Returns

NameTypeDescription

<none>

Error

An error if signer is not recoveredSigner.

Enums

Error

An enum representing the possible errors that can be emitted during signature validation.

enum Error {
    NoError,
    InvalidSignature,
    InvalidSignatureLength,
    InvalidSignatureS,
    InvalidSignatureV,
    SignerMismatch
}

Copyright 2024 M^0 Foundation