Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Building with the SDK

A short tour of building on ENC from code. Where the SDK Reference documents every function, this gets you from zero to a verified read/write in a few steps using the @enc-protocol/client high-level surface (which re-exports the core primitives it needs).

Install

npm config set @enc-protocol:registry https://npm-registry.ocrybit.workers.dev/
npm install @enc-protocol/client @enc-protocol/core

1. Create an identity

import { createIdentity, createNodeClient } from '@enc-protocol/client'
 
const me = createIdentity()                 // random Schnorr keypair
const client = createNodeClient('https://your-node.example.com')

An identity is just a keypair; nothing is registered with anyone. Point the client at any ENC node.

2. Create an enclave

An enclave is defined by a manifest — its RBAC schema, states, traits, and initial roles. Submitting a signed manifest commit mints the enclave; its id is derived deterministically from the manifest.

import { createManifestCommit } from '@enc-protocol/client'
 
const manifest = JSON.stringify({
  enc_v: 2, nonce: Date.now(),
  RBAC: {
    use_temp: 'none',
    schema: [
      { event: 'post', role: 'owner', ops: ['C', 'U', 'D'] },
      { event: '*',    role: 'Public', ops: ['R'] },
    ],
    states: [], traits: ['owner(0)'],
    initial_state: { owner: [me.publicKeyHex] },
  },
})
 
const manifestCommit = createManifestCommit(me, manifest)
const enclaveId = manifestCommit.enclave                 // deterministic id
const { sequencer: seqPubHex } = await client.submitCommit(manifestCommit)

3. Submit and read events

import { createCommit, verifyNodeReceipt } from '@enc-protocol/client'
 
// write
const receipt = await client.submitCommit(
  createCommit(me, enclaveId, 'post', JSON.stringify({ body: 'hello' })),
)
console.log(verifyNodeReceipt(receipt, seqPubHex))   // true — node co-signed it
 
// read
const { events } = await client.pull(-1, { enclave: enclaveId, limit: 100 })
for (const e of events) console.log(e.seq, e.type, e.content)

4. Verify without trusting the node

Every read is independently checkable. Verify the Signed Tree Head and each event's signatures locally — no trust in the operator:

import { verifySTH, hexToBytes } from '@enc-protocol/core/crypto.js'
import { verifyEvent } from '@enc-protocol/core/event.js'
 
const sth = await client.getSTH(enclaveId)
console.log(verifySTH(sth.t, sth.ts, hexToBytes(sth.r), sth.sig, hexToBytes(seqPubHex)))
 
for (const e of events) console.log(e.seq, verifyEvent(e))   // author + sequencer sigs

For inclusion and consistency proofs, see core's CT module.

Pick your level

You want to…Use
Drive an existing app with typed methodsan App SDK@enc-protocol/<app>-cli
Build your own app / protocol logiccore + client
Run the whole protocol in-process (tests, local dev)memory
Encrypt contenta confidentiality plugin

See also