@bounded-sh/client 0.0.55 → 0.0.57

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 (68) hide show
  1. package/REACT_NATIVE.md +31 -8
  2. package/dist/auth/bounded-login-widget.d.ts +25 -0
  3. package/dist/auth/bounded-widget-modal.d.ts +33 -0
  4. package/dist/auth/index.d.ts +42 -0
  5. package/dist/auth/oidc-auth.d.ts +18 -0
  6. package/dist/auth/providers/wallet-login-finalize.d.ts +17 -0
  7. package/dist/auth/providers/wallet-standard-discovery.d.ts +23 -0
  8. package/dist/auth/providers/wallet-standard-tx.d.ts +7 -0
  9. package/dist/auth/turnkey-auth.d.ts +17 -0
  10. package/dist/auth/turnkey-signer-bridge.d.ts +32 -0
  11. package/dist/auth/turnkey-wallet-widget.d.ts +17 -0
  12. package/dist/{email-auth-provider-BaZceaov.js → email-auth-provider-8k8iBIQL.js} +2 -2
  13. package/dist/{email-auth-provider-BaZceaov.js.map → email-auth-provider-8k8iBIQL.js.map} +1 -1
  14. package/dist/{email-auth-provider-lVwM8vRR.js → email-auth-provider-BlJI-8w9.js} +2 -2
  15. package/dist/{email-auth-provider-lVwM8vRR.js.map → email-auth-provider-BlJI-8w9.js.map} +1 -1
  16. package/dist/{email-auth-provider-yBbGzH2e.mjs → email-auth-provider-Bmah1GWS.mjs} +2 -2
  17. package/dist/{email-auth-provider-yBbGzH2e.mjs.map → email-auth-provider-Bmah1GWS.mjs.map} +1 -1
  18. package/dist/{email-auth-provider-BKl9GgHV.mjs → email-auth-provider-CfNSS8Du.mjs} +2 -2
  19. package/dist/{email-auth-provider-BKl9GgHV.mjs.map → email-auth-provider-CfNSS8Du.mjs.map} +1 -1
  20. package/dist/{guest-auth-provider-DhN9PoAi.js → guest-auth-provider-BRjJV8Zq.js} +2 -2
  21. package/dist/{guest-auth-provider-DhN9PoAi.js.map → guest-auth-provider-BRjJV8Zq.js.map} +1 -1
  22. package/dist/{guest-auth-provider-DTKczntw.js → guest-auth-provider-BjfjrpdW.js} +2 -2
  23. package/dist/{guest-auth-provider-DTKczntw.js.map → guest-auth-provider-BjfjrpdW.js.map} +1 -1
  24. package/dist/{guest-auth-provider-BnugW3TI.mjs → guest-auth-provider-D6h4eAtx.mjs} +2 -2
  25. package/dist/{guest-auth-provider-Dgs8zcnC.mjs.map → guest-auth-provider-D6h4eAtx.mjs.map} +1 -1
  26. package/dist/{guest-auth-provider-Dgs8zcnC.mjs → guest-auth-provider-DxhZ5sWN.mjs} +2 -2
  27. package/dist/{guest-auth-provider-BnugW3TI.mjs.map → guest-auth-provider-DxhZ5sWN.mjs.map} +1 -1
  28. package/dist/{index.native-aSo8M0A8.mjs → index-C7rOe6B2.mjs} +1745 -24
  29. package/dist/index-C7rOe6B2.mjs.map +1 -0
  30. package/dist/{index.native-CouprxZp.js → index-CnObYQhV.js} +1752 -22
  31. package/dist/index-CnObYQhV.js.map +1 -0
  32. package/dist/index.d.ts +7 -1
  33. package/dist/index.js +6 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/index.mjs +1 -1
  36. package/dist/{index-DkdIADby.mjs → index.native-CQiw9baS.mjs} +29 -94
  37. package/dist/index.native-CQiw9baS.mjs.map +1 -0
  38. package/dist/{index-CXVwyR6_.js → index.native-hu3o3zXU.js} +28 -96
  39. package/dist/index.native-hu3o3zXU.js.map +1 -0
  40. package/dist/index.native.d.ts +2 -0
  41. package/dist/index.native.js +2 -1
  42. package/dist/index.native.js.map +1 -1
  43. package/dist/index.native.mjs +1 -1
  44. package/dist/{injected-evm-wallet-provider-CtrS-gLC.js → injected-evm-wallet-provider-CcwS6p3o.js} +2 -2
  45. package/dist/{injected-evm-wallet-provider-CtrS-gLC.js.map → injected-evm-wallet-provider-CcwS6p3o.js.map} +1 -1
  46. package/dist/{injected-evm-wallet-provider-BgiFW_kf.mjs → injected-evm-wallet-provider-DCGnUedJ.mjs} +2 -2
  47. package/dist/{injected-evm-wallet-provider-BgiFW_kf.mjs.map → injected-evm-wallet-provider-DCGnUedJ.mjs.map} +1 -1
  48. package/dist/{injected-evm-wallet-provider-D7fd42En.mjs → injected-evm-wallet-provider-DIWeWiAN.mjs} +2 -2
  49. package/dist/{injected-evm-wallet-provider-D7fd42En.mjs.map → injected-evm-wallet-provider-DIWeWiAN.mjs.map} +1 -1
  50. package/dist/{injected-evm-wallet-provider-CiCeS1n2.js → injected-evm-wallet-provider-Xbt2CUPi.js} +2 -2
  51. package/dist/{injected-evm-wallet-provider-CiCeS1n2.js.map → injected-evm-wallet-provider-Xbt2CUPi.js.map} +1 -1
  52. package/dist/{injected-wallet-provider-CST-B9EE.js → injected-wallet-provider-7ep-jcal.js} +2 -2
  53. package/dist/{injected-wallet-provider-CST-B9EE.js.map → injected-wallet-provider-7ep-jcal.js.map} +1 -1
  54. package/dist/{injected-wallet-provider-Bic6GpDr.js → injected-wallet-provider-B_jQFifE.js} +2 -2
  55. package/dist/{injected-wallet-provider-Bic6GpDr.js.map → injected-wallet-provider-B_jQFifE.js.map} +1 -1
  56. package/dist/{injected-wallet-provider-CRG9TaA9.mjs → injected-wallet-provider-Bps6a9IP.mjs} +2 -2
  57. package/dist/{injected-wallet-provider-CRG9TaA9.mjs.map → injected-wallet-provider-Bps6a9IP.mjs.map} +1 -1
  58. package/dist/{injected-wallet-provider-BhpwmpgW.mjs → injected-wallet-provider-CFnqSsHy.mjs} +2 -2
  59. package/dist/{injected-wallet-provider-BhpwmpgW.mjs.map → injected-wallet-provider-CFnqSsHy.mjs.map} +1 -1
  60. package/dist/wallet-standard-tx-C1HJFLjC.js +30 -0
  61. package/dist/wallet-standard-tx-C1HJFLjC.js.map +1 -0
  62. package/dist/wallet-standard-tx-DBliTUWH.mjs +27 -0
  63. package/dist/wallet-standard-tx-DBliTUWH.mjs.map +1 -0
  64. package/package.json +9 -3
  65. package/dist/index-CXVwyR6_.js.map +0 -1
  66. package/dist/index-DkdIADby.mjs.map +0 -1
  67. package/dist/index.native-CouprxZp.js.map +0 -1
  68. package/dist/index.native-aSo8M0A8.mjs.map +0 -1
@@ -3475,7 +3475,7 @@ const EMBEDDED_WALLET_UNSUPPORTED = 'Unsupported for embedded smart wallets —
3475
3475
  const NO_EMBEDDED_WALLET = 'This login has no embedded wallet. Enable `"auth": { "wallets": true }` in ' +
3476
3476
  'the app policy so email logins get a non-custodial wallet (@user.address), ' +
3477
3477
  'then sign from a user gesture.';
