cursedauth 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -43,14 +43,29 @@ logins and nothing else. The provider is a separate service reached over HTTPS a
43
43
  | `cursedauth/content-census` | server | answer "what has this account made here?" by COUNT |
44
44
  | `cursedauth/account-slots` | both | several accounts signed in on one browser |
45
45
  | `cursedauth/sso` | both | the grant: its wire shape, its claims, its verification |
46
+ | `cursedauth/session-claims` | server | the bearer-token half: `SESSION_CLAIMS_KEY`, `SessionClaims`, `createRequireSession`. **Worker-safe** — reaches no `bun:sqlite` |
46
47
  | `cursedauth/constant-time` | both | `constantTimeEqual` — compare two secrets without leaking where they differ |
48
+ | `cursedauth/offline-grant` | both | the bounded offline window: how long a device with no network may keep using cached content |
47
49
  | `cursedauth/auth` | browser | `startSsoSignIn`, `useSsoAutoSignIn`, session hooks |
48
50
  | `cursedauth/account-ui` | browser | the account menu |
49
51
  | `cursedauth/account-slot-client` | browser | slot switching in the page |
50
52
  | `cursedauth/testing` | server | the grant→callback→cookie harness, for a consumer's own suite |
51
53
 
52
54
  🔴 The barrel reaches `bun:sqlite`. A browser bundle imports the three browser
53
- subpaths and never the root.
55
+ subpaths and never the root — **and so does a Cloudflare Worker**, which is why
56
+ `cursedauth/session-claims` exists. `apps/patterns` could not `wrangler deploy` at
57
+ all on 2026-09-18 (`Could not resolve "bun:sqlite"`, naming `dist/userSessions.js`)
58
+ because one string constant was reachable only through the barrel. Which subpaths
59
+ may reach `bun:sqlite` is now a CHECK — `src/subpathsReachNoBunBuiltin.test.ts` —
60
+ and that allowlist may only shrink.
61
+
62
+ 🔴 **Two different things are called a "grant" here, and only one is a
63
+ credential.** `cursedauth/sso` has *the* grant: signed by the accounts service,
64
+ single-use, and it authorizes a sign-in. `cursedauth/offline-grant` has an
65
+ `OfflineGrant`: a local stamp saying "this device completed a verified session
66
+ for account X at time T", which authorizes nothing, is never sent anywhere, and
67
+ only bounds how long already-cached bytes may be replayed while there is no
68
+ network to re-check. Separate subpaths, no import between them.
54
69
 
55
70
  🔴 **This table is a CHECK, not prose** — `src/publishShape.test.ts` fails if an
56
71
  export subpath is missing a row. A subpath nobody can find is a subpath every app
