WhisperCache is a privacy-first memory layer for AI agents that uses zero-knowledge proofs and end-to-end encryption. This document describes the complete API for integrating with WhisperCache.
Base URL: http://localhost:4000/api
WhisperCache uses DID (Decentralized Identity) authentication with session tokens.
POST /api/auth/demoCreates a demo session for development/testing.
Response:
{
"success": true,
"did": "did:midnight:abc123...",
"token": "session_token...",
"keyId": "key_abc123",
"expiresAt": "2024-01-02T00:00:00.000Z",
"permissions": ["read", "write", "prove"]
}POST /api/auth/register
Content-Type: application/json
{
"publicKey": "64-character-hex-public-key"
}POST /api/auth/challenge
Content-Type: application/json
{
"did": "did:midnight:abc123..."
}POST /api/auth/authenticate
Content-Type: application/json
{
"challenge": "challenge_hash",
"signature": "ed25519_signature",
"did": "did:midnight:abc123..."
}All authenticated endpoints require:
Authorization: Bearer <session_token>
POST /api/memory
Authorization: Bearer <token>
Content-Type: application/json
{
"encryptedData": "base64-encoded-encrypted-content",
"nonce": "base64-encoded-nonce",
"tags": ["work", "important"],
"confidence": 0.95
}Response:
{
"success": true,
"memoryId": "mem_abc123...",
"contentHash": "sha256-hash",
"createdAt": "2024-01-01T00:00:00.000Z"
}GET /api/memory/:memoryId
Authorization: Bearer <token>Response:
{
"memoryId": "mem_abc123",
"encryptedData": "base64-data",
"nonce": "base64-nonce",
"algorithm": "XChaCha20-Poly1305",
"metadata": {
"contentHash": "sha256-hash",
"tags": ["work"],
"confidence": 0.95,
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-01T00:00:00.000Z"
}
}GET /api/memory?tag=work&limit=50
Authorization: Bearer <token>GET /api/memory/search?tags=work,important&minConfidence=0.8
Authorization: Bearer <token>PATCH /api/memory/:memoryId
Authorization: Bearer <token>
Content-Type: application/json
{
"tags": ["work", "archived"],
"confidence": 0.85
}DELETE /api/memory/:memoryId
Authorization: Bearer <token>POST /api/memory/:memoryId/verify
Authorization: Bearer <token>POST /api/zk/prove
Content-Type: application/json
{
"query": "Any mental health patterns?",
"memoryHashes": ["hash1", "hash2"]
}Response:
{
"result": "ok",
"confidence": 0.89,
"proofHash": "zk_proof_hash",
"pattern": "Elevated stress pattern detected",
"query": "Any mental health patterns?",
"timestamp": "2024-01-01T00:00:00.000Z",
"category": "mental_health",
"sensitivity": "critical",
"insights": [
"High confidence pattern match detected",
"Emotional context preserved in encrypted form",
"No raw sentiment data exposed",
"Zero-knowledge proof generated successfully"
],
"recommendation": "Consider consulting a professional for personalized guidance",
"proofData": {
"commitment": "commitment_hash",
"publicInputs": ["input1", "input2"],
"verified": true
}
}GET /api/zk/verify/:proofHashPOST /api/anchor
Content-Type: application/json
{
"memoryHash": "memory_content_hash",
"proofHash": "zk_proof_hash"
}Response:
{
"txId": "midnight_tx_abc123",
"status": "confirmed",
"blockHeight": 1005942,
"blockHash": "block_hash",
"timestamp": "2024-01-01T00:00:00.000Z",
"confirmations": 3,
"anchorData": {
"commitment": "commitment_hash",
"network": "midnight-devnet",
"nonce": "nonce_value",
"proofHash": "proof_hash",
"memoryHash": "memory_hash"
},
"fees": "0.00012345"
}GET /api/anchor/:txIdPOST /api/anchor/verify
Content-Type: application/json
{
"txId": "midnight_tx_abc123"
}GET /api/anchor/statusResponse:
{
"network": "midnight",
"connected": true,
"chainId": "midnight-devnet-1",
"latestBlock": 1005942,
"syncProgress": 100,
"peersConnected": 12,
"networkVersion": "0.1.0"
}GET /api/anchor/recent?limit=10POST /api/anchor/estimate
Content-Type: application/json
{
"payloadSize": 256
}POST /api/compliance/log
Content-Type: application/json
{
"action": "create",
"keyId": "key_abc123",
"memoryId": "mem_abc123",
"metadata": {
"reason": "User created new memory"
}
}Actions: create, access, delete, proof, rotate_key, anchor, export, share
GET /api/compliance/logs?keyId=key_abc123&action=create&limit=100GET /api/compliance/verifyResponse:
{
"verified": true,
"chainLength": 42,
"latestLogHash": "hash..."
}GET /api/compliance/export?keyId=key_abc123GET /api/compliance/statsResponse:
{
"complianceLogs": 150,
"memories": 45,
"zkProofs": 30,
"anchors": 25,
"keyRotations": 2,
"timestamp": "2024-01-01T00:00:00.000Z"
}POST /api/keys/rotate
Authorization: Bearer <token>
Content-Type: application/json
{
"reason": "Scheduled rotation"
}POST /api/keys/revoke
Authorization: Bearer <token>
Content-Type: application/json
{
"keyId": "key_to_revoke",
"reason": "Suspected compromise"
}GET /api/keys/history
Authorization: Bearer <token>GET /api/keys/status/:keyIdGET /api/healthResponse:
{
"status": "healthy",
"services": {
"crypto": { "status": "ready", "algorithm": "XChaCha20-Poly1305" },
"database": {
"status": "ready",
"type": "SQLite",
"complianceLogs": 150,
"memories": 45,
"zkProofs": 30,
"anchors": 25,
"keyRotations": 2
},
"midnight": { "status": "ready", "network": "devnet" }
},
"networks": {
"midnight": { "connected": true, "latency": 45 },
"cardano": { "connected": true, "latency": 120 }
},
"timestamp": "2024-01-01T00:00:00.000Z"
}All errors follow this format:
{
"error": "Error message",
"code": "ERROR_CODE"
}| Code | HTTP Status | Description |
|---|---|---|
UNAUTHORIZED |
401 | Missing or invalid auth token |
KEY_REVOKED |
401 | The session key has been revoked |
FORBIDDEN |
403 | Insufficient permissions |
NOT_FOUND |
404 | Resource not found |
VALIDATION_ERROR |
400 | Invalid request parameters |
PROOF_FAILED |
500 | ZK proof generation failed |
| Endpoint Category | Rate Limit |
|---|---|
| Authentication | 10/minute |
| Memory Operations | 100/minute |
| ZK Proofs | 20/minute |
| Blockchain Anchoring | 10/minute |
| Compliance Logs | 100/minute |
- Algorithm: XChaCha20-Poly1305 (AEAD)
- Key Size: 256 bits
- Nonce Size: 192 bits
- MAC Size: 128 bits (Poly1305)
All memory content is encrypted client-side before transmission. The server never has access to plaintext data.
- Hash Function: Poseidon (ZK-friendly)
- Proving System: Groth16 via SnarkJS
- Curve: BN128 (alt_bn128)
- Constraint System: R1CS (Rank-1 Constraint System)
Proofs verify:
- Memory ownership (via key hash)
- Pattern matching (without revealing content)
- Confidence scoring (deterministic computation)