@waku/zerokit-rln-wasm
v0.3.0
Published
[](https://badge.fury.io/js/@waku%2Fzerokit-rln-wasm) [](https://opensource.org/licenses/MIT) [, 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.0If 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 installdepsBuilding the library
First, navigate to the rln-wasm directory:
cd rln-wasmCompile zerokit for wasm32-unknown-unknown:
cargo make buildRunning tests and benchmarks
cargo make testIf you want to run the tests in browser headless mode, you can use the following command:
cargo make test_browserParallel 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 nightlyBuild Commands
To enable parallel computation for WebAssembly threads, you can use the following command:
cargo make build_parallelWebAssembly 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();