@oxyhq/core 12.10.6 → 12.11.1

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 (139) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/HttpService.js +66 -6
  3. package/dist/cjs/boot/sessionColdBoot.js +142 -37
  4. package/dist/cjs/i18n/locales/ar-SA.json +13 -1
  5. package/dist/cjs/i18n/locales/ca-ES.json +13 -1
  6. package/dist/cjs/i18n/locales/de-DE.json +13 -1
  7. package/dist/cjs/i18n/locales/en-US.json +13 -4
  8. package/dist/cjs/i18n/locales/es-ES.json +13 -4
  9. package/dist/cjs/i18n/locales/fr-FR.json +13 -1
  10. package/dist/cjs/i18n/locales/it-IT.json +13 -1
  11. package/dist/cjs/i18n/locales/ja-JP.json +13 -1
  12. package/dist/cjs/i18n/locales/ko-KR.json +13 -1
  13. package/dist/cjs/i18n/locales/locales/ar-SA.json +13 -1
  14. package/dist/cjs/i18n/locales/locales/ca-ES.json +13 -1
  15. package/dist/cjs/i18n/locales/locales/de-DE.json +13 -1
  16. package/dist/cjs/i18n/locales/locales/en-US.json +13 -4
  17. package/dist/cjs/i18n/locales/locales/es-ES.json +13 -4
  18. package/dist/cjs/i18n/locales/locales/fr-FR.json +13 -1
  19. package/dist/cjs/i18n/locales/locales/it-IT.json +13 -1
  20. package/dist/cjs/i18n/locales/locales/ja-JP.json +13 -1
  21. package/dist/cjs/i18n/locales/locales/ko-KR.json +13 -1
  22. package/dist/cjs/i18n/locales/locales/pt-PT.json +13 -1
  23. package/dist/cjs/i18n/locales/locales/zh-CN.json +13 -1
  24. package/dist/cjs/i18n/locales/pt-PT.json +13 -1
  25. package/dist/cjs/i18n/locales/zh-CN.json +13 -1
  26. package/dist/cjs/index.js +31 -5
  27. package/dist/cjs/mixins/OxyServices.auth.js +257 -17
  28. package/dist/cjs/mixins/OxyServices.deviceBoot.js +54 -3
  29. package/dist/cjs/mixins/OxyServices.notifications.js +63 -0
  30. package/dist/cjs/mixins/OxyServices.privacy.js +6 -0
  31. package/dist/cjs/mixins/OxyServices.user.js +1 -0
  32. package/dist/cjs/mixins/index.js +5 -0
  33. package/dist/cjs/session/SessionClient.js +40 -4
  34. package/dist/cjs/session/accountDialogController.js +288 -41
  35. package/dist/cjs/session/identityPin.js +256 -0
  36. package/dist/cjs/session/identitySession.js +135 -0
  37. package/dist/cjs/session/projectSessionState.js +54 -15
  38. package/dist/cjs/session/refresh.js +73 -8
  39. package/dist/cjs/utils/commonsDelivery.js +59 -0
  40. package/dist/cjs/utils/oauthPkce.js +33 -3
  41. package/dist/esm/.tsbuildinfo +1 -1
  42. package/dist/esm/HttpService.js +66 -6
  43. package/dist/esm/boot/sessionColdBoot.js +142 -37
  44. package/dist/esm/i18n/locales/ar-SA.json +13 -1
  45. package/dist/esm/i18n/locales/ca-ES.json +13 -1
  46. package/dist/esm/i18n/locales/de-DE.json +13 -1
  47. package/dist/esm/i18n/locales/en-US.json +13 -4
  48. package/dist/esm/i18n/locales/es-ES.json +13 -4
  49. package/dist/esm/i18n/locales/fr-FR.json +13 -1
  50. package/dist/esm/i18n/locales/it-IT.json +13 -1
  51. package/dist/esm/i18n/locales/ja-JP.json +13 -1
  52. package/dist/esm/i18n/locales/ko-KR.json +13 -1
  53. package/dist/esm/i18n/locales/locales/ar-SA.json +13 -1
  54. package/dist/esm/i18n/locales/locales/ca-ES.json +13 -1
  55. package/dist/esm/i18n/locales/locales/de-DE.json +13 -1
  56. package/dist/esm/i18n/locales/locales/en-US.json +13 -4
  57. package/dist/esm/i18n/locales/locales/es-ES.json +13 -4
  58. package/dist/esm/i18n/locales/locales/fr-FR.json +13 -1
  59. package/dist/esm/i18n/locales/locales/it-IT.json +13 -1
  60. package/dist/esm/i18n/locales/locales/ja-JP.json +13 -1
  61. package/dist/esm/i18n/locales/locales/ko-KR.json +13 -1
  62. package/dist/esm/i18n/locales/locales/pt-PT.json +13 -1
  63. package/dist/esm/i18n/locales/locales/zh-CN.json +13 -1
  64. package/dist/esm/i18n/locales/pt-PT.json +13 -1
  65. package/dist/esm/i18n/locales/zh-CN.json +13 -1
  66. package/dist/esm/index.js +14 -1
  67. package/dist/esm/mixins/OxyServices.auth.js +257 -17
  68. package/dist/esm/mixins/OxyServices.deviceBoot.js +52 -3
  69. package/dist/esm/mixins/OxyServices.notifications.js +60 -0
  70. package/dist/esm/mixins/OxyServices.privacy.js +6 -0
  71. package/dist/esm/mixins/OxyServices.user.js +1 -0
  72. package/dist/esm/mixins/index.js +5 -0
  73. package/dist/esm/session/SessionClient.js +40 -4
  74. package/dist/esm/session/accountDialogController.js +288 -41
  75. package/dist/esm/session/identityPin.js +249 -0
  76. package/dist/esm/session/identitySession.js +131 -0
  77. package/dist/esm/session/projectSessionState.js +54 -15
  78. package/dist/esm/session/refresh.js +73 -8
  79. package/dist/esm/utils/commonsDelivery.js +54 -0
  80. package/dist/esm/utils/oauthPkce.js +31 -2
  81. package/dist/types/.tsbuildinfo +1 -1
  82. package/dist/types/HttpService.d.ts +18 -1
  83. package/dist/types/boot/sessionColdBoot.d.ts +38 -1
  84. package/dist/types/index.d.ts +12 -4
  85. package/dist/types/mixins/OxyServices.auth.d.ts +262 -11
  86. package/dist/types/mixins/OxyServices.deviceBoot.d.ts +31 -1
  87. package/dist/types/mixins/OxyServices.notifications.d.ts +143 -0
  88. package/dist/types/mixins/OxyServices.user.d.ts +2 -0
  89. package/dist/types/mixins/index.d.ts +2 -1
  90. package/dist/types/session/SessionClient.d.ts +28 -0
  91. package/dist/types/session/accountDialogController.d.ts +187 -9
  92. package/dist/types/session/identityPin.d.ts +87 -0
  93. package/dist/types/session/identitySession.d.ts +105 -0
  94. package/dist/types/session/projectSessionState.d.ts +21 -19
  95. package/dist/types/session/refresh.d.ts +32 -1
  96. package/dist/types/utils/commonsDelivery.d.ts +105 -0
  97. package/dist/types/utils/oauthPkce.d.ts +21 -1
  98. package/package.json +3 -3
  99. package/src/HttpService.ts +67 -6
  100. package/src/__tests__/inSessionRefresh.test.ts +67 -0
  101. package/src/boot/__tests__/sessionColdBoot.identity.test.ts +393 -0
  102. package/src/boot/sessionColdBoot.ts +183 -37
  103. package/src/i18n/locales/ar-SA.json +13 -1
  104. package/src/i18n/locales/ca-ES.json +13 -1
  105. package/src/i18n/locales/de-DE.json +13 -1
  106. package/src/i18n/locales/en-US.json +13 -4
  107. package/src/i18n/locales/es-ES.json +13 -4
  108. package/src/i18n/locales/fr-FR.json +13 -1
  109. package/src/i18n/locales/it-IT.json +13 -1
  110. package/src/i18n/locales/ja-JP.json +13 -1
  111. package/src/i18n/locales/ko-KR.json +13 -1
  112. package/src/i18n/locales/pt-PT.json +13 -1
  113. package/src/i18n/locales/zh-CN.json +13 -1
  114. package/src/index.ts +49 -0
  115. package/src/mixins/OxyServices.auth.ts +464 -24
  116. package/src/mixins/OxyServices.deviceBoot.ts +54 -2
  117. package/src/mixins/OxyServices.notifications.ts +142 -0
  118. package/src/mixins/OxyServices.privacy.ts +6 -0
  119. package/src/mixins/OxyServices.user.ts +3 -0
  120. package/src/mixins/__tests__/commonsSignIn.test.ts +754 -2
  121. package/src/mixins/__tests__/deviceTokenMintPinned.test.ts +113 -0
  122. package/src/mixins/__tests__/preSessionSkipAuth.test.ts +18 -0
  123. package/src/mixins/__tests__/privacyCacheInvalidation.test.ts +2 -0
  124. package/src/mixins/index.ts +6 -0
  125. package/src/session/SessionClient.ts +57 -4
  126. package/src/session/__tests__/SessionClient.identityPin.test.ts +175 -0
  127. package/src/session/__tests__/accountDialogController.test.ts +812 -1
  128. package/src/session/__tests__/identityPin.test.ts +131 -0
  129. package/src/session/__tests__/identitySession.test.ts +194 -0
  130. package/src/session/__tests__/projectSessionState.test.ts +88 -0
  131. package/src/session/__tests__/refresh.identityPin.test.ts +306 -0
  132. package/src/session/accountDialogController.ts +435 -44
  133. package/src/session/identityPin.ts +310 -0
  134. package/src/session/identitySession.ts +206 -0
  135. package/src/session/projectSessionState.ts +61 -13
  136. package/src/session/refresh.ts +103 -9
  137. package/src/utils/__tests__/oauthPkce.test.ts +51 -0
  138. package/src/utils/commonsDelivery.ts +132 -0
  139. package/src/utils/oauthPkce.ts +56 -3
