@pooflabs/web 0.0.84 → 0.0.85-rc1

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 +42 -20
  2. package/dist/{index-ep10Sw82.esm.js → index-4TKz3Mn_.esm.js} +3 -3
  3. package/dist/{index-ep10Sw82.esm.js.map → index-4TKz3Mn_.esm.js.map} +1 -1
  4. package/dist/{index-BM6hgCdH.js → index-BoWQVxMI.js} +2 -2
  5. package/dist/{index-BM6hgCdH.js.map → index-BoWQVxMI.js.map} +1 -1
  6. package/dist/{index-CH2G5Y9i.esm.js → index-Buu8v-Oe.esm.js} +2 -2
  7. package/dist/{index-CH2G5Y9i.esm.js.map → index-Buu8v-Oe.esm.js.map} +1 -1
  8. package/dist/{index-CSeN3jbG.js → index-C2p1Cldz.js} +3 -3
  9. package/dist/{index-CSeN3jbG.js.map → index-C2p1Cldz.js.map} +1 -1
  10. package/dist/index-COF6zNCs.esm.js +6 -0
  11. package/dist/index-COF6zNCs.esm.js.map +1 -0
  12. package/dist/{index-Bp4b5LXs.js → index-DlyeWzMk.js} +2 -2
  13. package/dist/index-DlyeWzMk.js.map +1 -0
  14. package/dist/{index-BPlF6-PQ.js → index-R7cvXys2.js} +394 -286
  15. package/dist/{index-BPlF6-PQ.js.map → index-R7cvXys2.js.map} +1 -1
  16. package/dist/{index-XHbmzFFO.esm.js → index-ZKzq5QT_.esm.js} +395 -287
  17. package/dist/{index-XHbmzFFO.esm.js.map → index-ZKzq5QT_.esm.js.map} +1 -1
  18. package/dist/{index.browser-C1QL04xM.js → index.browser-BQSN-6X2.js} +846 -815
  19. package/dist/index.browser-BQSN-6X2.js.map +1 -0
  20. package/dist/index.browser-DZCNegue.js +6070 -0
  21. package/dist/index.browser-DZCNegue.js.map +1 -0
  22. package/dist/{index.browser-Cgj7Hs6n.esm.js → index.browser-tPepE5fo.esm.js} +836 -802
  23. package/dist/index.browser-tPepE5fo.esm.js.map +1 -0
  24. package/dist/index.browser-zfGYm0ST.esm.js +6060 -0
  25. package/dist/index.browser-zfGYm0ST.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-BGaUOX9f.js} +4 -4
  29. package/dist/{index.native-BmtuyGXs.js.map → index.native-BGaUOX9f.js.map} +1 -1
  30. package/dist/{index.native-X01vlukI.esm.js → index.native-BPQqeP6_.esm.js} +4 -4
  31. package/dist/{index.native-X01vlukI.esm.js.map → index.native-BPQqeP6_.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-DRvhBbbR.esm.js → phantom-wallet-provider-DheGhOp4.esm.js} +4 -4
  35. package/dist/{phantom-wallet-provider-DRvhBbbR.esm.js.map → phantom-wallet-provider-DheGhOp4.esm.js.map} +1 -1
  36. package/dist/{phantom-wallet-provider-C_LPU6Ns.js → phantom-wallet-provider-MFcwrRpJ.js} +4 -4
  37. package/dist/{phantom-wallet-provider-C_LPU6Ns.js.map → phantom-wallet-provider-MFcwrRpJ.js.map} +1 -1
  38. package/dist/{privy-wallet-provider-DQM8xO38.js → privy-wallet-provider-CFw6o7O5.js} +3 -3
  39. package/dist/{privy-wallet-provider-DQM8xO38.js.map → privy-wallet-provider-CFw6o7O5.js.map} +1 -1
  40. package/dist/{privy-wallet-provider-ZGu8q5T5.esm.js → privy-wallet-provider-D15Au3j8.esm.js} +3 -3
  41. package/dist/{privy-wallet-provider-ZGu8q5T5.esm.js.map → privy-wallet-provider-D15Au3j8.esm.js.map} +1 -1
  42. package/dist/solana-mobile-wallet-provider-BM9wdF0m.js +719 -0
  43. package/dist/solana-mobile-wallet-provider-BM9wdF0m.js.map +1 -0
  44. package/dist/solana-mobile-wallet-provider-ChHh-U_p.esm.js +698 -0
  45. package/dist/solana-mobile-wallet-provider-ChHh-U_p.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
@@ -12838,10 +12838,10 @@ let currentAuthProvider = null;
12838
12838
  let currentAuthMethod = null;
12839
12839
  let initConfig = null;
12840
12840
  // --- localStorage helpers: track which auth method the user last logged in with ---
