Files

RLN for WASM

npm version License: MIT License: Apache 2.0

The Zerokit RLN WASM Module provides WebAssembly bindings for working with Rate-Limiting Nullifier RLN zkSNARK proofs and primitives. This module is used by waku-org/js-rln to enable RLN functionality in JavaScript/TypeScript applications.

Install Dependencies

Note

This project requires the following tools:

  • wasm-pack (v0.13.1) - for compiling Rust to WebAssembly
  • cargo-make - for running build commands
  • nvm - to install and manage Node.js (v22.14.0+)

Quick Install

make installdeps

Manual Installation

# Install wasm-pack
cargo install wasm-pack --version=0.13.1

# Install cargo-make
cargo install cargo-make

# Install Node.js via nvm
nvm install 22.14.0
nvm use 22.14.0
nvm alias default 22.14.0

Building the Library

Navigate to the rln-wasm directory:

cd rln-wasm

Build commands:

cargo make build          # Default → @waku/zerokit-rln-wasm
cargo make build_parallel # Parallel → @waku/zerokit-rln-wasm-parallel (requires nightly Rust)
cargo make build_utils    # Utils only → @waku/zerokit-rln-wasm-utils

All packages output to pkg/ directory.

Running Tests and Benchmarks

cargo make test           # Standard tests
cargo make test_browser   # Browser headless mode
cargo make test_utils     # Utils-only tests
cargo make test_parallel  # Parallel tests

Examples

See Node example and README for proof generation, verification, and slashing.

Parallel Computation

Enables multi-threaded browser execution using wasm-bindgen-rayon.

Note

  • Parallel support is not enabled by default due to WebAssembly and browser limitations.
  • Requires nightly Rust: rustup install nightly
  • Browser-only (not compatible with Node.js)
  • Requires HTTP headers for SharedArrayBuffer:
    • Cross-Origin-Opener-Policy: same-origin
    • Cross-Origin-Embedder-Policy: require-corp

Usage

Direct usage (modern browsers with WebAssembly threads support):

import * as wasmPkg from '@waku/zerokit-rln-wasm-parallel';

await wasmPkg.default();
await wasmPkg.initThreadPool(navigator.hardwareConcurrency);
wasmPkg.nowCallAnyExportedFuncs();

Feature Detection for Older Browsers

If you're targeting older browser versions that didn't support WebAssembly threads yet, you'll want to use both builds - the parallel version for modern browsers and the default version as a fallback. Use feature detection to choose the appropriate build on the JavaScript side.

You can use the wasm-feature-detect library for this purpose:

import { threads } from 'wasm-feature-detect';

let wasmPkg;

if (await threads()) {
  wasmPkg = await import('@waku/zerokit-rln-wasm-parallel');
  await wasmPkg.default();
  await wasmPkg.initThreadPool(navigator.hardwareConcurrency);
} else {
  wasmPkg = await import('@waku/zerokit-rln-wasm');
  await wasmPkg.default();
}

wasmPkg.nowCallAnyExportedFuncs();