Try it Live
Run SIWE examples in the interactive playground
Validation
Message structure and timestamp validation.validate
Validate SIWE message structure and timestamps.Signature
Parameters
message- BrandedMessage to validateoptions.now- Current time for timestamp checks (defaults tonew Date())
Returns
Success:{ valid: true }
Failure: { valid: false, error: ValidationError }
ValidationError types:
invalid_domain- Domain empty or missinginvalid_address- Address not 20-byte Uint8Arrayinvalid_uri- URI missinginvalid_version- Version not “1”invalid_chain_id- Chain ID not positive integerinvalid_nonce- Nonce less than 8 charactersinvalid_timestamp- Timestamp not valid ISO 8601expired- Current time >= expirationTimenot_yet_valid- Current time < notBefore
Validation Rules
Domain:- Must be non-empty string
- RFC 4501 dns authority format
- Must be Uint8Array instance
- Exactly 20 bytes length
- Valid Ethereum address format
- Must be non-empty string
- RFC 3986 URI format
- Must be exactly “1”
- No other versions supported
- Must be positive integer (>= 1)
- EIP-155 chain identifier
- Minimum 8 characters
- Prevents replay attacks
- Must be valid ISO 8601 format
- Parsed with
new Date() - Checked against
options.nowor current time
- If
expirationTimepresent:now < expirationTime - Returns
expirederror if past
- If
notBeforepresent:now >= notBefore - Returns
not_yet_validerror if too early
Example
Error Handling
Timestamp Validation
Check Expiration
Check Not Before
Session Validation
Common Patterns
Pre-Verification Validation
Instance Method
Backend Validation
Clock Skew Handling
Validation Details
Domain Validation:- Checks non-empty, non-whitespace
- Does not validate DNS format (caller responsibility)
- Runtime type check:
instanceof Uint8Array - Length check:
length === 20 - Does not validate checksum
- Checks non-empty
- Does not validate RFC 3986 syntax (caller responsibility)
- Strict equality:
version === "1" - No version coercion
Number.isInteger(chainId)chainId >= 1- Rejects floats, negative, zero
nonce.length >= 8- Does not validate character set
- Server must verify uniqueness
- ISO 8601 format via
new Date() - Checks
isNaN(date.getTime()) - Time comparisons use
>=and<
Performance
- O(1) complexity
- No crypto operations
- Fast structure checks
- Ideal for pre-filtering before expensive verification
See Also
- Siwe.verifyMessage - Combined validation and verification
- Siwe.verify - Signature verification
- Message Format - Field specifications
- Usage Patterns - Best practices

