Skip to content

Latest commit

 

History

History

proof

Semaphore proof

A library to generate and verify Semaphore proofs.

NPM 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.

🛠 Install

npm or yarn

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

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

or yarn:

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

📜 Usage

For more information on the functions provided by @semaphore-protocol/proof, please refer to the TypeDoc documentation.

# generateProof( identity: Identity, group: Group, message: BigNumberish | Uint8Array | string, scope: BigNumberish | Uint8Array | string, merkleTreeDepth: number, snarkArtifacts?: SnarkArtifacts ): Promise<SemaphoreProof>

import { Identity } from "@semaphore-protocol/identity"
import { Group } from "@semaphore-protocol/group"
import { generateProof } from "@semaphore-protocol/proof"

const identity1 = new Identity()
const identity2 = new Identity()
const identity3 = new Identity()

const group = new Group([identity1.commitment, identity2.commitment, identity3.commitment])

const message = "Hello world"
const scope = "Semaphore"

// snarkArtifacts are not provided.
// So they will be automatically downloaded (see https://github.com/privacy-scaling-explorations/snark-artifacts).
const proof1 = await generateProof(identity1, group, message, scope)

// You can also specify the maximum tree depth supported by the proof.
const proof2 = await generateProof(identity2, group, message, scope, 20)

// You can also override our default zkey/wasm files.
const proof3 = await generateProof(identity3, group, message, scope, 20, {
    wasm: "./semaphore.wasm",
    zkey: "./semaphore.zkey"
})

# verifyProof(semaphoreProof: SemaphoreProof): Promise<boolean>

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

await verifyProof(proof1)