Versie 0.2.0
This commit is contained in:
commit
e77d8fd373
495 files changed
+81026
No files matched your search
@@ -0,0 +1,25 @@
|
||||
// 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(); }
|
||||
Reference in new issue
Block a user