@fuzdev/fuz_app 0.183.0 → 0.184.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.
Files changed (179) hide show
  1. package/dist/actions/CLAUDE.md +535 -1223
  2. package/dist/actions/action_codegen.d.ts +1 -1
  3. package/dist/actions/action_codegen.d.ts.map +1 -1
  4. package/dist/actions/action_codegen.js +3 -2
  5. package/dist/actions/connection_closer.d.ts +11 -9
  6. package/dist/actions/connection_closer.d.ts.map +1 -1
  7. package/dist/actions/connection_closer.js +11 -9
  8. package/dist/actions/frontend_rpc_client.d.ts +1 -1
  9. package/dist/actions/register_action_ws.d.ts +14 -1
  10. package/dist/actions/register_action_ws.d.ts.map +1 -1
  11. package/dist/actions/register_action_ws.js +2 -1
  12. package/dist/actions/ws_socket_session.d.ts +9 -1
  13. package/dist/actions/ws_socket_session.d.ts.map +1 -1
  14. package/dist/actions/ws_socket_session.js +43 -19
  15. package/dist/auth/CLAUDE.md +430 -1048
  16. package/dist/auth/account_queries.d.ts +1 -1
  17. package/dist/auth/account_queries.js +1 -1
  18. package/dist/auth/account_routes.d.ts +4 -5
  19. package/dist/auth/account_routes.d.ts.map +1 -1
  20. package/dist/auth/account_routes.js +8 -10
  21. package/dist/auth/admin_actions.d.ts.map +1 -1
  22. package/dist/auth/admin_actions.js +10 -11
  23. package/dist/auth/api_token.d.ts +20 -3
  24. package/dist/auth/api_token.d.ts.map +1 -1
  25. package/dist/auth/api_token.js +28 -9
  26. package/dist/auth/api_token_queries.d.ts +2 -2
  27. package/dist/auth/api_token_queries.js +2 -2
  28. package/dist/auth/audit_log_schema.d.ts +15 -9
  29. package/dist/auth/audit_log_schema.d.ts.map +1 -1
  30. package/dist/auth/audit_log_schema.js +1 -2
  31. package/dist/auth/auth_guard_resolver.d.ts +1 -1
  32. package/dist/auth/auth_guard_resolver.js +1 -1
  33. package/dist/auth/bearer_auth.d.ts +2 -5
  34. package/dist/auth/bearer_auth.d.ts.map +1 -1
  35. package/dist/auth/bearer_auth.js +4 -13
  36. package/dist/auth/bootstrap_account.d.ts +13 -15
  37. package/dist/auth/bootstrap_account.d.ts.map +1 -1
  38. package/dist/auth/bootstrap_account.js +9 -11
  39. package/dist/auth/bootstrap_routes.d.ts +20 -21
  40. package/dist/auth/bootstrap_routes.d.ts.map +1 -1
  41. package/dist/auth/bootstrap_routes.js +21 -19
  42. package/dist/auth/bootstrap_token_store.d.ts +3 -4
  43. package/dist/auth/bootstrap_token_store.d.ts.map +1 -1
  44. package/dist/auth/bootstrap_token_store.js +1 -1
  45. package/dist/auth/daemon_token.d.ts +5 -1
  46. package/dist/auth/daemon_token.d.ts.map +1 -1
  47. package/dist/auth/daemon_token_middleware.d.ts +12 -8
  48. package/dist/auth/daemon_token_middleware.d.ts.map +1 -1
  49. package/dist/auth/daemon_token_middleware.js +15 -21
  50. package/dist/auth/deps.d.ts +11 -0
  51. package/dist/auth/deps.d.ts.map +1 -1
  52. package/dist/auth/invite_queries.d.ts +51 -3
  53. package/dist/auth/invite_queries.d.ts.map +1 -1
  54. package/dist/auth/invite_queries.js +81 -6
  55. package/dist/auth/invite_schema.d.ts +2 -1
  56. package/dist/auth/invite_schema.d.ts.map +1 -1
  57. package/dist/auth/middleware.d.ts +2 -3
  58. package/dist/auth/middleware.d.ts.map +1 -1
  59. package/dist/auth/middleware.js +3 -3
  60. package/dist/auth/request_context.d.ts +3 -3
  61. package/dist/auth/request_context.js +3 -3
  62. package/dist/auth/role_grant_offer_actions.d.ts +2 -2
  63. package/dist/auth/role_grant_offer_actions.js +2 -2
  64. package/dist/auth/session_cookie.d.ts +82 -174
  65. package/dist/auth/session_cookie.d.ts.map +1 -1
  66. package/dist/auth/session_cookie.js +80 -130
  67. package/dist/auth/session_middleware.d.ts +8 -17
  68. package/dist/auth/session_middleware.d.ts.map +1 -1
  69. package/dist/auth/session_middleware.js +14 -23
  70. package/dist/auth/session_queries.d.ts +9 -14
  71. package/dist/auth/session_queries.d.ts.map +1 -1
  72. package/dist/auth/session_queries.js +8 -9
  73. package/dist/auth/signup_routes.d.ts.map +1 -1
  74. package/dist/auth/signup_routes.js +4 -6
  75. package/dist/db/CLAUDE.md +5 -3
  76. package/dist/dev/setup.d.ts +3 -1
  77. package/dist/dev/setup.d.ts.map +1 -1
  78. package/dist/dev/setup.js +3 -1
  79. package/dist/http/CLAUDE.md +315 -768
  80. package/dist/http/db_routes.d.ts +1 -1
  81. package/dist/http/db_routes.js +1 -1
  82. package/dist/http/origin.d.ts +7 -8
  83. package/dist/http/origin.d.ts.map +1 -1
  84. package/dist/http/origin.js +7 -8
  85. package/dist/http/pending_effects.d.ts +78 -4
  86. package/dist/http/pending_effects.d.ts.map +1 -1
  87. package/dist/http/pending_effects.js +82 -4
  88. package/dist/http/route_result.d.ts +1 -1
  89. package/dist/http/route_spec.d.ts +14 -11
  90. package/dist/http/route_spec.d.ts.map +1 -1
  91. package/dist/realtime/sse.d.ts +4 -23
  92. package/dist/realtime/sse.d.ts.map +1 -1
  93. package/dist/realtime/sse.js +4 -25
  94. package/dist/server/app_backend.d.ts +4 -5
  95. package/dist/server/app_backend.d.ts.map +1 -1
  96. package/dist/server/app_backend.js +3 -1
  97. package/dist/server/app_server.d.ts +53 -30
  98. package/dist/server/app_server.d.ts.map +1 -1
  99. package/dist/server/app_server.js +81 -53
  100. package/dist/server/app_server_context.d.ts +1 -2
  101. package/dist/server/app_server_context.d.ts.map +1 -1
  102. package/dist/server/env.js +2 -2
  103. package/dist/testing/CLAUDE.md +17 -17
  104. package/dist/testing/admin_integration.d.ts +2 -3
  105. package/dist/testing/admin_integration.d.ts.map +1 -1
  106. package/dist/testing/admin_integration.js +3 -3
  107. package/dist/testing/app_server.d.ts +3 -8
  108. package/dist/testing/app_server.d.ts.map +1 -1
  109. package/dist/testing/app_server.js +10 -9
  110. package/dist/testing/attack_surface.d.ts +1 -1
  111. package/dist/testing/attack_surface.d.ts.map +1 -1
  112. package/dist/testing/audit_completeness.d.ts +2 -3
  113. package/dist/testing/audit_completeness.d.ts.map +1 -1
  114. package/dist/testing/audit_completeness.js +1 -1
  115. package/dist/testing/cross_backend/capability_mounts.d.ts.map +1 -1
  116. package/dist/testing/cross_backend/capability_mounts.js +16 -11
  117. package/dist/testing/cross_backend/conformance_table.d.ts +5 -6
  118. package/dist/testing/cross_backend/conformance_table.d.ts.map +1 -1
  119. package/dist/testing/cross_backend/conformance_table.js +4 -4
  120. package/dist/testing/cross_backend/cookie_attributes.js +1 -1
  121. package/dist/testing/cross_backend/default_backend_configs.d.ts +3 -3
  122. package/dist/testing/cross_backend/default_spine_surface.d.ts +0 -6
  123. package/dist/testing/cross_backend/default_spine_surface.d.ts.map +1 -1
  124. package/dist/testing/cross_backend/default_spine_surface.js +4 -9
  125. package/dist/testing/cross_backend/differential.d.ts +2 -3
  126. package/dist/testing/cross_backend/differential.d.ts.map +1 -1
  127. package/dist/testing/cross_backend/differential.js +1 -1
  128. package/dist/testing/cross_backend/full_spine_mount.d.ts +1 -42
  129. package/dist/testing/cross_backend/full_spine_mount.d.ts.map +1 -1
  130. package/dist/testing/cross_backend/full_spine_mount.js +45 -4
  131. package/dist/testing/cross_backend/in_process_setup.d.ts +6 -7
  132. package/dist/testing/cross_backend/in_process_setup.d.ts.map +1 -1
  133. package/dist/testing/cross_backend/in_process_setup.js +9 -12
  134. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts +3 -4
  135. package/dist/testing/cross_backend/rust_spine_consumer_surface.d.ts.map +1 -1
  136. package/dist/testing/cross_backend/rust_spine_consumer_surface.js +2 -2
  137. package/dist/testing/cross_backend/setup.d.ts +1 -1
  138. package/dist/testing/cross_backend/spine_suites.d.ts +2 -3
  139. package/dist/testing/cross_backend/spine_suites.d.ts.map +1 -1
  140. package/dist/testing/cross_backend/spine_suites.js +5 -5
  141. package/dist/testing/cross_backend/standard.d.ts +2 -3
  142. package/dist/testing/cross_backend/standard.d.ts.map +1 -1
  143. package/dist/testing/cross_backend/standard.js +3 -3
  144. package/dist/testing/cross_backend/testing_credential_read.d.ts +10 -11
  145. package/dist/testing/cross_backend/testing_credential_read.d.ts.map +1 -1
  146. package/dist/testing/cross_backend/testing_credential_read.js +12 -12
  147. package/dist/testing/cross_backend/testing_reset_actions.d.ts +35 -30
  148. package/dist/testing/cross_backend/testing_reset_actions.d.ts.map +1 -1
  149. package/dist/testing/cross_backend/testing_reset_actions.js +39 -31
  150. package/dist/testing/cross_backend/testing_server_core.d.ts.map +1 -1
  151. package/dist/testing/cross_backend/testing_server_core.js +2 -3
  152. package/dist/testing/daemon_token_rotation.d.ts.map +1 -1
  153. package/dist/testing/daemon_token_rotation.js +2 -3
  154. package/dist/testing/integration.d.ts +2 -3
  155. package/dist/testing/integration.d.ts.map +1 -1
  156. package/dist/testing/integration.js +4 -4
  157. package/dist/testing/rate_limiting.d.ts +2 -3
  158. package/dist/testing/rate_limiting.d.ts.map +1 -1
  159. package/dist/testing/rate_limiting.js +3 -3
  160. package/dist/testing/rpc_helpers.d.ts +1 -2
  161. package/dist/testing/rpc_helpers.d.ts.map +1 -1
  162. package/dist/testing/rpc_helpers.js +3 -3
  163. package/dist/testing/rpc_round_trip.d.ts +2 -3
  164. package/dist/testing/rpc_round_trip.d.ts.map +1 -1
  165. package/dist/testing/rpc_round_trip.js +1 -1
  166. package/dist/testing/sse_round_trip.d.ts +2 -3
  167. package/dist/testing/sse_round_trip.d.ts.map +1 -1
  168. package/dist/testing/sse_round_trip.js +2 -2
  169. package/dist/testing/stubs.d.ts +5 -6
  170. package/dist/testing/stubs.d.ts.map +1 -1
  171. package/dist/testing/stubs.js +10 -8
  172. package/dist/testing/test_app.d.ts +5 -3
  173. package/dist/testing/test_app.d.ts.map +1 -1
  174. package/dist/testing/test_app.js +2 -3
  175. package/dist/testing/ws_round_trip.d.ts.map +1 -1
  176. package/dist/testing/ws_round_trip.js +3 -0
  177. package/dist/ui/ui_format.d.ts.map +1 -1
  178. package/dist/ui/ui_format.js +1 -2
  179. package/package.json +1 -1
