zk402-prover
Client-side proof generation for zk402 payments.
Overview
This crate provides the client-side functionality for generating zero-knowledge payment proofs. It takes a witness (private key and payment data) along with payment requirements and produces a complete PaymentPayload ready to send to a facilitator.
Features
- High-level API - Simple interface for proof generation
- Witness management - Safe handling of private key material
- Payload assembly - Automatic construction of wire-format payloads
- Proof system agnostic - Works with any
ProofSystemimplementation
Usage
Add this to your Cargo.toml:
[]
= "0.1.0"
= "0.1.0"
= "0.1.0"
Example:
use build_payment_payload;
use ;
use Groth16ProofSystem;
// Payment requirements from the payee
let requirements = PaymentRequirements ;
// Your private witness data
let witness = Witness ;
// Public inputs
let public_inputs = PublicInputs ;
// Generate the payment payload
let payload = ?;
// Send payload to facilitator
// POST to /verify then /settle
Security Best Practices
- Never reuse nonces - Generate a fresh random nonce for each payment
- Secure key storage - Keep private keys in secure enclaves/keystores
- Time windows - Set reasonable
valid_afterandvalid_beforebounds - Clear secrets - Zero out witness data after proof generation
Timing Considerations
- Proof generation is CPU-intensive (0.5-2 seconds typical)
- Consider showing a loading indicator in UI applications
- Can be run in a Web Worker (via WASM) to avoid blocking the main thread
Related Crates
zk402-core- Core types and traitszk402-groth16- Groth16 proof system backendzk402-wasm- WebAssembly bindings for browser clientszk402-facilitator- Server-side verification and settlement
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.