Skip to main content

Try it Live

Run SIWE examples in the interactive playground

Constructors

Methods for creating SIWE message instances.

create

Create new SIWE message with automatic defaults.

Signature

Parameters

Required:
  • domain - RFC 4501 dns authority requesting signing
  • address - AddressType performing signing (20 bytes)
  • uri - RFC 3986 URI referring to subject of signing
  • chainId - EIP-155 Chain ID (positive integer)
Optional:
  • statement - Human-readable ASCII assertion
  • expirationTime - ISO 8601 datetime for expiration
  • notBefore - ISO 8601 datetime for not-before
  • requestId - System-specific identifier
  • resources - Array of resource URIs
  • nonce - Custom nonce (auto-generated if omitted, min 8 chars)
  • issuedAt - Custom issued time (current time if omitted)

Returns

BrandedMessage with:
  • version automatically set to "1"
  • nonce auto-generated if not provided (11 chars, base62)
  • issuedAt auto-set to current ISO 8601 time if not provided
  • Optional fields only included if provided

Example

Type Safety

Generic parameters preserve exact types:

Notes

  • Nonce generation: Uses crypto.getRandomValues() for secure randomness
  • Timestamp format: ISO 8601 format required for all timestamps
  • Version: Always “1” per EIP-4361 current specification
  • Optional fields: Only present in returned object if provided (no undefined)
  • Address format: Must be valid 20-byte AddressType

Common Use Cases

Session with Expiration

Resource-Restricted Access

Delayed Activation

Request Tracking

Implementation Details

  • Uses conditional spreading for optional fields (no undefined values)
  • Delegates nonce generation to generateNonce()
  • Current timestamp from new Date().toISOString()
  • Version hardcoded to “1” per EIP-4361 spec
  • Returns plain object (not class instance)

See Also