@cryptkeeperzk/semaphore-proof
v3.10.3
Published
A library to generate and verify Semaphore proofs.
Downloads
5
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 @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)