GithubHelp home page GithubHelp logo

dvlprsh / rlnjs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rate-limiting-nullifier/rlnjs

0.0 0.0 0.0 72.15 MB

Client library for generating and using RLN ZK proofs

JavaScript 0.40% TypeScript 99.60%

rlnjs's Introduction

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.

rlnjs's People

Contributors

atheartengineer avatar dvlprsh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.