/** * The Cross Events Hub's public licence key (Ed25519). Installs check every licence token with * it, so a licence can't be faked by editing the database. The matching private key exists * only on the Hub server (events-hub repo, `npm run generate-keys`). * * PRODUCTION_PUBLIC_KEY is the key the production Hub prints (also served at /api/public-key); if * the Hub key is regenerated, update it here. HUB_PUBLIC_KEY (env) overrides it — for a local Hub. */ const PRODUCTION_PUBLIC_KEY = "MCowBQYDK2VwAyEAcKpEo/JdS96wR3r9yh8uFUxBlzPUd2YKbC60fNRUhoU="; /** * A public key as proper PEM, however it was pasted: with real line breaks, with "\n", all on * one line ("-----BEGIN PUBLIC KEY-----MCow…-----END PUBLIC KEY-----"), or just the base64. */ function normalisePem(input) { const text = String(input || '').replace(/\\n/g, '\n').trim(); if (!text) return null; const body = text .replace(/-----BEGIN PUBLIC KEY-----/, '') .replace(/-----END PUBLIC KEY-----/, '') .replace(/\s+/g, ''); if (!/^[A-Za-z0-9+/]+={0,2}$/.test(body)) return text; // not base64 — let the caller's parse fail clearly const lines = body.match(/.{1,64}/g).join('\n'); return `-----BEGIN PUBLIC KEY-----\n${lines}\n-----END PUBLIC KEY-----\n`; } function hubPublicKey() { return normalisePem(process.env.HUB_PUBLIC_KEY) || normalisePem(PRODUCTION_PUBLIC_KEY); } module.exports = { hubPublicKey, normalisePem, PRODUCTION_PUBLIC_KEY };