@pcd/semaphore-proof-v3
v3.15.2
Published
A library to generate and verify Semaphore proofs.
Downloads
2,921
Keywords
Readme
| 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 | MerkleProof, externalNullifier: BytesLike | Hexable | number | bigint, signal: BytesLike | Hexable | number | bigint, 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 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(semaphoreProof: SemaphoreProof, treeDepth: number): Promise<boolean>
import { verifyProof } from "@semaphore-protocol/proof"
await verifyProof(fullProof, 20)
# calculateNullifierHash( identityNullifier: bigint | number | string, externalNullifier: _BytesLike | Hexable | number | bigint ): bigint
import { Identity } from "@semaphore-protocol/identity"
import { calculateNullifierHash } from "@semaphore-protocol/proof"
const identity = new Identity()
const externalNullifier = utils.formatBytes32String("Topic")
const nullifierHash = calculateNullifierHash(identity.nullifier, externalNullifier)