@@ -1,24 +1,32 @@
1
1
  /**
2
- * Generic session management for cookie-based auth.
2
+ * The signed session cookie: its name, value format, verification, and the
3
+ * exact `Set-Cookie` strings that set and clear it — byte for byte the Rust
4
+ * spine's `fuz_auth::session_cookie`.
3
5
  *
4
- * Parameterized on identity type via `SessionOptions<TIdentity>`.
5
- * Handles signing, expiration, and key rotation. Apps provide
6
- * encode/decode for their specific identity format.
7
- *
8
- * Cookie value format: `${encode(identity)}:${expires_at}` (signed with HMAC-SHA256).
6
+ * Cookie value: `keyring.sign("${session_token}:${expires_at}")`. The signed
7
+ * payload carries the raw session token (whose blake3 hash is the
8
+ * `auth_session` row id) and its expiry, so one HMAC covers both the token
9
+ * bind and the freshness check.
9
10
  *
10
11
  * @module
11
12
  */
13
+ import { read_session_cookie_value } from './credential_headers.js';
14
+ /**
15
+ * The default session cookie name — the Rust spine's `SESSION_COOKIE_NAME`,
16
+ * so a cookie either spine mints reads on both. An app with its own name
17
+ * passes it as `session_cookie_name` wherever the spine takes one.
18
+ */
19
+ export const SESSION_COOKIE_NAME = 'fuz_session';
12
20
  /**
13
21
  * Cookie max age in seconds (30 days — aligned with AUTH_SESSION_LIFETIME_MS).
14
22
  *
15
23
  * This is an **absolute** session lifetime: the cookie is signed once at
16
- * mint (`expires_at = mint + max_age`) and never re-signed, matching the DB
24
+ * mint (`expires_at = mint + SESSION_AGE_MAX`) and never re-signed, matching the DB
17
25
  * row's fixed `expires_at`. There is deliberately no sliding renewal on
18
26
  * either leg — see `docs/security.md` §Session Security.
19
27
  */
