Stateless REST API for Fully Homomorphic Encryption using Fhenix CoFHE SDK.
- Encrypt all FHE types:
euint8,euint16,euint32,euint64,euint128,euint256,eaddress,ebool - Worker Thread Pool for parallel encryption
- Docker-ready deployment
- OpenAPI/Swagger documentation
- Health checks (liveness + readiness)
- RFC 7807 error responses
docker-compose -f docker/docker-compose.yml up -dnpm install
npm run build
npm run start:prodThe service will be available at http://localhost:3000.
POST /api/v1/encrypt
Content-Type: application/json
{
"type": "euint64",
"value": "1000000"
}Supported types: euint8, euint16, euint32, euint64, euint128, euint256, eaddress, ebool
Note:
contractAddressanduserAddressare optional for Fhenix (not required for encryption).
POST /api/v1/encrypt/uint8
POST /api/v1/encrypt/uint16
POST /api/v1/encrypt/uint32
POST /api/v1/encrypt/uint64
POST /api/v1/encrypt/uint128
POST /api/v1/encrypt/uint256
POST /api/v1/encrypt/address
POST /api/v1/encrypt/boolEncrypt multiple values in a single request (max 10 items).
POST /api/v1/encrypt/batch
Content-Type: application/json
{
"items": [
{ "type": "euint64", "value": "1000000" },
{ "type": "ebool", "value": true },
{ "type": "eaddress", "value": "0xabcdef0123456789abcdef0123456789abcdef01" }
]
}Batch Response:
{
"results": [
{
"type": "euint64",
"data": "0x...",
"inputProof": "0x...",
"encryptionTimeMs": 1200
}
],
"totalEncryptionTimeMs": 3500
}All-or-nothing: if any item fails, the entire batch returns an error.
{
"type": "euint64",
"data": "0x1234...abcd",
"inputProof": "0xabcd...1234",
"encryptionTimeMs": 2350
}GET /health # Liveness probe
GET /health/ready # Readiness probe (CoFHE SDK initialized)Swagger UI available at /api/docs.
| Variable | Default | Description |
|---|---|---|
PORT |
3000 |
HTTP server port |
NODE_ENV |
development |
Environment mode |
LOG_LEVEL |
info |
Logging level (debug, info, warn, error) |
| Variable | Default | Description |
|---|---|---|
WORKER_MIN_THREADS |
2 |
Minimum worker threads |
WORKER_MAX_THREADS |
CPU cores |
Maximum worker threads |
WORKER_IDLE_TIMEOUT |
60000 |
Idle timeout (ms) |
WORKER_MAX_QUEUE |
100 |
Maximum queued tasks |
WORKER_TASK_TIMEOUT |
45000 |
Task timeout (ms) |
| Variable | Default | Description |
|---|---|---|
COFHE_CHAIN_ID |
421614 |
Blockchain chain ID |
COFHE_NETWORK_NAME |
Arbitrum Sepolia |
Network name |
COFHE_RPC_URL |
https://sepolia-rollup.arbitrum.io/rpc |
RPC URL |
COFHE_ENV |
testnet |
Environment (mock/testnet) |
| Network | Chain ID | RPC URL |
|---|---|---|
| Arbitrum Sepolia | 421614 | https://sepolia-rollup.arbitrum.io/rpc |
| Ethereum Sepolia | 11155111 | https://eth-sepolia.public.blastapi.io |
src/
├── domain/ # Business logic, value objects, errors
├── application/ # Use cases, DTOs
├── infrastructure/ # Worker pool, CoFHE SDK integration
└── interface/ # Controllers, filters, health checks
Uses Piscina for CPU parallelism and fault isolation. Each worker maintains its own CoFHE SDK instance for thread-safe encryption.
- Node.js 24+
- npm 10+
npm installnpm run start:dev # Development with watch
npm run start:prod # Productionnpm test # Unit tests
npm run test:cov # With coverage
npm run test:e2e # E2E testsdocker build -f docker/Dockerfile -t cofhe-worker .All errors follow RFC 7807 Problem Details format:
{
"type": "urn:fhe:error:encryption-failed",
"title": "Encryption Failed",
"status": 500,
"detail": "Failed to encrypt uint64",
"instance": "/api/v1/encrypt/uint64"
}| Error | Status | Type URN |
|---|---|---|
| Validation failed | 400 | urn:fhe:error:validation |
| Invalid address | 422 | urn:fhe:error:invalid-address |
| Value out of range | 422 | urn:fhe:error:invalid-value |
| Unsupported type | 422 | urn:fhe:error:unsupported-type |
| Encryption failed | 500 | urn:fhe:error:encryption-failed |
| Internal error | 500 | urn:fhe:error:internal |
| CoFHE not ready | 503 | urn:fhe:error:not-initialized |
| Initialization failed | 503 | urn:fhe:error:initialization-failed |
| Pool exhausted | 503 | urn:fhe:error:pool-exhausted |
| Timeout | 504 | urn:fhe:error:timeout |
MIT