mirror of
https://github.com/privacy-scaling-explorations/zk-kit.git
synced 2026-04-22 03:00:15 -04:00
Former-commit-id: 6c06fca568c3755d497e4f946a4318f71637cc23 [formerly 4ecf79b73bd52f5d04d876f7198b8bac9fbb93da] [formerly 5876d74b7cea6aa7d21dfce2174697fcae65bf93 [formerly 09ea260b8d10914eb0e5ca7fad8bea8f810633de]] [formerly 3a1c8745c75f12cb842d4c16d767b9d3f2566305 [formerly 4a36e36f7254b6b9e167230f2c7f01e93a586efc] [formerly c53777cae645271b8dcb9909959c0699f4b4904f [formerly 26883cb3f2]]]
Former-commit-id: dd22c534142fb5f1ac5743fb526ff30b4f567c2d [formerly fc4709313eb01b1ec47ad73d84cfb571631da6f5] [formerly dd33337a37b31db21c3a2cfcd87f7f4ba952482a [formerly 999b84f2a77fb833187129c55629bbaecd81442d]]
Former-commit-id: bae50458ad904e789ad5a37a9792e10b31110f1f [formerly 3edec89cfc1d91889c26fdc88f5ef04d8e8a80d9]
Former-commit-id: 5c74ca4bd1e85b312d6fe074eea239c64b3ecdb1
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)