mirror of
https://github.com/privacy-scaling-explorations/zk-kit.git
synced 2026-04-22 03:00:15 -04:00
Former-commit-id: 8744e4cb1875edbfa65c8d4ce9a592ce18c61a07 [formerly f3b164ca20b63a7d359eca08ad68d98fbfd116a0] [formerly 2ced3501b269c95f82b491ea9535eec0c61867c8 [formerly 74bfdf6a7d3332dc650586164c036840e9c4748d]] [formerly 38029c5714398bf72239d611040a9908c59fcd2e [formerly 3d6a8f23405fbe5b23369248271f08979d693b4d] [formerly e6a3370951eb4a9d1eb0b6c41f0db050e9bec5d9 [formerly 9e9a50cd8d]]]
Former-commit-id: 49932a36672bde15e10328a047d790b70961ad4e [formerly 864056d1300f8b8e17a8dbf310bf682905e06968] [formerly 5183ab34cb646b8910d481bb80cc490b3559e85f [formerly 2eaf83d032dfaf4236ea9608f560fbb38aab02d3]]
Former-commit-id: bab484bb15cba767155e0323008cdbdffbd85ff1 [formerly f0ef8068d84b2586e291bf38b8880fec2beb55d7]
Former-commit-id: ca6bdf79a9bf8d3aaaca7d783fabaca3214aedd7
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
Generating Merkle proofs
import { ZkIdentity } from "@zk-kit/identity"
import { generateMerkleProof } from "@zk-kit/protocols"
const depth = 20
const zeroValue= BigInt(0)
const arity = 5
const identity = new ZkIdentity();
const identityCommitment = identity.genIdentityCommitment();
const identityCommitments = [BigInt(1), identityCommitment, BigInt(2)];
const merkleProof = generateMerkleProof(depth, zeroValue, arity, identityCommitments, 1);
Creating Semaphore proofs
import { Semaphore } from "@zk-kit/protocols"
const signal = "Hello world"
const externalNullifier = BigInt(1)
const witness = Semaphore.genWitness(identity, merkleProof, externalNullifier, signal)
const fullProof = await Semaphore.genProof(witness, "./semaphore.wasm", "./semaphore.zkey")
const solidityProof = Semaphore.packToSolidityProof(fullProof)