@oxyhq/contracts 0.11.0 → 0.13.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,28 +1,16 @@
1
1
  "use strict";
2
2
  /**
3
- * Device-first bootstrap & token contracts (auth centralization, wave 1).
3
+ * First-party login result contract.
4
4
  *
5
- * SINGLE SOURCE OF TRUTH for the wire shape of the new device-first session
6
- * bootstrap: the top-level `#oxy_boot=…` fragment the API hands back from
7
- * `GET /auth/device/bootstrap`, the token bundle a boot code / web-session
8
- * fast-path exchanges into, the persisted-refresh rotation, the native
9
- * device-token issuance, the IdP chooser's device-resolve, and the first-party
10
- * password login result (2FA arm vs. session arm). The API validates its OUTPUT
11
- * against these schemas; every consumer (`@oxyhq/core`'s device-boot mixin, the
12
- * SDK cold boot, the IdP chooser) validates its INPUT against the same
13
- * definitions, so producer and consumers cannot drift.
5
+ * SINGLE SOURCE OF TRUTH for the first-party password login result (2FA arm vs.
6
+ * session arm). The API validates its OUTPUT against this schema; every consumer
7
+ * (`@oxyhq/core`'s auth mixin) validates its INPUT against the same definition,
8
+ * so producer and consumers cannot drift.
14
9
  *
15
- * Design anchors (from the auth-centralization plan):
16
- * - The bootstrap fragment carries NO tokens and NO deviceId — only a
17
- * `state` echo (CSRF), a `reason`, a short-lived single-use `code`, and an
18
- * opaque `deviceToken`. Tokens are obtained by exchanging the `code` at
19
- * `POST /auth/device/exchange` (origin-bound GETDEL burn).
20
- * - Refresh is ONE rotating, single-use family shared by web and native.
21
- * - `loginResult` mirrors what `POST /auth/login` returns today
22
- * (`buildSessionAuthResponse` in the API's `session.controller.ts`): either a
23
- * 2FA challenge (`{ twoFactorRequired: true, loginToken }`) or a session
24
- * payload. The session arm matches `SessionAuthResponse` EXACTLY, plus an
25
- * optional `refreshToken` the new server adds for the persisted-refresh lane.
10
+ * The device transport is `deviceId` + `deviceSecret` + `POST /session/device/token`
11
+ * (see `deviceSession.ts`). The legacy cookie/bootstrap/refresh-family lanes were
12
+ * removed in the zero-cookie cutover — nothing here carries a refresh token or a
13
+ * boot fragment.
26
14
  *
27
15
  * Nested-object response shapes are declared as explicit `interface`s with the
28
16
  * runtime schema annotated `z.ZodType<Interface>` — the same rationale as
@@ -35,129 +23,27 @@
35
23
  * `require()`).
36
24
  */
37
25
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.deviceResolveResponseSchema = exports.deviceResolveRequestSchema = exports.loginResultSchema = exports.deviceTokenIssueResponseSchema = exports.tokenRefreshResponseSchema = exports.tokenRefreshRequestSchema = exports.webSessionResultSchema = exports.authTokenBundleSchema = exports.deviceExchangeRequestSchema = exports.deviceBootFragmentSchema = exports.deviceBootReasonSchema = void 0;
26
+ exports.loginResultSchema = void 0;
39
27
  const zod_1 = require("zod");
