# h33-client
Official Rust client for the [H33](https://h33.ai) post-quantum cryptographic API.
One crate. Full access to FHE encryption, Dilithium signatures, Kyber key exchange, and biometric authentication — all post-quantum secure.
## Install
```toml
[dependencies]
h33-client = "0.1"
```
## Quick Start
```rust
use h33_client::H33Client;
#[tokio::main]
async fn main() -> h33_client::Result<()> {
let client = H33Client::builder()
.api_url("https://api.h33.ai")
.api_key("h33_live_...")
.build()?;
// FHE: Encrypt → Compute → Decrypt (data never leaves encrypted form)
let session = client.fhe_init("bfv").await?;
let ct = client.fhe_encrypt(&session, "42").await?;
let result = client.fhe_compute(&session, "add", &[&ct, &ct]).await?;
let answer = client.fhe_decrypt(&session, &result).await?;
assert_eq!(answer, "84");
// Post-quantum signatures (Dilithium)
let sig = client.sign("important data").await?;
let valid = client.verify("important data", &sig).await?;
assert!(valid);
// Biometric auth (FHE-encrypted, zero exposure)
let template = vec![0.1; 128]; // 128-dim embedding from your model
client.biometric_enroll("user_123", &template).await?;
let matched = client.biometric_verify("user_123", &template).await?;
assert!(matched);
Ok(())
}
```
## Environment Variables
| `H33_API_URL` | `http://localhost:8080` | API endpoint |
| `H33_API_KEY` | (required) | Your API key from [h33.ai/pricing](https://h33.ai/pricing) |
```rust
// Auto-configure from environment
let client = H33Client::from_env()?;
```
## API Coverage
| `health()` | `GET /health` | Service health check |
| `connect()` | `POST /api/v1/auth/token` | Get JWT (optional, API key works) |
| `fhe_init(scheme)` | `POST /api/v1/fhe/init` | Start FHE session (bfv/ckks) |
| `fhe_encrypt(session, plaintext)` | `POST /api/v1/fhe/encrypt` | Encrypt plaintext |
| `fhe_decrypt(session, ciphertext)` | `POST /api/v1/fhe/decrypt` | Decrypt ciphertext |
| `fhe_compute(session, op, operands)` | `POST /api/v1/fhe/compute` | Homomorphic computation |
| `pq_encrypt(plaintext)` | `POST /api/v1/encrypt` | Kyber + AES-256-GCM encrypt |
| `pq_decrypt(ciphertext)` | `POST /api/v1/decrypt` | Hybrid decrypt |
| `sign(data)` | `POST /api/v1/sign` | Dilithium signature |
| `verify(data, signature)` | `POST /api/v1/verify` | Verify signature |
| `biometric_enroll(user, template)` | `POST /api/v2/biometric/enroll` | Enroll FHE-encrypted template |
| `biometric_verify(user, template)` | `POST /api/v2/biometric/verify` | Verify against enrolled template |
| `usage()` | `GET /api/v1/usage` | Usage statistics |
## Error Handling
All methods return `h33_client::Result<T>`. Errors include HTTP status, error code, message, and optional hint:
```rust
match client.fhe_encrypt(&session, "data").await {
Ok(ct) => println!("Encrypted: {}", ct),
Err(H33Error::Api { status, message, hint, .. }) => {
eprintln!("API error {}: {} ({})", status, message, hint.unwrap_or_default());
}
Err(e) => eprintln!("Network error: {}", e),
}
```
## Performance
For latency-critical applications (biometric auth), use [`h33-fhe-client`](https://crates.io/crates/h33-fhe-client) to move BFV encryption client-side, eliminating ~419us from the server pipeline.
## License
MIT