Files
zk-kit/packages/protocols
cedoor 46aa315787 chore: set tsconfig paths for all zk-kit packages
Former-commit-id: 92f063bf3794f022233565633299610938e62e09 [formerly 9fb0532beafe80f1591bd9aa3b083dfd55469611] [formerly 3b14775151319fe357ebbe82a4931f85c15a3bbd [formerly 87dbdfb166]]
Former-commit-id: 28a49fe4119f800a610d6a1c0315baf31f598fe0 [formerly 346fea95b7b9f2d17c928a5019cbcfb664b0fdfc]
Former-commit-id: 65d03434f0522b0ef27ef74ef456099e4db9309a
2022-01-23 14:10:03 +01:00
..
2022-01-23 12:27:17 +01:00
2022-01-21 22:43:14 +01:00

ZK protocols

Client library for generating and verifying Semaphore & RLN ZK proofs.

Github license NPM version Downloads npm bundle size (scoped) Linter eslint Code style prettier


🛠 Install

npm or yarn

Install the @zk-kit/protocols package with npm:

npm i @zk-kit/protocols

or yarn:

yarn add @zk-kit/protocols

📜 Usage

Import

import { ZkIdentity, Identity } from "@zk-kit/identity"
import {
  Semaphore,
  MerkleProof,
  IProof,
  generateMerkleProof,
  genExternalNullifier,
  genSignalHash
} from "@zk-kit/protocols"
const { ZkIdentity } = require("@zk-kit/identity")
const { Semaphore, Rln, NRln, generateMerkleProof, genExternalNullifier, genSignalHash } = require("@zk-kit/protocols")

Merkle Proofs Generate merkle proof for your identity given the array of registered identity commitments

const identityCommitments: Array<bigint> = [...];
const identity: ZkIdentity = new ZkIdentity();
const identityCommitment: bigint = identity.genIdentityCommitment();

const merkleProof: MerkleProof = generateMerkleProof(TREE_DEPTH, ZERO_VALUE, NUMBER_OF_LEAVES_PER_NODE, identityCommitments, identityCommitment);

Semaphore

In order to create semaphore proof, make sure to

const witness = Semaphore.genWitness(identity, merkleProof, externalNullifier, signal)
const fullProof = await Semaphore.genProof(witness, wasmFilePath, finalZkeyPath)

📜 Final Note

For full examples of how to integrate with contracts check https://github.com/appliedzkp/semaphore repository.

For additional info check tests directory.