@@ -0,0 +1,127 @@
1
+ /**
2
+ * The offline validity window — the bounded answer to "a disabled account cannot
3
+ * be revoked on a device that is offline".
4
+ *
5
+ * Cached bytes cannot be revoked and auth's revocation ticket cannot reach an
6
+ * offline device, so we do NOT pretend a disable is instantaneous. Instead every
7
+ * successful ONLINE session verification stamps a grant; offline use is allowed
8
+ * only while that stamp is recent. A reconnect re-verifies and either refreshes
9
+ * the stamp (still valid) or drops the grant and purges the cache (revoked).
10
+ *
11
+ * This module is pure: it never touches storage, `Date` or the network — the
12
+ * caller passes `now` and the persisted grant. That is what makes the window a
13
+ * unit-testable decision rather than a scattering of `Date.now()` comparisons.
14
+ * It imports nothing, so it is a leaf on both sides of the wire.
15
+ *
16
+ * ## 🔴 This is NOT the SSO grant
17
+ *
18
+ * `cursedauth/sso` publishes *the grant*: a signed, single-use credential the
19
+ * accounts service mints, which authorizes a sign-in. An {@link OfflineGrant} is
20
+ * the opposite kind of object — a local stamp that authorizes nothing and is
21
+ * never sent anywhere. Same word, two meanings, and the distinction is the whole
22
+ * safety argument below, so the two live on separate subpaths and never import
23
+ * each other.
24
+ *
25
+ * ## Where it came from
26
+ *
27
+ * Built, tested and justified in `roms` as `src/offline/validity.ts`, which is
28
+ * still where the trade-off is written down: `apps/roms/docs/offline.md`
29
+ * §"Constraint 2 — offline play vs. account disable: a bounded window". Lifted
30
+ * here on 2026-09-17 because the window is a property of a *session*, the
31
+ * revocation argument is auth's, and `music` was named as the second app that
32
+ * wants it — one app's `src/offline/` is unreachable from every other app.
33
+ *
34
+ * The shell/service-worker/cache half of `roms`' offline work deliberately did
35
+ * NOT come with it: `swRouting`, the outbox and quota relief are shaped around
36
+ * ROM bytes and save states, and whether they generalise is a question to answer
37
+ * with a second consumer in hand.
38
+ *
39
+ * One rename on the way over, and nothing else: `isOfflinePlayAllowed` is
40
+ * {@link isOfflineGrantValid} here, because a library that knows nothing about
41
+ * games should not decide whether "play" is allowed. Every other name, every
42
+ * default and every spec is the one `roms` reasoned about.
43
+ */
44
+ /**
45
+ * The maximum time a device may use cached content while offline, measured from
46
+ * the last successful online session check. Seven days: long enough for a normal
47
+ * trip, short enough that a revoked account cannot indefinitely retain access by
48
+ * never reconnecting. See the trade-off write-up in `apps/roms/docs/offline.md`.
49
+ *
50
+ * 🔴 **A consumer may pass a SHORTER `maxWindowMs`, never a longer one by
51
+ * default.** This number *is* the revocation argument: the exposure a disabled
52
+ * account keeps is exactly this window, and it was justified against cached game
53
+ * bytes on a device that may never reconnect. Raising the shared default would
54
+ * widen every app's exposure at once, on no app's reasoning.
55
+ */
56
+ export declare const OFFLINE_MAX_WINDOW_MS: number;
57
+ /**
58
+ * Proof, stamped at the last successful ONLINE session verification, that this
59
+ * device was a valid session for `accountId` at `lastVerifiedAt`. Persisted
60
+ * locally (e.g. localStorage). It is not a credential — it grants nothing on its
61
+ * own; it only bounds how long already-cached bytes may be replayed offline.
62
+ */
63
+ export interface OfflineGrant {
64
+ accountId: string;
65
+ /** Epoch ms of the last successful online session check. */
66
+ lastVerifiedAt: number;
67
+ /**
68
+ * The account's email, purely so a cold OFFLINE load can put a name in the
69
+ * header instead of a uuid (`apps/roms/src/offlineAuth.ts` is the app that
70
+ * does exactly this). Optional: grants written before 2026-08-05 have none,
71
+ * and nothing may depend on it — it is a label, never a credential and never
72
+ * an identity check.
73
+ */
74
+ email?: string;
75
+ }
76
+ export type OfflineValidity =
77
+ /** No grant on this device — it never signed in. Offline use is refused. */
78
+ {
79
+ state: "no-grant";
80
+ }
81
+ /** Within the window — offline use allowed. */
82
+ | {
83
+ state: "valid";
84
+ remainingMs: number;
85
+ }
86
+ /** The window has lapsed — offline use refused until a reconnect re-checks. */
87
+ | {
88
+ state: "expired";
89
+ expiredForMs: number;
90
+ };
91
+ /**
92
+ * How much of the offline window is left, clamped to zero. Negative inputs
93
+ * (a grant stamped in the "future" by a skewed clock) are treated as fully spent
94
+ * rather than trusted, so clock games cannot extend the window.
95
+ */
96
+ export declare function offlineWindowRemainingMs(grant: OfflineGrant, now: number, maxWindowMs?: number): number;
97
+ /** The full validity verdict for a (possibly absent) grant at time `now`. */
98
+ export declare function offlineValidity(grant: OfflineGrant | null | undefined, now: number, maxWindowMs?: number): OfflineValidity;
99
+ /**
100
+ * Convenience: is offline use permitted on the strength of this grant right now?
101
+ *
102
+ * (`roms` calls this `isOfflinePlayAllowed`; it is the same predicate.)
103
+ */
104
+ export declare function isOfflineGrantValid(grant: OfflineGrant | null | undefined, now: number, maxWindowMs?: number): boolean;
105
+ /**
106
+ * The outcome of an online reconnect check. `revoked` means auth reported the
107
+ * account disabled or the session no longer valid; `verified` means it is still
108
+ * this account and still valid.
109
+ */
110
+ export type ReconnectCheck = {
111
+ verified: true;
112
+ accountId: string;
113
+ at: number;
114
+ } | {
115
+ revoked: true;
116
+ };
117
+ /**
118
+ * Fold a fresh online check into the stored grant — the stamp-on-successful-
119
+ * verification hook, and the only way a grant is ever created or refreshed.
120
+ *
121
+ * - verified → a refreshed grant stamped `at` (the window resets).
122
+ * - revoked, OR verified as a DIFFERENT account than the one that cached the
123
+ * bytes → `null`. The caller MUST then purge its content cache: a null grant is
124
+ * the signal that whatever is cached must no longer be usable.
125
+ */
126
+ export declare function reconcileGrant(previous: OfflineGrant | null | undefined, check: ReconnectCheck): OfflineGrant | null;
127
+ //# sourceMappingURL=offlineGrant.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"offlineGrant.d.ts","sourceRoot":"","sources":["../src/offlineGrant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB,QAA0B,CAAC;AAE7D;;;;;GAKG;AACH,MA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"a disabled account cannot
3
+ * be revoked on a device that is offline".
4
+ *
5
+ * Cached bytes cannot be revoked and auth's revocation ticket cannot reach an
6
+ * offline device, so we do NOT pretend a disable is instantaneous. Instead every
7
+ * successful ONLINE session verification stamps a grant; offline use is allowed
8
+ * only while that stamp is recent. A reconnect re-verifies and either refreshes
9
+ * the stamp (still valid) or drops the grant and purges the cache (revoked).
10
+ *
11
+ * This module is pure: it never touches storage, `Date` or the network — the
12
+ * caller passes `now` and the persisted grant. That is what makes the window a
13
+ * unit-testable decision rather than a scattering of `Date.now()` comparisons.
14
+ * It imports nothing, so it is a leaf on both sides of the wire.
15
+ *
16
+ * ## 🔴 This is NOT the SSO grant
17
+ *
18
+ * `cursedauth/sso` publishes *the grant*: a signed, single-use credential the
19
+ * accounts service mints, which authorizes a sign-in. An {@link OfflineGrant} is
20
+ * the opposite kind of object — a local stamp that authorizes nothing and is
21
+ * never sent anywhere. Same word, two meanings, and the distinction is the whole
22
+ * safety argument below, so the two live on separate subpaths and never import
23
+ * each other.
24
+ *
25
+ * ## Where it came from
26
+ *
27
+ * Built, tested and justified in `roms` as `src/offline/validity.ts`, which is
28
+ * still where the trade-off is written down: `apps/roms/docs/offline.md`
29
+ * §"Constraint 2 — offline play vs. account disable: a bounded window". Lifted
30
+ * here on 2026-09-17 because the window is a property of a *session*, the
31
+ * revocation argument is auth's, and `music` was named as the second app that
32
+ * wants it — one app's `src/offline/` is unreachable from every other app.
33
+ *
34
+ * The shell/service-worker/cache half of `roms`' offline work deliberately did
35
+ * NOT come with it: `swRouting`, the outbox and quota relief are shaped around
36
+ * ROM bytes and save states, and whether they generalise is a question to answer
37
+ * with a second consumer in hand.
38
+ *
39
+ * One rename on the way over, and nothing else: `isOfflinePlayAllowed` is
40
+ * {@link isOfflineGrantValid} here, because a library that knows nothing about
41
+ * games should not decide whether "play" is allowed. Every other name, every
42
+ * default and every spec is the one `roms` reasoned about.
43
+ */
44
+ /**
45
+ * The maximum time a device may use cached content while offline, measured from
46
+ * the last successful online session check. Seven days: long enough for a normal
47
+ * trip, short enough that a revoked account cannot indefinitely retain access by
48
+ * never reconnecting. See the trade-off write-up in `apps/roms/docs/offline.md`.
49
+ *
50
+ * 🔴 **A consumer may pass a SHORTER `maxWindowMs`, never a longer one by
51
+ * default.** This number *is* the revocation argument: the exposure a disabled
52
+ * account keeps is exactly this window, and it was justified against cached game
53
+ * bytes on a device that may never reconnect. Raising the shared default would
54
+ * widen every app's exposure at once, on no app's reasoning.
55
+ */
56
+ export const OFFLINE_MAX_WINDOW_MS = 7 * 24 * 60 * 60 * 1000;
57
+ /**
58
+ * How much of the offline window is left, clamped to zero. Negative inputs
59
+ * (a grant stamped in the "future" by a skewed clock) are treated as fully spent
60
+ * rather than trusted, so clock games cannot extend the window.
61
+ */
62
+ export function offlineWindowRemainingMs(grant, now, maxWindowMs = OFFLINE_MAX_WINDOW_MS) {
63
+ const elapsed = now - grant.lastVerifiedAt;
64
+ if (elapsed < 0)
65
+ return 0; // future-stamped grant: don't trust it
66
+ return Math.max(0, maxWindowMs - elapsed);
67
+ }
68
+ /** The full validity verdict for a (possibly absent) grant at time `now`. */
69
+ export function offlineValidity(grant, now, maxWindowMs = OFFLINE_MAX_WINDOW_MS) {
70
+ if (!grant)
71
+ return { state: "no-grant" };
72
+ const remainingMs = offlineWindowRemainingMs(grant, now, maxWindowMs);
73
+ if (remainingMs > 0)
74
+ return { state: "valid", remainingMs };
75
+ const elapsed = now - grant.lastVerifiedAt;
76
+ return { state: "expired", expiredForMs: Math.max(0, elapsed - maxWindowMs) };
77
+ }
78
+ /**
79
+ * Convenience: is offline use permitted on the strength of this grant right now?
80
+ *
81
+ * (`roms` calls this `isOfflinePlayAllowed`; it is the same predicate.)
82
+ */
83
+ export function isOfflineGrantValid(grant, now, maxWindowMs = OFFLINE_MAX_WINDOW_MS) {
84
+ return offlineValidity(grant, now, maxWindowMs).state === "valid";
85
+ }
86
+ /**
87
+ * Fold a fresh online check into the stored grant — the stamp-on-successful-
88
+ * verification hook, and the only way a grant is ever created or refreshed.
89
+ *
90
+ * - verified → a refreshed grant stamped `at` (the window resets).
91
+ * - revoked, OR verified as a DIFFERENT account than the one that cached the
92
+ * bytes → `null`. The caller MUST then purge its content cache: a null grant is
93
+ * the signal that whatever is cached must no longer be usable.
94
+ */
95
+ export function reconcileGrant(previous, check) {
96
+ if ("revoked" in check)
97
+ return null;
98
+ // A device that comes back as a different account must not inherit the prior
99
+ // account's offline window over the prior account's cached library.
100
+ if (previous && previous.accountId !== check.accountId)
101
+ return null;
102
+ return { accountId: check.accountId, lastVerifiedAt: check.at };
103
+ }
104
+ //# sourceMappingURL=offlineGrant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"offlineGrant.js","sourceRoot":"","sources":["../src/offlineGrant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AA8B7D;;;;GAIG;AACH,MAAM,UAAU,wBAAwB,CACvC,KAAmB,EACnB,GAAW,EACX,cAAsB,qBAAqB;IAE3C,MAAM,OAAO,GAAG,GAAG,GAAG,KAAK,CAAC,cAAc,CAAC;IAC3C,IAAI,OAAO,GAAG,CAAC;QAAE,OAAO,CAAC,CAAC,CAAC,uCAAuC;IAClE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,CAAC;AAC3C,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,eAAe,CAC9B,KAAsC,EACtC,GAAW,EACX,cAAsB,qBAAqB;IAE3C,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC;IACzC,MAAM,WAAW,GAAG,wBAAwB,CAAC,KAAK,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;IAC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IACH,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,EAAE,CAAC;IACxC,4DAA4D;IAC5D,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACvC,qEAAqE;IACrE,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,IAAI,CAAC;IACxD;;;;;OAKG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,GAAG,aAAa,EAAE,CAAC;IAC5D;;;;;;;OAOG;IACH,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;IACxD;;;;;;;;OAQG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAClE,+DAA+D;IAC/D,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CACnD;AAwBD,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,gBAAgB,CA6VzF"}
@@ -64,12 +64,20 @@
64
64
  * resolves to null and the request is anonymous. Never treat a slot number as