@@ -53,11 +53,30 @@ const CSRF_FETCH_MAX_ATTEMPTS = 2;
53
53
  const CSRF_FETCH_RETRY_DELAY_MS = 500;
54
54
  /**
55
55
  * Cooldown (ms) applied after a failed access-token refresh before another
56
- * refresh is attempted. Prevents a refresh storm (and server hammering) when
56
+ * refresh is attempted while the CURRENT token is still valid (a proactive,
57
+ * near-expiry refresh). Prevents a refresh storm (and server hammering) when
57
58
  * the auth refresh handler is failing — every in-flight request that
58
- * hits a 401 would otherwise trigger its own refresh.
59
+ * hits a 401 would otherwise trigger its own refresh. A still-valid token can
60
+ * afford to wait this out; the request keeps carrying it in the meantime.
59
61
  */
60
62
  const TOKEN_REFRESH_COOLDOWN_MS = 15000;
63
+ /**
64
+ * Cooldown (ms) applied after a failed refresh when the CURRENT access token is
65
+ * already past its `exp`. Much shorter than {@link TOKEN_REFRESH_COOLDOWN_MS}:
66
+ * an expired token is UNUSABLE, so the client must re-mint as soon as the mint
67
+ * endpoint is reachable again (e.g. a few seconds after an ECS rolling-deploy
68
+ * blip drains/restarts a task) instead of waiting out the full proactive
69
+ * cooldown while every request forwards or omits a stale bearer → server 401.
70
+ *
71
+ * Still NON-ZERO on purpose: it bounds the request-driven retry rate to at most
72
+ * one attempt per this interval so a PROLONGED outage cannot become a tight
73
+ * network storm. Combined with the process-wide single-flight below (concurrent
74
+ * requests coalesce to one in-flight mint) and the refresh handler's own
75
+ * terminal-state handling (a genuinely revoked session clears its device
76
+ * credential and stops issuing network mints), this recovers a transient blip
77
+ * ~15× faster without weakening the storm guard.
78
+ */
79
+ const EXPIRED_TOKEN_REFRESH_COOLDOWN_MS = 1000;
61
80
  /**
62
81
  * Lead time (seconds) before access-token expiry at which a preflight refresh
63
82
  * is triggered. A token within this window of `exp` is treated as effectively
@@ -130,7 +149,15 @@ class TokenStore {
130
149
  export class HttpService {
131
150
  constructor(config) {
132
151
  this.tokenRefreshPromise = null;
133
- this.tokenRefreshCooldownUntil = 0;
152
+ /**
153
+ * Epoch ms of the last FAILED refresh (0 = none since the last success). The
154
+ * post-failure cooldown is measured from here; its length depends on whether
155
+ * the current token is still valid ({@link TOKEN_REFRESH_COOLDOWN_MS}) or
156
+ * already expired ({@link EXPIRED_TOKEN_REFRESH_COOLDOWN_MS}), so an expired
157
+ * token recovers promptly the instant it crosses `exp` — without storing a
158
+ * fixed deadline that could not shrink once the token expired mid-cooldown.
159
+ */
160
+ this.lastRefreshFailureAt = 0;
134
161
  this.authRefreshHandler = null;
