Files
zk-kit/packages/protocols
cedoor 18dda5ce20 chore(protocols): v1.2.0
Former-commit-id: 44d2d9ec2a51a0a0e57551632323b73c20d931f0 [formerly 025efb20760397eaf2a8d1c1a4edc7a47dd609ff] [formerly f26951bedf07fb3017a4356931128b526edae170 [formerly 6895e32b3f]]
Former-commit-id: 4106b2be7f4a542b8c28b2762df0b44febee295a [formerly 1c03eecff2516b9bf19bd41ce23b75eec97b1a0f]
Former-commit-id: d685729e25ba753403751a3558bea20372811b99
2022-01-23 12:27:17 +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.