Files
optima/utils/genPrivateKeys.ts
T

57 lines
1.3 KiB
TypeScript

import keypair from "keypair";
console.log(`
Generating Private Keys
-----------------
This script will go through and genrate all the keys necessary for running the Credential Manager API locally.
This process might take several minutes.
-----------------`);
const keyFiles = [
".accessToken.key",
".refreshToken.key",
".permissions.key",
".secureValues.key",
];
const publicDir = "public-keys";
await Promise.all(
keyFiles.map(async (v) => {
const privExists = await Bun.file(v)
.exists()
.then((bool) => {
if (bool) {
console.log(`'${v}' already exists`);
return true;
}
return false;
});
const pubPath = `${publicDir}/${v.replace(/\.key$/, ".pub")}`;
const pubExists = await Bun.file(pubPath)
.exists()
.then((bool) => {
if (bool) {
console.log(`'${pubPath}' already exists`);
return true;
}
return false;
});
if (!privExists || !pubExists) {
console.log(`Generating '${v}' and '${pubPath}'...`);
const keys = keypair({ bits: 4096 });
if (!privExists) {
await Bun.write(v, keys.private);
}
if (!pubExists) {
await Bun.write(pubPath, keys.public);
}
}
return;
}),
);
console.log("\nGenerated All Keys Successfully!");