40
- const userResponse_1 = require("./userResponse");
41
- /* -------------------------------------------------------------------------- */
42
- /* Bootstrap fragment */
43
- /* -------------------------------------------------------------------------- */
44
- /**
45
- * Why the bootstrap hop resolved the way it did.
46
- * - `session` — the device cookie resolved an active session; a `code` is
47
- * present to exchange for tokens.
48
- * - `no_session` — the device is known but has no active session; no `code`.
49
- * - `new_device` — first contact; the cookie was just planted, no session yet.
50
- */
51
- exports.deviceBootReasonSchema = zod_1.z.enum(['session', 'no_session', 'new_device']);
52
- /**
53
- * The `#oxy_boot=<json>` fragment `GET /auth/device/bootstrap` appends to the
54
- * `return_to` URL. Carries the CSRF `state` echo, the resolution `reason`, the
55
- * opaque `deviceToken`, and — ONLY on the `session` arm — the single-use
56
- * exchange `code`. NEVER carries tokens or a deviceId.
57
- *
58
- * Discriminated on `reason` so the code↔reason coupling is enforced by the
59
- * schema, not by the consumer: the `session` arm REQUIRES `code`, and the
60
- * `no_session` / `new_device` arms omit it (a stray `code` on those arms is
61
- * stripped). A `session` fragment WITHOUT a code therefore fails to parse and
62
- * is treated as "no usable fragment" rather than half-processed.
63
- */
64
- const deviceBootFragmentBase = {
65
- v: zod_1.z.literal(1),
66
- state: zod_1.z.string().min(1).max(256),
67
- deviceToken: zod_1.z.string().min(20).max(512),
68
- };
69
- exports.deviceBootFragmentSchema = zod_1.z.discriminatedUnion('reason', [
70
- zod_1.z.object({
71
- ...deviceBootFragmentBase,
72
- reason: zod_1.z.literal('session'),
73
- code: zod_1.z.string().min(20).max(128),
74
- }),
75
- zod_1.z.object({
76
- ...deviceBootFragmentBase,
77
- reason: zod_1.z.literal('no_session'),
78
- }),
79
- zod_1.z.object({
80
- ...deviceBootFragmentBase,
81
- reason: zod_1.z.literal('new_device'),
82
- }),
83
- ]);
84
- /* -------------------------------------------------------------------------- */
85
- /* Boot-code exchange */
86
- /* -------------------------------------------------------------------------- */
87
- /** Request body for `POST /auth/device/exchange` — the single-use boot code. */
88
- exports.deviceExchangeRequestSchema = zod_1.z.object({
89
- code: zod_1.z.string().min(20).max(128),
90
- });
91
- exports.authTokenBundleSchema = zod_1.z.object({
92
- sessionId: zod_1.z.string(),
93
- accessToken: zod_1.z.string(),
94
- refreshToken: zod_1.z.string(),
95
- expiresAt: zod_1.z.string(),
96
- user: userResponse_1.userResponseSchema,
97
- });
98
- // Internal (unexported) arm schemas — PLAIN `z.object` literals (no
99
- // `z.ZodType<>` annotation) so `z.discriminatedUnion` can introspect the
100
- // `reason` discriminator. The node10 `.d.ts`-degradation safety comes from the
101
- // EXPORTED symbols instead: the public types are explicit interfaces
102
- // (`WebSessionSession` / `WebSessionNoSession` / `WebSessionResult`) and the
103
- // exported schema is annotated `z.ZodType<WebSessionResult>` below, so the
104
- // emitted declaration states the shape literally rather than a degradable
105
- // `z.infer<>` of the nested `session` object.
106
- const webSessionSessionSchema = zod_1.z.object({
107
- reason: zod_1.z.literal('session'),
108
- session: exports.authTokenBundleSchema,
109
- deviceToken: zod_1.z.string().min(1),
110
- });
111
- const webSessionNoSessionSchema = zod_1.z.object({
112
- reason: zod_1.z.enum(['no_session', 'new_device']),
113
- deviceToken: zod_1.z.string().min(1),
114
- });
115
- // Discriminated on `reason` — a true `discriminatedUnion` (not `z.union`): it
116
- // dispatches on the discriminator instead of sequentially probing each arm,
117
- // giving precise per-arm errors.
118
- exports.webSessionResultSchema = zod_1.z.discriminatedUnion('reason', [
119
- webSessionSessionSchema,
120
- webSessionNoSessionSchema,
121
- ]);
122
- /* -------------------------------------------------------------------------- */
123
- /* Refresh-token rotation (web + native, one implementation) */
124
- /* -------------------------------------------------------------------------- */
125
- /** Request body for `POST /auth/refresh-token` — the current refresh token. */
126
- exports.tokenRefreshRequestSchema = zod_1.z.object({
127
- refreshToken: zod_1.z.string().min(20),
128
- });
129
- /**
130
- * Wire shape of `POST /auth/refresh-token`: the rotated (single-use) family —
131
- * a new access token, the next refresh token, the new access-token expiry, and
132
- * the owning session id. `expiresAt` is an ISO string.
133
- */
134
- exports.tokenRefreshResponseSchema = zod_1.z.object({
135
- accessToken: zod_1.z.string(),
136
- refreshToken: zod_1.z.string(),
137
- expiresAt: zod_1.z.string(),
138
- sessionId: zod_1.z.string(),
139
- });
140
- /* -------------------------------------------------------------------------- */
141
- /* Native device-token issuance */
142
- /* -------------------------------------------------------------------------- */
143
- /**
144
- * Wire shape of `POST /auth/device/token` — issues (or rotates) the opaque
145
- * device token for the native channel. The deviceId is taken from the bearer
146
- * JWT claims server-side; only the token comes back.
147
- */
148
- exports.deviceTokenIssueResponseSchema = zod_1.z.object({
149
- deviceToken: zod_1.z.string(),
150
- });
151
28
  const loginTwoFactorRequiredSchema = zod_1.z.object({
152
29
  twoFactorRequired: zod_1.z.literal(true),
153
30
  loginToken: zod_1.z.string(),
154
31
  });
