@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
@@ -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-Buu8v-Oe.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,135 @@ 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 () => {
21292
- try {
21293
- mwaProtocolModule = await import('./index.browser-D8VWPXTZ.esm.js');
21281
+ const STORED_AUTH_METHOD_KEY = 'tarobase_last_auth_method';
21282
+ const MWA_AUTH_METHOD = 'mobile-wallet-adapter';
21283
+ /**
21284
+ * Normalize a chain string to a wallet-standard Solana chain identifier.
21285
+ *
21286
+ * Handles three input shapes that all show up in practice:
21287
+ * - Bare cluster name from `SolanaMobileWalletConfig.cluster` (e.g. 'devnet').
21288
+ * - Prefixed `solana:cluster` (e.g. 'solana:devnet').
21289
+ * - Double-prefixed `solana:solana:cluster` (constructor used to wrap cluster
21290
+ * with `solana:` blindly; if a caller already passed a prefixed string the
21291
+ * result was `solana:solana:devnet`).
21292
+ *
21293
+ * Wallet-standard Solana chains are exactly:
21294
+ * 'solana:mainnet' | 'solana:devnet' | 'solana:testnet' | 'solana:localnet'
21295
+ * — `mainnet-beta` is NOT a valid wallet-standard identifier and must be
21296
+ * normalized to `solana:mainnet`.
21297
+ */
21298
+ function mapChainToWalletStandard(input) {
21299
+ if (!input)
21300
+ return 'solana:mainnet';
21301
+ let s = String(input).toLowerCase();
21302
+ while (s.startsWith('solana:'))
21303
+ s = s.slice('solana:'.length);
21304
+ if (s === 'mainnet-beta' || s === 'mainnet')
21305
+ return 'solana:mainnet';
21306
+ if (s === 'devnet')
21307
+ return 'solana:devnet';
21308
+ if (s === 'testnet')
21309
+ return 'solana:testnet';
21310
+ if (s === 'localnet')
21311
+ return 'solana:localnet';
21312
+ return 'solana:mainnet';
21313
+ }
21314
+ /**
21315
+ * Serialize a Transaction/VersionedTransaction to a Uint8Array wire payload
21316
+ * that the wallet-standard `solana:signTransaction` /
21317
+ * `solana:signAndSendTransaction` features expect.
21318
+ *
21319
+ * Legacy transactions must serialize with `requireAllSignatures: false` and
21320
+ * `verifySignatures: false` — the wallet hasn't signed yet, and the default
21321
+ * `serialize()` would throw "Signature verification failed". Versioned
21322
+ * transactions use the default `serialize()` which already permits unsigned
21323
+ * payloads. Mirrors the helper at
21324
+ * `@solana-mobile/mobile-wallet-adapter-protocol-web3js/lib/esm/index.browser.js:13-18`.
21325
+ */
21326
+ function txToWireBytes(tx) {
21327
+ if ('version' in tx)
21328
+ return tx.serialize();
21329
+ return tx.serialize({ requireAllSignatures: false, verifySignatures: false });
21330
+ }
21331
+ /**
21332
+ * Deserialize a wire-format transaction returned by the wallet
21333
+ * `solana:signTransaction` feature. Mirrors the helper at
21334
+ * `@solana-mobile/mobile-wallet-adapter-protocol-web3js/lib/esm/index.browser.js:19-23`
21335
+ * so legacy and versioned bytes both round-trip correctly.
21336
+ */
21337
+ function txFromWireBytes(byteArray) {
21338
+ const messageOffset = byteArray[0] * ED25519_SIGNATURE_LENGTH + 1;
21339
+ const messageVersion = VersionedMessage.deserializeMessageVersion(byteArray.slice(messageOffset, byteArray.length));
21340
+ if (messageVersion === 'legacy') {
21341
+ return Transaction.from(byteArray);
21342
+ }
21343
+ return VersionedTransaction.deserialize(byteArray);
21344
+ }
21345
+ /**
21346
+ * Per-method runtime narrowing of wallet-standard features. The wallet's
21347
+ * `.features` type is a union (`signAndSendTransaction` | `signTransaction`),
21348
+ * and after authorization the wallet may also narrow `#optionalFeatures`
21349
+ * based on actual wallet capabilities. Narrow at the call site so a method
21350
+ * that needs only `signMessage` doesn't fail when a wallet lacks
21351
+ * `signTransaction`.
21352
+ */
21353
+ function getSignMessageFeature(wallet) {
21354
+ const f = wallet.features;
21355
+ const feat = f['solana:signMessage'];
21356
+ if (!feat || typeof feat.signMessage !== 'function') {
21357
+ throw new Error('Wallet does not support solana:signMessage');
21358
+ }
21359
+ return feat;
21360
+ }
21361
+ function getSignTransactionFeature(wallet) {
21362
+ const f = wallet.features;
21363
+ const feat = f['solana:signTransaction'];
21364
+ if (!feat || typeof feat.signTransaction !== 'function') {
21365
+ throw new Error('Wallet does not support solana:signTransaction');
21366
+ }
21367
+ return feat;
21368
+ }
21369
+ function getSignAndSendTransactionFeature(wallet) {
21370
+ const f = wallet.features;
21371
+ const feat = f['solana:signAndSendTransaction'];
21372
+ if (!feat || typeof feat.signAndSendTransaction !== 'function') {
21373
+ throw new Error('Wallet does not support solana:signAndSendTransaction');
21374
+ }
21375
+ return feat;
21376
+ }
21377
+ function getConnectFeature(wallet) {
21378
+ const f = wallet.features;
21379
+ const feat = f['standard:connect'];
21380
+ if (!feat || typeof feat.connect !== 'function') {
21381
+ throw new Error('Wallet does not support standard:connect');
21382
+ }
21383
+ return feat;
21384
+ }
21385
+ function getDisconnectFeature(wallet) {
21386
+ const f = wallet.features;
21387
+ const feat = f['standard:disconnect'];
21388
+ return feat && typeof feat.disconnect === 'function' ? feat : null;
21389
+ }
21390
+ function writeAuthMethod(method) {
21391
+ try {
21392
+ if (method === null) {
21393
+ getPlatform().storage.removeItem(STORED_AUTH_METHOD_KEY);
21294
21394
  }
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');
21395
+ else {
21396
+ getPlatform().storage.setItem(STORED_AUTH_METHOD_KEY, method);
21298
21397
  }
21299
- })();
21300
- return mwaProtocolLoadPromise;
21398
+ }
21399
+ catch (_a) {
21400
+ // storage may be unavailable
21401
+ }
21402
+ }
21403
+ function readAuthMethod() {
21404
+ try {
21405
+ return getPlatform().storage.getItem(STORED_AUTH_METHOD_KEY);
21406
+ }
21407
+ catch (_a) {
21408
+ return null;
21409
+ }
21301
21410
  }
