Skip to content

Latest commit

 

History

History
 
 

proof

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Semaphore proof

A library to generate and verify Semaphore proofs.

Github license NPM version Downloads 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. 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, 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)