Skip to content

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,
); // true

The examples below leave the transport out.

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),
);

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 });

Effect<boolean, Transport.Error, Transport.Transport>

true when the account signed the digest, false when it did not.

The account that is said to have signed: a key, or a contract.

What was signed: 32 bytes.

  • Type: Hex | Signature.Signature

The signature: what the signer gave. See a signature.

  • 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 true and 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…6492 and 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.
  • false is 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 into false.
  • 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. v as 0 or as 27, s in 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.
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
  1. the signature recovers to the address: no requestgives true

  2. otherwise

    1. your nodeeth_call({ data }, block)with no to. data is the validator’s code ‖ abi(address, digest, signature)
    2. the validator runs as a deployment that is never made, and returns one byte

      1. the signature ends in 6492…6492: unwrap it: (factory, calldata, signature). No code at the address: call the factory, which deploys it

      2. there is code at the address: isValidSignature(digest, signature) on it (ERC-1271)

      3. there is none: ecrecover, which the first line already tried

    3. 0x01gives true

    4. 0x00, or the call revertsgives false

    5. anything else, or no answerfails with a failure

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.