20
28
  export const SESSION_AGE_MAX = 60 * 60 * 24 * 30;
21
- /** Separator between identity payload and expires_at in signed value. */
29
+ /** Separator between the session token and `expires_at` in the signed value. */
22
30
  const VALUE_SEPARATOR = ':';
23
31
  /** Strict integer matcher for the embedded `expires_at` field. */
24
32
  const EXPIRES_AT_INTEGER_RE = /^\d+$/;
@@ -58,9 +66,8 @@ export const is_cookie_name = (name) => typeof name === 'string' && COOKIE_NAME_
58
66
  * what a reader that decodes nothing needs. Twin of the Rust spine's
59
67
  * `is_cookie_value`.
60
68
  *
61
- * Anything but a string is refused, whatever its type says: the value comes
62
- * out of a consumer's `encode_identity` and keyring, and a regex alone would
63
- * read `undefined` as the text `undefined`.
69
+ * Anything but a string is refused, whatever its type says: a regex alone
70
+ * would read `undefined` as the text `undefined`.
64
71
  *
65
72
  * @param value - a cookie value
66
73
  */
@@ -87,14 +94,14 @@ const assert_cookie_name = (cookie_name) => {
87
94
  * @param value - the signed cookie value (`create_session_cookie_value`)
88
95
  * @param max_age - the cookie's lifetime in seconds
89
96
  * @returns the `Set-Cookie` header value
90
- * @throws Error when the name is not an RFC 6265 `cookie-name`, the value holds anything but `cookie-octet`s (an `encode_identity` that emits a space, a `;`, or a non-ASCII character), or `max_age` is not a non-negative safe integer — a header that would read back differently is never written
97
+ * @throws Error when the name is not an RFC 6265 `cookie-name`, the value holds anything but `cookie-octet`s (a space, a `;`, a non-ASCII character), or `max_age` is not a non-negative safe integer — a header that would read back differently is never written
91
98
  */
92
99
  export const format_session_set_cookie = (cookie_name, value, max_age) => {
93
100
  assert_cookie_name(cookie_name);
94
101
  if (!is_cookie_value(value)) {
95
102
  // the value is a credential: say what is wrong with it, never what it is
96
103
  throw new Error(`session cookie '${cookie_name}': the signed value holds a character outside RFC 6265's ` +
97
- 'cookie-octets — `encode_identity` must emit only visible ASCII without `"`, `,`, `;` or `\\`');
104
+ 'cookie-octets — only visible ASCII without `"`, `,`, `;` or `\\` can be written');
98
105
  }
99
106
  if (!Number.isSafeInteger(max_age) || max_age < 0) {
100
107
  throw new Error(`session cookie '${cookie_name}': max_age ${max_age} is not a whole number of seconds`);
@@ -115,60 +122,51 @@ export const format_session_clear_cookie = (cookie_name) => {
115
122
  return `${cookie_name}=; ${SESSION_COOKIE_ATTRIBUTES}; Max-Age=0`;
116
123
  };
117
124
  /**
118
- * The `Set-Cookie` value that sets the session cookie to `value`, a signed
119
- * cookie value (`create_session_cookie_value`, or the `cookie_value` of
120
- * `create_capped_session`) — what a success carries
121
- * (`route_ok(value, {set_cookie: [...]})`). `options.max_age` sets `Max-Age`,
122
- * as it set the value's embedded expiry; `SESSION_AGE_MAX` when unset. Twin of
123
- * the Rust `session_cookie_header`, which signs the token itself.
125
+ * Sign a session token into a session cookie value: the keyring's signature
126
+ * of `${session_token}:${expires_at}`, the expiry `SESSION_AGE_MAX` from now —
127
+ * what a `Cookie` header carries after `<name>=`. Signed once, at mint: the
128
+ * lifetime is absolute, never renewed (`docs/security.md` §Session Security).
129
+ * Twin of the Rust `create_session_cookie_value`.
124
130
  *
125
- * @param value - the signed cookie value
126
- * @param options - the cookie name and lifetime
127
- * @returns the `Set-Cookie` header value (`format_session_set_cookie`)
128
- * @throws Error when the cookie name or the value is outside the RFC 6265 grammar
131
+ * @param keyring - key ring for signing
132
+ * @param session_token - the raw session token
133
+ * @param now_seconds - current time in seconds (for testing)
134
+ * @returns the signed cookie value
129
135
  */
130
- export const session_cookie_header = (value, options) => format_session_set_cookie(options.cookie_name, value, options.max_age ?? SESSION_AGE_MAX);
136
+ export const create_session_cookie_value = async (keyring, session_token, now_seconds) => {
137
+ const now = now_seconds ?? Math.floor(Date.now() / 1000);
138
+ return keyring.sign(`${session_token}${VALUE_SEPARATOR}${now + SESSION_AGE_MAX}`);
139
+ };
131
140
  /**
132
- * The `Set-Cookie` value that clears the session cookie — what a logout or a
133
- * password change carries on its success. Twin of the Rust
134
- * `clear_session_cookie_header`.
141
+ * Sign a session token and build the `Set-Cookie` header value that sets it
142
+ * under `cookie_name` — `format_session_set_cookie` over
143
+ * `create_session_cookie_value`, with `SESSION_AGE_MAX` as its lifetime. What
144
+ * a success that mints a session carries (`route_ok(value, {set_cookie})`).
145
+ * Twin of the Rust `sign_session_cookie`.
135
146
  *
136
- * @param options - the cookie name
137
- * @returns the `Set-Cookie` header value (`format_session_clear_cookie`)
138
- * @throws Error when the cookie name is outside the RFC 6265 grammar
147
+ * @param keyring - key ring for signing
148
+ * @param session_token - the raw session token (`create_capped_session`'s `token`)
149
+ * @param cookie_name - the session cookie's name
150
+ * @returns the `Set-Cookie` header value
151
+ * @throws Error when the cookie name, or the signed value, is outside the RFC 6265 grammar
139
152
  */
140
- export const clear_session_cookie_header = (options) => format_session_clear_cookie(options.cookie_name);
153
+ export const sign_session_cookie = async (keyring, session_token, cookie_name) => format_session_set_cookie(cookie_name, await create_session_cookie_value(keyring, session_token), SESSION_AGE_MAX);
141
154
  /**
142
- * Parse a signed session cookie value.
143
- *
144
- * The signed value format is `${encode(identity)}:${expires_at}`.
145
- * Tries all keys in order to support key rotation.
146
- *
147
- * An empty string is a cookie that was sent with no value (`name=`): present
148
- * and invalid, like any other value that fails verification. Only a nullish
149
- * `signed_value` is "no cookie".
150
- *
151
- * @param signed_value - the raw cookie value (signed), nullish when the request carries no session cookie
152
- * @param keyring - key ring for verification
153
- * @param options - session configuration with decode logic
154
- * @param now_seconds - current time in seconds (for testing)
155
- * @returns `ParsedSession` if valid, null if invalid/expired (the empty string included), undefined if missing
155
+ * Verify one signed cookie value: the MAC under any of the keyring's keys (a
156
+ * retired key keeps verifying until it leaves the keyring — safe to drop after
157
+ * `SESSION_AGE_MAX`, `docs/security.md` §Cookie Key Rotation), the
158
+ * `expires_at` grammar and freshness, and a non-empty token.
156
159
  */
157
- export const parse_session = async (signed_value, keyring, options, now_seconds) => {
158
- if (signed_value == null)
159
- return undefined;
160
+ const verify_session_cookie_value = async (signed_value, keyring, now_seconds) => {
160
161
  const result = await keyring.verify(signed_value);
161
162
  if (!result)
162
163
  return null;
163
- // Split on the last VALUE_SEPARATOR to get identity_payload and expires_at
164
+ // split on the last separator: the token, then the signed expiry
164
165
  const last_sep = result.value.lastIndexOf(VALUE_SEPARATOR);
165
166
  if (last_sep === -1)
166
167
  return null;
167
- const identity_payload = result.value.slice(0, last_sep);
168
+ const token = result.value.slice(0, last_sep);
168
169
  const expires_at_str = result.value.slice(last_sep + 1);
169
- const identity = options.decode_identity(identity_payload);
170
- if (identity === null)
171
- return null;
172
170
  // Strict integer match — `parseInt` would accept `'123abc'` as `123` and
173
171
  // `' 123'` as `123`. HMAC integrity makes such a tampered value
174
172
  // theoretical, but stricter parsing closes the gap as defense-in-depth.
@@ -178,86 +176,38 @@ export const parse_session = async (signed_value, keyring, options, now_seconds)
178
176
  if (BigInt(expires_at_str) > EXPIRES_AT_MAX)
179
177
  return null;
180
178
  const expires_at = parseInt(expires_at_str, 10);
181
- // Check expiration
182
- const now = now_seconds ?? Math.floor(Date.now() / 1000);
183
- if (expires_at <= now)
179
+ if (expires_at <= now_seconds)
184
180
  return null;
185
- return {
186
- identity,
187
- key_index: result.key_index,
188
- expires_at
189
- };
190
- };
191
- /**
192
- * Create a signed session cookie value.
193
- *
194
- * Format: `${encode(identity)}:${expires_at}` signed with HMAC-SHA256.
195
- * Embeds expiration in the signed value itself for defense-in-depth.
196
- *
197
- * @param keyring - key ring for signing
198
- * @param identity - the identity to encode
199
- * @param options - session configuration with encode logic
200
- * @param now_seconds - current time in seconds (for testing)
201
- * @returns signed cookie value string
202
- */
203
- export const create_session_cookie_value = async (keyring, identity, options, now_seconds) => {
204
- const max_age = options.max_age ?? SESSION_AGE_MAX;
205
- const now = now_seconds ?? Math.floor(Date.now() / 1000);
206
- const expires_at = now + max_age;
207
- const value = `${options.encode_identity(identity)}${VALUE_SEPARATOR}${expires_at}`;
208
- return keyring.sign(value);
181
+ if (token === '')
182
+ return null;
183
+ return { token, expires_at };
209
184
  };
210
185
  /**
211
- * Create a session config for raw session token identity.
212
- *
213
- * The standard pattern: cookie stores the raw session token,
214
- * server hashes it (blake3) to look up the `auth_session` row.
215
- * Only the `cookie_name` varies per app.
216
- *
217
- * @param cookie_name - cookie name (e.g. `'zap_session'`, `'visiones_session'`)
218
- * @returns a `SessionOptions<string>` ready for use with session middleware
219
- */
220
- export const create_session_config = (cookie_name) => ({
221
- cookie_name,
222
- encode_identity: (session_id) => session_id,
223
- decode_identity: (payload) => payload || null
224
- });
225
- /** Canonical session config for fuz_app auth. */
226
- export const fuz_session_config = create_session_config('fuz_session');
227
- /**
228
- * Process a session cookie and determine what action to take.
229
- *
230
- * There is deliberately no refresh action: any re-sign computes a fresh
231
- * `now + max_age` expiry, extending the cookie past the DB row's fixed
232
- * `expires_at` — the holder would go silently anonymous while carrying a
233
- * self-perpetuating cookie. The absolute lifetime is one signing at mint,
234
- * on both legs, matching the Rust spine. A cookie signed by a retired
235
- * (non-primary) key keeps verifying until the key leaves the keyring;
236
- * retired keys are safe to drop after `SESSION_AGE_MAX` (see
237
- * `docs/security.md` §Cookie Key Rotation).
238
- *
239
- * The three outcomes are what the cookie alone shows: no cookie (`action:
240
- * 'none'`), a cookie that fails verification — unreadable, a bad MAC, a signed
241
- * expiry that has passed, an empty identity, an empty value — (`action:
242
- * 'clear'`), and a valid one. A valid cookie whose `auth_session` row is gone
243
- * is still valid here; nothing clears it.
244
- *
245
- * @param signed_value - the raw cookie value, nullish when the request carries no session cookie
246
- * @param keyring - key ring for verification and signing
247
- * @param options - session configuration
186
+ * Read the session cookie out of a request's `Cookie` lines: the
187
+ * `cookie_name` pair (`read_session_cookie_value` — the first, verbatim),
188
+ * verified under the keyring, its signed expiry checked, its session token
189
+ * answered with that expiry.
190
+ *
191
+ * The three answers are what the cookie alone shows (`SessionCookieRead`). An
192
+ * empty value (`name=`) is a cookie sent with none: present and invalid. A
193
+ * valid cookie whose `auth_session` row is gone is still valid here; nothing
194
+ * clears it. There is deliberately no refresh: a re-sign would compute a
195
+ * fresh expiry past the row's fixed `expires_at`, so the lifetime is the one
196
+ * signing at mint, on both spines.
197
+ *
198
+ * Twin of the Rust `parse_session_from_cookies`, which takes the request's
199
+ * headers.
200
+ *
201
+ * @param cookie_lines - the request's `Cookie` header lines
202
+ * @param keyring - key ring for verification
203
+ * @param cookie_name - the session cookie's name
248
204
  * @param now_seconds - current time in seconds (for testing)
249
- * @returns result with validity and action to take
205
+ * @returns the cookie's reading
250
206
  */
251
- export const process_session_cookie = async (signed_value, keyring, options, now_seconds) => {
252
- const now = now_seconds ?? Math.floor(Date.now() / 1000);
253
- const parsed = await parse_session(signed_value, keyring, options, now);
254
- if (parsed === undefined) {
255
- // No cookie present
256
- return { valid: false, action: 'none' };
257
- }
258
- if (parsed === null) {
259
- // Invalid cookie - should be cleared
260
- return { valid: false, action: 'clear' };
261
- }
262
- return { valid: true, action: 'none', identity: parsed.identity, expires_at: parsed.expires_at };
207
+ export const parse_session_from_cookies = async (cookie_lines, keyring, cookie_name, now_seconds) => {
208
+ const signed_value = read_session_cookie_value(cookie_lines, cookie_name);
209
+ if (signed_value === null)
210
+ return { kind: 'absent' };
211
+ const cookie = await verify_session_cookie_value(signed_value, keyring, now_seconds ?? Math.floor(Date.now() / 1000));
212
+ return cookie ? { kind: 'valid', cookie } : { kind: 'invalid' };
263
213
  };
@@ -1,36 +1,27 @@
1
1
  /**
2
- * Hono session boundary — the session cookie read off a request, and the
3
- * request-time middleware that resolves it and clears a stale one.
2
+ * Hono session boundary — the request-time middleware that reads the session
3
+ * cookie off a request, resolves it, and clears a stale one.
4
4
  *
5
5
  * The cookie is read from the request's `Cookie` lines by
6
- * `read_session_cookie_value` and written as the exact `Set-Cookie` strings of
6
+ * `parse_session_from_cookies` and written as the exact `Set-Cookie` strings of
7
7
  * `auth/session_cookie.ts` — no framework cookie parser or serializer sits on
8
8
  * the credential path, so nothing is percent-decoded on the way in or
9
9
  * percent-encoded on the way out. A route sets or clears the cookie by
10
10
  * returning the line on its success (`route_ok(value, {set_cookie})`, the
11
- * lines from `session_cookie_header` and `clear_session_cookie_header`), never
11
+ * lines from `sign_session_cookie` and `format_session_clear_cookie`), never
12
12
  * by writing on the context.
13
13
  *
14
14
  * @module
15
15
  */
16
- import type { Context, MiddlewareHandler } from 'hono';
16
+ import type { MiddlewareHandler } from 'hono';
17
17
  import type { Keyring } from './keyring.js';
18
- import { type SessionOptions } from './session_cookie.js';
19
- /**
20
- * Read the session cookie's value from a request, as sent
21
- * (`read_session_cookie_value` over the request's `Cookie` lines).
22
- *
23
- * @returns the value — `''` for a cookie sent with none — or `null` when the request carries no session cookie
24
- */
25
- export declare const get_session_cookie: <T>(c: Context, options: SessionOptions<T>) => string | null;
26
18
  /**
27
19
  * Create session middleware that parses cookies and sets the session token on
28
20
  * context.
29
21
  *
30
22
  * Always sets `SESSION_TOKEN_KEY` (null when invalid/missing) for type-safe
31
23
  * reads — the key the session leg (`create_request_context_middleware`)
32
- * reads. The identity is the session token, so the options are a
33
- * `SessionOptions<string>`.
24
+ * reads.
34
25
  *
35
26
  * A cookie that is present and fails verification is cleared — an empty value
36
27
  * (`name=`) included; a request with no session cookie clears nothing. The
@@ -100,8 +91,8 @@ export declare const get_session_cookie: <T>(c: Context, options: SessionOptions
100
91
  * where its own router puts the auth scope.
101
92
  *
102
93
  * @param keyring - key ring for cookie verification
103
- * @param options - session configuration
94
+ * @param session_cookie_name - the session cookie's name
104
95
  * @mutates Hono context - sets `SESSION_TOKEN_KEY` and `SESSION_COOKIE_EXPIRES_AT_KEY`, and may put the clearing `Set-Cookie` on the context's headers, recording it under `EXPECTED_FIRST_SET_COOKIE_KEY`
105
96
  */
106
- export declare const create_session_middleware: (keyring: Keyring, options: SessionOptions<string>) => MiddlewareHandler;
97
+ export declare const create_session_middleware: (keyring: Keyring, session_cookie_name: string) => MiddlewareHandler;
107
98
  //# sourceMappingURL=session_middleware.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"session_middleware.d.ts","sourceRoot":"","sources":["../../src/lib/auth/session_middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAEvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EACN,KAAK,cAAc,EAGnB,MAAM,qBAAqB,CAAC;AAQ7B;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,EAAE,GAAG,OAAO,EAAE,SAAS,cAAc,CAAC,CAAC,CAAC,KAAG,MAAM,GAAG,IACV,CAAC;AAE/E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+EG;AACH,eAAO,MAAM,yBAAyB,GACrC,SAAS,OAAO,EAChB,SAAS,cAAc,CAAC,MAAM,CAAC,KAC7B,iBAoBF,CAAC"}
1
+ {"version":3,"file":"session_middleware.d.ts","sourceRoot":"","sources":["../../src/lib/auth/session_middleware.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AAE9C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAS5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8EG;AACH,eAAO,MAAM,yBAAyB,GACrC,SAAS,OAAO,EAChB,qBAAqB,MAAM,KACzB,iBAwBF,CAAC"}
@@ -1,37 +1,28 @@
1
1
  /**
2
- * Hono session boundary — the session cookie read off a request, and the
3
- * request-time middleware that resolves it and clears a stale one.
2
+ * Hono session boundary — the request-time middleware that reads the session
3
+ * cookie off a request, resolves it, and clears a stale one.
4
4
  *
5
5
  * The cookie is read from the request's `Cookie` lines by
6
- * `read_session_cookie_value` and written as the exact `Set-Cookie` strings of
6
+ * `parse_session_from_cookies` and written as the exact `Set-Cookie` strings of
7
7
  * `auth/session_cookie.ts` — no framework cookie parser or serializer sits on
8
8
  * the credential path, so nothing is percent-decoded on the way in or
9
9
  * percent-encoded on the way out. A route sets or clears the cookie by
10
10
  * returning the line on its success (`route_ok(value, {set_cookie})`, the
11
- * lines from `session_cookie_header` and `clear_session_cookie_header`), never
11
+ * lines from `sign_session_cookie` and `format_session_clear_cookie`), never
12
12
  * by writing on the context.
13
13
  *
14
14
  * @module
15
15
  */
16
- import { read_session_cookie_value } from './credential_headers.js';
17
- import { format_session_clear_cookie, process_session_cookie } from './session_cookie.js';
16
+ import { format_session_clear_cookie, parse_session_from_cookies } from './session_cookie.js';
18
17
  import { EXPECTED_FIRST_SET_COOKIE_KEY, SESSION_COOKIE_EXPIRES_AT_KEY, SESSION_TOKEN_KEY } from '../hono_context.js';
19
18
  import { get_header_lines } from '../http/header_lines.js';
20
- /**
21
- * Read the session cookie's value from a request, as sent
22
- * (`read_session_cookie_value` over the request's `Cookie` lines).
23
- *
24
- * @returns the value — `''` for a cookie sent with none — or `null` when the request carries no session cookie
25
- */
26
- export const get_session_cookie = (c, options) => read_session_cookie_value(get_header_lines(c, 'Cookie'), options.cookie_name);
27
19
  /**
28
20
  * Create session middleware that parses cookies and sets the session token on
29
21
  * context.
30
22
  *
31
23
  * Always sets `SESSION_TOKEN_KEY` (null when invalid/missing) for type-safe
32
24
  * reads — the key the session leg (`create_request_context_middleware`)
33
- * reads. The identity is the session token, so the options are a
34
- * `SessionOptions<string>`.
25
+ * reads.
35
26
  *
36
27
  * A cookie that is present and fails verification is cleared — an empty value
37
28
  * (`name=`) included; a request with no session cookie clears nothing. The
@@ -101,21 +92,21 @@ export const get_session_cookie = (c, options) => read_session_cookie_value(get_
101
92
  * where its own router puts the auth scope.
102
93
  *
103
94
  * @param keyring - key ring for cookie verification
104
- * @param options - session configuration
95
+ * @param session_cookie_name - the session cookie's name
105
96
  * @mutates Hono context - sets `SESSION_TOKEN_KEY` and `SESSION_COOKIE_EXPIRES_AT_KEY`, and may put the clearing `Set-Cookie` on the context's headers, recording it under `EXPECTED_FIRST_SET_COOKIE_KEY`
106
97
  */
107
- export const create_session_middleware = (keyring, options) => {
98
+ export const create_session_middleware = (keyring, session_cookie_name) => {
108
99
  return async (c, next) => {
109
- const signed_value = get_session_cookie(c, options);
110
- const result = await process_session_cookie(signed_value, keyring, options);
100
+ const read = await parse_session_from_cookies(get_header_lines(c, 'Cookie'), keyring, session_cookie_name);
101
+ const cookie = read.kind === 'valid' ? read.cookie : null;
111
102
  // Always set the token (null when invalid/missing) for type-safe reads
112
- c.set(SESSION_TOKEN_KEY, result.identity ?? null);
103
+ c.set(SESSION_TOKEN_KEY, cookie?.token ?? null);
113
104
  // the signed expiry rides beside it, for the credential deadline
114
- c.set(SESSION_COOKIE_EXPIRES_AT_KEY, result.expires_at ?? null);
105
+ c.set(SESSION_COOKIE_EXPIRES_AT_KEY, cookie?.expires_at ?? null);
115
106
  // ahead of the handler, so it precedes any `Set-Cookie` a success carries;
116
107
  // recorded, so the DEV `Set-Cookie` check can see a response that lost it
117
- if (result.action === 'clear') {
118
- const clear = format_session_clear_cookie(options.cookie_name);
108
+ if (read.kind === 'invalid') {
109
+ const clear = format_session_clear_cookie(session_cookie_name);
119
110
  c.header('Set-Cookie', clear, { append: true });
120
111
  c.set(EXPECTED_FIRST_SET_COOKIE_KEY, clear);
121
112
  }
@@ -7,8 +7,6 @@
7
7
  * @module
8
8
  */
9
9
  import type { QueryDeps } from '../db/query_deps.js';
10
- import type { Keyring } from './keyring.js';
11
- import { type SessionOptions } from './session_cookie.js';
12
10
  import type { AuthSession, SessionId } from './account_schema.js';
13
11
  /**
14
12
  * Session lifetime in milliseconds (30 days).
@@ -245,29 +243,26 @@ export declare const query_session_cleanup_expired: (deps: QueryDeps) => Promise
245
243
  * Options for `create_capped_session`.
246
244
  */
247
245
  export interface CreateCappedSessionOptions {
248
- /** Keyring for cookie signing. */
249
- keyring: Keyring;
250
246
  /** Query deps (needs db for session creation). */
251
247
  deps: QueryDeps;
252
248
  /** The account to create a session for. */
253
249
  account_id: string;
254
- /** Session cookie configuration. */
255
- session_options: SessionOptions<string>;
256
250
  /** Per-account session cap (`null` to skip enforcement). */
257
251
  max_sessions?: number | null;
258
252
  }
259
- /** What `create_capped_session` minted. */
253
+ /** What `create_capped_session` minted. Twin of the Rust `CappedSession`. */
260
254
  export interface CappedSession {
261
- /** The signed session cookie value, for `session_cookie_header`. */
262
- cookie_value: string;
255
+ /** The raw session token, for `sign_session_cookie` — a live credential. */
256
+ token: string;
263
257
  /** The token hashes of the sessions the cap evicted, empty without a cap. */
264
258
  evicted: Array<string>;
265
259
  }
266
260
  /**
267
- * Mint an auth session: generate a token, persist its hashed row, enforce
268
- * the per-account cap when given one, and sign the cookie value — without
269
- * touching a response, so a caller minting inside a transaction sets the
270
- * cookie only once that transaction has succeeded. Twin of the Rust
261
+ * Mint an auth session: generate a token, persist its hashed row, and enforce
262
+ * the per-account cap when given one — without touching a response. The
263
+ * caller signs the token into its `Set-Cookie` line (`sign_session_cookie`)
264
+ * and sets it on its success, so a session minted inside a transaction gets
265
+ * its cookie only once that transaction has succeeded. Twin of the Rust
271
266
  * `fuz_auth::create_capped_session`.
272
267
  *
273
268
  * The cap deletes the sessions it evicts, but not the connections they
@@ -282,7 +277,7 @@ export interface CappedSession {
282
277
  * account's mints take turns, which the cap counts on
283
278
  * (`query_session_enforce_limit`).
284
279
  *
285
- * @returns the signed cookie value and the evicted sessions' token hashes
280
+ * @returns the raw session token and the evicted sessions' token hashes
286
281
  * @mutates `auth_session` table - inserts the new session row (and evicts older rows when `max_sessions` is set)
287
282
  */
288
283
  export declare const create_capped_session: (options: CreateCappedSessionOptions) => Promise<CappedSession>;
@@ -1 +1 @@
1
- {"version":3,"file":"session_queries.d.ts","sourceRoot":"","sources":["../../src/lib/auth/session_queries.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAA+B,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEvF,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAMlE;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,QAAuC,CAAC;AAE7E;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GA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generate_random_base64url } from '../crypto.js';
11
- import { create_session_cookie_value } from './session_cookie.js';
12
11
  import { columns_sql, iso8601_timestamp_expr, qualify_columns } from '../db/sql_columns.js';
13
12
  import { EXPIRES_IN_MS_SQL } from './credential_deadline.js';
14
13
  /** The session lifetime in whole seconds, which the insert's interval spells. */
@@ -298,10 +297,11 @@ export const query_session_cleanup_expired = async (deps) => {
298
297
  return rows.map((row) => row.id);
299
298
  };
300
299
  /**
301
- * Mint an auth session: generate a token, persist its hashed row, enforce
302
- * the per-account cap when given one, and sign the cookie value — without
303
- * touching a response, so a caller minting inside a transaction sets the
304
- * cookie only once that transaction has succeeded. Twin of the Rust
300
+ * Mint an auth session: generate a token, persist its hashed row, and enforce
301
+ * the per-account cap when given one — without touching a response. The
302
+ * caller signs the token into its `Set-Cookie` line (`sign_session_cookie`)
303
+ * and sets it on its success, so a session minted inside a transaction gets
304
+ * its cookie only once that transaction has succeeded. Twin of the Rust
305
305
  * `fuz_auth::create_capped_session`.
306
306
  *
307
307
  * The cap deletes the sessions it evicts, but not the connections they
@@ -316,15 +316,14 @@ export const query_session_cleanup_expired = async (deps) => {
316
316
  * account's mints take turns, which the cap counts on
317
317
  * (`query_session_enforce_limit`).
318
318
  *
319
- * @returns the signed cookie value and the evicted sessions' token hashes
319
+ * @returns the raw session token and the evicted sessions' token hashes
320
320
  * @mutates `auth_session` table - inserts the new session row (and evicts older rows when `max_sessions` is set)
321
321
  */
322
322
  export const create_capped_session = async (options) => {
323
- const { keyring, deps, account_id, session_options, max_sessions } = options;
323
+ const { deps, account_id, max_sessions } = options;
324
324
  const session_token = generate_session_token();
325
325
  const token_hash = hash_session_token(session_token);
326
326
  await query_create_session(deps, token_hash, account_id);
327
327
  const evicted = max_sessions != null ? await query_session_enforce_limit(deps, account_id, max_sessions) : [];
328
- const cookie_value = await create_session_cookie_value(keyring, session_token, session_options);
329
- return { cookie_value, evicted };
328
+ return { token: session_token, evicted };
330
329
  };
@@ -1 +1 @@
1
- {"version":3,"file":"signup_routes.d.ts","sourceRoot":"","sources":["../../src/lib/auth/signup_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAcH,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAI7E,OAAO,EAAoB,KAAK,WAAW,EAA6B,MAAM,oBAAoB,CAAC;AACnG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAOlD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAGnE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAEhD;;;;;;;GAOG;AACH,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,uBAAuB;IAClE;;;;;;;;;OASG;IACH,sBAAsB,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3C,6FAA6F;IAC7F,2BAA2B,EAAE,WAAW,GAAG,IAAI,CAAC;IAChD;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAID;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,GACrC,MAAM,gBAAgB,EACtB,SAAS,kBAAkB,KACzB,KAAK,CAAC,SAAS,CA2QjB,CAAC"}
1
+ {"version":3,"file":"signup_routes.d.ts","sourceRoot":"","sources":["../../src/lib/auth/signup_routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAcH,OAAO,EAAwB,KAAK,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAI7E,OAAO,EAAoB,KAAK,WAAW,EAA6B,MAAM,oBAAoB,CAAC;AACnG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAOlD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAGnE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAEhD;;;;;;;GAOG;AACH,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,kBAAmB,SAAQ,uBAAuB;IAClE;;;;;;;;;OASG;IACH,sBAAsB,EAAE,WAAW,GAAG,IAAI,CAAC;IAC3C,6FAA6F;IAC7F,2BAA2B,EAAE,WAAW,GAAG,IAAI,CAAC;IAChD;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAID;;;;;;GAMG;AACH,eAAO,MAAM,yBAAyB,GACrC,MAAM,gBAAgB,EACtB,SAAS,kBAAkB,KACzB,KAAK,CAAC,SAAS,CA6QjB,CAAC"}
@@ -9,7 +9,7 @@
9
9
  */
10
10
  import { query_create_account_with_actor } from './account_queries.js';
11
11
  import { create_capped_session } from './session_queries.js';
12
- import { session_cookie_header } from './session_cookie.js';
12
+ import { sign_session_cookie } from './session_cookie.js';
13
13
  import { query_app_settings_load } from './app_settings_queries.js';
14
14
  import { query_invite_find_unclaimed_match_for_update, query_invite_claim_unscoped } from './invite_queries.js';
15
15
  import { create_signup_route_shape } from './signup_route_schema.js';
@@ -53,7 +53,7 @@ export const DEFAULT_SIGNUP_FAIL_JITTER_MS = 25;
53
53
  */
54
54
  export const create_signup_route_specs = (deps, options) => {
55
55
  const { keyring, password } = deps;
56
- const { session_options, signup_ip_rate_limiter, signup_account_rate_limiter, signup_fail_floor_ms = DEFAULT_SIGNUP_FAIL_FLOOR_MS, signup_fail_jitter_ms = DEFAULT_SIGNUP_FAIL_JITTER_MS } = options;
56
+ const { session_cookie_name, signup_ip_rate_limiter, signup_account_rate_limiter, signup_fail_floor_ms = DEFAULT_SIGNUP_FAIL_FLOOR_MS, signup_fail_jitter_ms = DEFAULT_SIGNUP_FAIL_JITTER_MS } = options;
57
57
  warn_if_fail_floor_disabled('signup', signup_fail_floor_ms, deps.log);
58
58
  return [
59
59
  attach_route_handler(create_signup_route_shape({
@@ -210,12 +210,10 @@ export const create_signup_route_specs = (deps, options) => {
210
210
  // the account back, and rides the success, answered only
211
211
  // once the commit has landed
212
212
  const session = await create_capped_session({
213
- keyring,
214
213
  deps: tx_ctx,
215
- account_id: account.id,
216
- session_options
214
+ account_id: account.id
217
215
  });
218
- const set_cookie = session_cookie_header(session.cookie_value, session_options);
216
+ const set_cookie = await sign_session_cookie(keyring, session.token, session_cookie_name);
219
217
  // the success row, last: a refused row rolls the account back
220
218
  // and answers through the `internal_error` catch below
221
219
  await deps.audit.emit(tx_ctx, {
package/dist/db/CLAUDE.md CHANGED
@@ -199,8 +199,9 @@ records who holds them. Optional — minimal consumers never migrate it.
199
199
  - **`fact_ddl.ts`** — `fact` (content-addressed bytes: embedded `bytes` xor
200
200
  `external_url`, CHECK enforces exactly one) + `fact_ref` (declared
201
201
  dependency edges; `target_hash` deliberately not an FK, for federation) +
202
- `memo` (`(fn_id, input_hash) → output_hash`) + `fact_holder` (`(actor_id,
203
- hash)` possession rows, both FKs cascading). `FACT_MIGRATION_NS`, namespace
202
+ `memo` (`(fn_id, input_hash) → output_hash`; the table ships, no store
203
+ reads or writes it yet) + `fact_holder` (`(actor_id, hash)` possession
204
+ rows, both FKs cascading). `FACT_MIGRATION_NS`, namespace
204
205
  `fuz_facts` — frozen and append-only (`full_fact_schema`, then
205
206
  `fact_holder`), each entry statement-identical with the Rust `fuz_fact`
206
207
  migration of the same name.
@@ -211,7 +212,8 @@ DO NOTHING`), `_put_fact_refs`, `_get_fact` / `_get_fact_meta` / `_has_fact`
211
212
  / `_select_for_delete` (a fact is orphan when no active `cell.refs` names it;
212
213
  the `older_than` cutoff keeps a fact whose `created_at` or any
213
214
  `fact_holder.created_at` is within the window, so a deduplicated re-upload
214
- survives any sweep whose window covers it).
215
+ survives any sweep whose window covers it). No action or sweep runs them
216
+ yet.
215
217
  - **`fact_holder_queries.ts`** — `FACT_HOLDER_COLUMNS`, `query_put_fact_holder`
216
218
  (idempotent upsert — a repeat put refreshes the row's `created_at` to the
217
219
  most recent put), and the admission reads `query_fact_holder_table_exists` /
@@ -283,7 +283,9 @@ export interface SeedDevAccountDeps extends QueryDeps {
283
283
  * Flips `bootstrap_lock` in the same transaction as its writes, as a real
284
284
  * bootstrap and `bootstrap_test_keeper` do: a database holding an account
285
285
  * never reads as open for bootstrap, so the lock stays the single signal
286
- * production trusts. Seed after bootstrapping, or seed the keeper itself.
286
+ * production trusts. Seed after bootstrapping, or seed the keeper itself — a
287
+ * keeper seeded while a server runs reaches its daemon-token leg after a
288
+ * restart, which resolves the keeper once at startup.
287
289
  *
288
290
  * Intended for a dev setup task — do not call in production.
289
291
  *