Signature.verify
Says whether an account signed a digest: 32 bytes, hashed the way the signer hashed them. For
a message or typed data, verifyMessage and
verifyTypedData hash for you.
import { Effect } from "effect";import { FetchHttpClient } from "effect/http";import { Address, Signature, Transport } from "@ethect/core";
const ADDRESS = Address.makeUnsafe("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266");
const program = Signature.verify({ address: ADDRESS, digest: "0x5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c5c", signature: "0x563bf02d856c1151500e047d2dd047a9b80a7f9d6a0337c82b641574145dc8514bc0bb75aabf368dbaeb97619c5888a069ad2d297f19c3ac7d75422fe1960d1b1b",});
const signed = await program.pipe( Effect.provide(Transport.http("https://ethereum-rpc.publicnode.com")), Effect.provide(FetchHttpClient.layer), Effect.runPromise,); // trueThe examples below leave the transport out.
At a block
Section titled “At a block”A contract account can change who signs for it. Ask what it said at a block with
Call.withBlock.
import { Call, Signature, type Address, type Hash, type Hex } from "@ethect/core";
const signedThen = (address: Address.Address, digest: Hash.Hash, signature: Hex.Hex) => Signature.verify({ address, digest, signature }).pipe( Call.withBlock(19_000_000n), );An account that is not deployed yet
Section titled “An account that is not deployed yet”A smart wallet signs before its contract exists. Its signature then says how to deploy it (ERC-6492), and nothing changes in the call: pass it as it is.
import { Signature, type Address, type Hash, type Hex } from "@ethect/core";
const signed = (wallet: Address.Address, digest: Hash.Hash, wrapped: Hex.Hex) => Signature.verify({ address: wallet, digest, signature: wrapped });Returns
Section titled “Returns”Effect<boolean, Transport.Error, Transport.Transport>
true when the account signed the digest, false when it did not.
Parameters
Section titled “Parameters”claim.address
Section titled “claim.address”- Type:
Address.Address
The account that is said to have signed: a key, or a contract.
claim.digest
Section titled “claim.digest”- Type:
Hash.Hash
What was signed: 32 bytes.
claim.signature
Section titled “claim.signature”- Type:
Hex | Signature.Signature
The signature: what the signer gave. See a signature.
Behavior
Section titled “Behavior”- Check a digest your program hashed, never one it was sent. For any account, anyone can make a signature that fits some digest. Only the hash of a message you know proves a thing.
- A key’s signature costs no request. When the signature recovers to the address, the
answer is
trueand the node is not asked. Only a key can make such a signature, so it is right whatever is deployed at the address. - Anything else is asked of the node. A contract has no key: it says itself whether a
signature is its own, with
isValidSignature(ERC-1271). A multisig, a smart wallet and an account behind a passkey are checked this way. - An account that is not deployed yet is checked too. Its signature ends with the 32 bytes
6492…6492and says how to deploy it (ERC-6492). The account is deployed for the length of the call, then asked. Nothing is sent, and nothing changes on the chain. falseis an answer. The account refuses, the signature is of another key or of another digest, the account has no code and the bytes are no signature of a key.- What cannot be asked is
false, with no request. A signature that is not hex, a digest that is not 32 bytes, the zero address, which no key and no contract has. - A failure is no answer. A node that cannot be reached, a call it refuses, or one that
runs out of gas fails with a
Transport.Error. It is never turned intofalse. - The latest block is asked, or the one of
Call.withBlock. - 64 bytes are
r ‖ s. The signature is the account’s when either parity recovers it. See 64 bytes. - One signature has several writings.
vas 0 or as 27,sin either half of the order: each is the same signature, and each is accepted. Do not remember a signature by its bytes to refuse it a second time. Remember what was signed: a nonce in the message.
Errors
Section titled “Errors”| Error | When |
|---|---|
Transport.Error |
the node does not answer |
TransportError, "MalformedResponse" |
the node answered the call with something else than one byte, 0x00 or 0x01: it does not run a call with no to as a deployment |
Under the hood
Section titled “Under the hood”the signature recovers to the address: no requestgives
trueotherwise
- your node
eth_call({ data }, block)with noto.datais the validator’s code ‖abi(address, digest, signature) the validator runs as a deployment that is never made, and returns one byte
the signature ends in
6492…6492: unwrap it:(factory, calldata, signature). No code at the address: call the factory, which deploys itthere is code at the address:
isValidSignature(digest, signature)on it (ERC-1271)there is none:
ecrecover, which the first line already tried
0x01givestrue0x00, or the call revertsgivesfalseanything else, or no answerfails with a failure
- your node
The validator is the reference implementation of
ERC-6492, from the text of the standard, compiled
into the library: 3.4 kB that only a program that calls verify* ships. The call goes through
Call.Reader, alone: it is never put in a multicall.