To avoid CI blocking other PR's CI: + https://github.com/vacp2p/zerokit/pull/337 + https://github.com/vacp2p/zerokit/pull/346 + https://github.com/vacp2p/zerokit/pull/349
RLN for WASM
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- for compiling Rust to WebAssemblycargo-make- for running build commandsnvm- to install and manage Node.jsEnsure all dependencies are installed before proceeding.
Manually
Install wasm-pack
cargo install wasm-pack --version=0.13.1
Install cargo-make
cargo install cargo-make
Install Node.js
If you don't have nvm (Node Version Manager), install it by following
the installation instructions.
After installing nvm, install and use Node.js v22.14.0:
nvm install 22.14.0
nvm use 22.14.0
nvm alias default 22.14.0
If you already have Node.js installed,
check your version with node -v command — the version must be strictly greater than 22.
Or install everything
You can run the following command from the root of the repository to install all required dependencies for zerokit
make installdeps
Building the library
First, navigate to the rln-wasm directory:
cd rln-wasm
Compile zerokit for wasm32-unknown-unknown:
cargo make build
Running tests and benchmarks
cargo make test
If you want to run the tests in browser headless mode, you can use the following command:
cargo make test_browser
Parallel computation
The library supports parallel computation using the wasm-bindgen-rayon crate,
enabling multi-threaded execution in the browser.
Note
Parallel support is not enabled by default due to WebAssembly and browser limitations.
Compiling this feature requiresnightlyRust.
Build Setup
Install nightly Rust
rustup install nightly-2025-09-24
Build Commands
To enable parallel computation for WebAssembly threads, you can use the following command:
cargo make build_parallel
WebAssembly Threading Support
Most modern browsers support WebAssembly threads,
but they require the following headers to enable SharedArrayBuffer, which is necessary for multithreading:
- Cross-Origin-Opener-Policy: same-origin
- Cross-Origin-Embedder-Policy: require-corp
Without these, the application will fall back to single-threaded mode.
Feature detection
If you're targeting older browser versions that didn't support WebAssembly threads yet, you'll likely want to create two builds - one with thread support and one without - and use feature detection to choose the right one on the JavaScript side.
You can use wasm-feature-detect library for this purpose. For example, your code might look like this:
import { threads } from 'wasm-feature-detect';
let wasmPkg;
if (await threads()) {
wasmPkg = await import('./pkg-with-threads/index.js');
await wasmPkg.default();
await wasmPkg.initThreadPool(navigator.hardwareConcurrency);
} else {
wasmPkg = await import('./pkg-without-threads/index.js');
await wasmPkg.default();
}
wasmPkg.nowCallAnyExportedFuncs();