Skip to main content

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 header
  • Error - 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

Required Lines:
  1. Header: {domain} wants you to sign in with your Ethereum account:
  2. Address: 0x{40 hex chars}
  3. Empty line
  4. URI: {uri}
  5. Version: {version}
  6. Chain ID: {chainId}
  7. Nonce: {nonce}
  8. Issued At: {issuedAt}
Optional:
  • 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)
Statement Handling:
  • All lines between address and field section
  • Stops at first line containing : or empty line before fields
  • Multi-line statements preserved with newlines
Field Parsing:
  • Fields identified by Key: Value format
  • Resources section starts with Resources: line
  • Resources items prefixed with -
Optional Fields:
  • 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 signing

Example

Formatting Rules

Address Formatting:
  • Converts 20-byte Uint8Array to hex string
  • Lowercase with 0x prefix
  • No EIP-55 checksum
Line Structure:
  1. Domain header line
  2. Address (lowercase hex)
  3. Empty line
  4. Statement (if present)
  5. Empty line (if statement present)
  6. Required fields (URI, Version, Chain ID, Nonce, Issued At)
  7. Optional fields (Expiration Time, Not Before, Request ID)
  8. Resources (if present)
Field Order:
  • 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