Agora

Crypto 1.x is a release candidate. npm's latest tag still installs 0.x, so install these docs' version from the rc tag:

npm i @adonis-agora/crypto@rc
node ace configure @adonis-agora/crypto

The same goes for every @adonis-agora/* package these docs install: add @rc, and where a page says node ace add, install with @rc first and then run node ace configure. On 0.x? Read the 0.x docs.

Integrations

The 0.x package that plugs @adonis-agora/crypto into authkit, agent, config, durable, flags, collaboration and any HTTP call — without touching the rc libs.

@adonis-agora/crypto-integrations holds the seams between the crypto server and the other Agora libs. It stays 0.x on purpose: the rc libs are untouched, and every integration is one small import instead of a config option added to a package you already tested.

It works the same with the crypto server embedded in the app or remote:

// remote (topology: 'tenant', or an app calling a central server)
const source = { client: crypto }              // a CryptoClient

// embedded (standalone / control-plane): no HTTP hop
const source = { service, partition: 'meuprontoo' }

Every helper takes { source, key? }; each subpath defaults to its lib's key convention.

KMS roots — /authkit, /agent, /config

node ace crypto:keys:create authkit-root --type aes256-gcm
node ace crypto:keys:create agent-poppy-root --type aes256-gcm
node ace crypto:keys:create config-root --type aes256-gcm
config/authkit.ts
import { authkitKms, authkitKmsCheck } from '@adonis-agora/crypto-integrations/authkit'

export default defineConfig({
  // …
  crypto: { kms: authkitKms({ source: { client: crypto } }) },
})
config/poppy.ts (agent)
import { agentPoppyKms, agentPoppyKmsCheck } from '@adonis-agora/crypto-integrations/agent'

export default defineConfig({
  // …
  crypto: { kms: agentPoppyKms({ source: { client: crypto } }) },
})
config/config.ts (config control plane)
import { configKms, configKmsCheck } from '@adonis-agora/crypto-integrations/config'

export default defineConfig({
  topology: 'control-plane',
  verifyTenant,
  crypto: { kms: configKms({ source: { client: crypto } }) },
})

Each lib then seals every value with a data key wrapped by its root on the crypto server: rotating the root is node ace crypto:keys:rotate authkit-root, old values keep opening, and no key material sits in the lib's database. The keyring's purpose is bound into the wrap, so a data key from authkit-root cannot open a config value.

Doctor

import { registerDoctorChecks } from '@adonis-agora/crypto'
import { authkitKmsCheck } from '@adonis-agora/crypto-integrations/authkit'

await registerDoctorChecks(app.container, [authkitKmsCheck({ source: { client: crypto } })])

node ace agora:doctor --lib authkit --deep then reports authkit.kms: the key exists, it is an aes256-gcm key, and this process really sealed and opened a value with it — which catches a missing key, a wrong type, a token without crypto:encrypt:<key> / crypto:decrypt:<key>, and a crypto server whose root changed. Two audit rows per run, by design.

durable — /durable

durable accepts a ready instance for transport and controlPlane, so the decorators wrap whatever you already configured:

config/durable.ts
import { encryptedControlPlane, encryptedTransport } from '@adonis-agora/crypto-integrations/durable'

export default defineConfig({
  transports: {
    default: encryptedTransport(transports.redis({ connection: 'main' }), {
      source: { client: crypto },
      key: 'durable-tasks',
    }),
  },
  controlPlane: encryptedControlPlane(new RedisControlPlane({ connection: 'main' }), {
    source: { client: crypto },
    key: 'durable-tasks',
    aad: 'control',
  }),
})

What is sealed and what stays readable:

MessageSealedClear (routing / dedupe)
dispatch(task)inputrunId, seq, stepId, name, group, attempt, priority, traceparent, transport
onResultoutput, a step errorrunId, seq, stepId, status, startedAt
onHeartbeatprogressrunId, stepId, group, at
publishControl (event)eventkind, from, runId
publishControl (cancel/enqueued/schedulePause)—everything (routing only)

onControl keeps the broker's delivery order: every message, encrypted or not, goes through one serialized chain before the handler runs, so an enqueued can never overtake the completed before it.

:::warning Interop An encrypted channel is not readable by a plain consumer. A NestJS fleet (or any service without the decorator) on the same Redis channel sees sealed event payloads it cannot open — upgrade both sides together, or run the encrypted plane on its own channel. The same applies to workers: a worker without encryptedTransport receives { agoraSealed } instead of input. :::

strict: true makes the receiver refuse a plain payload instead of passing it through (use it once the whole fleet is upgraded; during a rollout the default passes plain values untouched).

collaboration — /collaboration

collaborationCodec is a storage codec for @adonis-agora/collaboration: document state, version snapshots, comment bodies and anchors of the matched documents are encrypted before they reach the database; the server keeps working on plaintext in memory.

With subject keys (crypto.subjects), each document is sealed with its owner's key, so forgetting the subject shreds their documents too:

config/collaboration.ts
import { defineConfig, lucidStorage } from '@adonis-agora/collaboration'
import crypto from '@adonis-agora/crypto/services/main'
import { collaborationCodec } from '@adonis-agora/crypto-integrations/collaboration'

export default defineConfig({
  engine: 'yjs',
  storage: lucidStorage({
    connection: 'primary',
    codec: collaborationCodec({
      // only the thesis is encrypted; whiteboards pass through untouched
      docs: /^projects\/([^/]+)\/writing$/,
      subjects: () => crypto.subjects,
      subject: async ([, projectId]) => ({ type: 'researcher', id: await ownerOf(projectId) }),
    }),
  }),
})

With a named key on the crypto server instead:

codec: collaborationCodec({
  source: { client: crypto },        // or { service, partition } when embedded
  key: 'collab-docs',                // or (match, ctx) => a key per document
})
OptionDefault
docsevery documenta RegExp on docName (its match goes to subject/key), or (docName) => match | null
subjects + subject—per-subject keys; subject(match, ctx) returns the subject (may be async)
source + key—a named key; key may be a function of (match, ctx)
aad["agora:collab", docName, kind, field, versionId ?? commentId ?? null]binds a value to its row and column
envelopefalsenamed key only, see below

Binary values (state, snapshot) are base64'd and sealed; the stored value is the ciphertext string. A value that does not open (wrong key, moved to another row, tampered) throws, and the collaboration storage then refuses to overwrite that document. Rows written before the codec was configured are read as plaintext and encrypted on their next save, or all at once with node ace collaboration:reencode.

Envelope mode

Large Yjs states sent to a remote crypto server cost a round trip and the payload on every save. envelope: true (or { ttlMs, maxEntries }, default 5 minutes / 500 documents) seals locally with AES-256-GCM under a data key per document; the data key is wrapped by key on the server once per document and ttlMs, and travels in the value (agora:ce1:…). Both formats always open, so the option can be turned on or off without touching stored rows. Subject keys already work this way and do not take the option.

flags — /flags

config/flags.ts
import { flagsEnvelope } from '@adonis-agora/crypto-integrations/flags'

const envelope = flagsEnvelope({ source: { client: crypto }, aad: 'flags' })

export default defineConfig({
  // …
  transport: transports.http({
    url: env.get('FLAGS_URL'),
    token,
    partition: 'streaming',
    ...envelope,                        // { fetch }
  }),
  sinks: [
    sinks.posthog({ apiKey: env.get('POSTHOG_KEY'), ...envelope }),
    sinks.clickhouse({ url: env.get('CLICKHOUSE_URL'), ...envelope }),
  ],
})

transports.http and the posthog/clickhouse sinks take a fetch; every batch they send is sealed to the flags server, which opens it with the same key (flags-events by default).

Any HTTP call — /http

import { httpEnvelope } from '@adonis-agora/crypto-integrations/http'

const envelope = httpEnvelope({ source: { client: crypto }, key: 'svc-config' })

// authkit token requests
const token = authkitTenantToken({ issuer, clientId, clientSecret, resource: 'urn:agora:config', ...envelope })

// config tenant fetches
const config = createConfigClient({ url, partition: 'streaming', token, ...envelope })

The receiver uses cryptoEnvelopeMiddleware({ client, key }) (or { service, partition }) from @adonis-agora/crypto, and cryptoEnvelopeReply() to answer encrypted. See encrypted requests.

Secrets stored in config, decrypted by the app

config.kms (above) protects the values config seals itself. When the value must stay unreadable to the control plane, config stores a crypto reference instead of a secret, and the app resolves it:

config/config.ts (control plane: encrypt only)
import { configCrypto } from '@adonis-agora/crypto-integrations/config'

const secrets = configCrypto({ source: { client: crypto }, key: 'config-root' })

// writing an entry: the value stored is { key, ciphertext } — never the plaintext
const reference = await secrets.seal('hunter2', {
  app, environment, label, key: 'db.password',
})
the app (decrypt only)
const secrets = configCrypto({ source: { client: crypto } })
const password = await secrets.open(entry.value, { app, environment, label, key })
PieceValue
stored value{ "key": "config-root", "ciphertext": "agora:ct1:config-root:1:…" }
keyaes256-gcm, config-root, in one partition both sides address (a dedicated platform, or the control plane's)
control plane tokencrypto:encrypt:config-root (+ crypto:keys:read for the console) — never decrypt
app tokencrypto:decrypt:config-root — never encrypt
AADconfig:<app>:<environment>:<label>:<key> (configCryptoAad)
allow-listkeys (default [key]): a reference naming another key is refused before any call

isCryptoReference(value) and parseReference(value) are exported so config can mask the value and validate it without knowing crypto; a rotation keeps old references opening (keys lists the old root during the window). Works with the server embedded ({ service, partition }) or remote ({ client }), and every seal/open is audited by the crypto server.

Auditing a recipient-held open

Server-held opens are audited by the crypto server. A sealTo share is opened on the recipient's device, so the app emits crypto:sealed.open with sealedOpenEvent({ actor, subject, key, kid, resource }): actor ?? sub (the crypto audit's own rule), the kid that opened it and a timestamp. openWithAudit() in @adonis-agora/crypto-react returns the value plus kid/at for that event.

Adopting it without a dependency

The Agora rule is that a lib does not depend on another product lib, and crypto-integrations is not on npm yet. Until it is, a lib can implement the same seams structurally — these are the whole contract, and they are stable:

// 1. the stored reference (server-held), nothing else
type CryptoReference = { key: string; ciphertext: string }

// 2. the AAD both sides derive
const configCryptoAad = (entry: { app: string; environment: string; label?: string; key: string }) =>
  `config:${entry.app}:${entry.environment}:${entry.label ?? 'main'}:${entry.key}`

// 3. the audit payload + channel (recipient-held)
//    payload.event = 'crypto:sealed.open'
//    channel       = `agora:${lib}:sealed.open`   (lib = the emitter, e.g. 'config')
//    shape         = { event, v: 1, actor, subject?, key, kid?, resource?, at, result }

Capabilities: sealing needs crypto:encrypt:<key>, opening needs crypto:decrypt:<key>; the emitting lib's token never holds the other half. decrypt accepts a context (≤200 chars, no control characters) recorded as metadata.context on the crypto audit, refusals included.

When @adonis-agora/crypto-integrations 0.1.0 is published, swap the copies for configCrypto/configCryptoAad/sealedOpenEvent/sealedOpenChannel — or add the package as an optional peer, the same way @adonis-agora/authkit-client is optional elsewhere.

Seams still missing in the rc libs

These would make an integration cleaner, but are not changed today:

LibFileWhat is missing
flagspackages/adonis/src/topology/remote_source.tsthe tenant ruleset fetch builds its own fetch; a fetch option (like transports.http) would let the ruleset read be encrypted too
durablepackages/adonis/src/transports/*dispatchWorkflowTask, dispatchStepEvent and the P4 start-run/run-request/reply/tenant-event methods carry payloads the decorator does not cover yet; a hook per payload (or a sealPayload option) would close them
configpackages/client/src/client.tsfetch already exists; a payloadCodec would let the whole document be sealed, not just the transport
configpackages/adonis/src/admin.tsthe result of sealTo/configCrypto.seal needs a place on an entry (a crypto field next to sealedTo); today a reference is just a JSON value the console must not reveal
authkit-serversrc/crypto/authkit_crypto.tskms exists; a kmsKey name convention would remove the custom key option

On this page

Partner

Your product as the official integration for Crypto, right here.

Become a partner →