@saurabhchalke/proof
TypeScript icon, indicating that this package has built-in type declarations

3.15.31 • Public • Published

Semaphore proof

A library to generate and verify Semaphore proofs.

Github license NPM version Downloads Documentation typedoc 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 @saurabhchalke/proof package and its peer dependencies with npm:

npm i @semaphore-protocol/identity @semaphore-protocol/group @saurabhchalke/proof

or yarn:

yarn add @semaphore-protocol/identity @semaphore-protocol/group @saurabhchalke/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 "@saurabhchalke/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 "@saurabhchalke/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 "@saurabhchalke/proof"

const identity = new Identity()
const externalNullifier = utils.formatBytes32String("Topic")

const nullifierHash = calculateNullifierHash(identity.nullifier, externalNullifier)

Readme

Keywords

none

Package Sidebar

Install

npm i @saurabhchalke/proof

Weekly Downloads

0

Version

3.15.31

License

MIT

Unpacked Size

1.41 MB

Total Files

28

Last publish

Collaborators

  • saurabhchalke