Hub 2.0 step 1: products foundation
- Product enum (events, accounts, website, app) on Licence and Install, Install.publicKey; existing rows are events - One open licence per product per customer: partial unique index, with a migration guard that names customers with duplicates (npm run check:hub2 lists them beforehand) - Licence keys per product (CEH-, CCA-, CCW-, CCP-); free Accounts licence created with the first other product licence - Protocol v1 registers Events licences only (409 WRONG_PRODUCT); only Events licences can be invoiced until billing per customer - Cross Code Hub in the UI, emails and PDFs - @crosscode/contracts 1.0.0 vendored (backend/vendor) - Steps merge into release/2.0, not main (plan updated) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
const crypto = require('crypto');
|
||||
const { KEY_PREFIXES } = require('./products');
|
||||
|
||||
let cachedKey = null;
|
||||
function key() {
|
||||
@@ -35,11 +36,16 @@ function decrypt(stored) {
|
||||
// No 0/O, 1/I/L, 5/S, 8/B — easy to read out over the phone.
|
||||
const KEY_ALPHABET = 'ACDEFGHJKMNPQRTUVWXY234679';
|
||||
|
||||
/** A licence key: CEH-XXXX-XXXX-XXXX-XXXX (16 characters from 26, ~75 bits of randomness). */
|
||||
function licenceKey() {
|
||||
/**
|
||||
* A licence key for a product: CEH-XXXX-XXXX-XXXX-XXXX for Events, CCA-/CCW-/CCP- for Accounts,
|
||||
* Website and App (16 characters from 26, ~75 bits of randomness).
|
||||
*/
|
||||
function licenceKey(product = 'events') {
|
||||
const prefix = KEY_PREFIXES[product];
|
||||
if (!prefix) throw new Error(`Unknown product: ${product}`);
|
||||
const bytes = crypto.randomBytes(20);
|
||||
const chars = Array.from(bytes, b => KEY_ALPHABET[b % KEY_ALPHABET.length]).join('');
|
||||
return `CEH-${chars.slice(0, 4)}-${chars.slice(4, 8)}-${chars.slice(8, 12)}-${chars.slice(12, 16)}`;
|
||||
return `${prefix}-${chars.slice(0, 4)}-${chars.slice(4, 8)}-${chars.slice(8, 12)}-${chars.slice(12, 16)}`;
|
||||
}
|
||||
|
||||
/** Tidy what someone typed: upper case, no spaces. */
|
||||
|
||||
Reference in New Issue
Block a user