Try it Live
Run SIWE examples in the interactive playground
Verification
Signature verification for SIWE messages.verify
Verify SIWE message signature matches claimed address.- Wrapper API
Signature
Parameters
message- BrandedMessage that was signedsignature- 65-byte signature (r + s + v)
Returns
true if signature valid and matches message.address
false if signature invalid or address mismatchSignature Format
- If v >= 27:
recoveryId = v - 27 - If v < 27:
recoveryId = v - Valid recovery IDs: 0 or 1
Process
- Validate Message: Check structure with
validate(message) - Get Hash: Compute EIP-191 hash with
getMessageHash(message) - Extract Components: Parse r, s, v from signature
- Normalize V: Convert v to recovery ID (0 or 1)
- Recover Public Key: Use secp256k1 recovery
- Derive Address: Keccak-256(publicKey)[12:32]
- Compare: Check recovered address === message.address
Example
Common Patterns
Backend Verification
Instance Method
With Validation
Error Cases
Returnsfalse for:
- Invalid message structure
- Signature length !== 65 bytes
- Invalid v value (not 0, 1, 27, or 28)
- Failed public key recovery
- Address mismatch
- Any exception during verification
Security Considerations
Constant-Time Comparison:- Address comparison loops through all 20 bytes
- Prevents timing attacks
- Accepts both raw (0, 1) and EIP-155 (27, 28) formats
- Rejects invalid v values
- Uses secp256k1 curve (same as Ethereum)
- Validates recovered point on curve
- Rejects invalid signatures
- Signature uniqueness enforced by secp256k1
- Low-s values recommended but not required
verifyMessage
Combined validation and signature verification.Signature
Parameters
message- BrandedMessage to verifysignature- 65-byte signatureoptions.now- Current time for timestamp checks
Returns
ValidationResult:
{ valid: true }- Structure valid AND signature verified{ valid: false, error: ValidationError }- Structure invalid OR signature mismatch
Process
- Validate Structure: Call
validate(message, options) - Return if Invalid: Early return with validation error
- Verify Signature: Call
verify(message, signature) - Return Result:
{ valid: true }or signature mismatch error
Example
Error Types
All validation errors plus:signature_mismatch- Signature does not match address or verification failed
Common Patterns
Complete Verification
With Timestamp Check
Complete Auth Flow
Advantages Over Separate Calls
Convenience:- Single function call for complete verification
- Structured error handling
- Consistent return type
- Early return on validation failure
- Skips expensive signature verification if structure invalid
- Ensures validation always happens first
- Prevents verification of malformed messages
Performance
Validation: O(1) - Fast structure checks Signature Verification: O(1) - secp256k1 recovery (expensive) Optimization: Always validates first to avoid wasting cycles on invalid messagesFactory API
Tree-shakeable factory pattern with explicit crypto dependencies.Verify Factory
keccak256: (data: Uint8Array) => Uint8Array- Keccak256 hash functionsecp256k1RecoverPublicKey: (sig: {r, s, v}, hash: Uint8Array) => Uint8Array- secp256k1 public key recoveryaddressFromPublicKey: (x: bigint, y: bigint) => Uint8Array- Address derivation from public key
VerifyMessage Factory
Verify.
Example:
GetMessageHash Factory
keccak256: (data: Uint8Array) => Uint8Array- Keccak256 hash function
See Also
- Siwe.validate - Message validation
- Siwe.getMessageHash - Hash generation
- Usage Patterns - Authentication flows
- EIP-191 - Signed data standard

