TypeScript icon, indicating that this package has built-in type declarations

3.10.3 • Public • Published

Semaphore proof

A library to generate and verify Semaphore proofs.

Github license NPM version Downloads Documentation typedoc Linter eslint Code style prettier

This library provides utility functions to generate and verify Semaphore proofs compatible with the Semaphore circuits. Generating valid zero-knowledge proofs requires files that can only be obtained in an attested trusted-setup ceremony. For a complete list of ready-to-use files visit trusted-setup-pse.org.

🛠 Install

npm or yarn

Install the @cryptkeeperzk/semaphore-proof package and its peer dependencies with npm:

npm i @cryptkeeperzk/semaphore-identity@cryptkeeperzk/semaphore-group @cryptkeeperzk/semaphore-proof

or yarn:

yarn add @cryptkeeperzk/semaphore-identity@cryptkeeperzk/semaphore-group @cryptkeeperzk/semaphore-proof

📜 Usage

# generateProof( identity: Identity, group: Group | MerkleProof, externalNullifier: BytesLike | Hexable | number | bigint, signal: BytesLike | Hexable | number | bigint, snarkArtifacts?: SnarkArtifacts ): Promise<SemaphoreFullProof>

import { Identity } from "@cryptkeeperzk/semaphore-identity"
import { Group } from "@cryptkeeperzk/semaphore-group"
import { generateProof } from "@cryptkeeperzk/semaphore-proof"
import { utils } from "ethers"

const identity = new Identity()
const group = new Group()
const externalNullifier = utils.formatBytes32String("Topic")
const signal = utils.formatBytes32String("Hello world")

group.addMembers([...identityCommitments, identity.generateCommitment()])

const fullProof = await generateProof(identity, group, externalNullifier, signal, {
    zkeyFilePath: "./semaphore.zkey",
    wasmFilePath: "./semaphore.wasm"

// You can also use the default zkey/wasm files (it only works from browsers!).
// const fullProof = await generateProof(identity, group, externalNullifier, signal)

# verifyProof(fullProof: FullProof, treeDepth: number): Promise<boolean>

import { verifyProof } from "@cryptkeeperzk/semaphore-proof"

await verifyProof(fullProof, 20)

# calculateNullifierHash( identityNullifier: bigint | number | string, externalNullifier: _BytesLike | Hexable | number | bigint ): bigint

import { Identity } from "@cryptkeeperzk/semaphore-identity"
import { calculateNullifierHash } from "@cryptkeeperzk/semaphore-proof"

const identity = new Identity()
const externalNullifier = utils.formatBytes32String("Topic")

const nullifierHash = calculateNullifierHash(identity.nullifier, externalNullifier)




Package Sidebar


npm i @cryptkeeperzk/semaphore-proof

Weekly Downloads






Unpacked Size

150 kB

Total Files


Last publish


  • cryptkeeper-admin