UNPKG

@neabyte/quantum-zkp

Version:

Educational quantum-resistant zero-knowledge proof library for learning and prototyping

525 lines (389 loc) โ€ข 15.5 kB
# ๐Ÿ” Quantum-Resistant Zero-Knowledge Proofs **NeaByteLab** | **August 2025** | **Version 1.0.0** [![Node.js](https://img.shields.io/badge/Node.js-22+-green.svg)](https://nodejs.org/) [![TypeScript](https://img.shields.io/badge/TypeScript-5.9+-blue.svg)](https://www.typescriptlang.org/) [![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](https://opensource.org/licenses/Apache-2.0) [![Build Status](https://img.shields.io/badge/Build-Passing-brightgreen.svg)](https://github.com/NeaByteLab/Quantum-ZKP) > **Research Implementation** - Comprehensive TypeScript library for understanding quantum-resistant zero-knowledge proof protocols. Designed for research, education, and prototyping applications. ## ๐Ÿ“‹ Overview A comprehensive TypeScript library implementing quantum-resistant zero-knowledge proof protocols using educational cryptographic concepts. This library provides educational implementations of four major post-quantum cryptography approaches: - **Hash-Based ZKP**: Hash chain implementations using SHA-256/384/512 - **Lattice-Based ZKP**: Learning With Errors (LWE) implementations for lattice cryptography - **Multivariate ZKP**: Polynomial system implementations for multivariate cryptography - **Hybrid ZKP**: Multi-algorithm approaches for defense-in-depth concepts ## โœจ Key Features - **๐Ÿ”ฌ Research Focus**: Comprehensive implementations for understanding cryptographic concepts - **๐Ÿ“š Detailed Documentation**: Mathematical foundations and security analysis - **โšก Performance Benchmarks**: Built-in benchmarking for algorithm comparison - **๐Ÿ›ก๏ธ Security Analysis**: Research-grade security assessments - **๐Ÿ“ฑ Cross-Platform**: Node.js 22+ (browser support planned) - **๐Ÿงช Prototyping Tools**: Development utilities for testing concepts ## ๐Ÿ—๏ธ Library Architecture ```mermaid graph TB A[QuantumZKP Core] --> B[HashZKP] A --> C[LatticeZKP] A --> D[MultivariateZKP] A --> E[HybridZKP] A --> F[Benchmarking] A --> G[Documentation] style A fill:#e3f2fd,stroke:#1976d2,stroke-width:3px,color:#000000 style B fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px,color:#000000 style C fill:#fff3e0,stroke:#f57c00,stroke-width:2px,color:#000000 style D fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px,color:#000000 style E fill:#f8bbd9,stroke:#c2185b,stroke-width:2px,color:#000000 style F fill:#e8f5e8,stroke:#388e3c,stroke-width:2px,color:#000000 style G fill:#fff3e0,stroke:#f57c00,stroke-width:2px,color:#000000 ``` ## ๐Ÿ“Š Algorithm Comparison | Algorithm | Foundation | Research Purpose | Performance Profile | |-----------|------------|-------------------|-------------------| | **Hash** | SHA-256/384/512 hash functions | Understanding hash-based cryptography | 1.76ms generation, 1.07ms verification | | **Lattice** | Learning With Errors (LWE) | Researching lattice cryptography principles | 389.67ms generation, 104.79ฮผs verification | | **Multivariate** | Multivariate polynomial systems | Studying polynomial cryptography concepts | 377.03ฮผs generation, 17.80ฮผs verification | | **Hybrid** | Multiple algorithm combination | Researching defense-in-depth concepts | 1.33s generation, 654.66ฮผs verification | *Performance data based on real benchmarks on Apple M3 Pro hardware* --- ## ๐Ÿš€ Quick Start ### Installation ```bash npm install @neabyte/quantum-zkp ``` ### Basic Usage ```typescript import { QuantumZKP } from '@neabyte/quantum-zkp' // Create a quantum-resistant zero-knowledge proof const secret = 'my-secret-data' const zkp = new QuantumZKP() const proof = zkp.createProof(secret, 'hash') // Verify the proof const verificationResult = zkp.verifyProof(proof) console.log('Proof valid:', verificationResult.isValid) // true console.log('Verification time:', verificationResult.verificationTime, 'ms') ``` ### Advanced Usage ```typescript import { LatticeZKP, HashZKP, MultivariateZKP, HybridZKP } from '@neabyte/quantum-zkp' // Hash-based ZKP const hashProof = HashZKP.createProof(secret, { chainLength: 1000 }) // Lattice-based ZKP const latticeProof = LatticeZKP.createProof(secret, { dimension: 256, modulus: 2n ** 512n }) // Multivariate ZKP const multivariateProof = MultivariateZKP.createProof(secret, { variables: 8, equations: 12 }) // Hybrid ZKP const hybridProof = HybridZKP.createProof(secret, { algorithms: ['hash', 'lattice'], weights: [0.6, 0.4] }) ``` ## ๐Ÿ”ง Advanced Features ### Threshold Cryptography ```typescript // Create distributed proof across multiple parties const thresholdProof = zkp.createThresholdProof(secret, 3, 'lattice') console.log('Threshold:', thresholdProof.threshold) // 2 console.log('Parties:', thresholdProof.parties) // 3 ``` ### Batch Processing ```typescript // Process multiple proofs efficiently const secrets = ['secret1', 'secret2', 'secret3', 'secret4'] const proofs = zkp.batchCreateProofs(secrets, 'hash', { parallel: true, batchSize: 2, progressCallback: (progress) => console.log(`Progress: ${progress * 100}%`) }) ``` --- ### Performance Benchmarking ```typescript // Benchmark all algorithms const benchmarks = zkp.benchmarkAllAlgorithms() benchmarks.forEach(result => { console.log(`${result.algorithm}: ${result.operationsPerSecond} ops/sec`) }) ``` ## ๐Ÿง  Zero-Knowledge Proof Concepts ### Basic ZKP Flow ```mermaid flowchart LR A[Prover<br/>Secret Knowledge] --> B[Commitment<br/>Hide Secret] B --> C[Challenge<br/>Random Value] C --> D[Response<br/>Proof Without Secret] D --> E[Verification<br/>Check Validity] style A fill:#ffebee,color:#000000 style E fill:#e8f5e8,color:#000000 ``` ### ZKP Properties ```mermaid graph TD A[ZKP Properties] --> B[๐Ÿ” Completeness] A --> C[๐Ÿ›ก๏ธ Soundness] A --> D[๐Ÿค Zero-Knowledge] A --> E[โšก Efficiency] B --> B1[Valid proofs always verify] C --> C1[Invalid proofs rarely verify] D --> D1[No secret information revealed] E --> E1[Practical to generate/verify] style A fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000 style B fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000 style C fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000 style D fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000 style E fill:#ffffff,stroke:#000000,stroke-width:2px,color:#000000 ``` ### Hash-Based ZKP Flow ```mermaid flowchart LR A[Secret] --> B[Hash Chain] B --> C[Commitment] C --> D[Challenge] A --> E[Witness] E --> F[Response] F --> G[Verification] G --> H[Result] D --> F subgraph "Research Features" I[๐Ÿ“Š Hash Chain Concepts] J[๐Ÿ”’ Hash Function Security] K[โšก Fast Performance] end style A fill:#ffebee,color:#000000 style H fill:#e8f5e8,color:#000000 style I fill:#e3f2fd,color:#000000 style J fill:#fff3e0,color:#000000 style K fill:#f3e5f5,color:#000000 ``` ### Lattice-Based ZKP Flow ```mermaid %%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#ffffff', 'primaryTextColor': '#000000', 'primaryBorderColor': '#000000', 'lineColor': '#000000', 'secondaryColor': '#f8f9fa', 'tertiaryColor': '#ffffff'}}}%% flowchart LR A[Secret] --> B[LWE Problem] B --> C[Commitment] C --> D[Challenge] A --> E[Witness] E --> F[LWE Solution] F --> G[Verification] G --> H[Result] D --> F subgraph "Research Features" I[๐Ÿ“Š Lattice Cryptography] J[๐Ÿ”’ LWE Hardness Assumption] K[โšก Medium Performance] end style A fill:#ffebee,color:#000000 style H fill:#e8f5e8,color:#000000 style I fill:#e3f2fd,color:#000000 style J fill:#fff3e0,color:#000000 style K fill:#f3e5f5,color:#000000 ``` ### Multivariate ZKP Flow ```mermaid flowchart LR A[Secret] --> B[Polynomial System] B --> C[Commitment] C --> D[Challenge] A --> E[Witness] E --> F[Polynomial Solution] F --> G[Verification] G --> H[Result] D --> F subgraph "Research Features" I[๐Ÿ“Š Polynomial Cryptography] J[๐Ÿ”’ Polynomial System Solving] K[โšก Complex Security] end style A fill:#ffebee,color:#000000 style H fill:#e8f5e8,color:#000000 style I fill:#e3f2fd,color:#000000 style J fill:#fff3e0,color:#000000 style K fill:#f3e5f5,color:#000000 ``` ### Hybrid ZKP Flow ```mermaid flowchart LR A[Secret] --> B[Multiple Algorithms] B --> C[Combined Commitment] C --> D[Challenge] A --> E[Witness] E --> F[Weighted Response] F --> G[Multi-Verification] G --> H[Result] D --> F subgraph "Research Features" I[๐Ÿ“Š Defense-in-Depth Concepts] J[๐Ÿ”’ Multiple Security Assumptions] K[โšก Maximum Research Security] end style A fill:#ffebee,color:#000000 style H fill:#e8f5e8,color:#000000 style I fill:#e3f2fd,color:#000000 style J fill:#fff3e0,color:#000000 style K fill:#f3e5f5,color:#000000 ``` --- ## ๐Ÿ”ฌ Research Use Cases ### Blockchain & Web3 Research ```typescript // Research privacy-preserving transactions const proof = zkp.createProof(transactionData, 'hash') // Study how zero-knowledge proofs work in blockchain systems ``` ### Identity Management Research ```typescript // Research identity proof concepts const identityProof = zkp.createProof(userCredentials, 'lattice') // Study anonymous authentication concepts ``` ### IoT Security Research ```typescript // Research lightweight authentication concepts const deviceProof = HashZKP.createProof(deviceSecret) // Study device-to-device communication concepts ``` ### Financial Security Research ```typescript // Research digital signature concepts const signature = HybridZKP.createProof(financialDocument) // Study long-term document security concepts ``` --- ## โšก Performance Characteristics For detailed performance analysis and optimization recommendations, see [PERFORMANCE.md](./PERFORMANCE.md). ### Algorithm Performance (Real Benchmarks) | Algorithm | Generation Time | Verification Time | Proof Size | Memory Usage | Ops/sec | |-----------|----------------|-------------------|------------|--------------|---------| | Hash | 1.76ms | 1.07ms | 416.18 KB | ~256 KB | 569.1 | | Lattice | 389.67ms | 104.79ฮผs | 5.01 KB | ~512 KB | 2.6 | | Multivariate | 377.03ฮผs | 17.80ฮผs | 9.26 KB | 255.9 KB | 2652.3 | | Hybrid | 1.33s | 654.66ฮผs | 431.54 KB | ~1 MB | 0.7 | *Benchmark results from Apple M3 Pro with Node.js 22.16.0* ### Hardware Requirements - **Minimum**: Node.js 22+, 2GB RAM - **Recommended**: 4GB+ RAM for research hybrid algorithms - **Research**: 8GB+ RAM for comprehensive research demonstrations --- ## ๐Ÿ“š API Reference ### Core Class: `QuantumZKP` #### Constructor ```typescript new QuantumZKP(config?: Partial<ZKPConfig>) ``` #### Methods ##### `createProof(secret, algorithm?, parameters?)` Creates a quantum-resistant zero-knowledge proof. **Parameters:** - `secret: Buffer | string` - Secret to prove knowledge of - `algorithm: AlgorithmType` - Algorithm to use (default: 'hash') - `parameters?: Partial<ProofParameters>` - Algorithm-specific parameters **Returns:** `Proof` - Quantum-resistant proof ##### `verifyProof(proof)` Verifies a quantum-resistant proof. **Parameters:** - `proof: Proof` - Proof to verify **Returns:** `VerificationResult` - Verification result with timing information ##### `createThresholdProof(secret, parties?, algorithm?)` Creates distributed proof across multiple parties. **Parameters:** - `secret: Buffer | string` - Secret to prove knowledge of - `parties: number` - Number of parties (default: 3) - `algorithm: AlgorithmType` - Algorithm to use **Returns:** `ThresholdProof` - Distributed proof with reconstruction key ##### `batchCreateProofs(secrets, algorithm?, options?)` Efficiently creates multiple proofs. **Parameters:** - `secrets: (Buffer | string)[]` - Array of secrets - `algorithm: AlgorithmType` - Algorithm to use - `options?: BatchProcessingOptions` - Processing options **Returns:** `Proof[]` - Array of proofs ##### `benchmarkAllAlgorithms()` Benchmarks all supported algorithms. **Returns:** `BenchmarkResult[]` - Performance comparison results ### Algorithm-Specific Classes #### `HashZKP` ```typescript // Create hash-based proof const proof = HashZKP.createProof(secret, { chainLength: 1000 }) // Verify hash-based proof const isValid = HashZKP.verifyProof(proof) // Get performance metrics const metrics = HashZKP.getPerformanceMetrics() // Get security level const security = HashZKP.getSecurityLevel() ``` #### `LatticeZKP` ```typescript // Create lattice-based proof const proof = LatticeZKP.createProof(secret, { dimension: 256, modulus: 2n ** 512n }) // Verify lattice-based proof const isValid = LatticeZKP.verifyProof(proof) ``` #### `MultivariateZKP` ```typescript // Create multivariate proof const proof = MultivariateZKP.createProof(secret, { variables: 8, equations: 12 }) // Verify multivariate proof const isValid = MultivariateZKP.verifyProof(proof) ``` #### `HybridZKP` ```typescript // Create hybrid proof const proof = HybridZKP.createProof(secret, { algorithms: ['hash', 'lattice'], weights: [0.6, 0.4] }) // Verify hybrid proof const isValid = HybridZKP.verifyProof(proof) ``` --- ## ๐Ÿ› ๏ธ Development ### Setup ```bash git clone https://github.com/NeaByteLab/Quantum-ZKP.git cd Quantum-ZKP npm install ``` ### Available Scripts ```bash npm run build # Build the library npm run dev # Development mode with watch npm run test # Run tests npm run lint # Lint code npm run format # Format code npm run benchmark # Run performance benchmarks npm run example # Run basic usage example ``` ### Documentation - **[README.md](./README.md)** - Project overview and quick start - **[PERFORMANCE.md](./PERFORMANCE.md)** - Detailed performance analysis and benchmarks - **[SECURITY.md](./SECURITY.md)** - Security analysis and cryptographic foundations - **[LICENSE](./LICENSE)** - Apache 2.0 license --- ## ๐Ÿ“„ License This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details. --- ## ๐Ÿ”’ Security This is a **research implementation** designed for understanding quantum-resistant cryptography concepts. While the implementations follow established cryptographic principles, they are intended for research and prototyping purposes. For detailed security analysis and cryptographic foundations, see [SECURITY.md](./SECURITY.md). For production quantum-resistant cryptography, consult with qualified cryptographic experts and use established, audited implementations that have undergone formal security analysis. ## ๐Ÿค Contributing We welcome contributions for research improvements, documentation enhancements, and bug fixes. Please read our [Contributing Guidelines](CONTRIBUTING.md) before submitting pull requests. ## ๐Ÿ’ฌ Support For research support, questions about implementation concepts, or consulting inquiries: - **Issues**: [GitHub Issues](https://github.com/NeaByteLab/Quantum-ZKP/issues) - **Consulting**: [Contact NeaByteLab](mailto:me@neabyte.com) --- **Note**: This library is designed for research purposes and prototyping. For production quantum-resistant cryptography implementations, please consult with qualified cryptographic experts.