21302
21411
  /**
21303
21412
  * Registers Mobile Wallet Adapter as a wallet-standard wallet so it appears
@@ -21312,7 +21421,7 @@ async function registerMobileWalletAdapter(config) {
21312
21421
  if (typeof window === 'undefined')
21313
21422
  return;
21314
21423
  try {
21315
- const walletStandardMobile = await import('./index.browser-Cgj7Hs6n.esm.js');
21424
+ const walletStandardMobile = await import('./index.browser-zfGYm0ST.esm.js');
21316
21425
  const registerMwa = walletStandardMobile.registerMwa || ((_a = walletStandardMobile.default) === null || _a === void 0 ? void 0 : _a.registerMwa);
21317
21426
  if (!registerMwa) {
21318
21427
  console.warn('[SolanaMobileWallet] registerMwa not found in @solana-mobile/wallet-standard-mobile');
@@ -21341,32 +21450,41 @@ async function registerMobileWalletAdapter(config) {
21341
21450
  registerMwa(options);
21342
21451
  }
21343
21452
  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
21453
  console.debug('[SolanaMobileWallet] @solana-mobile/wallet-standard-mobile not available, skipping wallet-standard registration');
21348
21454
  }
21349
21455
  }
21350
21456
  /**
21351
- * SolanaMobileWalletProvider implements the AuthProvider interface using the
21352
- * Solana Mobile Wallet Adapter (MWA) protocol's low-level `transact` API.
21457
+ * SolanaMobileWalletProvider implements the AuthProvider interface using
21458
+ * Solana Mobile's wallet-standard wrapper (`LocalSolanaMobileWalletAdapterWallet`).
21353
21459
  *
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.
21460
+ * Why wallet-standard and not the raw MWA protocol: as of
21461
+ * `@solana-mobile/wallet-standard-mobile@0.5.0+`, the wallet's internal
21462
+ * `#transact` calls `checkLocalNetworkAccessPermission()` before opening the
21463
+ * localhost WebSocket. That helper renders a three-stage UX flow Solana
21464
+ * Mobile designed specifically to defuse Chrome's Local Network Access
21465
+ * permission dialog (which renders with disabled buttons on Android Chrome,
21466
+ * the source of the long-running Seeker MWA bug):
21357
21467
  *
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.
21468
+ * 1. "Allow connections to your wallet" informational modal.
21469
+ * 2. Chrome's permission prompt (interactive because it's spawned as a
21470
+ * fresh user gesture from step 1).
21471
+ * 3. "Ready to connect!" success modal.
21472
+ *
21473
+ * `checkLocalNetworkAccessPermission` is internal to the library — it's not
21474
+ * exported. The only way to invoke it is to go through the wallet's
21475
+ * `standard:connect` / `solana:sign*` features, which is what this provider
21476
+ * does.
21477
+ *
21478
+ * Notes on UX: login uses two wallet popups in succession — `standard:connect`
21479
+ * (authorize) and `solana:signMessage` (sign the Tarobase nonce). The
21480
+ * previous implementation combined both inside a single `transact` callback;
21481
+ * splitting them is the cost of going through wallet-standard, and is
21482
+ * acceptable given the alternative was broken on Seeker.
21361
21483
  */
