mirror of
https://github.com/semaphore-protocol/semaphore.git
synced 2026-04-28 03:00:41 -04:00
Semaphore proof
A library to generate and verify Semaphore proofs.
| 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 @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
# generateProof( identity: Identity, group: Group, message: BytesLike | Hexable | number | bigint, scope: BytesLike | Hexable | number | bigint, treeDepth: number, snarkArtifacts?: SnarkArtifacts ): Promise<SemaphoreProof>
import { Identity } from "@semaphore-protocol/identity"
import { Group } from "@semaphore-protocol/group"
import { generateProof } from "@semaphore-protocol/proof"
import { utils } from "ethers"
const identity = new Identity()
const group = new Group()
const scope = utils.formatBytes32String("Topic")
const message = utils.formatBytes32String("Hello world")
group.addMembers([...identityCommitments, identity.generateCommitment()])
const fullProof1 = await generateProof(identity, group, message, scope)
// You can also specify the maximum tree depth supported by the proof.
const fullProof2 = await generateProof(identity, group, message, scope, 20)
// You can also specify the default zkey/wasm files.
const fullProof3 = await generateProof(identity, group, message, scope, 20, {
wasmFilePath: "./semaphore.wasm",
zkeyFilePath: "./semaphore.zkey"
})
# verifyProof(semaphoreProof: SemaphoreProof, treeDepth: number): Promise<boolean>
import { verifyProof } from "@semaphore-protocol/proof"
await verifyProof(fullProof, 20)