A comprehensive implementation of Chaum-Pedersen Zero-Knowledge Proofs with multiple interfaces and practical applications.
- Support for scalar (multiplicative) group operations
- Support for secp256k1 elliptic curve operations
- Support for Curve25519 (optional feature)
- Multi-round session support
- WebAssembly support
- Python bindings
- CLI tool
- Comprehensive benchmarks
- Web demo application
- Ethereum integration example
- Interactive documentation
Add to your Cargo.toml
:
[dependencies]
cpzkp = { version = "0.1", features = ["curve25519"] } # Optional features
use cpzkp::{Group, Point, get_constants, solve_zk_challenge_s};
use num_bigint::BigUint;
// Select the group type
let group = Group::Scalar;
// Get the system parameters
let (p, q, g, h) = get_constants(&group).unwrap();
// Generate a random secret
let x_secret = BigUint::from(1234u32);
let k = BigUint::from(5678u32);
let c = BigUint::from(910u32);
// Solve the ZK challenge
let s = solve_zk_challenge_s(&x_secret, &k, &c, &q);
# Generate a key pair
cpzkp gen-key --group scalar --output keypair.json
# Generate a proof
cpzkp prove --msg "Hello, World!" --keypair keypair.json --output proof.json
# Verify a proof
cpzkp verify --proof proof.json --keypair keypair.json
import { KeyPair, Proof } from 'cpzkp';
// Generate a key pair
const keypair = await KeyPair.new('scalar');
// Generate a proof
const proof = await Proof.generate(keypair, 'Hello, World!');
// Verify the proof
const isValid = await proof.verify();
from cpzkp import KeyPair, Proof
# Generate a key pair
keypair = KeyPair('scalar')
# Generate a proof
proof = Proof.generate(keypair, 'Hello, World!')
# Verify the proof
is_valid = proof.verify()
use cpzkp::{Group, Session};
// Create a new session
let mut session = Session::new(Group::Scalar).unwrap();
// Start a new round
let (r1, r2) = session.next_round().unwrap();
// Solve the challenge
let s = session.solve_challenge(0, &challenge).unwrap();
// Verify the round
let is_valid = session.verify_round(0).unwrap();
// Finalize the session
session.finalize().unwrap();
use cpzkp::ethereum_integration;
// Generate an Ethereum wallet and ZKP
let (wallet, proof) = ethereum_integration::generate_proof().await?;
// Verify the proof
let is_valid = proof.verify()?;
Try the interactive web demo:
cd examples/webapp
docker build -t cpzkp-webapp .
docker run -p 8080:80 cpzkp-webapp
Then open http://localhost:8080 in your browser.
scalar
: Enable scalar group operations (default)ecc
: Enable elliptic curve operationscurve25519
: Enable Curve25519 supportwasm
: Enable WebAssembly supportpython
: Enable Python bindingsethereum
: Enable Ethereum integration
Run the benchmarks with:
cargo bench
The benchmarks measure:
- Scalar operations
- ECC operations
- Verification time
- Serialization/deserialization
The complete documentation is available at:
This library is intended for educational purposes. For production use, please consult with a cryptographer and perform a security audit.
MIT