Skip to main content

WASM

Voltaire compiles to WebAssembly for browser and non-Bun JavaScript runtimes.
Runtime support: In Node.js, use the regular TypeScript API or WASM. Native FFI is currently Bun-only.

Build Modes

ReleaseSmall (Default)

Size-optimized for production bundles:
  • Output: wasm/primitives.wasm (~385KB)
  • Optimized for bundle size
  • Suitable for browser deployment

ReleaseFast

Performance-optimized for benchmarking:
  • Output: wasm/primitives-fast.wasm (~500KB)
  • Maximum performance
  • Use for performance-critical applications

Individual Crypto Modules

Tree-shakeable individual modules:
Output in wasm/crypto/:
  • keccak256.wasm (~50KB)
  • secp256k1.wasm (~80KB)
  • blake2.wasm (~40KB)
  • ripemd160.wasm (~30KB)
  • bn254.wasm (~100KB)

WASM Loader

The loader handles instantiation, memory management, and error translation.

Location

Usage

Automatic Loading

Most functions auto-load WASM on first use:

Memory Management

How It Works

  1. TypeScript passes data to WASM memory
  2. WASM processes in its linear memory
  3. Results copied back to JavaScript

Memory Limits

Default WASM memory: 256 pages (16MB) For large operations, memory grows automatically:

Platform Detection

The library automatically selects the best implementation:

Forcing WASM

Limitations

KZG Not Supported

KZG operations require the trusted setup and are too large for WASM:
For KZG in browsers, use a server-side proxy or the c-kzg-4844 JS library.

No Assembly Optimization

WASM can’t use platform-specific assembly. Rust crypto uses portable feature:
Performance difference:
  • Native (asm): ~500ns per Keccak256
  • WASM: ~2μs per Keccak256

Browser Integration

Bundler Setup

Vite

Webpack

CDN Usage

Testing WASM

Separate Test Files

Running WASM Tests

Cross-Validation

Bundle Size Analysis

Output in BUNDLE-SIZES.md:

Performance Comparison

Typical results:

Troubleshooting

WASM Not Loading

Memory Errors

Build Issues