mirror of
https://github.com/privacy-scaling-explorations/zk-kit.git
synced 2026-04-22 03:00:15 -04:00
Former-commit-id: 597a6ad3b701d49f34ebc8a1422c348d164422a6 [formerly b5c3220c433a7458236f6e75c9ae7e79147990df] [formerly 0229594563ae27a3357bc519977748ecab6a8515 [formerly 0ea41345a69e5035856bfff8559369c3dbc35505]] [formerly 493d28d1350920cf9103d180b4347b792b350536 [formerly 8a8efd70788c637c5e70db77226e6363650a00fc] [formerly 8ec91ae4eff216ad8df9ca89ed0323969f43beaf [formerly 18c613d17c]]]
Former-commit-id: 172a10c0e336ffc826bd449ed8edaf9df3ec91b7 [formerly 33df535b3de1046c7bba04f6ace4084c39534312] [formerly 29c1e444a4d1450c21ef09da0318d51b907a5cf4 [formerly 3de852281d263af7bd1b752b0ed12e339cc1c117]]
Former-commit-id: 0fa3fba9e3bcbf918da68e8be125b8a6e19890e6 [formerly 12954c3906b1aca68d93385f312479dd01dcca80]
Former-commit-id: 7e1d098504573e41b8a5aed56a158686ac5af25b
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 = 2
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)