Skip to content
LogoLogo

verifyAuthorization

Verifies that an Authorization object was signed by the provided address.

Import

import {  } from 'viem/utils'

Usage

// @filename: client.ts
import { createWalletClient, http } from 'viem'
import { mainnet } from 'viem/chains'
 
export const walletClient = createWalletClient({
  chain: mainnet,
  transport: http(),
})
// @filename: example.ts
// ---cut---
import { privateKeyToAccount } from 'viem/accounts'
import { verifyAuthorization } from 'viem/utils'
import { walletClient } from './client'
 
const eoa = privateKeyToAccount('0x...')
 
const authorization = await walletClient.signAuthorization({
  account: eoa,
  authorization: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2'
})
 
const valid = await verifyAuthorization({ 
  address: eoa.address, 
  authorization, 
}) 

Returns

boolean

Whether the signature is valid for the provided Authorization object.

Parameters

address

  • Type: Address

The address that signed the Authorization object.

// @filename: client.ts
import { createWalletClient, http } from 'viem'
import { mainnet } from 'viem/chains'
 
export const walletClient = createWalletClient({
  chain: mainnet,
  transport: http(),
})
// @filename: example.ts
// ---cut---
import { verifyAuthorization } from 'viem/utils'
import { walletClient } from './client'
 
const authorization = await walletClient.signAuthorization({
  authorization: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2'
})
// ---cut---
const valid = await verifyAuthorization({
  address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', 
  authorization,
}) 

authorization

  • Type: Authorization | SignedAuthorization

The Authorization object to be verified.

// @filename: client.ts
import { createWalletClient, http } from 'viem'
import { mainnet } from 'viem/chains'
 
export const walletClient = createWalletClient({
  chain: mainnet,
  transport: http(),
})
// @filename: example.ts
// ---cut---
import { verifyAuthorization } from 'viem/utils'
import { walletClient } from './client'
// ---cut---
const authorization = await walletClient.signAuthorization({
  authorization: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2'
})
 
const valid = await verifyAuthorization({
  address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
  authorization, 
}) 

signature

  • Type: Hex | ByteArray | Signature | SignedAuthorization

The signature that was generated by signing the Authorization object with the address's private key.

// @filename: client.ts
import { createWalletClient, http } from 'viem'
import { mainnet } from 'viem/chains'
 
export const walletClient = createWalletClient({
  chain: mainnet,
  transport: http(),
})
// @filename: example.ts
// ---cut---
import { verifyAuthorization } from 'viem/utils'
import { walletClient } from './client'
// ---cut---
const signature = await walletClient.signAuthorization({
  authorization: {
    address: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
    chainId: 1,
    nonce: 0,
  }
})
 
const valid = await verifyAuthorization({
  address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
  authorization: {
    address: '0xd8da6bf26964af9d7eed9e03e53415d37aa96045',
    chainId: 1,
    nonce: 0,
  },
  signature, 
})