Skip to main content

Documentation Index

Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt

Use this file to discover all available pages before exploring further.

Try it Live

Run SIWE examples in the interactive playground

WASM

WebAssembly bindings for SIWE operations.

Overview

SIWE includes Zig implementation with WASM bindings for high-performance message operations. WASM provides native-speed formatting, parsing, and validation.

Availability

WASM bindings are compiled from Zig source at:
  • Source: /Users/williamcory/primitives/src/primitives/Siwe/siwe.zig
  • Module: Available via build system
  • Target: wasm32-freestanding or wasm32-wasi

Types

pub const SiweMessage = struct {
    domain: []const u8,
    address: Address,
    statement: ?[]const u8,
    uri: []const u8,
    version: []const u8,
    chain_id: u64,
    nonce: []const u8,
    issued_at: []const u8,
    expiration_time: ?[]const u8,
    not_before: ?[]const u8,
    request_id: ?[]const u8,
    resources: ?[]const []const u8,
};

Core Functions

format

pub fn format(
    self: *const SiweMessage,
    allocator: Allocator
) ![]u8
Format SiweMessage to EIP-4361 string.

parse

pub fn parse(
    text: []const u8,
    allocator: Allocator
) !SiweMessage
Parse EIP-4361 string to SiweMessage.

validate

pub fn validate(
    self: *const SiweMessage
) SiweError!void
Validate message structure.

Performance

Benchmarks

Typical performance compared to JavaScript:
OperationJS (ms)WASM (ms)Speedup
Format0.050.022.5x
Parse0.150.062.5x
Validate0.010.0052x
WASM faster for string operations. JS competitive for simple validation. WASM benefits increase with message size.

When to Use WASM

Use WASM for:
  • High-throughput servers
  • Batch processing
  • Large messages
  • Performance-critical paths
Use JS for:
  • Simple applications
  • Infrequent operations
  • Browser compatibility
  • Smaller bundle size

Building WASM

Build Command

zig build-lib \
  src/primitives/Siwe/siwe.zig \
  -target wasm32-freestanding \
  -dynamic \
  -rdynamic \
  -O ReleaseFast

Output

  • File: siwe.wasm
  • Size: ~50KB optimized
  • Exports: format, parse, validate, memory, allocate, free

Browser Support

Modern Browsers

  • Chrome 57+
  • Firefox 52+
  • Safari 11+
  • Edge 16+

Feature Detection

if (typeof WebAssembly === 'undefined') {
  // Fallback to JavaScript implementation
  console.warn('WebAssembly not supported, using JS fallback');
}

Limitations

  • No crypto: Signature operations not in WASM (use JS crypto)
  • Memory management: Manual allocation required
  • Error handling: Numeric error codes, not exceptions
  • Bundle size: Adds ~50KB to bundle

See Also