mirror of
https://github.com/logos-messaging/js-rln.git
synced 2026-01-02 13:43:06 +00:00
js-rln
Browser library providing the cryptographic functions for Waku RLN Relay https://rfc.vac.dev/spec/17/
Install
npm install @waku/rln
# or with yarn
yarn add @waku/rln
Usage
Initializing the library
import * as rln from "@waku/rln";
const rlnInstance = wait rln.create();
Generating RLN membership keypair
let memKeys = rlnInstance.generateMembershipKey();
Adding membership keys into merkle tree
rlnInstance.inserMember(memKeys.IDCommitment);
Generating a proof
// prepare the message
const uint8Msg = Uint8Array.from("Hello World".split("").map(x => x.charCodeAt()));
// setting up the epoch (With 0s for the test)
const epoch = new Uint8Array(32);
// generating a proof
const proof = await rlnInstance.generateProof(uint8Msg, index, epoch, memKeys.IDKey)
Verifying a proof
try {
// verify the proof
const verifResult = rlnInstance.verifyProof(proof);
console.log("Is proof verified?", verifResult ? "yes" : "no");
} catch (err) {
console.log("Invalid proof")
}
Updating circuit, verification key and zkey
The RLN specs defines the defaults. These values are fixed and should not
change. If they do, this file needs to be updated in resources.ts which
contains these values encoded in base64 in this format:
const verification_key = "...";
const circuit = "..."; // wasm file generated by circom
const zkey = "...";
export {verification_key, circuit, zkey};
A tool like GNU's base64 could be used to encode this data
Updating zerokit
- Make sure you have nodejs installed and a C compiler
- Install wasm-pack
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
- Compile RLN for wasm
git clone https://github.com/vacp2p/zerokit
cd zerokit/rln-wasm
wasm-pack build --release
- Copy
pkg/rln*intosrc/zerokit
Bugs, Questions & Features
If you encounter any bug or would like to propose new features, feel free to open an issue.
For more general discussion, help and latest news, join Vac Discord or Telegram.
License
Licensed and distributed under either of
- MIT license: LICENSE-MIT or http://opensource.org/licenses/MIT
or
- Apache License, Version 2.0, (LICENSE-APACHEv2 or http://www.apache.org/licenses/LICENSE-2.0)
at your option. These files may not be copied, modified, or distributed except according to those terms.
Description
Browser library providing the cryptographic functions for Waku RLN Relay https://rfc.vac.dev/spec/17/
Languages
TypeScript
77.1%
JavaScript
22.6%
HTML
0.3%