@pooflabs/web 0.0.84 → 0.0.85-rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/dist/auth/providers/solana-mobile-wallet-provider.d.ts +47 -20
  2. package/dist/{index-BM6hgCdH.js → index-B1_Q49qQ.js} +2 -2
  3. package/dist/{index-BM6hgCdH.js.map → index-B1_Q49qQ.js.map} +1 -1
  4. package/dist/{index-CH2G5Y9i.esm.js → index-B7tJ8TAn.esm.js} +2 -2
  5. package/dist/{index-CH2G5Y9i.esm.js.map → index-B7tJ8TAn.esm.js.map} +1 -1
  6. package/dist/{index-BPlF6-PQ.js → index-BeFR3-cf.js} +522 -289
  7. package/dist/{index-BPlF6-PQ.js.map → index-BeFR3-cf.js.map} +1 -1
  8. package/dist/index-DbJCCvVN.esm.js +6 -0
  9. package/dist/index-DbJCCvVN.esm.js.map +1 -0
  10. package/dist/{index-CSeN3jbG.js → index-DflG_JAB.js} +3 -3
  11. package/dist/{index-CSeN3jbG.js.map → index-DflG_JAB.js.map} +1 -1
  12. package/dist/{index-Bp4b5LXs.js → index-DyRIXw-l.js} +2 -2
  13. package/dist/index-DyRIXw-l.js.map +1 -0
  14. package/dist/{index-XHbmzFFO.esm.js → index-QukWgaIi.esm.js} +523 -290
  15. package/dist/{index-XHbmzFFO.esm.js.map → index-QukWgaIi.esm.js.map} +1 -1
  16. package/dist/{index-ep10Sw82.esm.js → index-agGmWBn4.esm.js} +3 -3
  17. package/dist/{index-ep10Sw82.esm.js.map → index-agGmWBn4.esm.js.map} +1 -1
  18. package/dist/{index.browser-C1QL04xM.js → index.browser-BJmFjY2f.js} +1006 -15
  19. package/dist/index.browser-BJmFjY2f.js.map +1 -0
  20. package/dist/index.browser-DZtZWdul.js +4994 -0
  21. package/dist/index.browser-DZtZWdul.js.map +1 -0
  22. package/dist/index.browser-lHP9glAW.esm.js +6060 -0
  23. package/dist/index.browser-lHP9glAW.esm.js.map +1 -0
  24. package/dist/{index.browser-Cgj7Hs6n.esm.js → index.browser-p-pgsxxW.esm.js} +836 -916
  25. package/dist/index.browser-p-pgsxxW.esm.js.map +1 -0
  26. package/dist/index.esm.js +1 -1
  27. package/dist/index.js +1 -1
  28. package/dist/{index.native-BmtuyGXs.js → index.native-ANhb4jEB.js} +4 -4
  29. package/dist/{index.native-BmtuyGXs.js.map → index.native-ANhb4jEB.js.map} +1 -1
  30. package/dist/{index.native-X01vlukI.esm.js → index.native-a3mhu9HP.esm.js} +4 -4
  31. package/dist/{index.native-X01vlukI.esm.js.map → index.native-a3mhu9HP.esm.js.map} +1 -1
  32. package/dist/index.native.esm.js +1 -1
  33. package/dist/index.native.js +1 -1
  34. package/dist/{phantom-wallet-provider-C_LPU6Ns.js → phantom-wallet-provider-BOdn0D1Q.js} +4 -4
  35. package/dist/{phantom-wallet-provider-C_LPU6Ns.js.map → phantom-wallet-provider-BOdn0D1Q.js.map} +1 -1
  36. package/dist/{phantom-wallet-provider-DRvhBbbR.esm.js → phantom-wallet-provider-Dsza6TBv.esm.js} +4 -4
  37. package/dist/{phantom-wallet-provider-DRvhBbbR.esm.js.map → phantom-wallet-provider-Dsza6TBv.esm.js.map} +1 -1
  38. package/dist/{privy-wallet-provider-DQM8xO38.js → privy-wallet-provider-BlPh3Gn_.js} +3 -3
  39. package/dist/{privy-wallet-provider-DQM8xO38.js.map → privy-wallet-provider-BlPh3Gn_.js.map} +1 -1
  40. package/dist/{privy-wallet-provider-ZGu8q5T5.esm.js → privy-wallet-provider-bwwhkFjL.esm.js} +3 -3
  41. package/dist/{privy-wallet-provider-ZGu8q5T5.esm.js.map → privy-wallet-provider-bwwhkFjL.esm.js.map} +1 -1
  42. package/dist/solana-mobile-wallet-provider-S8yWHG6i.js +841 -0
  43. package/dist/solana-mobile-wallet-provider-S8yWHG6i.js.map +1 -0
  44. package/dist/solana-mobile-wallet-provider-fzLIgJBf.esm.js +820 -0
  45. package/dist/solana-mobile-wallet-provider-fzLIgJBf.esm.js.map +1 -0
  46. package/package.json +2 -1
  47. package/dist/index-Bp4b5LXs.js.map +0 -1
  48. package/dist/index-C80kRxWk.esm.js +0 -6
  49. package/dist/index-C80kRxWk.esm.js.map +0 -1
  50. package/dist/index.browser-BvNsUWjt.js +0 -105
  51. package/dist/index.browser-BvNsUWjt.js.map +0 -1
  52. package/dist/index.browser-BwIqqM4U.js +0 -1099
  53. package/dist/index.browser-BwIqqM4U.js.map +0 -1
  54. package/dist/index.browser-C1QL04xM.js.map +0 -1
  55. package/dist/index.browser-Cgj7Hs6n.esm.js.map +0 -1
  56. package/dist/index.browser-CifFI7Ju.esm.js +0 -1096
  57. package/dist/index.browser-CifFI7Ju.esm.js.map +0 -1
  58. package/dist/index.browser-D8VWPXTZ.esm.js +0 -102
  59. package/dist/index.browser-D8VWPXTZ.esm.js.map +0 -1
  60. package/dist/index.browser-OvGNsMPu.esm.js +0 -1002
  61. package/dist/index.browser-OvGNsMPu.esm.js.map +0 -1
  62. package/dist/index.browser-vuTr40so.js +0 -1008
  63. package/dist/index.browser-vuTr40so.js.map +0 -1
  64. package/dist/solana-mobile-wallet-provider-6gNw2_bX.js +0 -608
  65. package/dist/solana-mobile-wallet-provider-6gNw2_bX.js.map +0 -1
  66. package/dist/solana-mobile-wallet-provider-B65A7abd.esm.js +0 -587
  67. package/dist/solana-mobile-wallet-provider-B65A7abd.esm.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import globalAxios from 'axios';
2
- import { PublicKey, SystemProgram, TransactionInstruction, ComputeBudgetProgram, Keypair, VersionedTransaction, TransactionMessage, Transaction, Connection } from '@solana/web3.js';
2
+ import { PublicKey, SystemProgram, TransactionInstruction, ComputeBudgetProgram, Keypair, VersionedTransaction, TransactionMessage, Transaction, Connection, VersionedMessage } from '@solana/web3.js';
3
3
  import * as anchor from '@coral-xyz/anchor';
4
4
  import { Program } from '@coral-xyz/anchor';
5
5
  import * as React$2 from 'react';
@@ -12817,10 +12817,10 @@ let currentAuthProvider = null;
12817
12817
  let currentAuthMethod = null;
12818
12818
  let initConfig = null;
12819
12819
  // --- localStorage helpers: track which auth method the user last logged in with ---