135
162
  this.accessTokenProvider = null;
136
163
  this.deviceSecretMintInFlight = null;
@@ -820,26 +847,38 @@ export class HttpService {
820
847
  if (!this.authRefreshHandler) {
821
848
  return null;
822
849
  }
823
- if (Date.now() < this.tokenRefreshCooldownUntil) {
850
+ // Post-failure cooldown. A genuinely EXPIRED current token uses a much
851
+ // shorter cooldown than a still-valid (proactive, near-expiry) one: an
852
+ // expired token is unusable, so re-mint as soon as the endpoint is reachable
853
+ // again rather than waiting out the full window while requests carry a stale
854
+ // bearer. Both cooldowns are measured from the last failure, so the moment a
855
+ // still-valid token crosses `exp` mid-cooldown the shorter window applies.
856
+ const cooldownMs = this.isAccessTokenExpired()
857
+ ? EXPIRED_TOKEN_REFRESH_COOLDOWN_MS
858
+ : TOKEN_REFRESH_COOLDOWN_MS;
859
+ if (Date.now() - this.lastRefreshFailureAt < cooldownMs) {
824
860
  return null;
825
861
  }
826
862
  if (!this.tokenRefreshPromise) {
827
863
  this.tokenRefreshPromise = this.authRefreshHandler(reason)
828
864
  .then((newToken) => {
829
865
  if (!newToken) {
830
- this.tokenRefreshCooldownUntil = Date.now() + TOKEN_REFRESH_COOLDOWN_MS;
866
+ this.lastRefreshFailureAt = Date.now();
831
867
  return null;
832
868
  }
833
869
  if (this.tokenStore.getAccessToken() !== newToken) {
834
870
  this.tokenStore.setTokens(newToken);
835
871
  this.notifyTokenChange();
836
872
  }
873
+ // A success clears the failure timestamp so the next refresh is never
874
+ // throttled by a stale cooldown.
875
+ this.lastRefreshFailureAt = 0;
837
876
  this.logger.debug('Token refreshed via the auth refresh handler');
838
877
  return newToken;
839
878
  })
840
879
  .catch((error) => {
841
880
  this.logger.warn('Token refresh failed:', error);
842
- this.tokenRefreshCooldownUntil = Date.now() + TOKEN_REFRESH_COOLDOWN_MS;
881
+ this.lastRefreshFailureAt = Date.now();
843
882
  return null;
844
883
  })
845
884
  .finally(() => {
@@ -848,6 +887,27 @@ export class HttpService {
848
887
  }
849
888
  return this.tokenRefreshPromise;
850
889
  }
890
+ /**
891
+ * Whether the CURRENT stored access token is already past its `exp`. Drives
892
+ * the shorter post-failure refresh cooldown ({@link EXPIRED_TOKEN_REFRESH_COOLDOWN_MS}):
893
+ * a still-valid (near-expiry) token can wait out the full cooldown, but an
894
+ * expired one must re-mint promptly. Returns `false` for an absent or
895
+ * opaque/no-`exp` token — no proof it is expired, so keep the conservative
896
+ * (longer) cooldown and avoid an unnecessary retry loop.
897
+ */
898
+ isAccessTokenExpired() {
899
+ const token = this.tokenStore.getAccessToken();
900
+ if (!token) {
901
+ return false;
902
+ }
903
+ try {
904
+ const decoded = jwtDecode(token);
905
+ return typeof decoded.exp === 'number' && decoded.exp <= Math.floor(Date.now() / 1000);
906
+ }
907
+ catch {
908
+ return false;
909
+ }
910
+ }
851
911
  /**
852
912
  * PROCESS-WIDE single-flight for the rotating device-secret mint
853
913
  * (`POST /session/device/token`).
@@ -15,15 +15,28 @@
15
15
  * origin persisted a `deviceId` + `deviceSecret`, mint a short access token
16
16
  * with a single bearer-less POST to `/session/device/token` (no cookie, no
17
17
  * navigation) and rotate the secret in-use.
18
- * 3. `shared-key-signin` (native) — re-mint from the shared-keychain identity.
18
+ * 3. `shared-key-signin` (native, ACCOUNT mode) — re-mint from the
19
+ * shared-keychain identity — OR `identity-key-signin` (IDENTITY mode) —
20
+ * re-mint from THIS device's primary identity key.
19
21
  * 4. Signed out.
20
22
  *
23
+ * Two session modes (see {@link RunSessionColdBootOptions.sessionMode}):
24
+ * - `account` (default) — the device's ACTIVE account owns the session. Every
25
+ * Oxy app but the identity vault boots this way; behaviour is unchanged.
26
+ * - `identity` — the owner of the local PRIMARY identity key owns the session,
27
+ * permanently, regardless of which account the device is switched to. Each
28
+ * step above is bound to the persisted identity pin, and the shared-keychain
29
+ * lane is replaced by the primary-key one (the shared slot is a CROSS-APP
30
+ * slot that may hold a different identity).
31
+ *
21
32
  * ESM-safe (no `require()`); no react/react-native/expo imports.
22
33
  */
23
34
  import { runColdBoot } from '../utils/coldBoot.js';
24
35
  import { isNative as detectNative } from '../utils/platform.js';
25
36
  import { logger } from '../logger/index.js';
37
+ import { computeIdentityTag } from '../utils/cacheKey.js';
26
38
  import { TOKEN_REFRESH_LEAD_MS, refreshDeviceSecretArm } from '../session/refresh.js';
39
+ import { establishIdentitySession, resolveIdentityPin, } from '../session/identitySession.js';
27
40
  /**
28
41
  * Run the device-first cold boot. Resolves to the `runColdBoot` outcome and, as
29
42
  * a side effect, invokes `onSession` (winning session, token already planted) or
@@ -32,6 +45,14 @@ import { TOKEN_REFRESH_LEAD_MS, refreshDeviceSecretArm } from '../session/refres
32
45
  export async function runSessionColdBoot(opts) {
33
46
  const { oxy, store } = opts;
34
47
  const isNative = opts.platform?.isNative ?? detectNative();
48
+ // Non-null ONLY in identity mode; every `!== null` test below therefore reads
49
+ // as "is this boot identity-bound?" while also narrowing the binding.
50
+ const identityBinding = opts.sessionMode === 'identity' ? opts.identity ?? null : null;
51
+ if (opts.sessionMode === 'identity' && identityBinding === null) {
52
+ logger.error('runSessionColdBoot: sessionMode "identity" requires an `identity` binding — refusing to run any lane (an identity-bound client must never adopt the device active account)', undefined, { component: 'sessionColdBoot', method: 'runSessionColdBoot' });
53
+ await opts.onSignedOut?.('error');
54
+ return { kind: 'unauthenticated' };
55
+ }
35
56
  // Best-effort connectivity gate for the NETWORK steps only. A missing hint or
36
57
  // any non-`true` verdict means "assume online" — never falsely skip a real
37
58
  // sign-in on an ambiguous probe.
@@ -39,6 +60,22 @@ export async function runSessionColdBoot(opts) {
39
60
  // Boot-local (not module-level) so it cannot leak across boots or break under
40
61
  // bundler re-evaluation.
41
62
  let signedOutReason = 'no_session';
63
+ // Boot-local memo for the identity pin. Resolved lazily INSIDE a step so the
64
+ // (local, but storage-backed) read is covered by `overallDeadlineMs`, and
65
+ // resolved at most once per boot so two steps cannot disagree. Always `null`
66
+ // in account mode.
67
+ let pinResolved = false;
68
+ let cachedPin = null;
69
+ const getIdentityPin = async () => {
70
+ if (identityBinding === null) {
71
+ return null;
72
+ }
73
+ if (!pinResolved) {
74
+ cachedPin = await resolveIdentityPin(identityBinding);
75
+ pinResolved = true;
76
+ }
77
+ return cachedPin;
78
+ };
42
79
  const steps = [];
43
80
  // 1. warm-token-plant (web + native) — the fastest path. When the persisted
44
81
  // store already holds a still-valid warm access token (its expiry more than
@@ -66,6 +103,19 @@ export async function runSessionColdBoot(opts) {
66
103
  if (!Number.isFinite(expiresAtMs) || expiresAtMs <= Date.now() + TOKEN_REFRESH_LEAD_MS) {
67
104
  return { kind: 'skip' };
68
105
  }
106
+ if (identityBinding !== null) {
107
+ // Identity-bound: a persisted token is only acceptable when it belongs to
108
+ // the PINNED account. Both the token's own claim (`computeIdentityTag`,
109
+ // the same derivation `SessionClient.applyState` uses) and the owning
110
+ // session identity must match — a token planted for another account by an
111
+ // earlier account-mode write is exactly the durable drift this gate stops.
112
+ const pin = await getIdentityPin();
113
+ if (pin === null ||
114
+ persisted.userId !== pin.accountId ||
115
+ computeIdentityTag(persisted.accessToken) !== pin.accountId) {
116
+ return { kind: 'skip' };
117
+ }
118
+ }
69
119
  oxy.setTokens(persisted.accessToken);
70
120
  return {
71
121
  kind: 'session',
@@ -91,7 +141,16 @@ export async function runSessionColdBoot(opts) {
91
141
  // a doomed mint cannot burn the overall deadline before routing settles.
92
142
  enabled: () => !isOffline(),
93
143
  run: async () => {
94
- const result = await refreshDeviceSecretArm({ oxy, store });
144
+ const pin = await getIdentityPin();
145
+ if (identityBinding !== null && pin === null) {
146
+ // Identity-bound with no verified pin (never written, or cleared because
147
+ // the local key changed/vanished). An UNPINNED mint would adopt whichever
148
+ // account the device is currently switched to — the exact drift this mode
149
+ // exists to prevent. Fall through to `identity-key-signin`, which
150
+ // re-derives the account from the local key and rewrites the pin.
151
+ return { kind: 'skip' };
152
+ }
153
+ const result = await refreshDeviceSecretArm({ oxy, store, pin });
95
154
  switch (result.status) {
96
155
  case 'ok':
97
156
  // The arm persisted the rotated secret and planted the token.
@@ -125,6 +184,12 @@ export async function runSessionColdBoot(opts) {
125
184
  // the secret; a later boot/attempt re-mints once storage recovers.
126
185
  logger.error('device-secret mint rotated the secret but it could not be durably persisted — not planting', undefined, { component: 'sessionColdBoot', method: 'device-secret-mint' });
127
186
  return { kind: 'skip' };
187
+ case 'account-not-on-device':
188
+ // Pinned mint rejected: the pinned account is no longer a live account
189
+ // of this device session. The secret is healthy — keep it untouched and
190
+ // let `identity-key-signin` re-establish from the local key.
191
+ logger.debug('pinned device-secret mint rejected (account_not_on_device) — keeping secret, re-establishing from the identity key', { component: 'sessionColdBoot', method: 'device-secret-mint' });
192
+ return { kind: 'skip' };
128
193
  case 'transient':
129
194
  // Network / 5xx: keep the secret; a later attempt can succeed.
130
195
  logger.debug('device-secret mint failed (transient) — keeping secret', { component: 'sessionColdBoot', method: 'device-secret-mint' });
@@ -134,42 +199,82 @@ export async function runSessionColdBoot(opts) {
134
199
  }
135
200
  },
136
201
  });
137
- // 3. shared-key-signin (native) — re-mint from the shared identity. Native
138
- // AND online: it is a network step (challenge + verify round-trips), so it
139
- // is gated by the same offline hint as the mint lane. `{ retry: false }`
140
- // keeps the two round-trips as single attempts the refresh scheduler /
141
- // 401 lane own later retries so this step cannot multiply boot latency.
142
- steps.push({
143
- id: 'shared-key-signin',
144
- enabled: () => isNative && !isOffline(),
145
- run: async () => {
146
- const session = await oxy.signInWithSharedIdentity({ requestOptions: { retry: false } });
147
- if (!session?.accessToken) {
148
- return { kind: 'skip' };
149
- }
150
- // `verifyChallenge` mints a rotating deviceSecret; persist it so the next
151
- // boot can use the faster device-secret-mint lane (sockets + tab-focus
152
- // re-mint depend on the credential being in the store).
153
- if (session.deviceId && session.deviceSecret) {
154
- await store.save({
155
- sessionId: session.sessionId,
156
- userId: session.user.id,
157
- deviceId: session.deviceId,
158
- deviceSecret: session.deviceSecret,
159
- accessToken: session.accessToken,
160
- expiresAt: session.expiresAt,
202
+ if (identityBinding !== null) {
203
+ // 3-identity. identity-key-signin re-mint from THIS device's PRIMARY
204
+ // identity key (`getPublicKey` challenge sign verify). It REPLACES
205
+ // `shared-key-signin`, which reads the CROSS-APP shared keychain slot and
206
+ // may therefore hold a different identity than the device's primary the
207
+ // one thing an identity-bound client must never adopt. The server resolves
208
+ // the account from the verified signer, so the winning session is
209
+ // identity-authoritative and the pin is (re)written from it.
210
+ //
211
+ // Online-gated like every network step; `{ retry: false }` keeps the two
212
+ // round-trips single attempts (the refresh scheduler / 401 lane own later
213
+ // retries) so this step cannot multiply boot latency. On web
214
+ // `KeyManager.getPublicKey()` resolves to `null`, so it skips.
215
+ steps.push({
216
+ id: 'identity-key-signin',
217
+ enabled: () => !isOffline(),
218
+ run: async () => {
219
+ const established = await establishIdentitySession({
220
+ oxy,
221
+ store,
222
+ binding: identityBinding,
223
+ requestOptions: { retry: false },
161
224
  });
162
- }
163
- return {
164
- kind: 'session',
165
- session: {
166
- sessionId: session.sessionId,
167
- userId: session.user.id,
168
- accessToken: session.accessToken,
169
- },
170
- };
171
- },
172
- });
225
+ const accessToken = established?.session.accessToken;
226
+ if (!established || !accessToken) {
227
+ return { kind: 'skip' };
228
+ }
229
+ return {
230
+ kind: 'session',
231
+ session: {
232
+ sessionId: established.session.sessionId,
233
+ userId: established.session.user.id,
234
+ accessToken,
235
+ },
236
+ };
237
+ },
238
+ });
239
+ }
240
+ else {
241
+ // 3. shared-key-signin (native) — re-mint from the shared identity. Native
242
+ // AND online: it is a network step (challenge + verify round-trips), so it
243
+ // is gated by the same offline hint as the mint lane. `{ retry: false }`
244
+ // keeps the two round-trips as single attempts — the refresh scheduler /
245
+ // 401 lane own later retries — so this step cannot multiply boot latency.
246
+ steps.push({
247
+ id: 'shared-key-signin',
248
+ enabled: () => isNative && !isOffline(),
249
+ run: async () => {
250
+ const session = await oxy.signInWithSharedIdentity({ requestOptions: { retry: false } });
251
+ if (!session?.accessToken) {
252
+ return { kind: 'skip' };
253
+ }
254
+ // `verifyChallenge` mints a rotating deviceSecret; persist it so the next
255
+ // boot can use the faster device-secret-mint lane (sockets + tab-focus
256
+ // re-mint depend on the credential being in the store).
257
+ if (session.deviceId && session.deviceSecret) {
258
+ await store.save({
259
+ sessionId: session.sessionId,
260
+ userId: session.user.id,
261
+ deviceId: session.deviceId,
262
+ deviceSecret: session.deviceSecret,
263
+ accessToken: session.accessToken,
264
+ expiresAt: session.expiresAt,
265
+ });
266
+ }
267
+ return {
268
+ kind: 'session',
269
+ session: {
270
+ sessionId: session.sessionId,
271
+ userId: session.user.id,
272
+ accessToken: session.accessToken,
273
+ },
274
+ };
275
+ },
276
+ });
277
+ }
173
278
  const outcome = await runColdBoot({
174
279
  steps,
175
280
  overallDeadlineMs: opts.overallDeadlineMs,
@@ -124,7 +124,19 @@
124
124
  "commonsNotInstalled": "لا تملك Commons؟ احصل على التطبيق لتسجيل الدخول بمعرّف Oxy الخاص بك.",
125
125
  "showQrAnyway": "لدي Commons على جهاز آخر",
126
126
  "switchWhileSignedInAs": "تبديل الحساب، مسجّل الدخول باسم {{name}}",
127
- "manageOnDevice": "إدارة الحسابات على هذا الجهاز"
127
+ "manageOnDevice": "إدارة الحسابات على هذا الجهاز",
128
+ "continueWithOxy": "المتابعة باستخدام Oxy",
129
+ "havingTrouble": "هل تواجه مشكلة؟",
130
+ "progress": {
131
+ "preparing": "جارٍ تحضير الطلب",
132
+ "awaitingApproval": "في انتظار الموافقة",
133
+ "scanWithCommons": "امسح الرمز باستخدام Commons على هاتفك",
134
+ "continueInCommons": "تابع في Commons",
135
+ "checkCommons": "تحقّق من Commons على هاتفك",
136
+ "openedInCommons": "تم الفتح في Commons",
137
+ "confirming": "جارٍ تأكيد الهوية",
138
+ "confirmed": "تم تأكيد الهوية"
139
+ }
128
140
  },
129
141
  "common": {
130
142
  "actions": {
@@ -124,7 +124,19 @@
124
124
  "commonsNotInstalled": "No tens Commons? Descarrega l'app per iniciar sessió amb el teu Oxy ID.",
125
125
  "showQrAnyway": "Tinc Commons en un altre dispositiu",
126
126
  "switchWhileSignedInAs": "Canvia de compte, amb la sessió iniciada com a {{name}}",
127
- "manageOnDevice": "Gestionar comptes en aquest dispositiu"
127
+ "manageOnDevice": "Gestionar comptes en aquest dispositiu",
128
+ "continueWithOxy": "Continua amb Oxy",
129
+ "havingTrouble": "Algun problema?",
130
+ "progress": {
131
+ "preparing": "Preparant la sol·licitud",
132
+ "awaitingApproval": "Esperant l'aprovació",
133
+ "scanWithCommons": "Escaneja amb Commons al teu mòbil",
134
+ "continueInCommons": "Continua a Commons",
135
+ "checkCommons": "Revisa Commons al teu mòbil",
136
+ "openedInCommons": "Obert a Commons",
137
+ "confirming": "Confirmant la identitat",
138
+ "confirmed": "Identitat confirmada"
139
+ }
128
140
  },
129
141
  "common": {
130
142
  "actions": {
@@ -124,7 +124,19 @@
124
124
  "commonsNotInstalled": "Kein Commons? Holen Sie sich die App, um sich mit Ihrer Oxy-ID anzumelden.",
125
125
  "showQrAnyway": "Ich habe Commons auf einem anderen Gerät",
126
126
  "switchWhileSignedInAs": "Konto wechseln, angemeldet als {{name}}",
127
- "manageOnDevice": "Konten auf diesem Gerät verwalten"
127
+ "manageOnDevice": "Konten auf diesem Gerät verwalten",
128
+ "continueWithOxy": "Mit Oxy fortfahren",
129
+ "havingTrouble": "Gibt es ein Problem?",
130
+ "progress": {
131
+ "preparing": "Anfrage wird vorbereitet",
132
+ "awaitingApproval": "Warten auf Freigabe",
133
+ "scanWithCommons": "Scannen Sie mit Commons auf Ihrem Telefon",
134
+ "continueInCommons": "In Commons fortfahren",
135
+ "checkCommons": "Prüfen Sie Commons auf Ihrem Telefon",
136
+ "openedInCommons": "In Commons geöffnet",
137
+ "confirming": "Identität wird bestätigt",
138
+ "confirmed": "Identität bestätigt"
139
+ }
128
140
  },
129
141
  "common": {
130
142
  "actions": {
@@ -412,9 +412,6 @@
412
412
  },
413
413
  "label": "Account switcher",
414
414
  "searchPlaceholder": "Search accounts",
415
- "scanTitle": "Scan to sign in",
416
- "scanSubtitle": "Open the Oxy app on your phone and scan this code",
417
- "scanWithOxy": "Scan with the Oxy app to continue",
418
415
  "scanQr": "Scan QR code",
419
416
  "qrHeadline": "Sign in with your Oxy identity",
420
417
  "signInWithOxy": "Sign in with Oxy",
@@ -424,7 +421,19 @@
424
421
  "commonsNotInstalled": "Don't have Commons? Get the app to sign in with your Oxy ID.",
425
422
  "showQrAnyway": "I have Commons on another device",
426
423
  "switchWhileSignedInAs": "Switch account, signed in as {{name}}",
427
- "manageOnDevice": "Manage accounts on this device"
424
+ "manageOnDevice": "Manage accounts on this device",
425
+ "continueWithOxy": "Continue with Oxy",
426
+ "havingTrouble": "Having trouble?",
427
+ "progress": {
428
+ "preparing": "Preparing request",
429
+ "awaitingApproval": "Waiting for approval",
430
+ "scanWithCommons": "Scan with Commons on your phone",
431
+ "continueInCommons": "Continue in Commons",
432
+ "checkCommons": "Check Commons on your phone",
433
+ "openedInCommons": "Opened in Commons",
434
+ "confirming": "Confirming identity",
435
+ "confirmed": "Identity confirmed"
436
+ }
428
437
  },
429
438
  "reputation": {
430
439
  "faq": {
@@ -652,9 +652,6 @@
652
652
  },
653
653
  "label": "Selector de cuentas",
654
654
  "searchPlaceholder": "Buscar cuentas",
655
- "scanTitle": "Escanea para iniciar sesión",
656
- "scanSubtitle": "Abre la app de Oxy en tu móvil y escanea este código",
657
- "scanWithOxy": "Escanea con la app de Oxy para continuar",
658
655
  "scanQr": "Escanear código QR",
659
656
  "qrHeadline": "Inicia sesión con tu identidad de Oxy",
660
657
  "signInWithOxy": "Inicia sesión con Oxy",
@@ -664,7 +661,19 @@
664
661
  "commonsNotInstalled": "¿No tienes Commons? Descarga la app para iniciar sesión con tu Oxy ID.",
665
662
  "showQrAnyway": "Tengo Commons en otro dispositivo",
666
663
  "switchWhileSignedInAs": "Cambiar de cuenta, con la sesión iniciada como {{name}}",
667
- "manageOnDevice": "Gestionar cuentas en este dispositivo"
664
+ "manageOnDevice": "Gestionar cuentas en este dispositivo",
665
+ "continueWithOxy": "Continuar con Oxy",
666
+ "havingTrouble": "¿Algún problema?",
667
+ "progress": {
668
+ "preparing": "Preparando la solicitud",
669
+ "awaitingApproval": "Esperando la aprobación",
670
+ "scanWithCommons": "Escanea con Commons en tu móvil",
671
+ "continueInCommons": "Continúa en Commons",
672
+ "checkCommons": "Revisa Commons en tu móvil",
673
+ "openedInCommons": "Abierto en Commons",
674
+ "confirming": "Confirmando identidad",
675
+ "confirmed": "Identidad confirmada"
676
+ }
668
677
  },
669
678
  "feedback": {
670
679
  "type": {
@@ -124,7 +124,19 @@
124
124
  "commonsNotInstalled": "Pas de Commons ? Téléchargez l'app pour vous connecter avec votre Oxy ID.",
125
125
  "showQrAnyway": "J'ai Commons sur un autre appareil",
126
126
  "switchWhileSignedInAs": "Changer de compte, connecté en tant que {{name}}",
127
- "manageOnDevice": "Gérer les comptes sur cet appareil"
127
+ "manageOnDevice": "Gérer les comptes sur cet appareil",
128
+ "continueWithOxy": "Continuer avec Oxy",
129
+ "havingTrouble": "Un problème ?",
130
+ "progress": {
131
+ "preparing": "Préparation de la demande",
132
+ "awaitingApproval": "En attente d'approbation",
133
+ "scanWithCommons": "Scannez avec Commons sur votre téléphone",
134
+ "continueInCommons": "Continuez dans Commons",
135
+ "checkCommons": "Consultez Commons sur votre téléphone",
136
+ "openedInCommons": "Ouvert dans Commons",
137
+ "confirming": "Confirmation de l'identité",
138
+ "confirmed": "Identité confirmée"
139
+ }
128
140
  },
129
141
  "common": {
130
142
  "actions": {
@@ -124,7 +124,19 @@
124
124
  "commonsNotInstalled": "Non hai Commons? Scarica l'app per accedere con il tuo Oxy ID.",
125
125
  "showQrAnyway": "Ho Commons su un altro dispositivo",
126
126
  "switchWhileSignedInAs": "Cambia account, connesso come {{name}}",
127
- "manageOnDevice": "Gestisci account su questo dispositivo"
127
+ "manageOnDevice": "Gestisci account su questo dispositivo",
128
+ "continueWithOxy": "Continua con Oxy",
129
+ "havingTrouble": "Problemi?",
130
+ "progress": {
131
+ "preparing": "Preparazione della richiesta",
132
+ "awaitingApproval": "In attesa di approvazione",
133
+ "scanWithCommons": "Scansiona con Commons sul tuo telefono",
134
+ "continueInCommons": "Continua in Commons",
135
+ "checkCommons": "Controlla Commons sul tuo telefono",
136
+ "openedInCommons": "Aperto in Commons",
137
+ "confirming": "Conferma dell'identità in corso",
138
+ "confirmed": "Identità confermata"
139
+ }
128
140
  },
129
141
  "common": {
130
142
  "actions": {
@@ -124,7 +124,19 @@
124
124
  "commonsNotInstalled": "Commonsがありませんか?アプリを入手してOxy IDでサインインしましょう。",
125
125
  "showQrAnyway": "別のデバイスにCommonsがあります",
126
126
  "switchWhileSignedInAs": "アカウントを切り替え({{name}} としてログイン中)",
127
- "manageOnDevice": "このデバイスのアカウントを管理"
127
+ "manageOnDevice": "このデバイスのアカウントを管理",
128
+ "continueWithOxy": "Oxyで続ける",
129
+ "havingTrouble": "うまくいきませんか?",
130
+ "progress": {
131
+ "preparing": "リクエストを準備しています",
132
+ "awaitingApproval": "承認を待っています",
133
+ "scanWithCommons": "スマートフォンのCommonsでスキャンしてください",
134
+ "continueInCommons": "Commonsで続けてください",
135
+ "checkCommons": "スマートフォンのCommonsを確認してください",
136
+ "openedInCommons": "Commonsで開きました",
137
+ "confirming": "本人確認をしています",
138
+ "confirmed": "本人確認が完了しました"
139
+ }
128
140
  },
129
141
  "common": {
130
142
  "actions": {
@@ -124,7 +124,19 @@
124
124
  "commonsNotInstalled": "Commons가 없으신가요? 앱을 다운로드하여 Oxy ID로 로그인하세요.",
125
125
  "showQrAnyway": "다른 기기에 Commons가 있습니다",
126
126
  "switchWhileSignedInAs": "계정 전환, {{name}}(으)로 로그인됨",
127
- "manageOnDevice": "이 기기의 계정 관리"
127
+ "manageOnDevice": "이 기기의 계정 관리",
128
+ "continueWithOxy": "Oxy로 계속하기",
129
+ "havingTrouble": "문제가 있으신가요?",
130
+ "progress": {
131
+ "preparing": "요청 준비 중",
132
+ "awaitingApproval": "승인 대기 중",
133
+ "scanWithCommons": "휴대폰의 Commons로 스캔하세요",
134
+ "continueInCommons": "Commons에서 계속하세요",
135
+ "checkCommons": "휴대폰에서 Commons를 확인하세요",
136
+ "openedInCommons": "Commons에서 열림",
137
+ "confirming": "신원 확인 중",
138
+ "confirmed": "신원 확인 완료"
139
+ }
128
140
  },
129
141
  "common": {
130
142
  "actions": {
@@ -124,7 +124,19 @@
124
124
  "commonsNotInstalled": "لا تملك Commons؟ احصل على التطبيق لتسجيل الدخول بمعرّف Oxy الخاص بك.",
125
125
  "showQrAnyway": "لدي Commons على جهاز آخر",
126
126
  "switchWhileSignedInAs": "تبديل الحساب، مسجّل الدخول باسم {{name}}",
127
- "manageOnDevice": "إدارة الحسابات على هذا الجهاز"
127
+ "manageOnDevice": "إدارة الحسابات على هذا الجهاز",
128
+ "continueWithOxy": "المتابعة باستخدام Oxy",
129
+ "havingTrouble": "هل تواجه مشكلة؟",
130
+ "progress": {
131
+ "preparing": "جارٍ تحضير الطلب",
132
+ "awaitingApproval": "في انتظار الموافقة",
133
+ "scanWithCommons": "امسح الرمز باستخدام Commons على هاتفك",
134
+ "continueInCommons": "تابع في Commons",
135
+ "checkCommons": "تحقّق من Commons على هاتفك",
136
+ "openedInCommons": "تم الفتح في Commons",
137
+ "confirming": "جارٍ تأكيد الهوية",
138
+ "confirmed": "تم تأكيد الهوية"
139
+ }
128
140
  },
129
141
  "common": {
130
142
  "actions": {
@@ -124,7 +124,19 @@
124
124
  "commonsNotInstalled": "No tens Commons? Descarrega l'app per iniciar sessió amb el teu Oxy ID.",
125
125
  "showQrAnyway": "Tinc Commons en un altre dispositiu",
126
126
  "switchWhileSignedInAs": "Canvia de compte, amb la sessió iniciada com a {{name}}",
127
- "manageOnDevice": "Gestionar comptes en aquest dispositiu"
127
+ "manageOnDevice": "Gestionar comptes en aquest dispositiu",
128
+ "continueWithOxy": "Continua amb Oxy",
129
+ "havingTrouble": "Algun problema?",
130
+ "progress": {
131
+ "preparing": "Preparant la sol·licitud",
132
+ "awaitingApproval": "Esperant l'aprovació",
133
+ "scanWithCommons": "Escaneja amb Commons al teu mòbil",
134
+ "continueInCommons": "Continua a Commons",
135
+ "checkCommons": "Revisa Commons al teu mòbil",
136
+ "openedInCommons": "Obert a Commons",
137
+ "confirming": "Confirmant la identitat",
138
+ "confirmed": "Identitat confirmada"
139
+ }
128
140
  },
129
141
  "common": {
130
142
  "actions": {
@@ -124,7 +124,19 @@
124
124
  "commonsNotInstalled": "Kein Commons? Holen Sie sich die App, um sich mit Ihrer Oxy-ID anzumelden.",
125
125
  "showQrAnyway": "Ich habe Commons auf einem anderen Gerät",
126
126
  "switchWhileSignedInAs": "Konto wechseln, angemeldet als {{name}}",
127
- "manageOnDevice": "Konten auf diesem Gerät verwalten"
127
+ "manageOnDevice": "Konten auf diesem Gerät verwalten",
128
+ "continueWithOxy": "Mit Oxy fortfahren",
129
+ "havingTrouble": "Gibt es ein Problem?",
130
+ "progress": {
131
+ "preparing": "Anfrage wird vorbereitet",
132
+ "awaitingApproval": "Warten auf Freigabe",
133
+ "scanWithCommons": "Scannen Sie mit Commons auf Ihrem Telefon",
134
+ "continueInCommons": "In Commons fortfahren",
135
+ "checkCommons": "Prüfen Sie Commons auf Ihrem Telefon",
136
+ "openedInCommons": "In Commons geöffnet",
137
+ "confirming": "Identität wird bestätigt",
138
+ "confirmed": "Identität bestätigt"
139
+ }
128
140
  },
129
141
  "common": {
130
142
  "actions": {