26 lines
803 B
JavaScript
26 lines
803 B
JavaScript
// Generated, do not edit. sha256:ffc38e35f09c2a28784811c7505bad194c65e207ac58b284c202aff9a6c08ec2
|
|
import { randomBytes } from 'node:crypto';
|
|
|
|
import { readSecretsStore, writeSecretsStore, secretsFile } from '../keys.mjs';
|
|
|
|
const SLEUTEL = 'ai_handle_secret';
|
|
|
|
const cache = new Map();
|
|
|
|
export async function handleSecret() {
|
|
const pad = secretsFile();
|
|
if (cache.has(pad)) return cache.get(pad);
|
|
const store = await readSecretsStore();
|
|
const bestaand = store[SLEUTEL];
|
|
if (typeof bestaand === 'string' && bestaand.length >= 32) {
|
|
cache.set(pad, bestaand);
|
|
return bestaand;
|
|
}
|
|
const nieuw = randomBytes(32).toString('hex');
|
|
await writeSecretsStore({ ...store, [SLEUTEL]: nieuw });
|
|
cache.set(pad, nieuw);
|
|
return nieuw;
|
|
}
|
|
|
|
export function _resetHandleSecret() { cache.clear(); }
|