Files
zk-kit/packages/protocols
Nasi Jofce d694534801 fix(incremental-merkle-tree): merkle tree supports zero leaves. Merkle proof fails for zero value
The incremental-merkle-tree can be constructed with any value, including zeros. The generation of
merkle proof will fail for zero value.


Former-commit-id: 9786bd018d1a1d118b25211b81bc130ce73dd72d [formerly 6bcb273b46528f9598d63e741b623e431f550279] [formerly fc6b6316f431a40fd5d3227984ee10ed9ae91512 [formerly 76fa7474e1bf580b65ef1ebf5cc2f3bc9a298fcf]] [formerly 1239a3573218f05bd7874fc93f307e912e256782 [formerly 7e2d839ace7e3b5ad9b8955bc8342e302cb17c21] [formerly e884bd5e471842ead2c6769e9c67b97f2dc7f9da [formerly d001f11730]]]
Former-commit-id: 4ca0db7c48be9f11a18219052fc18942669a31ba [formerly add55bb929f06f818db1b65382900c7005c3215f] [formerly 5576da9d8efcb2c5c1b8c198beeaf11e389c7d09 [formerly 8d92106155c937cf77d542f362cca882fb2560c7]]
Former-commit-id: 58e8a5c36bc1667d071b9e35e39a118bf2c9bec2 [formerly d822513d2e092cbc1ee293cfaae283abc15b94b6]
Former-commit-id: 76048b82db6f9d220622cf7b388ff5039247c817
2022-02-21 12:53:03 +01:00
..
2022-02-09 19:01:38 +01:00

ZK protocols

Client library for generating and verifying Semaphore & RLN ZK proofs.

Github license NPM version Downloads Linter eslint Code style prettier


🛠 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)