Skip to content

dvlprsh/rlnjs

 
 

Repository files navigation

Rate Limiting Nullifier Javascript / Typescript Library

Contents

Description

RLN (Rate-Limiting Nullifier) is a zk-gadget/protocol that enables spam prevention mechanism for anonymous environments. The core of the RLN is in the circuit logic. RLN also provides Javascript Library for easy management of the registry and proof creation.

Install

git clone https://github.com/Rate-Limiting-Nullifier/rlnjs.git

And install the dependencies:

cd rlnjs && npm i

Usage

Create RLNRegistry

// generate default RLN registry
const registry = new RLNRegistry()

// generate RLN registry that contains slashed registry
const registry = new RLNRegistry(
  20, 
  BigInt(0), 
  true
)

Generate identity commitment

const identity = new ZkIdentity()
const identityCommitment = identity.genIdentityCommitment()

Add members to registry

registry.addMember(identityCommitment)

Remove members from registry

registry.removeMember(identityCommitment)

Generating a proof

const secretHash = identity.getSecretHash()

const leaves = Object.assign([], identityCommitments)
leaves.push(identityCommitment)

const signal = "signal"
const epoch = genExternalNullifier("test-epoch")
const rlnIdentifier = RLN.genIdentifier()

const merkleProof = await generateMerkleProof(15, BigInt(0), leaves, identityCommitment)
const witness = RLN.genWitness(secretHash, merkleProof, epoch, signal, rlnIdentifier)
const fullProof = await RLN.genProof(witness, wasmFilePath, finalZkeyPath)

Verifying a proof

const proofResult = await RLN.verifyProof(vKey, fullProof)

Tests

npm test

License

RLNjs is released under the MIT license.

About

Client library for generating and using RLN ZK proofs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 99.6%
  • JavaScript 0.4%