mirror of
https://github.com/privacy-scaling-explorations/zk-kit.git
synced 2026-04-22 03:00:15 -04:00
Former-commit-id: d685e8d32516693622e26cced51db5789b3c54e4 [formerly 8a2d89b7f73b5add7a2689c2a4a58cfb17425b39] [formerly 28dfb96e63f6e4ef61dcf37441195a6dac0efc94 [formerly 972ab53a02a591a5396fbb50616a74294b85c862]] [formerly c6e51757f5058062cfa4431eff9dc8f2bbcbf57d [formerly 15b32e8f7e50ef01408f5856a93fd4550a2c2f99] [formerly d22a2b5c39b262966c93b0a727175ba08c40a0af [formerly f8e80a45fb]]]
Former-commit-id: 53b4ae9caeb7ad612fcc01402fcbf01a165e5204 [formerly df988a661881fee50a8e6150e4b25838608e0921] [formerly 7a17047355a14d786f8734b3c6d99038c8e8985c [formerly 891f9c7752349630d94013996a5a52173051cee4]]
Former-commit-id: bf57ac77219a074fcfe2f0dc974ce3386c2257e9 [formerly 4da602390292601a095891f384c6b3f7e57173a9]
Former-commit-id: 52abad658706329063b5a5294449e532cc1e0f0f
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.