zks 0.1.1

Zero Knowledge Swarm - Post-quantum secure networking SDK with built-in anonymity
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
<p align="center">
  <img src="resources/logo.png" alt="ZKS Protocol" width="400">
</p>

<h1 align="center">πŸ” ZKS Protocol</h1>

<p align="center">
  <strong>Zero Knowledge Swarm β€” Post-Quantum Encryption with Built-in Anonymity</strong>
</p>

<p align="center">
  <a href="https://github.com/zks-protocol/zks/actions"><img src="https://img.shields.io/github/actions/workflow/status/zks-protocol/zks/ci.yml?branch=main&style=flat-square&logo=github" alt="Build Status"></a>
  <a href="https://crates.io/crates/zks"><img src="https://img.shields.io/crates/v/zks.svg?style=flat-square&logo=rust" alt="Crates.io"></a>
  <a href="https://docs.rs/zks"><img src="https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square&logo=rust" alt="Docs"></a>
  <a href="LICENSE"><img src="https://img.shields.io/badge/license-AGPL--3.0-blue.svg?style=flat-square" alt="License"></a>
  <a href="https://www.rust-lang.org/"><img src="https://img.shields.io/badge/rust-1.70+-orange.svg?style=flat-square&logo=rust" alt="Rust"></a>
</p>

<p align="center">
  <img src="https://img.shields.io/badge/Linux-FCC624?style=for-the-badge&logo=linux&logoColor=black" alt="Linux">
  <img src="https://img.shields.io/badge/macOS-000000?style=for-the-badge&logo=macos&logoColor=F0F0F0" alt="macOS">
  <img src="https://img.shields.io/badge/Windows-0078D6?style=for-the-badge&logo=windows&logoColor=white" alt="Windows">
  <img src="https://img.shields.io/badge/WebAssembly-654FF0?style=for-the-badge&logo=webassembly&logoColor=white" alt="WASM">
</p>

---

## 🌟 Why ZKS?

ZKS Protocol is the **first post-quantum secure networking SDK** with built-in **anonymity through onion routing**. Built with 100% safe Rust, it provides unbreakable encryption for the quantum computing era.

| Protocol | Description | Security Model |
|----------|-------------|----------------|
| `zk://`  | Direct encrypted connection | Post-quantum secure, low latency |
| `zks://` | Swarm-routed anonymous connection | Post-quantum + onion routing |

---

## πŸ“‘ Table of Contents

- [🌟 Key Features]#-key-features
- [πŸš€ Quick Start]#-quick-start
- [πŸ”’ Security Architecture]#-security-architecture
- [πŸ“¦ Crate Structure]#-crate-structure
- [πŸ§… Anonymous Routing]#-anonymous-routing
- [πŸ“± Platform Support]#-platform-support
- [πŸ“– Examples]#-examples
- [πŸ›‘οΈ Security]#️-security
- [🀝 Contributing]#-contributing
- [πŸ“œ License]#-license

---

## 🌟 Key Features

<table>
<tr>
<td width="50%">

### πŸ” Post-Quantum Cryptography
- **ML-KEM-768** (Kyber) β€” NIST Level 3 key exchange
- **ML-DSA-65** (Dilithium) β€” Post-quantum signatures
- Resistant to quantum computer attacks

</td>
<td width="50%">

### πŸ§… Onion Routing
- Multi-hop anonymous connections
- Traffic analysis resistance
- Built-in swarm networking

</td>
</tr>
<tr>
<td width="50%">

### ⚑ High Performance
- Async/await native design
- Zero-copy message handling
- Minimal memory footprint

</td>
<td width="50%">

### 🌐 Cross-Platform
- Native Linux, macOS, Windows
- WebAssembly for browsers
- Mobile-ready architecture

</td>
</tr>
</table>

---

## πŸš€ Quick Start

### πŸ“‹ Prerequisites

- Rust 1.70+ toolchain
- OpenSSL (for development)

### πŸ“₯ Installation

Add to your `Cargo.toml`:

```toml
[dependencies]
zks_sdk = "0.1"
tokio = { version = "1", features = ["full"] }
```

### πŸ’» Basic Connection (ZK://)

