Overview
This guide walks you through the basic operations of the ZK ElGamal Proof SDK:- Generating ElGamal keypairs
- Encrypting and decrypting data
- Creating zero-knowledge proofs
- Verifying proofs
Basic Usage
- Rust
- JavaScript (Node.js)
- JavaScript (Web)
Generate a Keypair
First, let’s create an ElGamal keypair for encryption:Encrypt and Decrypt Data
Now let’s encrypt a value and decrypt it:The
decrypt_u32() method returns Option<u64> because decryption requires solving the discrete logarithm problem. It works efficiently for small values but may fail or take time for large values.Create a Zero-Knowledge Proof
Let’s create a public key validity proof to prove we know the secret key:Complete Example
Here’s a complete example demonstrating the full workflow:Working with Keys
Serialize and Deserialize Keys
- Rust
- JavaScript
Encrypt with Custom Opening
For advanced use cases, you can provide your own Pedersen opening:- Rust
- JavaScript
Understanding Proofs
Public Key Validity Proof
A public key validity proof proves that you know the secret key corresponding to a public key without revealing the secret key itself. What it proves: “I know the discrete logarithm (secret key) of this public key.” Use cases:- Proving ownership of an ElGamal public key
- Authenticating without revealing credentials
- Establishing trust in encrypted communications
Proof Context and Verification
- Rust
- JavaScript
Next Steps
Core Concepts
Understand the cryptographic foundations of ElGamal encryption and zero-knowledge proofs.
Proof Types
Learn about range proofs, equality proofs, and batched proof systems.
Rust SDK
Explore the complete Rust API documentation for all cryptographic primitives.
JavaScript SDK
Browse JavaScript/TypeScript examples and integration patterns.
Common Patterns
Encrypting Multiple Values
Encrypting Multiple Values
When encrypting multiple values with the same public key:
Serializing Proofs for Storage
Serializing Proofs for Storage
Proofs can be serialized and stored for later verification:Rust:JavaScript:
Error Handling Best Practices
Error Handling Best Practices
Always handle cryptographic errors gracefully:Rust:JavaScript: