/** * 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`). * * Set PRODUCTION_PUBLIC_KEY to the key the production Hub prints, before the release that ships * the Hub connection. HUB_PUBLIC_KEY (env) overrides it — for a local Hub while developing. */ const PRODUCTION_PUBLIC_KEY = null; /** * 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) || PRODUCTION_PUBLIC_KEY; } module.exports = { hubPublicKey, normalisePem, PRODUCTION_PUBLIC_KEY };