initialize project with basic structure and dependencies
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env node
|
||||
import { createPrivateKey, sign } from "crypto";
|
||||
import { readFileSync } from "fs";
|
||||
import { resolve, dirname } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
const envPath = resolve(dirname(fileURLToPath(import.meta.url)), "../.env");
|
||||
|
||||
let privateKeyB64 = process.env.LICENSE_PRIVATE_KEY;
|
||||
|
||||
if (!privateKeyB64) {
|
||||
try {
|
||||
const envContents = readFileSync(envPath, "utf8");
|
||||
const match = envContents.match(/^LICENSE_PRIVATE_KEY=(.+)$/m);
|
||||
if (match) privateKeyB64 = match[1].trim();
|
||||
} catch {}
|
||||
}
|
||||
|
||||
if (!privateKeyB64) {
|
||||
console.error("LICENSE_PRIVATE_KEY not found in env or .env file");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const window = Math.floor(Date.now() / 1000 / 300);
|
||||
const msg = Buffer.from(String(window));
|
||||
|
||||
const privateKey = createPrivateKey({
|
||||
key: Buffer.from(privateKeyB64, "base64"),
|
||||
format: "der",
|
||||
type: "pkcs8",
|
||||
});
|
||||
|
||||
const sig = sign(null, msg, privateKey);
|
||||
const key = sig.toString("base64url");
|
||||
|
||||
const minutesLeft = 5 - (Math.floor(Date.now() / 1000) % 300) / 60;
|
||||
|
||||
console.log(`\nLicense key (valid for ~${minutesLeft.toFixed(1)} more minutes):\n`);
|
||||
console.log(key);
|
||||
console.log();
|
||||
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env node
|
||||
import { generateKeyPairSync } from "crypto";
|
||||
|
||||
const { privateKey, publicKey } = generateKeyPairSync("ed25519", {
|
||||
privateKeyEncoding: { type: "pkcs8", format: "der" },
|
||||
publicKeyEncoding: { type: "spki", format: "der" },
|
||||
});
|
||||
|
||||
console.log("Add these to your .env files:\n");
|
||||
console.log(`LICENSE_PRIVATE_KEY=${privateKey.toString("base64")}`);
|
||||
console.log(`LICENSE_PUBLIC_KEY=${publicKey.toString("base64")}`);
|
||||
console.log("\nLICENSE_PRIVATE_KEY goes on your LOCAL machine only.");
|
||||
console.log("LICENSE_PUBLIC_KEY goes on the SERVER .env only.");
|
||||
Reference in New Issue
Block a user