Prover
The Prover handles ZK proof generation for transfers and unshields.
createProver
Create a new prover instance.
typescript
import { createProver } from '@zkprivacy/sdk';
const prover = await createProver(config: ProverConfig): Promise<Prover>ProverConfig
| Property | Type | Required | Description |
|---|---|---|---|
transferCircuit | CircuitSource | Yes | Transfer circuit JSON |
unshieldCircuit | CircuitSource | Yes | Unshield circuit JSON |
CircuitSource
Can be:
string- URL to fetch the circuit JSONobject- Already-parsed circuit JSON
Examples
typescript
// Browser: fetch from URLs
const prover = await createProver({
transferCircuit: '/circuits/transfer.json',
unshieldCircuit: '/circuits/unshield.json',
});
// Node.js: pass parsed JSON
import { readFileSync } from 'fs';
const prover = await createProver({
transferCircuit: JSON.parse(readFileSync('circuits/transfer.json', 'utf-8')),
unshieldCircuit: JSON.parse(readFileSync('circuits/unshield.json', 'utf-8')),
});setGlobalProver
Set the global prover instance used by PrivacyClient.
typescript
import { setGlobalProver } from '@zkprivacy/sdk';
setGlobalProver(prover: Prover): voidExample
typescript
const prover = await createProver({ ... });
setGlobalProver(prover);
// PrivacyClient will use this prover automatically
const client = new PrivacyClient({ ... });Prover Class
isReady
Check if prover is initialized.
typescript
prover.isReady(): booleangenerateTransferProof
Generate a proof for a transfer.
typescript
await prover.generateTransferProof(params: TransferParams): Promise<ProofResult>INFO
You typically don't call this directly. Use client.transfer() instead.
generateUnshieldProof
Generate a proof for an unshield.
typescript
await prover.generateUnshieldProof(params: UnshieldParams): Promise<ProofResult>Types
ProofResult
typescript
interface ProofResult {
proof: Uint8Array;
publicInputs: bigint[];
}TransferParams
typescript
interface TransferParams {
// Input notes
inputs: {
note: Note;
leafIndex: number;
siblings: bigint[][];
}[];
// Output notes
outputs: {
npk: bigint;
amount: bigint;
random: bigint;
}[];
// Keys
spendingKey: bigint;
nullifyingKey: bigint;
// Merkle root
merkleRoot: bigint;
// Token
tokenId: bigint;
}Performance
| Circuit | Browser | Node.js |
|---|---|---|
| Transfer | 30-60s | 15-30s |
| Unshield | 20-40s | 10-20s |
Optimization Tips
- Reuse prover instance - Don't recreate for each proof
- Initialize early - Load prover at app startup
- Show progress - 30-60s is a long wait for users
- Consider relayer - Offload proving to server if needed
Circuit Files
Circuit files are ~500KB each and contain:
json
{
"noir_version": "1.0.0-beta.17",
"hash": 12345678,
"abi": { ... },
"bytecode": "H4sIAAAA..."
}Host them on your server or CDN. The SDK fetches them once and caches.