32
+ const securityAlertSchema = zod_1.z.object({
33
+ message: zod_1.z.string(),
34
+ anomalies: zod_1.z.array(zod_1.z.object({
35
+ type: zod_1.z.string(),
36
+ reason: zod_1.z.string(),
37
+ details: zod_1.z.string().optional(),
38
+ })),
39
+ });
155
40
  const loginSessionResultSchema = zod_1.z.object({
156
41
  sessionId: zod_1.z.string(),
157
42
  deviceId: zod_1.z.string(),
158
43
  expiresAt: zod_1.z.string(),
159
44
  accessToken: zod_1.z.string().optional(),
160
- refreshToken: zod_1.z.string().optional(),
45
+ deviceSecret: zod_1.z.string().optional(),
46
+ securityAlert: securityAlertSchema.optional(),
161
47
  user: zod_1.z.object({
162
48
  id: zod_1.z.string(),
163
49
  username: zod_1.z.string().optional(),
@@ -168,24 +54,3 @@ exports.loginResultSchema = zod_1.z.union([
168
54
  loginTwoFactorRequiredSchema,
169
55
  loginSessionResultSchema,
170
56
  ]);
171
- /* -------------------------------------------------------------------------- */
172
- /* IdP chooser device-resolve */
173
- /* -------------------------------------------------------------------------- */
174
- /**
175
- * Request body for `POST /auth/device/resolve` (X-Oxy-Internal, called by the
176
- * IdP chooser) — the device key the chooser read from the first-party
177
- * `oxy_device` cookie.
178
- */
179
- exports.deviceResolveRequestSchema = zod_1.z.object({
180
- deviceKey: zod_1.z.string().min(20),
181
- });
182
- const deviceResolveAccountSchema = zod_1.z.object({
183
- user: userResponse_1.userResponseSchema,
184
- sessionId: zod_1.z.string(),
185
- accessToken: zod_1.z.string(),
186
- expiresAt: zod_1.z.string(),
187
- });
188
- exports.deviceResolveResponseSchema = zod_1.z.object({
189
- activeAccountId: zod_1.z.string().nullable(),
190
- accounts: zod_1.z.array(deviceResolveAccountSchema),
191
- });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deviceSessionSyncSchema = exports.activeTokenSchema = exports.deviceSessionStateSchema = exports.sessionAccountSchema = void 0;
3
+ exports.deviceTokenMintResponseSchema = exports.deviceTokenMintRequestSchema = exports.deviceSessionSyncSchema = exports.activeTokenSchema = exports.deviceSessionStateSchema = exports.sessionAccountSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  exports.sessionAccountSchema = zod_1.z.object({
6
6
  accountId: zod_1.z.string(),
@@ -23,3 +23,30 @@ exports.deviceSessionSyncSchema = zod_1.z.object({
23
23
  state: exports.deviceSessionStateSchema,
24
24
  activeToken: exports.activeTokenSchema.nullable(),
25
25
  });
26
+ /* -------------------------------------------------------------------------- */
27
+ /* Device-secret token mint (phase 2c — zero-cookie transport) */
28
+ /* -------------------------------------------------------------------------- */
29
+ /**
30
+ * Request body for `POST /session/device/token` — the client presents the
31
+ * `deviceId` it stored first-party plus the opaque `deviceSecret`. NO bearer:
32
+ * possession of the secret IS the proof of device ownership. The server matches
33
+ * `sha256(deviceSecret)` against the device's stored `secretHash` (constant-time)
34
+ * and mints a short access token for the device's active account.
35
+ */
36
+ exports.deviceTokenMintRequestSchema = zod_1.z.object({
37
+ deviceId: zod_1.z.string().min(1),
38
+ deviceSecret: zod_1.z.string().min(1),
39
+ });
40
+ /**
41
+ * Wire shape of a successful `POST /session/device/token`: the freshly-minted
42
+ * short access token for the active account, its expiry, the NEXT rotating
43
+ * device secret the client must persist (rotation-in-use — the presented secret
44
+ * stays valid for a short grace so multi-tab races don't lock out), and the
45
+ * projected device-session state.
46
+ */
47
+ exports.deviceTokenMintResponseSchema = zod_1.z.object({
48
+ accessToken: zod_1.z.string(),
49
+ expiresAt: zod_1.z.string(),
50
+ nextDeviceSecret: zod_1.z.string(),
51
+ state: exports.deviceSessionStateSchema,
52
+ });
package/dist/cjs/index.js CHANGED
@@ -12,7 +12,7 @@
12
12
  */
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.personhoodBreakdownSchema = exports.personhoodVouchRecordSchema = exports.validationVoteResultSchema = exports.validationRequestSummarySchema = exports.validationOpenResultSchema = exports.validationOpenRequestSchema = exports.validationVerdictRecordSchema = exports.realLifeAttestationResultSchema = exports.realLifeAttestationRecordSchema = exports.signedPublicCardSchema = exports.publicCardSchema = exports.logPageResponseSchema = exports.chainHeadResponseSchema = exports.oxySignedRecordTypeSchema = exports.exportBundleSchema = exports.exportAttestationSchema = exports.authMethodsResponseSchema = exports.authMethodEntrySchema = exports.domainVerificationInstructionsSchema = exports.domainVerificationRequestSchema = exports.verifiedDomainSchema = exports.signedRecordEnvelopeSchema = exports.didDocumentSchema = exports.didServiceSchema = exports.verificationMethodSchema = exports.appAffinityEventsIngestSchema = exports.appAffinityEventSchema = exports.appAffinityEventTypeSchema = exports.appUserSignalIngestSchema = exports.appInterestInputSchema = exports.appEndorsementInputSchema = exports.recommendationResponseSchema = exports.recommendationItemSchema = exports.recommendationCountSchema = exports.recommendationRequestSchema = exports.recommendationSignalWeightsSchema = exports.recommendationBoostSchema = exports.recommendationExcludeTypeSchema = exports.fedcmTokenPayloadSchema = exports.sessionStatusSchema = exports.publicApplicationSchema = exports.applicationTypeSchema = exports.safeParseContract = exports.resolveUserId = exports.deviceLinkedSessionsResponseSchema = exports.deviceLinkedSessionSchema = exports.currentUserResponseSchema = exports.userProfileUpdateSchema = exports.userResponseSchema = exports.userNameSchema = void 0;
15
- exports.deviceResolveResponseSchema = exports.deviceResolveRequestSchema = exports.loginResultSchema = exports.deviceTokenIssueResponseSchema = exports.tokenRefreshResponseSchema = exports.tokenRefreshRequestSchema = exports.webSessionResultSchema = exports.authTokenBundleSchema = exports.deviceExchangeRequestSchema = exports.deviceBootFragmentSchema = exports.deviceBootReasonSchema = exports.deviceSessionSyncSchema = exports.activeTokenSchema = exports.deviceSessionStateSchema = exports.sessionAccountSchema = exports.linkPreviewResponseSchema = exports.linkPreviewBatchResponseSchema = exports.linkPreviewBatchRequestSchema = exports.linkPreviewSchema = exports.credentialVerifyResultSchema = exports.credentialListResultSchema = exports.credentialIssueResultSchema = exports.verifiableCredentialResponseSchema = exports.credentialRecordSchema = exports.vouchResultSchema = exports.personhoodStatusResultSchema = void 0;
15
+ exports.loginResultSchema = exports.deviceTokenMintResponseSchema = exports.deviceTokenMintRequestSchema = exports.deviceSessionSyncSchema = exports.activeTokenSchema = exports.deviceSessionStateSchema = exports.sessionAccountSchema = exports.linkPreviewResponseSchema = exports.linkPreviewBatchResponseSchema = exports.linkPreviewBatchRequestSchema = exports.linkPreviewSchema = exports.credentialVerifyResultSchema = exports.credentialListResultSchema = exports.credentialIssueResultSchema = exports.verifiableCredentialResponseSchema = exports.credentialRecordSchema = exports.vouchResultSchema = exports.personhoodStatusResultSchema = void 0;
16
16
  var userResponse_1 = require("./userResponse");
17
17
  // Schemas
18
18
  Object.defineProperty(exports, "userNameSchema", { enumerable: true, get: function () { return userResponse_1.userNameSchema; } });
@@ -99,16 +99,8 @@ Object.defineProperty(exports, "sessionAccountSchema", { enumerable: true, get:
99
99
  Object.defineProperty(exports, "deviceSessionStateSchema", { enumerable: true, get: function () { return deviceSession_1.deviceSessionStateSchema; } });
100
100
  Object.defineProperty(exports, "activeTokenSchema", { enumerable: true, get: function () { return deviceSession_1.activeTokenSchema; } });
101
101
  Object.defineProperty(exports, "deviceSessionSyncSchema", { enumerable: true, get: function () { return deviceSession_1.deviceSessionSyncSchema; } });
102
+ Object.defineProperty(exports, "deviceTokenMintRequestSchema", { enumerable: true, get: function () { return deviceSession_1.deviceTokenMintRequestSchema; } });
103
+ Object.defineProperty(exports, "deviceTokenMintResponseSchema", { enumerable: true, get: function () { return deviceSession_1.deviceTokenMintResponseSchema; } });
102
104
  var deviceBoot_1 = require("./deviceBoot");
103
105
  // Schemas
104
- Object.defineProperty(exports, "deviceBootReasonSchema", { enumerable: true, get: function () { return deviceBoot_1.deviceBootReasonSchema; } });
105
- Object.defineProperty(exports, "deviceBootFragmentSchema", { enumerable: true, get: function () { return deviceBoot_1.deviceBootFragmentSchema; } });
106
- Object.defineProperty(exports, "deviceExchangeRequestSchema", { enumerable: true, get: function () { return deviceBoot_1.deviceExchangeRequestSchema; } });
107
- Object.defineProperty(exports, "authTokenBundleSchema", { enumerable: true, get: function () { return deviceBoot_1.authTokenBundleSchema; } });
108
- Object.defineProperty(exports, "webSessionResultSchema", { enumerable: true, get: function () { return deviceBoot_1.webSessionResultSchema; } });
109
- Object.defineProperty(exports, "tokenRefreshRequestSchema", { enumerable: true, get: function () { return deviceBoot_1.tokenRefreshRequestSchema; } });
110
- Object.defineProperty(exports, "tokenRefreshResponseSchema", { enumerable: true, get: function () { return deviceBoot_1.tokenRefreshResponseSchema; } });
111
- Object.defineProperty(exports, "deviceTokenIssueResponseSchema", { enumerable: true, get: function () { return deviceBoot_1.deviceTokenIssueResponseSchema; } });
112
106
  Object.defineProperty(exports, "loginResultSchema", { enumerable: true, get: function () { return deviceBoot_1.loginResultSchema; } });
113
- Object.defineProperty(exports, "deviceResolveRequestSchema", { enumerable: true, get: function () { return deviceBoot_1.deviceResolveRequestSchema; } });
114
- Object.defineProperty(exports, "deviceResolveResponseSchema", { enumerable: true, get: function () { return deviceBoot_1.deviceResolveResponseSchema; } });
@@ -17,8 +17,7 @@
17
17
  *
18
18
  * Faithful to the producers:
19
19
  * - `packages/api/src/utils/userTransform.ts` `formatUserResponse` — the
20
- * canonical serialization used by the device-first bootstrap/exchange
21
- * endpoints (`deviceAuth.ts`), login/signup, device sessions, etc.
20
+ * canonical serialization used by login/signup, device sessions, etc.
22
21
  * Emits `id` (NOT `_id`), forwards `username` verbatim (may be absent), and
23
22
  * emits `name` as the structured `{ first, last, full, displayName }`
24
23
  * subdocument.