21362
21484
  class SolanaMobileWalletProvider {
21363
21485
  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;
21486
+ /** LocalSolanaMobileWalletAdapterWallet, lazy-constructed in ensureWallet(). */
21487
+ this.wallet = null;
21370
21488
  this.networkUrl = networkUrl;
21371
21489
  this.config = config;
21372
21490
  if (typeof window === 'undefined') {
@@ -21379,7 +21497,7 @@ class SolanaMobileWalletProvider {
21379
21497
  name: 'TaroBase App',
21380
21498
  uri: getPlatform().getLocationOrigin(),
21381
21499
  };
21382
- this.chain = `solana:${config.cluster || 'mainnet-beta'}`;
21500
+ this.cluster = config.cluster || 'mainnet-beta';
21383
21501
  SolanaMobileWalletProvider.instance = this;
21384
21502
  }
21385
21503
  static getInstance(networkUrl, config) {
@@ -21388,154 +21506,118 @@ class SolanaMobileWalletProvider {
21388
21506
  }
21389
21507
  return SolanaMobileWalletProvider.instance;
21390
21508
  }
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;
21509
+ /** Lazy-construct LocalSolanaMobileWalletAdapterWallet on first need. */
21510
+ async ensureWallet() {
21511
+ if (this.wallet)
21512
+ return this.wallet;
21513
+ const mod = await import('./index.browser-zfGYm0ST.esm.js');
21514
+ const chain = mapChainToWalletStandard(this.cluster);
21515
+ this.wallet = new mod.LocalSolanaMobileWalletAdapterWallet({
21516
+ appIdentity: this.appIdentity,
21517
+ authorizationCache: mod.createDefaultAuthorizationCache(),
21518
+ chains: [chain],
21519
+ chainSelector: mod.createDefaultChainSelector(),
21520
+ onWalletNotFound: mod.createDefaultWalletNotFoundHandler(),
21521
+ });
21522
+ return this.wallet;
21397
21523
  }
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;
21524
+ /**
21525
+ * Ensure the wallet has an active authorization. After a Tarobase session
21526
+ * is restored from storage on cold-start, `wallet.accounts` is empty until
21527
+ * we silently reconnect from the AuthorizationCache. If the cache is also
21528
+ * empty, fall back to interactive `login()` (which surfaces the three-stage
21529
+ * Solana Mobile LNA flow + wallet popups).
21530
+ *
21531
+ * Returns the wallet-standard `WalletAccount` to use for sign operations.
21532
+ */
21533
+ async ensureAuthorized() {
21534
+ const wallet = await this.ensureWallet();
21535
+ if (wallet.accounts.length === 0) {
21536
+ try {
21537
+ const connectFeat = getConnectFeature(wallet);
21538
+ await connectFeat.connect({ silent: true });
21539
+ }
21540
+ catch (e) {
21541
+ console.warn('[SolanaMobileWallet] silent connect failed:', e === null || e === void 0 ? void 0 : e.message);
21542
+ }
21408
21543
  }
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;
21544
+ if (wallet.accounts.length === 0) {
21545
+ const user = await this.login();
21546
+ if (!user)
21547
+ throw new Error('MWA not connected');
21426
21548
  }
21549
+ return wallet.accounts[0];
21427
21550
  }
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
- }
21551
+ /** Returns the active wallet-standard chain identifier (e.g. 'solana:mainnet'). */
21552
+ getChain() {
21553
+ return mapChainToWalletStandard(this.cluster);
21441
21554
  }
21442
21555
  async login() {
21443
21556
  var _a, _b, _c, _d, _e;
21444
21557
  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) { }