```rust
use zks_sdk::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Build a post-quantum secure connection
    let connection = ZkConnectionBuilder::new()
        .url("zk://secure-server.example.com:8443")
        .security(SecurityLevel::PostQuantum)
        .build()
        .await?;
    
    println!("βœ… Connected with post-quantum encryption!");
    
    // Send encrypted data
    connection.send(b"Hello, quantum-proof world!").await?;
    
    // Receive response
    let response = connection.recv().await?;
    println!("πŸ“© Received: {:?}", response);
    
    connection.close().await?;
    Ok(())
}
```

### πŸ§… Anonymous Connection (ZKS://)

```rust
use zks_sdk::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Build an anonymous swarm-routed connection
    let connection = ZksConnectionBuilder::new()
        .url("zks://hidden-service.example.com:8443")
        .min_hops(3)  // Route through 3+ relay nodes
        .security(SecurityLevel::TrueVernam)
        .build()
        .await?;
    
    println!("πŸ§… Anonymous connection established!");
    println!("   Your IP is hidden from the destination server.");
    
    // Send anonymous message
    connection.send(b"Confidential message").await?;
    
    connection.close().await?;
    Ok(())
}
```

### 🌐 Browser (WebAssembly)

```javascript
import init, { ZksWasmUtils } from 'zks-wasm';

await init();

// Generate post-quantum keypair
const keypair = ZksWasmUtils.generate_ml_dsa_keypair();
console.log("πŸ”‘ Generated ML-DSA keypair");

// Sign a message
const message = new TextEncoder().encode("Hello from the browser!");
const signature = ZksWasmUtils.ml_dsa_sign(message, keypair.signing_key);
console.log("✍️ Signature created");

// Verify signature
const isValid = ZksWasmUtils.ml_dsa_verify(message, signature, keypair.verifying_key);
console.log("βœ… Signature valid:", isValid);
```

---

## πŸ”’ Security Architecture

### πŸ” Cryptographic Primitives

| Component | Algorithm | Security Level |
|-----------|-----------|----------------|
| Key Exchange | ML-KEM-768 (Kyber) | NIST Level 3 (IND-CCA2) |
| Signatures | ML-DSA-65 (Dilithium) | NIST Level 3 (EUF-CMA) |
| Symmetric Encryption | Wasif-Vernam Cipher | ChaCha20-Poly1305 + XOR |
| Random Entropy | drand beacon + local | TRUE random (not pseudo) |

### πŸ›‘οΈ Security Levels

```rust
pub enum SecurityLevel {
    /// Classical cryptography (for testing only)
    Classical,
    
    /// Post-quantum secure (recommended for production)
    PostQuantum,
    
    /// Maximum security with TRUE random entropy
    TrueVernam,
}
```

| Level | Key Exchange | Encryption | Use Case |
|-------|--------------|------------|----------|
| `Classical` | Random | ChaCha20 | Testing/Development |
| `PostQuantum` | ML-KEM | Wasif-Vernam | Production |
| `TrueVernam` | ML-KEM + drand | OTP-style | Maximum Security |

### πŸ”„ 3-Message Handshake

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                           β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Initiator  β”‚                           β”‚  Responder   β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜                           β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚                                          β”‚
       β”‚  1. HandshakeInit                        β”‚
       β”‚  ─────────────────────────────────────►  β”‚
       β”‚  [ephemeral_pk, nonce]                   β”‚
       β”‚                                          β”‚
       β”‚  2. HandshakeResponse                    β”‚
       β”‚  ◄─────────────────────────────────────  β”‚
       β”‚  [ephemeral_pk, ciphertext, signature]   β”‚
       β”‚                                          β”‚
       β”‚  3. HandshakeFinish                      β”‚
       β”‚  ─────────────────────────────────────►  β”‚
       β”‚  [confirmation_hash]                     β”‚
       β”‚                                          β”‚
       β–Ό                                          β–Ό
   [shared_secret derived]                [shared_secret derived]
```

---

## πŸ“¦ Crate Structure

```
zks/
β”œβ”€β”€ zks_sdk        # High-level SDK (start here!)
β”œβ”€β”€ zks_crypt      # Wasif-Vernam cipher, drand integration
β”œβ”€β”€ zks_pqcrypto   # ML-KEM-768, ML-DSA-65
β”œβ”€β”€ zks_proto      # Handshake protocol, URL parsing
β”œβ”€β”€ zks_wire       # Swarm networking, NAT traversal
β”œβ”€β”€ zks_types      # Common type definitions
└── zks_wasm       # WebAssembly bindings
```

| Crate | Description | Key Features |
|-------|-------------|--------------|
| `zks_sdk` | High-level developer API | Connection builders, prefabs |
| `zks_crypt` | Core cryptographic operations | Wasif-Vernam, scrambling, drand |
| `zks_pqcrypto` | Post-quantum primitives | ML-KEM, ML-DSA, Zeroizing |
| `zks_proto` | Protocol implementation | 3-message handshake, messages |
| `zks_wire` | Network layer | STUN, NAT traversal, swarm |
| `zks_types` | Shared types | Error types, crypto params |
| `zks_wasm` | Browser support | JS bindings via wasm-bindgen |

---

## πŸ§… Anonymous Routing

The `zks://` protocol provides **onion routing** through a decentralized swarm network:

