@bounded-sh/client 0.0.111 → 0.0.112-ux-audit.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 (67) hide show
  1. package/dist/auth/index.d.ts +3 -1
  2. package/dist/auth/oidc-auth.d.ts +2 -0
  3. package/dist/auth/providers/email-auth-provider.d.ts +1 -1
  4. package/dist/auth/providers/guest-auth-provider.d.ts +1 -1
  5. package/dist/auth/providers/injected-evm-wallet-provider.d.ts +1 -1
  6. package/dist/auth/providers/injected-wallet-provider.d.ts +1 -1
  7. package/dist/auth/providers/offchain-auth-provider.d.ts +1 -1
  8. package/dist/auth/providers/privy-expo-provider.d.ts +1 -1
  9. package/dist/{email-auth-provider-CVp6hSCo.mjs → email-auth-provider-BfCH7K6N.mjs} +4 -3
  10. package/dist/email-auth-provider-BfCH7K6N.mjs.map +1 -0
  11. package/dist/{email-auth-provider-DxS2WYxM.js → email-auth-provider-CG5cxOj0.js} +4 -3
  12. package/dist/email-auth-provider-CG5cxOj0.js.map +1 -0
  13. package/dist/{email-auth-provider-CiqhQ1c2.js → email-auth-provider-DTrCfOJd.js} +4 -3
  14. package/dist/email-auth-provider-DTrCfOJd.js.map +1 -0
  15. package/dist/{email-auth-provider-BfBvF_4M.mjs → email-auth-provider-eyi3Wpnx.mjs} +4 -3
  16. package/dist/email-auth-provider-eyi3Wpnx.mjs.map +1 -0
  17. package/dist/{guest-auth-provider-Bm_yqQF6.mjs → guest-auth-provider-BsW56oJg.mjs} +10 -5
  18. package/dist/guest-auth-provider-BsW56oJg.mjs.map +1 -0
  19. package/dist/{guest-auth-provider-Cc8y4Qd1.mjs → guest-auth-provider-DjOFjtnk.mjs} +10 -5
  20. package/dist/guest-auth-provider-DjOFjtnk.mjs.map +1 -0
  21. package/dist/{guest-auth-provider-DDBXeHoo.js → guest-auth-provider-Dtl1J-2F.js} +10 -5
  22. package/dist/guest-auth-provider-Dtl1J-2F.js.map +1 -0
  23. package/dist/{guest-auth-provider-D9FGNuP9.js → guest-auth-provider-Tndt6tzJ.js} +10 -5
  24. package/dist/guest-auth-provider-Tndt6tzJ.js.map +1 -0
  25. package/dist/{index-BghQ8jX0.js → index-Brdwqgqs.js} +213 -60
  26. package/dist/index-Brdwqgqs.js.map +1 -0
  27. package/dist/{index-B9__gwTi.mjs → index-CRxls8Qc.mjs} +214 -61
  28. package/dist/index-CRxls8Qc.mjs.map +1 -0
  29. package/dist/index.js +1 -1
  30. package/dist/index.mjs +1 -1
  31. package/dist/{index.native-BHjpXkKQ.mjs → index.native-CAH_ks0s.mjs} +200 -56
  32. package/dist/index.native-CAH_ks0s.mjs.map +1 -0
  33. package/dist/{index.native-B_AFa0GD.js → index.native-ingNhWPw.js} +199 -55
  34. package/dist/index.native-ingNhWPw.js.map +1 -0
  35. package/dist/index.native.js +1 -1
  36. package/dist/index.native.mjs +1 -1
  37. package/dist/{injected-evm-wallet-provider-CIeCSOPL.mjs → injected-evm-wallet-provider-BjkCeRBL.mjs} +4 -3
  38. package/dist/injected-evm-wallet-provider-BjkCeRBL.mjs.map +1 -0
  39. package/dist/{injected-evm-wallet-provider-DeLUwvGs.js → injected-evm-wallet-provider-Cao1U0NZ.js} +4 -3
  40. package/dist/{injected-evm-wallet-provider-DeLUwvGs.js.map → injected-evm-wallet-provider-Cao1U0NZ.js.map} +1 -1
  41. package/dist/{injected-evm-wallet-provider-Ckb85p6a.js → injected-evm-wallet-provider-CwOGXCDt.js} +4 -3
  42. package/dist/injected-evm-wallet-provider-CwOGXCDt.js.map +1 -0
  43. package/dist/{injected-evm-wallet-provider-BUjqxQxp.mjs → injected-evm-wallet-provider-DXjwPjLW.mjs} +4 -3
  44. package/dist/{injected-evm-wallet-provider-BUjqxQxp.mjs.map → injected-evm-wallet-provider-DXjwPjLW.mjs.map} +1 -1
  45. package/dist/{injected-wallet-provider-BlzA0J_V.mjs → injected-wallet-provider-BG6gGNch.mjs} +4 -3
  46. package/dist/{injected-wallet-provider-BlzA0J_V.mjs.map → injected-wallet-provider-BG6gGNch.mjs.map} +1 -1
  47. package/dist/{injected-wallet-provider-BEuj4sM3.mjs → injected-wallet-provider-CfYNIIHd.mjs} +4 -3
  48. package/dist/{injected-wallet-provider-BEuj4sM3.mjs.map → injected-wallet-provider-CfYNIIHd.mjs.map} +1 -1
  49. package/dist/{injected-wallet-provider-CUKdAuFu.js → injected-wallet-provider-DSlHfgMU.js} +4 -3
  50. package/dist/{injected-wallet-provider-CUKdAuFu.js.map → injected-wallet-provider-DSlHfgMU.js.map} +1 -1
  51. package/dist/{injected-wallet-provider-Cfb4ayCP.js → injected-wallet-provider-LTnqoaYD.js} +4 -3
  52. package/dist/{injected-wallet-provider-Cfb4ayCP.js.map → injected-wallet-provider-LTnqoaYD.js.map} +1 -1
  53. package/package.json +2 -2
  54. package/dist/email-auth-provider-BfBvF_4M.mjs.map +0 -1
  55. package/dist/email-auth-provider-CVp6hSCo.mjs.map +0 -1
  56. package/dist/email-auth-provider-CiqhQ1c2.js.map +0 -1
  57. package/dist/email-auth-provider-DxS2WYxM.js.map +0 -1
  58. package/dist/guest-auth-provider-Bm_yqQF6.mjs.map +0 -1
  59. package/dist/guest-auth-provider-Cc8y4Qd1.mjs.map +0 -1
  60. package/dist/guest-auth-provider-D9FGNuP9.js.map +0 -1
  61. package/dist/guest-auth-provider-DDBXeHoo.js.map +0 -1
  62. package/dist/index-B9__gwTi.mjs.map +0 -1
  63. package/dist/index-BghQ8jX0.js.map +0 -1
  64. package/dist/index.native-BHjpXkKQ.mjs.map +0 -1
  65. package/dist/index.native-B_AFa0GD.js.map +0 -1
  66. package/dist/injected-evm-wallet-provider-CIeCSOPL.mjs.map +0 -1
  67. package/dist/injected-evm-wallet-provider-Ckb85p6a.js.map +0 -1
