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.

Keys

Types, versions, rotation, decryption floor, deletion and export.

A key is a name, in one app, with a type and a list of versions. Names are lowercase and flat (media, orders-v2): they appear inside capabilities (crypto:encrypt:media), so : is not allowed.

Types

TypeWhat it doesPublic half
aes256-gcmencrypt / decrypt / rewrap / datakey—
x25519encrypt / decrypt / rewrap (seal to the key, open with it)JWK for sealTo
ed25519sign / verifyJWK / JWKS
hmac-sha256hmac—

x25519 and ed25519 publish their public halves, so a caller can seal something the server opens (sealTo) or verify a signature the server made, without ever seeing a private key.

Creating a key

node ace crypto:keys:create media --type aes256-gcm
node ace crypto:keys:create inbox --type x25519
node ace crypto:keys:create webhooks --type ed25519 --exportable
await crypto.keys.create({ name: 'media', type: 'aes256-gcm', description: 'media URLs' })

A key starts with version 1, minDecryptionVersion: 1, deletionAllowed: false and exportable: false. The name is reserved forever: deleting a key does not free it.

Every key carries createdAt / createdBy and updatedAt / updatedBy (ISO 8601 strings). A new key has updatedAt equal to createdAt; a rotation, a policy change or a delete moves updatedAt, never createdAt. A key created before these fields existed and never changed since has no updatedAt (the console shows —). Each version has its own createdAt / createdBy: versions are never edited, so they have no updatedAt. The audit trail is append-only too: each event has its at.

Versions and rotation

node ace crypto:keys:rotate media
const rotated = await crypto.keys.rotate('media')   // latestVersion: 2

A rotation adds a version; it does not rewrite data. New writes use the latest version, and every ciphertext names the version that sealed it, so old ciphertext keeps opening. rewrap moves an old value to the latest version without returning the plaintext:

const { ciphertext } = await crypto.rewrap({ key: 'media', ciphertext: old })

Retiring a version

minDecryptionVersion is the floor: a version below it no longer decrypts (and rewrap on such a ciphertext fails, so a leftover row is visible instead of silently readable).

await crypto.keys.updatePolicy('media', { minDecryptionVersion: 2 })

Retire a version only after every stored ciphertext was rewrapped. The console shows each version's status: latest, decryptable, or retired.

Deletion and export

Both are off by default, on purpose.

  • Deletion destroys every version's material and marks the key deleted. It requires deletionAllowed: true first:

    await crypto.keys.updatePolicy('media', { deletionAllowed: true })
    await crypto.keys.delete('media')
  • Export returns the private material (a base64url key, or a private JWK). It requires exportable: true and the crypto:keys:export capability, and it is audited like any other operation:

    await crypto.keys.updatePolicy('media', { exportable: true })
    const { material } = await crypto.keys.export('media')

    Prefer not to export: a key that never leaves the server cannot leak from an app.

Rotating the root that seals the material

The versions above rotate a key. Independently, the root that seals every key's material can rotate too: prepend a key to crypto.keys, or switch to a KMS. While both roots are configured everything keeps working; then move the stored material:

node ace crypto:keys:reseal --dry-run   # how many versions would move
node ace crypto:keys:reseal             # move them

Keys, versions, public halves and every ciphertext stay the same — only the envelope around the private material changes. node ace agora:doctor --lib crypto --deep reports a version sealed with a retired root as a warning, and one that no configured root opens as an error (restore the root: it cannot be re-created).

Metadata, never material

Every read — the console, the CLI, the MCP tools, keys.list — returns metadata only: name, type, policy, and per version the status, kid and public JWK. The sealed material is not part of any view, and the audit trail never records it.

On this page

Partner

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

Become a partner →