12841
- const STORED_AUTH_METHOD_KEY = 'tarobase_last_auth_method';
12841
+ const STORED_AUTH_METHOD_KEY$1 = 'tarobase_last_auth_method';
12842
12842
  function getStoredAuthMethod() {
12843
12843
  try {
12844
- return getPlatform().storage.getItem(STORED_AUTH_METHOD_KEY);
12844
+ return getPlatform().storage.getItem(STORED_AUTH_METHOD_KEY$1);
12845
12845
  }
12846
12846
  catch (_a) {
12847
12847
  return null;
@@ -12850,10 +12850,10 @@ function getStoredAuthMethod() {
12850
12850
  function setStoredAuthMethod(method) {
12851
12851
  try {
12852
12852
  if (method) {
12853
- getPlatform().storage.setItem(STORED_AUTH_METHOD_KEY, method);
12853
+ getPlatform().storage.setItem(STORED_AUTH_METHOD_KEY$1, method);
12854
12854
  }
12855
12855
  else {
12856
- getPlatform().storage.removeItem(STORED_AUTH_METHOD_KEY);
12856
+ getPlatform().storage.removeItem(STORED_AUTH_METHOD_KEY$1);
12857
12857
  }
12858
12858
  }
12859
12859
  catch (_a) {
@@ -15730,7 +15730,7 @@ async function loadDependencies() {
15730
15730
  const [reactModule, reactDomModule, phantomModule] = await Promise.all([
15731
15731
  import('react'),
15732
15732
  import('react-dom/client'),
15733
- Promise.resolve().then(function () { return require('./index-BM6hgCdH.js'); })
15733
+ Promise.resolve().then(function () { return require('./index-BoWQVxMI.js'); })
15734
15734
  ]);
15735
15735
  // Extract default export from ESM module namespace
15736
15736
  // Dynamic import() returns { default: Module, ...exports }, not the module directly
@@ -21299,26 +21299,135 @@ function isMobileWalletAvailable() {
21299
21299
  return detectAndroid();
21300
21300
  }
21301
21301
  const ED25519_SIGNATURE_LENGTH = 64;
21302
- // Dynamically imported MWA protocol module
21303
- let mwaProtocolModule = null;
21304
- let mwaProtocolLoadPromise = null;
21305
- async function loadMwaProtocol() {
21306
- if (mwaProtocolModule)
21307
- return;
21308
- if (typeof window === 'undefined')
21309
- return;
21310
- if (mwaProtocolLoadPromise)
21311
- return mwaProtocolLoadPromise;
21312
- mwaProtocolLoadPromise = (async () => {
21313
- try {
21314
- mwaProtocolModule = await Promise.resolve().then(function () { return require('./index.browser-BvNsUWjt.js'); });
21302
+ const STORED_AUTH_METHOD_KEY = 'tarobase_last_auth_method';
21303
+ const MWA_AUTH_METHOD = 'mobile-wallet-adapter';
21304
+ /**
21305
+ * Normalize a chain string to a wallet-standard Solana chain identifier.
21306
+ *
21307
+ * Handles three input shapes that all show up in practice:
21308
+ * - Bare cluster name from `SolanaMobileWalletConfig.cluster` (e.g. 'devnet').
21309
+ * - Prefixed `solana:cluster` (e.g. 'solana:devnet').
21310
+ * - Double-prefixed `solana:solana:cluster` (constructor used to wrap cluster
21311
+ * with `solana:` blindly; if a caller already passed a prefixed string the
21312
+ * result was `solana:solana:devnet`).
21313
+ *
21314
+ * Wallet-standard Solana chains are exactly:
21315
+ * 'solana:mainnet' | 'solana:devnet' | 'solana:testnet' | 'solana:localnet'
21316
+ * — `mainnet-beta` is NOT a valid wallet-standard identifier and must be
21317
+ * normalized to `solana:mainnet`.
21318
+ */
21319
+ function mapChainToWalletStandard(input) {
21320
+ if (!input)
21321
+ return 'solana:mainnet';
21322
+ let s = String(input).toLowerCase();
21323
+ while (s.startsWith('solana:'))
21324
+ s = s.slice('solana:'.length);
21325
+ if (s === 'mainnet-beta' || s === 'mainnet')
21326
+ return 'solana:mainnet';
21327
+ if (s === 'devnet')
21328
+ return 'solana:devnet';
21329
+ if (s === 'testnet')
21330
+ return 'solana:testnet';
21331
+ if (s === 'localnet')
21332
+ return 'solana:localnet';
21333
+ return 'solana:mainnet';
21334
+ }
21335
+ /**
21336
+ * Serialize a Transaction/VersionedTransaction to a Uint8Array wire payload
21337
+ * that the wallet-standard `solana:signTransaction` /
21338
+ * `solana:signAndSendTransaction` features expect.
21339
+ *
21340
+ * Legacy transactions must serialize with `requireAllSignatures: false` and
21341
+ * `verifySignatures: false` — the wallet hasn't signed yet, and the default
21342
+ * `serialize()` would throw "Signature verification failed". Versioned
21343
+ * transactions use the default `serialize()` which already permits unsigned
21344
+ * payloads. Mirrors the helper at
21345
+ * `@solana-mobile/mobile-wallet-adapter-protocol-web3js/lib/esm/index.browser.js:13-18`.
21346
+ */
21347
+ function txToWireBytes(tx) {
21348
+ if ('version' in tx)
21349
+ return tx.serialize();
21350
+ return tx.serialize({ requireAllSignatures: false, verifySignatures: false });
21351
+ }
21352
+ /**
21353
+ * Deserialize a wire-format transaction returned by the wallet
21354
+ * `solana:signTransaction` feature. Mirrors the helper at
21355
+ * `@solana-mobile/mobile-wallet-adapter-protocol-web3js/lib/esm/index.browser.js:19-23`
21356
+ * so legacy and versioned bytes both round-trip correctly.
21357
+ */
21358
+ function txFromWireBytes(byteArray) {
21359
+ const messageOffset = byteArray[0] * ED25519_SIGNATURE_LENGTH + 1;
21360
+ const messageVersion = web3_js.VersionedMessage.deserializeMessageVersion(byteArray.slice(messageOffset, byteArray.length));
21361
+ if (messageVersion === 'legacy') {
21362
+ return web3_js.Transaction.from(byteArray);
21363
+ }
21364
+ return web3_js.VersionedTransaction.deserialize(byteArray);
21365
+ }
21366
+ /**
21367
+ * Per-method runtime narrowing of wallet-standard features. The wallet's
21368
+ * `.features` type is a union (`signAndSendTransaction` | `signTransaction`),
21369
+ * and after authorization the wallet may also narrow `#optionalFeatures`
21370
+ * based on actual wallet capabilities. Narrow at the call site so a method
21371
+ * that needs only `signMessage` doesn't fail when a wallet lacks
21372
+ * `signTransaction`.
21373
+ */
21374
+ function getSignMessageFeature(wallet) {
21375
+ const f = wallet.features;
21376
+ const feat = f['solana:signMessage'];
21377
+ if (!feat || typeof feat.signMessage !== 'function') {
21378
+ throw new Error('Wallet does not support solana:signMessage');
21379
+ }
21380
+ return feat;
21381
+ }
21382
+ function getSignTransactionFeature(wallet) {
21383
+ const f = wallet.features;
21384
+ const feat = f['solana:signTransaction'];
21385
+ if (!feat || typeof feat.signTransaction !== 'function') {
21386
+ throw new Error('Wallet does not support solana:signTransaction');
21387
+ }
21388
+ return feat;
21389
+ }
21390
+ function getSignAndSendTransactionFeature(wallet) {
21391
+ const f = wallet.features;
21392
+ const feat = f['solana:signAndSendTransaction'];
21393
+ if (!feat || typeof feat.signAndSendTransaction !== 'function') {
21394
+ throw new Error('Wallet does not support solana:signAndSendTransaction');
21395
+ }
21396
+ return feat;
21397
+ }
21398
+ function getConnectFeature(wallet) {
21399
+ const f = wallet.features;
21400
+ const feat = f['standard:connect'];
21401
+ if (!feat || typeof feat.connect !== 'function') {
21402
+ throw new Error('Wallet does not support standard:connect');
21403
+ }
21404
+ return feat;
21405
+ }
21406
+ function getDisconnectFeature(wallet) {
21407
+ const f = wallet.features;
21408
+ const feat = f['standard:disconnect'];
21409
+ return feat && typeof feat.disconnect === 'function' ? feat : null;
21410
+ }
21411
+ function writeAuthMethod(method) {
21412
+ try {
21413
+ if (method === null) {
21414
+ getPlatform().storage.removeItem(STORED_AUTH_METHOD_KEY);
21315
21415
  }
21316
- catch (e) {
21317
- console.warn('[SolanaMobileWallet] @solana-mobile/mobile-wallet-adapter-protocol-web3js not installed. Install it to enable Seeker wallet support.');
21318
- throw new Error('Missing @solana-mobile/mobile-wallet-adapter-protocol-web3js dependency');
21416
+ else {
21417
+ getPlatform().storage.setItem(STORED_AUTH_METHOD_KEY, method);
21319
21418
  }
21320
- })();
21321
- return mwaProtocolLoadPromise;
21419
+ }
21420
+ catch (_a) {
21421
+ // storage may be unavailable
21422
+ }
21423
+ }
21424
+ function readAuthMethod() {
21425
+ try {
21426
+ return getPlatform().storage.getItem(STORED_AUTH_METHOD_KEY);
21427
+ }
21428
+ catch (_a) {
21429
+ return null;
21430
+ }
21322
21431
  }
21323
21432
  /**
21324
21433
  * Registers Mobile Wallet Adapter as a wallet-standard wallet so it appears
@@ -21333,7 +21442,7 @@ async function registerMobileWalletAdapter(config) {
21333
21442
  if (typeof window === 'undefined')
21334
21443
  return;
21335
21444
  try {
21336
- const walletStandardMobile = await Promise.resolve().then(function () { return require('./index.browser-C1QL04xM.js'); });
21445
+ const walletStandardMobile = await Promise.resolve().then(function () { return require('./index.browser-DZCNegue.js'); });
21337
21446
  const registerMwa = walletStandardMobile.registerMwa || ((_a = walletStandardMobile.default) === null || _a === void 0 ? void 0 : _a.registerMwa);
21338
21447
  if (!registerMwa) {
21339
21448
  console.warn('[SolanaMobileWallet] registerMwa not found in @solana-mobile/wallet-standard-mobile');
@@ -21362,32 +21471,41 @@ async function registerMobileWalletAdapter(config) {
21362
21471
  registerMwa(options);
21363
21472
  }
21364
21473
  catch (e) {
21365
- // @solana-mobile/wallet-standard-mobile is an optional dependency
21366
- // Silently skip if not installed — the provider still works via
21367
- // @solana-mobile/mobile-wallet-adapter-protocol-web3js directly
21368
21474
  console.debug('[SolanaMobileWallet] @solana-mobile/wallet-standard-mobile not available, skipping wallet-standard registration');
21369
21475
  }
21370
21476
  }
21371
21477
  /**
21372
- * SolanaMobileWalletProvider implements the AuthProvider interface using the
21373
- * Solana Mobile Wallet Adapter (MWA) protocol's low-level `transact` API.
21478
+ * SolanaMobileWalletProvider implements the AuthProvider interface using
21479
+ * Solana Mobile's wallet-standard wrapper (`LocalSolanaMobileWalletAdapterWallet`).
21374
21480
  *
21375
- * This enables TaroBase dApps to work with any MWA-compliant wallet on Solana
21376
- * mobile devices (Seeker, Saga) — including the native Seed Vault Wallet,
21377
- * Phantom, Solflare, and any other wallet that implements the MWA protocol.
21481
+ * Why wallet-standard and not the raw MWA protocol: as of
21482
+ * `@solana-mobile/wallet-standard-mobile@0.5.0+`, the wallet's internal
21483
+ * `#transact` calls `checkLocalNetworkAccessPermission()` before opening the
21484
+ * localhost WebSocket. That helper renders a three-stage UX flow Solana
21485
+ * Mobile designed specifically to defuse Chrome's Local Network Access
21486
+ * permission dialog (which renders with disabled buttons on Android Chrome,
21487
+ * the source of the long-running Seeker MWA bug):
21378
21488
  *
21379
- * By using `transact()` directly (instead of the wallet-adapter wrapper),
21380
- * login combines authorize + signMessage into a single wallet session —
21381
- * meaning one popup/approval instead of two.
21489
+ * 1. "Allow connections to your wallet" informational modal.
21490
+ * 2. Chrome's permission prompt (interactive because it's spawned as a
21491
+ * fresh user gesture from step 1).
21492
+ * 3. "Ready to connect!" success modal.
21493
+ *
21494
+ * `checkLocalNetworkAccessPermission` is internal to the library — it's not
21495
+ * exported. The only way to invoke it is to go through the wallet's
21496
+ * `standard:connect` / `solana:sign*` features, which is what this provider
21497
+ * does.
21498
+ *
21499
+ * Notes on UX: login uses two wallet popups in succession — `standard:connect`
21500
+ * (authorize) and `solana:signMessage` (sign the Tarobase nonce). The
21501
+ * previous implementation combined both inside a single `transact` callback;
21502
+ * splitting them is the cost of going through wallet-standard, and is
21503
+ * acceptable given the alternative was broken on Seeker.
21382
21504
  */
21383
21505
  class SolanaMobileWalletProvider {
21384
21506
  constructor(networkUrl = null, config = {}) {
21385
- // MWA authorization state
21386
- this.authToken = null;
21387
- this.walletUriBase = null;
21388
- this.base64Address = null;
21389
- this.authorizedPublicKey = null;
21390
- this.publicKeyObj = null;
21507
+ /** LocalSolanaMobileWalletAdapterWallet, lazy-constructed in ensureWallet(). */
21508
+ this.wallet = null;
21391
21509
  this.networkUrl = networkUrl;
21392
21510
  this.config = config;
21393
21511
  if (typeof window === 'undefined') {
@@ -21400,7 +21518,7 @@ class SolanaMobileWalletProvider {
21400
21518
  name: 'TaroBase App',
21401
21519
  uri: getPlatform().getLocationOrigin(),
21402
21520
  };
21403
- this.chain = `solana:${config.cluster || 'mainnet-beta'}`;
21521
+ this.cluster = config.cluster || 'mainnet-beta';
21404
21522
  SolanaMobileWalletProvider.instance = this;
21405
21523
  }
21406
21524
  static getInstance(networkUrl, config) {
@@ -21409,154 +21527,118 @@ class SolanaMobileWalletProvider {
21409
21527
  }
21410
21528
  return SolanaMobileWalletProvider.instance;
21411
21529
  }
21412
- /** Config for transact() routes to the same wallet if we've already authorized */
21413
- getAssociationConfig() {
21414
- if (this.walletUriBase) {
21415
- return { baseUri: this.walletUriBase };
21416
- }
21417
- return undefined;
21530
+ /** Lazy-construct LocalSolanaMobileWalletAdapterWallet on first need. */
21531
+ async ensureWallet() {
21532
+ if (this.wallet)
21533
+ return this.wallet;
21534
+ const mod = await Promise.resolve().then(function () { return require('./index.browser-DZCNegue.js'); });
21535
+ const chain = mapChainToWalletStandard(this.cluster);
21536
+ this.wallet = new mod.LocalSolanaMobileWalletAdapterWallet({
21537
+ appIdentity: this.appIdentity,
21538
+ authorizationCache: mod.createDefaultAuthorizationCache(),
21539
+ chains: [chain],
21540
+ chainSelector: mod.createDefaultChainSelector(),
21541
+ onWalletNotFound: mod.createDefaultWalletNotFoundHandler(),
21542
+ });
21543
+ return this.wallet;
21418
21544
  }
21419
- /** Reauthorize within a transact callback using a stored auth_token */
21420
- async reauthorizeWallet(wallet) {
21421
- if (!this.authToken) {
21422
- // No existing auth do a fresh authorize
21423
- const authResult = await wallet.authorize({
21424
- identity: this.appIdentity,
21425
- chain: this.chain,
21426
- });
21427
- this.storeAuthResult(authResult);
21428
- return authResult;
21545
+ /**
21546
+ * Ensure the wallet has an active authorization. After a Tarobase session
21547
+ * is restored from storage on cold-start, `wallet.accounts` is empty until
21548
+ * we silently reconnect from the AuthorizationCache. If the cache is also
21549
+ * empty, fall back to interactive `login()` (which surfaces the three-stage
21550
+ * Solana Mobile LNA flow + wallet popups).
21551
+ *
21552
+ * Returns the wallet-standard `WalletAccount` to use for sign operations.
21553
+ */
21554
+ async ensureAuthorized() {
21555
+ const wallet = await this.ensureWallet();
21556
+ if (wallet.accounts.length === 0) {
21557
+ try {
21558
+ const connectFeat = getConnectFeature(wallet);
21559
+ await connectFeat.connect({ silent: true });
21560
+ }
21561
+ catch (e) {
21562
+ console.warn('[SolanaMobileWallet] silent connect failed:', e === null || e === void 0 ? void 0 : e.message);
21563
+ }
21429
21564
  }
21430
- try {
21431
- const authResult = await wallet.reauthorize({
21432
- auth_token: this.authToken,
21433
- identity: this.appIdentity,
21434
- });
21435
- this.storeAuthResult(authResult);
21436
- return authResult;
21437
- }
21438
- catch (e) {
21439
- // Reauth failed (token expired, wallet reset, etc.) — try fresh authorize
21440
- console.warn('[SolanaMobileWallet] Reauthorization failed, attempting fresh authorize:', e === null || e === void 0 ? void 0 : e.message);
21441
- const authResult = await wallet.authorize({
21442
- identity: this.appIdentity,
21443
- chain: this.chain,
21444
- });
21445
- this.storeAuthResult(authResult);
21446
- return authResult;
21565
+ if (wallet.accounts.length === 0) {
21566
+ const user = await this.login();
21567
+ if (!user)
21568
+ throw new Error('MWA not connected');
21447
21569
  }
21570
+ return wallet.accounts[0];
21448
21571
  }
21449
- /** Persist auth result from an authorize/reauthorize call */
21450
- storeAuthResult(authResult) {
21451
- var _a;
21452
- this.authToken = authResult.auth_token;
21453
- this.walletUriBase = authResult.wallet_uri_base;
21454
- if (((_a = authResult.accounts) === null || _a === void 0 ? void 0 : _a.length) > 0) {
21455
- const account = authResult.accounts[0];
21456
- this.base64Address = account.address;
21457
- // Decode base64 address → PublicKey → base58
21458
- const addressBytes = Uint8Array.from(getPlatform().atob(account.address), c => c.charCodeAt(0));
21459
- this.publicKeyObj = new web3_js.PublicKey(addressBytes);
21460
- this.authorizedPublicKey = this.publicKeyObj.toBase58();
21461
- }
21572
+ /** Returns the active wallet-standard chain identifier (e.g. 'solana:mainnet'). */
21573
+ getChain() {
21574
+ return mapChainToWalletStandard(this.cluster);
21462
21575
  }
21463
21576
  async login() {
21464
21577
  var _a, _b, _c, _d, _e;
21465
21578
  setAuthLoading(true);
21466
- // Mark the auth method early so a concurrent Phantom auto-create can see
21467
- // 'mobile-wallet-adapter' during our slow transact() / session-creation
21468
- // roundtrip and back off (see phantom-wallet-provider autoCreateSession).
21469
- // Capture the previous value so we can restore it if login fails.
21470
- let prevAuthMethod = null;
21471
- try {
21472
- prevAuthMethod = getPlatform().storage.getItem('tarobase_last_auth_method');
21473
- }
21474
- catch (_f) { }
21579
+ // Mark the auth method early so a concurrent Phantom auto-create-session
21580
+ // effect (see phantom-wallet-provider) sees 'mobile-wallet-adapter'
21581
+ // during our slow connect/sign roundtrip and backs off. Capture the
21582
+ // previous value so we can restore it if login fails.
21583
+ const prevAuthMethod = readAuthMethod();
21584
+ writeAuthMethod(MWA_AUTH_METHOD);
21475
21585
  try {
21476
- getPlatform().storage.setItem('tarobase_last_auth_method', 'mobile-wallet-adapter');
21477
- }
21478
- catch (_g) { }
21479
- try {
21480
- await loadMwaProtocol();
21481
- const { transact } = mwaProtocolModule;
21482
- // Quick check: if we already have auth state and a valid session, skip
21483
- if (this.authorizedPublicKey) {
21586
+ const wallet = await this.ensureWallet();
21587
+ // Quick-check: wallet may already have authorization (e.g. from a
21588
+ // previous in-page login) and a matching Tarobase session — skip
21589
+ // popups in that case.
21590
+ if (wallet.accounts.length > 0) {
21591
+ const accountPubkey = new web3_js.PublicKey(wallet.accounts[0].publicKey);
21592
+ const base58Addr = accountPubkey.toBase58();
21484
21593
  const existingSession = await WebSessionManager.getSession();
21485
- if (existingSession && existingSession.address === this.authorizedPublicKey) {
21486
- const user = { provider: this, address: this.authorizedPublicKey };
21594
+ if (existingSession && existingSession.address === base58Addr) {
21595
+ const user = { provider: this, address: base58Addr };
21487
21596
  setCurrentUser(user);
21488
21597
  return user;
21489
21598
  }
21490
21599
  }
21491
- // Pre-fetch nonce from server while wallet is not yet connected
21600
+ // Pre-fetch nonce while the wallet popup is not yet open.
21492
21601
  const nonce = await genAuthNonce();
21493
- // Single transact() call: authorize + signMessages one wallet popup
21494
- const result = await transact(async (wallet) => {
21495
- // Step 1: Authorize user approves the dApp
21496
- const authResult = await wallet.authorize({
21497
- identity: this.appIdentity,
21498
- chain: this.chain,
21499
- });
21500
- const base64Addr = authResult.accounts[0].address;
21501
- const addressBytes = Uint8Array.from(getPlatform().atob(base64Addr), c => c.charCodeAt(0));
21502
- const pubkey = new web3_js.PublicKey(addressBytes);
21503
- const base58Addr = pubkey.toBase58();
21504
- // Step 2: Sign the auth message — still in the same wallet session
21505
- const messageText = await genSolanaMessage(base58Addr, nonce);
21506
- const messageBytes = getPlatform().textEncode(messageText);
21507
- const signedMessages = await wallet.signMessages({
21508
- addresses: [base64Addr],
21509
- payloads: [messageBytes],
21510
- });
21511
- // The signed payload is [original message bytes][64-byte ed25519 signature]
21512
- const signedPayload = signedMessages[0];
21513
- const signatureBytes = signedPayload.slice(-ED25519_SIGNATURE_LENGTH);
21514
- return {
21515
- base58Address: base58Addr,
21516
- base64Address: base64Addr,
21517
- publicKey: pubkey,
21518
- signature: bufferExports.Buffer.from(signatureBytes).toString('base64'),
21519
- messageText,
21520
- authToken: authResult.auth_token,
21521
- walletUriBase: authResult.wallet_uri_base,
21522
- };
21523
- }, this.getAssociationConfig());
21524
- // Store MWA auth state for reauthorization in subsequent transact() calls
21525
- this.authToken = result.authToken;
21526
- this.walletUriBase = result.walletUriBase;
21527
- this.base64Address = result.base64Address;
21528
- this.authorizedPublicKey = result.base58Address;
21529
- this.publicKeyObj = result.publicKey;
21530
- // Check if we already have a valid session for this address
21602
+ // Wallet popup #1: standard:connect performs MWA authorize. This
21603
+ // is where wallet-standard's checkLocalNetworkAccessPermission()
21604
+ // fires the three-stage LNA UX (info modal → permission prompt →
21605
+ // success modal) before opening the localhost WebSocket.
21606
+ const connectFeat = getConnectFeature(wallet);
21607
+ const { accounts } = await connectFeat.connect();
21608
+ if (!accounts || accounts.length === 0) {
21609
+ throw new Error('MWA returned no accounts');
21610
+ }
21611
+ const account = accounts[0];
21612
+ const accountPubkey = new web3_js.PublicKey(account.publicKey);
21613
+ const base58Addr = accountPubkey.toBase58();
21614
+ // If we happen to already have a matching Tarobase session, reuse it.
21531
21615
  const existingSession = await WebSessionManager.getSession();
21532
- if (existingSession && existingSession.address === result.base58Address) {
21533
- const user = { provider: this, address: result.base58Address };
21616
+ if (existingSession && existingSession.address === base58Addr) {
21617
+ const user = { provider: this, address: base58Addr };
21534
21618
  setCurrentUser(user);
21535
21619
  return user;
21536
21620
  }
21537
- // Create new session on the server
21538
- const createSessionResult = await createSessionWithSignature(result.base58Address, result.messageText, result.signature);
21539
- await WebSessionManager.storeSession(result.base58Address, createSessionResult.accessToken, createSessionResult.idToken, createSessionResult.refreshToken);
21540
- // Mark auth method
21541
- try {
21542
- getPlatform().storage.setItem('tarobase_last_auth_method', 'mobile-wallet-adapter');
21621
+ // Wallet popup #2: sign the Tarobase nonce message.
21622
+ const messageText = await genSolanaMessage(base58Addr, nonce);
21623
+ const messageBytes = getPlatform().textEncode(messageText);
21624
+ const signMessageFeat = getSignMessageFeature(wallet);
21625
+ const signResults = await signMessageFeat.signMessage({ account, message: messageBytes });
21626
+ if (!signResults || signResults.length === 0) {
21627
+ throw new Error('MWA returned no signature');
21543
21628
  }
21544
- catch (_h) { }
21545
- const user = { provider: this, address: result.base58Address };
21629
+ const { signature: sigBytes } = signResults[0];
21630
+ const signatureBase64 = bufferExports.Buffer.from(sigBytes).toString('base64');
21631
+ // Create Tarobase session on the server.
21632
+ const createSessionResult = await createSessionWithSignature(base58Addr, messageText, signatureBase64);
21633
+ await WebSessionManager.storeSession(base58Addr, createSessionResult.accessToken, createSessionResult.idToken, createSessionResult.refreshToken);
21634
+ // Auth-method marker is already 'mobile-wallet-adapter' from above.
21635
+ const user = { provider: this, address: base58Addr };
21546
21636
  setCurrentUser(user);
21547
21637
  return user;
21548
21638
  }
21549
21639
  catch (error) {
21550
- // Restore the previous auth method since this login attempt failed.
21551
- try {
21552
- if (prevAuthMethod === null) {
21553
- getPlatform().storage.removeItem('tarobase_last_auth_method');
21554
- }
21555
- else {
21556
- getPlatform().storage.setItem('tarobase_last_auth_method', prevAuthMethod);
21557
- }
21558
- }
21559
- catch (_j) { }
21640
+ // Restore the previous auth-method marker since this login attempt failed.
21641
+ writeAuthMethod(prevAuthMethod);
21560
21642
  const isUserRejection = (error === null || error === void 0 ? void 0 : error.code) === 4001 ||
21561
21643
  ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes('user rejected')) ||
21562
21644
  ((_b = error === null || error === void 0 ? void 0 : error.message) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes('user denied')) ||
@@ -21575,61 +21657,42 @@ class SolanaMobileWalletProvider {
21575
21657
  async restoreSession() {
21576
21658
  const session = await WebSessionManager.getSession();
21577
21659
  if (session) {
21578
- this.authorizedPublicKey = session.address;
21579
- this.publicKeyObj = new web3_js.PublicKey(session.address);
21580
21660
  return { provider: this, address: session.address };
21581
21661
  }
21582
21662
  return null;
21583
21663
  }
21584
21664
  async logout() {
21585
- // Deauthorize with the wallet if we have an auth_token
21586
- if (this.authToken) {
21587
- try {
21588
- await loadMwaProtocol();
21589
- const { transact } = mwaProtocolModule;
21590
- const authToken = this.authToken;
21591
- await transact(async (wallet) => {
21592
- await wallet.deauthorize({ auth_token: authToken });
21593
- }, this.getAssociationConfig());
21594
- }
21595
- catch (error) {
21596
- console.error('[SolanaMobileWallet] Deauthorize error:', error);
21665
+ try {
21666
+ const wallet = await this.ensureWallet();
21667
+ const disconnectFeat = getDisconnectFeature(wallet);
21668
+ if (disconnectFeat) {
21669
+ // Disconnect clears the AuthorizationCache and resets
21670
+ // wallet.#authorization internally (no LNA dialog).
21671
+ await disconnectFeat.disconnect();
21597
21672
  }
21598
21673
  }
21599
- this.authToken = null;
21600
- this.walletUriBase = null;
21601
- this.base64Address = null;
21602
- this.authorizedPublicKey = null;
21603
- this.publicKeyObj = null;
21674
+ catch (error) {
21675
+ console.error('[SolanaMobileWallet] Disconnect error:', error);
21676
+ }
21604
21677
  WebSessionManager.clearSession();
21605
21678
  // Clear the auth-method marker so Phantom auto-create is unblocked
21606
21679
  // for any subsequent fresh login on this device.
21607
- try {
21608
- getPlatform().storage.removeItem('tarobase_last_auth_method');
21609
- }
21610
- catch (_a) { }
21680
+ writeAuthMethod(null);
21611
21681
  setCurrentUser(null);
21612
21682
  }
21613
21683
  async signMessage(message) {
21614
21684
  var _a, _b;
21615
- if (!this.authorizedPublicKey || !this.base64Address) {
21616
- throw new Error('Not connected. Call login() first.');
21617
- }
21618
- await loadMwaProtocol();
21619
- const { transact } = mwaProtocolModule;
21620
- const base64Addr = this.base64Address;
21685
+ const account = await this.ensureAuthorized();
21686
+ const wallet = await this.ensureWallet();
21621
21687
  try {
21622
- const signedMessages = await transact(async (wallet) => {
21623
- await this.reauthorizeWallet(wallet);
21624
- const messageBytes = getPlatform().textEncode(message);
21625
- return wallet.signMessages({
21626
- addresses: [base64Addr],
21627
- payloads: [messageBytes],
21628
- });
21629
- }, this.getAssociationConfig());
21630
- const signedPayload = signedMessages[0];
21631
- const signatureBytes = signedPayload.slice(-ED25519_SIGNATURE_LENGTH);
21632
- return bufferExports.Buffer.from(signatureBytes).toString('base64');
21688
+ const signMessageFeat = getSignMessageFeature(wallet);
21689
+ const messageBytes = getPlatform().textEncode(message);
21690
+ const results = await signMessageFeat.signMessage({ account, message: messageBytes });
21691
+ if (!results || results.length === 0) {
21692
+ throw new Error('MWA returned no signature');
21693
+ }
21694
+ const { signature: sigBytes } = results[0];
21695
+ return bufferExports.Buffer.from(sigBytes).toString('base64');
21633
21696
  }
21634
21697
  catch (error) {
21635
21698
  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')) ||
@@ -21642,41 +21705,42 @@ class SolanaMobileWalletProvider {
21642
21705
  }
21643
21706
  async signTransaction(transaction) {
21644
21707
  var _a, _b;
21645
- if (!this.publicKeyObj) {
21646
- throw new Error('Not connected. Call login() first.');
21647
- }
21648
- await loadMwaProtocol();
21649
- const { transact } = mwaProtocolModule;
21650
- // Ensure blockhash and fee payer are set before signing
21708
+ const account = await this.ensureAuthorized();
21709
+ const connectedPubkey = new web3_js.PublicKey(account.publicKey);
21710
+ const wallet = await this.ensureWallet();
21711
+ const chain = this.getChain();
21712
+ // Preserve existing prep: fill missing blockhash / fee payer so call
21713
+ // sites that build a tx without these fields don't regress.
21651
21714
  const isLegacyTransaction = 'recentBlockhash' in transaction && !('message' in transaction && 'staticAccountKeys' in transaction.message);
21652
21715
  if (isLegacyTransaction) {
21653
21716
  const legacyTx = transaction;
21654
21717
  if (!legacyTx.recentBlockhash) {
21655
- const rpcUrl = this.getRpcUrl();
21656
- const connection = new web3_js.Connection(rpcUrl, 'confirmed');
21657
- const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
21718
+ const conn = new web3_js.Connection(this.getRpcUrl(), 'confirmed');
21719
+ const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash('confirmed');
21658
21720
  legacyTx.recentBlockhash = blockhash;
21659
21721
  legacyTx.lastValidBlockHeight = lastValidBlockHeight;
21660
21722
  }
21661
- if (!legacyTx.feePayer && this.publicKeyObj) {
21662
- legacyTx.feePayer = this.publicKeyObj;
21723
+ if (!legacyTx.feePayer) {
21724
+ legacyTx.feePayer = connectedPubkey;
21663
21725
  }
21664
21726
  }
21665
21727
  else {
21666
21728
  const versionedTx = transaction;
21667
21729
  if (!versionedTx.message.recentBlockhash) {
21668
- const rpcUrl = this.getRpcUrl();
21669
- const connection = new web3_js.Connection(rpcUrl, 'confirmed');
21670
- const { blockhash } = await connection.getLatestBlockhash('confirmed');
21730
+ const conn = new web3_js.Connection(this.getRpcUrl(), 'confirmed');
21731
+ const { blockhash } = await conn.getLatestBlockhash('confirmed');
21671
21732
  versionedTx.message.recentBlockhash = blockhash;
21672
21733
  }
21673
21734
  }
21674
21735
  try {
21675
- const signedTransactions = await transact(async (wallet) => {
21676
- await this.reauthorizeWallet(wallet);
21677
- return wallet.signTransactions({ transactions: [transaction] });
21678
- }, this.getAssociationConfig());
21679
- return signedTransactions[0];
21736
+ const signTxFeat = getSignTransactionFeature(wallet);
21737
+ const wireBytes = txToWireBytes(transaction);
21738
+ const results = await signTxFeat.signTransaction({ account, transaction: wireBytes, chain });
21739
+ if (!results || results.length === 0) {
21740
+ throw new Error('MWA returned no signed transaction');
21741
+ }
21742
+ const { signedTransaction: signedBytes } = results[0];
21743
+ return txFromWireBytes(new Uint8Array(signedBytes));
21680
21744
  }
21681
21745
  catch (error) {
21682
21746
  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')) ||
@@ -21689,15 +21753,15 @@ class SolanaMobileWalletProvider {
21689
21753
  }
21690
21754
  async signAndSubmitTransaction(transaction, feePayer) {
21691
21755
  var _a, _b, _c, _d, _e, _f;
21692
- if (!this.publicKeyObj) {
21693
- throw new Error('Not connected. Call login() first.');
21694
- }
21695
- await loadMwaProtocol();
21696
- const { transact } = mwaProtocolModule;
21756
+ const account = await this.ensureAuthorized();
21757
+ const connectedPubkey = new web3_js.PublicKey(account.publicKey);
21758
+ const wallet = await this.ensureWallet();
21759
+ const chain = this.getChain();
21697
21760
  const rpcUrl = this.getRpcUrl();
21698
21761
  const connection = new web3_js.Connection(rpcUrl, 'confirmed');
21699
21762
  const isSurfnet = rpcUrl === SURFNET_RPC_URL$2;
21700
21763
  try {
21764
+ // Preserve existing prep: refresh blockhash and set fee payer.
21701
21765
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
21702
21766
  const isLegacyTransaction = 'recentBlockhash' in transaction && !('message' in transaction && 'staticAccountKeys' in transaction.message);
21703
21767
  if (isLegacyTransaction) {
@@ -21705,12 +21769,7 @@ class SolanaMobileWalletProvider {
21705
21769
  legacyTx.recentBlockhash = blockhash;
21706
21770
  legacyTx.lastValidBlockHeight = lastValidBlockHeight;
21707
21771
  if (!legacyTx.feePayer) {
21708
- if (feePayer) {
21709
- legacyTx.feePayer = feePayer;
21710
- }
21711
- else if (this.publicKeyObj) {
21712
- legacyTx.feePayer = this.publicKeyObj;
21713
- }
21772
+ legacyTx.feePayer = feePayer !== null && feePayer !== void 0 ? feePayer : connectedPubkey;
21714
21773
  }
21715
21774
  }
21716
21775
  else {
@@ -21718,14 +21777,19 @@ class SolanaMobileWalletProvider {
21718
21777
  versionedTx.message.recentBlockhash = blockhash;
21719
21778
  }
21720
21779
  if (isSurfnet) {
21721
- // Surfnet: sign-only, then submit to our specific RPC
21722
- const signedTransactions = await transact(async (wallet) => {
21723
- await this.reauthorizeWallet(wallet);
21724
- return wallet.signTransactions({ transactions: [transaction] });
21725
- }, this.getAssociationConfig());
21726
- const signedTx = signedTransactions[0];
21780
+ // Surfnet: sign locally via wallet-standard, submit manually
21781
+ // to the Surfnet RPC. Don't route through signAndSendTransaction
21782
+ // because the wallet would submit to its own RPC.
21783
+ const signTxFeat = getSignTransactionFeature(wallet);
21784
+ const wireBytes = txToWireBytes(transaction);
21785
+ const results = await signTxFeat.signTransaction({ account, transaction: wireBytes, chain });
21786
+ if (!results || results.length === 0) {
21787
+ throw new Error('MWA returned no signed transaction');
21788
+ }
21789
+ const { signedTransaction: signedBytes } = results[0];
21790
+ const signedTx = txFromWireBytes(new Uint8Array(signedBytes));
21727
21791
  const signature = await connection.sendRawTransaction(signedTx.serialize(), {
21728
- preflightCommitment: 'confirmed'
21792
+ preflightCommitment: 'confirmed',
21729
21793
  });
21730
21794
  const confirmation = await connection.confirmTransaction({
21731
21795
  signature,
@@ -21737,15 +21801,20 @@ class SolanaMobileWalletProvider {
21737
21801
  }
21738
21802
  return signature;
21739
21803
  }
21740
- // Non-surfnet: use signAndSendTransactions for wallet-optimized submission
21741
- const signatures = await transact(async (wallet) => {
21742
- await this.reauthorizeWallet(wallet);
21743
- return wallet.signAndSendTransactions({
21744
- transactions: [transaction],
21745
- commitment: 'confirmed',
21746
- });
21747
- }, this.getAssociationConfig());
21748
- const signature = signatures[0];
21804
+ // Non-Surfnet: wallet signs and submits to its own RPC.
21805
+ const signSendFeat = getSignAndSendTransactionFeature(wallet);
21806
+ const wireBytes = txToWireBytes(transaction);
21807
+ const results = await signSendFeat.signAndSendTransaction({
21808
+ account,
21809
+ transaction: wireBytes,
21810
+ chain,
21811
+ options: { commitment: 'confirmed' },
21812
+ });
21813
+ if (!results || results.length === 0) {
21814
+ throw new Error('MWA returned no signature');
21815
+ }
21816
+ const { signature: sigBytes } = results[0];
21817
+ const signature = base58.encode(sigBytes);
21749
21818
  await confirmAndCheckTransaction(connection, signature);
21750
21819
  return signature;
21751
21820
  }
@@ -21771,16 +21840,14 @@ class SolanaMobileWalletProvider {
21771
21840
  if (!solTransactionData) {
21772
21841
  throw new Error('Solana transaction data is required for mobile wallet');
21773
21842
  }
21774
- if (!this.publicKeyObj || !this.authorizedPublicKey) {
21775
- await this.login();
21776
- }
21777
- await loadMwaProtocol();
21778
- const { transact } = mwaProtocolModule;
21843
+ const account = await this.ensureAuthorized();
21844
+ const connectedPubkey = new web3_js.PublicKey(account.publicKey);
21845
+ const wallet = await this.ensureWallet();
21846
+ const chain = this.getChain();
21779
21847
  const rpcUrl = this.getRpcUrl(solTransactionData.network);
21780
21848
  const connection = new web3_js.Connection(rpcUrl, 'confirmed');
21781
21849
  const isSurfnet = rpcUrl === SURFNET_RPC_URL$2;
21782
21850
  try {
21783
- const publicKey = this.publicKeyObj;
21784
21851
  const remainingAccounts = convertRemainingAccounts(solTransactionData.txArgs[0].remainingAccounts);
21785
21852
  let app_id = solTransactionData.appId;
21786
21853
  if (typeof window !== 'undefined' && window.CUSTOM_TAROBASE_APP_ID_HEADER) {
@@ -21789,9 +21856,9 @@ class SolanaMobileWalletProvider {
21789
21856
  if (!app_id) {
21790
21857
  throw new Error('App ID is required');
21791
21858
  }
21792
- // Create a mock wallet adapter for Anchor (only publicKey is needed for building TX)
21859
+ // Mock wallet adapter for Anchor only publicKey is read during build.
21793
21860
  const mockWalletAdapter = {
21794
- publicKey,
21861
+ publicKey: connectedPubkey,
21795
21862
  signTransaction: async (tx) => tx,
21796
21863
  signAllTransactions: async (txs) => txs,
21797
21864
  };
@@ -21809,10 +21876,12 @@ class SolanaMobileWalletProvider {
21809
21876
  }
21810
21877
  let tx;
21811
21878
  if (solTransactionData.signedTransaction) {
21879
+ // Server has co-signed a CPI attestation. Do NOT mutate its
21880
+ // blockhash — that would invalidate the server's signature.
21812
21881
  tx = web3_js.VersionedTransaction.deserialize(bufferExports.Buffer.from(solTransactionData.signedTransaction, 'base64'));
21813
21882
  }
21814
21883
  else {
21815
- const result = await buildSetDocumentsTransaction(connection, solTransactionData.txArgs[0].idl, anchorProvider, publicKey, {
21884
+ const result = await buildSetDocumentsTransaction(connection, solTransactionData.txArgs[0].idl, anchorProvider, connectedPubkey, {
21816
21885
  app_id,
21817
21886
  documents: solTransactionData.txArgs[0].setDocumentData,
21818
21887
  delete_paths: solTransactionData.txArgs[0].deletePaths,
@@ -21820,11 +21889,16 @@ class SolanaMobileWalletProvider {
21820
21889
  }, finalDeduped, solTransactionData.lutKey, solTransactionData.preInstructions, false, solTransactionData.additionalLutAddresses);
21821
21890
  tx = result.tx;
21822
21891
  }
21892
+ // Sign-only branch — sign the tx but don't submit.
21823
21893
  if ((options === null || options === void 0 ? void 0 : options.shouldSubmitTx) === false) {
21824
- const [signedTx] = await transact(async (wallet) => {
21825
- await this.reauthorizeWallet(wallet);
21826
- return wallet.signTransactions({ transactions: [tx] });
21827
- }, this.getAssociationConfig());
21894
+ const signTxFeat = getSignTransactionFeature(wallet);
21895
+ const wireBytes = txToWireBytes(tx);
21896
+ const results = await signTxFeat.signTransaction({ account, transaction: wireBytes, chain });
21897
+ if (!results || results.length === 0) {
21898
+ throw new Error('MWA returned no signed transaction');
21899
+ }
21900
+ const { signedTransaction: signedBytes } = results[0];
21901
+ const signedTx = txFromWireBytes(new Uint8Array(signedBytes));
21828
21902
  return {
21829
21903
  signedTransaction: signedTx,
21830
21904
  blockNumber: 0,
@@ -21833,14 +21907,18 @@ class SolanaMobileWalletProvider {
21833
21907
  };
21834
21908
  }
21835
21909
  if (isSurfnet) {
21836
- // Surfnet: sign then submit manually to our RPC
21837
- const [signedTx] = await transact(async (wallet) => {
21838
- await this.reauthorizeWallet(wallet);
21839
- return wallet.signTransactions({ transactions: [tx] });
21840
- }, this.getAssociationConfig());
21910
+ // Surfnet: sign locally via wallet-standard, submit manually.
21911
+ const signTxFeat = getSignTransactionFeature(wallet);
21912
+ const wireBytes = txToWireBytes(tx);
21913
+ const results = await signTxFeat.signTransaction({ account, transaction: wireBytes, chain });
21914
+ if (!results || results.length === 0) {
21915
+ throw new Error('MWA returned no signed transaction');
21916
+ }
21917
+ const { signedTransaction: signedBytes } = results[0];
21918
+ const signedTx = txFromWireBytes(new Uint8Array(signedBytes));
21841
21919
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
21842
21920
  const signature = await connection.sendRawTransaction(signedTx.serialize(), {
21843
- preflightCommitment: 'confirmed'
21921
+ preflightCommitment: 'confirmed',
21844
21922
  });
21845
21923
  const confirmation = await connection.confirmTransaction({
21846
21924
  signature,
@@ -21852,7 +21930,7 @@ class SolanaMobileWalletProvider {
21852
21930
  }
21853
21931
  const txInfo = await connection.getParsedTransaction(signature, {
21854
21932
  maxSupportedTransactionVersion: 0,
21855
- commitment: 'confirmed'
21933
+ commitment: 'confirmed',
21856
21934
  });
21857
21935
  return {
21858
21936
  transactionSignature: signature,
@@ -21861,15 +21939,20 @@ class SolanaMobileWalletProvider {
21861
21939
  data: txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta,
21862
21940
  };
21863
21941
  }
21864
- // Non-surfnet: use signAndSendTransactions
21865
- const signatures = await transact(async (wallet) => {
21866
- await this.reauthorizeWallet(wallet);
21867
- return wallet.signAndSendTransactions({
21868
- transactions: [tx],
21869
- commitment: 'confirmed',
21870
- });
21871
- }, this.getAssociationConfig());
21872
- const signature = signatures[0];
21942
+ // Non-Surfnet: wallet signs and submits to its own RPC.
21943
+ const signSendFeat = getSignAndSendTransactionFeature(wallet);
21944
+ const wireBytes = txToWireBytes(tx);
21945
+ const results = await signSendFeat.signAndSendTransaction({
21946
+ account,
21947
+ transaction: wireBytes,
21948
+ chain,
21949
+ options: { commitment: 'confirmed' },
21950
+ });
21951
+ if (!results || results.length === 0) {
21952
+ throw new Error('MWA returned no signature');
21953
+ }
21954
+ const { signature: sigBytes } = results[0];
21955
+ const signature = base58.encode(sigBytes);
21873
21956
  const txInfo = await confirmAndCheckTransaction(connection, signature);
21874
21957
  return {
21875
21958
  transactionSignature: signature,
@@ -21896,11 +21979,36 @@ class SolanaMobileWalletProvider {
21896
21979
  }
21897
21980
  }
21898
21981
  async getNativeMethods() {
21982
+ var _a, _b, _c;
21983
+ // Synchronous-ish state read; tolerate the wallet being unauthorized
21984
+ // (return nulls). Don't trigger ensureAuthorized() here — callers that
21985
+ // need the wallet active should sign through one of the sign methods.
21986
+ const wallet = this.wallet;
21987
+ if (!wallet) {
21988
+ return {
21989
+ authToken: null,
21990
+ walletUriBase: null,
21991
+ publicKey: null,
21992
+ base64Address: null,
21993
+ wallet: null,
21994
+ currentAuthorization: null,
21995
+ };
21996
+ }
21997
+ const acct = (_a = wallet.accounts) === null || _a === void 0 ? void 0 : _a[0];
21998
+ const auth = wallet.currentAuthorization;
21999
+ let publicKey = null;
22000
+ let base64Address = null;
22001
+ if (acct) {
22002
+ publicKey = new web3_js.PublicKey(acct.publicKey);
22003
+ base64Address = btoa(String.fromCharCode(...acct.publicKey));
22004
+ }
21899
22005
  return {
21900
- authToken: this.authToken,
21901
- walletUriBase: this.walletUriBase,
21902
- publicKey: this.publicKeyObj,
21903
- base64Address: this.base64Address,
22006
+ authToken: (_b = auth === null || auth === void 0 ? void 0 : auth.auth_token) !== null && _b !== void 0 ? _b : null,
22007
+ walletUriBase: (_c = auth === null || auth === void 0 ? void 0 : auth.wallet_uri_base) !== null && _c !== void 0 ? _c : null,
22008
+ publicKey,
22009
+ base64Address,
22010
+ wallet,
22011
+ currentAuthorization: auth !== null && auth !== void 0 ? auth : null,
21904
22012
  };
21905
22013
  }
21906
22014
  /* ----------------------------------------------------------- *
@@ -22328,4 +22436,4 @@ exports.signSessionCreateMessage = signSessionCreateMessage;
22328
22436
  exports.signTransaction = signTransaction;
22329
22437
  exports.subscribe = subscribe;
22330
22438
  exports.useAuth = useAuth;
22331
- //# sourceMappingURL=index-BPlF6-PQ.js.map
22439
+ //# sourceMappingURL=index-R7cvXys2.js.map