Skip to main content

Try it Live

Run SIWE examples in the interactive playground
New to SIWE? Start with Fundamentals for guided examples and authentication concepts.

Type Definition

Sign-In with Ethereum (EIP-4361) implementation for decentralized authentication. Creates structured messages users sign with private keys, proving address ownership without key exposure.

Authentication Flow

Message Structure

A SIWE message is a human-readable text format combining user intent with cryptographic proof:
Key components:
  • Domain (RFC 4501): Where the message is being signed for
  • Address: Which account is signing
  • URI: What resource is being accessed
  • Statement: Human-readable context
  • Chain ID: Which blockchain
  • Nonce: One-time value, prevents replay attacks
  • Timestamps: Validity window
  • Resources: Optional list of what’s being granted access to

Factory

Creates Siwe message instance from parameters. Parameters:
  • params.domain: RFC 4501 dns authority
  • params.address: AddressType performing signing
  • params.uri: RFC 3986 URI
  • params.chainId: EIP-155 Chain ID
  • params.statement?: Human-readable assertion (optional)
  • params.expirationTime?: ISO 8601 expiration (optional)
  • params.notBefore?: ISO 8601 valid-from time (optional)
  • params.requestId?: System identifier (optional)
  • params.resources?: Resource URIs (optional)
  • params.nonce?: Custom nonce (auto-generated if omitted)
  • params.issuedAt?: Custom timestamp (current time if omitted)
Returns: Siwe message instance

Static Constructors

Siwe.create(params)

Create message with defaults. Same as factory.

Siwe.parse(text)

Parse EIP-4361 formatted string to message. Throws: Error if format invalid

Static Utilities

Formatting

Siwe.format(message)

Format message to EIP-4361 string for signing.

Validation

Siwe.validate(message, options?)

Validate message structure and timestamps. Returns: { valid: true } or { valid: false, error: ValidationError }

Signing & Verification

Siwe.getMessageHash(message)

Get EIP-191 personal sign message hash (32 bytes).

Siwe.verify(message, signature)

Verify signature matches message address. Parameters:
  • signature: 65-byte signature (r + s + v)
Returns: true if valid

Siwe.verifyMessage(message, signature, options?)

Combined validation and verification.

Nonce Generation

Siwe.generateNonce(length?)

Generate cryptographically secure random nonce. Parameters:
  • length: Nonce length (default 11, min 8)
Returns: Base62 alphanumeric string

Instance Methods

All static utilities available as instance methods:
Instance methods delegate to BrandedSiwe namespace functions.

Types

See BrandedSiwe for branded type details.

Implementation

  • Delegates to BrandedSiwe namespace
  • Extends Object.prototype
  • Structured message format per EIP-4361
  • Supports optional fields via conditional spreading

Quick Start

Common Patterns

Authentication Flow

Session Management

API Documentation

Constructors

Creating SIWE messages from parameters or text. View constructors →

Parsing

Parse EIP-4361 formatted strings to message objects. View parsing →

Validation

Validate message structure and timestamps. View validation →

Signing & Verification

Create hashes and verify signatures with addresses. View signing →

Utilities

Nonce generation and helper functions. View utilities →

Usage Patterns

Real-world authentication and session patterns. View patterns →

Quick Reference: Security Checklist

Always Verify:
  • Domain matches request origin
  • Nonce is fresh and single-use
  • Signature is valid
  • Message not expired
  • Address matches session
  • HTTPS in production
  • Siwe (Effect) - Effect.ts integration with Schema validation
  • Address - 20-byte Ethereum addresses used in messages
  • Signature - 65-byte signatures (r + s + v) for verification
  • Keccak256 - 32-byte hashes from message signing

References