```
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Client │───►│ Entry   │───►│ Middle  │───►│ Exit    │───►│ Destinationβ”‚
β”‚        β”‚    β”‚ Relay   β”‚    β”‚ Relay   β”‚    β”‚ Relay   β”‚    β”‚            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
     β”‚              β”‚              β”‚              β”‚               β”‚
     └──encrypted──►└──encrypted──►└──encrypted──►└──plaintext───►│
```

### Features

- **Multi-hop routing**: Configurable number of relay hops (default: 3)
- **Layered encryption**: Each hop can only decrypt its layer
- **Traffic analysis resistance**: Optional scrambling mode
- **Peer discovery**: Automatic swarm network formation

---

## πŸ“± Platform Support

| Platform | Status | Notes |
|----------|--------|-------|
| Linux | βœ… Full Support | Primary development platform |
| macOS | βœ… Full Support | Intel and Apple Silicon |
| Windows | βœ… Full Support | Windows 10/11 |
| WebAssembly | βœ… Full Support | Chrome, Firefox, Safari |
| iOS | πŸ”„ Planned | Via Rust FFI |
| Android | πŸ”„ Planned | Via Rust FFI |

---

## πŸ“– Examples

The `examples/` directory contains complete working examples:

```bash
# Basic encrypted connection
cargo run --example basic_connection

# Anonymous swarm-routed connection
cargo run --example anonymous_connection

# Secure file transfer
cargo run --example file_transfer
```

### 🌐 What Can You Build?

| Application | Protocol | Description |
|-------------|----------|-------------|
| **Encrypted Messenger** | `zks://` | Quantum-proof end-to-end chat |
| **Secure File Sharing** | `zk://` | Unbreakable file transfer |
| **Anonymous APIs** | `zks://` | Hide client IP addresses |
| **VPN Replacement** | `zks://` | Better than VPN + Tor combined |
| **Whistleblowing Platform** | `zks://` | Source protection |
| **Healthcare/Finance** | `zk://` | HIPAA/PCI compliance |

---

## πŸ›‘οΈ Security

### Security Model

- **Post-quantum resistance**: All key exchanges use NIST-standardized algorithms
- **Forward secrecy**: Session keys are derived per-connection
- **Zero trust**: End-to-end encryption with mutual authentication
- **Memory safety**: 100% safe Rust, no `unsafe` code in core crates

### Responsible Disclosure

Please report security vulnerabilities to: **security@zks-protocol.org**

See [SECURITY.md](SECURITY.md) for our full security policy.

---

## πŸ§ͺ Testing

```bash
# Run all tests
cargo test --workspace

# Run specific crate tests
cargo test -p zks_sdk
cargo test -p zks_crypt

# Run integration tests
cargo test --test integration_tests
```

---

## 🀝 Contributing

Contributions are welcome! Here's how to get started:

1. **Fork** the repository
2. **Create** a feature branch (`git checkout -b feature/amazing-feature`)
3. **Commit** your changes (`git commit -m 'Add amazing feature'`)
4. **Push** to the branch (`git push origin feature/amazing-feature`)
5. **Open** a Pull Request

Please ensure your code:
- βœ… Follows Rust best practices
- βœ… Includes appropriate tests
- βœ… Has documentation for public APIs
- βœ… Passes all CI checks

---

## πŸ“œ License

This project is licensed under the **GNU Affero General Public License v3.0 (AGPL-3.0)**.

See [LICENSE](LICENSE) for the full license text.

---

## πŸ“ž Contact

- **GitHub Issues**: [Report bugs and request features]https://github.com/zks-protocol/zks/issues
- **Security**: security@zks-protocol.org

---

<p align="center">
  <strong>Built with ❀️ for a quantum-safe future</strong>
</p>

<p align="center">
  <sub>Protecting your privacy today, and tomorrow.</sub>
</p>