@oxy.so/contracts 1.5.0 → 2.0.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.
@@ -1,215 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.hubAuthorizeResultSchema = exports.hubAuthorizeRequestSchema = exports.hubActivateRequestSchema = exports.hubClaimRequestSchema = exports.hubSessionSchema = exports.browserHubRevokeResponseSchema = exports.browserHubErrorSchema = exports.browserHubResolveResponseSchema = exports.browserHubHandleResponseSchema = exports.browserHubHandleRequestSchema = exports.browserHubHandleSchema = exports.BROWSER_HUB_HANDLE_TTL_MS = exports.BROWSER_HUB_COOKIE_ATTRIBUTES = exports.BROWSER_HUB_COOKIE_NAME = void 0;
4
- const zod_1 = require("zod");
5
- const deviceDirectory_1 = require("./deviceDirectory");
6
- /**
7
- * The browser DeviceSession hub at `auth.oxy.so` (issue #937, Phase 5, ADR 0003).
8
- *
9
- * Two wire surfaces live in this file and they are deliberately different
10
- * shapes, because they answer to different callers:
11
- *
12
- * - The `browserHub*` schemas below the first divider are the API's
13
- * (`api.oxy.so/session/browser-hub/*`), spoken ONLY by the IdP's own
14
- * server/edge layer. They carry the raw handle and a bearer, so nothing that
15
- * speaks them may run in a browser.
16
- * - The `hub*` schemas below the second divider are the EDGE's
17
- * (`auth.oxy.so/hub/*`), spoken by the IdP SPA. They carry neither: the
18
- * handle stays in an `HttpOnly` cookie the script cannot read, and the
19
- * device-wide bearer stays at the edge.
20
- *
21
- * That split is the whole point of the phase. A single schema covering both
22
- * would let a refactor move a credential across the boundary without any type
23
- * changing shape.
24
- *
25
- * ## What is NOT reopened here
26
- *
27
- * Relying-party origins remain zero-cookie: they keep `{deviceId,
28
- * deviceSecret}` + `POST /session/device/token` and set no cookie of any kind.
29
- * `auth.oxy.so` alone holds a handle, first-party only. There is no
30
- * refresh-token family and no bootstrap hop.
31
- */
32
- /* -------------------------------------------------------------------------- */
33
- /* The cookie */
34
- /* -------------------------------------------------------------------------- */
35
- /**
36
- * The one cookie name, `__Host-` prefixed.
37
- *
38
- * The prefix is not decoration: a browser refuses to store a `__Host-` cookie
39
- * that carries a `Domain` attribute or a `Path` other than `/`, or that arrives
40
- * without `Secure`. So the name itself is what makes "bound to `auth.oxy.so`
41
- * alone, readable by no other `oxy.so` host" enforced by the client rather than
42
- * merely intended by the server — including against a compromised sibling
43
- * subdomain, which is the specific attack `Domain=.oxy.so` would have opened.
44
- */
45
- exports.BROWSER_HUB_COOKIE_NAME = '__Host-oxy-device';
46
- /**
47
- * The exact attribute set the edge sets, in the order it writes them.
48
- *
49
- * Held as data rather than as a template string so a test can assert the set
50
- * rather than a rendered line, and so removing one attribute is a diff to a
51
- * named constant instead of an edit inside a string literal.
52
- *
53
- * `Max-Age` is deliberately NOT in this list — see
54
- * {@link BROWSER_HUB_HANDLE_TTL_MS}, which the edge appends. Everything here is
55
- * a SECURITY attribute and none of them is ever conditional.
56
- */
57
- exports.BROWSER_HUB_COOKIE_ATTRIBUTES = ['Secure', 'HttpOnly', 'SameSite=Lax', 'Path=/'];
58
- /**
59
- * How long a hub handle lives, server-side and in the cookie alike.
60
- *
61
- * Thirty days. The cookie's `Max-Age` is derived from this same constant so the
62
- * two cannot disagree: a cookie outliving its credential produces a browser that
63
- * believes it is signed in and is refused on every call, and a credential
64
- * outliving its cookie leaves an un-addressable row alive on the server.
65
- *
66
- * A hub handle is NOT a session cookie (one with no `Max-Age`, discarded when
67
- * the browser closes). It cannot be: the thing it identifies is the browser
68
- * PROFILE's device session, and a device session that evaporates when the user
69
- * quits their browser would send them back to a QR scan every morning — the
70
- * exact failure ADR 0003 exists to remove.
71
- */
72
- exports.BROWSER_HUB_HANDLE_TTL_MS = 30 * 24 * 60 * 60 * 1000;
73
- /* -------------------------------------------------------------------------- */
74
- /* api.oxy.so/session/browser-hub/* — spoken by the edge, never a browser */
75
- /* -------------------------------------------------------------------------- */
76
- /**
77
- * The raw handle, as it travels between the edge and the API.
78
- *
79
- * An opaque base64url random value and NOTHING else — no token, no user id, no
80
- * device id, no account id, no serialized state. The server stores only
81
- * `sha256(handle)`, so a dump of the column cannot address a browser.
82
- *
83
- * The minimum length is a floor against an empty or truncated value reaching a
84
- * hash comparison, not a statement about the entropy: that is fixed by the
85
- * issuer (`BROWSER_HUB_HANDLE_BYTES` in the API), and a handle is the only
86
- * credential in this flow, so it is 256 bits.
87
- */
88
- exports.browserHubHandleSchema = zod_1.z.string().min(32);
89
- /** Request body of every handle-presenting API endpoint. */
90
- exports.browserHubHandleRequestSchema = zod_1.z.object({
91
- handle: exports.browserHubHandleSchema,
92
- });
93
- /**
94
- * Response of `POST /session/browser-hub/establish` and `.../rotate`.
95
- *
96
- * The raw handle is returned exactly ONCE, to the edge, which puts it straight
97
- * into the cookie and keeps no copy. It is never logged, never re-readable, and
98
- * never reaches the browser's script context.
99
- */
100
- exports.browserHubHandleResponseSchema = zod_1.z.object({
101
- handle: exports.browserHubHandleSchema,
102
- expiresAt: zod_1.z.string(),
103
- });
104
- /**
105
- * Response of `POST /session/browser-hub/resolve` — the browser's device
106
- * session, resolved from the handle alone.
107
- *
108
- * Carries a bearer because the edge needs one to run the authorize lane on the
109
- * browser's behalf. It is the ordinary short-lived access token of the device's
110
- * active context, and it stops at the edge.
111
- */
112
- exports.browserHubResolveResponseSchema = zod_1.z.object({
113
- accessToken: zod_1.z.string().min(1),
114
- expiresAt: zod_1.z.string(),
115
- directory: deviceDirectory_1.deviceDirectorySchema,
116
- });
117
- /**
118
- * Why a handle did not resolve. A CLOSED set, and deliberately coarse.
119
- *
120
- * - `invalid_handle` — unknown, expired, or revoked. One code for all
121
- * three: distinguishing them would tell a caller
122
- * holding a guessed value whether it ever existed.
123
- * - `no_active_session` — the handle is good and the device has nothing live
124
- * to mint for. The credential is NOT revoked; the
125
- * browser re-authenticates and keeps its cookie.
126
- */
127
- exports.browserHubErrorSchema = zod_1.z.enum(['invalid_handle', 'no_active_session']);
128
- /** Response of `POST /session/browser-hub/revoke`. Idempotent by construction. */
129
- exports.browserHubRevokeResponseSchema = zod_1.z.object({
130
- revoked: zod_1.z.boolean(),
131
- });
132
- /* -------------------------------------------------------------------------- */
133
- /* auth.oxy.so/hub/* — spoken by the IdP SPA */
134
- /* -------------------------------------------------------------------------- */
135
- /**
136
- * What the SPA is allowed to know about the hub session.
137
- *
138
- * `signed_out` covers "no cookie", "cookie present but the handle no longer
139
- * resolves" and "resolved, but the device has nothing live" — from the script's
140
- * side those are one state, and collapsing them here is what stops a UI from
141
- * branching on a distinction it must not act on.
142
- *
143
- * `active` carries the DIRECTORY and no credential. A switcher renders from it;
144
- * nothing in it can be spent against the API. The bearer that produced it never
145
- * left the edge.
146
- */
147
- exports.hubSessionSchema = zod_1.z.discriminatedUnion('status', [
148
- zod_1.z.object({ status: zod_1.z.literal('signed_out') }),
149
- zod_1.z.object({ status: zod_1.z.literal('active'), directory: deviceDirectory_1.deviceDirectorySchema }),
150
- ]);
151
- /** Request body of `POST /hub/claim` — the Commons approval lane's handoff. */
152
- exports.hubClaimRequestSchema = zod_1.z.object({
153
- /**
154
- * The secret `sessionToken` of an approved `AuthSession`, held only by the
155
- * page that created it. The edge spends it server-side: the access token and
156
- * device secret the claim yields are consumed to establish the hub and are
157
- * then discarded, so neither is ever returned to the script.
158
- */
159
- sessionToken: zod_1.z.string().min(1),
160
- });
161
- /** Request body of `POST /hub/activate` — pick the globally active context. */
162
- exports.hubActivateRequestSchema = zod_1.z.object({
163
- contextId: zod_1.z.string().min(1),
164
- });
165
- /**
166
- * Request body of `POST /hub/authorize` — a later official origin joining.
167
- *
168
- * There is no `prompt` field, and that is not an omission. `'none'` is absent
169
- * from `buildOAuthAuthorizeUrl`'s union in `@oxy.so/core` precisely so a silent
170
- * loop cannot be rebuilt in one line, and this endpoint would be the second
171
- * place to rebuild it. A caller that needs a login or consent prompt gets one
172
- * by not passing `approve`.
173
- */
174
- exports.hubAuthorizeRequestSchema = zod_1.z.object({
175
- clientId: zod_1.z.string().min(1),
176
- redirectUri: zod_1.z.string().url(),
177
- state: zod_1.z.string().optional(),
178
- codeChallenge: zod_1.z.string().min(1),
179
- /** S256 only. `plain` is refused before the request leaves the edge. */
180
- codeChallengeMethod: zod_1.z.literal('S256'),
181
- scope: zod_1.z.string().optional(),
182
- /**
183
- * The user's explicit answer on the consent screen.
184
- *
185
- * Absent or `false` means "tell me whether consent is needed"; the edge then
186
- * returns `consent_required` and mints nothing. Only `true` may mint, and only
187
- * the consent screen's own button sends it — which is why the decision of
188
- * WHETHER consent is required is re-read from the server on both passes rather
189
- * than remembered from the first.
190
- */
191
- approve: zod_1.z.boolean().optional(),
192
- });
193
- /**
194
- * Result of `POST /hub/authorize`.
195
- *
196
- * `signed_out` is the honest answer for a browser with no hub session: the SPA
197
- * runs the ordinary Commons-first authentication and tries again. It is never a
198
- * redirect the edge performs on the browser's behalf — no automatic chain
199
- * across Oxy origins, and nothing here can be hidden inside an iframe.
200
- */
201
- exports.hubAuthorizeResultSchema = zod_1.z.discriminatedUnion('status', [
202
- zod_1.z.object({ status: zod_1.z.literal('signed_out') }),
203
- zod_1.z.object({
204
- status: zod_1.z.literal('consent_required'),
205
- reason: zod_1.z.enum(['new', 'scope_changed']),
206
- userConsentScopes: zod_1.z.array(zod_1.z.string()).optional(),
207
- }),
208
- zod_1.z.object({
209
- status: zod_1.z.literal('code'),
210
- code: zod_1.z.string().min(1),
211
- state: zod_1.z.string().nullable(),
212
- redirectUri: zod_1.z.string(),
213
- expiresIn: zod_1.z.number().int().positive(),
214
- }),
215
- ]);
@@ -1,212 +0,0 @@
1
- import { z } from 'zod';
2
- import { deviceDirectorySchema } from './deviceDirectory.js';
3
- /**
4
- * The browser DeviceSession hub at `auth.oxy.so` (issue #937, Phase 5, ADR 0003).
5
- *
6
- * Two wire surfaces live in this file and they are deliberately different
7
- * shapes, because they answer to different callers:
8
- *
9
- * - The `browserHub*` schemas below the first divider are the API's
10
- * (`api.oxy.so/session/browser-hub/*`), spoken ONLY by the IdP's own
11
- * server/edge layer. They carry the raw handle and a bearer, so nothing that
12
- * speaks them may run in a browser.
13
- * - The `hub*` schemas below the second divider are the EDGE's
14
- * (`auth.oxy.so/hub/*`), spoken by the IdP SPA. They carry neither: the
15
- * handle stays in an `HttpOnly` cookie the script cannot read, and the
16
- * device-wide bearer stays at the edge.
17
- *
18
- * That split is the whole point of the phase. A single schema covering both
19
- * would let a refactor move a credential across the boundary without any type
20
- * changing shape.
21
- *
22
- * ## What is NOT reopened here
23
- *
24
- * Relying-party origins remain zero-cookie: they keep `{deviceId,
25
- * deviceSecret}` + `POST /session/device/token` and set no cookie of any kind.
26
- * `auth.oxy.so` alone holds a handle, first-party only. There is no
27
- * refresh-token family and no bootstrap hop.
28
- */
29
- /* -------------------------------------------------------------------------- */
30
- /* The cookie */
31
- /* -------------------------------------------------------------------------- */
32
- /**
33
- * The one cookie name, `__Host-` prefixed.
34
- *
35
- * The prefix is not decoration: a browser refuses to store a `__Host-` cookie
36
- * that carries a `Domain` attribute or a `Path` other than `/`, or that arrives
37
- * without `Secure`. So the name itself is what makes "bound to `auth.oxy.so`
38
- * alone, readable by no other `oxy.so` host" enforced by the client rather than
39
- * merely intended by the server — including against a compromised sibling
40
- * subdomain, which is the specific attack `Domain=.oxy.so` would have opened.
41
- */
42
- export const BROWSER_HUB_COOKIE_NAME = '__Host-oxy-device';
43
- /**
44
- * The exact attribute set the edge sets, in the order it writes them.
45
- *
46
- * Held as data rather than as a template string so a test can assert the set
47
- * rather than a rendered line, and so removing one attribute is a diff to a
48
- * named constant instead of an edit inside a string literal.
49
- *
50
- * `Max-Age` is deliberately NOT in this list — see
51
- * {@link BROWSER_HUB_HANDLE_TTL_MS}, which the edge appends. Everything here is
52
- * a SECURITY attribute and none of them is ever conditional.
53
- */
54
- export const BROWSER_HUB_COOKIE_ATTRIBUTES = ['Secure', 'HttpOnly', 'SameSite=Lax', 'Path=/'];
55
- /**
56
- * How long a hub handle lives, server-side and in the cookie alike.
57
- *
58
- * Thirty days. The cookie's `Max-Age` is derived from this same constant so the
59
- * two cannot disagree: a cookie outliving its credential produces a browser that
60
- * believes it is signed in and is refused on every call, and a credential
61
- * outliving its cookie leaves an un-addressable row alive on the server.
62
- *
63
- * A hub handle is NOT a session cookie (one with no `Max-Age`, discarded when
64
- * the browser closes). It cannot be: the thing it identifies is the browser
65
- * PROFILE's device session, and a device session that evaporates when the user
66
- * quits their browser would send them back to a QR scan every morning — the
67
- * exact failure ADR 0003 exists to remove.
68
- */
69
- export const BROWSER_HUB_HANDLE_TTL_MS = 30 * 24 * 60 * 60 * 1000;
70
- /* -------------------------------------------------------------------------- */
71
- /* api.oxy.so/session/browser-hub/* — spoken by the edge, never a browser */
72
- /* -------------------------------------------------------------------------- */
73
- /**
74
- * The raw handle, as it travels between the edge and the API.
75
- *
76
- * An opaque base64url random value and NOTHING else — no token, no user id, no
77
- * device id, no account id, no serialized state. The server stores only
78
- * `sha256(handle)`, so a dump of the column cannot address a browser.
79
- *
80
- * The minimum length is a floor against an empty or truncated value reaching a
81
- * hash comparison, not a statement about the entropy: that is fixed by the
82
- * issuer (`BROWSER_HUB_HANDLE_BYTES` in the API), and a handle is the only
83
- * credential in this flow, so it is 256 bits.
84
- */
85
- export const browserHubHandleSchema = z.string().min(32);
86
- /** Request body of every handle-presenting API endpoint. */
87
- export const browserHubHandleRequestSchema = z.object({
88
- handle: browserHubHandleSchema,
89
- });
90
- /**
91
- * Response of `POST /session/browser-hub/establish` and `.../rotate`.
92
- *
93
- * The raw handle is returned exactly ONCE, to the edge, which puts it straight
94
- * into the cookie and keeps no copy. It is never logged, never re-readable, and
95
- * never reaches the browser's script context.
96
- */
97
- export const browserHubHandleResponseSchema = z.object({
98
- handle: browserHubHandleSchema,
99
- expiresAt: z.string(),
100
- });
101
- /**
102
- * Response of `POST /session/browser-hub/resolve` — the browser's device
103
- * session, resolved from the handle alone.
104
- *
105
- * Carries a bearer because the edge needs one to run the authorize lane on the
106
- * browser's behalf. It is the ordinary short-lived access token of the device's
107
- * active context, and it stops at the edge.
108
- */
109
- export const browserHubResolveResponseSchema = z.object({
110
- accessToken: z.string().min(1),
111
- expiresAt: z.string(),
112
- directory: deviceDirectorySchema,
113
- });
114
- /**
115
- * Why a handle did not resolve. A CLOSED set, and deliberately coarse.
116
- *
117
- * - `invalid_handle` — unknown, expired, or revoked. One code for all
118
- * three: distinguishing them would tell a caller
119
- * holding a guessed value whether it ever existed.
120
- * - `no_active_session` — the handle is good and the device has nothing live
121
- * to mint for. The credential is NOT revoked; the
122
- * browser re-authenticates and keeps its cookie.
123
- */
124
- export const browserHubErrorSchema = z.enum(['invalid_handle', 'no_active_session']);
125
- /** Response of `POST /session/browser-hub/revoke`. Idempotent by construction. */
126
- export const browserHubRevokeResponseSchema = z.object({
127
- revoked: z.boolean(),
128
- });
129
- /* -------------------------------------------------------------------------- */
130
- /* auth.oxy.so/hub/* — spoken by the IdP SPA */
131
- /* -------------------------------------------------------------------------- */
132
- /**
133
- * What the SPA is allowed to know about the hub session.
134
- *
135
- * `signed_out` covers "no cookie", "cookie present but the handle no longer
136
- * resolves" and "resolved, but the device has nothing live" — from the script's
137
- * side those are one state, and collapsing them here is what stops a UI from
138
- * branching on a distinction it must not act on.
139
- *
140
- * `active` carries the DIRECTORY and no credential. A switcher renders from it;
141
- * nothing in it can be spent against the API. The bearer that produced it never
142
- * left the edge.
143
- */
144
- export const hubSessionSchema = z.discriminatedUnion('status', [
145
- z.object({ status: z.literal('signed_out') }),
146
- z.object({ status: z.literal('active'), directory: deviceDirectorySchema }),
147
- ]);
148
- /** Request body of `POST /hub/claim` — the Commons approval lane's handoff. */
149
- export const hubClaimRequestSchema = z.object({
150
- /**
151
- * The secret `sessionToken` of an approved `AuthSession`, held only by the
152
- * page that created it. The edge spends it server-side: the access token and
153
- * device secret the claim yields are consumed to establish the hub and are
154
- * then discarded, so neither is ever returned to the script.
155
- */
156
- sessionToken: z.string().min(1),
157
- });
158
- /** Request body of `POST /hub/activate` — pick the globally active context. */
159
- export const hubActivateRequestSchema = z.object({
160
- contextId: z.string().min(1),
161
- });
162
- /**
163
- * Request body of `POST /hub/authorize` — a later official origin joining.
164
- *
165
- * There is no `prompt` field, and that is not an omission. `'none'` is absent
166
- * from `buildOAuthAuthorizeUrl`'s union in `@oxy.so/core` precisely so a silent
167
- * loop cannot be rebuilt in one line, and this endpoint would be the second
168
- * place to rebuild it. A caller that needs a login or consent prompt gets one
169
- * by not passing `approve`.
170
- */
171
- export const hubAuthorizeRequestSchema = z.object({
172
- clientId: z.string().min(1),
173
- redirectUri: z.string().url(),
174
- state: z.string().optional(),
175
- codeChallenge: z.string().min(1),
176
- /** S256 only. `plain` is refused before the request leaves the edge. */
177
- codeChallengeMethod: z.literal('S256'),
178
- scope: z.string().optional(),
179
- /**
180
- * The user's explicit answer on the consent screen.
181
- *
182
- * Absent or `false` means "tell me whether consent is needed"; the edge then
183
- * returns `consent_required` and mints nothing. Only `true` may mint, and only
184
- * the consent screen's own button sends it — which is why the decision of
185
- * WHETHER consent is required is re-read from the server on both passes rather
186
- * than remembered from the first.
187
- */
188
- approve: z.boolean().optional(),
189
- });
190
- /**
191
- * Result of `POST /hub/authorize`.
192
- *
193
- * `signed_out` is the honest answer for a browser with no hub session: the SPA
194
- * runs the ordinary Commons-first authentication and tries again. It is never a
195
- * redirect the edge performs on the browser's behalf — no automatic chain
196
- * across Oxy origins, and nothing here can be hidden inside an iframe.
197
- */
198
- export const hubAuthorizeResultSchema = z.discriminatedUnion('status', [
199
- z.object({ status: z.literal('signed_out') }),
200
- z.object({
201
- status: z.literal('consent_required'),
202
- reason: z.enum(['new', 'scope_changed']),
203
- userConsentScopes: z.array(z.string()).optional(),
204
- }),
205
- z.object({
206
- status: z.literal('code'),
207
- code: z.string().min(1),
208
- state: z.string().nullable(),
209
- redirectUri: z.string(),
210
- expiresIn: z.number().int().positive(),
211
- }),
212
- ]);