UNPKG

@adonis-agora/agent

Version:

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

29 lines • 1.37 kB
// agora crypto-kit v1 — copied verbatim from _1x/shared/crypto-kit; never edit in one lib only. import { randomBytes } from 'node:crypto'; import { Encryption } from '@adonisjs/core/encryption'; import { AES256GCM } from '@adonisjs/core/encryption/drivers/aes_256_gcm'; /** * A KMS that lives in memory, for tests and local development: Adonis' AES-256-GCM under a master * key that never leaves the process (pass the same `masterKey` to read values back later). */ export function createInMemoryKms(masterKey = randomBytes(32).toString('base64url')) { const encryption = new Encryption({ driver: (key) => new AES256GCM({ id: 'kms', key }), keys: [masterKey], }); const purposeOf = (context) => `kms:${context.purpose}`; return { wrap(dataKey, context) { const payload = Buffer.from(dataKey).toString('base64url'); return Buffer.from(encryption.encrypt(payload, { purpose: purposeOf(context) }), 'utf8'); }, unwrap(wrapped, context) { const payload = encryption.decrypt(Buffer.from(wrapped).toString('utf8'), purposeOf(context)); if (typeof payload !== 'string') { throw new Error('crypto-kit: in-memory KMS could not unwrap'); } return Buffer.from(payload, 'base64url'); }, }; } //# sourceMappingURL=kms.js.map