@enc-protocol/cloud — SDK Reference
Client SDK for the ENC Cloud provisioner. Manages tenants, enclaves, billing, and faucet.
Install
npm install @enc-protocol/cloud --registry https://npm-registry.ocrybit.workers.dev/Quick Start
import { CloudClient } from '@enc-protocol/cloud'
const cloud = new CloudClient('https://enc-cloud.ocrybit.workers.dev', myPubKeyHex)
// Deploy an enclave
const { data } = await cloud.deployEnclave('Personal', 'My Personal')
console.log('Enclave:', data.enclave_id)
// Check billing
const { data: billing } = await cloud.getBillingUsage()
console.log('Due:', billing.due_usdt, 'USDT')CloudClient
Constructor
new CloudClient(baseUrl, pubKey?)baseUrl— Provisioner URL (e.g.,https://enc-cloud.ocrybit.workers.dev)pubKey— 64-hex secp256k1 public key for authenticated requests
All methods return { status: number, data: any }.
Public (no auth required)
getTemplates()
List available enclave templates.
const { data } = await cloud.getTemplates()
// [{ id: 'Personal', name: 'Personal', description: '...' }, ...]getConfig(key)
Read a config value.
const { data } = await cloud.getConfig('usdt_address')
// { key: 'usdt_address', value: '0x5fbd...' }getFaucetWhitelist()
const { data } = await cloud.getFaucetWhitelist()
// { whitelist: ['0x...', ...], open: true }getFaucetClaim(address)
Check if an address has claimed faucet funds.
const { data } = await cloud.getFaucetClaim('0x1234...')
// { claimed: false } or { claimed: true, eth_tx: '...', usdt_tx: '...', ... }Tenant
register(pubKey, name)
Register a new tenant. Idempotent.
const { data } = await cloud.register(pubKeyHex, 'Alice')
// { ok: true, pub_key: '...' }Enclaves (auth required)
deployEnclave(template, name?, nodeId?)
Deploy an enclave from a template. The provisioner creates it on the node server-side.
const { data } = await cloud.deployEnclave('Personal', 'My Vault')
// {
// enclave_id: '64-hex',
// seq_pub: '64-hex (node public key)',
// template: 'Personal',
// node_id: 'shared-1',
// node_url: 'https://enc-node.ocrybit.workers.dev',
// name: 'My Vault'
// }Templates: Hello, DM, Group, Personal, Registry, Timeline
listEnclaves()
const { data } = await cloud.listEnclaves()
// [{ enclave_id, template, node_id, node_url, node_type, name, status, created_at }, ...]deleteEnclave(enclaveId)
Stop an enclave. State persists on the node but no new commits are accepted.
const { data } = await cloud.deleteEnclave(enclaveId)
// { ok: true, enclave_id: '...', status: 'stopped' }registerEnclave(enclaveId, template?, nodeId?, name?)
Register an externally-created enclave with the provisioner.
await cloud.registerEnclave(enclaveId, 'custom', 'shared-1', 'My Custom')Nodes
listNodes()
const { data } = await cloud.listNodes()
// [{ node_id: 'shared-1', type: 'shared', url: '...', enc_v: 2, status: 'running' }]Billing
getBillingUsage()
Server-authoritative billing. Fetches event counts from each enclave's node STH.
const { data } = await cloud.getBillingUsage()
// {
// enclaves: [{ enclave_id, name, events, cost_usdt }],
// total_events: 301,
// paid_events: 0,
// due_events: 301,
// price_per_event: 0.001,
// currency: 'USDT',
// gross_usdt: 0.301,
// paid_usdt: 0,
// due_usdt: 0.301,
// treasury: '0xf39F...',
// usdt_address: '0x5fbd...'
// }recordPayment(txHash)
Record an on-chain USDT payment. Server verifies the tx on-chain.
const { data } = await cloud.recordPayment('0x...')
// { ok: true, tx_hash: '0x...', amount: '0.301', events_billed: 301, chain_id: 31340 }listPayments()
const { data } = await cloud.listPayments()
// [{ id, pub_key, tx_hash, amount, currency, events_billed, chain_id, status, created_at }]Usage
getUsage()
const { data } = await cloud.getUsage()
// { enclaves: 3, dedicated_nodes: 0, events_total: 0, storage_bytes: 0 }Faucet (auth required)
claimFaucet(address)
Claim testnet ETH + USDT. One claim per address.
const { data } = await cloud.claimFaucet('0x1234...')
// { ok: true, address: '0x...', eth_tx: null, usdt_tx: '0x...', eth_wei: '0x...', usdt_units: '0x...' }Admin
setConfig(key, value, adminToken)
await cloud.setConfig('usdt_address', '0x...', adminToken)addToWhitelist(address, adminToken)
await cloud.addToWhitelist('0x...', adminToken)removeFromWhitelist(address, adminToken)
await cloud.removeFromWhitelist('0x...', adminToken)Error Handling
All methods return { status, data }. Check status:
const { status, data } = await cloud.deployEnclave('Bad')
if (status !== 200) {
console.error(data.error) // "Unknown template: Bad. Available: Hello, DM, ..."
}| Status | Meaning |
|---|---|
| 200 | Success |
| 400 | Bad request (invalid input) |
| 401 | Auth required (missing Bearer token) |
| 403 | Forbidden (wrong tenant, not whitelisted) |
| 404 | Not found (unknown tenant, enclave, or route) |
| 409 | Conflict (duplicate payment, already claimed) |
| 502 | Node unreachable |
| 503 | Server misconfigured (missing USDT address, etc.) |