Confidential coprocessor client — compute on encrypted data via Koa's FHE service
Project description
koa-fhe
Confidential coprocessor client — compute on encrypted data via Koa's FHE service.
The server never sees plaintext. Your data is encrypted locally, evaluated under Fully Homomorphic Encryption, and decrypted locally. Every query costs $0.001–$0.10 USDC via x402.
Install
pip install koa-fhe # core (compare, add, multiply, schedule analysis)
pip install koa-fhe[ml] # + encrypted ML inference (XGBoost workload scoring)
Quickstart
import koa_fhe
client = koa_fhe.Client() # default: localhost:3410
# Encrypted comparison — server never sees 85 or 80
result = client.compare(85, 80)
print(result.greater) # True
# Encrypted addition
result = client.add(500, 300)
print(result.value) # 800
# Encrypted multiplication
result = client.multiply(7, 13)
print(result.value) # 91
API Reference
Client(server, *, payment_proof)
| Method | Returns | Latency | Price |
|---|---|---|---|
compare(a, b) |
CompareResult(greater, stats) |
~625ms | $0.002 |
add(a, b) |
ArithmeticResult(value, stats) |
~260ms | $0.001 |
multiply(a, b) |
ArithmeticResult(value, stats) |
~685ms | $0.002 |
measure_rigidity(old, new) |
RigidityResult(hamming_distance, rigidity_score, severity, stats) |
~3.5s | $0.05 |
analyze_schedule(old, new, *, constraints, alpha, beta) |
ScheduleAnalysis(objective, ...) |
~5s | $0.10 |
predict_workload(features) |
WorkloadPrediction(predictions, stats) |
~7s | $0.01 |
health() |
ServiceHealth(status, circuits, ...) |
instant | free |
circuits() |
dict — circuit catalog with hashes, pricing |
instant | free |
Warm-up & Readiness
Key generation is the slowest step (~2-30s per circuit). Use warm_up() to pre-generate keys in background threads:
client = koa_fhe.Client()
client.warm_up(["add", "threshold"]) # keygen in background
# ... do other work ...
print(client.ready) # {"add": True, "threshold": True}
result = client.add(1, 2) # instant — keys already ready
Key Deduplication
Evaluation keys are content-addressed (SHA-256). If you create multiple Client instances with the same circuits, the SDK detects duplicate keys on the server via HEAD /keys/{circuit}?hash=... and reuses them — no redundant uploads.
How it works
- On first call, the SDK downloads circuit specs from the server
- Keys are generated locally — the server never sees your secret key
- Key hash is checked against server — if a matching key exists, it's reused
- Otherwise, keys are uploaded (with integrity verification via
X-Content-Hash) - Inputs are encrypted locally, sent as ciphertext
- Server evaluates the FHE circuit on ciphertext
- Encrypted result returns, SDK decrypts locally
Key setup is cached per circuit. Subsequent calls skip steps 1-4. Server-side key management enforces TTL (24h default) and per-circuit caps (10 keys max).
LangChain Integration
pip install koa-fhe[langchain]
from koa_fhe.langchain import koa_tools
from langchain.agents import initialize_agent, AgentType
from langchain_openai import ChatOpenAI
agent = initialize_agent(
tools=koa_tools("http://your-koa-server:3410"),
llm=ChatOpenAI(),
agent=AgentType.OPENAI_FUNCTIONS,
)
agent.run("Is 85 greater than 80? Use encrypted comparison.")
Tools: koa_encrypted_compare, koa_encrypted_add, koa_encrypted_multiply, koa_encrypted_rigidity, koa_encrypted_schedule_analysis, koa_fhe_health.
Discovery
The FHE service exposes machine-readable metadata for agent-to-agent integration:
- OpenAPI spec:
GET /openapi.yaml - Service manifest:
GET /.well-known/x402— x402 payment info, service catalog, ERC-8004 identity - Agent aliases:
/v1/confidential/{predicate,aggregate,arithmetic,rigidity,analysis,predict}
On-chain identity: ERC-8004 Agent #21648 on Base mainnet.
Dependencies
Core (pip install koa-fhe): concrete-python + numpy. Handles compare, add, multiply, rigidity, and schedule analysis.
ML (pip install koa-fhe[ml]): adds concrete-ml for encrypted XGBoost inference. This pulls in PyTorch, scikit-learn, etc. — only install if you need predict_workload().
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file koa_fhe-0.1.2.tar.gz.
File metadata
- Download URL: koa_fhe-0.1.2.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35085aa5a7095b7315bfde50974f08e74dd7beb96ce2b09e1196e91c0eabf4f9
|
|
| MD5 |
424fbaeee9bf07c05dc6ea611c520f00
|
|
| BLAKE2b-256 |
f68d921166887247c78c6501e301e653ecb74e2aadd7398573192970454490dd
|
File details
Details for the file koa_fhe-0.1.2-py3-none-any.whl.
File metadata
- Download URL: koa_fhe-0.1.2-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be45d064a9ed5da00d5d9aae70b64bb60c3fbe02399231883cf2253936cd1330
|
|
| MD5 |
f652c5fad261edb4f9a97a955b242e8d
|
|
| BLAKE2b-256 |
f5c17f617e958685b9eea44ffb14349d34e67fd2a4720eb0180ce3b83b9246cf
|