Skip to main content
Version: next

Class: WebProver

provers/web.WebProver

The circuits package includes a browser compatible prover. This prover loads the proving keys from a remote URL. By default this url is https://keys.unirep.io/${version}/.

The server is expected to serve the zkey, wasm, and vkey files at their respective names in the provided subpath. e.g. for the above url the signup zkey is at https://keys.unirep.io/${version}/signup.zkey`. @param serverUrl The server url to the zkey, wasm, and vkey files. Default: https://keys.unirep.io/${version}/

Note

caution

The keys included are not safe for production use. A phase 2 trusted setup needs to be done before use.

Example

Default key server

import { Circuit } from '@unirep/circuits'
import prover from '@unirep/circuits/provers/web'

await prover.genProofAndPublicSignals(Circuit.signup, {
// circuit inputs
})

Custom key server

import { Circuit } from '@unirep/circuits'
import { WebProver } from '@unirep/circuits/provers/web'

// For a local key server
const prover = new WebProver('http://localhost:8000/keys/')
await prover.genProofAndPublicSignals(Circuit.signup, {
// circuit inputs
})

Constructors

constructor

new WebProver(serverUrl?)

Parameters

NameTypeDefault value
serverUrlstringKEY_URL

Defined in

circuits/provers/web.ts:49

Properties

cache

cache: Object = {}

Index signature

[key: string]: any

Defined in

circuits/provers/web.ts:46


url

url: string

Defined in

circuits/provers/web.ts:47

Methods

genProofAndPublicSignals

genProofAndPublicSignals(circuitName, inputs): Promise<{ proof: Groth16Proof ; publicSignals: PublicSignals }>

Generate proof and public signals with snarkjs.groth16.fullProve

Parameters

NameTypeDescription
circuitNamestring
inputsanyName of the circuit, which can be chosen from Circuit

Returns

Promise<{ proof: Groth16Proof ; publicSignals: PublicSignals }>

Snark proof and public signals

Defined in

circuits/provers/web.ts:112


getKey

getKey(circuitUrl): Promise<any>

Get key object from the server.

Parameters

NameTypeDescription
circuitUrlstringThe url to the a vkey, a zkeys or a wasm.

Returns

Promise<any>

The vkey, the zkeys or the wasm object.

Defined in

circuits/provers/web.ts:58


getVKey

getVKey(circuitName): Promise<any>

Get vkey from a remote URL.

Parameters

NameTypeDescription
circuitNamestringName of the circuit, which can be chosen from Circuit

Returns

Promise<any>

vkey of the circuit

Defined in

circuits/provers/web.ts:134


verifyProof

verifyProof(circuitName, publicSignals, proof): Promise<boolean>

The function returns true if the proof of the circuit is valid, false otherwise.

Parameters

NameTypeDescription
circuitNamestringName of the circuit, which can be chosen from Circuit
publicSignalsPublicSignalsThe snark public signals that are generated from genProofAndPublicSignals
proofGroth16ProofThe snark proof that is generated from genProofAndPublicSignals

Returns

Promise<boolean>

True if the proof is valid, false otherwise

Defined in

circuits/provers/web.ts:89


warmKeys

warmKeys(circuitName): Promise<void>

Load proving keys for a circuit into memory. Future proofs using these keys will not need to wait for download.

tip

Use this function without await to start the download in the background.

Parameters

NameTypeDescription
circuitNamestringName of the circuit, which can be chosen from Circuit

Returns

Promise<void>

Example

await webProver.warmKeys(circuitName: string)

Defined in

circuits/provers/web.ts:76