Try it Live
Run SIWE examples in the interactive playground
Utilities
Helper functions for SIWE message operations.generateNonce
Generate cryptographically secure random nonce.Signature
Parameters
length- Nonce length in characters (default: 11, minimum: 8)
Returns
Random base62 alphanumeric string (0-9, a-z, A-Z)Throws
Error- If length < 8 (EIP-4361 requirement)
Example
Character Set
Base62: 62 total characters- Digits:
0123456789(10 chars) - Uppercase:
ABCDEFGHIJKLMNOPQRSTUVWXYZ(26 chars) - Lowercase:
abcdefghijklmnopqrstuvwxyz(26 chars)
- URL-safe (no special characters)
- Case-sensitive
- Human-readable
- No ambiguous characters
Randomness
Browser Environment
Uses Web Crypto API:Node.js Environment
Uses Node crypto module:- Cryptographically secure PRNG
- Suitable for authentication tokens
- Platform-specific random source
Generation Algorithm
Modulo bias is negligible for 256 values mapped to 62 characters
Common Patterns
Message Creation
Server-Side Nonce Management
Batch Generation
Custom Length for Different Security Levels
Entropy Analysis
Bits of entropy = log2(62^length)| Length | Combinations | Bits of Entropy | Security Level |
|---|---|---|---|
| 8 | 62^8 | ~48 bits | Minimum (spec) |
| 11 | 62^11 | ~65 bits | Standard |
| 16 | 62^16 | ~95 bits | High |
| 22 | 62^22 | ~131 bits | Very High |
- 8 chars: Spec minimum, adequate for short-lived nonces with rate limiting
- 11 chars: Default, good balance of security and length
- 16+ chars: High-value authentication, long-lived sessions
Security Considerations
Nonce Requirements
- Uniqueness: Each nonce must be globally unique
- Randomness: Cryptographically secure random generation
- Single-Use: Consume after verification to prevent replay
- Expiration: Limit nonce lifetime (5-15 minutes recommended)
- Storage: Store server-side, verify on auth
Replay Attack Prevention
Rate Limiting
Performance
Time Complexity: O(n) where n = length Space Complexity: O(n) Typical Performance:- 11-char nonce: less than 0.1ms
- 100 nonces: less than 1ms
- Dominated by random number generation
- Pre-generate nonce pool for high throughput
- Batch generation more efficient than individual calls
- No allocation overhead (returns string)
Best Practices
- Default Length: Use default 11 chars unless specific needs
- Server-Side Generation: Generate on backend, send to frontend
- Store Metadata: Track creation time, expiration, usage
- Single Use: Invalidate after successful authentication
- Expiration: Set reasonable TTL (5-15 minutes)
- Rate Limit: Prevent nonce generation abuse
- Uniqueness Check: Verify nonce not already in use (optional for high security)
See Also
- Siwe.create - Create message with nonce
- Validation - Nonce validation rules
- Usage Patterns - Nonce management patterns
- EIP-4361 - Nonce requirements

