UNPKG

@adonis-agora/agent

Version:

Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.

36 lines • 1.57 kB
// agora crypto-kit v1 — copied verbatim from _1x/shared/crypto-kit; never edit in one lib only. import { Encryption } from '@adonisjs/core/encryption'; import { AES256GCM } from '@adonisjs/core/encryption/drivers/aes_256_gcm'; /** Adonis `Encryption` over AES-256-GCM with these keys (first encrypts). */ export function gcmEncryption(keys, id = 'agora') { return new Encryption({ driver: (key) => new AES256GCM({ id, key }), keys: keys.map((key) => (typeof key === 'string' ? key : key.release())), }); } export function createKeyring(options) { const { purpose, keys, encryption } = options; if (typeof purpose !== 'string' || purpose.length === 0) { throw new Error('crypto-kit: a keyring needs a `purpose`'); } if ((keys === undefined) === (encryption === undefined)) { throw new Error('crypto-kit: give a keyring either `keys` or `encryption`'); } if (keys !== undefined && keys.length === 0) { throw new Error('crypto-kit: `keys` needs at least one key'); } if (options.kms && (typeof options.kms.wrap !== 'function' || typeof options.kms.unwrap !== 'function')) { throw new Error('crypto-kit: `kms` needs wrap() and unwrap()'); } const all = keys ? gcmEncryption(keys) : encryption; const active = keys ? (keys.length === 1 ? all : gcmEncryption(keys.slice(0, 1))) : undefined; return { purpose, all, active, kms: options.kms, legacy: [...(options.legacy ?? [])], }; } //# sourceMappingURL=keyring.js.map