mirror of
https://github.com/privacy-scaling-explorations/zk-kit.git
synced 2026-04-22 03:00:15 -04:00
Former-commit-id: 53f73abf79b19877cba05bcd0331d1a64026a0cb [formerly 25ce2e73440d8a8eb3ce9c7435fb7d508bddd936] [formerly ff0d72b72fefb05290b9c2199e97bcf79fd2a1b6 [formerly e8abe3fabe]]
Former-commit-id: dce824c063df0129f5585bdc86e481b43d49c17a [formerly ed45af3315719b55a156387f38d80ead4b8931ef]
Former-commit-id: 03ab6f38dbbb0601f49b8eef48dae1fe1ead2eb2
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.