Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(project-limit): the flip release, not a red test, enforces owner step O1

reviewd82d4ec527f1
diff --git a/docs/project-limit.md b/docs/project-limit.md
index e0bc1e563..9e632ec75 100644
--- a/docs/project-limit.md
+++ b/docs/project-limit.md
@@ -222,28 +222,33 @@ with "Up to N open projects", lists "Unlimited open projects" under Pro, and the
deadline past the new plan — ship it before the frozen date passes.
- Freezing in the first release *after* the flip removes the hazard. Its cost: DO_NOT_TRACK
installs on the release before it stay ungated until that release's own deadline passes.
-3. **After an undo**, unfreeze: a release with `FROZEN = false` and a deadline past the new plan
+3. **The flip release needs owner step O1**: a frozen release is refused while
+ `PROJECT_ALLOWANCE_PUBLIC_KEY` is empty (see O1 — and do it well before then).
+4. **After an undo**, unfreeze: a release with `FROZEN = false` and a deadline past the new plan
(see Undo below — without it, DO_NOT_TRACK installs stay gated).
-4. Keep both constants in their literal one-line form —
+5. Keep both constants in their literal one-line form —
`export const PROJECT_LIMIT_DEADLINE_MS = Date.parse('<ISO instant>')` and
`export const PROJECT_LIMIT_DEADLINE_FROZEN = true | false` — because the guard reads the source.
**The guard**: `scripts/check-project-limit-deadline.mjs` is the first step that runs in each build
job of `.github/workflows/release.yml` — `release-mac`, `release-linux` and `release-win` — right
after checkout and setup-node, before `npm ci` (plain node). It exits 1 when the deadline is less
-than 30 days away and not frozen, or when it cannot read the constants. The three jobs run in
+than 30 days away and not frozen, or when it cannot read the constants; and for a **frozen** (flip)
+release also when `PROJECT_ALLOWANCE_PUBLIC_KEY` (`src/core/project-allowance-key.ts`) is empty,
+unreadable, not an Ed25519 public-key PEM, or a private key. An unfrozen release never looks at the
+key. The three jobs run in
parallel and each creates the release on its first upload, so a refused tag fails all three before
anything is built or uploaded: no release, not even a prerelease, and `publish` never runs. Bump the
deadline, then move the tag to that commit (or tag the next version) and rerun.
`scripts/check-project-limit-deadline.test.ts` pins the guard's reading to the compiled constants,
so a change of literal form fails on the PR, not on release day, and pins the step's place in all
-three jobs. It never guards a frozen deadline — that is item 2's hazard.
+three jobs. It never guards a frozen deadline's DATE — that is item 2's hazard.
## Before Release B ships — owner decisions
-### O1: the allowance key pair (merge guard)
+### O1: the allowance key pair
-`PROJECT_ALLOWANCE_PUBLIC_KEY` in `src/core/project-allowance-key.ts` is `''` until the owner
+`PROJECT_ALLOWANCE_PUBLIC_KEY` in `src/core/project-allowance-key.ts` ships as `''` until the owner
generates the key pair:
```sh
@@ -252,11 +257,27 @@ openssl genpkey -algorithm ed25519 -out allowance.pem && openssl pkey -in allowa
The private key goes **only** into the server's Dokploy env as `PROJECT_ALLOWANCE_PRIVATE_KEY`; the
public half (SPKI PEM) goes into `project-allowance-key.ts`. Delete the local `.pem` afterwards.
-Until then the test "PROJECT_ALLOWANCE_PUBLIC_KEY parses as an Ed25519 public key and differs from
-ENTITLEMENT_PUBLIC_KEY" (`src/core/project-allowance-token.test.ts`) is **red on purpose**, and
-every allowance token verifies to `null` (no allowance — a claim then reads as a server error). On
-the server, without the private key the claim route does not exist (404) and `/v1/check` never
-sends `limits`, whatever the cutoff says.
+
+What enforces it:
+
+- **The flip release.** The release guard refuses a frozen release while the key is `''`
+ (unreadable, not an Ed25519 public-key PEM, or a private key): "PROJECT_ALLOWANCE_PUBLIC_KEY is
+ empty — paste the public half of PROJECT_ALLOWANCE_PRIVATE_KEY into
+ src/core/project-allowance-key.ts before the flip release (docs/project-limit.md, O1)".
+- **The unit test** (`src/core/project-allowance-token.test.ts`) accepts exactly `''` or an
+ Ed25519 public-key PEM that differs from `ENTITLEMENT_PUBLIC_KEY` and is not a private key, so a
+ half-pasted or wrong key goes red on the PR that pastes it. It is green on `main` either way.
+- **On the server**, without the private key the claim route does not exist (404) and `/v1/check`
+ never sends `limits`, whatever the cutoff says.
+
+**Do O1 before the next release you expect people to still be running at the flip — not just
+before the flip release.** While the key is `''` every allowance token verifies to `null`. Nothing
+happens while the limit is off, but a build with an empty key that is still in use when the server
+switches the limit on fails every claim (the server's signed token does not verify, which reads as a
+server error): its installs — legacy ones included — are held at FREE behind "Couldn't check your
+free allowance" until they update. (Nothing is closed; new opens above FREE are refused.) The
+guard only enforces the key at the flip release, because refusing every release before O1 would
+block unrelated releases; so the timing is the owner's to keep.
### NODE_EXTRA_CA_CERTS / NODE_OPTIONS (owner's call before Release B)
@@ -296,15 +317,17 @@ The decision is enes's. Device check 10 below gathers the evidence.
`telemetryEnabled: true`; the site says off by default. Either the site changes or the app default
changes (a separate PR). Release A's count follows the toggle, so this also decides how many
installs get a snapshot.
-- **O1 — before the client half merges:** the key pair (above).
+- **O1 — before the next release that may still be in use at the flip** (the flip release itself is
+ refused without it): the key pair (above).
- **O2 — Release A:** merge and deploy the server snapshot recording, merge the privacy copy, then
release the desktop report. Let it run 1–2 weeks; read the admin card's p50 / p90 / p99 and set
CAP ≈ p99 (and revisit FREE).
- **O3 — Release B:** confirm server#18 is deployed (`/v1/license/status` answers 502 when keygen is
down — otherwise a keygen outage drops paying users into the limit); merge and deploy the server
claims with `PROJECT_ALLOWANCE_PRIVATE_KEY` set **and the cutoff still unset**; release this
- client. Every later release before the flip bumps `PROJECT_LIMIT_DEADLINE_MS` (the release
- workflow refuses otherwise).
+ client — with the O1 public key pasted, or its installs will fail every claim after the flip.
+ Every later release before the flip bumps `PROJECT_LIMIT_DEADLINE_MS` (the release workflow
+ refuses otherwise).
- **O4 — flip day:**
1. In the release that accompanies the flip (or the first one after it), set
`PROJECT_LIMIT_DEADLINE_FROZEN = true` and the deadline to the flip date. If the flip slips past
diff --git a/scripts/check-project-limit-deadline.mjs b/scripts/check-project-limit-deadline.mjs
index 2ae40eb09..e9be345d6 100644
--- a/scripts/check-project-limit-deadline.mjs
+++ b/scripts/check-project-limit-deadline.mjs
@@ -7,7 +7,13 @@
// IN EVERY RELEASE to a date past the planned flip, or those users are gated before anyone else.
// Nobody remembers a checklist item every release, so the release workflow runs this first and
// refuses to build when the deadline is less than 30 days away. At the flip the deadline becomes the
-// flip date for good and `PROJECT_LIMIT_DEADLINE_FROZEN = true` switches this guard off.
+// flip date for good and `PROJECT_LIMIT_DEADLINE_FROZEN = true` switches the deadline check off.
+//
+// The FLIP release (frozen) also needs owner step O1 done: `PROJECT_ALLOWANCE_PUBLIC_KEY`
+// (src/core/project-allowance-key.ts) ships as '' until the owner pastes the public half of the
+// server's `PROJECT_ALLOWANCE_PRIVATE_KEY`, and with '' every allowance token verifies to nothing.
+// So a frozen release is refused while the key is empty, unreadable, not an Ed25519 public-key PEM,
+// or a PRIVATE key. An unfrozen release does not look at the key at all.
//
// It reads the SOURCE TEXT, not the compiled constant, so it runs before `npm ci` with node alone.
// That is why the constants must keep their literal forms on one line:
@@ -16,16 +22,21 @@
// Anything else is reported as unreadable — never waved through. The test pins these readings to the
// values the app actually compiles.
//
-// Usage: node scripts/check-project-limit-deadline.mjs [path/to/project-limit.ts]
+// Usage: node scripts/check-project-limit-deadline.mjs [path/to/project-limit.ts [path/to/project-allowance-key.ts]]
+import crypto from 'node:crypto'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const MIN_LEAD_MS = 30 * 24 * 60 * 60 * 1000
const SOURCE = 'src/shared/project-limit.ts'
+const KEY_SOURCE = 'src/core/project-allowance-key.ts'
const DEADLINE_RE = /^export const PROJECT_LIMIT_DEADLINE_MS = Date\.parse\('([^']*)'\)\s*$/m
const FROZEN_RE = /^export const PROJECT_LIMIT_DEADLINE_FROZEN = (true|false)\s*$/m
+// '' / "" / a template literal (the shape entitlement-key.ts uses), optionally typed `: string`.
+const KEY_RE =
+ /^export const PROJECT_ALLOWANCE_PUBLIC_KEY(?:\s*:\s*string)?\s*=\s*(?:'((?:[^'\\\n]|\\.)*)'|"((?:[^"\\\n]|\\.)*)"|`([^`]*)`)/m
/**
* The deadline and the frozen flag as written in the source, or null when either is missing or not in
@@ -67,6 +78,67 @@ export function deadlineProblem(source, now) {
return null
}
+/**
+ * `PROJECT_ALLOWANCE_PUBLIC_KEY` as written in src/core/project-allowance-key.ts, or null when the
+ * constant is missing or not a plain string literal. Only `\n` escapes are decoded in a quoted form.
+ * @param {string} source
+ * @returns {string | null}
+ */
+export function readAllowanceKey(source) {
+ const m = KEY_RE.exec(source)
+ if (!m) return null
+ if (m[3] !== undefined) return m[3]
+ return (m[1] ?? m[2]).replace(/\\n/g, '\n')
+}
+
+/**
+ * Why this pair of sources must not be released at `now`, or null when it may: the deadline first
+ * (`deadlineProblem`), then — only for a frozen (flip) release — the allowance key.
+ * @param {string} source the text of src/shared/project-limit.ts
+ * @param {string | null} keySource the text of src/core/project-allowance-key.ts; null = unreadable
+ * @param {Date} now
+ * @returns {string | null}
+ */
+export function releaseProblem(source, keySource, now) {
+ const deadline = deadlineProblem(source, now)
+ if (deadline) return deadline
+ if (!readDeadline(source).frozen) return null
+ const key = keySource === null ? null : readAllowanceKey(keySource)
+ if (key === null) {
+ return (
+ `could not read PROJECT_ALLOWANCE_PUBLIC_KEY from ${KEY_SOURCE} — the flip release needs it ` +
+ '(docs/project-limit.md, O1)'
+ )
+ }
+ if (key === '') {
+ return (
+ 'PROJECT_ALLOWANCE_PUBLIC_KEY is empty — paste the public half of PROJECT_ALLOWANCE_PRIVATE_KEY into ' +
+ `${KEY_SOURCE} before the flip release (docs/project-limit.md, O1)`
+ )
+ }
+ // Checked by text first: createPublicKey accepts a PRIVATE key too (it derives the public half).
+ if (/PRIVATE KEY/.test(key)) {
+ return (
+ `PROJECT_ALLOWANCE_PUBLIC_KEY in ${KEY_SOURCE} is a PRIVATE key — remove it, rotate the key pair, ` +
+ 'and paste only the public half (docs/project-limit.md, O1)'
+ )
+ }
+ let ed25519 = false
+ try {
+ const k = crypto.createPublicKey(key)
+ ed25519 = /-----BEGIN PUBLIC KEY-----/.test(key) && k.type === 'public' && k.asymmetricKeyType === 'ed25519'
+ } catch {
+ ed25519 = false
+ }
+ if (!ed25519) {
+ return (
+ `PROJECT_ALLOWANCE_PUBLIC_KEY in ${KEY_SOURCE} is not an Ed25519 public key (SPKI PEM) — paste the ` +
+ 'public half of PROJECT_ALLOWANCE_PRIVATE_KEY before the flip release (docs/project-limit.md, O1)'
+ )
+ }
+ return null
+}
+
function fail(message) {
// An annotation on the run summary when it runs in GitHub Actions, a plain line elsewhere.
console.error(`${process.env.GITHUB_ACTIONS === 'true' ? '::error::' : ''}${message}`)
@@ -85,15 +157,23 @@ const isMain = (() => {
})()
if (isMain) {
- const file =
- process.argv[2] ?? path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', SOURCE)
+ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..')
+ const file = process.argv[2] ?? path.join(root, SOURCE)
+ const keyFile = process.argv[3] ?? path.join(root, KEY_SOURCE)
let source
try {
source = fs.readFileSync(file, 'utf8')
} catch (err) {
fail(`could not read ${file}: ${err instanceof Error ? err.message : String(err)}`)
}
- const problem = deadlineProblem(source, new Date())
+ // Unreadable is null, not a failure here: only a frozen release needs the key (releaseProblem).
+ let keySource = null
+ try {
+ keySource = fs.readFileSync(keyFile, 'utf8')
+ } catch {
+ keySource = null
+ }
+ const problem = releaseProblem(source, keySource, new Date())
if (problem) fail(problem)
const { deadlineMs, frozen } = readDeadline(source)
console.log(
diff --git a/scripts/check-project-limit-deadline.test.ts b/scripts/check-project-limit-deadline.test.ts
index de79cc093..b672c7939 100644
--- a/scripts/check-project-limit-deadline.test.ts
+++ b/scripts/check-project-limit-deadline.test.ts
@@ -1,15 +1,40 @@
import { describe, it, expect } from 'vitest'
import { spawnSync } from 'node:child_process'
+import crypto from 'node:crypto'
import fs from 'fs'
import path from 'path'
import { testTmpDir } from '../src/core/test-tmp'
import { PROJECT_LIMIT_DEADLINE_FROZEN, PROJECT_LIMIT_DEADLINE_MS } from '../src/shared/project-limit'
-// @ts-expect-error -- plain .mjs repo tooling, deliberately outside the typechecked projects.
-import { deadlineProblem, readDeadline } from './check-project-limit-deadline.mjs'
+import { PROJECT_ALLOWANCE_PUBLIC_KEY } from '../src/core/project-allowance-key'
+import {
+ deadlineProblem,
+ readAllowanceKey,
+ readDeadline,
+ releaseProblem
+ // @ts-expect-error -- plain .mjs repo tooling, deliberately outside the typechecked projects.
+} from './check-project-limit-deadline.mjs'
const DAY_MS = 24 * 60 * 60 * 1000
const SCRIPT = path.resolve(__dirname, 'check-project-limit-deadline.mjs')
const REAL_SOURCE = fs.readFileSync(path.resolve(__dirname, '../src/shared/project-limit.ts'), 'utf8')
+const REAL_KEY_SOURCE = fs.readFileSync(path.resolve(__dirname, '../src/core/project-allowance-key.ts'), 'utf8')
+
+const keyPair = crypto.generateKeyPairSync('ed25519')
+const PUBLIC_PEM = keyPair.publicKey.export({ type: 'spki', format: 'pem' }).toString()
+const PRIVATE_PEM = keyPair.privateKey.export({ type: 'pkcs8', format: 'pem' }).toString()
+
+/** src/core/project-allowance-key.ts as it ships before O1 (`''`) or after it (a template literal,
+ * the shape entitlement-key.ts uses), with the header comment that mentions the constant. */
+function keySource(value: string): string {
+ const literal = value === '' ? "''" : `\`${value}\``
+ return [
+ '// The public half of PROJECT_ALLOWANCE_PRIVATE_KEY; see PROJECT_ALLOWANCE_PUBLIC_KEY below.',
+ `export const PROJECT_ALLOWANCE_PUBLIC_KEY: string = ${literal}`,
+ ''
+ ].join('\n')
+}
+const EMPTY_KEY =
+ 'PROJECT_ALLOWANCE_PUBLIC_KEY is empty — paste the public half of PROJECT_ALLOWANCE_PRIVATE_KEY into src/core/project-allowance-key.ts before the flip release (docs/project-limit.md, O1)'
/** The two lines the guard reads, in the shape src/shared/project-limit.ts writes them, wrapped in
* the same kind of doc comment (which itself quotes the literal form — it must not be matched). */
@@ -82,6 +107,50 @@ describe('deadlineProblem', () => {
})
})
+describe('releaseProblem: the flip release also needs the allowance key (owner step O1)', () => {
+ const FAR = source('2027-01-31T00:00:00Z', false)
+ const FROZEN = source('2026-01-01T00:00:00Z', true)
+
+ it('refuses a frozen (flip) release while the key is empty', () => {
+ expect(releaseProblem(FROZEN, keySource(''), NOW)).toBe(EMPTY_KEY)
+ })
+
+ it('passes a frozen release with an Ed25519 public key, as a template literal or a quoted string', () => {
+ expect(releaseProblem(FROZEN, keySource(PUBLIC_PEM), NOW)).toBeNull()
+ const quoted = `export const PROJECT_ALLOWANCE_PUBLIC_KEY = '${PUBLIC_PEM.replace(/\n/g, '\\n')}'\n`
+ expect(releaseProblem(FROZEN, quoted, NOW)).toBeNull()
+ })
+
+ it('does not check the key while the deadline is not frozen — not even an unreadable key file', () => {
+ expect(releaseProblem(FAR, keySource(''), NOW)).toBeNull()
+ expect(releaseProblem(FAR, null, NOW)).toBeNull()
+ expect(releaseProblem(FAR, 'garbage', NOW)).toBeNull()
+ })
+
+ it('fails closed on a frozen release whose key file is unreadable or has no key constant', () => {
+ for (const src of [null, '', 'garbage', 'export const SOMETHING_ELSE = 1\n']) {
+ expect(releaseProblem(FROZEN, src, NOW)).toMatch(/^could not read PROJECT_ALLOWANCE_PUBLIC_KEY/)
+ }
+ })
+
+ it('refuses a frozen release whose key is not an Ed25519 public-key PEM', () => {
+ const rsa = crypto.generateKeyPairSync('rsa', { modulusLength: 2048 }).publicKey.export({ type: 'spki', format: 'pem' })
+ for (const value of ['not a pem', rsa.toString()]) {
+ expect(releaseProblem(FROZEN, keySource(value), NOW)).toMatch(/is not an Ed25519 public key/)
+ }
+ })
+
+ it('refuses a pasted PRIVATE key outright (it would parse: Node derives the public half)', () => {
+ expect(releaseProblem(FROZEN, keySource(PRIVATE_PEM), NOW)).toMatch(/PRIVATE key/)
+ })
+
+ it('still reports the deadline first, and deadlineProblem alone never looks at the key', () => {
+ const iso = new Date(NOW.getTime() + 10 * DAY_MS).toISOString()
+ expect(releaseProblem(source(iso, false), keySource(''), NOW)).toBe(late(iso))
+ expect(deadlineProblem(FROZEN, NOW)).toBeNull()
+ })
+})
+
describe('the real src/shared/project-limit.ts', () => {
// Pins the guard to the compiled constants, so a change of literal form fails on the PR that makes
// it, not on release day.
@@ -91,15 +160,22 @@ describe('the real src/shared/project-limit.ts', () => {
frozen: PROJECT_LIMIT_DEADLINE_FROZEN
})
})
+
+ it('and the real src/core/project-allowance-key.ts reads as the key the app compiles', () => {
+ expect(readAllowanceKey(REAL_KEY_SOURCE)).toBe(PROJECT_ALLOWANCE_PUBLIC_KEY)
+ })
})
describe('the CLI the release workflow runs', () => {
- function run(src: string): { status: number | null; stderr: string; stdout: string } {
+ /** Run the CLI on a limit source and a key source (`null` = point it at a key file that is not there). */
+ function run(src: string, key: string | null = keySource(PUBLIC_PEM)): { status: number | null; stderr: string } {
const dir = testTmpDir('nt-limit-deadline-')
const file = path.join(dir, 'project-limit.ts')
+ const keyFile = path.join(dir, 'project-allowance-key.ts')
fs.writeFileSync(file, src)
- const r = spawnSync(process.execPath, [SCRIPT, file], { encoding: 'utf8' })
- return { status: r.status, stderr: r.stderr, stdout: r.stdout }
+ if (key !== null) fs.writeFileSync(keyFile, key)
+ const r = spawnSync(process.execPath, [SCRIPT, file, keyFile], { encoding: 'utf8' })
+ return { status: r.status, stderr: r.stderr }
}
it('exits 1 with the message when the deadline is too close', () => {
@@ -117,11 +193,23 @@ describe('the CLI the release workflow runs', () => {
expect(r.stderr).toContain('missing.ts')
})
- it('exits 0 for a far deadline and for a frozen one', () => {
- expect(run(source(new Date(Date.now() + 90 * DAY_MS).toISOString(), false)).status).toBe(0)
+ it('exits 0 for a far deadline (key unchecked) and for a frozen one with a real key', () => {
+ const far = source(new Date(Date.now() + 90 * DAY_MS).toISOString(), false)
+ expect(run(far, keySource('')).status).toBe(0)
+ expect(run(far, null).status).toBe(0)
expect(run(source('2026-01-01T00:00:00Z', true)).status).toBe(0)
})
+ it('exits 1 for a frozen release with an empty or missing key file', () => {
+ const frozen = source('2026-01-01T00:00:00Z', true)
+ const empty = run(frozen, keySource(''))
+ expect(empty.status).toBe(1)
+ expect(empty.stderr).toContain(EMPTY_KEY)
+ const missing = run(frozen, null)
+ expect(missing.status).toBe(1)
+ expect(missing.stderr).toContain('could not read PROJECT_ALLOWANCE_PUBLIC_KEY')
+ })
+
// Skipped on Windows: creating a symlink there needs a privilege CI runners do not grant.
it.skipIf(process.platform === 'win32')('still runs when invoked through a symlinked path', () => {
// Node resolves the main module through symlinks (macOS's /var → /private/var does it to a whole
diff --git a/src/core/project-allowance-key.ts b/src/core/project-allowance-key.ts
index 90ddd3791..20daeef1d 100644
--- a/src/core/project-allowance-key.ts
+++ b/src/core/project-allowance-key.ts
@@ -6,7 +6,10 @@
// entitlement-key signature that carries their deviceId and a live `exp`, checking neither `typ`
// nor `tier`, so an allowance token signed with the entitlement key would read as Pro everywhere.
//
-// TODO(O1): the owner pastes the production SPKI PEM here before merge. Until then it is empty, so
-// every allowance token verifies to null, and the merge-guard test in project-allowance-token.test.ts
-// ("parses as an Ed25519 public key and differs from ENTITLEMENT_PUBLIC_KEY") stays red.
+// TODO(O1): the owner pastes the production SPKI PEM here (docs/project-limit.md, O1). Until then
+// it is empty and every allowance token verifies to null: harmless while the limit is off, but a
+// build with '' that is still in use at the flip fails every claim, so do it before the next
+// release expected to be running then. The flip (frozen-deadline) release is refused while it is
+// empty (scripts/check-project-limit-deadline.mjs); project-allowance-token.test.ts accepts only ''
+// or a real Ed25519 public-key PEM distinct from ENTITLEMENT_PUBLIC_KEY.
export const PROJECT_ALLOWANCE_PUBLIC_KEY: string = ''
diff --git a/src/core/project-allowance-token.test.ts b/src/core/project-allowance-token.test.ts
index 9e9145baa..04a2feef0 100644
--- a/src/core/project-allowance-token.test.ts
+++ b/src/core/project-allowance-token.test.ts
@@ -174,12 +174,26 @@ describe('verifyAllowanceToken', () => {
})
describe('PROJECT_ALLOWANCE_PUBLIC_KEY', () => {
- // MERGE GUARD: red until owner step O1 pastes the production SPKI PEM into project-allowance-key.ts.
- it('parses as an Ed25519 public key and differs from ENTITLEMENT_PUBLIC_KEY', () => {
- const key = crypto.createPublicKey(PROJECT_ALLOWANCE_PUBLIC_KEY)
- expect(key.type).toBe('public')
- expect(key.asymmetricKeyType).toBe('ed25519')
- const entitlement = crypto.createPublicKey(ENTITLEMENT_PUBLIC_KEY)
- expect(key.export({ type: 'spki', format: 'der' }).equals(entitlement.export({ type: 'spki', format: 'der' }))).toBe(false)
+ // Owner step O1 pastes the production key. Until then it is '' — and the FLIP release is refused
+ // while it is (scripts/check-project-limit-deadline.mjs), so an empty key can be merged but never
+ // flipped on. Anything else in that constant must be the real thing.
+ it("is '' before owner step O1, else an Ed25519 public-key PEM distinct from ENTITLEMENT_PUBLIC_KEY", () => {
+ if (PROJECT_ALLOWANCE_PUBLIC_KEY !== '') {
+ // A pasted PRIVATE key also parses (createPublicKey derives the public half) — refuse it by text.
+ expect(PROJECT_ALLOWANCE_PUBLIC_KEY).toMatch(/-----BEGIN PUBLIC KEY-----/)
+ expect(PROJECT_ALLOWANCE_PUBLIC_KEY).not.toMatch(/PRIVATE KEY/)
+ const key = crypto.createPublicKey(PROJECT_ALLOWANCE_PUBLIC_KEY)
+ expect(key.type).toBe('public')
+ expect(key.asymmetricKeyType).toBe('ed25519')
+ const entitlement = crypto.createPublicKey(ENTITLEMENT_PUBLIC_KEY)
+ expect(
+ key.export({ type: 'spki', format: 'der' }).equals(entitlement.export({ type: 'spki', format: 'der' }))
+ ).toBe(false)
+ }
+ })
+
+ it('an empty key verifies nothing, not even a valid token (the pre-O1 state)', () => {
+ expect(verifyAllowanceToken(mint(), EXPECT, PUB)).not.toBeNull() // control: the token is valid
+ expect(verifyAllowanceToken(mint(), EXPECT, '')).toBeNull()
})
})