- separated all identity generation functions as separate functions, rather than RLN methods - added BE support - only for these functions so far - covered the functions with tests, as well as conversion to big endian - prepared for publication, but is actually awaiting the initial publication of the RLN module @vinhtc27, please check that everything is correct from the wasm point of view. This module does not require parallel computing, so if there are any unnecessary dependencies, builds, etc., please let me know. --------- Co-authored-by: vinhtc27 <vinhtc27@gmail.com>
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 and thewasm-bindgen-clitool.
Build Setup
Install nightly Rust
rustup install nightly
Install wasm-bindgen-cli
cargo install wasm-bindgen-cli --version=0.2.100
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();