Skip to content

verifyHash

Verify that a hash (digest) was signed by the provided address.

Supports verification of:

  • Externally Owned Accounts
  • Smart Contract Accounts:

Usage

example.ts
import { account, publicClient } from './client'
 
const valid = await publicClient.verifyHash({
  address: account.address,
  hash: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
  signature: '0x...',
})
true

Returns

boolean

Whether the signed hash is valid for the given address.

Parameters

address

The Ethereum address that signed the original hash.

const valid = await publicClient.verifyHash({
  address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', 
  hash: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
  signature:
    '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})

hash

  • Type: string

The hash to be verified.

const valid = await publicClient.verifyHash({
  address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
  hash: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef', 
  signature:
    '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})

signature

  • Type: Hex | ByteArray | Signature

The signature that was generated by signing the hash with the address's signer.

const valid = await publicClient.verifyHash({
  address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
  hash: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
  signature: 
    '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c', 
})

blockNumber (optional)

  • Type: bigint

Only used when verifying a message that was signed by a Smart Contract Account. The block number to check if the contract was already deployed.

const valid = await publicClient.verifyHash({
  blockNumber: 42069n, 
  address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
  hash: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
  signature:
    '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})

blockTag (optional)

  • Type: 'latest' | 'earliest' | 'pending' | 'safe' | 'finalized'
  • Default: 'latest'

Only used when verifying a message that was signed by a Smart Contract Account. The block tag to check if the contract was already deployed.

const valid = await publicClient.verifyHash({
  blockTag: 'safe', 
  address: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
  hash: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
  signature:
    '0x66edc32e2ab001213321ab7d959a2207fcef5190cc9abb6da5b0d2a8a9af2d4d2b0700e2c317c4106f337fd934fbbb0bf62efc8811a78603b33a8265d3b8f8cb1c',
})