21558
+ // Mark the auth method early so a concurrent Phantom auto-create-session
21559
+ // effect (see phantom-wallet-provider) sees 'mobile-wallet-adapter'
21560
+ // during our slow connect/sign roundtrip and backs off. Capture the
21561
+ // previous value so we can restore it if login fails.
21562
+ const prevAuthMethod = readAuthMethod();
21563
+ writeAuthMethod(MWA_AUTH_METHOD);
21454
21564
  try {
21455
- getPlatform().storage.setItem('tarobase_last_auth_method', 'mobile-wallet-adapter');
21456
- }
21457
- catch (_g) { }
21458
- 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) {
21565
+ const wallet = await this.ensureWallet();
21566
+ // Quick-check: wallet may already have authorization (e.g. from a
21567
+ // previous in-page login) and a matching Tarobase session — skip
21568
+ // popups in that case.
21569
+ if (wallet.accounts.length > 0) {
21570
+ const accountPubkey = new PublicKey(wallet.accounts[0].publicKey);
21571
+ const base58Addr = accountPubkey.toBase58();
21463
21572
  const existingSession = await WebSessionManager.getSession();
21464
- if (existingSession && existingSession.address === this.authorizedPublicKey) {
21465
- const user = { provider: this, address: this.authorizedPublicKey };
21573
+ if (existingSession && existingSession.address === base58Addr) {
21574
+ const user = { provider: this, address: base58Addr };
21466
21575
  setCurrentUser(user);
21467
21576
  return user;
21468
21577
  }
21469
21578
  }
21470
- // Pre-fetch nonce from server while wallet is not yet connected
21579
+ // Pre-fetch nonce while the wallet popup is not yet open.
21471
21580
  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
21581
+ // Wallet popup #1: standard:connect performs MWA authorize. This
21582
+ // is where wallet-standard's checkLocalNetworkAccessPermission()
21583
+ // fires the three-stage LNA UX (info modal → permission prompt →
21584
+ // success modal) before opening the localhost WebSocket.
21585
+ const connectFeat = getConnectFeature(wallet);
21586
+ const { accounts } = await connectFeat.connect();
21587
+ if (!accounts || accounts.length === 0) {
21588
+ throw new Error('MWA returned no accounts');
21589
+ }
21590
+ const account = accounts[0];
21591
+ const accountPubkey = new PublicKey(account.publicKey);
21592
+ const base58Addr = accountPubkey.toBase58();
21593
+ // If we happen to already have a matching Tarobase session, reuse it.
21510
21594
  const existingSession = await WebSessionManager.getSession();
21511
- if (existingSession && existingSession.address === result.base58Address) {
21512
- const user = { provider: this, address: result.base58Address };
21595
+ if (existingSession && existingSession.address === base58Addr) {
21596
+ const user = { provider: this, address: base58Addr };
21513
21597
  setCurrentUser(user);
21514
21598
  return user;
21515
21599
  }
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');
21600
+ // Wallet popup #2: sign the Tarobase nonce message.
21601
+ const messageText = await genSolanaMessage(base58Addr, nonce);
21602
+ const messageBytes = getPlatform().textEncode(messageText);
21603
+ const signMessageFeat = getSignMessageFeature(wallet);
21604
+ const signResults = await signMessageFeat.signMessage({ account, message: messageBytes });
21605
+ if (!signResults || signResults.length === 0) {
21606
+ throw new Error('MWA returned no signature');
21522
21607
  }
21523
- catch (_h) { }
21524
- const user = { provider: this, address: result.base58Address };
21608
+ const { signature: sigBytes } = signResults[0];
21609
+ const signatureBase64 = bufferExports.Buffer.from(sigBytes).toString('base64');
21610
+ // Create Tarobase session on the server.
21611
+ const createSessionResult = await createSessionWithSignature(base58Addr, messageText, signatureBase64);
21612
+ await WebSessionManager.storeSession(base58Addr, createSessionResult.accessToken, createSessionResult.idToken, createSessionResult.refreshToken);
21613
+ // Auth-method marker is already 'mobile-wallet-adapter' from above.
21614
+ const user = { provider: this, address: base58Addr };
21525
21615
  setCurrentUser(user);
21526
21616
  return user;
21527
21617
  }
21528
21618
  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) { }
21619
+ // Restore the previous auth-method marker since this login attempt failed.
21620
+ writeAuthMethod(prevAuthMethod);
21539
21621
  const isUserRejection = (error === null || error === void 0 ? void 0 : error.code) === 4001 ||
21540
21622
  ((_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.toLowerCase().includes('user rejected')) ||
21541
21623
  ((_b = error === null || error === void 0 ? void 0 : error.message) === null || _b === void 0 ? void 0 : _b.toLowerCase().includes('user denied')) ||
@@ -21554,61 +21636,42 @@ class SolanaMobileWalletProvider {
21554
21636
  async restoreSession() {
21555
21637
  const session = await WebSessionManager.getSession();
21556
21638
  if (session) {
21557
- this.authorizedPublicKey = session.address;
21558
- this.publicKeyObj = new PublicKey(session.address);
21559
21639
  return { provider: this, address: session.address };
21560
21640
  }
21561
21641
  return null;
21562
21642
  }
21563
21643
  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);
21644
+ try {
21645
+ const wallet = await this.ensureWallet();
21646
+ const disconnectFeat = getDisconnectFeature(wallet);
21647
+ if (disconnectFeat) {
21648
+ // Disconnect clears the AuthorizationCache and resets
21649
+ // wallet.#authorization internally (no LNA dialog).
21650
+ await disconnectFeat.disconnect();
21576
21651
  }
21577
21652
  }
21578
- this.authToken = null;
21579
- this.walletUriBase = null;
21580
- this.base64Address = null;
21581
- this.authorizedPublicKey = null;
21582
- this.publicKeyObj = null;
21653
+ catch (error) {
21654
+ console.error('[SolanaMobileWallet] Disconnect error:', error);
21655
+ }
21583
21656
  WebSessionManager.clearSession();
21584
21657
  // Clear the auth-method marker so Phantom auto-create is unblocked
21585
21658
  // for any subsequent fresh login on this device.
21586
- try {
21587
- getPlatform().storage.removeItem('tarobase_last_auth_method');
21588
- }
21589
- catch (_a) { }
21659
+ writeAuthMethod(null);
21590
21660
  setCurrentUser(null);
21591
21661
  }
21592
21662
  async signMessage(message) {
21593
21663
  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;
21664
+ const account = await this.ensureAuthorized();
21665
+ const wallet = await this.ensureWallet();
21600
21666
  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');
21667
+ const signMessageFeat = getSignMessageFeature(wallet);
21668
+ const messageBytes = getPlatform().textEncode(message);
21669
+ const results = await signMessageFeat.signMessage({ account, message: messageBytes });
21670
+ if (!results || results.length === 0) {
21671
+ throw new Error('MWA returned no signature');
21672
+ }
21673
+ const { signature: sigBytes } = results[0];
21674
+ return bufferExports.Buffer.from(sigBytes).toString('base64');
21612
21675
  }
21613
21676
  catch (error) {
21614
21677
  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 +21684,42 @@ class SolanaMobileWalletProvider {
21621
21684
  }
21622
21685
  async signTransaction(transaction) {
21623
21686
  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
21687
+ const account = await this.ensureAuthorized();
21688
+ const connectedPubkey = new PublicKey(account.publicKey);
21689
+ const wallet = await this.ensureWallet();
21690
+ const chain = this.getChain();
21691
+ // Preserve existing prep: fill missing blockhash / fee payer so call
21692
+ // sites that build a tx without these fields don't regress.
21630
21693
  const isLegacyTransaction = 'recentBlockhash' in transaction && !('message' in transaction && 'staticAccountKeys' in transaction.message);
21631
21694
  if (isLegacyTransaction) {
21632
21695
  const legacyTx = transaction;
21633
21696
  if (!legacyTx.recentBlockhash) {
21634
- const rpcUrl = this.getRpcUrl();
21635
- const connection = new Connection(rpcUrl, 'confirmed');
21636
- const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
21697
+ const conn = new Connection(this.getRpcUrl(), 'confirmed');
21698
+ const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash('confirmed');
21637
21699
  legacyTx.recentBlockhash = blockhash;
21638
21700
  legacyTx.lastValidBlockHeight = lastValidBlockHeight;
21639
21701
  }
21640
- if (!legacyTx.feePayer && this.publicKeyObj) {
21641
- legacyTx.feePayer = this.publicKeyObj;
21702
+ if (!legacyTx.feePayer) {
21703
+ legacyTx.feePayer = connectedPubkey;
21642
21704
  }
21643
21705
  }
21644
21706
  else {
21645
21707
  const versionedTx = transaction;
21646
21708
  if (!versionedTx.message.recentBlockhash) {
21647
- const rpcUrl = this.getRpcUrl();
21648
- const connection = new Connection(rpcUrl, 'confirmed');
21649
- const { blockhash } = await connection.getLatestBlockhash('confirmed');
21709
+ const conn = new Connection(this.getRpcUrl(), 'confirmed');
21710
+ const { blockhash } = await conn.getLatestBlockhash('confirmed');
21650
21711
  versionedTx.message.recentBlockhash = blockhash;
21651
21712
  }
21652
21713
  }
21653
21714
  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];
21715
+ const signTxFeat = getSignTransactionFeature(wallet);
21716
+ const wireBytes = txToWireBytes(transaction);
21717
+ const results = await signTxFeat.signTransaction({ account, transaction: wireBytes, chain });
21718
+ if (!results || results.length === 0) {
21719
+ throw new Error('MWA returned no signed transaction');
21720
+ }
21721
+ const { signedTransaction: signedBytes } = results[0];
21722
+ return txFromWireBytes(new Uint8Array(signedBytes));
21659
21723
  }
21660
21724
  catch (error) {
21661
21725
  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 +21732,15 @@ class SolanaMobileWalletProvider {
21668
21732
  }
21669
21733
  async signAndSubmitTransaction(transaction, feePayer) {
21670
21734
  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;
21735
+ const account = await this.ensureAuthorized();
21736
+ const connectedPubkey = new PublicKey(account.publicKey);
21737
+ const wallet = await this.ensureWallet();
21738
+ const chain = this.getChain();
21676
21739
  const rpcUrl = this.getRpcUrl();
21677
21740
  const connection = new Connection(rpcUrl, 'confirmed');
21678
21741
  const isSurfnet = rpcUrl === SURFNET_RPC_URL$2;
21679
21742
  try {
21743
+ // Preserve existing prep: refresh blockhash and set fee payer.
21680
21744
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
21681
21745
  const isLegacyTransaction = 'recentBlockhash' in transaction && !('message' in transaction && 'staticAccountKeys' in transaction.message);
21682
21746
  if (isLegacyTransaction) {
@@ -21684,12 +21748,7 @@ class SolanaMobileWalletProvider {
21684
21748
  legacyTx.recentBlockhash = blockhash;
21685
21749
  legacyTx.lastValidBlockHeight = lastValidBlockHeight;
21686
21750
  if (!legacyTx.feePayer) {
21687
- if (feePayer) {
21688
- legacyTx.feePayer = feePayer;
21689
- }
21690
- else if (this.publicKeyObj) {
21691
- legacyTx.feePayer = this.publicKeyObj;
21692
- }
21751
+ legacyTx.feePayer = feePayer !== null && feePayer !== void 0 ? feePayer : connectedPubkey;
21693
21752
  }
21694
21753
  }
21695
21754
  else {
@@ -21697,14 +21756,19 @@ class SolanaMobileWalletProvider {
21697
21756
  versionedTx.message.recentBlockhash = blockhash;
21698
21757
  }
21699
21758
  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];
21759
+ // Surfnet: sign locally via wallet-standard, submit manually
21760
+ // to the Surfnet RPC. Don't route through signAndSendTransaction
21761
+ // because the wallet would submit to its own RPC.
21762
+ const signTxFeat = getSignTransactionFeature(wallet);
21763
+ const wireBytes = txToWireBytes(transaction);
21764
+ const results = await signTxFeat.signTransaction({ account, transaction: wireBytes, chain });
21765
+ if (!results || results.length === 0) {
21766
+ throw new Error('MWA returned no signed transaction');
21767
+ }
21768
+ const { signedTransaction: signedBytes } = results[0];
21769
+ const signedTx = txFromWireBytes(new Uint8Array(signedBytes));
21706
21770
  const signature = await connection.sendRawTransaction(signedTx.serialize(), {
21707
- preflightCommitment: 'confirmed'
21771
+ preflightCommitment: 'confirmed',
21708
21772
  });
21709
21773
  const confirmation = await connection.confirmTransaction({
21710
21774
  signature,
@@ -21716,15 +21780,20 @@ class SolanaMobileWalletProvider {
21716
21780
  }
21717
21781
  return signature;
21718
21782
  }
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];
21783
+ // Non-Surfnet: wallet signs and submits to its own RPC.
21784
+ const signSendFeat = getSignAndSendTransactionFeature(wallet);
21785
+ const wireBytes = txToWireBytes(transaction);
21786
+ const results = await signSendFeat.signAndSendTransaction({
21787
+ account,
21788
+ transaction: wireBytes,
21789
+ chain,
21790
+ options: { commitment: 'confirmed' },
21791
+ });
21792
+ if (!results || results.length === 0) {
21793
+ throw new Error('MWA returned no signature');
21794
+ }
21795
+ const { signature: sigBytes } = results[0];
21796
+ const signature = base58.encode(sigBytes);
21728
21797
  await confirmAndCheckTransaction(connection, signature);
21729
21798
  return signature;
21730
21799
  }
@@ -21750,16 +21819,14 @@ class SolanaMobileWalletProvider {
21750
21819
  if (!solTransactionData) {
21751
21820
  throw new Error('Solana transaction data is required for mobile wallet');
21752
21821
  }
21753
- if (!this.publicKeyObj || !this.authorizedPublicKey) {
21754
- await this.login();
21755
- }
21756
- await loadMwaProtocol();
21757
- const { transact } = mwaProtocolModule;
21822
+ const account = await this.ensureAuthorized();
21823
+ const connectedPubkey = new PublicKey(account.publicKey);
21824
+ const wallet = await this.ensureWallet();
21825
+ const chain = this.getChain();
21758
21826
  const rpcUrl = this.getRpcUrl(solTransactionData.network);
21759
21827
  const connection = new Connection(rpcUrl, 'confirmed');
21760
21828
  const isSurfnet = rpcUrl === SURFNET_RPC_URL$2;
21761
21829
  try {
21762
- const publicKey = this.publicKeyObj;
21763
21830
  const remainingAccounts = convertRemainingAccounts(solTransactionData.txArgs[0].remainingAccounts);
21764
21831
  let app_id = solTransactionData.appId;
21765
21832
  if (typeof window !== 'undefined' && window.CUSTOM_TAROBASE_APP_ID_HEADER) {
@@ -21768,9 +21835,9 @@ class SolanaMobileWalletProvider {
21768
21835
  if (!app_id) {
21769
21836
  throw new Error('App ID is required');
21770
21837
  }
21771
- // Create a mock wallet adapter for Anchor (only publicKey is needed for building TX)
21838
+ // Mock wallet adapter for Anchor only publicKey is read during build.
21772
21839
  const mockWalletAdapter = {
21773
- publicKey,
21840
+ publicKey: connectedPubkey,
21774
21841
  signTransaction: async (tx) => tx,
21775
21842
  signAllTransactions: async (txs) => txs,
21776
21843
  };
@@ -21788,10 +21855,12 @@ class SolanaMobileWalletProvider {
21788
21855
  }
21789
21856
  let tx;
21790
21857
  if (solTransactionData.signedTransaction) {
21858
+ // Server has co-signed a CPI attestation. Do NOT mutate its
21859
+ // blockhash — that would invalidate the server's signature.
21791
21860
  tx = VersionedTransaction.deserialize(bufferExports.Buffer.from(solTransactionData.signedTransaction, 'base64'));
21792
21861
  }
21793
21862
  else {
21794
- const result = await buildSetDocumentsTransaction(connection, solTransactionData.txArgs[0].idl, anchorProvider, publicKey, {
21863
+ const result = await buildSetDocumentsTransaction(connection, solTransactionData.txArgs[0].idl, anchorProvider, connectedPubkey, {
21795
21864
  app_id,
21796
21865
  documents: solTransactionData.txArgs[0].setDocumentData,
21797
21866
  delete_paths: solTransactionData.txArgs[0].deletePaths,
@@ -21799,11 +21868,16 @@ class SolanaMobileWalletProvider {
21799
21868
  }, finalDeduped, solTransactionData.lutKey, solTransactionData.preInstructions, false, solTransactionData.additionalLutAddresses);
21800
21869
  tx = result.tx;
21801
21870
  }
21871
+ // Sign-only branch — sign the tx but don't submit.
21802
21872
  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());
21873
+ const signTxFeat = getSignTransactionFeature(wallet);
21874
+ const wireBytes = txToWireBytes(tx);
21875
+ const results = await signTxFeat.signTransaction({ account, transaction: wireBytes, chain });
21876
+ if (!results || results.length === 0) {
21877
+ throw new Error('MWA returned no signed transaction');
21878
+ }
21879
+ const { signedTransaction: signedBytes } = results[0];
21880
+ const signedTx = txFromWireBytes(new Uint8Array(signedBytes));
21807
21881
  return {
21808
21882
  signedTransaction: signedTx,
21809
21883
  blockNumber: 0,
@@ -21812,14 +21886,18 @@ class SolanaMobileWalletProvider {
21812
21886
  };
21813
21887
  }
21814
21888
  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());
21889
+ // Surfnet: sign locally via wallet-standard, submit manually.
21890
+ const signTxFeat = getSignTransactionFeature(wallet);
21891
+ const wireBytes = txToWireBytes(tx);
21892
+ const results = await signTxFeat.signTransaction({ account, transaction: wireBytes, chain });
21893
+ if (!results || results.length === 0) {
21894
+ throw new Error('MWA returned no signed transaction');
21895
+ }
21896
+ const { signedTransaction: signedBytes } = results[0];
21897
+ const signedTx = txFromWireBytes(new Uint8Array(signedBytes));
21820
21898
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
21821
21899
  const signature = await connection.sendRawTransaction(signedTx.serialize(), {
21822
- preflightCommitment: 'confirmed'
21900
+ preflightCommitment: 'confirmed',
21823
21901
  });
21824
21902
  const confirmation = await connection.confirmTransaction({
21825
21903
  signature,
@@ -21831,7 +21909,7 @@ class SolanaMobileWalletProvider {
21831
21909
  }
21832
21910
  const txInfo = await connection.getParsedTransaction(signature, {
21833
21911
  maxSupportedTransactionVersion: 0,
21834
- commitment: 'confirmed'
21912
+ commitment: 'confirmed',
21835
21913
  });
21836
21914
  return {
21837
21915
  transactionSignature: signature,
@@ -21840,15 +21918,20 @@ class SolanaMobileWalletProvider {
21840
21918
  data: txInfo === null || txInfo === void 0 ? void 0 : txInfo.meta,
21841
21919
  };
21842
21920
  }
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];
21921
+ // Non-Surfnet: wallet signs and submits to its own RPC.
21922
+ const signSendFeat = getSignAndSendTransactionFeature(wallet);
21923
+ const wireBytes = txToWireBytes(tx);
21924
+ const results = await signSendFeat.signAndSendTransaction({
21925
+ account,
21926
+ transaction: wireBytes,
21927
+ chain,
21928
+ options: { commitment: 'confirmed' },
21929
+ });
21930
+ if (!results || results.length === 0) {
21931
+ throw new Error('MWA returned no signature');
21932
+ }
21933
+ const { signature: sigBytes } = results[0];
21934
+ const signature = base58.encode(sigBytes);
21852
21935
  const txInfo = await confirmAndCheckTransaction(connection, signature);
21853
21936
  return {
21854
21937
  transactionSignature: signature,
@@ -21875,11 +21958,36 @@ class SolanaMobileWalletProvider {
21875
21958
  }
21876
21959
  }
21877
21960
  async getNativeMethods() {
21961
+ var _a, _b, _c;
21962
+ // Synchronous-ish state read; tolerate the wallet being unauthorized
21963
+ // (return nulls). Don't trigger ensureAuthorized() here — callers that
21964
+ // need the wallet active should sign through one of the sign methods.
21965
+ const wallet = this.wallet;
21966
+ if (!wallet) {
21967
+ return {
21968
+ authToken: null,
21969
+ walletUriBase: null,
21970
+ publicKey: null,
21971
+ base64Address: null,
21972
+ wallet: null,
21973
+ currentAuthorization: null,
21974
+ };
21975
+ }
21976
+ const acct = (_a = wallet.accounts) === null || _a === void 0 ? void 0 : _a[0];
21977
+ const auth = wallet.currentAuthorization;
21978
+ let publicKey = null;
21979
+ let base64Address = null;
21980
+ if (acct) {
21981
+ publicKey = new PublicKey(acct.publicKey);
21982
+ base64Address = btoa(String.fromCharCode(...acct.publicKey));
21983
+ }
21878
21984
  return {
21879
- authToken: this.authToken,
21880
- walletUriBase: this.walletUriBase,
21881
- publicKey: this.publicKeyObj,
21882
- base64Address: this.base64Address,
21985
+ authToken: (_b = auth === null || auth === void 0 ? void 0 : auth.auth_token) !== null && _b !== void 0 ? _b : null,
21986
+ walletUriBase: (_c = auth === null || auth === void 0 ? void 0 : auth.wallet_uri_base) !== null && _c !== void 0 ? _c : null,
21987
+ publicKey,
21988
+ base64Address,
21989
+ wallet,
21990
+ currentAuthorization: auth !== null && auth !== void 0 ? auth : null,
21883
21991
  };
21884
21992
  }
21885
21993
  /* ----------------------------------------------------------- *
@@ -22250,4 +22358,4 @@ class PrivyExpoProvider {
22250
22358
  }
22251
22359
 
22252
22360
  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
22361
+ //# sourceMappingURL=index-ZKzq5QT_.esm.js.map