mirror of
https://github.com/privacy-scaling-explorations/zk-kit.git
synced 2026-04-22 03:00:15 -04:00
Former-commit-id: 13deac1d450892fb63398954f42693635d64ccef [formerly bd1e305b1e5920d82b4996fce71c6011122e23e1] [formerly f6d7d7d5cfac68c7678e61a27f8e01a4b39a60e4 [formerly ed3d514f79]]
Former-commit-id: 929f716bc58c9b915d6e33ec1c742503831512e1 [formerly cf8817b33ddd7332f66dd620c46c576feed73cad]
Former-commit-id: 7860cab6b078dbdf9cf75bc851d466ebdbb22d70
ZK protocols
Client library for generating and verifying Semaphore & RLN ZK proofs.
🛠 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.