// Generates the Ed25519 signing key into the vault (chmod 600). Prints only the public key id.
import fs from 'node:fs';
const out = process.argv[2] || '/home/box/crypto-vault/agentcomply-signing-key.json';
if (fs.existsSync(out)) { console.log('key already exists, not overwriting:', out); process.exit(0); }
const kp = await crypto.subtle.generateKey({ name: 'Ed25519' }, true, ['sign', 'verify']);
const jwk = await crypto.subtle.exportKey('jwk', kp.privateKey);
const kidBuf = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(jwk.x));
const kid = [...new Uint8Array(kidBuf)].slice(0, 8).map((b) => b.toString(16).padStart(2, '0')).join('');
fs.writeFileSync(out, JSON.stringify({ kty: 'OKP', crv: 'Ed25519', x: jwk.x, d: jwk.d, kid, created: new Date().toISOString(), purpose: 'AgentComply receipt signing' }), { mode: 0o600 });
fs.chmodSync(out, 0o600);
console.log('wrote', out, '(chmod 600) kid', kid);
agentgate-source: code mirror on Cloudflare Pages. All repos