Skip to content

validateSiweMessage

Validates EIP-4361 message.

Import

import { validateSiweMessage } from 'viem/siwe'

Usage

import { validateSiweMessage } from 'viem/siwe'
 
const valid = validateSiweMessage({
  address: '0xd2135CfB216b74109775236E36d4b433F1DF507B',
  message: {
    address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
    chainId: 1,
    domain: 'example.com',
    nonce: 'foobarbaz',
    uri: 'https://example.com/path',
    version: '1',
  },
})

Returns

boolean

Whether the message fields are valid.

Parameters

message

  • Type: Partial<SiweMessage>

EIP-4361 message fields.

address (optional)

  • Type: string

Ethereum address to check against.

domain (optional)

  • Type: string

RFC 3986 authority to check against.

nonce (optional)

  • Type: string

Random string to check against.

scheme (optional)

  • Type: string

RFC 3986 URI scheme to check against.

time (optional)

  • Type: Date
  • Default: new Date()

Current time to check optional expirationTime and notBefore message fields.