@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
31 lines • 1.07 kB
JavaScript
import { calculateJwkThumbprint, exportJWK, generateKeyPair, importJWK } from 'jose';
export async function generateEs256Key() {
const { privateKey, publicKey } = await generateKeyPair('ES256', { extractable: true });
const pub = await exportJWK(publicKey);
const priv = await exportJWK(privateKey);
const kid = await calculateJwkThumbprint(pub, 'sha256');
return {
kid,
privateJwk: { ...priv, kid, alg: 'ES256', use: 'sig' },
publicJwk: { ...bareEcPublicJwk(pub), kid, alg: 'ES256', use: 'sig' },
};
}
const cache = new WeakMap();
export function importSigningKey(key) {
let p = cache.get(key);
if (!p) {
p = importJWK(key.privateJwk, 'ES256');
cache.set(key, p);
}
return p;
}
/** Only the public members of an EC JWK, as embedded in a DPoP header (RFC 9449 4.2). */
export function bareEcPublicJwk(jwk) {
const out = {};
for (const k of ['kty', 'crv', 'x', 'y']) {
if (jwk[k] !== undefined)
out[k] = jwk[k];
}
return out;
}
//# sourceMappingURL=keys.js.map