Files
semaphore/packages/proof
Jake C-T 13a9480165 fix(core): bump ethers to v6.13.4 (#921)
Update ethers version to resolve ws security issue (CVE-2024-37890).
Move contract address check outside of branch statement so Typescript can see.
Add build instructions to setup to resolve 'Cannot find module '@semaphore-protocol/...' when
running tests for the first time.

re #920
2024-12-12 08:53:17 +00:00
..
2024-02-10 15:26:06 +00:00

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)