Try it Live
Run SIWE examples in the interactive playground
Parsing
Methods for converting between SIWE message objects and formatted strings.parse
Parse EIP-4361 formatted string to BrandedMessage object.Signature
Parameters
text- EIP-4361 formatted SIWE message string
Returns
BrandedMessage object with all parsed fields
Throws
Error- Missing domain headerError- Missing or invalid address (must be 40 hex chars with 0x)Error- Missing required fields (URI, Version, Chain ID, Nonce, Issued At)Error- Chain ID not a number
Format Specification
- Header:
{domain} wants you to sign in with your Ethereum account: - Address:
0x{40 hex chars} - Empty line
URI: {uri}Version: {version}Chain ID: {chainId}Nonce: {nonce}Issued At: {issuedAt}
- Statement (between address and URI, surrounded by empty lines)
- Expiration Time
- Not Before
- Request ID
- Resources (list with
-prefix)
Example
Parsing Rules
Address Conversion:- Expects hex string with 0x prefix
- Converts to 20-byte Uint8Array (AddressType)
- Validates 40 hex characters (case insensitive)
- All lines between address and field section
- Stops at first line containing
:or empty line before fields - Multi-line statements preserved with newlines
- Fields identified by
Key: Valueformat - Resources section starts with
Resources:line - Resources items prefixed with
-
- Only included if present in text
- Result object omits undefined fields
Common Patterns
Roundtrip Conversion
Verify Wallet-Signed Message
Parse and Verify Signature
format
Format BrandedMessage to EIP-4361 string for signing.Signature
Parameters
message- BrandedMessage to format
Returns
EIP-4361 formatted string ready for wallet signingExample
Formatting Rules
Address Formatting:- Converts 20-byte Uint8Array to hex string
- Lowercase with 0x prefix
- No EIP-55 checksum
- Domain header line
- Address (lowercase hex)
- Empty line
- Statement (if present)
- Empty line (if statement present)
- Required fields (URI, Version, Chain ID, Nonce, Issued At)
- Optional fields (Expiration Time, Not Before, Request ID)
- Resources (if present)
- Order matches EIP-4361 specification exactly
- Optional fields only included if defined
- Resources always last
Common Patterns
Prepare for Wallet Signing
Display to User
Instance Method
Implementation Notes
- Address bytes converted to lowercase hex
- Newlines between sections for readability
- Resources prefixed with
-per spec - No trailing newline
- UTF-8 text encoding
See Also
- Siwe.parse - Parse formatted string
- Message Format - EIP-4361 specification
- Siwe.getMessageHash - Hash formatted message
- Siwe.create - Create message