@@ -1,4 +1,4 @@
1
- import { getConfig, getActiveSessionManager, WebSessionManager, ReactNativeSessionManager, revokeSession, reconnectWithNewAuth, init as init$2, deriveUserIdentityFromIdToken, onSessionCleared, subscribe, getFreshAuthToken, getSessionGeneration, getIdToken as getIdToken$1, genAuthNonce, genSolanaMessage, createSessionWithSignature } from '@bounded-sh/core';
1
+ import { getConfig, getActiveSessionManager, WebSessionManager, ReactNativeSessionManager, revokeSession, reconnectWithNewAuth, deriveUserIdentityFromIdToken, init as init$2, onSessionCleared, subscribe, getFreshAuthToken, getSessionGeneration, getIdToken as getIdToken$1, genAuthNonce, genSolanaMessage, createSessionWithSignature } from '@bounded-sh/core';
2
2
  import * as React from 'react';
3
3
 
4
4
  function walletContextFromClaims(claims, baseUrl, expectedAppId, tenantOrigin) {
@@ -256,8 +256,9 @@ class OffchainAuthProvider {
256
256
  async logout() {
257
257
  await this.wrappedProvider.logout();
258
258
  }
259
- async restoreSession() {
260
- const user = await this.wrappedProvider.restoreSession();
259
+ async restoreSession(beforeCommit) {
260
+ const provider = this.wrappedProvider;
261
+ const user = await provider.restoreSession(beforeCommit);
261
262
  if (user) {
262
263
  return Object.assign(Object.assign({}, user), { provider: this });
263
264
  }
@@ -5511,7 +5512,8 @@ async function loginWithRedirect(opts) {
5511
5512
  return runNativeLogin(opts);
5512
5513
  if (!hasDOM$2())
5513
5514
  throw new Error('loginWithRedirect requires a browser or a configured React Native platform');
5514
- const { url, pkce } = await buildAuthorize(opts);
5515
+ const { url, pkce } = await untilAborted(buildAuthorize(opts), opts.signal);
5516
+ throwIfCancelled(opts.signal);
5515
5517
  // Stash the verifier + state so the redirect_uri page can finish the exchange. sessionStorage
5516
5518
  // is per-tab and cleared on close — appropriate for a short-lived auth handshake. Keyed by
5517
5519
  // this attempt's own state so a second concurrent login cannot overwrite it.
@@ -5540,9 +5542,29 @@ async function completeLoginFromRedirect() {
5540
5542
  throw error;
5541
5543
  return result.user;
5542
5544
  }
5545
+ function throwIfCancelled(signal) {
5546
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted)
5547
+ throw new Error('cancelled');
5548
+ }
5549
+ async function untilAborted(work, signal) {
5550
+ if (!signal)
5551
+ return work;
5552
+ throwIfCancelled(signal);
5553
+ let onAbort;
5554
+ try {
5555
+ return await Promise.race([work, new Promise((_, reject) => {
5556
+ onAbort = () => reject(new Error('cancelled'));
5557
+ signal.addEventListener('abort', onAbort, { once: true });
5558
+ })]);
5559
+ }
5560
+ finally {
5561
+ signal.removeEventListener('abort', onAbort);
5562
+ }
5563
+ }
5543
5564
  /** Popup variant: open the hosted login in a popup; resolves with the User once the popup's
5544
5565
  * redirect_uri page initializes the SDK, which hands the code back automatically. */
5545
5566
  async function loginWithPopup(opts) {
5567
+ throwIfCancelled(opts.signal);
5546
5568
  if (!hasDOM$2())
5547
5569
  throw new Error('loginWithPopup is web-only — on React Native use loginWithRedirect()');
5548
5570
  // Open synchronously, before PKCE/config awaits consume the click's user-
@@ -5560,7 +5582,7 @@ async function loginWithPopup(opts) {
5560
5582
  throw new Error('Popup blocked — use loginWithRedirect() instead');
5561
5583
  let authorization;
5562
5584
  try {
5563
- authorization = await buildAuthorize(opts, 'popup');
5585
+ authorization = await untilAborted(buildAuthorize(opts, 'popup'), opts.signal);
5564
5586
  }
5565
5587
  catch (error) {
5566
5588
  try {
@@ -5577,6 +5599,7 @@ async function loginWithPopup(opts) {
5577
5599
  // window with no listener or watchdog attached.
5578
5600
  let expectedOrigin;
5579
5601
  try {
5602
+ throwIfCancelled(opts.signal);
5580
5603
  expectedOrigin = new URL(pkce.redirectUri).origin;
5581
5604
  sessionStorage.setItem(pkceKey(pkce.state), JSON.stringify(pkce));
5582
5605
  }
@@ -5608,20 +5631,42 @@ async function loginWithPopup(opts) {
5608
5631
  setAuthLoading(true); // reflect "signing in…" while the popup is open
5609
5632
  try {
5610
5633
  return await new Promise((resolve, reject) => {
5634
+ var _a, _b;
5611
5635
  let settled = false;
5636
+ let handedOff = false;
5637
+ let committing = false;
5612
5638
  let timer;
5613
5639
  let navigationTimer;
5614
5640
  let completionTimer;
5615
5641
  const cleanup = () => {
5616
- settled = true;
5617
5642
  clearInterval(timer);
5618
5643
  clearTimeout(navigationTimer);
5619
5644
  clearTimeout(completionTimer);
5620
5645
  window.removeEventListener('message', onMsg);
5621
5646
  removeAttempt(pkce.state);
5622
5647
  };
5648
+ const finish = (error, user) => {
5649
+ var _a;
5650
+ if (settled)
5651
+ return;
5652
+ settled = true;
5653
+ cleanup();
5654
+ (_a = opts.signal) === null || _a === void 0 ? void 0 : _a.removeEventListener('abort', onAbort);
5655
+ try {
5656
+ popup.close();
5657
+ }
5658
+ catch ( /* ignore */_b) { /* ignore */ }
5659
+ if (error)
5660
+ reject(error);
5661
+ else
5662
+ resolve(user);
5663
+ };
5664
+ // Provider adoption commits synchronously after its final guard. An auth
5665
+ // listener dismissing the card there cannot cancel an already signed-in user.
5666
+ const onAbort = () => { if (!committing)
5667
+ finish(new Error('cancelled')); };
5623
5668
  const onMsg = async (ev) => {
5624
- if (settled || ev.origin !== expectedOrigin || ev.source !== popup)
5669
+ if (settled || handedOff || ev.origin !== expectedOrigin || ev.source !== popup)
5625
5670
  return;
5626
5671
  const d = ev.data;
5627
5672
  if (!d || d.type !== 'bounded-oidc-code' ||
@@ -5635,35 +5680,30 @@ async function loginWithPopup(opts) {
5635
5680
  return;
5636
5681
  if (d.appId !== pkce.appId || d.issuer !== pkce.issuer)
5637
5682
  return;
5683
+ handedOff = true;
5638
5684
  cleanup();
5639
5685
  try {
5686
+ throwIfCancelled(opts.signal);
5640
5687
  await validateAttempt(pkce, new URL(d.callbackUrl));
5688
+ throwIfCancelled(opts.signal);
5641
5689
  popup.postMessage({ type: 'bounded-oidc-accepted', state: pkce.state }, expectedOrigin);
5642
5690
  if (d.error)
5643
5691
  throw new Error(typeof d.errorDescription === 'string' ? d.errorDescription : `Login failed: ${d.error}`);
5644
- const user = await exchangeCode(d.code, pkce);
5645
- try {
5646
- popup.close();
5647
- }
5648
- catch ( /* ignore */_a) { /* ignore */ }
5649
- resolve(user);
5692
+ const user = await exchangeCode(d.code, pkce, opts.signal, () => { committing = true; });
5693
+ finish(undefined, user);
5650
5694
  }
5651
5695
  catch (e) {
5652
- try {
5653
- popup.close();
5654
- }
5655
- catch ( /* ignore */_b) { /* ignore */ }
5656
- reject(e);
5696
+ finish(e);
5657
5697
  }
5658
5698
  };
5699
+ (_a = opts.signal) === null || _a === void 0 ? void 0 : _a.addEventListener('abort', onAbort, { once: true });
5700
+ if ((_b = opts.signal) === null || _b === void 0 ? void 0 : _b.aborted) {
5701
+ onAbort();
5702
+ return;
5703
+ }
5659
5704
  window.addEventListener('message', onMsg);
5660
5705
  completionTimer = setTimeout(() => {
5661
- cleanup();
5662
- try {
5663
- popup.close();
5664
- }
5665
- catch ( /* ignore */_a) { /* ignore */ }
5666
- reject(new Error('Login expired or its popup disconnected. Start sign-in again.'));
5706
+ finish(new Error('Login expired or its popup disconnected. Start sign-in again.'));
5667
5707
  }, LOGIN_TIMEOUT_MS);
5668
5708
  // Some browser/extension combinations can return a real popup handle but
5669
5709
  // strand the window at about:blank instead of navigating to the hosted
@@ -5684,23 +5724,18 @@ async function loginWithPopup(opts) {
5684
5724
  const NAVIGATION_RECHECK_MS = 2000;
5685
5725
  const navigationStartedAt = Date.now();
5686
5726
  const checkNavigation = () => {
5687
- if (settled || popup.closed)
5727
+ if (settled || handedOff || popup.closed)
5688
5728
  return;
5689
5729
  try {
5690
5730
  if (popup.location.href === 'about:blank') {
5691
5731
  if (Date.now() - navigationStartedAt >= NAVIGATION_GRACE_MS) {
5692
- cleanup();
5693
- try {
5694
- popup.close();
5695
- }
5696
- catch ( /* ignore */_a) { /* ignore */ }
5697
- reject(new Error('Popup stalled at about:blank - use loginWithRedirect() instead'));
5732
+ finish(new Error('Popup stalled at about:blank - use loginWithRedirect() instead'));
5698
5733
  return;
5699
5734
  }
5700
5735
  navigationTimer = setTimeout(checkNavigation, NAVIGATION_RECHECK_MS);
5701
5736
  }
5702
5737
  }
5703
- catch ( /* cross-origin hosted auth loaded normally */_b) { /* cross-origin hosted auth loaded normally */ }
5738
+ catch ( /* cross-origin hosted auth loaded normally */_a) { /* cross-origin hosted auth loaded normally */ }
5704
5739
  };
5705
5740
  navigationTimer = setTimeout(checkNavigation, NAVIGATION_RECHECK_MS);
5706
5741
  // The popup posts its code and then closes ITSELF, so a naive "popup.closed -> reject"
@@ -5710,10 +5745,8 @@ async function loginWithPopup(opts) {
5710
5745
  timer = setInterval(() => {
5711
5746
  if (popup.closed) {
5712
5747
  clearInterval(timer);
5713
- setTimeout(() => { if (!settled) {
5714
- cleanup();
5715
- reject(new Error('Login window closed'));
5716
- } }, 500);
5748
+ setTimeout(() => { if (!settled && !handedOff)
5749
+ finish(new Error('Login window closed')); }, 500);
5717
5750
  }
5718
5751
  }, 500);
5719
5752
  });
@@ -5764,9 +5797,10 @@ async function inlineAuthEndpoint() {
5764
5797
  const cfg = await getConfig();
5765
5798
  return { base: await issuerBase(), appId: cfg.appId };
5766
5799
  }
5767
- async function exchangeCode(code, pkce) {
5800
+ async function exchangeCode(code, pkce, signal, onCommitting) {
5768
5801
  const generation = getInitializationGeneration();
5769
5802
  const beforeCommit = () => {
5803
+ throwIfCancelled(signal);
5770
5804
  if (generation !== getInitializationGeneration())
5771
5805
  throw new Error('Login was superseded by SDK reinitialization. Start sign-in again.');
5772
5806
  };
@@ -5782,7 +5816,7 @@ async function exchangeCode(code, pkce) {
5782
5816
  let res;
5783
5817
  try {
5784
5818
  res = await fetch(`${base}/api/auth/oauth2/token`, {
5785
- method: 'POST', headers: { 'content-type': 'application/x-www-form-urlencoded' }, body: body.toString(),
5819
+ method: 'POST', headers: { 'content-type': 'application/x-www-form-urlencoded' }, body: body.toString(), signal,
5786
5820
  });
5787
5821
  }
5788
5822
  catch (err) {
@@ -5808,7 +5842,7 @@ async function exchangeCode(code, pkce) {
5808
5842
  // Adopt on EVERY session surface (see establishInlineSession) - hosted
5809
5843
  // popup/redirect completions all land here, so this closes their gap too.
5810
5844
  try {
5811
- await adoptSessionProvider({ provider: oidcProviderSingleton, method: 'email', configKey: 'direct:oidc', user, beforeCommit });
5845
+ await adoptSessionProvider({ provider: oidcProviderSingleton, method: 'email', configKey: 'direct:oidc', user, beforeCommit: () => { beforeCommit(); onCommitting === null || onCommitting === void 0 ? void 0 : onCommitting(); } });
5812
5846
  }
5813
5847
  catch (error) {
5814
5848
  if (typeof rollback === 'function')
@@ -5877,6 +5911,31 @@ function idTokenIsGuest(idToken, expectedAddress) {
5877
5911
  function storedSessionIsGuest() {
5878
5912
  return idTokenIsGuest(getStoredIdToken());
5879
5913
  }
5914
+ /** Internal: select a cross-tab restore from bearer claims, never global hints. */
5915
+ function storedSessionAuthMethod(config) {
5916
+ try {
5917
+ const token = getStoredIdToken();
5918
+ if (!token)
5919
+ return null;
5920
+ let payload = token.split('.')[1].replace(/-/g, '+').replace(/_/g, '/');
5921
+ payload += '='.repeat((4 - payload.length % 4) % 4);
5922
+ const claims = JSON.parse(getPlatform().atob(payload));
5923
+ const method = claims.is_anonymous === true ? 'guest'
5924
+ : claims['custom:walletProvider'] === 'turnkey' || claims.email ? 'email'
5925
+ : claims['custom:evmWalletAddress'] ? 'evm-wallet'
5926
+ : claims['custom:walletAddress'] ? 'phantom' : 'email';
5927
+ if (config.authMethod != null && canonicalWalletAuthMethod(config.authMethod) !== method)
5928
+ return null;
5929
+ if (method === 'evm-wallet' && config.authMethod !== 'evm-wallet')
5930
+ return null;
5931
+ if (method === 'phantom' && (isWalletLoginDisabled(config) || isEmailRequired(config)))
5932
+ return null;
5933
+ return method;
5934
+ }
5935
+ catch (_a) {
5936
+ return null;
5937
+ }
5938
+ }
5880
5939
  /**
5881
5940
  * Pick the provider used for an ordinary `init({ appId })` restore.
5882
5941
  *
@@ -6138,9 +6197,10 @@ function optionalProviderError(method) {
6138
6197
  `loginWithRedirect(...) for Bounded Auth, signInAnonymously() for guests, ` +
6139
6198
  `or install/import an explicit wallet-provider entry once your app opts into "${method}".`);
6140
6199
  }
6141
- async function getAuthProvider(config) {
6200
+ async function getAuthProvider(config, fromStorage = false) {
6142
6201
  var _a;
6143
- const nextProviderConfigKey = config ? authProviderConfigKey(config) : null;
6202
+ const requestedAuthMethod = config ? (fromStorage ? storedSessionAuthMethod(config) : authMethodForInit(config)) : null;
6203
+ const nextProviderConfigKey = config ? authProviderConfigKey(Object.assign(Object.assign({}, config), { authMethod: requestedAuthMethod })) : null;
6144
6204
  if (currentAuthProvider && (!config || currentAuthProviderConfigKey === nextProviderConfigKey)) {
6145
6205
  return currentAuthProvider;
6146
6206
  }
@@ -6155,7 +6215,8 @@ async function getAuthProvider(config) {
6155
6215
  initConfig = config;
6156
6216
  // Keep what the app actually wrote for error text; everything else runs on
6157
6217
  // the canonical method so exactly one string reaches storage and the issuer.
6158
- const requestedAuthMethod = authMethodForInit(config);
6218
+ if (!requestedAuthMethod)
6219
+ throw new Error('The stored session is incompatible with this app authentication configuration.');
6159
6220
  const authMethod = canonicalWalletAuthMethod(requestedAuthMethod);
6160
6221
  const rpcUrl = normalizeSolanaRpcUrl(config.rpcUrl);
6161
6222
  const configuredNetwork = getConfiguredSolanaNetwork(config);
@@ -6180,7 +6241,7 @@ async function getAuthProvider(config) {
6180
6241
  // manager as legacy email sessions. Human login should be started
6181
6242
  // with loginWithRedirect(); this provider is kept as the restore and
6182
6243
  // logout surface for those sessions.
6183
- currentAuthProvider = new (await import('./email-auth-provider-BfBvF_4M.mjs')).EmailAuthProvider();
6244
+ currentAuthProvider = new (await import('./email-auth-provider-eyi3Wpnx.mjs')).EmailAuthProvider();
6184
6245
  break;
6185
6246
  case "phantom": {
6186
6247
  // First-class Solana WALLET LOGIN (the poof/TaroBase-style "connect
@@ -6222,7 +6283,7 @@ async function getAuthProvider(config) {
6222
6283
  // (bounded-login-widget.ts), so registration never counts as
6223
6284
  // evidence the user has a wallet.
6224
6285
  await ensureSolanaMobileWalletRegistered(config, configuredNetwork);
6225
- const { InjectedWalletProvider } = await import('./injected-wallet-provider-BlzA0J_V.mjs');
6286
+ const { InjectedWalletProvider } = await import('./injected-wallet-provider-BG6gGNch.mjs');
6226
6287
  currentAuthProvider = new InjectedWalletProvider(resolveInjectedWalletConfig(config), rpcUrl, configuredNetwork);
6227
6288
  break;
6228
6289
  }
@@ -6235,7 +6296,7 @@ async function getAuthProvider(config) {
6235
6296
  // Selecting authMethod:'evm-wallet' IS the opt-in — pass evmWalletConfig
6236
6297
  // to point at a specific wallet or set chainId/domain.
6237
6298
  const evmWalletConfig = ((_a = config.evmWalletConfig) !== null && _a !== void 0 ? _a : {});
6238
- const { InjectedEvmWalletProvider } = await import('./injected-evm-wallet-provider-CIeCSOPL.mjs');
6299
+ const { InjectedEvmWalletProvider } = await import('./injected-evm-wallet-provider-BjkCeRBL.mjs');
6239
6300
  currentAuthProvider = new InjectedEvmWalletProvider(evmWalletConfig);
6240
6301
  break;
6241
6302
  }
@@ -6260,7 +6321,7 @@ async function getAuthProvider(config) {
6260
6321
  break;
6261
6322
  case "guest":
6262
6323
  // Anonymous auth: a device-local ed25519 keypair signs the challenge.
6263
- currentAuthProvider = new (await import('./guest-auth-provider-Bm_yqQF6.mjs')).GuestAuthProvider();
6324
+ currentAuthProvider = new (await import('./guest-auth-provider-BsW56oJg.mjs')).GuestAuthProvider();
6264
6325
  break;
6265
6326
  }
6266
6327
  if (!currentAuthProvider) {
@@ -6322,7 +6383,7 @@ async function signInAnonymously() {
6322
6383
  // Lazy-load the guest provider so its ed25519/web3 dependencies stay out of
6323
6384
  // the main bundle for data-only apps. Specifier is a static string literal
6324
6385
  // so bundle-splitting can see it.
6325
- const provider = new (await import('./guest-auth-provider-Bm_yqQF6.mjs')).GuestAuthProvider();
6386
+ const provider = new (await import('./guest-auth-provider-BsW56oJg.mjs')).GuestAuthProvider();
6326
6387
  setAuthLoading(true); // reflect "signing in…" while the guest keypair session is minted
6327
6388
  // adoptSessionProvider awaits only getConfig() (already resolved here) and then
6328
6389
  // runs every write - provider/method/config/marker/user - in one synchronous
@@ -6493,7 +6554,7 @@ function ensureSharedWalletLoginReady() {
6493
6554
  if (!sharedWalletReady) {
6494
6555
  sharedWalletReady = (async () => {
6495
6556
  await getConfig();
6496
- await import('./injected-wallet-provider-BlzA0J_V.mjs');
6557
+ await import('./injected-wallet-provider-BG6gGNch.mjs');
6497
6558
  })().catch((error) => {
6498
6559
  sharedWalletReady = null;
6499
6560
  throw error;
@@ -6596,7 +6657,7 @@ async function loginWithWallet(options) {
6596
6657
  await ensureSharedWalletLoginReady();
6597
6658
  else
6598
6659
  await ensureWalletLoginReady();
6599
- const { InjectedWalletProvider } = await import('./injected-wallet-provider-BlzA0J_V.mjs');
6660
+ const { InjectedWalletProvider } = await import('./injected-wallet-provider-BG6gGNch.mjs');
6600
6661
  // Keep the RAW wallet provider: the offchain wrapper forwards only a fixed
6601
6662
  // set of methods, so cleanup below must speak to the provider that actually
6602
6663
  // holds the config rather than to whatever is wrapping it.
@@ -6868,7 +6929,8 @@ var index = /*#__PURE__*/Object.freeze({
6868
6929
  logout: logout$1,
6869
6930
  preloadWalletLogin: preloadWalletLogin,
6870
6931
  resolveAuthMode: resolveAuthMode,
6871
- signInAnonymously: signInAnonymously
6932
+ signInAnonymously: signInAnonymously,
6933
+ storedSessionAuthMethod: storedSessionAuthMethod
6872
6934
  });
6873
6935
 
6874
6936
  /**
@@ -6946,12 +7008,80 @@ let isAuthLoading = false;
6946
7008
  let authReadyPromise = null;
6947
7009
  let initializingConfig = null;
6948
7010
  let initializationGeneration = 0;
7011
+ let initializedConfig = null;
7012
+ let storageBridgeRegistered = false;
7013
+ let observedIdToken = null;
7014
+ let observedIssuer = null;
7015
+ // Storage events carry no authority. Re-read the active manager's app/issuer
7016
+ // namespace, then use the ordinary initializer/provider restore and listeners.
7017
+ function registerStorageBridge() {
7018
+ if (storageBridgeRegistered || !getPlatform().hasDOM || typeof window === 'undefined')
7019
+ return;
7020
+ storageBridgeRegistered = true;
7021
+ window.addEventListener('storage', (event) => {
7022
+ if (event.storageArea !== window.localStorage || !initializedConfig)
7023
+ return;
7024
+ void syncStoredSession().catch((error) => console.warn('Bounded session synchronization failed:', error));
7025
+ });
7026
+ }
7027
+ async function syncStoredSession() {
7028
+ const config = initializedConfig;
7029
+ if (!config)
7030
+ return;
7031
+ const token = WebSessionManager.getIdToken();
7032
+ const issuer = WebSessionManager.getIssuer();
7033
+ if (token === observedIdToken && issuer === observedIssuer)
7034
+ return;
7035
+ observedIdToken = token;
7036
+ observedIssuer = issuer;
7037
+ const generation = ++initializationGeneration;
7038
+ // Hide the former principal while the replacement is validated. This also
7039
+ // reconnects live reads through the existing auth-state change path.
7040
+ setCurrentUser(null);
7041
+ if (authReadyPromise)
7042
+ await authReadyPromise.catch(() => { });
7043
+ if (generation !== initializationGeneration || config !== initializedConfig)
7044
+ return;
7045
+ const record = await WebSessionManager.readSessionWithGeneration();
7046
+ if (generation !== initializationGeneration || config !== initializedConfig)
7047
+ return;
7048
+ if (!record)
7049
+ return;
7050
+ const normalize = (url) => (url || '').replace(/\/+$/, '');
7051
+ const resolvedConfig = await getConfig();
7052
+ if (generation !== initializationGeneration || config !== initializedConfig)
7053
+ return;
7054
+ const allowedIssuers = [normalize(resolvedConfig.humanAuthApiUrl || 'https://auth.bounded.sh'), normalize(resolvedConfig.authApiUrl)].filter(Boolean);
7055
+ // A legacy shared blob can belong to another app. Never restore or clear
7056
+ // that app's credential; the current app remains signed out.
7057
+ if ((record.appId && record.appId !== config.appId)
7058
+ || (record.issuer && !allowedIssuers.includes(normalize(record.issuer))))
7059
+ return;
7060
+ if (!storedSessionAuthMethod(config))
7061
+ return;
7062
+ const restored = startInitialization(config, true);
7063
+ const restoreGeneration = initializationGeneration;
7064
+ try {
7065
+ await restored;
7066
+ }
7067
+ catch (error) {
7068
+ if (restoreGeneration === initializationGeneration && WebSessionManager.getIdToken())
7069
+ throw error;
7070
+ }
7071
+ }
6949
7072
  /** Internal guard for a login result arriving after the app reconfigured the SDK. */
6950
7073
  function getInitializationGeneration() { return initializationGeneration; }
6951
7074
  // This file acts as a middleware for the global state of the SDK
6952
7075
  // This mostly involves setting up the AuthProvider and managing the current user
6953
- async function initialize(requestedConfig) {
7076
+ async function initialize(requestedConfig, fromStorage) {
6954
7077
  const newConfig = withDefaultSolanaRpcUrl(requestedConfig);
7078
+ const generation = initializationGeneration;
7079
+ const validateStorage = fromStorage ? WebSessionManager.captureSessionEstablishment() : undefined;
7080
+ const beforeCommit = () => {
7081
+ if (generation !== initializationGeneration)
7082
+ throw new Error('Session restore was superseded.');
7083
+ validateStorage === null || validateStorage === void 0 ? void 0 : validateStorage();
7084
+ };
6955
7085
  // Mark auth as loading for the ENTIRE init/restore window so consumers render
6956
7086
  // a neutral/loading state instead of the signed-out UI while we rehydrate the
6957
7087
  // session — otherwise getCurrentUser() is null + loading is false during the
@@ -6970,8 +7100,9 @@ async function initialize(requestedConfig) {
6970
7100
  // onAuthStateChanged never fired, and every consumer UI went on showing a
6971
7101
  // connected wallet for a session the server no longer knew about.
6972
7102
  registerSessionClearedBridge();
7103
+ registerStorageBridge();
6973
7104
  // Get auth provider first
6974
- authProviderInstance = await getAuthProvider(newConfig);
7105
+ authProviderInstance = await getAuthProvider(newConfig, fromStorage);
6975
7106
  // Initialize config with auth provider
6976
7107
  await init$2(Object.assign(Object.assign({}, newConfig), { authProvider: authProviderInstance }));
6977
7108
  // A return establishes its own provider/session, or hands off a popup.
@@ -6996,7 +7127,8 @@ async function initialize(requestedConfig) {
6996
7127
  // Wait for restoreSession to complete
6997
7128
  // The appId check is done in SessionManager.getSession which is called by restoreSession
6998
7129
  // If there's an appId mismatch, the session will be cleared and restoreSession will return null
6999
- let user = await authProviderInstance.restoreSession();
7130
+ let user = await authProviderInstance.restoreSession(beforeCommit);
7131
+ beforeCommit();
7000
7132
  // If a session exists but was created before auth method tracking (legacy session),
7001
7133
  // clear it to avoid mismatches when the app switches auth methods (e.g. email → phantom)
7002
7134
  //
@@ -7004,9 +7136,10 @@ async function initialize(requestedConfig) {
7004
7136
  // unawaited call would return a Promise (always truthy) — nulling the user
7005
7137
  // unconditionally AND letting setCurrentUser run while the old credential
7006
7138
  // was still in storage.
7007
- if (user && await clearIncompatibleSession()) {
7139
+ if (user && !fromStorage && await clearIncompatibleSession()) {
7008
7140
  user = null;
7009
7141
  }
7142
+ beforeCommit();
7010
7143
  setCurrentUser(user);
7011
7144
  // Mark init as completed
7012
7145
  initCompleted = true;
@@ -7046,13 +7179,17 @@ function sameConfigValue(a, b, seen = new WeakMap()) {
7046
7179
  && sameConfigValue(a[key], b[key], seen));
7047
7180
  }
7048
7181
  function init$1(newConfig) {
7182
+ return startInitialization(newConfig, false);
7183
+ }
7184
+ function startInitialization(newConfig, fromStorage) {
7049
7185
  if (initializingConfig) {
7050
7186
  if (sameConfigValue(initializingConfig, newConfig)) {
7051
7187
  return authReadyPromise;
7052
7188
  }
7053
7189
  return Promise.reject(new Error('SDK initialization is in progress. Await init() before changing its configuration.'));
7054
7190
  }
7055
- initializingConfig = Object.assign({}, newConfig);
7191
+ initializedConfig = Object.assign({}, newConfig);
7192
+ initializingConfig = initializedConfig;
7056
7193
  initializationGeneration++;
7057
7194
  let resolveReady;
7058
7195
  let rejectReady;
@@ -7064,7 +7201,7 @@ function init$1(newConfig) {
7064
7201
  // auth-loading listener to call waitForAuthReady() synchronously when init()
7065
7202
  // announces that session restoration has begun.
7066
7203
  authReadyPromise = ready;
7067
- void initialize(initializingConfig).then(() => { initializingConfig = null; resolveReady(); }, (error) => { initializingConfig = null; rejectReady(error); });
7204
+ void initialize(initializingConfig, fromStorage).then(() => { initializingConfig = null; resolveReady(); }, (error) => { initializingConfig = null; rejectReady(error); });
7068
7205
  return ready;
7069
7206
  }
7070
7207
  /**
@@ -7137,6 +7274,13 @@ function userPrincipalKey(user) {
7137
7274
  }
7138
7275
  // Update the currentUser and notify listeners
7139
7276
  function setCurrentUser(user) {
7277
+ observedIdToken = getCurrentIdToken();
7278
+ try {
7279
+ observedIssuer = getActiveSessionManager().getIssuer();
7280
+ }
7281
+ catch (_a) {
7282
+ observedIssuer = null;
7283
+ }
7140
7284
  // Enrich with the universal identity fields (id/email) derived from the
7141
7285
  // active session's idToken — central chokepoint so every provider's user
7142
7286
  // object gains { id, address, email } without each construction site
@@ -8084,7 +8228,8 @@ async function prepareAndOpen(opts, pending) {
8084
8228
  return authApi.loginWithRedirect(options);
8085
8229
  // Invoke immediately inside the click handler to retain popup activation.
8086
8230
  return authApi.loginWithPopup(options).catch((error) => {
8087
- if (shouldFallbackToRedirect(error))
8231
+ var _a;
8232
+ if (!((_a = options.signal) === null || _a === void 0 ? void 0 : _a.aborted) && shouldFallbackToRedirect(error))
8088
8233
  return authApi.loginWithRedirect(options);
8089
8234
  throw error;
8090
8235
  });
@@ -8222,6 +8367,12 @@ async function prepareAndOpen(opts, pending) {
8222
8367
  let activeAttempt = 0;
8223
8368
  let abortScopedLogin = null;
8224
8369
  let abortGesture = null;
8370
+ const startHostedLogin = (options) => {
8371
+ const controller = new AbortController();
8372
+ const abort = () => controller.abort();
8373
+ abortScopedLogin = abort;
8374
+ return hostedLogin(Object.assign(Object.assign({}, options), { signal: controller.signal }));
8375
+ };
8225
8376
  /** Reject a gesture promise already waiting on a view that is going away. */
8226
8377
  const abortPendingGesture = () => {
8227
8378
  const abort = abortGesture;
@@ -8247,6 +8398,7 @@ async function prepareAndOpen(opts, pending) {
8247
8398
  if (!attemptIsCurrent(id))
8248
8399
  return false;
8249
8400
  activeAttempt = 0;
8401
+ abortScopedLogin = null;
8250
8402
  return true;
8251
8403
  };
8252
8404
  /** Take the card back (Back, a lane switch, settling the modal). Deliberately
@@ -8401,7 +8553,7 @@ async function prepareAndOpen(opts, pending) {
8401
8553
  loginHint: input.value,
8402
8554
  redirectUri: opts.redirectUri,
8403
8555
  };
8404
- hostedLogin(emailOpts)
8556
+ startHostedLogin(emailOpts)
8405
8557
  // A hosted login that RESOLVES minted a real session, so it settles
8406
8558
  // the card even if another lane has since taken it - dropping it
8407
8559
  // would leave the app signed in behind a widget that says it is not.
@@ -8451,7 +8603,7 @@ async function prepareAndOpen(opts, pending) {
8451
8603
  }
8452
8604
  setBusy(b, "Opening secure sign-in\u2026");
8453
8605
  const socialOpts = { provider: method, redirectUri: opts.redirectUri };
8454
- hostedLogin(socialOpts)
8606
+ startHostedLogin(socialOpts)
8455
8607
  .then((u) => {
8456
8608
  if (u) {
8457
8609
  settleAttempt(attempt);
@@ -10523,8 +10675,9 @@ class PrivyExpoProvider {
10523
10675
  const { signature } = await this.signAndSubmitInternal(transaction, wallet, connection);
10524
10676
  return signature;
10525
10677
  }
10526
- async restoreSession() {
10678
+ async restoreSession(beforeCommit) {
10527
10679
  const session = await getActiveSessionManager().getSession();
10680
+ beforeCommit === null || beforeCommit === void 0 ? void 0 : beforeCommit();
10528
10681
  if (session) {
10529
10682
  this.authenticatedAddress = session.address;
10530
10683
  return { provider: this, address: session.address };
@@ -11039,4 +11192,4 @@ function init(config = {}) {
11039
11192
  }
11040
11193
 
11041
11194
  export { onrampStatus as $, getAuthProvider as A, signInAnonymously as B, loginWithPrivy as C, loginWithWallet as D, ensureWalletLoginReady as E, ensureSharedWalletLoginReady as F, preloadWalletLogin as G, loginWithRedirect as H, completeLoginFromRedirect as I, getLoginReturnError as J, loginWithPopup as K, openBoundedWidget as L, ensureSignedIn as M, useAuth as N, useQuery as O, useBuildRun as P, apps as Q, signSolanaMessageViaTurnkey as R, getOrCreateTurnkeyWallet as S, openTurnkeyKeyExport as T, getTurnkeyWalletSessionState as U, getTurnkeyWalletRecoveryUrl as V, WalletConfigError as W, startTurnkeyEmailLogin as X, getIdToken as Y, onramp as Z, onrampQuote as _, signMessageWithTurnkey as a, setPlatform as a0, OffchainAuthProvider as a1, PrivyExpoProvider as a2, requestEip6963Providers as a3, connectBroadcast as a4, connectServiceSession as a5, builds as a6, BuildsApiError as a7, mediaAgentTools as a8, NON_TERMINAL_STATES as a9, TERMINAL_STATES as aa, RUN_STATES as ab, PARK_REASONS as ac, FAILURE_REASONS as ad, BUILD_REVIEW_CAPABILITY_SCHEMA as ae, BUILD_REVIEW_CAPABILITY_REFRESH_SCHEMA as af, BUILD_DELEGATED_REVIEW_CAPABILITY_SCHEMA as ag, signTransactionWithTurnkey as b, signTransactionV1WithTurnkey as c, signAndSubmitTransactionWithTurnkey as d, bs58 as e, defaultInjectedProvider as f, getPlatform as g, hasTurnkeyWallet as h, firstStandardWalletProvider as i, setAuthLoading as j, bufferExports as k, setStoredAuthMethod as l, confirmAndCheckTransaction as m, normalizeSolanaRpcUrl as n, defaultInjectedEvmProvider as o, init as p, getCurrentUser as q, resolveSolanaRpcUrl as r, setCurrentUser as s, transactionHasSignature as t, onAuthStateChanged as u, onAuthLoadingChanged as v, getAuthLoading as w, waitForAuthReady as x, login as y, logout as z };
11042
- //# sourceMappingURL=index-B9__gwTi.mjs.map
11195
+ //# sourceMappingURL=index-CRxls8Qc.mjs.map