65
65
  * identity — resolve it here, every time.
66
66
  */
67
- import { createHash, createHmac, randomBytes, timingSafeEqual } from "node:crypto";
67
+ import { createHash, createHmac, randomBytes } from "node:crypto";
68
68
  import { mkdirSync } from "node:fs";
69
69
  import path from "node:path";
70
70
  import { Database } from "bun:sqlite";
71
71
  import { ACCOUNT_SLOT_HEADER, ACCOUNT_USER_HEADER, MAX_ACCOUNT_SLOTS, normalizeSlot, slotCookieName, slotFromUrl, } from "./accountSlots";
72
72
  import { clientAddressOf, clientFactsOf, clientUserAgentOf, describePlace, } from "./clientDescription";
73
+ // 🔴 The compare, not a copy of it. This file carried its OWN `constantTimeEqual`
74
+ // until 2026-09-17 — a `node:crypto` `timingSafeEqual` with both sides padded to a
75
+ // common length — while `constantTime.ts` sat two files away with the same contract.
76
+ // That made an eighth copy of this primitive inside the very package that publishes
77
+ // it, and it was found while shipping `cursedauth/constant-time` for the three apps
78
+ // that had each copied the file. Both forms were correct; neither knew about the other,
79
+ // which is the whole failure mode.
80
+ import { constantTimeEqual } from "./constantTime";
73
81
  import { isSecureRequest } from "./secureRequest";
