initialize project with basic structure and dependencies

This commit is contained in:
ImBenji
2026-04-27 22:26:40 +01:00
parent a3b3bd6b04
commit 83f2837ce6
7 changed files with 250 additions and 6 deletions
+31
View File
@@ -0,0 +1,31 @@
import { createPublicKey, verify } from "crypto";
function getPublicKey() {
const b64 = process.env.LICENSE_PUBLIC_KEY;
if (!b64) throw createError({ statusCode: 500, message: "License system not configured" });
return createPublicKey({
key: Buffer.from(b64, "base64"),
format: "der",
type: "spki",
});
}
export function verifyLicenseKey(key: string): boolean {
try {
const pubKey = getPublicKey();
const now = Math.floor(Date.now() / 1000 / 300);
const sig = Buffer.from(key, "base64url");
// accept current window and the one before (edge case tolerance)
for (const window of [now, now - 1]) {
const msg = Buffer.from(String(window));
if (verify(null, msg, pubKey, sig)) return true;
}
return false;
} catch {
return false;
}
}