12820
- const STORED_AUTH_METHOD_KEY = 'tarobase_last_auth_method';
12820
+ const STORED_AUTH_METHOD_KEY$1 = 'tarobase_last_auth_method';
12821
12821
  function getStoredAuthMethod() {
12822
12822
  try {
12823
- return getPlatform().storage.getItem(STORED_AUTH_METHOD_KEY);
12823
+ return getPlatform().storage.getItem(STORED_AUTH_METHOD_KEY$1);
12824
12824
  }
12825
12825
  catch (_a) {
12826
12826
  return null;
@@ -12829,10 +12829,10 @@ function getStoredAuthMethod() {
12829
12829
  function setStoredAuthMethod(method) {
12830
12830
  try {
12831
12831
  if (method) {
12832
- getPlatform().storage.setItem(STORED_AUTH_METHOD_KEY, method);
12832
+ getPlatform().storage.setItem(STORED_AUTH_METHOD_KEY$1, method);
12833
12833
  }
12834
12834
  else {
12835
- getPlatform().storage.removeItem(STORED_AUTH_METHOD_KEY);
12835
+ getPlatform().storage.removeItem(STORED_AUTH_METHOD_KEY$1);
12836
12836
  }
12837
12837
  }
12838
12838
  catch (_a) {
@@ -15709,7 +15709,7 @@ async function loadDependencies() {
15709
15709
  const [reactModule, reactDomModule, phantomModule] = await Promise.all([
15710
15710
  import('react'),
15711
15711
  import('react-dom/client'),
15712
- import('./index-CH2G5Y9i.esm.js')
15712
+ import('./index-B7tJ8TAn.esm.js')
15713
15713
  ]);
15714
15714
  // Extract default export from ESM module namespace
15715
15715
  // Dynamic import() returns { default: Module, ...exports }, not the module directly
@@ -21278,26 +21278,239 @@ function isMobileWalletAvailable() {
21278
21278
  return detectAndroid();
21279
21279
  }
21280
21280
  const ED25519_SIGNATURE_LENGTH = 64;
21281
- // Dynamically imported MWA protocol module
21282
- let mwaProtocolModule = null;
21283
- let mwaProtocolLoadPromise = null;
21284
- async function loadMwaProtocol() {
21285
- if (mwaProtocolModule)
21286
- return;
21287
- if (typeof window === 'undefined')
21288
- return;
21289
- if (mwaProtocolLoadPromise)
21290
- return mwaProtocolLoadPromise;
21291
- mwaProtocolLoadPromise = (async () => {
21281
+ const STORED_AUTH_METHOD_KEY = 'tarobase_last_auth_method';
21282
+ const MWA_AUTH_METHOD = 'mobile-wallet-adapter';
21283
+ function findMwaError(e, maxDepth = 5) {
21284
+ var _a;
21285
+ let cur = e;
21286
+ let depth = 0;
21287
+ while (cur && depth < maxDepth) {
21288
+ if ((cur === null || cur === void 0 ? void 0 : cur.name) === 'SolanaMobileWalletAdapterError' && typeof (cur === null || cur === void 0 ? void 0 : cur.code) === 'string') {
21289
+ return { code: cur.code, message: String((_a = cur.message) !== null && _a !== void 0 ? _a : '') };
21290
+ }
21291
+ cur = cur === null || cur === void 0 ? void 0 : cur.cause;
21292
+ depth++;
21293
+ }
21294
+ return null;
21295
+ }
21296
+ /**
21297
+ * Returns the matched MwaErrorInfo when the error is from an association
21298
+ * failure that an automatic retry can recover from (i.e. the wallet exists
21299
+ * on-device but the dApp's protocol session didn't complete in time). Returns
21300
+ * null for non-retryable errors (user cancel, unknown wallet errors, etc.).
21301
+ *
21302
+ * Specifically:
21303
+ * - ERROR_WALLET_NOT_FOUND: thrown from the protocol's startScenario when
21304
+ * it gave up waiting for a wallet to respond. On Seeker this races the
21305
+ * first-time-consent UI on the very first authorize.
21306
+ * - ERROR_SESSION_TIMEOUT: similar — the protocol's session-establishment
21307
+ * timer expired.
21308
+ * - ERROR_ASSOCIATION_CANCELLED: shared by user-cancel ("Wallet connection
21309
+ * cancelled by user") AND the 30s wallet-standard WALLET_ASSOCIATION_TIMEOUT
21310
+ * ("Wallet connection timed out"). Discriminate by message — never retry
21311
+ * a user cancel.
21312
+ */
21313
+ function isMwaAssociationRetryable(e) {
21314
+ const info = findMwaError(e);
21315
+ if (!info)
21316
+ return null;
21317
+ if (info.code === 'ERROR_WALLET_NOT_FOUND')
21318
+ return info;
21319
+ if (info.code === 'ERROR_SESSION_TIMEOUT')
21320
+ return info;
21321
+ if (info.code === 'ERROR_ASSOCIATION_CANCELLED' && /timed out/i.test(info.message))
21322
+ return info;
21323
+ return null;
21324
+ }
21325
+ /**
21326
+ * Single-retry wrapper for MWA association failures. Used ONLY for login's
21327
+ * `standard:connect` and `solana:signMessage` calls — never for
21328
+ * `signAndSendTransaction`/`runTransaction` because retry on a path that
21329
+ * may have already submitted a tx can double-send.
21330
+ *
21331
+ * The retry exists for one specific scenario: on first-time MWA usage from a
21332
+ * given origin on Seeker, the protocol's session-establishment timer races
21333
+ * Seeker's first-time consent UI. The user reads the consent sheet, taps
21334
+ * Connect — but by then the protocol has given up and thrown
21335
+ * ERROR_WALLET_NOT_FOUND. The consent itself IS persisted on Seeker though,
21336
+ * so a second attempt skips the consent sheet, jumps straight to
21337
+ * Verify/Approve, and completes inside the timeout.
21338
+ */
21339
+ async function withMwaAssociationRetry(label, fn) {
21340
+ const t0 = Date.now();
21341
+ console.log(`[MWA-DEBUG] ${label} attempt=1 start`);
21342
+ try {
21343
+ const result = await fn();
21344
+ console.log(`[MWA-DEBUG] ${label} attempt=1 ok (${Date.now() - t0}ms)`);
21345
+ return result;
21346
+ }
21347
+ catch (e) {
21348
+ const info = findMwaError(e);
21349
+ console.log(`[MWA-DEBUG] ${label} attempt=1 err (${Date.now() - t0}ms)`, {
21350
+ outer: { name: e === null || e === void 0 ? void 0 : e.name, message: e === null || e === void 0 ? void 0 : e.message },
21351
+ mwa: info,
21352
+ });
21353
+ const retryable = isMwaAssociationRetryable(e);
21354
+ if (!retryable)
21355
+ throw e;
21356
+ // Seeker's consent sheet is a bottom-sheet overlay — Chrome doesn't
21357
+ // reliably flip document.visibilityState to 'hidden' while it's open,
21358
+ // so visibility-based waits fire too early. Use a fixed delay long
21359
+ // enough for Seeker to dismiss its sheet and the OS to release intent
21360
+ // state. 2.5s is empirically safe; tune from device traces if needed.
21361
+ console.log(`[MWA-DEBUG] ${label} retryable (${retryable.code}); waiting 2500ms before retry`);
21362
+ await new Promise(r => setTimeout(r, 2500));
21363
+ const t1 = Date.now();
21364
+ console.log(`[MWA-DEBUG] ${label} attempt=2 start`);
21292
21365
  try {
21293
- mwaProtocolModule = await import('./index.browser-D8VWPXTZ.esm.js');
21366
+ const result = await fn();
21367
+ console.log(`[MWA-DEBUG] ${label} attempt=2 ok (${Date.now() - t1}ms)`);
21368
+ return result;
21294
21369
  }
21295
- catch (e) {
21296
- console.warn('[SolanaMobileWallet] @solana-mobile/mobile-wallet-adapter-protocol-web3js not installed. Install it to enable Seeker wallet support.');
21297
- throw new Error('Missing @solana-mobile/mobile-wallet-adapter-protocol-web3js dependency');
21370
+ catch (e2) {
21371
+ const info2 = findMwaError(e2);
21372
+ console.log(`[MWA-DEBUG] ${label} attempt=2 err (${Date.now() - t1}ms)`, {
21373
+ outer: { name: e2 === null || e2 === void 0 ? void 0 : e2.name, message: e2 === null || e2 === void 0 ? void 0 : e2.message },
21374
+ mwa: info2,
21375
+ });
21376
+ // Only mask the error with the clean Seeker message when the
21377
+ // second failure is also an association-flavored error. If it's
21378
+ // a user cancel, wallet rejection, or unknown error, rethrow
21379
+ // the original so the host app surfaces the real cause.
21380
+ if (isMwaAssociationRetryable(e2)) {
21381
+ throw new Error("Couldn't connect to your Seeker wallet. Please try again.");
21382
+ }
21383
+ throw e2;
21298
21384
  }
21299
- })();
21300
- return mwaProtocolLoadPromise;
21385
+ }
21386
+ }
21387
+ /**
21388
+ * Normalize a chain string to a wallet-standard Solana chain identifier.
21389
+ *
21390
+ * Handles three input shapes that all show up in practice:
21391
+ * - Bare cluster name from `SolanaMobileWalletConfig.cluster` (e.g. 'devnet').
21392
+ * - Prefixed `solana:cluster` (e.g. 'solana:devnet').
21393
+ * - Double-prefixed `solana:solana:cluster` (constructor used to wrap cluster
21394
+ * with `solana:` blindly; if a caller already passed a prefixed string the
21395
+ * result was `solana:solana:devnet`).
21396
+ *
21397
+ * Wallet-standard Solana chains are exactly:
21398
+ * 'solana:mainnet' | 'solana:devnet' | 'solana:testnet' | 'solana:localnet'
21399
+ * — `mainnet-beta` is NOT a valid wallet-standard identifier and must be
21400
+ * normalized to `solana:mainnet`.
21401
+ */
21402
+ function mapChainToWalletStandard(input) {
21403
+ if (!input)
21404
+ return 'solana:mainnet';
21405
+ let s = String(input).toLowerCase();
21406
+ while (s.startsWith('solana:'))
21407
+ s = s.slice('solana:'.length);
21408
+ if (s === 'mainnet-beta' || s === 'mainnet')
21409
+ return 'solana:mainnet';
21410
+ if (s === 'devnet')
21411
+ return 'solana:devnet';
21412
+ if (s === 'testnet')
21413
+ return 'solana:testnet';
21414
+ if (s === 'localnet')
21415
+ return 'solana:localnet';
21416
+ return 'solana:mainnet';
21417
+ }
21418
+ /**
21419
+ * Serialize a Transaction/VersionedTransaction to a Uint8Array wire payload
21420
+ * that the wallet-standard `solana:signTransaction` /
21421
+ * `solana:signAndSendTransaction` features expect.
21422
+ *
21423
+ * Legacy transactions must serialize with `requireAllSignatures: false` and
21424
+ * `verifySignatures: false` — the wallet hasn't signed yet, and the default
21425
+ * `serialize()` would throw "Signature verification failed". Versioned
21426
+ * transactions use the default `serialize()` which already permits unsigned
21427
+ * payloads. Mirrors the helper at
21428
+ * `@solana-mobile/mobile-wallet-adapter-protocol-web3js/lib/esm/index.browser.js:13-18`.
21429
+ */
21430
+ function txToWireBytes(tx) {
21431
+ if ('version' in tx)
21432
+ return tx.serialize();
21433
+ return tx.serialize({ requireAllSignatures: false, verifySignatures: false });
21434
+ }
21435
+ /**
21436
+ * Deserialize a wire-format transaction returned by the wallet
21437
+ * `solana:signTransaction` feature. Mirrors the helper at
21438
+ * `@solana-mobile/mobile-wallet-adapter-protocol-web3js/lib/esm/index.browser.js:19-23`
21439
+ * so legacy and versioned bytes both round-trip correctly.
21440
+ */
21441
+ function txFromWireBytes(byteArray) {
21442
+ const messageOffset = byteArray[0] * ED25519_SIGNATURE_LENGTH + 1;
21443
+ const messageVersion = VersionedMessage.deserializeMessageVersion(byteArray.slice(messageOffset, byteArray.length));
21444
+ if (messageVersion === 'legacy') {
21445
+ return Transaction.from(byteArray);
21446
+ }
21447
+ return VersionedTransaction.deserialize(byteArray);
21448
+ }
21449
+ /**
21450
+ * Per-method runtime narrowing of wallet-standard features. The wallet's
21451
+ * `.features` type is a union (`signAndSendTransaction` | `signTransaction`),
21452
+ * and after authorization the wallet may also narrow `#optionalFeatures`
21453
+ * based on actual wallet capabilities. Narrow at the call site so a method
21454
+ * that needs only `signMessage` doesn't fail when a wallet lacks
21455
+ * `signTransaction`.
21456
+ */
21457
+ function getSignMessageFeature(wallet) {
21458
+ const f = wallet.features;
21459
+ const feat = f['solana:signMessage'];
21460
+ if (!feat || typeof feat.signMessage !== 'function') {
21461
+ throw new Error('Wallet does not support solana:signMessage');
21462
+ }
21463
+ return feat;
21464
+ }
21465
+ function getSignTransactionFeature(wallet) {
21466
+ const f = wallet.features;
21467
+ const feat = f['solana:signTransaction'];
21468
+ if (!feat || typeof feat.signTransaction !== 'function') {
21469
+ throw new Error('Wallet does not support solana:signTransaction');
21470
+ }
21471
+ return feat;
21472
+ }
21473
+ function getSignAndSendTransactionFeature(wallet) {
21474
+ const f = wallet.features;
21475
+ const feat = f['solana:signAndSendTransaction'];
21476
+ if (!feat || typeof feat.signAndSendTransaction !== 'function') {
21477
+ throw new Error('Wallet does not support solana:signAndSendTransaction');
21478
+ }
21479
+ return feat;
21480
+ }
21481
+ function getConnectFeature(wallet) {
21482
+ const f = wallet.features;
21483
+ const feat = f['standard:connect'];
21484
+ if (!feat || typeof feat.connect !== 'function') {
21485
+ throw new Error('Wallet does not support standard:connect');
21486
+ }
21487
+ return feat;
21488
+ }
21489
+ function getDisconnectFeature(wallet) {
21490
+ const f = wallet.features;
21491
+ const feat = f['standard:disconnect'];
21492
+ return feat && typeof feat.disconnect === 'function' ? feat : null;
21493
+ }
21494
+ function writeAuthMethod(method) {
21495
+ try {
21496
+ if (method === null) {
21497
+ getPlatform().storage.removeItem(STORED_AUTH_METHOD_KEY);
21498
+ }
21499
+ else {
21500
+ getPlatform().storage.setItem(STORED_AUTH_METHOD_KEY, method);
21501
+ }
21502
+ }
21503
+ catch (_a) {
21504
+ // storage may be unavailable
21505
+ }
21506
+ }
21507
+ function readAuthMethod() {
21508
+ try {
21509
+ return getPlatform().storage.getItem(STORED_AUTH_METHOD_KEY);
21510
+ }
21511
+ catch (_a) {
21512
+ return null;
21513
+ }
21301
21514
  }
21302
21515
  /**
21303
21516
  * Registers Mobile Wallet Adapter as a wallet-standard wallet so it appears
@@ -21308,11 +21521,11 @@ async function loadMwaProtocol() {
21308
21521
  * @param config - App identity and optional remote host authority for desktop QR code support
21309
21522
  */
21310
21523
  async function registerMobileWalletAdapter(config) {
21311
- var _a;
21524
+ var _a, _b;
21312
21525
  if (typeof window === 'undefined')
21313
21526
  return;
21314
21527
  try {
21315
- const walletStandardMobile = await import('./index.browser-Cgj7Hs6n.esm.js');
21528
+ const walletStandardMobile = await import('./index.browser-lHP9glAW.esm.js');
21316
21529
  const registerMwa = walletStandardMobile.registerMwa || ((_a = walletStandardMobile.default) === null || _a === void 0 ? void 0 : _a.registerMwa);
21317
21530
  if (!registerMwa) {
21318
21531
  console.warn('[SolanaMobileWallet] registerMwa not found in @solana-mobile/wallet-standard-mobile');
@@ -21335,38 +21548,50 @@ async function registerMobileWalletAdapter(config) {
21335
21548
  if (walletStandardMobile.createDefaultChainSelector) {
21336
21549
  options.chainSelector = walletStandardMobile.createDefaultChainSelector();
21337
21550
  }
21338
- if (walletStandardMobile.createDefaultWalletNotFoundHandler) {
21339
- options.onWalletNotFound = walletStandardMobile.createDefaultWalletNotFoundHandler();
21340
- }
21551
+ // Default: suppress the "We can't find a wallet" modal — see
21552
+ // SolanaMobileWalletProvider.ensureWallet() for why. Consumers that
21553
+ // want their own UX can pass config.onWalletNotFound.
21554
+ options.onWalletNotFound = (_b = config === null || config === void 0 ? void 0 : config.onWalletNotFound) !== null && _b !== void 0 ? _b : (async () => {
21555
+ console.warn('[MWA-DEBUG] registerMobileWalletAdapter onWalletNotFound (suppressed)');
21556
+ });
21341
21557
  registerMwa(options);
21342
21558
  }
21343
21559
  catch (e) {
21344
- // @solana-mobile/wallet-standard-mobile is an optional dependency
21345
- // Silently skip if not installed — the provider still works via
21346
- // @solana-mobile/mobile-wallet-adapter-protocol-web3js directly
21347
21560
  console.debug('[SolanaMobileWallet] @solana-mobile/wallet-standard-mobile not available, skipping wallet-standard registration');
21348
21561
  }
21349
21562
  }
21350
21563
  /**
21351
- * SolanaMobileWalletProvider implements the AuthProvider interface using the
21352
- * Solana Mobile Wallet Adapter (MWA) protocol's low-level `transact` API.
21564
+ * SolanaMobileWalletProvider implements the AuthProvider interface using
21565
+ * Solana Mobile's wallet-standard wrapper (`LocalSolanaMobileWalletAdapterWallet`).
21566
+ *
21567
+ * Why wallet-standard and not the raw MWA protocol: as of
21568
+ * `@solana-mobile/wallet-standard-mobile@0.5.0+`, the wallet's internal
21569
+ * `#transact` calls `checkLocalNetworkAccessPermission()` before opening the
21570
+ * localhost WebSocket. That helper renders a three-stage UX flow Solana
21571
+ * Mobile designed specifically to defuse Chrome's Local Network Access
21572
+ * permission dialog (which renders with disabled buttons on Android Chrome,
21573
+ * the source of the long-running Seeker MWA bug):
21574
+ *
21575
+ * 1. "Allow connections to your wallet" informational modal.
21576
+ * 2. Chrome's permission prompt (interactive because it's spawned as a
21577
+ * fresh user gesture from step 1).
21578
+ * 3. "Ready to connect!" success modal.
21353
21579
  *
21354
- * This enables TaroBase dApps to work with any MWA-compliant wallet on Solana
21355
- * mobile devices (Seeker, Saga) including the native Seed Vault Wallet,
21356
- * Phantom, Solflare, and any other wallet that implements the MWA protocol.
21580
+ * `checkLocalNetworkAccessPermission` is internal to the library it's not
21581
+ * exported. The only way to invoke it is to go through the wallet's
21582
+ * `standard:connect` / `solana:sign*` features, which is what this provider
21583
+ * does.
21357
21584
  *
21358
- * By using `transact()` directly (instead of the wallet-adapter wrapper),
21359
- * login combines authorize + signMessage into a single wallet session —
21360
- * meaning one popup/approval instead of two.
21585
+ * Notes on UX: login uses two wallet popups in succession — `standard:connect`
21586
+ * (authorize) and `solana:signMessage` (sign the Tarobase nonce). The
21587
+ * previous implementation combined both inside a single `transact` callback;
21588
+ * splitting them is the cost of going through wallet-standard, and is
21589
+ * acceptable given the alternative was broken on Seeker.
21361
21590
  */
21362
21591
  class SolanaMobileWalletProvider {
21363
21592
  constructor(networkUrl = null, config = {}) {
21364
- // MWA authorization state
21365
- this.authToken = null;
21366
- this.walletUriBase = null;
21367
- this.base64Address = null;
21368
- this.authorizedPublicKey = null;
21369
- this.publicKeyObj = null;
21593
+ /** LocalSolanaMobileWalletAdapterWallet, lazy-constructed in ensureWallet(). */
21594
+ this.wallet = null;
21370
21595
  this.networkUrl = networkUrl;
21371
21596
  this.config = config;
21372
21597
  if (typeof window === 'undefined') {
@@ -21379,7 +21604,7 @@ class SolanaMobileWalletProvider {
21379
21604
  name: 'TaroBase App',
21380
21605
  uri: getPlatform().getLocationOrigin(),
21381
21606
  };
21382
- this.chain = `solana:${config.cluster || 'mainnet-beta'}`;
21607
+ this.cluster = config.cluster || 'mainnet-beta';
21383
21608
  SolanaMobileWalletProvider.instance = this;
21384
21609
  }
21385
21610
  static getInstance(networkUrl, config) {
@@ -21388,154 +21613,136 @@ class SolanaMobileWalletProvider {
21388
21613
  }
21389
21614
  return SolanaMobileWalletProvider.instance;
21390
21615
  }
21391
- /** Config for transact() routes to the same wallet if we've already authorized */
21392
- getAssociationConfig() {
21393
- if (this.walletUriBase) {
21394
- return { baseUri: this.walletUriBase };
21395
- }
21396
- return undefined;
21616
+ /** Lazy-construct LocalSolanaMobileWalletAdapterWallet on first need. */
21617
+ async ensureWallet() {
21618
+ if (this.wallet)
21619
+ return this.wallet;
21620
+ const mod = await import('./index.browser-lHP9glAW.esm.js');
21621
+ const chain = mapChainToWalletStandard(this.cluster);
21622
+ this.wallet = new mod.LocalSolanaMobileWalletAdapterWallet({
21623
+ appIdentity: this.appIdentity,
21624
+ authorizationCache: mod.createDefaultAuthorizationCache(),
21625
+ chains: [chain],
21626
+ chainSelector: mod.createDefaultChainSelector(),
21627
+ // Suppress the default "We can't find a wallet" modal — that
21628
+ // modal is misleading when ERROR_WALLET_NOT_FOUND fires during
21629
+ // a first-time-consent race on Seeker (the wallet IS installed,
21630
+ // the protocol just gave up before the user finished consenting).
21631
+ // login()'s withMwaAssociationRetry handles this case; on second
21632
+ // failure it surfaces a clean error message to the host app.
21633
+ onWalletNotFound: async () => {
21634
+ console.warn('[MWA-DEBUG] ensureWallet onWalletNotFound (suppressed)');
21635
+ },
21636
+ });
21637
+ return this.wallet;
21397
21638
  }
21398
- /** Reauthorize within a transact callback using a stored auth_token */
21399
- async reauthorizeWallet(wallet) {
21400
- if (!this.authToken) {
21401
- // No existing auth do a fresh authorize
21402
- const authResult = await wallet.authorize({
21403
- identity: this.appIdentity,
21404
- chain: this.chain,
21405
- });
21406
- this.storeAuthResult(authResult);
21407
- return authResult;
21639
+ /**
21640
+ * Ensure the wallet has an active authorization. After a Tarobase session
21641
+ * is restored from storage on cold-start, `wallet.accounts` is empty until
21642
+ * we silently reconnect from the AuthorizationCache. If the cache is also
21643
+ * empty, fall back to interactive `login()` (which surfaces the three-stage
21644
+ * Solana Mobile LNA flow + wallet popups).
21645
+ *
21646
+ * Returns the wallet-standard `WalletAccount` to use for sign operations.
21647
+ */
21648
+ async ensureAuthorized() {
21649
+ const wallet = await this.ensureWallet();
21650
+ if (wallet.accounts.length === 0) {
21651
+ try {
21652
+ const connectFeat = getConnectFeature(wallet);
21653
+ await connectFeat.connect({ silent: true });
21654
+ }
21655
+ catch (e) {
21656
+ console.warn('[SolanaMobileWallet] silent connect failed:', e === null || e === void 0 ? void 0 : e.message);
21657
+ }
21408
21658
  }
21409
- try {
21410
- const authResult = await wallet.reauthorize({
21411
- auth_token: this.authToken,
21412
- identity: this.appIdentity,
21413
- });
21414
- this.storeAuthResult(authResult);
21415
- return authResult;
21416
- }
21417
- catch (e) {
21418
- // Reauth failed (token expired, wallet reset, etc.) — try fresh authorize
21419
- console.warn('[SolanaMobileWallet] Reauthorization failed, attempting fresh authorize:', e === null || e === void 0 ? void 0 : e.message);
21420
- const authResult = await wallet.authorize({
21421
- identity: this.appIdentity,
21422
- chain: this.chain,
21423
- });
21424
- this.storeAuthResult(authResult);
21425
- return authResult;
21659
+ if (wallet.accounts.length === 0) {
21660
+ const user = await this.login();
21661
+ if (!user)
21662
+ throw new Error('MWA not connected');
21426
21663
  }
21664
+ return wallet.accounts[0];
21427
21665
  }
21428
- /** Persist auth result from an authorize/reauthorize call */
21429
- storeAuthResult(authResult) {
21430
- var _a;
21431
- this.authToken = authResult.auth_token;
21432
- this.walletUriBase = authResult.wallet_uri_base;
21433
- if (((_a = authResult.accounts) === null || _a === void 0 ? void 0 : _a.length) > 0) {
21434
- const account = authResult.accounts[0];
21435
- this.base64Address = account.address;
21436
- // Decode base64 address → PublicKey → base58
21437
- const addressBytes = Uint8Array.from(getPlatform().atob(account.address), c => c.charCodeAt(0));
21438
- this.publicKeyObj = new PublicKey(addressBytes);
21439
- this.authorizedPublicKey = this.publicKeyObj.toBase58();
21440
- }
21666
+ /** Returns the active wallet-standard chain identifier (e.g. 'solana:mainnet'). */
21667
+ getChain() {
21668
+ return mapChainToWalletStandard(this.cluster);
21441
21669
  }
21442
21670
  async login() {
21443
21671
  var _a, _b, _c, _d, _e;
21444
21672
  setAuthLoading(true);
21445
- // Mark the auth method early so a concurrent Phantom auto-create can see
21446
- // 'mobile-wallet-adapter' during our slow transact() / session-creation
21447
- // roundtrip and back off (see phantom-wallet-provider autoCreateSession).
21448
- // Capture the previous value so we can restore it if login fails.
21449
- let prevAuthMethod = null;
21450
- try {
21451
- prevAuthMethod = getPlatform().storage.getItem('tarobase_last_auth_method');
21452
- }
21453
- catch (_f) { }
21454
- try {
21455
- getPlatform().storage.setItem('tarobase_last_auth_method', 'mobile-wallet-adapter');
21456
- }
21457
- catch (_g) { }
21673
+ // Mark the auth method early so a concurrent Phantom auto-create-session
21674
+ // effect (see phantom-wallet-provider) sees 'mobile-wallet-adapter'
21675
+ // during our slow connect/sign roundtrip and backs off. Capture the
21676
+ // previous value so we can restore it if login fails.
21677
+ const prevAuthMethod = readAuthMethod();
21678
+ writeAuthMethod(MWA_AUTH_METHOD);
21458
21679
  try {
21459
- await loadMwaProtocol();
21460
- const { transact } = mwaProtocolModule;
21461
- // Quick check: if we already have auth state and a valid session, skip
21462
- if (this.authorizedPublicKey) {
21680
+ const wallet = await this.ensureWallet();
21681
+ // Quick-check: wallet may already have authorization (e.g. from a
21682
+ // previous in-page login) and a matching Tarobase session skip
21683
+ // popups in that case.
21684
+ if (wallet.accounts.length > 0) {
21685
+ const accountPubkey = new PublicKey(wallet.accounts[0].publicKey);
21686
+ const base58Addr = accountPubkey.toBase58();
21463
21687
  const existingSession = await WebSessionManager.getSession();
21464
- if (existingSession && existingSession.address === this.authorizedPublicKey) {
21465
- const user = { provider: this, address: this.authorizedPublicKey };
21688
+ if (existingSession && existingSession.address === base58Addr) {
21689
+ const user = { provider: this, address: base58Addr };
21466
21690
  setCurrentUser(user);
21467
21691
  return user;
21468
21692
  }
21469
21693
  }
21470
- // Pre-fetch nonce from server while wallet is not yet connected
21694
+ // Pre-fetch nonce while the wallet popup is not yet open.
21471
21695
  const nonce = await genAuthNonce();
21472
- // Single transact() call: authorize + signMessages one wallet popup
21473
- const result = await transact(async (wallet) => {
21474
- // Step 1: Authorize user approves the dApp
21475
- const authResult = await wallet.authorize({
21476
- identity: this.appIdentity,
21477
- chain: this.chain,
21478
- });
21479
- const base64Addr = authResult.accounts[0].address;
21480
- const addressBytes = Uint8Array.from(getPlatform().atob(base64Addr), c => c.charCodeAt(0));
21481
- const pubkey = new PublicKey(addressBytes);
21482
- const base58Addr = pubkey.toBase58();
21483
- // Step 2: Sign the auth message — still in the same wallet session
21484
- const messageText = await genSolanaMessage(base58Addr, nonce);
21485
- const messageBytes = getPlatform().textEncode(messageText);
21486
- const signedMessages = await wallet.signMessages({
21487
- addresses: [base64Addr],
21488
- payloads: [messageBytes],
21489
- });
21490
- // The signed payload is [original message bytes][64-byte ed25519 signature]
21491
- const signedPayload = signedMessages[0];
21492
- const signatureBytes = signedPayload.slice(-ED25519_SIGNATURE_LENGTH);
21493
- return {
21494
- base58Address: base58Addr,
21495
- base64Address: base64Addr,
21496
- publicKey: pubkey,
21497
- signature: bufferExports.Buffer.from(signatureBytes).toString('base64'),
21498
- messageText,
21499
- authToken: authResult.auth_token,
21500
- walletUriBase: authResult.wallet_uri_base,
21501
- };
21502
- }, this.getAssociationConfig());
21503
- // Store MWA auth state for reauthorization in subsequent transact() calls
21504
- this.authToken = result.authToken;
21505
- this.walletUriBase = result.walletUriBase;
21506
- this.base64Address = result.base64Address;
21507
- this.authorizedPublicKey = result.base58Address;
21508
- this.publicKeyObj = result.publicKey;
21509
- // Check if we already have a valid session for this address
21696
+ // Wallet popup #1: standard:connect performs MWA authorize. This
21697
+ // is where wallet-standard's checkLocalNetworkAccessPermission()
21698
+ // fires the three-stage LNA UX (info modal → permission prompt →
21699
+ // success modal) before opening the localhost WebSocket.
21700
+ //
21701
+ // Wrap with single-retry: on a Seeker origin's first MWA usage,
21702
+ // the protocol's session-establishment timer often races Seeker's
21703
+ // first-time consent UI and throws ERROR_WALLET_NOT_FOUND before
21704
+ // the user finishes tapping. The retry hits Seeker's cached
21705
+ // consent on the second pass and completes quickly. See
21706
+ // withMwaAssociationRetry for details.
21707
+ const connectFeat = getConnectFeature(wallet);
21708
+ const { accounts } = await withMwaAssociationRetry('login:connect', () => connectFeat.connect());
21709
+ if (!accounts || accounts.length === 0) {
21710
+ throw new Error('MWA returned no accounts');
21711
+ }
21712
+ const account = accounts[0];
21713
+ const accountPubkey = new PublicKey(account.publicKey);
21714
+ const base58Addr = accountPubkey.toBase58();
21715
+ // If we happen to already have a matching Tarobase session, reuse it.
21510
21716
  const existingSession = await WebSessionManager.getSession();
21511
- if (existingSession && existingSession.address === result.base58Address) {
21512
- const user = { provider: this, address: result.base58Address };
21717
+ if (existingSession && existingSession.address === base58Addr) {
21718
+ const user = { provider: this, address: base58Addr };
21513
21719
  setCurrentUser(user);
21514
21720
  return user;
21515
21721
  }
21516
- // Create new session on the server
21517
- const createSessionResult = await createSessionWithSignature(result.base58Address, result.messageText, result.signature);
21518
- await WebSessionManager.storeSession(result.base58Address, createSessionResult.accessToken, createSessionResult.idToken, createSessionResult.refreshToken);
21519
- // Mark auth method
21520
- try {
21521
- getPlatform().storage.setItem('tarobase_last_auth_method', 'mobile-wallet-adapter');
21722
+ // Wallet popup #2: sign the Tarobase nonce message. Wrap with the
21723
+ // same retry for defense in depth — by now Seeker has cached the
21724
+ // consent so this rarely hits the retry path, but if the
21725
+ // protocol's session timer fires here too we recover transparently.
21726
+ const messageText = await genSolanaMessage(base58Addr, nonce);
21727
+ const messageBytes = getPlatform().textEncode(messageText);
21728
+ const signMessageFeat = getSignMessageFeature(wallet);
21729
+ const signResults = await withMwaAssociationRetry('login:signMessage', () => signMessageFeat.signMessage({ account, message: messageBytes }));
21730
+ if (!signResults || signResults.length === 0) {
21731
+ throw new Error('MWA returned no signature');
21522
21732
  }
21523
- catch (_h) { }
21524
- const user = { provider: this, address: result.base58Address };
21733
+ const { signature: sigBytes } = signResults[0];
21734
+ const signatureBase64 = bufferExports.Buffer.from(sigBytes).toString('base64');
21735
+ // Create Tarobase session on the server.
21736
+ const createSessionResult = await createSessionWithSignature(base58Addr, messageText, signatureBase64);
21737
+ await WebSessionManager.storeSession(base58Addr, createSessionResult.accessToken, createSessionResult.idToken, createSessionResult.refreshToken);
21738
+ // Auth-method marker is already 'mobile-wallet-adapter' from above.
21739
+ const user = { provider: this, address: base58Addr };
21525
21740
  setCurrentUser(user);
21526
21741
  return user;
21527
21742
  }
21528
21743
  catch (error) {
21529
- // Restore the previous auth method since this login attempt failed.
21530
- try {
21531
- if (prevAuthMethod === null) {
21532
- getPlatform().storage.removeItem('tarobase_last_auth_method');
21533
- }
21534
- else {
21535
- getPlatform().storage.setItem('tarobase_last_auth_method', prevAuthMethod);
21536
- }
21537
- }
21538
- catch (_j) { }
21744
+ // Restore the previous auth-method marker since this login attempt failed.
21745
+ writeAuthMethod(prevAuthMethod);
21539
21746
  const isUserRejection = (error === null || error === void 0 ? void 0 : error.code) === 4001 ||
21540
21747
  ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes('user rejected')) ||
21541
21748
  ((_b = error === null || error === void 0 ? void 0 : error.message) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes('user denied')) ||
@@ -21554,61 +21761,42 @@ class SolanaMobileWalletProvider {
21554
21761
  async restoreSession() {
21555
21762
  const session = await WebSessionManager.getSession();
21556
21763
  if (session) {
21557
- this.authorizedPublicKey = session.address;
21558
- this.publicKeyObj = new PublicKey(session.address);
21559
21764
  return { provider: this, address: session.address };
21560
21765
  }
21561
21766
  return null;
21562
21767
  }
21563
21768
  async logout() {
21564
- // Deauthorize with the wallet if we have an auth_token
21565
- if (this.authToken) {
21566
- try {
21567
- await loadMwaProtocol();
21568
- const { transact } = mwaProtocolModule;
21569
- const authToken = this.authToken;
21570
- await transact(async (wallet) => {
21571
- await wallet.deauthorize({ auth_token: authToken });
21572
- }, this.getAssociationConfig());
21573
- }
21574
- catch (error) {
21575
- console.error('[SolanaMobileWallet] Deauthorize error:', error);
21769
+ try {
21770
+ const wallet = await this.ensureWallet();
21771
+ const disconnectFeat = getDisconnectFeature(wallet);
21772
+ if (disconnectFeat) {
21773
+ // Disconnect clears the AuthorizationCache and resets
21774
+ // wallet.#authorization internally (no LNA dialog).
21775
+ await disconnectFeat.disconnect();
21576
21776
  }
21577
21777
  }
21578
- this.authToken = null;
21579
- this.walletUriBase = null;
21580
- this.base64Address = null;
21581
- this.authorizedPublicKey = null;
21582
- this.publicKeyObj = null;
21778
+ catch (error) {
21779
+ console.error('[SolanaMobileWallet] Disconnect error:', error);
21780
+ }
21583
21781
  WebSessionManager.clearSession();
21584
21782
  // Clear the auth-method marker so Phantom auto-create is unblocked
21585
21783
  // for any subsequent fresh login on this device.
21586
- try {
21587
- getPlatform().storage.removeItem('tarobase_last_auth_method');
21588
- }
21589
- catch (_a) { }
21784
+ writeAuthMethod(null);
21590
21785
  setCurrentUser(null);
21591
21786
  }
21592
21787
  async signMessage(message) {
21593
21788
  var _a, _b;
21594
- if (!this.authorizedPublicKey || !this.base64Address) {
21595
- throw new Error('Not connected. Call login() first.');
21596
- }
21597
- await loadMwaProtocol();
21598
- const { transact } = mwaProtocolModule;
21599
- const base64Addr = this.base64Address;
21789
+ const account = await this.ensureAuthorized();
21790
+ const wallet = await this.ensureWallet();
21600
21791
  try {
21601
- const signedMessages = await transact(async (wallet) => {
21602
- await this.reauthorizeWallet(wallet);
21603
- const messageBytes = getPlatform().textEncode(message);
21604
- return wallet.signMessages({
21605
- addresses: [base64Addr],
21606
- payloads: [messageBytes],
21607
- });
21608
- }, this.getAssociationConfig());
21609
- const signedPayload = signedMessages[0];
21610
- const signatureBytes = signedPayload.slice(-ED25519_SIGNATURE_LENGTH);
21611
- return bufferExports.Buffer.from(signatureBytes).toString('base64');
21792
+ const signMessageFeat = getSignMessageFeature(wallet);
21793
+ const messageBytes = getPlatform().textEncode(message);
21794
+ const results = await signMessageFeat.signMessage({ account, message: messageBytes });
21795
+ if (!results || results.length === 0) {
21796
+ throw new Error('MWA returned no signature');
21797
+ }
21798
+ const { signature: sigBytes } = results[0];
21799
+ return bufferExports.Buffer.from(sigBytes).toString('base64');
21612
21800
  }
21613
21801
  catch (error) {
21614
21802
  if (((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes('not connected')) || ((_b = error === null || error === void 0 ? void 0 : error.message) === null || _b === void 0 ? void 0 : _b.includes('not authorized')) ||
@@ -21621,41 +21809,42 @@ class SolanaMobileWalletProvider {
21621
21809
  }
21622
21810
  async signTransaction(transaction) {
21623
21811
  var _a, _b;
21624
- if (!this.publicKeyObj) {
21625
- throw new Error('Not connected. Call login() first.');
21626
- }
21627
- await loadMwaProtocol();
21628
- const { transact } = mwaProtocolModule;
21629
- // Ensure blockhash and fee payer are set before signing
21812
+ const account = await this.ensureAuthorized();
21813
+ const connectedPubkey = new PublicKey(account.publicKey);
21814
+ const wallet = await this.ensureWallet();
21815
+ const chain = this.getChain();
21816
+ // Preserve existing prep: fill missing blockhash / fee payer so call
21817
+ // sites that build a tx without these fields don't regress.
21630
21818
  const isLegacyTransaction = 'recentBlockhash' in transaction && !('message' in transaction && 'staticAccountKeys' in transaction.message);
21631
21819
  if (isLegacyTransaction) {
21632
21820
  const legacyTx = transaction;
21633
21821
  if (!legacyTx.recentBlockhash) {
21634
- const rpcUrl = this.getRpcUrl();
21635
- const connection = new Connection(rpcUrl, 'confirmed');
21636
- const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
21822
+ const conn = new Connection(this.getRpcUrl(), 'confirmed');
21823
+ const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash('confirmed');
21637
21824
  legacyTx.recentBlockhash = blockhash;
21638
21825
  legacyTx.lastValidBlockHeight = lastValidBlockHeight;
21639
21826
  }
21640
- if (!legacyTx.feePayer && this.publicKeyObj) {
21641
- legacyTx.feePayer = this.publicKeyObj;
21827
+ if (!legacyTx.feePayer) {
21828
+ legacyTx.feePayer = connectedPubkey;
21642
21829
  }
21643
21830
  }
21644
21831
  else {
21645
21832
  const versionedTx = transaction;
21646
21833
  if (!versionedTx.message.recentBlockhash) {
21647
- const rpcUrl = this.getRpcUrl();
21648
- const connection = new Connection(rpcUrl, 'confirmed');
21649
- const { blockhash } = await connection.getLatestBlockhash('confirmed');
21834
+ const conn = new Connection(this.getRpcUrl(), 'confirmed');
21835
+ const { blockhash } = await conn.getLatestBlockhash('confirmed');
21650
21836
  versionedTx.message.recentBlockhash = blockhash;
21651
21837
  }
21652
21838
  }
21653
21839
  try {
21654
- const signedTransactions = await transact(async (wallet) => {
21655
- await this.reauthorizeWallet(wallet);
21656
- return wallet.signTransactions({ transactions: [transaction] });
21657
- }, this.getAssociationConfig());
21658
- return signedTransactions[0];
21840
+ const signTxFeat = getSignTransactionFeature(wallet);
21841
+ const wireBytes = txToWireBytes(transaction);
21842
+ const results = await signTxFeat.signTransaction({ account, transaction: wireBytes, chain });
21843
+ if (!results || results.length === 0) {
21844
+ throw new Error('MWA returned no signed transaction');
21845
+ }
21846
+ const { signedTransaction: signedBytes } = results[0];
21847
+ return txFromWireBytes(new Uint8Array(signedBytes));
21659
21848
  }
21660
21849
  catch (error) {
21661
21850
  if (((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.includes('not connected')) || ((_b = error === null || error === void 0 ? void 0 : error.message) === null || _b === void 0 ? void 0 : _b.includes('not authorized')) ||
@@ -21668,15 +21857,15 @@ class SolanaMobileWalletProvider {
21668
21857
  }
21669
21858
  async signAndSubmitTransaction(transaction, feePayer) {
21670
21859
  var _a, _b, _c, _d, _e, _f;
21671
- if (!this.publicKeyObj) {
21672
- throw new Error('Not connected. Call login() first.');
21673
- }
21674
- await loadMwaProtocol();
21675
- const { transact } = mwaProtocolModule;
21860
+ const account = await this.ensureAuthorized();
21861
+ const connectedPubkey = new PublicKey(account.publicKey);
21862
+ const wallet = await this.ensureWallet();
21863
+ const chain = this.getChain();
21676
21864
  const rpcUrl = this.getRpcUrl();
21677
21865
  const connection = new Connection(rpcUrl, 'confirmed');
21678
21866
  const isSurfnet = rpcUrl === SURFNET_RPC_URL$2;
21679
21867
  try {
21868
+ // Preserve existing prep: refresh blockhash and set fee payer.
21680
21869
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
21681
21870
  const isLegacyTransaction = 'recentBlockhash' in transaction && !('message' in transaction && 'staticAccountKeys' in transaction.message);
21682
21871
  if (isLegacyTransaction) {
@@ -21684,12 +21873,7 @@ class SolanaMobileWalletProvider {
21684
21873
  legacyTx.recentBlockhash = blockhash;
21685
21874
  legacyTx.lastValidBlockHeight = lastValidBlockHeight;
21686
21875
  if (!legacyTx.feePayer) {
21687
- if (feePayer) {
21688
- legacyTx.feePayer = feePayer;
21689
- }
21690
- else if (this.publicKeyObj) {
21691
- legacyTx.feePayer = this.publicKeyObj;
21692
- }
21876
+ legacyTx.feePayer = feePayer !== null && feePayer !== void 0 ? feePayer : connectedPubkey;
21693
21877
  }
21694
21878
  }
21695
21879
  else {
@@ -21697,14 +21881,19 @@ class SolanaMobileWalletProvider {
21697
21881
  versionedTx.message.recentBlockhash = blockhash;
21698
21882
  }
21699
21883
  if (isSurfnet) {
21700
- // Surfnet: sign-only, then submit to our specific RPC
21701
- const signedTransactions = await transact(async (wallet) => {
21702
- await this.reauthorizeWallet(wallet);
21703
- return wallet.signTransactions({ transactions: [transaction] });
21704
- }, this.getAssociationConfig());
21705
- const signedTx = signedTransactions[0];
21884
+ // Surfnet: sign locally via wallet-standard, submit manually
21885
+ // to the Surfnet RPC. Don't route through signAndSendTransaction
21886
+ // because the wallet would submit to its own RPC.
21887
+ const signTxFeat = getSignTransactionFeature(wallet);
21888
+ const wireBytes = txToWireBytes(transaction);
21889
+ const results = await signTxFeat.signTransaction({ account, transaction: wireBytes, chain });
21890
+ if (!results || results.length === 0) {
21891
+ throw new Error('MWA returned no signed transaction');
21892
+ }
21893
+ const { signedTransaction: signedBytes } = results[0];
21894
+ const signedTx = txFromWireBytes(new Uint8Array(signedBytes));
21706
21895
  const signature = await connection.sendRawTransaction(signedTx.serialize(), {
21707
- preflightCommitment: 'confirmed'
21896
+ preflightCommitment: 'confirmed',
21708
21897
  });
21709
21898
  const confirmation = await connection.confirmTransaction({
21710
21899
  signature,
@@ -21716,15 +21905,20 @@ class SolanaMobileWalletProvider {
21716
21905
  }
21717
21906
  return signature;
21718
21907
  }
21719
- // Non-surfnet: use signAndSendTransactions for wallet-optimized submission
21720
- const signatures = await transact(async (wallet) => {
21721
- await this.reauthorizeWallet(wallet);
21722
- return wallet.signAndSendTransactions({
21723
- transactions: [transaction],
21724
- commitment: 'confirmed',
21725
- });
21726
- }, this.getAssociationConfig());
21727
- const signature = signatures[0];
21908
+ // Non-Surfnet: wallet signs and submits to its own RPC.
21909
+ const signSendFeat = getSignAndSendTransactionFeature(wallet);
21910
+ const wireBytes = txToWireBytes(transaction);
21911
+ const results = await signSendFeat.signAndSendTransaction({
21912
+ account,
21913
+ transaction: wireBytes,
21914
+ chain,
21915
+ options: { commitment: 'confirmed' },
21916
+ });
21917
+ if (!results || results.length === 0) {
21918
+ throw new Error('MWA returned no signature');
21919
+ }
21920
+ const { signature: sigBytes } = results[0];
21921
+ const signature = base58.encode(sigBytes);
21728
21922
  await confirmAndCheckTransaction(connection, signature);
21729
21923
  return signature;
21730
21924
  }
@@ -21750,16 +21944,14 @@ class SolanaMobileWalletProvider {
21750
21944
  if (!solTransactionData) {
21751
21945
  throw new Error('Solana transaction data is required for mobile wallet');
21752
21946
  }
21753
- if (!this.publicKeyObj || !this.authorizedPublicKey) {
21754
- await this.login();
21755
- }
21756
- await loadMwaProtocol();
21757
- const { transact } = mwaProtocolModule;
21947
+ const account = await this.ensureAuthorized();
21948
+ const connectedPubkey = new PublicKey(account.publicKey);
21949
+ const wallet = await this.ensureWallet();
21950
+ const chain = this.getChain();
21758
21951
  const rpcUrl = this.getRpcUrl(solTransactionData.network);
21759
21952
  const connection = new Connection(rpcUrl, 'confirmed');
21760
21953
  const isSurfnet = rpcUrl === SURFNET_RPC_URL$2;
21761
21954
  try {
21762
- const publicKey = this.publicKeyObj;
21763
21955
  const remainingAccounts = convertRemainingAccounts(solTransactionData.txArgs[0].remainingAccounts);
21764
21956
  let app_id = solTransactionData.appId;
21765
21957
  if (typeof window !== 'undefined' && window.CUSTOM_TAROBASE_APP_ID_HEADER) {
@@ -21768,9 +21960,9 @@ class SolanaMobileWalletProvider {
21768
21960
  if (!app_id) {
21769
21961
  throw new Error('App ID is required');
21770
21962
  }
21771
- // Create a mock wallet adapter for Anchor (only publicKey is needed for building TX)
21963
+ // Mock wallet adapter for Anchor only publicKey is read during build.
21772
21964
  const mockWalletAdapter = {
21773
- publicKey,
21965
+ publicKey: connectedPubkey,
21774
21966
  signTransaction: async (tx) => tx,
21775
21967
  signAllTransactions: async (txs) => txs,
21776
21968
  };
@@ -21788,10 +21980,12 @@ class SolanaMobileWalletProvider {
21788
21980
  }
21789
21981
  let tx;
21790
21982
  if (solTransactionData.signedTransaction) {
21983
+ // Server has co-signed a CPI attestation. Do NOT mutate its
21984
+ // blockhash — that would invalidate the server's signature.
21791
21985
  tx = VersionedTransaction.deserialize(bufferExports.Buffer.from(solTransactionData.signedTransaction, 'base64'));
21792
21986
  }
21793
21987
  else {
21794
- const result = await buildSetDocumentsTransaction(connection, solTransactionData.txArgs[0].idl, anchorProvider, publicKey, {
21988
+ const result = await buildSetDocumentsTransaction(connection, solTransactionData.txArgs[0].idl, anchorProvider, connectedPubkey, {
21795
21989
  app_id,
21796
21990
  documents: solTransactionData.txArgs[0].setDocumentData,
21797
21991
  delete_paths: solTransactionData.txArgs[0].deletePaths,
@@ -21799,11 +21993,16 @@ class SolanaMobileWalletProvider {
21799
21993
  }, finalDeduped, solTransactionData.lutKey, solTransactionData.preInstructions, false, solTransactionData.additionalLutAddresses);
21800
21994
  tx = result.tx;
21801
21995
  }
21996
+ // Sign-only branch — sign the tx but don't submit.
21802
21997
  if ((options === null || options === void 0 ? void 0 : options.shouldSubmitTx) === false) {
21803
- const [signedTx] = await transact(async (wallet) => {
21804
- await this.reauthorizeWallet(wallet);
21805
- return wallet.signTransactions({ transactions: [tx] });
21806
- }, this.getAssociationConfig());
21998
+ const signTxFeat = getSignTransactionFeature(wallet);
21999
+ const wireBytes = txToWireBytes(tx);
22000
+ const results = await signTxFeat.signTransaction({ account, transaction: wireBytes, chain });
22001
+ if (!results || results.length === 0) {
22002
+ throw new Error('MWA returned no signed transaction');
22003
+ }
22004
+ const { signedTransaction: signedBytes } = results[0];
22005
+ const signedTx = txFromWireBytes(new Uint8Array(signedBytes));
21807
22006
  return {
21808
22007
  signedTransaction: signedTx,
21809
22008
  blockNumber: 0,
@@ -21812,14 +22011,18 @@ class SolanaMobileWalletProvider {
21812
22011
  };
21813
22012
  }
21814
22013
  if (isSurfnet) {
21815
- // Surfnet: sign then submit manually to our RPC
21816
- const [signedTx] = await transact(async (wallet) => {
21817
- await this.reauthorizeWallet(wallet);
21818
- return wallet.signTransactions({ transactions: [tx] });
21819
- }, this.getAssociationConfig());
22014
+ // Surfnet: sign locally via wallet-standard, submit manually.
22015
+ const signTxFeat = getSignTransactionFeature(wallet);
22016
+ const wireBytes = txToWireBytes(tx);
22017
+ const results = await signTxFeat.signTransaction({ account, transaction: wireBytes, chain });
22018
+ if (!results || results.length === 0) {
22019
+ throw new Error('MWA returned no signed transaction');
22020
+ }
22021
+ const { signedTransaction: signedBytes } = results[0];
22022
+ const signedTx = txFromWireBytes(new Uint8Array(signedBytes));
21820
22023
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
21821
22024
  const signature = await connection.sendRawTransaction(signedTx.serialize(), {
21822
- preflightCommitment: 'confirmed'
22025
+ preflightCommitment: 'confirmed',
21823
22026
  });
21824
22027
  const confirmation = await connection.confirmTransaction({
21825
22028
  signature,
@@ -21831,7 +22034,7 @@ class SolanaMobileWalletProvider {
21831
22034
  }
21832
22035
  const txInfo = await connection.getParsedTransaction(signature, {
21833
22036
  maxSupportedTransactionVersion: 0,
21834
- commitment: 'confirmed'
22037
+ commitment: 'confirmed',
21835
22038
  });
21836
22039
  return {
21837
22040
  transactionSignature: signature,
@@ -21840,15 +22043,20 @@ class SolanaMobileWalletProvider {
21840
22043
  data: txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta,
21841
22044
  };
21842
22045
  }
21843
- // Non-surfnet: use signAndSendTransactions
21844
- const signatures = await transact(async (wallet) => {
21845
- await this.reauthorizeWallet(wallet);
21846
- return wallet.signAndSendTransactions({
21847
- transactions: [tx],
21848
- commitment: 'confirmed',
21849
- });
21850
- }, this.getAssociationConfig());
21851
- const signature = signatures[0];
22046
+ // Non-Surfnet: wallet signs and submits to its own RPC.
22047
+ const signSendFeat = getSignAndSendTransactionFeature(wallet);
22048
+ const wireBytes = txToWireBytes(tx);
22049
+ const results = await signSendFeat.signAndSendTransaction({
22050
+ account,
22051
+ transaction: wireBytes,
22052
+ chain,
22053
+ options: { commitment: 'confirmed' },
22054
+ });
22055
+ if (!results || results.length === 0) {
22056
+ throw new Error('MWA returned no signature');
22057
+ }
22058
+ const { signature: sigBytes } = results[0];
22059
+ const signature = base58.encode(sigBytes);
21852
22060
  const txInfo = await confirmAndCheckTransaction(connection, signature);
21853
22061
  return {
21854
22062
  transactionSignature: signature,
@@ -21875,11 +22083,36 @@ class SolanaMobileWalletProvider {
21875
22083
  }
21876
22084
  }
21877
22085
  async getNativeMethods() {
22086
+ var _a, _b, _c;
22087
+ // Synchronous-ish state read; tolerate the wallet being unauthorized
22088
+ // (return nulls). Don't trigger ensureAuthorized() here — callers that
22089
+ // need the wallet active should sign through one of the sign methods.
22090
+ const wallet = this.wallet;
22091
+ if (!wallet) {
22092
+ return {
22093
+ authToken: null,
22094
+ walletUriBase: null,
22095
+ publicKey: null,
22096
+ base64Address: null,
22097
+ wallet: null,
22098
+ currentAuthorization: null,
22099
+ };
22100
+ }
22101
+ const acct = (_a = wallet.accounts) === null || _a === void 0 ? void 0 : _a[0];
22102
+ const auth = wallet.currentAuthorization;
22103
+ let publicKey = null;
22104
+ let base64Address = null;
22105
+ if (acct) {
22106
+ publicKey = new PublicKey(acct.publicKey);
22107
+ base64Address = btoa(String.fromCharCode(...acct.publicKey));
22108
+ }
21878
22109
  return {
21879
- authToken: this.authToken,
21880
- walletUriBase: this.walletUriBase,
21881
- publicKey: this.publicKeyObj,
21882
- base64Address: this.base64Address,
22110
+ authToken: (_b = auth === null || auth === void 0 ? void 0 : auth.auth_token) !== null && _b !== void 0 ? _b : null,
22111
+ walletUriBase: (_c = auth === null || auth === void 0 ? void 0 : auth.wallet_uri_base) !== null && _c !== void 0 ? _c : null,
22112
+ publicKey,
22113
+ base64Address,
22114
+ wallet,
22115
+ currentAuthorization: auth !== null && auth !== void 0 ? auth : null,
21883
22116
  };
21884
22117
  }
21885
22118
  /* ----------------------------------------------------------- *
@@ -22250,4 +22483,4 @@ class PrivyExpoProvider {
22250
22483
  }
22251
22484
 
22252
22485
  export { getCachedData as $, subscribe as A, useAuth as B, deserializeTransaction as C, getIdToken as D, setPlatform as E, getPlatform as F, PrivyWalletProvider as G, DEFAULT_TEST_ADDRESS as H, isMobileWalletAvailable as I, registerMobileWalletAdapter as J, PrivyExpoProvider as K, InsufficientBalanceError as L, MockAuthProvider as M, ServerSessionManager as N, OffchainAuthProvider as O, PhantomWalletProvider as P, buildSetDocumentsTransaction as Q, ReactNativeSessionManager as R, SolanaMobileWalletProvider as S, clearCache as T, closeAllSubscriptions as U, convertRemainingAccounts as V, WebSessionManager as W, createSessionWithPrivy as X, createSessionWithSignature as Y, genAuthNonce as Z, genSolanaMessage as _, base58 as a, getMany as a0, reconnectWithNewAuth as a1, refreshSession as a2, signSessionCreateMessage as a3, bufferExports as b, getCurrentUser as c, onAuthLoadingChanged as d, getAuthLoading as e, logout as f, getDefaultExportFromCjs$1 as g, getConfig as h, init as i, getAuthProvider as j, get as k, login as l, setMany as m, setFile as n, onAuthStateChanged as o, getFiles as p, runQueryMany as q, runQuery as r, set as s, runExpression as t, runExpressionMany as u, signMessage as v, signTransaction as w, signAndSubmitTransaction as x, count as y, aggregate as z };
22253
- //# sourceMappingURL=index-XHbmzFFO.esm.js.map
22486
+ //# sourceMappingURL=index-QukWgaIi.esm.js.map