Try it Live
Run SIWE examples in the interactive playground
BrandedSiwe
Branded type for SIWE messages with type safety.Overview
BrandedMessage provides type-safe SIWE message representation using TypeScript’s structural typing. All SIWE operations work with BrandedMessage type.Type Definition
Generic Parameters
TDomain
- Type:
stringliteral type - Default:
string - Purpose: Exact domain typing
- Example:
"example.com"vsstring
TAddress
- Type:
AddressType - Default:
AddressType - Purpose: Type-safe Ethereum address (20 bytes)
TUri
- Type:
stringliteral type - Default:
string - Purpose: Exact URI typing
- Example:
"https://example.com"vsstring
TVersion
- Type:
stringliteral type - Default:
string - Purpose: Version typing (always “1” currently)
TChainId
- Type:
numberliteral type - Default:
number - Purpose: Exact chain ID typing
- Example:
1vsnumber
Field Types
Required Fields
Optional Fields
Type Examples
Basic Usage
Literal Type Preservation
With Optional Fields
Type-Safe Functions
Namespace Pattern
BrandedSiwe follows namespace pattern for tree-shakeable methods:Usage
Type Guards
Runtime Type Checking
Validation Type Guard
Related Types
Signature
ValidationResult
ValidationError
Type Safety Benefits
Compile-Time Checks
Inference
Optional Field Handling
Pattern Details
Data-Based Architecture
All Siwe code follows data-based pattern:- Data: TypeScript interfaces (BrandedMessage)
- Methods: Namespace functions operating on data
- No classes: Functions take data as first argument
Tree-Shakeable
Individual functions can be imported:Type Conventions
BrandedMessage- Message typeSignature- Signature typeValidationResult- Result typeValidationError- Error type
Branded* or *Result naming.
Implementation Notes
- Plain objects: No class instantiation overhead
- Immutable operations: Functions don’t mutate inputs
- Type-safe: Full TypeScript type checking
- Serializable: JSON-compatible data structures
- No brand field: Uses structural typing, no runtime brand
See Also
- AddressType - Address type
- Siwe.create - Create messages
- Message Format - Field specifications

