Skip to main content

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

Core Functions

format

Format SiweMessage to EIP-4361 string.

parse

Parse EIP-4361 string to SiweMessage.

validate

Validate message structure.

Performance

Benchmarks

Typical performance compared to JavaScript:
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

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

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