@webb-tools/semaphore-proof
v0.0.1-5
Published
A library to generate and verify Semaphore-anchor proofs.
Downloads
8
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 @webb-tools/semaphore-proof
package and its peer dependencies with npm:
npm i @webb-tools/semaphore-identity @webb-tools/semaphore-group @webb-tools/semaphore-proof
or yarn:
yarn add @webb-tools/semaphore-identity @webb-tools/semaphore-group @webb-tools/semaphore-proof
📜 Usage
# generateProof(identity: Identity, group: Group, externalNullifier: BigNumberish, signal: string, snarkArtifacts?: SnarkArtifacts): Promise<SemaphoreFullProof>
import { Identity } from "@webb-tools/semaphore-identity"
import { Group } from "@webb-tools/semaphore-group"
import { generateProof } from "@webb-tools/semaphore-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 "@webb-tools/semaphore-proof"
const verificationKey = JSON.parse(fs.readFileSync("/semaphore.json", "utf-8"))
await verifyProof(verificationKey, fullProof)
# packToSolidityProof(proof: Proof): SolidityProof
import { packToSolidityProof } from "@webb-tools/semaphore-proof"
const solidityProof = packToSolidityProof(fullProof.proof)
# generateNullifierHash(externalNullifier: BigNumberish, identityNullifier: BigNumberish): bigint
import { generateNullifierHash } from "@webb-tools/semaphore-proof"
const nullifierHash = generateNullifierHash(
externalNullifier,
identity.getNullifier()
)
# generateSignalHash(signal: string): bigint
import { generateSignalHash } from "@webb-tools/semaphore-proof"
const signalHash = generateSignalHash(signal)