74
82
  /**
75
83
  * How stale `last_seen_at` may get before a request writes it.
@@ -91,16 +99,6 @@ const TOUCH_THROTTLE_MS = 60_000;
91
99
  * would have been sessions the owner could see and not revoke.
92
100
  */
93
101
  const handleOf = (id) => createHash("sha256").update(id).digest("hex").slice(0, 24);
94
- function constantTimeEqual(a, b) {
95
- const ab = Buffer.from(a, "utf8");
96
- const bb = Buffer.from(b, "utf8");
97
- const len = Math.max(ab.length, bb.length);
98
- const pa = Buffer.alloc(len);
99
- const pb = Buffer.alloc(len);
100
- ab.copy(pa);
101
- bb.copy(pb);
102
- return timingSafeEqual(pa, pb) && ab.length === bb.length;
103
- }
104
102
  export function createUserSessionStore(options) {
105
103
  // Resolved once per store rather than per sign-in. `null` and unset are the
106
104
  // same thing — see `placeLookup` on the options for why there is no default.
@@ -1 +1 @@
1
- {"version":3,"file":"userSessions.js","sourceRoot":"","sources":["../src/userSessions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiEG;AACH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACpC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EACN,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,aAAa,EACb,cAAc,EACd,WAAW,GACX,MAAM,gBAAgB,CA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,CAAC,CAAC,CAAC;YACrE,OAAO,GAAG,IAAI,MAAM,gBAAgB,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC;QAChD,CAAC;KACD,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cursedauth",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "The app side of fleet SSO — sign in through the accounts service, keep a local snapshot of who signed in, and gate the app on it. Bun + Hono + React, one SQLite file per app.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -71,12 +71,24 @@
71
71
  "source": "./src/ssoTestHarness.ts",
72
72
  "import": "./dist/ssoTestHarness.js"
73
73
  },
74
+ "./session-claims": {
75
+ "types": "./dist/auth.server.d.ts",
76
+ "bun": "./src/auth.server.ts",
77
+ "source": "./src/auth.server.ts",
78
+ "import": "./dist/auth.server.js"
79
+ },
74
80
  "./constant-time": {
75
81
  "types": "./dist/constantTime.d.ts",
76
82
  "bun": "./src/constantTime.ts",
77
83
  "source": "./src/constantTime.ts",
78
84
  "import": "./dist/constantTime.js"
79
85
  },
86
+ "./offline-grant": {
87
+ "types": "./dist/offlineGrant.d.ts",
88
+ "bun": "./src/offlineGrant.ts",
89
+ "source": "./src/offlineGrant.ts",
90
+ "import": "./dist/offlineGrant.js"
91
+ },
80
92
  "./package.json": "./package.json"
81
93
  },
82
94
  "files": [
@@ -88,7 +100,7 @@
88
100
  "LICENSE"
89
101
  ],
90
102
  "scripts": {
91
- "paths": "bun ../../tools/check-paths.ts .",
103
+ "paths": "bun run scripts/paths.ts",
92
104
  "typecheck": "tsc -p tsconfig.json --noEmit",
93
105
  "build": "rm -rf dist && tsc -p tsconfig.build.json",
94
106
  "test": "bun test src",
@@ -0,0 +1,153 @@
1
+ /**
2
+ * The offline validity window — the bounded answer to "a disabled account cannot
3
+ * be revoked on a device that is offline".
4
+ *
5
+ * Cached bytes cannot be revoked and auth's revocation ticket cannot reach an
6
+ * offline device, so we do NOT pretend a disable is instantaneous. Instead every
7
+ * successful ONLINE session verification stamps a grant; offline use is allowed
8
+ * only while that stamp is recent. A reconnect re-verifies and either refreshes
9
+ * the stamp (still valid) or drops the grant and purges the cache (revoked).
10
+ *
11
+ * This module is pure: it never touches storage, `Date` or the network — the
12
+ * caller passes `now` and the persisted grant. That is what makes the window a
13
+ * unit-testable decision rather than a scattering of `Date.now()` comparisons.
14
+ * It imports nothing, so it is a leaf on both sides of the wire.
15
+ *
16
+ * ## 🔴 This is NOT the SSO grant
17
+ *
18
+ * `cursedauth/sso` publishes *the grant*: a signed, single-use credential the
19
+ * accounts service mints, which authorizes a sign-in. An {@link OfflineGrant} is
20
+ * the opposite kind of object — a local stamp that authorizes nothing and is
21
+ * never sent anywhere. Same word, two meanings, and the distinction is the whole
22
+ * safety argument below, so the two live on separate subpaths and never import
23
+ * each other.
24
+ *
25
+ * ## Where it came from
26
+ *
27
+ * Built, tested and justified in `roms` as `src/offline/validity.ts`, which is
28
+ * still where the trade-off is written down: `apps/roms/docs/offline.md`
29
+ * §"Constraint 2 — offline play vs. account disable: a bounded window". Lifted
30
+ * here on 2026-09-17 because the window is a property of a *session*, the
31
+ * revocation argument is auth's, and `music` was named as the second app that
32
+ * wants it — one app's `src/offline/` is unreachable from every other app.
33
+ *
34
+ * The shell/service-worker/cache half of `roms`' offline work deliberately did
35
+ * NOT come with it: `swRouting`, the outbox and quota relief are shaped around
36
+ * ROM bytes and save states, and whether they generalise is a question to answer
37
+ * with a second consumer in hand.
38
+ *
39
+ * One rename on the way over, and nothing else: `isOfflinePlayAllowed` is
40
+ * {@link isOfflineGrantValid} here, because a library that knows nothing about
41
+ * games should not decide whether "play" is allowed. Every other name, every
42
+ * default and every spec is the one `roms` reasoned about.
43
+ */
44
+
45
+ /**
46
+ * The maximum time a device may use cached content while offline, measured from
47
+ * the last successful online session check. Seven days: long enough for a normal
48
+ * trip, short enough that a revoked account cannot indefinitely retain access by
49
+ * never reconnecting. See the trade-off write-up in `apps/roms/docs/offline.md`.
50
+ *
51
+ * 🔴 **A consumer may pass a SHORTER `maxWindowMs`, never a longer one by
52
+ * default.** This number *is* the revocation argument: the exposure a disabled
53
+ * account keeps is exactly this window, and it was justified against cached game
54
+ * bytes on a device that may never reconnect. Raising the shared default would
55
+ * widen every app's exposure at once, on no app's reasoning.
56
+ */
57
+ export const OFFLINE_MAX_WINDOW_MS = 7 * 24 * 60 * 60 * 1000;
58
+
59
+ /**
60
+ * Proof, stamped at the last successful ONLINE session verification, that this
61
+ * device was a valid session for `accountId` at `lastVerifiedAt`. Persisted
62
+ * locally (e.g. localStorage). It is not a credential — it grants nothing on its
63
+ * own; it only bounds how long already-cached bytes may be replayed offline.
64
+ */
65
+ export interface OfflineGrant {
66
+ accountId: string;
67
+ /** Epoch ms of the last successful online session check. */
68
+ lastVerifiedAt: number;
69
+ /**
70
+ * The account's email, purely so a cold OFFLINE load can put a name in the
71
+ * header instead of a uuid (`apps/roms/src/offlineAuth.ts` is the app that
72
+ * does exactly this). Optional: grants written before 2026-08-05 have none,
73
+ * and nothing may depend on it — it is a label, never a credential and never
74
+ * an identity check.
75
+ */
76
+ email?: string;
77
+ }
78
+
79
+ export type OfflineValidity =
80
+ /** No grant on this device — it never signed in. Offline use is refused. */
81
+ | { state: "no-grant" }
82
+ /** Within the window — offline use allowed. */
83
+ | { state: "valid"; remainingMs: number }
84
+ /** The window has lapsed — offline use refused until a reconnect re-checks. */
85
+ | { state: "expired"; expiredForMs: number };
86
+
87
+ /**
88
+ * How much of the offline window is left, clamped to zero. Negative inputs
89
+ * (a grant stamped in the "future" by a skewed clock) are treated as fully spent
90
+ * rather than trusted, so clock games cannot extend the window.
91
+ */
92
+ export function offlineWindowRemainingMs(
93
+ grant: OfflineGrant,
94
+ now: number,
95
+ maxWindowMs: number = OFFLINE_MAX_WINDOW_MS,
96
+ ): number {
97
+ const elapsed = now - grant.lastVerifiedAt;
98
+ if (elapsed < 0) return 0; // future-stamped grant: don't trust it
99
+ return Math.max(0, maxWindowMs - elapsed);
100
+ }
101
+
102
+ /** The full validity verdict for a (possibly absent) grant at time `now`. */
103
+ export function offlineValidity(
104
+ grant: OfflineGrant | null | undefined,
105
+ now: number,
106
+ maxWindowMs: number = OFFLINE_MAX_WINDOW_MS,
107
+ ): OfflineValidity {
108
+ if (!grant) return { state: "no-grant" };
109
+ const remainingMs = offlineWindowRemainingMs(grant, now, maxWindowMs);
110
+ if (remainingMs > 0) return { state: "valid", remainingMs };
111
+ const elapsed = now - grant.lastVerifiedAt;
112
+ return { state: "expired", expiredForMs: Math.max(0, elapsed - maxWindowMs) };
113
+ }
114
+
115
+ /**
116
+ * Convenience: is offline use permitted on the strength of this grant right now?
117
+ *
118
+ * (`roms` calls this `isOfflinePlayAllowed`; it is the same predicate.)
119
+ */
120
+ export function isOfflineGrantValid(
121
+ grant: OfflineGrant | null | undefined,
122
+ now: number,
123
+ maxWindowMs: number = OFFLINE_MAX_WINDOW_MS,
124
+ ): boolean {
125
+ return offlineValidity(grant, now, maxWindowMs).state === "valid";
126
+ }
127
+
128
+ /**
129
+ * The outcome of an online reconnect check. `revoked` means auth reported the
130
+ * account disabled or the session no longer valid; `verified` means it is still
131
+ * this account and still valid.
132
+ */
133
+ export type ReconnectCheck = { verified: true; accountId: string; at: number } | { revoked: true };
134
+
135
+ /**
136
+ * Fold a fresh online check into the stored grant — the stamp-on-successful-
137
+ * verification hook, and the only way a grant is ever created or refreshed.
138
+ *
139
+ * - verified → a refreshed grant stamped `at` (the window resets).
140
+ * - revoked, OR verified as a DIFFERENT account than the one that cached the
141
+ * bytes → `null`. The caller MUST then purge its content cache: a null grant is
142
+ * the signal that whatever is cached must no longer be usable.
143
+ */
144
+ export function reconcileGrant(
145
+ previous: OfflineGrant | null | undefined,
146
+ check: ReconnectCheck,
147
+ ): OfflineGrant | null {
148
+ if ("revoked" in check) return null;
149
+ // A device that comes back as a different account must not inherit the prior
150
+ // account's offline window over the prior account's cached library.
151
+ if (previous && previous.accountId !== check.accountId) return null;
152
+ return { accountId: check.accountId, lastVerifiedAt: check.at };
153
+ }
@@ -64,7 +64,7 @@
64
64
  * resolves to null and the request is anonymous. Never treat a slot number as
65
65
  * identity — resolve it here, every time.
66
66
  */
67
- import { createHash, createHmac, randomBytes, timingSafeEqual } from "node:crypto";
67
+ import { createHash, createHmac, randomBytes } from "node:crypto";
68
68
  import { mkdirSync } from "node:fs";
69
69
  import path from "node:path";
70
70
  import { Database } from "bun:sqlite";
@@ -83,6 +83,14 @@ import {
83
83
  describePlace,
84
84
  type PlaceLookup,
85
85
  } from "./clientDescription";
86
+ // 🔴 The compare, not a copy of it. This file carried its OWN `constantTimeEqual`
87
+ // until 2026-09-17 — a `node:crypto` `timingSafeEqual` with both sides padded to a
88
+ // common length — while `constantTime.ts` sat two files away with the same contract.
89
+ // That made an eighth copy of this primitive inside the very package that publishes
90
+ // it, and it was found while shipping `cursedauth/constant-time` for the three apps
91
+ // that had each copied the file. Both forms were correct; neither knew about the other,
92
+ // which is the whole failure mode.
93
+ import { constantTimeEqual } from "./constantTime";
86
94
  import { isSecureRequest } from "./secureRequest";
87
95
 
88
96
  export interface UserSessionStoreOptions {
@@ -315,17 +323,6 @@ const TOUCH_THROTTLE_MS = 60_000;
315
323
  */
316
324
  const handleOf = (id: string): string => createHash("sha256").update(id).digest("hex").slice(0, 24);
317
325
 
318
- function constantTimeEqual(a: string, b: string): boolean {
319
- const ab = Buffer.from(a, "utf8");
320
- const bb = Buffer.from(b, "utf8");
321
- const len = Math.max(ab.length, bb.length);
322
- const pa = Buffer.alloc(len);
323
- const pb = Buffer.alloc(len);
324
- ab.copy(pa);
325
- bb.copy(pb);
326
- return timingSafeEqual(pa, pb) && ab.length === bb.length;
327
- }
328
-
329
326
  export function createUserSessionStore(options: UserSessionStoreOptions): UserSessionStore {
330
327
  // Resolved once per store rather than per sign-in. `null` and unset are the
331
328
  // same thing — see `placeLookup` on the options for why there is no default.