Options
All
  • Public
  • Public/Protected
  • All
Menu

@semaphore-protocol/proof

Semaphore proof

A library to generate and verify Semaphore proofs.

Github license NPM version Downloads Linter eslint Code style prettier

🗣️ Chat & Support   |   📘 Docs

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 with npm:

npm i @semaphore-protocol/proof

or yarn:

yarn add @semaphore-protocol/proof

📜 Usage

# generateProof(identity: Identity, group: Group, externalNullifier: BigNumberish, signal: string, snarkArtifacts?: SnarkArtifacts): Promise<_SemaphoreFullProof_>

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

const identity = new Identity()
const group = new Group()
const externalNullifier = BigInt(1)
const signal = "Hello world"

group.addMembers([...identityCommitments, identity.generateCommitment()])

const fullProof = await generateProof(identity, merkleProof, externalNullifier, signal, {
zkeyFilePath: "./semaphore.zkey",
wasmFilePath: "./semaphore.wasm"
})

// You can also use the default zkey/wasm files (only for browsers!).
// const fullProof = await generateProof(identity, merkleProof, externalNullifier, signal)

# verifyProof(verificationKey: any, fullProof: FullProof): Promise<_boolean_>

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

const verificationKey = JSON.parse(fs.readFileSync("/semaphore.json", "utf-8"))

await verifyProof(verificationKey, fullProof)

# packToSolidityProof(proof: Proof): SolidityProof

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

const solidityProof = packToSolidityProof(fullProof.proof)

# generateNullifierHash(externalNullifier: BigNumberish, identityNullifier: BigNumberish): bigint

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

const nullifierHash = generateNullifierHash(externalNullifier, identity.getNullifier())

# generateSignalHash(signal: string): bigint

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

const signalHash = generateSignalHash(signal)

Generated using TypeDoc