3478
- function hasDOM$1() {
3478
+ function hasDOM$4() {
3479
3479
  return typeof window !== 'undefined' && typeof document !== 'undefined';
3480
3480
  }
3481
3481
  function decodeJwt$1(token) {
@@ -3524,7 +3524,7 @@ async function signerPageUrl() {
3524
3524
  const base = (cfg.humanAuthApiUrl || 'https://auth.bounded.sh').replace(/\/$/, '');
3525
3525
  return { url: `${base}/wallet/signer`, origin: new URL(base).origin };
3526
3526
  }
3527
- let requestSeq = 0;
3527
+ let requestSeq$1 = 0;
3528
3528
  /**
3529
3529
  * Open the Bounded signer popup, send `action` to it, and resolve with the
3530
3530
  * submitted transaction result. Must be called from a USER GESTURE (click/tap) or
@@ -3535,7 +3535,7 @@ let requestSeq = 0;
3535
3535
  * wallet's owner, and validates that the wallet address matches the account.
3536
3536
  */
3537
3537
  async function signViaSignerPopup(action) {
3538
- if (!hasDOM$1()) {
3538
+ if (!hasDOM$4()) {
3539
3539
  throw new Error('Embedded-wallet signing is only available in the browser (popup-based).');
3540
3540
  }
3541
3541
  const isEvm = action.kind === 'evmTransaction';
@@ -3543,7 +3543,7 @@ async function signViaSignerPopup(action) {
3543
3543
  if (!claims)
3544
3544
  throw new Error(NO_EMBEDDED_WALLET);
3545
3545
  const { url, origin: signerOrigin } = await signerPageUrl();
3546
- const requestId = `bsign_${Date.now()}_${++requestSeq}`;
3546
+ const requestId = `bsign_${Date.now()}_${++requestSeq$1}`;
3547
3547
  // Centered popup, sized for the OTP form (matches the OIDC login popup shape).
3548
3548
  const w = 420, h = 600;
3549
3549
  const left = window.screenX + Math.max(0, (window.outerWidth - w) / 2);
@@ -3711,7 +3711,7 @@ const STORED_AUTH_METHOD_KEY$1 = 'bounded_last_auth_method';
3711
3711
  // not by `typeof window` (truthy on RN). OIDC redirect/popup is web-only, but the
3712
3712
  // session it mints is read back through this same selector everywhere.
3713
3713
  const sessionManager = core.getActiveSessionManager;
3714
- function hasDOM() {
3714
+ function hasDOM$3() {
3715
3715
  return typeof window !== 'undefined' && typeof document !== 'undefined';
3716
3716
  }
3717
3717
  function decodeJwt(token) {
@@ -3830,6 +3830,11 @@ function appendHostedLoginHints(params, opts) {
3830
3830
  const provider = normalizeMethod(opts.provider);
3831
3831
  if (provider)
3832
3832
  params.set('bounded_provider', provider);
3833
+ // login_hint: an identifier (usually an email) to prefill on the hosted page.
3834
+ // Kept short and free of control chars; the hosted page validates before use.
3835
+ const hint = String(opts.loginHint || '').trim();
3836
+ if (hint && hint.length <= 320 && !/[\s<>"']/.test(hint))
3837
+ params.set('login_hint', hint);
3833
3838
  // Standard OIDC prompt (e.g. 'login' to force a fresh sign-in / account choice).
3834
3839
  const prompt = normalizeMethod(opts.prompt);
3835
3840
  if (prompt)
@@ -3846,7 +3851,7 @@ async function buildAuthorize(opts) {
3846
3851
  throw new Error('appId is not configured (init the SDK with your appId)');
3847
3852
  // Web: default to the current page so callers don't have to pass redirectUri. Native has no
3848
3853
  // window — it MUST pass an https universal link (the system auth session needs a real URL).
3849
- const redirectUri = opts.redirectUri || (hasDOM() ? window.location.origin + window.location.pathname : undefined);
3854
+ const redirectUri = opts.redirectUri || (hasDOM$3() ? window.location.origin + window.location.pathname : undefined);
3850
3855
  if (!redirectUri)
3851
3856
  throw new Error('redirectUri is required on React Native — pass the https universal link the app owner registered.');
3852
3857
  const { verifier, challenge } = await makePkce();
@@ -3954,7 +3959,7 @@ async function runNativeLogin(opts) {
3954
3959
  async function loginWithRedirect(opts) {
3955
3960
  if (isNative())
3956
3961
  return runNativeLogin(opts);
3957
- if (!hasDOM())
3962
+ if (!hasDOM$3())
3958
3963
  throw new Error('loginWithRedirect requires a browser or a configured React Native platform');
3959
3964
  const { url, pkce } = await buildAuthorize(opts);
3960
3965
  // Stash the verifier + state so the redirect_uri page can finish the exchange. sessionStorage
@@ -3970,7 +3975,7 @@ async function loginWithRedirect(opts) {
3970
3975
  * loginWithRedirect() (which resolves with the User), so there is no separate redirect
3971
3976
  * page to finish from. Calling it on RN is harmless. */
3972
3977
  async function completeLoginFromRedirect() {
3973
- if (!hasDOM())
3978
+ if (!hasDOM$3())
3974
3979
  return null;
3975
3980
  const url = new URL(window.location.href);
3976
3981
  const code = url.searchParams.get('code');
@@ -4016,7 +4021,7 @@ async function completeLoginFromRedirect() {
4016
4021
  * redirect_uri page posts the code back. The redirect_uri page just calls the usual
4017
4022
  * completeLoginFromRedirect() (which auto-detects the popup) — no separate call needed. */
4018
4023
  async function loginWithPopup(opts) {
4019
- if (!hasDOM())
4024
+ if (!hasDOM$3())
4020
4025
  throw new Error('loginWithPopup is web-only — on React Native use loginWithRedirect()');
4021
4026
  // Open synchronously, before PKCE/config awaits consume the click's user-
4022
4027
  // activation window. Opening only after buildAuthorize() intermittently
@@ -4156,7 +4161,7 @@ async function loginWithPopup(opts) {
4156
4161
  /** Call this on the redirect_uri page when login was opened via loginWithPopup(): posts the
4157
4162
  * code back to the opener and closes. (For the redirect variant use completeLoginFromRedirect.) */
4158
4163
  function completeLoginInPopup(openerOrigin) {
4159
- if (!hasDOM() || !window.opener)
4164
+ if (!hasDOM$3() || !window.opener)
4160
4165
  return;
4161
4166
  const url = new URL(window.location.href);
4162
4167
  const code = url.searchParams.get('code');
@@ -4172,6 +4177,34 @@ function completeLoginInPopup(openerOrigin) {
4172
4177
  }
4173
4178
  catch ( /* ignore */_b) { /* ignore */ }
4174
4179
  }
4180
+ // Establish a Bounded session from a server-minted inline-session response (the same
4181
+ // { idToken, accessToken, refreshToken } shape as /session/refresh). Used by the
4182
+ // Turnkey-native login path (authMode:"turnkey"), which mints the session server-side
4183
+ // after Turnkey verifies the email OTP - there is no OIDC code to exchange. Wiring is
4184
+ // identical to exchangeCode's tail so the realtime worker cannot tell them apart.
4185
+ async function establishInlineSession(data) {
4186
+ const base = await issuerBase();
4187
+ const idToken = tokenField(data, 'id_token', 'idToken');
4188
+ if (!idToken)
4189
+ throw new Error('No id_token in the inline session response');
4190
+ const accessToken = tokenField(data, 'access_token', 'accessToken') || idToken;
4191
+ const refreshToken = boundedRefreshTokenField(data);
4192
+ const user = userFromIdToken(idToken);
4193
+ await sessionManager().storeSession(String(user.address || ''), accessToken, idToken, refreshToken, base);
4194
+ try {
4195
+ getPlatform().storage.setItem(STORED_AUTH_METHOD_KEY$1, 'email');
4196
+ }
4197
+ catch ( /* storage unavailable */_a) { /* storage unavailable */ }
4198
+ setCurrentUser(user);
4199
+ setAuthProviderInstance(oidcProviderSingleton);
4200
+ return user;
4201
+ }
4202
+ // Auth base + appId for the Turnkey-native inline OTP endpoints, resolved through the
4203
+ // same config the OIDC flow uses.
4204
+ async function inlineAuthEndpoint() {
4205
+ const cfg = await core.getConfig();
4206
+ return { base: await issuerBase(), appId: cfg.appId };
4207
+ }
4175
4208
  async function exchangeCode(code, verifier, redirectUri) {
4176
4209
  const cfg = await core.getConfig();
4177
4210
  const base = await issuerBase();
@@ -4405,6 +4438,40 @@ function isWalletLoginEnabled(config) {
4405
4438
  return true;
4406
4439
  return false;
4407
4440
  }
4441
+ /**
4442
+ * Whether the app explicitly turned the "connect wallet" lane OFF at init()
4443
+ * (`walletLogin: false`). This is the hard opt-OUT the unified widget honors: it
4444
+ * hides the wallet option entirely even when an injected wallet is detected and
4445
+ * even if a per-call `openBoundedWidget({ wallet: true })` asked for it.
4446
+ */
4447
+ function isWalletLoginDisabled(config) {
4448
+ return config.walletLogin === false;
4449
+ }
4450
+ /**
4451
+ * Site policy: the app requires an email on file for every user (`requireEmail:
4452
+ * true`). Native wallet login carries no email, so the unified widget suppresses
4453
+ * the wallet lane when this is set - email/social (which yields an email) remain.
4454
+ * This lets a policy deny wallet-only accounts without touching per-call options.
4455
+ */
4456
+ function isEmailRequired(config) {
4457
+ return config.requireEmail === true;
4458
+ }
4459
+ /** The config passed to the last `init()`, or null before init. Read-only view
4460
+ * for runtime surfaces (e.g. the unified login widget) that need wallet/rpc
4461
+ * settings without re-plumbing them through every call. */
4462
+ function getInitConfig() {
4463
+ return initConfig;
4464
+ }
4465
+ /**
4466
+ * Which LOGIN mode the app runs (default "bounded"). "turnkey" opts the app into
4467
+ * Turnkey-native email OTP: the unified widget runs the code entry INLINE (no OIDC
4468
+ * popup) via startTurnkeyEmailLogin(), and Bounded mints the session from Turnkey's
4469
+ * verification. The value comes from init() config (`authMode`); a `openBoundedWidget`
4470
+ * option can override it per call. Anything other than "turnkey" is "bounded".
4471
+ */
4472
+ function resolveAuthMode(config) {
4473
+ return config.authMode === 'turnkey' ? 'turnkey' : 'bounded';
4474
+ }
4408
4475
  /**
4409
4476
  * Resolve the injected-wallet-config the provider should use, merging the
4410
4477
  * `walletLogin` object form (if the app passed one) over `injectedWalletConfig`.
@@ -4464,7 +4531,7 @@ async function getAuthProvider(config) {
4464
4531
  // manager as legacy email sessions. Human login should be started
4465
4532
  // with loginWithRedirect(); this provider is kept as the restore and
4466
4533
  // logout surface for those sessions.
4467
- currentAuthProvider = new (await Promise.resolve().then(function () { return require('./email-auth-provider-lVwM8vRR.js'); })).EmailAuthProvider();
4534
+ currentAuthProvider = new (await Promise.resolve().then(function () { return require('./email-auth-provider-8k8iBIQL.js'); })).EmailAuthProvider();
4468
4535
  break;
4469
4536
  case "wallet":
4470
4537
  case "phantom": {
@@ -4483,7 +4550,7 @@ async function getAuthProvider(config) {
4483
4550
  if (!isWalletLoginEnabled(config)) {
4484
4551
  throw walletLoginNotEnabledError(authMethod);
4485
4552
  }
4486
- const { InjectedWalletProvider } = await Promise.resolve().then(function () { return require('./injected-wallet-provider-CST-B9EE.js'); });
4553
+ const { InjectedWalletProvider } = await Promise.resolve().then(function () { return require('./injected-wallet-provider-B_jQFifE.js'); });
4487
4554
  currentAuthProvider = new InjectedWalletProvider(resolveInjectedWalletConfig(config), rpcUrl, configuredNetwork);
4488
4555
  break;
4489
4556
  }
@@ -4496,7 +4563,7 @@ async function getAuthProvider(config) {
4496
4563
  // Selecting authMethod:'evm-wallet' IS the opt-in — pass evmWalletConfig
4497
4564
  // to point at a specific wallet or set chainId/domain.
4498
4565
  const evmWalletConfig = ((_a = config.evmWalletConfig) !== null && _a !== void 0 ? _a : {});
4499
- const { InjectedEvmWalletProvider } = await Promise.resolve().then(function () { return require('./injected-evm-wallet-provider-CiCeS1n2.js'); });
4566
+ const { InjectedEvmWalletProvider } = await Promise.resolve().then(function () { return require('./injected-evm-wallet-provider-CcwS6p3o.js'); });
4500
4567
  currentAuthProvider = new InjectedEvmWalletProvider(evmWalletConfig);
4501
4568
  break;
4502
4569
  }
@@ -4524,7 +4591,7 @@ async function getAuthProvider(config) {
4524
4591
  break;
4525
4592
  case "guest":
4526
4593
  // Anonymous auth: a device-local ed25519 keypair signs the challenge.
4527
- currentAuthProvider = new (await Promise.resolve().then(function () { return require('./guest-auth-provider-DhN9PoAi.js'); })).GuestAuthProvider();
4594
+ currentAuthProvider = new (await Promise.resolve().then(function () { return require('./guest-auth-provider-BjfjrpdW.js'); })).GuestAuthProvider();
4528
4595
  break;
4529
4596
  }
4530
4597
  if (!currentAuthProvider) {
@@ -4580,7 +4647,7 @@ async function signInAnonymously() {
4580
4647
  // Lazy-load the guest provider so its ed25519/web3 dependencies stay out of
4581
4648
  // the main bundle for data-only apps. Specifier is a static string literal
4582
4649
  // so bundle-splitting can see it.
4583
- const provider = new (await Promise.resolve().then(function () { return require('./guest-auth-provider-DhN9PoAi.js'); })).GuestAuthProvider();
4650
+ const provider = new (await Promise.resolve().then(function () { return require('./guest-auth-provider-BjfjrpdW.js'); })).GuestAuthProvider();
4584
4651
  setAuthLoading(true); // reflect "signing in…" while the guest keypair session is minted
4585
4652
  const commit = (user) => {
4586
4653
  // No await/interleaving inside this block: provider/method/config/marker
@@ -4710,6 +4777,44 @@ async function loginWithPrivy(options) {
4710
4777
  const result = await provider.login();
4711
4778
  return result ? Object.assign(Object.assign({}, result), { provider }) : null;
4712
4779
  }
4780
+ /**
4781
+ * Log in with an injected Solana WALLET (Phantom / Solflare / Backpack / any
4782
+ * Wallet-Standard `window.solana`) as a co-equal RUNTIME route - selectable
4783
+ * alongside `login()` / hosted `loginWithPopup()` / `signInAnonymously()` WITHOUT
4784
+ * re-`init()`. This is the "Continue with wallet" choice the unified Bounded
4785
+ * login widget offers: it NEVER touches Better Auth - the user's real wallet
4786
+ * becomes `@user.address` and login is a SIWS signature.
4787
+ *
4788
+ * `getProvider` pins a specific discovered wallet (e.g. when the widget lists
4789
+ * several); omit it to use Phantom-first discovery. Must be called from a user
4790
+ * gesture so the wallet's connect prompt is allowed. `init()` must have run first.
4791
+ */
4792
+ async function loginWithWallet(options) {
4793
+ assertBrowserAuthEnv('loginWithWallet');
4794
+ const coreConfig = await core.getConfig();
4795
+ const cfg = initConfig !== null && initConfig !== void 0 ? initConfig : {};
4796
+ const base = resolveInjectedWalletConfig(cfg);
4797
+ const injectedConfig = (options === null || options === void 0 ? void 0 : options.getProvider)
4798
+ ? Object.assign(Object.assign({}, base), { getProvider: options.getProvider }) : base;
4799
+ const rpcUrl = normalizeSolanaRpcUrl(cfg.rpcUrl);
4800
+ const network = getConfiguredSolanaNetwork(cfg);
4801
+ const { InjectedWalletProvider } = await Promise.resolve().then(function () { return require('./injected-wallet-provider-B_jQFifE.js'); });
4802
+ let provider = new InjectedWalletProvider(injectedConfig, rpcUrl, network);
4803
+ if (coreConfig.chain === 'offchain')
4804
+ provider = new OffchainAuthProvider(provider);
4805
+ // The provider stores the session + user + auth-method marker itself on success.
4806
+ const user = await provider.login();
4807
+ if (!user)
4808
+ return null;
4809
+ currentAuthProvider = provider;
4810
+ currentAuthMethod = 'phantom';
4811
+ currentAuthProviderConfigKey = authProviderConfigKey(Object.assign(Object.assign({}, cfg), { authMethod: 'phantom' }));
4812
+ coreConfig.authProvider = provider;
4813
+ coreConfig.authMethod = 'phantom';
4814
+ setAuthProviderInstance(provider);
4815
+ setStoredAuthMethod('phantom');
4816
+ return Object.assign(Object.assign({}, user), { provider });
4817
+ }
4713
4818
  async function login$1(options) {
4714
4819
  // Re-initialize provider if it was cleared by logout
4715
4820
  if (!currentAuthProvider && initConfig) {
@@ -4846,6 +4951,27 @@ async function logout$1(options) {
4846
4951
  }
4847
4952
  }
4848
4953
 
4954
+ var index = /*#__PURE__*/Object.freeze({
4955
+ __proto__: null,
4956
+ clearIncompatibleSession: clearIncompatibleSession,
4957
+ completeLoginFromRedirect: completeLoginFromRedirect,
4958
+ completeLoginInPopup: completeLoginInPopup,
4959
+ getAuthProvider: getAuthProvider,
4960
+ getCurrentAuthMethod: getCurrentAuthMethod,
4961
+ getInitConfig: getInitConfig,
4962
+ isEmailRequired: isEmailRequired,
4963
+ isWalletLoginDisabled: isWalletLoginDisabled,
4964
+ isWalletLoginEnabled: isWalletLoginEnabled,
4965
+ login: login$1,
4966
+ loginWithPopup: loginWithPopup,
4967
+ loginWithPrivy: loginWithPrivy,
4968
+ loginWithRedirect: loginWithRedirect,
4969
+ loginWithWallet: loginWithWallet,
4970
+ logout: logout$1,
4971
+ resolveAuthMode: resolveAuthMode,
4972
+ signInAnonymously: signInAnonymously
4973
+ });
4974
+
4849
4975
  /**
4850
4976
  * Read the active session's idToken synchronously from whichever store is live
4851
4977
  * for this runtime (WebSessionManager on web, ReactNativeSessionManager on RN —
@@ -5024,17 +5150,1150 @@ function setAuthProviderInstance(provider) {
5024
5150
  authProviderInstance = provider;
5025
5151
  }
5026
5152
 
5027
- var _a$1;
5153
+ // bounded-widget-modal.ts - the shared in-app WIDGET shell for Bounded's login
5154
+ // and signing surfaces. One Shadow-DOM overlay + panel that matches the Bounded
5155
+ // widget (Seal) look and MOTION: a backdrop fade, a panel rise on desktop, a
5156
+ // bottom-sheet on mobile, a height tween as content swaps, and a clean close.
5157
+ //
5158
+ // It hosts EITHER:
5159
+ // - NATIVE content (the login card the SDK renders itself), or
5160
+ // - an IFRAME (the Bounded-owned signer page, which must run on the single
5161
+ // signer origin because a WebAuthn passkey is bound to one origin).
5162
+ //
5163
+ // The modal is a warm singleton: it stays mounted (hidden) between uses so a
5164
+ // second open - or a signature right after login - is instant and, when it is
5165
+ // already open, a clean in-place view swap rather than a reopen.
5166
+ function hasDOM$2() {
5167
+ return typeof window !== "undefined" && typeof document !== "undefined";
5168
+ }
5169
+ const OVERLAY_CSS = `
5170
+ :host{all:initial}
5171
+ *{box-sizing:border-box}
5172
+ .bw-ov{position:fixed;inset:0;z-index:2147483647;display:none;
5173
+ font-family:"Schibsted Grotesk","Helvetica Neue",Arial,sans-serif}
5174
+ .bw-ov.mounted{display:block}
5175
+ .bw-back{position:fixed;inset:0;background:rgba(4,4,5,.62);opacity:0;
5176
+ transition:opacity .24s ease;-webkit-backdrop-filter:blur(5px);backdrop-filter:blur(5px)}
5177
+ .bw-wrap{position:fixed;inset:0;display:flex;align-items:center;justify-content:center;padding:20px}
5178
+ .bw-panel{position:relative;width:420px;max-width:calc(100vw - 28px);height:280px;
5179
+ border-radius:14px;overflow:hidden;background:#0e0f11;border:1px solid rgba(232,230,222,.08);
5180
+ box-shadow:0 1px 0 rgba(232,230,222,.03) inset,0 40px 90px -45px rgba(0,0,0,.85);
5181
+ opacity:0;transform:translateY(14px) scale(.98);will-change:transform,opacity,height;
5182
+ transition:opacity .28s cubic-bezier(.2,.8,.2,1),transform .28s cubic-bezier(.2,.8,.2,1),
5183
+ height .3s cubic-bezier(.2,.8,.2,1)}
5184
+ .bw-ov.show .bw-back{opacity:1}
5185
+ .bw-ov.show .bw-panel{opacity:1;transform:none}
5186
+ .bw-ov.closing .bw-back{opacity:0}
5187
+ .bw-ov.closing .bw-panel{opacity:0;transform:translateY(12px) scale(.99)}
5188
+ .bw-content{position:absolute;inset:0;overflow:hidden}
5189
+ .bw-frame{display:block;width:100%;height:100%;border:0;background:transparent;color-scheme:dark}
5190
+ /* editorial corner crop-marks, matching the reference frame */
5191
+ .bw-mk{position:absolute;width:13px;height:13px;pointer-events:none;z-index:2;
5192
+ border-color:rgba(232,230,222,.22);border-style:solid;border-width:0}
5193
+ .bw-mk.tl{top:11px;left:11px;border-top-width:1px;border-left-width:1px}
5194
+ .bw-mk.tr{top:11px;right:11px;border-top-width:1px;border-right-width:1px}
5195
+ .bw-mk.bl{bottom:11px;left:11px;border-bottom-width:1px;border-left-width:1px}
5196
+ .bw-mk.br{bottom:11px;right:11px;border-bottom-width:1px;border-right-width:1px}
5197
+ @media(max-width:560px){
5198
+ .bw-wrap{align-items:flex-end;padding:0}
5199
+ .bw-panel{width:100%;max-width:100%;border-radius:18px 18px 0 0;border-bottom:0}
5200
+ .bw-content{overflow-y:auto}
5201
+ .bw-ov.show .bw-panel{transform:none}
5202
+ .bw-ov:not(.show) .bw-panel,.bw-ov.closing .bw-panel{transform:translateY(18%)}
5203
+ }
5204
+ @media(prefers-reduced-motion:reduce){.bw-back,.bw-panel{transition:opacity .12s linear!important}}
5205
+ `;
5206
+ let modal = null;
5207
+ function getModal() {
5208
+ if (modal)
5209
+ return modal;
5210
+ const root = document.createElement("div");
5211
+ root.setAttribute("data-bounded-widget", "");
5212
+ const shadow = root.attachShadow({ mode: "open" });
5213
+ const style = document.createElement("style");
5214
+ style.textContent = OVERLAY_CSS;
5215
+ shadow.appendChild(style);
5216
+ const overlay = document.createElement("div");
5217
+ overlay.className = "bw-ov";
5218
+ const back = document.createElement("div");
5219
+ back.className = "bw-back";
5220
+ const wrap = document.createElement("div");
5221
+ wrap.className = "bw-wrap";
5222
+ const panel = document.createElement("div");
5223
+ panel.className = "bw-panel";
5224
+ const content = document.createElement("div");
5225
+ content.className = "bw-content";
5226
+ panel.appendChild(content);
5227
+ for (const corner of ["tl", "tr", "bl", "br"]) {
5228
+ const mk = document.createElement("span");
5229
+ mk.className = "bw-mk " + corner;
5230
+ panel.appendChild(mk);
5231
+ }
5232
+ wrap.appendChild(panel);
5233
+ overlay.appendChild(back);
5234
+ overlay.appendChild(wrap);
5235
+ shadow.appendChild(overlay);
5236
+ (document.body || document.documentElement).appendChild(root);
5237
+ const m = {
5238
+ root,
5239
+ overlay,
5240
+ panel,
5241
+ content,
5242
+ iframe: null,
5243
+ iframeOrigin: "",
5244
+ iframeReady: false,
5245
+ onBackdrop: null,
5246
+ onIframeMessage: null,
5247
+ chain: Promise.resolve(),
5248
+ fitObserver: null,
5249
+ };
5250
+ // The dismiss handler lives on `.bw-wrap`: it is the full-viewport flex layer
5251
+ // that sits ABOVE `.bw-back`, so it (not the backdrop element) receives clicks
5252
+ // outside the panel. Fire only when the click lands on the wrap itself, never
5253
+ // when it bubbles up from the panel or its content.
5254
+ wrap.addEventListener("click", (event) => {
5255
+ if (event.target === wrap && m.onBackdrop)
5256
+ m.onBackdrop();
5257
+ });
5258
+ window.addEventListener("message", (event) => {
5259
+ if (!m.iframe)
5260
+ return;
5261
+ if (event.origin !== m.iframeOrigin)
5262
+ return;
5263
+ if (event.source !== m.iframe.contentWindow)
5264
+ return;
5265
+ const d = event.data;
5266
+ if (!d || typeof d !== "object")
5267
+ return;
5268
+ if (m.onIframeMessage)
5269
+ m.onIframeMessage(d);
5270
+ });
5271
+ modal = m;
5272
+ return m;
5273
+ }
5274
+ function showModal(m) {
5275
+ m.overlay.classList.remove("closing");
5276
+ m.overlay.classList.add("mounted");
5277
+ // Force a reflow so the .show transition runs from the hidden state every open.
5278
+ void m.panel.offsetWidth;
5279
+ m.overlay.classList.add("show");
5280
+ }
5281
+ function hideModal(m, after) {
5282
+ m.overlay.classList.remove("show");
5283
+ m.overlay.classList.add("closing");
5284
+ window.setTimeout(() => {
5285
+ m.overlay.classList.remove("mounted", "closing");
5286
+ }, 260);
5287
+ }
5288
+ function setPanelHeight(m, px) {
5289
+ const h = Math.max(140, Math.min(680, Math.round(px)));
5290
+ m.panel.style.height = h + "px";
5291
+ }
5292
+ // True outer height of the mounted card: the max of its padding-box scroll height
5293
+ // (catches overflowing descendants) and its border-box height plus own vertical
5294
+ // margins (catches border + margins, which scrollHeight omits). Ceiled so a
5295
+ // sub-pixel row is never clipped under `overflow:hidden`.
5296
+ function measureOuterHeight(target) {
5297
+ var _a;
5298
+ const cs = (_a = target.ownerDocument.defaultView) === null || _a === void 0 ? void 0 : _a.getComputedStyle(target);
5299
+ const marginY = cs ? parseFloat(cs.marginTop) + parseFloat(cs.marginBottom) : 0;
5300
+ const borderBox = target.offsetHeight + (Number.isFinite(marginY) ? marginY : 0);
5301
+ const rect = target.getBoundingClientRect().height;
5302
+ return Math.ceil(Math.max(target.scrollHeight, borderBox, rect));
5303
+ }
5304
+ /**
5305
+ * Measure the currently mounted native content and tween the panel to fit it.
5306
+ * Re-fits automatically when the card's intrinsic height changes - notably after
5307
+ * the Newsreader/Schibsted web fonts swap in (which grows line boxes a few px
5308
+ * after first paint) and on inline view swaps (email -> OTP code -> success).
5309
+ */
5310
+ function fitPanelToContent(m) {
5311
+ var _a, _b;
5312
+ const first = m.content.firstElementChild;
5313
+ const target = first || m.content;
5314
+ const apply = () => {
5315
+ // Only fit while this exact node is still the mounted card.
5316
+ if (m.content.firstElementChild !== first && first)
5317
+ return;
5318
+ const h = measureOuterHeight(target);
5319
+ if (h > 0)
5320
+ setPanelHeight(m, h);
5321
+ };
5322
+ apply();
5323
+ const view = target.ownerDocument.defaultView;
5324
+ // Re-fit after fonts load (one-shot) and once the ResizeObserver-less browsers
5325
+ // have painted, so the height never lags a late reflow.
5326
+ (_a = view === null || view === void 0 ? void 0 : view.requestAnimationFrame) === null || _a === void 0 ? void 0 : _a.call(view, apply);
5327
+ const fonts = target.ownerDocument.fonts;
5328
+ if (fonts === null || fonts === void 0 ? void 0 : fonts.ready)
5329
+ fonts.ready.then(apply).catch(() => { });
5330
+ (_b = m.fitObserver) === null || _b === void 0 ? void 0 : _b.disconnect();
5331
+ m.fitObserver = null;
5332
+ if (first && typeof (view === null || view === void 0 ? void 0 : view.ResizeObserver) === "function") {
5333
+ const ro = new view.ResizeObserver(() => apply());
5334
+ ro.observe(first);
5335
+ m.fitObserver = ro;
5336
+ }
5337
+ }
5338
+ /** Switch the modal into NATIVE-content mode: detach any iframe, mount `node`. */
5339
+ function mountContent(m, node) {
5340
+ var _a;
5341
+ detachIframe(m);
5342
+ (_a = m.fitObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
5343
+ m.fitObserver = null;
5344
+ m.content.replaceChildren(node);
5345
+ m.content.style.display = "block";
5346
+ }
5347
+ /** Get (or lazily create) the warm iframe for signer/hosted-page mode. */
5348
+ function ensureIframe(m, url, origin) {
5349
+ var _a;
5350
+ if (m.iframe && m.iframeOrigin === origin && m.iframe.src === url)
5351
+ return m.iframe;
5352
+ detachIframe(m);
5353
+ (_a = m.fitObserver) === null || _a === void 0 ? void 0 : _a.disconnect();
5354
+ m.fitObserver = null;
5355
+ m.content.style.display = "none";
5356
+ const iframe = document.createElement("iframe");
5357
+ iframe.className = "bw-frame";
5358
+ iframe.setAttribute("title", "Bounded");
5359
+ // Grant the framed origin WebAuthn get + create so passkey enroll/sign run
5360
+ // inside the frame from the user's click (transient activation stays in-frame).
5361
+ iframe.setAttribute("allow", "publickey-credentials-get; publickey-credentials-create; clipboard-write");
5362
+ iframe.src = url;
5363
+ m.iframeOrigin = origin;
5364
+ m.iframeReady = false;
5365
+ m.panel.appendChild(iframe);
5366
+ m.iframe = iframe;
5367
+ return iframe;
5368
+ }
5369
+ function detachIframe(m) {
5370
+ if (m.iframe) {
5371
+ try {
5372
+ m.iframe.remove();
5373
+ }
5374
+ catch (_a) {
5375
+ /* ignore */
5376
+ }
5377
+ }
5378
+ m.iframe = null;
5379
+ m.iframeReady = false;
5380
+ m.iframeOrigin = "";
5381
+ m.onIframeMessage = null;
5382
+ }
5383
+ // Load the Bounded editorial typefaces (Newsreader display + Schibsted Grotesk body +
5384
+ // JetBrains Mono) once at the document level so they apply inside the shadow root. A
5385
+ // no-op if already present or off-DOM. Fonts loaded here match the hosted auth page.
5386
+ const FONTS_HREF = "https://fonts.googleapis.com/css2?family=Newsreader:opsz,wght@6..72,400;6..72,500&family=Schibsted+Grotesk:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap";
5387
+ function ensureFonts() {
5388
+ if (!hasDOM$2())
5389
+ return;
5390
+ if (document.querySelector('link[data-bounded-fonts="1"]'))
5391
+ return;
5392
+ const pre1 = document.createElement("link");
5393
+ pre1.rel = "preconnect";
5394
+ pre1.href = "https://fonts.googleapis.com";
5395
+ const pre2 = document.createElement("link");
5396
+ pre2.rel = "preconnect";
5397
+ pre2.href = "https://fonts.gstatic.com";
5398
+ pre2.crossOrigin = "anonymous";
5399
+ const link = document.createElement("link");
5400
+ link.rel = "stylesheet";
5401
+ link.href = FONTS_HREF;
5402
+ link.setAttribute("data-bounded-fonts", "1");
5403
+ document.head.append(pre1, pre2, link);
5404
+ }
5405
+
5406
+ var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
5407
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
5408
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5409
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5410
+ };
5411
+ var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
5412
+ if (kind === "m") throw new TypeError("Private method is not writable");
5413
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5414
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5415
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
5416
+ };
5417
+ var _AppReadyEvent_detail;
5418
+ let wallets = undefined;
5419
+ const registeredWalletsSet = new Set();
5420
+ function addRegisteredWallet(wallet) {
5421
+ cachedWalletsArray = undefined;
5422
+ registeredWalletsSet.add(wallet);
5423
+ }
5424
+ function removeRegisteredWallet(wallet) {
5425
+ cachedWalletsArray = undefined;
5426
+ registeredWalletsSet.delete(wallet);
5427
+ }
5428
+ const listeners = {};
5429
+ /**
5430
+ * Get an API for {@link Wallets.get | getting}, {@link Wallets.on | listening for}, and
5431
+ * {@link Wallets.register | registering} {@link "@wallet-standard/base".Wallet | Wallets}.
5432
+ *
5433
+ * When called for the first time --
5434
+ *
5435
+ * This dispatches a {@link "@wallet-standard/base".WindowAppReadyEvent} to notify each Wallet that the app is ready
5436
+ * to register it.
5437
+ *
5438
+ * This also adds a listener for {@link "@wallet-standard/base".WindowRegisterWalletEvent} to listen for a notification
5439
+ * from each Wallet that the Wallet is ready to be registered by the app.
5440
+ *
5441
+ * This combination of event dispatch and listener guarantees that each Wallet will be registered synchronously as soon
5442
+ * as the app is ready whether the app loads before or after each Wallet.
5443
+ *
5444
+ * @return API for getting, listening for, and registering Wallets.
5445
+ *
5446
+ * @group App
5447
+ */
5448
+ function getWallets() {
5449
+ if (wallets)
5450
+ return wallets;
5451
+ wallets = Object.freeze({ register, get: get$1, on });
5452
+ if (typeof window === 'undefined')
5453
+ return wallets;
5454
+ const api = Object.freeze({ register });
5455
+ try {
5456
+ window.addEventListener('wallet-standard:register-wallet', ({ detail: callback }) => callback(api));
5457
+ }
5458
+ catch (error) {
5459
+ console.error('wallet-standard:register-wallet event listener could not be added\n', error);
5460
+ }
5461
+ try {
5462
+ window.dispatchEvent(new AppReadyEvent(api));
5463
+ }
5464
+ catch (error) {
5465
+ console.error('wallet-standard:app-ready event could not be dispatched\n', error);
5466
+ }
5467
+ return wallets;
5468
+ }
5469
+ function register(...wallets) {
5470
+ // Filter out wallets that have already been registered.
5471
+ // This prevents the same wallet from being registered twice, but it also prevents wallets from being
5472
+ // unregistered by reusing a reference to the wallet to obtain the unregister function for it.
5473
+ wallets = wallets.filter((wallet) => !registeredWalletsSet.has(wallet));
5474
+ // If there are no new wallets to register, just return a no-op unregister function.
5475
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
5476
+ if (!wallets.length)
5477
+ return () => { };
5478
+ wallets.forEach((wallet) => addRegisteredWallet(wallet));
5479
+ listeners['register']?.forEach((listener) => guard(() => listener(...wallets)));
5480
+ // Return a function that unregisters the registered wallets.
5481
+ return function unregister() {
5482
+ wallets.forEach((wallet) => removeRegisteredWallet(wallet));
5483
+ listeners['unregister']?.forEach((listener) => guard(() => listener(...wallets)));
5484
+ };
5485
+ }
5486
+ let cachedWalletsArray;
5487
+ function get$1() {
5488
+ if (!cachedWalletsArray) {
5489
+ cachedWalletsArray = [...registeredWalletsSet];
5490
+ }
5491
+ return cachedWalletsArray;
5492
+ }
5493
+ function on(event, listener) {
5494
+ listeners[event]?.push(listener) || (listeners[event] = [listener]);
5495
+ // Return a function that removes the event listener.
5496
+ return function off() {
5497
+ listeners[event] = listeners[event]?.filter((existingListener) => listener !== existingListener);
5498
+ };
5499
+ }
5500
+ function guard(callback) {
5501
+ try {
5502
+ callback();
5503
+ }
5504
+ catch (error) {
5505
+ console.error(error);
5506
+ }
5507
+ }
5508
+ class AppReadyEvent extends Event {
5509
+ get detail() {
5510
+ return __classPrivateFieldGet(this, _AppReadyEvent_detail, "f");
5511
+ }
5512
+ get type() {
5513
+ return 'wallet-standard:app-ready';
5514
+ }
5515
+ constructor(api) {
5516
+ super('wallet-standard:app-ready', {
5517
+ bubbles: false,
5518
+ cancelable: false,
5519
+ composed: false,
5520
+ });
5521
+ _AppReadyEvent_detail.set(this, void 0);
5522
+ __classPrivateFieldSet(this, _AppReadyEvent_detail, api, "f");
5523
+ }
5524
+ /** @deprecated */
5525
+ preventDefault() {
5526
+ throw new Error('preventDefault cannot be called');
5527
+ }
5528
+ /** @deprecated */
5529
+ stopImmediatePropagation() {
5530
+ throw new Error('stopImmediatePropagation cannot be called');
5531
+ }
5532
+ /** @deprecated */
5533
+ stopPropagation() {
5534
+ throw new Error('stopPropagation cannot be called');
5535
+ }
5536
+ }
5537
+ _AppReadyEvent_detail = new WeakMap();
5538
+
5539
+ /** Name of the feature. */
5540
+ const SolanaSignAndSendTransaction = 'solana:signAndSendTransaction';
5541
+
5542
+ /** Name of the feature. */
5543
+ const SolanaSignMessage = 'solana:signMessage';
5544
+
5545
+ /** Name of the feature. */
5546
+ const SolanaSignTransaction = 'solana:signTransaction';
5547
+
5548
+ /** Name of the feature. */
5549
+ const StandardConnect = 'standard:connect';
5550
+
5551
+ /** Name of the feature. */
5552
+ const StandardDisconnect = 'standard:disconnect';
5553
+
5554
+ // wallet-standard-discovery.ts - PROPER native-wallet enumeration for the unified
5555
+ // login widget. We do NOT hand-maintain a list of wallet names (Phantom / Solflare
5556
+ // / Backpack / ...); instead we read the Solana Wallet Standard registry
5557
+ // (`@wallet-standard/app` getWallets(), fed by each wallet's
5558
+ // `wallet-standard:register-wallet` event) and surface every wallet that advertises
5559
+ // the Solana features we need. New wallets appear automatically, with their real
5560
+ // name + icon, and nothing is hardcoded.
5561
+ //
5562
+ // Each discovered wallet is adapted to the SDK's tiny `InjectedSolanaProvider`
5563
+ // shape so the existing wallet-login path (loginWithWallet -> InjectedWalletProvider,
5564
+ // SIWS) and the full app signing surface work unchanged. web3.js is only imported
5565
+ // lazily inside the transaction methods, so listing wallets and message-signing
5566
+ // login stay off the heavy chunk.
5567
+ function hasFeature(wallet, name) {
5568
+ return Object.prototype.hasOwnProperty.call(wallet.features, name);
5569
+ }
5570
+ function supportsSolana(wallet) {
5571
+ return wallet.chains.some((c) => c.startsWith("solana:"));
5572
+ }
5573
+ /** A wallet is usable for Bounded login when it can connect + sign a SIWS message
5574
+ * on a Solana chain. Transaction features are optional and checked lazily at
5575
+ * call time, so a message-signing-only wallet still qualifies for login. */
5576
+ function isLoginCapable(wallet) {
5577
+ return (supportsSolana(wallet) &&
5578
+ hasFeature(wallet, StandardConnect) &&
5579
+ hasFeature(wallet, SolanaSignMessage));
5580
+ }
5581
+ function feature(wallet, name) {
5582
+ return wallet.features[name];
5583
+ }
5584
+ function firstSolanaChain(wallet, account) {
5585
+ var _a;
5586
+ const fromAccount = account.chains.find((c) => c.startsWith("solana:"));
5587
+ const fromWallet = wallet.chains.find((c) => c.startsWith("solana:"));
5588
+ return ((_a = fromAccount !== null && fromAccount !== void 0 ? fromAccount : fromWallet) !== null && _a !== void 0 ? _a : "solana:mainnet");
5589
+ }
5590
+ /**
5591
+ * Adapt a Wallet Standard wallet to the slim `InjectedSolanaProvider` the SDK's
5592
+ * wallet-login + signing path consumes. Connect resolves (and caches) the active
5593
+ * account; sign* delegate to the wallet's own Solana features. Nothing is
5594
+ * wallet-name specific.
5595
+ */
5596
+ function standardWalletToInjectedProvider(wallet) {
5597
+ let account = null;
5598
+ const requireAccount = () => {
5599
+ if (!account)
5600
+ throw new Error("Wallet not connected");
5601
+ return account;
5602
+ };
5603
+ return {
5604
+ get isConnected() {
5605
+ return account !== null;
5606
+ },
5607
+ get publicKey() {
5608
+ // Wallet Standard account.address is already the base58 Solana address.
5609
+ return account ? { toString: () => account.address } : null;
5610
+ },
5611
+ async connect() {
5612
+ var _a;
5613
+ const connect = feature(wallet, StandardConnect);
5614
+ if (!connect)
5615
+ throw new Error("Wallet does not support standard:connect");
5616
+ const res = await connect.connect();
5617
+ const acc = (_a = res.accounts.find((a) => a.chains.some((c) => c.startsWith("solana:")))) !== null && _a !== void 0 ? _a : res.accounts[0];
5618
+ if (!acc)
5619
+ throw new Error("Wallet returned no account on connect");
5620
+ account = acc;
5621
+ return { publicKey: { toString: () => acc.address } };
5622
+ },
5623
+ async disconnect() {
5624
+ const disconnect = feature(wallet, StandardDisconnect);
5625
+ if (disconnect)
5626
+ await disconnect.disconnect();
5627
+ account = null;
5628
+ },
5629
+ async signMessage(message) {
5630
+ const acc = requireAccount();
5631
+ const sign = feature(wallet, SolanaSignMessage);
5632
+ if (!sign)
5633
+ throw new Error("Wallet does not support solana:signMessage");
5634
+ const [out] = await sign.signMessage({ account: acc, message });
5635
+ return { signature: out.signature, publicKey: { toString: () => acc.address } };
5636
+ },
5637
+ async signTransaction(tx) {
5638
+ const acc = requireAccount();
5639
+ const sign = feature(wallet, SolanaSignTransaction);
5640
+ if (!sign)
5641
+ throw new Error("Wallet does not support solana:signTransaction");
5642
+ const { serializeUnsignedTx, deserializeSignedTx } = await Promise.resolve().then(function () { return require('./wallet-standard-tx-C1HJFLjC.js'); });
5643
+ const [out] = await sign.signTransaction({ account: acc, transaction: serializeUnsignedTx(tx) });
5644
+ return deserializeSignedTx(out.signedTransaction);
5645
+ },
5646
+ async signAllTransactions(txs) {
5647
+ const acc = requireAccount();
5648
+ const sign = feature(wallet, SolanaSignTransaction);
5649
+ if (!sign)
5650
+ throw new Error("Wallet does not support solana:signTransaction");
5651
+ const { serializeUnsignedTx, deserializeSignedTx } = await Promise.resolve().then(function () { return require('./wallet-standard-tx-C1HJFLjC.js'); });
5652
+ const outs = await sign.signTransaction(...txs.map((tx) => ({ account: acc, transaction: serializeUnsignedTx(tx) })));
5653
+ return outs.map((o) => deserializeSignedTx(o.signedTransaction));
5654
+ },
5655
+ async signAndSendTransaction(tx) {
5656
+ const acc = requireAccount();
5657
+ const sas = feature(wallet, SolanaSignAndSendTransaction);
5658
+ if (!sas)
5659
+ throw new Error("Wallet does not support solana:signAndSendTransaction");
5660
+ const { serializeUnsignedTx } = await Promise.resolve().then(function () { return require('./wallet-standard-tx-C1HJFLjC.js'); });
5661
+ const [out] = await sas.signAndSendTransaction({
5662
+ account: acc,
5663
+ transaction: serializeUnsignedTx(tx),
5664
+ chain: firstSolanaChain(wallet, acc),
5665
+ });
5666
+ return { signature: bs58.encode(out.signature) };
5667
+ },
5668
+ };
5669
+ }
5670
+ /**
5671
+ * Enumerate every Solana-capable wallet currently registered with the Wallet
5672
+ * Standard, newest registrations included. Returns login-ready choices (name +
5673
+ * icon + provider factory). Empty array off-browser or when no wallet is present;
5674
+ * the widget then falls back to the legacy injected `window.solana` probe.
5675
+ */
5676
+ function discoverStandardWallets() {
5677
+ if (typeof window === "undefined")
5678
+ return [];
5679
+ const out = [];
5680
+ const seen = new Set();
5681
+ for (const wallet of getWallets().get()) {
5682
+ if (!isLoginCapable(wallet) || seen.has(wallet.name))
5683
+ continue;
5684
+ seen.add(wallet.name);
5685
+ out.push({
5686
+ name: wallet.name,
5687
+ icon: wallet.icon,
5688
+ getProvider: () => standardWalletToInjectedProvider(wallet),
5689
+ });
5690
+ }
5691
+ return out;
5692
+ }
5693
+
5694
+ function hasDOM$1() {
5695
+ return typeof window !== 'undefined' && typeof document !== 'undefined';
5696
+ }
5697
+ async function signerOrigin() {
5698
+ const cfg = await core.getConfig();
5699
+ const base = (cfg.humanAuthApiUrl || 'https://auth.bounded.sh').replace(/\/$/, '');
5700
+ return { url: `${base}/wallet/turnkey/signer`, origin: new URL(base).origin };
5701
+ }
5702
+ let encryptSeq = 0;
5703
+ // Seal the OTP in a HIDDEN, offscreen signer iframe on the Bounded origin. The signer page
5704
+ // runs the vendored @turnkey/crypto encryptOtpCodeToBundle (which verifies the enclave's
5705
+ // signature on the target bundle first). Origin + source + requestId are all pinned.
5706
+ function sealOtpInIframe(code, otpEncryptionTargetBundle) {
5707
+ return new Promise((resolve, reject) => {
5708
+ signerOrigin().then(({ url, origin }) => {
5709
+ const requestId = `tkotp_${Date.now()}_${++encryptSeq}`;
5710
+ const frame = document.createElement('iframe');
5711
+ frame.setAttribute('aria-hidden', 'true');
5712
+ frame.setAttribute('allow', 'publickey-credentials-get; publickey-credentials-create; clipboard-write');
5713
+ frame.style.cssText =
5714
+ 'position:fixed;width:1px;height:1px;left:-9999px;top:-9999px;border:0;opacity:0;pointer-events:none';
5715
+ let settled = false;
5716
+ let timer;
5717
+ const cleanup = () => {
5718
+ settled = true;
5719
+ window.removeEventListener('message', onMsg);
5720
+ if (timer)
5721
+ clearTimeout(timer);
5722
+ try {
5723
+ frame.remove();
5724
+ }
5725
+ catch ( /* already gone */_a) { /* already gone */ }
5726
+ };
5727
+ const onMsg = (event) => {
5728
+ var _a;
5729
+ if (event.origin !== origin || event.source !== frame.contentWindow)
5730
+ return;
5731
+ const d = event.data;
5732
+ if (!d || typeof d !== 'object')
5733
+ return;
5734
+ if (d.type === 'bounded:turnkey:ready') {
5735
+ try {
5736
+ (_a = frame.contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage({ type: 'bounded:turnkey:encryptOtp', requestId, otpCode: code, otpEncryptionTargetBundle }, origin);
5737
+ }
5738
+ catch ( /* frame gone */_b) { /* frame gone */ }
5739
+ return;
5740
+ }
5741
+ if (d.type === 'bounded:turnkey:result' && d.requestId === requestId) {
5742
+ if (d.ok && typeof d.encryptedOtpBundle === 'string' && d.encryptedOtpBundle) {
5743
+ const bundle = d.encryptedOtpBundle;
5744
+ cleanup();
5745
+ resolve(bundle);
5746
+ }
5747
+ else {
5748
+ cleanup();
5749
+ reject(new Error(String(d.error || 'Could not secure the code. Please try again.')));
5750
+ }
5751
+ }
5752
+ };
5753
+ window.addEventListener('message', onMsg);
5754
+ timer = setTimeout(() => {
5755
+ if (!settled) {
5756
+ cleanup();
5757
+ reject(new Error('Securing the code timed out. Please try again.'));
5758
+ }
5759
+ }, 30000);
5760
+ frame.src = url;
5761
+ document.body.appendChild(frame);
5762
+ }).catch(reject);
5763
+ });
5764
+ }
5765
+ /**
5766
+ * Begin authMode:"turnkey" login: ask Turnkey to email a one-time code to `email`.
5767
+ * Resolves with a handle whose `verify(code)` finishes the login. Web-only (the sealing
5768
+ * step needs the signer iframe); on React Native use loginWithRedirect() instead.
5769
+ */
5770
+ async function startTurnkeyEmailLogin(email) {
5771
+ if (!hasDOM$1()) {
5772
+ throw new Error('Turnkey-native email login is web-only - on React Native use loginWithRedirect()');
5773
+ }
5774
+ const trimmed = email.trim();
5775
+ if (!trimmed)
5776
+ throw new Error('Enter your email to continue.');
5777
+ const { base, appId } = await inlineAuthEndpoint();
5778
+ if (!appId)
5779
+ throw new Error('appId is not configured (init the SDK with your appId)');
5780
+ const res = await fetch(`${base}/wallet/turnkey/auth/init`, {
5781
+ method: 'POST',
5782
+ headers: { 'content-type': 'application/json' },
5783
+ body: JSON.stringify({ email: trimmed, appId }),
5784
+ });
5785
+ const data = await res.json().catch(() => null);
5786
+ if (!res.ok || !data || typeof data.otpId !== 'string' || typeof data.otpEncryptionTargetBundle !== 'string') {
5787
+ throw new Error(String((data && data.error) || 'Could not send a code. Please try again.'));
5788
+ }
5789
+ const otpId = data.otpId;
5790
+ const otpEncryptionTargetBundle = data.otpEncryptionTargetBundle;
5791
+ return {
5792
+ email: trimmed,
5793
+ async verify(code) {
5794
+ const trimmedCode = (code || '').trim();
5795
+ if (!trimmedCode)
5796
+ throw new Error('Enter the code from your email.');
5797
+ const encryptedOtpBundle = await sealOtpInIframe(trimmedCode, otpEncryptionTargetBundle);
5798
+ const vres = await fetch(`${base}/wallet/turnkey/auth/verify`, {
5799
+ method: 'POST',
5800
+ headers: { 'content-type': 'application/json' },
5801
+ body: JSON.stringify({ email: trimmed, appId, otpId, encryptedOtpBundle }),
5802
+ });
5803
+ const vdata = await vres.json().catch(() => null);
5804
+ if (!vres.ok || !vdata) {
5805
+ throw new Error(String((vdata && vdata.error) || 'Invalid or expired code.'));
5806
+ }
5807
+ return establishInlineSession(vdata);
5808
+ },
5809
+ };
5810
+ }
5811
+
5812
+ // bounded-login-widget.ts - the UNIFIED Bounded login surface: one in-app card
5813
+ // (Shadow-DOM modal from bounded-widget-modal.ts, Bounded look + motion) that folds
5814
+ // together every login lane the SDK supports:
5815
+ // - Email / social (Google, ...) -> the hosted Better Auth OIDC flow, run in a
5816
+ // brief FIRST-PARTY popup (loginWithPopup). A cross-origin auth IFRAME cannot
5817
+ // hold the Better Auth session cookie (third-party-cookie blocking in Safari /
5818
+ // Chrome), so the session handshake pops; the card itself stays in-app.
5819
+ // - "Continue with wallet" -> native injected wallets (Phantom / Solflare /
5820
+ // Backpack) via loginWithWallet(), run ENTIRELY on the app page (injected
5821
+ // providers only exist there, never inside a cross-origin frame).
5822
+ //
5823
+ // Redirect stays available as the popup-blocked fallback (loginWithRedirect).
5824
+ // The same modal is reused for Turnkey passkey signing, so login -> first
5825
+ // signature is one continuous surface.
5826
+ // Palette + type ladder mirror the hosted auth page (login-page.ts): dark editorial
5827
+ // panel, Newsreader display serif for the title, Schibsted Grotesk body, a light
5828
+ // (paper) primary button and inset inputs. This is the same look/feel as
5829
+ // auth.bounded, brought inline into the in-app widget.
5830
+ const CARD_CSS = `
5831
+ :host,*{box-sizing:border-box}
5832
+ .c{--bg-inset:#060607;--bg-raise:#131416;
5833
+ --line:rgba(232,230,222,.08);--line-strong:rgba(232,230,222,.16);
5834
+ --text:#e8e6de;--dim:#9b9991;--faint:#85837c;
5835
+ --green:#58c98f;--green-bg:rgba(88,201,143,.09);--green-line:rgba(88,201,143,.28);--red:#ec8488;
5836
+ --disp:"Newsreader","Iowan Old Style",Georgia,serif;
5837
+ --body:"Schibsted Grotesk","Helvetica Neue",Arial,sans-serif;
5838
+ position:relative;padding:34px 32px 20px;color:var(--text);font-family:var(--body);
5839
+ -webkit-font-smoothing:antialiased}
5840
+ .x{position:absolute;top:20px;right:24px;border:0;background:transparent;color:var(--faint);
5841
+ font-family:var(--body);font-size:13px;line-height:1;cursor:pointer;padding:4px}
5842
+ .x:hover{color:var(--text)}
5843
+ h1{font-family:var(--disp);font-weight:400;font-size:27px;line-height:1.12;letter-spacing:-.01em;margin:0 0 6px;max-width:88%}
5844
+ .sub{margin:0 0 24px;color:var(--dim);font-size:13.5px}
5845
+ label{display:block;font-size:12px;color:var(--dim);margin:0 0 7px}
5846
+ input{width:100%;padding:11px 13px;border-radius:6px;border:1px solid var(--line-strong);
5847
+ background:var(--bg-inset);color:var(--text);font-size:15px;font-family:var(--body);outline:none;
5848
+ transition:border-color .15s,box-shadow .15s}
5849
+ input::placeholder{color:var(--faint)}
5850
+ input:focus{border-color:var(--green-line);box-shadow:0 0 0 3px var(--green-bg)}
5851
+ input.otp{font-family:var(--mono,ui-monospace,monospace);letter-spacing:8px;text-align:center;font-size:21px;padding-left:8px}
5852
+ .btn{width:100%;padding:12px 14px;border-radius:6px;font-size:14px;font-weight:600;
5853
+ cursor:pointer;font-family:var(--body);display:flex;align-items:center;justify-content:center;gap:9px;
5854
+ transition:opacity .15s ease,background .15s ease,border-color .15s ease,transform .04s}
5855
+ .btn:disabled{opacity:.45;cursor:default}
5856
+ .primary{border:0;background:var(--text);color:#0a0a0b;margin-top:16px}
5857
+ .primary:hover:not(:disabled){opacity:.9}
5858
+ .primary:active:not(:disabled){transform:translateY(.5px)}
5859
+ .ghost{border:1px solid var(--line-strong);background:var(--bg-raise);color:var(--text);margin-top:9px}
5860
+ .ghost:hover:not(:disabled){background:#17181b}
5861
+ .ghost svg{width:16px;height:16px;flex:none}
5862
+ .wicon{width:18px;height:18px;border-radius:4px;flex:none}
5863
+ .or{display:flex;align-items:center;gap:12px;margin:20px 0 14px;color:var(--faint);
5864
+ font-size:11px;letter-spacing:.08em;text-transform:uppercase}
5865
+ .or::before,.or::after{content:"";flex:1;height:1px;background:var(--line)}
5866
+ .status{margin-top:16px;min-height:16px;font-size:12.5px;color:var(--dim)}
5867
+ .status.err{color:var(--red)}
5868
+ .foot{margin-top:24px;padding-top:15px;border-top:1px solid var(--line);
5869
+ color:var(--faint);font-size:11px;text-align:center;letter-spacing:.02em}
5870
+ .foot a{color:var(--dim);text-decoration:none}
5871
+ .foot a:hover{color:var(--text)}
5872
+ .back{background:transparent;border:0;color:var(--dim);font-size:12.5px;cursor:pointer;padding:0;margin-bottom:16px}
5873
+ .back:hover{color:var(--text)}
5874
+ .spin{width:15px;height:15px;border-radius:50%;border:2px solid rgba(10,10,11,.3);
5875
+ border-top-color:#0a0a0b;animation:bwspin .7s linear infinite}
5876
+ .ghost .spin,.primary.wallet-busy .spin{border:2px solid var(--line-strong);border-top-color:var(--text)}
5877
+ @keyframes bwspin{to{transform:rotate(360deg)}}
5878
+ `;
5879
+ // Brand glyphs, built as SVG DOM (never innerHTML) so the buttons match the hosted page.
5880
+ function googleGlyph() {
5881
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
5882
+ svg.setAttribute("viewBox", "0 0 48 48");
5883
+ svg.setAttribute("aria-hidden", "true");
5884
+ const paths = [
5885
+ ["#EA4335", "M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z"],
5886
+ ["#4285F4", "M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z"],
5887
+ ["#FBBC05", "M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z"],
5888
+ ["#34A853", "M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z"],
5889
+ ];
5890
+ for (const [fill, d] of paths) {
5891
+ const path = document.createElementNS("http://www.w3.org/2000/svg", "path");
5892
+ path.setAttribute("fill", fill);
5893
+ path.setAttribute("d", d);
5894
+ svg.appendChild(path);
5895
+ }
5896
+ return svg;
5897
+ }
5898
+ function walletGlyph() {
5899
+ const svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
5900
+ svg.setAttribute("viewBox", "0 0 24 24");
5901
+ svg.setAttribute("fill", "none");
5902
+ svg.setAttribute("aria-hidden", "true");
5903
+ const rect = document.createElementNS("http://www.w3.org/2000/svg", "rect");
5904
+ rect.setAttribute("x", "3");
5905
+ rect.setAttribute("y", "6");
5906
+ rect.setAttribute("width", "18");
5907
+ rect.setAttribute("height", "13");
5908
+ rect.setAttribute("rx", "2.5");
5909
+ rect.setAttribute("stroke", "currentColor");
5910
+ rect.setAttribute("stroke-width", "1.6");
5911
+ const dot = document.createElementNS("http://www.w3.org/2000/svg", "circle");
5912
+ dot.setAttribute("cx", "16.5");
5913
+ dot.setAttribute("cy", "12.5");
5914
+ dot.setAttribute("r", "1.4");
5915
+ dot.setAttribute("fill", "currentColor");
5916
+ svg.append(rect, dot);
5917
+ return svg;
5918
+ }
5919
+ function isInjectedProvider(v) {
5920
+ return (typeof v === "object" &&
5921
+ v !== null &&
5922
+ typeof v.signMessage === "function");
5923
+ }
5924
+ // Enumerate native wallets via the Solana Wallet Standard registry (NOT a
5925
+ // hardcoded name list) - every wallet that registered itself shows up with its
5926
+ // real name + icon. Only when the registry is empty (an older wallet that never
5927
+ // registers, exposing just `window.solana`) do we fall back to the injected probe.
5928
+ function discoverWallets() {
5929
+ if (typeof window === "undefined")
5930
+ return [];
5931
+ const standard = discoverStandardWallets();
5932
+ if (standard.length > 0) {
5933
+ return standard.map((w) => ({ name: w.name, icon: w.icon, get: () => w.getProvider() }));
5934
+ }
5935
+ const generic = window.solana;
5936
+ if (isInjectedProvider(generic))
5937
+ return [{ name: "Wallet", get: () => generic }];
5938
+ return [];
5939
+ }
5940
+ const METHOD_LABEL = {
5941
+ google: "Continue with Google",
5942
+ apple: "Continue with Apple",
5943
+ github: "Continue with GitHub",
5944
+ };
5945
+ function el(tag, cls, text) {
5946
+ const n = document.createElement(tag);
5947
+ if (cls)
5948
+ n.className = cls;
5949
+ if (text != null)
5950
+ n.textContent = text;
5951
+ return n;
5952
+ }
5953
+ /**
5954
+ * Open the unified Bounded login widget and resolve with the signed-in `User`.
5955
+ * Rejects with `Error("cancelled")` if the user dismisses it. `init()` must have
5956
+ * run first; call from a user gesture so social/wallet popups are allowed.
5957
+ */
5958
+ async function openBoundedWidget(opts = {}) {
5959
+ var _a, _b, _c, _d;
5960
+ if (!hasDOM$2()) {
5961
+ throw new Error("openBoundedWidget is web-only - on React Native use loginWithRedirect()");
5962
+ }
5963
+ // Imported lazily to avoid a static cycle with the auth index barrel.
5964
+ const authApi = await Promise.resolve().then(function () { return index; });
5965
+ const initCfg = (_a = authApi.getInitConfig()) !== null && _a !== void 0 ? _a : {};
5966
+ const methods = ((_b = opts.methods) !== null && _b !== void 0 ? _b : ["email", "google"]).map(String);
5967
+ const hasEmail = methods.includes("email") || methods.includes("text");
5968
+ const social = methods.filter((m) => m !== "email" && m !== "text");
5969
+ const wallets = discoverWallets();
5970
+ // Policy first: an app whose site requires an email on file, or that explicitly
5971
+ // set `walletLogin: false`, hides the wallet lane entirely - this OVERRIDES a
5972
+ // per-call `opts.wallet` and any detected injected wallet.
5973
+ const walletHardOff = authApi.isWalletLoginDisabled(initCfg) || authApi.isEmailRequired(initCfg);
5974
+ const walletEnabled = walletHardOff
5975
+ ? false
5976
+ : ((_c = opts.wallet) !== null && _c !== void 0 ? _c : (wallets.length > 0 || authApi.isWalletLoginEnabled(initCfg)));
5977
+ const authMode = (_d = opts.authMode) !== null && _d !== void 0 ? _d : authApi.resolveAuthMode(initCfg);
5978
+ ensureFonts();
5979
+ const m = getModal();
5980
+ return new Promise((resolve, reject) => {
5981
+ let settled = false;
5982
+ const done = (fn) => {
5983
+ if (settled)
5984
+ return;
5985
+ settled = true;
5986
+ m.onBackdrop = null;
5987
+ fn();
5988
+ };
5989
+ const succeed = (u) => {
5990
+ hideModal(m);
5991
+ done(() => resolve(u));
5992
+ };
5993
+ const cancel = () => {
5994
+ hideModal(m);
5995
+ done(() => reject(new Error("cancelled")));
5996
+ };
5997
+ m.onBackdrop = cancel;
5998
+ const style = el("style");
5999
+ style.textContent = CARD_CSS;
6000
+ const renderChoose = () => {
6001
+ var _a, _b;
6002
+ const card = el("div", "c");
6003
+ card.appendChild(style.cloneNode(true));
6004
+ const x = el("button", "x", "Close");
6005
+ x.type = "button";
6006
+ x.setAttribute("aria-label", "Close");
6007
+ x.addEventListener("click", cancel);
6008
+ card.appendChild(x);
6009
+ card.appendChild(el("h1", undefined, (_a = opts.title) !== null && _a !== void 0 ? _a : "Sign in"));
6010
+ if (opts.subtitle !== "") {
6011
+ card.appendChild(el("p", "sub", (_b = opts.subtitle) !== null && _b !== void 0 ? _b : "One account and wallet across every Bounded app."));
6012
+ }
6013
+ const status = el("div", "status");
6014
+ const setErr = (msg) => {
6015
+ status.textContent = msg;
6016
+ status.classList.add("err");
6017
+ };
6018
+ const setBusy = (btn, label) => {
6019
+ status.classList.remove("err");
6020
+ status.textContent = "";
6021
+ btn.disabled = true;
6022
+ btn.replaceChildren(el("span", "spin"), document.createTextNode(label));
6023
+ };
6024
+ if (hasEmail) {
6025
+ const form = el("form");
6026
+ const label = el("label");
6027
+ label.htmlFor = "bw-email";
6028
+ label.textContent = "Email";
6029
+ const input = el("input");
6030
+ input.id = "bw-email";
6031
+ input.type = "email";
6032
+ input.autocomplete = "email";
6033
+ input.placeholder = "you@example.com";
6034
+ input.required = true;
6035
+ const submit = el("button", "btn primary");
6036
+ submit.type = "submit";
6037
+ submit.textContent = "Continue";
6038
+ form.append(label, input, submit);
6039
+ form.addEventListener("submit", (e) => {
6040
+ e.preventDefault();
6041
+ if (!input.value)
6042
+ return;
6043
+ if (authMode === "turnkey") {
6044
+ // Turnkey-native: ask Turnkey to email a code, then collect it INLINE.
6045
+ setBusy(submit, "Sending code\u2026");
6046
+ startTurnkeyEmailLogin(input.value)
6047
+ .then((handle) => swap(renderOtp(handle)))
6048
+ .catch((err) => {
6049
+ submit.disabled = false;
6050
+ submit.textContent = "Continue";
6051
+ setErr(errText(err));
6052
+ });
6053
+ return;
6054
+ }
6055
+ setBusy(submit, "Opening secure sign-in\u2026");
6056
+ authApi
6057
+ .loginWithPopup({
6058
+ provider: "email",
6059
+ loginHint: input.value,
6060
+ redirectUri: opts.redirectUri,
6061
+ })
6062
+ .then(succeed)
6063
+ .catch((err) => {
6064
+ submit.disabled = false;
6065
+ submit.textContent = "Continue";
6066
+ setErr(errText(err));
6067
+ });
6068
+ });
6069
+ card.appendChild(form);
6070
+ }
6071
+ if (social.length || walletEnabled) {
6072
+ card.appendChild(el("div", "or", "OR"));
6073
+ }
6074
+ const labelFor = (method) => { var _a; return (_a = METHOD_LABEL[method]) !== null && _a !== void 0 ? _a : `Continue with ${cap(method)}`; };
6075
+ const glyphFor = (method) => method === "google" ? googleGlyph() : null;
6076
+ const setLabel = (b, method) => {
6077
+ const glyph = glyphFor(method);
6078
+ const text = document.createTextNode(labelFor(method));
6079
+ if (glyph)
6080
+ b.replaceChildren(glyph, text);
6081
+ else
6082
+ b.replaceChildren(text);
6083
+ };
6084
+ for (const method of social) {
6085
+ const b = el("button", "btn ghost");
6086
+ b.type = "button";
6087
+ setLabel(b, method);
6088
+ b.addEventListener("click", () => {
6089
+ setBusy(b, "Opening secure sign-in\u2026");
6090
+ authApi
6091
+ .loginWithPopup({ provider: method, redirectUri: opts.redirectUri })
6092
+ .then(succeed)
6093
+ .catch((err) => {
6094
+ b.disabled = false;
6095
+ setLabel(b, method);
6096
+ setErr(errText(err));
6097
+ });
6098
+ });
6099
+ card.appendChild(b);
6100
+ }
6101
+ if (walletEnabled) {
6102
+ const b = el("button", "btn ghost");
6103
+ b.type = "button";
6104
+ const walletLabel = () => b.replaceChildren(walletGlyph(), document.createTextNode("Continue with wallet"));
6105
+ walletLabel();
6106
+ b.addEventListener("click", () => {
6107
+ if (wallets.length <= 1) {
6108
+ connectWallet(wallets[0]);
6109
+ }
6110
+ else {
6111
+ swap(renderWallets());
6112
+ }
6113
+ });
6114
+ card.appendChild(b);
6115
+ const connectWallet = (choice) => {
6116
+ setBusy(b, "Approve in your wallet\u2026");
6117
+ authApi
6118
+ .loginWithWallet(choice ? { getProvider: choice.get } : undefined)
6119
+ .then((u) => {
6120
+ if (u)
6121
+ succeed(u);
6122
+ else {
6123
+ b.disabled = false;
6124
+ walletLabel();
6125
+ setErr("Wallet login was cancelled.");
6126
+ }
6127
+ })
6128
+ .catch((err) => {
6129
+ b.disabled = false;
6130
+ walletLabel();
6131
+ setErr(errText(err));
6132
+ });
6133
+ };
6134
+ }
6135
+ card.appendChild(status);
6136
+ const foot = el("div", "foot");
6137
+ const poweredBy = el("a", undefined, "Powered by Bounded");
6138
+ poweredBy.href = "https://bounded.sh";
6139
+ poweredBy.target = "_blank";
6140
+ poweredBy.rel = "noopener";
6141
+ foot.appendChild(poweredBy);
6142
+ card.appendChild(foot);
6143
+ return card;
6144
+ };
6145
+ const renderWallets = () => {
6146
+ const card = el("div", "c");
6147
+ card.appendChild(style.cloneNode(true));
6148
+ const back = el("button", "back", "\u2190 Back");
6149
+ back.type = "button";
6150
+ back.addEventListener("click", () => swap(renderChoose()));
6151
+ card.appendChild(back);
6152
+ card.appendChild(el("h1", undefined, "Connect a wallet"));
6153
+ card.appendChild(el("p", "sub", "Choose your Solana wallet."));
6154
+ const status = el("div", "status");
6155
+ // Icon (the wallet's own, from the Wallet Standard registry) + name.
6156
+ const setWalletLabel = (b, choice) => {
6157
+ const text = document.createTextNode(choice.name);
6158
+ if (choice.icon) {
6159
+ const img = el("img", "wicon");
6160
+ img.src = choice.icon;
6161
+ img.alt = "";
6162
+ b.replaceChildren(img, text);
6163
+ }
6164
+ else {
6165
+ b.replaceChildren(text);
6166
+ }
6167
+ };
6168
+ for (const choice of wallets) {
6169
+ const b = el("button", "btn ghost");
6170
+ b.type = "button";
6171
+ setWalletLabel(b, choice);
6172
+ b.addEventListener("click", () => {
6173
+ status.classList.remove("err");
6174
+ b.disabled = true;
6175
+ b.replaceChildren(el("span", "spin"), document.createTextNode("Approve in your wallet\u2026"));
6176
+ authApi
6177
+ .loginWithWallet({ getProvider: choice.get })
6178
+ .then((u) => {
6179
+ if (u)
6180
+ succeed(u);
6181
+ else {
6182
+ b.disabled = false;
6183
+ setWalletLabel(b, choice);
6184
+ }
6185
+ })
6186
+ .catch((err) => {
6187
+ b.disabled = false;
6188
+ setWalletLabel(b, choice);
6189
+ status.textContent = errText(err);
6190
+ status.classList.add("err");
6191
+ });
6192
+ });
6193
+ card.appendChild(b);
6194
+ }
6195
+ card.appendChild(status);
6196
+ return card;
6197
+ };
6198
+ // authMode:"turnkey" inline code entry. Same editorial card; the code is sealed
6199
+ // on the Bounded signer origin and verified server-side by Turnkey.
6200
+ const renderOtp = (handle) => {
6201
+ const card = el("div", "c");
6202
+ card.appendChild(style.cloneNode(true));
6203
+ const back = el("button", "back", "\u2190 Back");
6204
+ back.type = "button";
6205
+ back.addEventListener("click", () => swap(renderChoose()));
6206
+ card.appendChild(back);
6207
+ card.appendChild(el("h1", undefined, "Enter your code"));
6208
+ card.appendChild(el("p", "sub", `We sent a 6-digit code to ${handle.email}.`));
6209
+ const status = el("div", "status");
6210
+ const setErr = (msg) => { status.textContent = msg; status.classList.add("err"); };
6211
+ const form = el("form");
6212
+ const label = el("label");
6213
+ label.htmlFor = "bw-otp";
6214
+ label.textContent = "Verification code";
6215
+ const input = el("input", "otp");
6216
+ input.id = "bw-otp";
6217
+ input.type = "text";
6218
+ input.inputMode = "numeric";
6219
+ input.autocomplete = "one-time-code";
6220
+ input.maxLength = 6;
6221
+ input.placeholder = "000000";
6222
+ input.required = true;
6223
+ const submit = el("button", "btn primary");
6224
+ submit.type = "submit";
6225
+ submit.textContent = "Verify";
6226
+ form.append(label, input, submit);
6227
+ const verify = () => {
6228
+ const code = input.value.replace(/\D+/g, "");
6229
+ if (code.length < 6) {
6230
+ setErr("Enter the 6-digit code.");
6231
+ return;
6232
+ }
6233
+ status.classList.remove("err");
6234
+ status.textContent = "";
6235
+ submit.disabled = true;
6236
+ input.disabled = true;
6237
+ submit.replaceChildren(el("span", "spin"), document.createTextNode("Verifying\u2026"));
6238
+ handle
6239
+ .verify(code)
6240
+ .then(succeed)
6241
+ .catch((err) => {
6242
+ submit.disabled = false;
6243
+ input.disabled = false;
6244
+ submit.textContent = "Verify";
6245
+ input.value = "";
6246
+ input.focus();
6247
+ setErr(errText(err));
6248
+ });
6249
+ };
6250
+ form.addEventListener("submit", (e) => { e.preventDefault(); verify(); });
6251
+ // Auto-submit once six digits are in - the buttery one-shot paste/type path.
6252
+ input.addEventListener("input", () => {
6253
+ if (input.value.replace(/\D+/g, "").length === 6 && !submit.disabled)
6254
+ verify();
6255
+ });
6256
+ card.appendChild(form);
6257
+ card.appendChild(status);
6258
+ const foot = el("div", "foot");
6259
+ const poweredBy = el("a", undefined, "Powered by Bounded");
6260
+ poweredBy.href = "https://bounded.sh";
6261
+ poweredBy.target = "_blank";
6262
+ poweredBy.rel = "noopener";
6263
+ foot.appendChild(poweredBy);
6264
+ card.appendChild(foot);
6265
+ requestAnimationFrame(() => input.focus());
6266
+ return card;
6267
+ };
6268
+ const swap = (node) => {
6269
+ mountContent(m, node);
6270
+ requestAnimationFrame(() => fitPanelToContent(m));
6271
+ };
6272
+ swap(renderChoose());
6273
+ showModal(m);
6274
+ });
6275
+ }
6276
+ function cap(s) {
6277
+ return s ? s[0].toUpperCase() + s.slice(1) : s;
6278
+ }
6279
+ function errText(err) {
6280
+ const msg = err instanceof Error ? err.message : String(err);
6281
+ if (/blocked/i.test(msg))
6282
+ return "Popup blocked - allow popups and try again.";
6283
+ return msg || "Something went wrong. Try again.";
6284
+ }
6285
+
6286
+ var _a$2;
5028
6287
  // Whether we're in a server-side rendering context (no hooks allowed).
5029
6288
  // React Native has no `window` but DOES support hooks.
5030
6289
  // We detect Node SSR specifically via process.versions.node to avoid
5031
6290
  // false positives from Node 21+ which defines `navigator` globally.
5032
- const isSSR$1 = typeof window === 'undefined'
6291
+ const isSSR$2 = typeof window === 'undefined'
5033
6292
  && typeof process !== 'undefined'
5034
- && !!((_a$1 = process.versions) === null || _a$1 === void 0 ? void 0 : _a$1.node);
6293
+ && !!((_a$2 = process.versions) === null || _a$2 === void 0 ? void 0 : _a$2.node);
5035
6294
  function useAuth() {
5036
6295
  // Provide a fallback so server render doesn't break
5037
- if (isSSR$1) {
6296
+ if (isSSR$2) {
5038
6297
  return {
5039
6298
  login: async (_options) => undefined,
5040
6299
  logout: async () => undefined,
@@ -5096,6 +6355,72 @@ function useAuth() {
5096
6355
  };
5097
6356
  }
5098
6357
 
6358
+ var _a$1;
6359
+ // SSR guard (mirrors useAuth): no hooks/subscriptions during Node server render.
6360
+ // React Native has no `window` but DOES support hooks, so detect Node SSR
6361
+ // specifically via process.versions.node.
6362
+ const isSSR$1 = typeof window === 'undefined'
6363
+ && typeof process !== 'undefined'
6364
+ && !!((_a$1 = process.versions) === null || _a$1 === void 0 ? void 0 : _a$1.node);
6365
+ function useQuery(path, options) {
6366
+ if (isSSR$1) {
6367
+ return { data: undefined, loading: true, error: null };
6368
+ }
6369
+ const [data, setData] = React__namespace.useState(undefined);
6370
+ const [loading, setLoading] = React__namespace.useState(true);
6371
+ const [error, setError] = React__namespace.useState(null);
6372
+ // Re-subscribe only when the query actually changes (not on every render).
6373
+ const optionsKey = options ? JSON.stringify(options) : '';
6374
+ React__namespace.useEffect(() => {
6375
+ if (!path) {
6376
+ setData(undefined);
6377
+ setLoading(false);
6378
+ setError(null);
6379
+ return;
6380
+ }
6381
+ let active = true;
6382
+ let unsubscribe;
6383
+ setLoading(true);
6384
+ setError(null);
6385
+ core.subscribe(path, Object.assign(Object.assign({}, options), { onData: (d) => {
6386
+ if (!active)
6387
+ return;
6388
+ // A reconnect can legitimately surface a transport error before the
6389
+ // socket re-authenticates and sends a new authorized snapshot. That
6390
+ // fresh snapshot is the recovery boundary: keep the error visible
6391
+ // until data arrives, then clear it so React does not remain stuck on
6392
+ // a failure page after realtime has recovered.
6393
+ setError(null);
6394
+ setData(d);
6395
+ setLoading(false);
6396
+ }, onError: (e) => {
6397
+ if (!active)
6398
+ return;
6399
+ setError(e instanceof Error ? e : new Error(String(e)));
6400
+ setLoading(false);
6401
+ } }))
6402
+ .then((unsub) => {
6403
+ if (active)
6404
+ unsubscribe = unsub;
6405
+ else
6406
+ void unsub(); // unmounted before subscribe resolved
6407
+ })
6408
+ .catch((e) => {
6409
+ if (!active)
6410
+ return;
6411
+ setError(e instanceof Error ? e : new Error(String(e)));
6412
+ setLoading(false);
6413
+ });
6414
+ return () => {
6415
+ active = false;
6416
+ void (unsubscribe === null || unsubscribe === void 0 ? void 0 : unsubscribe());
6417
+ };
6418
+ // optionsKey captures the option object's contents; path is the other input.
6419
+ // eslint-disable-next-line react-hooks/exhaustive-deps
6420
+ }, [path, optionsKey]);
6421
+ return { data, loading, error };
6422
+ }
6423
+
5099
6424
  // Wrapper for getIdToken - passes isServer=false for client-side usage
5100
6425
  async function getIdToken() {
5101
6426
  return core.getIdToken(false);
@@ -5376,9 +6701,11 @@ const BUILD_REVIEW_CAPABILITY_SCHEMA = 'bounded.build-review-capability.v1';
5376
6701
  const BUILD_REVIEW_CAPABILITY_REFRESH_SCHEMA = 'bounded.build-review-capability-refresh.v1';
5377
6702
  const BUILD_DELEGATED_REVIEW_CAPABILITY_SCHEMA = 'bounded.build-delegated-review-capability.v1';
5378
6703
 
6704
+ const FAST_POLL_MS = 1000;
5379
6705
  const NORMAL_POLL_MS = 2000;
5380
6706
  const PARKED_POLL_MS = 5000;
5381
6707
  const LONG_RUNNING_POLL_MS = 10000;
6708
+ const THIRTY_SECONDS_MS = 30000;
5382
6709
  const TWO_MINUTES_MS = 2 * 60000;
5383
6710
  const TEN_MINUTES_MS = 10 * 60000;
5384
6711
  const terminalStates = new Set(TERMINAL_STATES);
@@ -5387,6 +6714,10 @@ function pollCadence(state, elapsedMs) {
5387
6714
  return LONG_RUNNING_POLL_MS;
5388
6715
  if ((state === null || state === void 0 ? void 0 : state.startsWith('parked')) || elapsedMs >= TWO_MINUTES_MS)
5389
6716
  return PARKED_POLL_MS;
6717
+ // The first 30s is where the user is staring at "waiting for a build slot" /
6718
+ // "building" and every transition matters most; poll fast, then relax.
6719
+ if (elapsedMs < THIRTY_SECONDS_MS)
6720
+ return FAST_POLL_MS;
5390
6721
  return NORMAL_POLL_MS;
5391
6722
  }
5392
6723
  function retryCadence(error, state, elapsedMs) {
@@ -5472,9 +6803,18 @@ function watch(appId, runId, onUpdate, options = {}) {
5472
6803
  const poll = async () => {
5473
6804
  if (!active)
5474
6805
  return;
6806
+ // Fire the view and the events page concurrently: the events cursor (lastSeq)
6807
+ // does not depend on the run view, so there is no reason to pay two serial
6808
+ // round-trips per tick. Error semantics below are unchanged — the run result
6809
+ // still gates, and a failed events page still publishes the run with no rows.
6810
+ const runPromise = get(appId, runId);
6811
+ const eventsPromise = events(appId, runId, lastSeq);
6812
+ // Keep the in-flight events page from becoming an unhandled rejection if the
6813
+ // run result makes us bail before awaiting it; the real await below still sees it.
6814
+ eventsPromise.catch(() => { });
5475
6815
  let run;
5476
6816
  try {
5477
- const view = await get(appId, runId);
6817
+ const view = await runPromise;
5478
6818
  if (!active)
5479
6819
  return;
5480
6820
  run = view.run;
@@ -5492,7 +6832,7 @@ function watch(appId, runId, onUpdate, options = {}) {
5492
6832
  return;
5493
6833
  }
5494
6834
  try {
5495
- const response = await events(appId, runId, lastSeq);
6835
+ const response = await eventsPromise;
5496
6836
  if (!active)
5497
6837
  return;
5498
6838
  const deduped = newEvents(Array.isArray(response.events) ? response.events : [], lastSeq, seenSeqs);
@@ -5701,6 +7041,302 @@ async function deserializeTransaction(tx) {
5701
7041
  }
5702
7042
  }
5703
7043
 
7044
+ // turnkey-wallet-widget.ts - runs one Turnkey signer exchange inside the shared
7045
+ // in-app WIDGET (bounded-widget-modal.ts). The Bounded-owned signer page is loaded
7046
+ // in a warm iframe behind the modal so signing feels native: an in-app card plus
7047
+ // the OS Face ID / Touch ID sheet, never a jarring popup.
7048
+ //
7049
+ // WHY AN IFRAME: a WebAuthn passkey is bound to ONE origin, so passkey create/sign
7050
+ // MUST run on the single Bounded signer origin. The iframe carries the
7051
+ // publickey-credentials-{get,create} permission policy and the user's click lands
7052
+ // INSIDE it, giving WebAuthn the transient activation it needs.
7053
+ //
7054
+ // SAFARI / restricted embedders: cross-origin iframe passkey CREATE is unreliable
7055
+ // in Safari. The signer detects that and posts `fallbackPopup`; we then rerun the
7056
+ // SAME request through `popupFallback` (a real window). Callers pass a popup
7057
+ // implementation and never see the difference.
7058
+ /**
7059
+ * Run one signer exchange through the in-app widget. Resolves when `onResult`
7060
+ * accepts a result; falls back to `popupFallback` if the frame cannot run WebAuthn
7061
+ * (Safari cross-origin create) or cannot be mounted.
7062
+ */
7063
+ async function runWidget(url, signerOrigin, ex, popupFallback) {
7064
+ if (!hasDOM$2())
7065
+ return popupFallback();
7066
+ const m = getModal();
7067
+ const requestId = String(ex.request.requestId);
7068
+ // Serialize: WebAuthn is modal, and one warm frame handles one request at a time.
7069
+ const run = m.chain.then(() => new Promise((resolve, reject) => {
7070
+ let settled = false;
7071
+ let usedFallback = false;
7072
+ const iframe = ensureIframe(m, url, signerOrigin);
7073
+ const send = () => {
7074
+ if (!iframe.contentWindow)
7075
+ return;
7076
+ try {
7077
+ iframe.contentWindow.postMessage(ex.request, signerOrigin);
7078
+ }
7079
+ catch (_a) {
7080
+ /* frame gone */
7081
+ }
7082
+ };
7083
+ let loadTimer = 0;
7084
+ let ceilingTimer = 0;
7085
+ const finish = (fn) => {
7086
+ if (settled)
7087
+ return;
7088
+ settled = true;
7089
+ m.onIframeMessage = null;
7090
+ m.onBackdrop = null;
7091
+ window.clearTimeout(loadTimer);
7092
+ window.clearTimeout(ceilingTimer);
7093
+ fn();
7094
+ };
7095
+ const goFallback = () => {
7096
+ if (usedFallback || settled)
7097
+ return;
7098
+ usedFallback = true;
7099
+ hideModal(m);
7100
+ finish(() => popupFallback().then(resolve, reject));
7101
+ };
7102
+ m.onBackdrop = () => {
7103
+ hideModal(m);
7104
+ finish(() => reject(new Error("cancelled")));
7105
+ };
7106
+ m.onIframeMessage = (d) => {
7107
+ if (d.type === "bounded:turnkey:ready") {
7108
+ m.iframeReady = true;
7109
+ send();
7110
+ return;
7111
+ }
7112
+ if (d.type === "bounded:turnkey:resize" && typeof d.height === "number") {
7113
+ setPanelHeight(m, d.height);
7114
+ return;
7115
+ }
7116
+ if (d.type === "bounded:turnkey:fallbackPopup" && d.requestId === requestId) {
7117
+ goFallback();
7118
+ return;
7119
+ }
7120
+ if (d.type === "bounded:turnkey:result" && d.requestId === requestId) {
7121
+ const outcome = ex.onResult(d);
7122
+ if ("error" in outcome) {
7123
+ hideModal(m);
7124
+ finish(() => reject(new Error(outcome.error)));
7125
+ return;
7126
+ }
7127
+ if (outcome.done) {
7128
+ hideModal(m);
7129
+ finish(() => resolve(outcome.value));
7130
+ }
7131
+ }
7132
+ };
7133
+ showModal(m);
7134
+ if (m.iframeReady)
7135
+ send();
7136
+ // If the frame never loads, degrade to the popup (best-effort - a post-load
7137
+ // popup may be blocked without a gesture, in which case the fallback rejects).
7138
+ loadTimer = window.setTimeout(() => {
7139
+ if (!m.iframeReady && !settled)
7140
+ goFallback();
7141
+ }, 8000);
7142
+ // Absolute ceiling so a stuck flow cannot hang forever.
7143
+ ceilingTimer = window.setTimeout(() => {
7144
+ if (!settled) {
7145
+ hideModal(m);
7146
+ finish(() => reject(new Error("Wallet approval timed out.")));
7147
+ }
7148
+ }, 5 * 60 * 1000);
7149
+ }));
7150
+ m.chain = run.then(() => undefined, () => undefined);
7151
+ return run;
7152
+ }
7153
+
7154
+ // turnkey-signer-bridge.ts - routes NON-CUSTODIAL Turnkey embedded-wallet signing
7155
+ // through the Bounded-owned signer page (auth.bounded.sh/wallet/turnkey/signer).
7156
+ //
7157
+ // TRANSPORT: by default the signer runs inside the in-app WIDGET (turnkey-wallet-
7158
+ // widget.ts) - an iframe behind a Shadow-DOM modal that matches the Bounded widget
7159
+ // look + motion, so signing feels native. Safari (unreliable at iframe passkey
7160
+ // CREATE) and any environment where the frame cannot mount fall back to a real
7161
+ // popup window; both transports speak the same postMessage protocol.
7162
+ //
7163
+ // Unlike the Crossmint bridge (crossmint-signer-bridge.ts), Turnkey wallets DO
7164
+ // produce raw detached signatures: the signer runs the Turnkey browser SDK on the
7165
+ // single Bounded origin, enrolls the user's passkey on first use (lazy - the
7166
+ // sub-org is created with the passkey + email attached at that moment), and stamps
7167
+ // an ed25519 signRawPayload with that passkey. So this bridge exposes a
7168
+ // `signSolanaMessage` primitive; the app builds + submits the transaction itself.
7169
+ //
7170
+ // ONE ORIGIN, ONE PASSKEY: a WebAuthn passkey is bound to a single origin, so ALL
7171
+ // Bounded apps (any subdomain / custom domain) sign through this one origin - giving
7172
+ // every user one wallet + one passkey that roams across every app.
7173
+ function hasDOM() {
7174
+ return typeof window !== 'undefined' && typeof document !== 'undefined';
7175
+ }
7176
+ // Safari (incl. iOS WebViews) is unreliable at running a WebAuthn CREATE inside a
7177
+ // cross-origin iframe, so the widget's automatic in-iframe passkey enrollment can
7178
+ // fail - and a post-failure popup would no longer have a user gesture to open with.
7179
+ // There we pick the popup up front, from the original click, so enrollment is solid.
7180
+ // Everywhere else the inline widget is used (buttery in-app modal).
7181
+ function preferPopup() {
7182
+ if (!hasDOM() || typeof navigator === 'undefined')
7183
+ return true;
7184
+ const ua = navigator.userAgent || '';
7185
+ return /^((?!chrome|android|crios|fxios|edg|edga|opr).)*safari/i.test(ua);
7186
+ }
7187
+ // Dispatch one signer exchange through the in-app WIDGET, degrading to the POPUP
7188
+ // when we cannot embed (Safari enrollment, or the frame never loads).
7189
+ async function deliver(url, origin, ex) {
7190
+ const popup = () => runPopup(url, origin, ex);
7191
+ if (preferPopup())
7192
+ return popup();
7193
+ return runWidget(url, origin, { request: ex.request, onResult: ex.onResult }, popup);
7194
+ }
7195
+ async function turnkeySignerPage() {
7196
+ const cfg = await core.getConfig();
7197
+ const base = (cfg.humanAuthApiUrl || 'https://auth.bounded.sh').replace(/\/$/, '');
7198
+ return { url: `${base}/wallet/turnkey/signer`, origin: new URL(base).origin };
7199
+ }
7200
+ function toHex(bytes) {
7201
+ let h = '';
7202
+ for (const b of bytes)
7203
+ h += b.toString(16).padStart(2, '0');
7204
+ return h;
7205
+ }
7206
+ function fromHex(hex) {
7207
+ const clean = hex.startsWith('0x') ? hex.slice(2) : hex;
7208
+ const out = new Uint8Array(clean.length / 2);
7209
+ for (let i = 0; i < out.length; i++)
7210
+ out[i] = parseInt(clean.substr(i * 2, 2), 16);
7211
+ return out;
7212
+ }
7213
+ let requestSeq = 0;
7214
+ // Shared popup driver: open the signer page, do the ready/postMessage handshake, and
7215
+ // resolve when `onResult` accepts a result message. Origin + source are pinned.
7216
+ async function runPopup(url, signerOrigin, ex) {
7217
+ var _a, _b;
7218
+ const w = (_a = ex.width) !== null && _a !== void 0 ? _a : 420, h = (_b = ex.height) !== null && _b !== void 0 ? _b : 620;
7219
+ const left = window.screenX + Math.max(0, (window.outerWidth - w) / 2);
7220
+ const top = window.screenY + Math.max(0, (window.outerHeight - h) / 2);
7221
+ const popup = window.open(url, 'bounded-turnkey-signer', `width=${w},height=${h},left=${left},top=${top}`);
7222
+ if (!popup) {
7223
+ throw new Error('Popup blocked - call this from a user gesture (e.g. a click handler) so the passkey approval window can open.');
7224
+ }
7225
+ return await new Promise((resolve, reject) => {
7226
+ let settled = false;
7227
+ let sentRequest = false;
7228
+ let closeTimer;
7229
+ const cleanup = () => { settled = true; window.removeEventListener('message', onMsg); if (closeTimer)
7230
+ clearInterval(closeTimer); };
7231
+ const sendRequest = () => { if (sentRequest)
7232
+ return; sentRequest = true; try {
7233
+ popup.postMessage(ex.request, signerOrigin);
7234
+ }
7235
+ catch ( /* popup gone */_a) { /* popup gone */ } };
7236
+ const onMsg = (event) => {
7237
+ if (event.origin !== signerOrigin)
7238
+ return;
7239
+ if (event.source !== popup)
7240
+ return;
7241
+ const d = event.data;
7242
+ if (!d || typeof d !== 'object')
7243
+ return;
7244
+ if (d.type === 'bounded:turnkey:ready') {
7245
+ sendRequest();
7246
+ return;
7247
+ }
7248
+ if (d.type === 'bounded:turnkey:result' && d.requestId === ex.request.requestId) {
7249
+ const outcome = ex.onResult(d);
7250
+ if ('error' in outcome) {
7251
+ cleanup();
7252
+ try {
7253
+ popup.close();
7254
+ }
7255
+ catch ( /* ignore */_a) { /* ignore */ }
7256
+ reject(new Error(outcome.error));
7257
+ return;
7258
+ }
7259
+ if (outcome.done) {
7260
+ cleanup();
7261
+ try {
7262
+ popup.close();
7263
+ }
7264
+ catch ( /* ignore */_b) { /* ignore */ }
7265
+ resolve(outcome.value);
7266
+ }
7267
+ }
7268
+ };
7269
+ window.addEventListener('message', onMsg);
7270
+ setTimeout(sendRequest, 1200);
7271
+ closeTimer = setInterval(() => {
7272
+ if (popup.closed) {
7273
+ clearInterval(closeTimer);
7274
+ setTimeout(() => { if (!settled) {
7275
+ cleanup();
7276
+ reject(new Error('Wallet approval window was closed before it completed.'));
7277
+ } }, 400);
7278
+ }
7279
+ }, 500);
7280
+ setTimeout(() => { if (!settled) {
7281
+ cleanup();
7282
+ try {
7283
+ popup.close();
7284
+ }
7285
+ catch ( /* ignore */_a) { /* ignore */ }
7286
+ reject(new Error('Wallet approval timed out.'));
7287
+ } }, 5 * 60 * 1000);
7288
+ });
7289
+ }
7290
+ /**
7291
+ * Get-or-create the user's non-custodial Turnkey wallet, resolving with its stable
7292
+ * Solana address. On first use the popup enrolls a device passkey (Face ID / Touch ID)
7293
+ * and creates the wallet (lazy) with no email code; if the wallet already exists it
7294
+ * resolves immediately without a prompt. Call from a USER GESTURE.
7295
+ *
7296
+ * Use this to learn the fee-payer address BEFORE building a transaction to sign.
7297
+ */
7298
+ async function getOrCreateTurnkeyWallet() {
7299
+ if (!hasDOM())
7300
+ throw new Error('Turnkey embedded wallets are only available in the browser (popup-based).');
7301
+ const { url, origin } = await turnkeySignerPage();
7302
+ const requestId = `tkcreate_${Date.now()}_${++requestSeq}`;
7303
+ return await deliver(url, origin, {
7304
+ request: { type: 'bounded:turnkey:createWallet', requestId },
7305
+ onResult: (d) => {
7306
+ if (d.ok && typeof d.address === 'string')
7307
+ return { done: true, value: { address: d.address, subOrgId: String(d.subOrgId || '') } };
7308
+ return { error: String(d.error || 'Wallet setup failed') };
7309
+ },
7310
+ });
7311
+ }
7312
+ /**
7313
+ * Open the Bounded Turnkey signer popup and sign `message` (raw bytes) with the
7314
+ * user's non-custodial Turnkey wallet, resolving with the ed25519 signature +
7315
+ * the wallet address. MUST be called from a USER GESTURE (click/tap) or the
7316
+ * browser blocks the popup.
7317
+ *
7318
+ * On the user's FIRST signature the popup transparently enrolls a device passkey
7319
+ * (Face ID / Touch ID) and creates their wallet - no email code. Subsequent
7320
+ * signatures are just a passkey approval.
7321
+ */
7322
+ async function signSolanaMessageViaTurnkey(message) {
7323
+ if (!hasDOM()) {
7324
+ throw new Error('Turnkey embedded-wallet signing is only available in the browser (popup-based).');
7325
+ }
7326
+ const { url, origin } = await turnkeySignerPage();
7327
+ const requestId = `tksign_${Date.now()}_${++requestSeq}`;
7328
+ const messageHex = toHex(message);
7329
+ return await deliver(url, origin, {
7330
+ request: { type: 'bounded:turnkey:sign', requestId, messageHex },
7331
+ onResult: (d) => {
7332
+ if (d.ok && typeof d.signatureHex === 'string' && typeof d.address === 'string') {
7333
+ return { done: true, value: { signature: fromHex(d.signatureHex), address: d.address, subOrgId: String(d.subOrgId || '') } };
7334
+ }
7335
+ return { error: String(d.error || 'Turnkey signing failed') };
7336
+ },
7337
+ });
7338
+ }
7339
+
5704
7340
  /**
5705
7341
  * Extracts a human-readable error message from Solana transaction logs.
5706
7342
  */
@@ -6084,6 +7720,91 @@ class PrivyExpoProvider {
6084
7720
  }
6085
7721
  }
6086
7722
 
7723
+ /**
7724
+ * Default provider discovery: Phantom-first, then any Wallet-Standard
7725
+ * `window.solana`. Kept tiny + synchronous (no heavy imports) so it works inside
7726
+ * a user gesture and can be eagerly exported from the SDK entry.
7727
+ */
7728
+ function defaultInjectedProvider() {
7729
+ var _a;
7730
+ if (typeof window === 'undefined')
7731
+ return null;
7732
+ const w = window;
7733
+ const phantom = (_a = w === null || w === void 0 ? void 0 : w.phantom) === null || _a === void 0 ? void 0 : _a.solana;
7734
+ if (phantom && typeof phantom.signMessage === 'function')
7735
+ return phantom;
7736
+ const generic = w === null || w === void 0 ? void 0 : w.solana;
7737
+ if (generic && typeof generic.signMessage === 'function')
7738
+ return generic;
7739
+ return null;
7740
+ }
7741
+
7742
+ // injected-evm-wallet-types.ts — tiny, dependency-free surface for the EVM
7743
+ // WALLET LOGIN path (BYO wallet via SIWE). The EVM twin of
7744
+ // injected-wallet-types.ts: kept separate from injected-evm-wallet-provider.ts
7745
+ // so the SDK entry can eagerly export the type surface + the provider-discovery
7746
+ // helper WITHOUT dragging the provider class into the default bundle. The
7747
+ // provider is lazy-loaded by getAuthProvider() when an app opts into
7748
+ // authMethod:'evm-wallet'.
7749
+ //
7750
+ // It rides the standard EIP-1193 injected provider a browser wallet exposes
7751
+ // (MetaMask / Rabby / Coinbase Wallet / any window.ethereum), discovered via
7752
+ // EIP-6963 (multi-wallet, collision-free) with a window.ethereum fallback. It
7753
+ // needs NO viem/ethers and NO React — EIP-1193 request() + hex strings suffice.
7754
+ // EIP-6963 is announcement-based: wallets add an `eip6963:requestProvider`
7755
+ // listener and synchronously dispatch `eip6963:announceProvider` in response. We
7756
+ // keep a persistent collector so announcements (including late ones) are
7757
+ // captured, and re-request on demand.
7758
+ const announcedProviders = [];
7759
+ let announceListenerAttached = false;
7760
+ function attachAnnounceListener() {
7761
+ if (announceListenerAttached || typeof window === 'undefined')
7762
+ return;
7763
+ announceListenerAttached = true;
7764
+ window.addEventListener('eip6963:announceProvider', (event) => {
7765
+ const detail = event === null || event === void 0 ? void 0 : event.detail;
7766
+ if (detail &&
7767
+ detail.provider &&
7768
+ typeof detail.provider.request === 'function' &&
7769
+ !announcedProviders.some((d) => { var _a, _b; return ((_a = d.info) === null || _a === void 0 ? void 0 : _a.uuid) === ((_b = detail.info) === null || _b === void 0 ? void 0 : _b.uuid); })) {
7770
+ announcedProviders.push(detail);
7771
+ }
7772
+ });
7773
+ }
7774
+ /**
7775
+ * Request + collect EIP-6963 providers. Dispatches `eip6963:requestProvider`
7776
+ * (synchronous — already-loaded wallets announce in the same tick) and returns
7777
+ * every wallet announced so far. Kept synchronous so it works inside a user
7778
+ * gesture and can be eagerly exported from the SDK entry.
7779
+ */
7780
+ function requestEip6963Providers() {
7781
+ if (typeof window === 'undefined')
7782
+ return [];
7783
+ attachAnnounceListener();
7784
+ try {
7785
+ window.dispatchEvent(new Event('eip6963:requestProvider'));
7786
+ }
7787
+ catch (_a) {
7788
+ /* older browsers without Event constructor — fall through to window.ethereum */
7789
+ }
7790
+ return announcedProviders.slice();
7791
+ }
7792
+ /**
7793
+ * Default EVM provider discovery: EIP-6963 first (multi-wallet, collision-free),
7794
+ * then legacy `window.ethereum`. Returns null when no injected wallet is present.
7795
+ */
7796
+ function defaultInjectedEvmProvider() {
7797
+ if (typeof window === 'undefined')
7798
+ return null;
7799
+ const details = requestEip6963Providers();
7800
+ if (details.length > 0)
7801
+ return details[0].provider;
7802
+ const eth = window.ethereum;
7803
+ if (eth && typeof eth.request === 'function')
7804
+ return eth;
7805
+ return null;
7806
+ }
7807
+
6087
7808
  exports.BUILD_DELEGATED_REVIEW_CAPABILITY_SCHEMA = BUILD_DELEGATED_REVIEW_CAPABILITY_SCHEMA;
6088
7809
  exports.BUILD_REVIEW_CAPABILITY_REFRESH_SCHEMA = BUILD_REVIEW_CAPABILITY_REFRESH_SCHEMA;
6089
7810
  exports.BUILD_REVIEW_CAPABILITY_SCHEMA = BUILD_REVIEW_CAPABILITY_SCHEMA;
@@ -6103,6 +7824,8 @@ exports.builds = builds;
6103
7824
  exports.completeLoginFromRedirect = completeLoginFromRedirect;
6104
7825
  exports.completeLoginInPopup = completeLoginInPopup;
6105
7826
  exports.confirmAndCheckTransaction = confirmAndCheckTransaction;
7827
+ exports.defaultInjectedEvmProvider = defaultInjectedEvmProvider;
7828
+ exports.defaultInjectedProvider = defaultInjectedProvider;
6106
7829
  exports.deserializeTransaction = deserializeTransaction;
6107
7830
  exports.embeddedRunEvmTransaction = embeddedRunEvmTransaction;
6108
7831
  exports.embeddedSignAndSubmit = embeddedSignAndSubmit;
@@ -6110,6 +7833,7 @@ exports.getAuthLoading = getAuthLoading;
6110
7833
  exports.getAuthProvider = getAuthProvider;
6111
7834
  exports.getCurrentUser = getCurrentUser;
6112
7835
  exports.getIdToken = getIdToken;
7836
+ exports.getOrCreateTurnkeyWallet = getOrCreateTurnkeyWallet;
6113
7837
  exports.getPlatform = getPlatform;
6114
7838
  exports.hasEmbeddedEvmWallet = hasEmbeddedEvmWallet;
6115
7839
  exports.hasEmbeddedWallet = hasEmbeddedWallet;
@@ -6118,15 +7842,21 @@ exports.login = login;
6118
7842
  exports.loginWithPopup = loginWithPopup;
6119
7843
  exports.loginWithPrivy = loginWithPrivy;
6120
7844
  exports.loginWithRedirect = loginWithRedirect;
7845
+ exports.loginWithWallet = loginWithWallet;
6121
7846
  exports.logout = logout;
6122
7847
  exports.normalizeSolanaRpcUrl = normalizeSolanaRpcUrl;
6123
7848
  exports.onAuthLoadingChanged = onAuthLoadingChanged;
6124
7849
  exports.onAuthStateChanged = onAuthStateChanged;
7850
+ exports.openBoundedWidget = openBoundedWidget;
7851
+ exports.requestEip6963Providers = requestEip6963Providers;
6125
7852
  exports.resolveSolanaRpcUrl = resolveSolanaRpcUrl;
6126
7853
  exports.setAuthLoading = setAuthLoading;
6127
7854
  exports.setCurrentUser = setCurrentUser;
6128
7855
  exports.setPlatform = setPlatform;
6129
7856
  exports.signInAnonymously = signInAnonymously;
7857
+ exports.signSolanaMessageViaTurnkey = signSolanaMessageViaTurnkey;
7858
+ exports.startTurnkeyEmailLogin = startTurnkeyEmailLogin;
6130
7859
  exports.useAuth = useAuth;
6131
7860
  exports.useBuildRun = useBuildRun;
6132
- //# sourceMappingURL=index.native-CouprxZp.js.map
7861
+ exports.useQuery = useQuery;
7862
+ //# sourceMappingURL=index-CnObYQhV.js.map