@pooflabs/web 0.0.85-rc3 → 0.0.87

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 (65) hide show
  1. package/dist/auth/providers/solana-mobile-wallet-provider.d.ts +43 -0
  2. package/dist/{index-B5qYY4YM.js → index-B-x9RTF7.js} +2 -2
  3. package/dist/index-B-x9RTF7.js.map +1 -0
  4. package/dist/{index-BaKs3A8s.js → index-BKN0IwAx.js} +3054 -300
  5. package/dist/index-BKN0IwAx.js.map +1 -0
  6. package/dist/{index-C4AnWFs_.esm.js → index-BTwX7FYW.esm.js} +425 -119
  7. package/dist/index-BTwX7FYW.esm.js.map +1 -0
  8. package/dist/{index-BzeiIIwF.js → index-DYBdUxnT.js} +3055 -301
  9. package/dist/index-DYBdUxnT.js.map +1 -0
  10. package/dist/{index-bEXLwE7_.js → index-Dj1tZr6X.js} +426 -118
  11. package/dist/index-Dj1tZr6X.js.map +1 -0
  12. package/dist/{index-dqqR5q7b.esm.js → index-DofM-ue2.esm.js} +3054 -301
  13. package/dist/index-DofM-ue2.esm.js.map +1 -0
  14. package/dist/index-_k6pjuwx.esm.js +6 -0
  15. package/dist/index-_k6pjuwx.esm.js.map +1 -0
  16. package/dist/{index-BE-VWSJT.esm.js → index-x7a-wH2l.esm.js} +3055 -300
  17. package/dist/index-x7a-wH2l.esm.js.map +1 -0
  18. package/dist/{index.browser-D8ttddP4.esm.js → index.browser-Cndx2raY.esm.js} +506 -1876
  19. package/dist/index.browser-Cndx2raY.esm.js.map +1 -0
  20. package/dist/{index.browser-CN6obNQM.js → index.browser-D7-FFk3q.js} +506 -1876
  21. package/dist/index.browser-D7-FFk3q.js.map +1 -0
  22. package/dist/{index.browser-CZIJCtms.js → index.browser-DlA-NKvf.js} +1223 -2565
  23. package/dist/index.browser-DlA-NKvf.js.map +1 -0
  24. package/dist/{index.browser-DQIwLToJ.esm.js → index.browser-nVGFrIHK.esm.js} +1223 -2565
  25. package/dist/index.browser-nVGFrIHK.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-DLziTime.esm.js → index.native-19VsREMJ.esm.js} +43 -62
  29. package/dist/index.native-19VsREMJ.esm.js.map +1 -0
  30. package/dist/{index.native-pG1NTZ0f.js → index.native-D8vj3Lbr.js} +44 -61
  31. package/dist/index.native-D8vj3Lbr.js.map +1 -0
  32. package/dist/index.native.esm.js +1 -1
  33. package/dist/index.native.js +1 -1
  34. package/dist/{phantom-wallet-provider-zBp7-uEw.js → phantom-wallet-provider-BlZZa_3s.js} +4 -4
  35. package/dist/{phantom-wallet-provider-zBp7-uEw.js.map → phantom-wallet-provider-BlZZa_3s.js.map} +1 -1
  36. package/dist/{phantom-wallet-provider-CP6NXRwG.esm.js → phantom-wallet-provider-Bz3qEFzX.esm.js} +4 -4
  37. package/dist/{phantom-wallet-provider-CP6NXRwG.esm.js.map → phantom-wallet-provider-Bz3qEFzX.esm.js.map} +1 -1
  38. package/dist/{privy-wallet-provider-CoyW5Gdg.js → privy-wallet-provider-CqCgq7uT.js} +3 -3
  39. package/dist/privy-wallet-provider-CqCgq7uT.js.map +1 -0
  40. package/dist/{privy-wallet-provider-CGYvf3-r.esm.js → privy-wallet-provider-DgNFzioA.esm.js} +3 -3
  41. package/dist/privy-wallet-provider-DgNFzioA.esm.js.map +1 -0
  42. package/dist/{solana-mobile-wallet-provider-B8rHfsPN.esm.js → solana-mobile-wallet-provider-EeQsBTdr.esm.js} +385 -60
  43. package/dist/solana-mobile-wallet-provider-EeQsBTdr.esm.js.map +1 -0
  44. package/dist/{solana-mobile-wallet-provider-CN-D_H4l.js → solana-mobile-wallet-provider-VqIGfdMV.js} +385 -60
  45. package/dist/solana-mobile-wallet-provider-VqIGfdMV.js.map +1 -0
  46. package/package.json +1 -1
  47. package/dist/index-B5qYY4YM.js.map +0 -1
  48. package/dist/index-BE-VWSJT.esm.js.map +0 -1
  49. package/dist/index-BaKs3A8s.js.map +0 -1
  50. package/dist/index-BzeiIIwF.js.map +0 -1
  51. package/dist/index-C4AnWFs_.esm.js.map +0 -1
  52. package/dist/index-TzHXEf3-.esm.js +0 -6
  53. package/dist/index-TzHXEf3-.esm.js.map +0 -1
  54. package/dist/index-bEXLwE7_.js.map +0 -1
  55. package/dist/index-dqqR5q7b.esm.js.map +0 -1
  56. package/dist/index.browser-CN6obNQM.js.map +0 -1
  57. package/dist/index.browser-CZIJCtms.js.map +0 -1
  58. package/dist/index.browser-D8ttddP4.esm.js.map +0 -1
  59. package/dist/index.browser-DQIwLToJ.esm.js.map +0 -1
  60. package/dist/index.native-DLziTime.esm.js.map +0 -1
  61. package/dist/index.native-pG1NTZ0f.js.map +0 -1
  62. package/dist/privy-wallet-provider-CGYvf3-r.esm.js.map +0 -1
  63. package/dist/privy-wallet-provider-CoyW5Gdg.js.map +0 -1
  64. package/dist/solana-mobile-wallet-provider-B8rHfsPN.esm.js.map +0 -1
  65. package/dist/solana-mobile-wallet-provider-CN-D_H4l.js.map +0 -1
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-B5qYY4YM.js');
4
- var index_native = require('./index.native-pG1NTZ0f.js');
3
+ var index = require('./index-B-x9RTF7.js');
4
+ var index_native = require('./index.native-D8vj3Lbr.js');
5
5
  var web3_js = require('@solana/web3.js');
6
6
  var anchor = require('@coral-xyz/anchor');
7
7
  require('axios');
@@ -26,6 +26,14 @@ function _interopNamespaceDefault(e) {
26
26
 
27
27
  var anchor__namespace = /*#__PURE__*/_interopNamespaceDefault(anchor);
28
28
 
29
+ /**
30
+ * Storage key for persisting the MWA auth_token across cold starts.
31
+ * Holds JSON `{ token: string, address: string }`. Cleared by
32
+ * `logout()`. Hydrated by the constructor on native so cold-start
33
+ * doesn't force the user back into Phantom's approval flow when the
34
+ * underlying wallet authorization is still valid.
35
+ */
36
+ const MWA_AUTH_TOKEN_STORAGE_KEY = 'tarobase_mwa_auth_token';
29
37
  const ED25519_SIGNATURE_LENGTH = 64;
30
38
  const STORED_AUTH_METHOD_KEY = 'tarobase_last_auth_method';
31
39
  const MWA_AUTH_METHOD = 'mobile-wallet-adapter';
@@ -85,20 +93,11 @@ function isMwaAssociationRetryable(e) {
85
93
  * so a second attempt skips the consent sheet, jumps straight to
86
94
  * Verify/Approve, and completes inside the timeout.
87
95
  */
88
- async function withMwaAssociationRetry(label, fn) {
89
- const t0 = Date.now();
90
- console.log(`[MWA-DEBUG] ${label} attempt=1 start`);
96
+ async function withMwaAssociationRetry(fn) {
91
97
  try {
92
- const result = await fn();
93
- console.log(`[MWA-DEBUG] ${label} attempt=1 ok (${Date.now() - t0}ms)`);
94
- return result;
98
+ return await fn();
95
99
  }
96
100
  catch (e) {
97
- const info = findMwaError(e);
98
- console.log(`[MWA-DEBUG] ${label} attempt=1 err (${Date.now() - t0}ms)`, {
99
- outer: { name: e === null || e === void 0 ? void 0 : e.name, message: e === null || e === void 0 ? void 0 : e.message },
100
- mwa: info,
101
- });
102
101
  const retryable = isMwaAssociationRetryable(e);
103
102
  if (!retryable)
104
103
  throw e;
@@ -107,21 +106,11 @@ async function withMwaAssociationRetry(label, fn) {
107
106
  // so visibility-based waits fire too early. Use a fixed delay long
108
107
  // enough for Seeker to dismiss its sheet and the OS to release intent
109
108
  // state. 2.5s is empirically safe; tune from device traces if needed.
110
- console.log(`[MWA-DEBUG] ${label} retryable (${retryable.code}); waiting 2500ms before retry`);
111
109
  await new Promise(r => setTimeout(r, 2500));
112
- const t1 = Date.now();
113
- console.log(`[MWA-DEBUG] ${label} attempt=2 start`);
114
110
  try {
115
- const result = await fn();
116
- console.log(`[MWA-DEBUG] ${label} attempt=2 ok (${Date.now() - t1}ms)`);
117
- return result;
111
+ return await fn();
118
112
  }
119
113
  catch (e2) {
120
- const info2 = findMwaError(e2);
121
- console.log(`[MWA-DEBUG] ${label} attempt=2 err (${Date.now() - t1}ms)`, {
122
- outer: { name: e2 === null || e2 === void 0 ? void 0 : e2.name, message: e2 === null || e2 === void 0 ? void 0 : e2.message },
123
- mwa: info2,
124
- });
125
114
  // Only mask the error with the clean Seeker message when the
126
115
  // second failure is also an association-flavored error. If it's
127
116
  // a user cancel, wallet rejection, or unknown error, rethrow
@@ -160,7 +149,7 @@ async function withMwaAssociationRetry(label, fn) {
160
149
  * next tap is a new activation (a real retry). A timer-based retry would
161
150
  * just hit the same Chrome block. Cap at 3 attempts before giving up.
162
151
  */
163
- async function awaitSignInGestureAndSign(label, theme, signFn) {
152
+ async function awaitSignInGestureAndSign(theme, signFn) {
164
153
  if (typeof document === 'undefined' || typeof window === 'undefined') {
165
154
  // SSR / non-browser: skip the gesture, just call (the activation
166
155
  // model doesn't apply outside the browser).
@@ -327,18 +316,15 @@ async function awaitSignInGestureAndSign(label, theme, signFn) {
327
316
  finishReject(new Error('User cancelled wallet sign in'));
328
317
  };
329
318
  closeBtn.addEventListener('click', () => {
330
- console.log(`[MWA-DEBUG] ${label} gesture: close clicked`);
331
319
  handleCancel();
332
320
  });
333
321
  overlay.addEventListener('click', (e) => {
334
322
  if (e.target === overlay) {
335
- console.log(`[MWA-DEBUG] ${label} gesture: overlay clicked (cancel)`);
336
323
  handleCancel();
337
324
  }
338
325
  });
339
326
  const onKeydown = (e) => {
340
327
  if (e.key === 'Escape') {
341
- console.log(`[MWA-DEBUG] ${label} gesture: Escape pressed (cancel)`);
342
328
  handleCancel();
343
329
  }
344
330
  };
@@ -348,7 +334,6 @@ async function awaitSignInGestureAndSign(label, theme, signFn) {
348
334
  return;
349
335
  attemptCount++;
350
336
  const attempt = attemptCount;
351
- console.log(`[MWA-DEBUG] ${label} gesture: button click attempt=${attempt}`);
352
337
  // Disable to prevent double-clicks while the wallet popup is up.
353
338
  button.disabled = true;
354
339
  setButtonDisabledStyle();
@@ -360,29 +345,17 @@ async function awaitSignInGestureAndSign(label, theme, signFn) {
360
345
  // so Chrome's transient user activation propagates to the
361
346
  // protocol's window.location.assign(associationUrl) inside
362
347
  // launchAssociation(). Do not `await` before calling.
363
- const t0 = Date.now();
364
- console.log(`[MWA-DEBUG] ${label} gesture: signMessage start (attempt=${attempt})`);
365
348
  signFn().then((results) => {
366
- const elapsed = Date.now() - t0;
367
349
  if (!results || results.length === 0) {
368
- console.log(`[MWA-DEBUG] ${label} gesture: signMessage returned empty (attempt=${attempt}, ${elapsed}ms)`);
369
350
  finishReject(new Error('MWA returned no signature'));
370
351
  return;
371
352
  }
372
- console.log(`[MWA-DEBUG] ${label} gesture: signMessage ok (attempt=${attempt}, ${elapsed}ms)`);
373
353
  finishResolve(results[0]);
374
354
  }).catch((err) => {
375
- const elapsed = Date.now() - t0;
376
- const info = findMwaError(err);
377
- console.log(`[MWA-DEBUG] ${label} gesture: signMessage err (attempt=${attempt}, ${elapsed}ms)`, {
378
- outer: { name: err === null || err === void 0 ? void 0 : err.name, message: err === null || err === void 0 ? void 0 : err.message },
379
- mwa: info,
380
- });
381
355
  const retryable = isMwaAssociationRetryable(err);
382
356
  if (retryable && attempt < MAX_ATTEMPTS) {
383
357
  // Re-enable the button so the user's next tap provides a
384
358
  // fresh user activation. Show inline error text.
385
- console.log(`[MWA-DEBUG] ${label} gesture: retryable (${retryable.code}); awaiting user tap to retry (attempt ${attempt}/${MAX_ATTEMPTS})`);
386
359
  button.disabled = false;
387
360
  setButtonEnabledStyle();
388
361
  button.textContent = originalText;
@@ -392,7 +365,6 @@ async function awaitSignInGestureAndSign(label, theme, signFn) {
392
365
  }
393
366
  if (retryable) {
394
367
  // Hit the attempt cap with a still-retryable failure.
395
- console.log(`[MWA-DEBUG] ${label} gesture: retryable but attempt cap reached (${attempt})`);
396
368
  finishReject(new Error("Couldn't connect to your Seeker wallet. Please try again."));
397
369
  return;
398
370
  }
@@ -401,7 +373,6 @@ async function awaitSignInGestureAndSign(label, theme, signFn) {
401
373
  finishReject(err);
402
374
  });
403
375
  });
404
- console.log(`[MWA-DEBUG] ${label} gesture: modal shown`);
405
376
  });
406
377
  }
407
378
  /**
@@ -564,19 +535,66 @@ class SolanaMobileWalletProvider {
564
535
  constructor(networkUrl = null, config = {}) {
565
536
  /** LocalSolanaMobileWalletAdapterWallet, lazy-constructed in ensureWallet(). */
566
537
  this.wallet = null;
538
+ /**
539
+ * Cached MWA auth_token returned by `wallet.authorize()`. Reused by
540
+ * subsequent native transact() calls (signMessage / signTransaction)
541
+ * so the user doesn't get the wallet-pick popup on every operation.
542
+ * Persisted to platform storage and hydrated by the constructor on
543
+ * native; cleared by logout() and on `ERROR_REAUTHORIZE`.
544
+ */
545
+ this.nativeAuthToken = null;
546
+ /** Cached public key string for the connected MWA wallet (native). */
547
+ this.nativeAddress = null;
567
548
  this.networkUrl = networkUrl;
568
549
  this.config = config;
569
- if (typeof window === 'undefined') {
550
+ // Allow construction in true React Native environments: getPlatform().hasDOM
551
+ // is false there even though `typeof window === 'object'` (RN exposes a
552
+ // partial window global). Web/PWA paths still keep their original guard:
553
+ // they need real window+document for wallet-standard-mobile's deep-link
554
+ // mechanism, so missing-window in those builds remains a fail-fast.
555
+ const hasDOM = index_native.getPlatform().hasDOM;
556
+ if (!hasDOM && typeof window === 'undefined') {
557
+ throw new Error('SolanaMobileWalletProvider can only be instantiated in a browser or React Native environment');
558
+ }
559
+ if (hasDOM && typeof window === 'undefined') {
570
560
  throw new Error('SolanaMobileWalletProvider can only be instantiated in a browser environment');
571
561
  }
572
562
  if (SolanaMobileWalletProvider.instance) {
573
563
  return SolanaMobileWalletProvider.instance;
574
564
  }
565
+ // `appIdentity.uri` is what Phantom Android (and other MWA wallets)
566
+ // display in their approval modal. On web/PWA this is the page
567
+ // origin; on native there's no `window.location`, so fall back to
568
+ // a stable identifier the user can recognize. Apps can override
569
+ // entirely via `config.appIdentity.uri`.
570
+ const fallbackUri = hasDOM
571
+ ? index_native.getPlatform().getLocationOrigin()
572
+ : 'tarobase://app';
575
573
  this.appIdentity = config.appIdentity || {
576
574
  name: 'TaroBase App',
577
- uri: index_native.getPlatform().getLocationOrigin(),
575
+ uri: fallbackUri,
578
576
  };
579
577
  this.cluster = config.cluster || 'mainnet-beta';
578
+ // Hydrate cached MWA auth_token from storage on native so we can
579
+ // skip the wallet-pick popup after a cold-start when the underlying
580
+ // wallet authorization is still valid. Sync storage call per the
581
+ // PlatformAdapter contract; safe to swallow read errors (a fresh
582
+ // login() just re-authorizes).
583
+ if (!hasDOM) {
584
+ try {
585
+ const raw = index_native.getPlatform().storage.getItem(MWA_AUTH_TOKEN_STORAGE_KEY);
586
+ if (raw) {
587
+ const parsed = JSON.parse(raw);
588
+ if (typeof parsed.token === 'string' && typeof parsed.address === 'string') {
589
+ this.nativeAuthToken = parsed.token;
590
+ this.nativeAddress = parsed.address;
591
+ }
592
+ }
593
+ }
594
+ catch (_a) {
595
+ // Corrupt or unreadable cache — ignore. login() will re-auth.
596
+ }
597
+ }
580
598
  SolanaMobileWalletProvider.instance = this;
581
599
  }
582
600
  static getInstance(networkUrl, config) {
@@ -589,7 +607,7 @@ class SolanaMobileWalletProvider {
589
607
  async ensureWallet() {
590
608
  if (this.wallet)
591
609
  return this.wallet;
592
- const mod = await Promise.resolve().then(function () { return require('./index.browser-CN6obNQM.js'); });
610
+ const mod = await Promise.resolve().then(function () { return require('./index.browser-D7-FFk3q.js'); });
593
611
  const chain = mapChainToWalletStandard(this.cluster);
594
612
  this.wallet = new mod.LocalSolanaMobileWalletAdapterWallet({
595
613
  appIdentity: this.appIdentity,
@@ -603,7 +621,7 @@ class SolanaMobileWalletProvider {
603
621
  // login()'s withMwaAssociationRetry handles this case; on second
604
622
  // failure it surfaces a clean error message to the host app.
605
623
  onWalletNotFound: async () => {
606
- console.warn('[MWA-DEBUG] ensureWallet onWalletNotFound (suppressed)');
624
+ // intentional no-op
607
625
  },
608
626
  });
609
627
  return this.wallet;
@@ -639,6 +657,134 @@ class SolanaMobileWalletProvider {
639
657
  getChain() {
640
658
  return mapChainToWalletStandard(this.cluster);
641
659
  }
660
+ /**
661
+ * Dynamically import and unwrap `transact` from the MWA web3js
662
+ * package. The package is externalized in rollup.config.js so this
663
+ * resolves to `lib/cjs/index.native.js` (TurboModule-backed) on
664
+ * Metro and `lib/esm/index.browser.js` (WebSocket) on webpack/vite
665
+ * per their respective platform conditions. Handles Metro's CJS-to-
666
+ * ESM interop variance (`mod.transact` vs `mod.default?.transact`).
667
+ */
668
+ async loadTransact() {
669
+ var _a;
670
+ const mod = await import('@solana-mobile/mobile-wallet-adapter-protocol-web3js');
671
+ const t = mod.transact || ((_a = mod.default) === null || _a === void 0 ? void 0 : _a.transact);
672
+ if (typeof t !== 'function') {
673
+ throw new Error('MWA transact API not available on this platform');
674
+ }
675
+ return t;
676
+ }
677
+ /**
678
+ * Cache and persist a fresh MWA auth_token + address. Called from
679
+ * `_loginNative` after a successful authorize. Storage failures are
680
+ * non-fatal (next cold-start re-auths).
681
+ */
682
+ persistNativeAuth(token, address) {
683
+ this.nativeAuthToken = token;
684
+ this.nativeAddress = address;
685
+ try {
686
+ index_native.getPlatform().storage.setItem(MWA_AUTH_TOKEN_STORAGE_KEY, JSON.stringify({ token, address }));
687
+ }
688
+ catch (_a) {
689
+ // non-fatal — token still in-memory for this process
690
+ }
691
+ }
692
+ /** Clear cached + persisted native auth state. */
693
+ clearNativeAuth() {
694
+ this.nativeAuthToken = null;
695
+ this.nativeAddress = null;
696
+ try {
697
+ index_native.getPlatform().storage.removeItem(MWA_AUTH_TOKEN_STORAGE_KEY);
698
+ }
699
+ catch (_a) {
700
+ // ignore
701
+ }
702
+ }
703
+ /**
704
+ * Classify an MWA-native error as a user cancellation. User-cancel
705
+ * shouldn't surface as a red console.error; callers can swallow or
706
+ * show a softer message. MWA spec codes plus the same substring
707
+ * checks the web path uses to catch wallet-specific phrasing.
708
+ */
709
+ isNativeUserCancel(err) {
710
+ var _a;
711
+ if (!err)
712
+ return false;
713
+ const code = err.code;
714
+ if (code === 'ERROR_NOT_SIGNED')
715
+ return true;
716
+ const msg = String((_a = err.message) !== null && _a !== void 0 ? _a : '').toLowerCase();
717
+ return /user (rejected|denied|cancelled|canceled|declined)/.test(msg);
718
+ }
719
+ /**
720
+ * Native MWA login via @solana-mobile/mobile-wallet-adapter-protocol-web3js.
721
+ * Used in true React Native (Expo) environments where wallet-standard-mobile's
722
+ * web universal-link path doesn't apply. Does authorize + signMessage in a
723
+ * single transact() roundtrip — intent-based MWA doesn't need the two-popup
724
+ * dance the web path uses (no Chrome activation-loss concern). Persists the
725
+ * resulting auth_token so cold-start can reauthorize without a fresh popup.
726
+ */
727
+ async _loginNative() {
728
+ const transact = await this.loadTransact();
729
+ const existingSession = await index_native.WebSessionManager.getSession();
730
+ const nonce = await index_native.genAuthNonce();
731
+ const result = await transact(async (wallet) => {
732
+ const auth = await wallet.authorize({
733
+ chain: this.getChain(),
734
+ identity: this.appIdentity,
735
+ });
736
+ if (!auth.accounts || auth.accounts.length === 0) {
737
+ throw new Error('MWA returned no accounts');
738
+ }
739
+ const account = auth.accounts[0];
740
+ // account.address is base64-encoded per MWA spec; convert to
741
+ // the base58 form Tarobase + the rest of the SDK use.
742
+ const base58Addr = new web3_js.PublicKey(index.bufferExports.Buffer.from(account.address, 'base64')).toBase58();
743
+ // Reuse session if already valid for this address — skip the
744
+ // signMessages roundtrip entirely.
745
+ if (existingSession && existingSession.address === base58Addr) {
746
+ return {
747
+ base58Addr,
748
+ authToken: auth.auth_token,
749
+ signatureBase64: null,
750
+ };
751
+ }
752
+ const messageText = await index_native.genSolanaMessage(base58Addr, nonce);
753
+ const messageBytes = index_native.getPlatform().textEncode(messageText);
754
+ const signatures = await wallet.signMessages({
755
+ addresses: [account.address],
756
+ payloads: [messageBytes],
757
+ });
758
+ if (!signatures || signatures.length === 0) {
759
+ throw new Error('MWA returned no signature');
760
+ }
761
+ // Per spec, signMessages returns Uint8Array[] of signatures
762
+ // (one per payload), not message+signature concatenations.
763
+ const signatureBase64 = index.bufferExports.Buffer.from(signatures[0]).toString('base64');
764
+ return {
765
+ base58Addr,
766
+ authToken: auth.auth_token,
767
+ signatureBase64,
768
+ messageText,
769
+ };
770
+ });
771
+ this.persistNativeAuth(result.authToken, result.base58Addr);
772
+ // Existing valid session — short-circuit before re-creating server-side.
773
+ if (existingSession && existingSession.address === result.base58Addr) {
774
+ const user = { provider: this, address: result.base58Addr };
775
+ index_native.setCurrentUser(user);
776
+ return user;
777
+ }
778
+ // Create Tarobase session on the server.
779
+ if (!result.signatureBase64 || !result.messageText) {
780
+ throw new Error('MWA login completed without signature');
781
+ }
782
+ const createSessionResult = await index_native.createSessionWithSignature(result.base58Addr, result.messageText, result.signatureBase64);
783
+ await index_native.WebSessionManager.storeSession(result.base58Addr, createSessionResult.accessToken, createSessionResult.idToken, createSessionResult.refreshToken);
784
+ const user = { provider: this, address: result.base58Addr };
785
+ index_native.setCurrentUser(user);
786
+ return user;
787
+ }
642
788
  async login() {
643
789
  var _a, _b, _c, _d, _e;
644
790
  index_native.setAuthLoading(true);
@@ -649,6 +795,13 @@ class SolanaMobileWalletProvider {
649
795
  const prevAuthMethod = readAuthMethod();
650
796
  writeAuthMethod(MWA_AUTH_METHOD);
651
797
  try {
798
+ // True React Native: skip the wallet-standard-mobile path (which
799
+ // requires window.isSecureContext and a real DOM) and use the raw
800
+ // MWA protocol via Android intents.
801
+ if (!index_native.getPlatform().hasDOM) {
802
+ const user = await this._loginNative();
803
+ return user;
804
+ }
652
805
  const wallet = await this.ensureWallet();
653
806
  // Quick-check: wallet may already have authorization (e.g. from a
654
807
  // previous in-page login) and a matching Tarobase session — skip
@@ -677,7 +830,7 @@ class SolanaMobileWalletProvider {
677
830
  // consent on the second pass and completes quickly. See
678
831
  // withMwaAssociationRetry for details.
679
832
  const connectFeat = getConnectFeature(wallet);
680
- const { accounts } = await withMwaAssociationRetry('login:connect', () => connectFeat.connect());
833
+ const { accounts } = await withMwaAssociationRetry(() => connectFeat.connect());
681
834
  if (!accounts || accounts.length === 0) {
682
835
  throw new Error('MWA returned no accounts');
683
836
  }
@@ -710,7 +863,7 @@ class SolanaMobileWalletProvider {
710
863
  const messageText = await index_native.genSolanaMessage(base58Addr, nonce);
711
864
  const messageBytes = index_native.getPlatform().textEncode(messageText);
712
865
  const signMessageFeat = getSignMessageFeature(wallet);
713
- const signResult = await awaitSignInGestureAndSign('login:signMessage', this.config.theme, () => signMessageFeat.signMessage({ account, message: messageBytes }));
866
+ const signResult = await awaitSignInGestureAndSign(this.config.theme, () => signMessageFeat.signMessage({ account, message: messageBytes }));
714
867
  if (!signResult) {
715
868
  throw new Error('MWA returned no signature');
716
869
  }
@@ -750,6 +903,29 @@ class SolanaMobileWalletProvider {
750
903
  return null;
751
904
  }
752
905
  async logout() {
906
+ if (!index_native.getPlatform().hasDOM) {
907
+ // Native path: deauthorize the cached MWA auth_token if we have
908
+ // one (failures non-fatal — the wallet app may have been
909
+ // uninstalled or the token already revoked), then clear local
910
+ // and persisted state.
911
+ const token = this.nativeAuthToken;
912
+ if (token) {
913
+ try {
914
+ const transact = await this.loadTransact();
915
+ await transact(async (wallet) => {
916
+ await wallet.deauthorize({ auth_token: token });
917
+ });
918
+ }
919
+ catch (error) {
920
+ console.warn('[SolanaMobileWallet] Native deauthorize error:', error);
921
+ }
922
+ }
923
+ this.clearNativeAuth();
924
+ index_native.WebSessionManager.clearSession();
925
+ writeAuthMethod(null);
926
+ index_native.setCurrentUser(null);
927
+ return;
928
+ }
753
929
  try {
754
930
  const wallet = await this.ensureWallet();
755
931
  const disconnectFeat = getDisconnectFeature(wallet);
@@ -769,7 +945,42 @@ class SolanaMobileWalletProvider {
769
945
  index_native.setCurrentUser(null);
770
946
  }
771
947
  async signMessage(message) {
772
- var _a, _b;
948
+ var _a, _b, _c;
949
+ // Native: reauthorize with cached auth_token, then signMessages inside
950
+ // the same transact() session. No wallet-pick popup if the auth_token
951
+ // is still valid for the user's wallet.
952
+ if (!index_native.getPlatform().hasDOM) {
953
+ if (!this.nativeAuthToken || !this.nativeAddress) {
954
+ throw new Error('Wallet not connected. Call login() first.');
955
+ }
956
+ const transact = await this.loadTransact();
957
+ const messageBytes = index_native.getPlatform().textEncode(message);
958
+ const addressBase64 = new web3_js.PublicKey(this.nativeAddress).toBuffer().toString('base64');
959
+ const authToken = this.nativeAuthToken;
960
+ try {
961
+ const signature = await transact(async (wallet) => {
962
+ await wallet.reauthorize({ auth_token: authToken, identity: this.appIdentity });
963
+ const sigs = await wallet.signMessages({
964
+ addresses: [addressBase64],
965
+ payloads: [messageBytes],
966
+ });
967
+ if (!sigs || sigs.length === 0)
968
+ throw new Error('MWA returned no signature');
969
+ return sigs[0];
970
+ });
971
+ return index.bufferExports.Buffer.from(signature).toString('base64');
972
+ }
973
+ catch (error) {
974
+ if (this.isNativeUserCancel(error)) {
975
+ throw new Error('User declined to sign');
976
+ }
977
+ if ((error === null || error === void 0 ? void 0 : error.code) === 'ERROR_AUTHORIZATION_FAILED' || (error === null || error === void 0 ? void 0 : error.code) === 'ERROR_REAUTHORIZE') {
978
+ await this.logout();
979
+ throw new Error('Wallet connection lost. Please reconnect.');
980
+ }
981
+ throw new Error(`Failed to sign message: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
982
+ }
983
+ }
773
984
  const account = await this.ensureAuthorized();
774
985
  const wallet = await this.ensureWallet();
775
986
  try {
@@ -783,7 +994,7 @@ class SolanaMobileWalletProvider {
783
994
  return index.bufferExports.Buffer.from(sigBytes).toString('base64');
784
995
  }
785
996
  catch (error) {
786
- 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')) ||
997
+ if (((_b = error === null || error === void 0 ? void 0 : error.message) === null || _b === void 0 ? void 0 : _b.includes('not connected')) || ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('not authorized')) ||
787
998
  (error === null || error === void 0 ? void 0 : error.code) === 'ERROR_AUTHORIZATION_FAILED') {
788
999
  await this.logout();
789
1000
  throw new Error('Wallet connection lost. Please reconnect.');
@@ -792,7 +1003,58 @@ class SolanaMobileWalletProvider {
792
1003
  }
793
1004
  }
794
1005
  async signTransaction(transaction) {
795
- var _a, _b;
1006
+ var _a, _b, _c;
1007
+ // Native: fill blockhash/feePayer if missing, then signTransactions
1008
+ // inside a transact() session keyed by the cached auth_token.
1009
+ if (!index_native.getPlatform().hasDOM) {
1010
+ if (!this.nativeAuthToken || !this.nativeAddress) {
1011
+ throw new Error('Wallet not connected. Call login() first.');
1012
+ }
1013
+ const connectedPubkey = new web3_js.PublicKey(this.nativeAddress);
1014
+ const isLegacyTransaction = 'recentBlockhash' in transaction && !('message' in transaction && 'staticAccountKeys' in transaction.message);
1015
+ if (isLegacyTransaction) {
1016
+ const legacyTx = transaction;
1017
+ if (!legacyTx.recentBlockhash) {
1018
+ const conn = new web3_js.Connection(this.getRpcUrl(), 'confirmed');
1019
+ const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash('confirmed');
1020
+ legacyTx.recentBlockhash = blockhash;
1021
+ legacyTx.lastValidBlockHeight = lastValidBlockHeight;
1022
+ }
1023
+ if (!legacyTx.feePayer) {
1024
+ legacyTx.feePayer = connectedPubkey;
1025
+ }
1026
+ }
1027
+ else {
1028
+ const versionedTx = transaction;
1029
+ if (!versionedTx.message.recentBlockhash) {
1030
+ const conn = new web3_js.Connection(this.getRpcUrl(), 'confirmed');
1031
+ const { blockhash } = await conn.getLatestBlockhash('confirmed');
1032
+ versionedTx.message.recentBlockhash = blockhash;
1033
+ }
1034
+ }
1035
+ const transact = await this.loadTransact();
1036
+ const authToken = this.nativeAuthToken;
1037
+ try {
1038
+ const signed = await transact(async (wallet) => {
1039
+ await wallet.reauthorize({ auth_token: authToken, identity: this.appIdentity });
1040
+ const results = await wallet.signTransactions({ transactions: [transaction] });
1041
+ if (!results || results.length === 0)
1042
+ throw new Error('MWA returned no signed transaction');
1043
+ return results[0];
1044
+ });
1045
+ return signed;
1046
+ }
1047
+ catch (error) {
1048
+ if (this.isNativeUserCancel(error)) {
1049
+ throw new Error('User declined to sign');
1050
+ }
1051
+ if ((error === null || error === void 0 ? void 0 : error.code) === 'ERROR_AUTHORIZATION_FAILED' || (error === null || error === void 0 ? void 0 : error.code) === 'ERROR_REAUTHORIZE') {
1052
+ await this.logout();
1053
+ throw new Error('Wallet connection lost. Please reconnect.');
1054
+ }
1055
+ throw new Error(`Failed to sign transaction: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
1056
+ }
1057
+ }
796
1058
  const account = await this.ensureAuthorized();
797
1059
  const connectedPubkey = new web3_js.PublicKey(account.publicKey);
798
1060
  const wallet = await this.ensureWallet();
@@ -831,7 +1093,7 @@ class SolanaMobileWalletProvider {
831
1093
  return txFromWireBytes(new Uint8Array(signedBytes));
832
1094
  }
833
1095
  catch (error) {
834
- 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')) ||
1096
+ if (((_b = error === null || error === void 0 ? void 0 : error.message) === null || _b === void 0 ? void 0 : _b.includes('not connected')) || ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('not authorized')) ||
835
1097
  (error === null || error === void 0 ? void 0 : error.code) === 'ERROR_AUTHORIZATION_FAILED') {
836
1098
  await this.logout();
837
1099
  throw new Error('Wallet connection lost. Please reconnect.');
@@ -840,7 +1102,70 @@ class SolanaMobileWalletProvider {
840
1102
  }
841
1103
  }
842
1104
  async signAndSubmitTransaction(transaction, feePayer) {
843
- var _a, _b, _c, _d, _e, _f;
1105
+ var _a, _b, _c, _d, _e, _f, _g;
1106
+ // Native: signAndSendTransactions inside a transact() session.
1107
+ // The wallet submits to its own RPC; we then await confirmation on
1108
+ // ours. Surfnet (custom RPC) needs manual submission because the
1109
+ // wallet won't route there — we fall back to sign-only + manual send.
1110
+ if (!index_native.getPlatform().hasDOM) {
1111
+ if (!this.nativeAuthToken || !this.nativeAddress) {
1112
+ throw new Error('Wallet not connected. Call login() first.');
1113
+ }
1114
+ const connectedPubkey = new web3_js.PublicKey(this.nativeAddress);
1115
+ const rpcUrl = this.getRpcUrl();
1116
+ const connection = new web3_js.Connection(rpcUrl, 'confirmed');
1117
+ const isSurfnet = rpcUrl === index_native.SURFNET_RPC_URL;
1118
+ const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
1119
+ const isLegacyTransaction = 'recentBlockhash' in transaction && !('message' in transaction && 'staticAccountKeys' in transaction.message);
1120
+ if (isLegacyTransaction) {
1121
+ const legacyTx = transaction;
1122
+ legacyTx.recentBlockhash = blockhash;
1123
+ legacyTx.lastValidBlockHeight = lastValidBlockHeight;
1124
+ if (!legacyTx.feePayer)
1125
+ legacyTx.feePayer = feePayer !== null && feePayer !== void 0 ? feePayer : connectedPubkey;
1126
+ }
1127
+ else {
1128
+ const versionedTx = transaction;
1129
+ versionedTx.message.recentBlockhash = blockhash;
1130
+ }
1131
+ const transact = await this.loadTransact();
1132
+ const authToken = this.nativeAuthToken;
1133
+ try {
1134
+ if (isSurfnet) {
1135
+ // Surfnet: sign only, submit manually to Surfnet RPC
1136
+ // (the wallet would route signAndSend to its own RPC).
1137
+ const signed = await transact(async (wallet) => {
1138
+ await wallet.reauthorize({ auth_token: authToken, identity: this.appIdentity });
1139
+ const results = await wallet.signTransactions({ transactions: [transaction] });
1140
+ if (!results || results.length === 0)
1141
+ throw new Error('MWA returned no signed transaction');
1142
+ return results[0];
1143
+ });
1144
+ const sig = await connection.sendRawTransaction(signed.serialize(), { preflightCommitment: 'confirmed' });
1145
+ await index_native.confirmAndCheckTransaction(connection, sig);
1146
+ return sig;
1147
+ }
1148
+ const sig = await transact(async (wallet) => {
1149
+ await wallet.reauthorize({ auth_token: authToken, identity: this.appIdentity });
1150
+ const results = await wallet.signAndSendTransactions({ transactions: [transaction] });
1151
+ if (!results || results.length === 0)
1152
+ throw new Error('MWA returned no signature');
1153
+ return results[0];
1154
+ });
1155
+ await index_native.confirmAndCheckTransaction(connection, sig);
1156
+ return sig;
1157
+ }
1158
+ catch (error) {
1159
+ if (this.isNativeUserCancel(error)) {
1160
+ throw new Error('User declined to sign');
1161
+ }
1162
+ if ((error === null || error === void 0 ? void 0 : error.code) === 'ERROR_AUTHORIZATION_FAILED' || (error === null || error === void 0 ? void 0 : error.code) === 'ERROR_REAUTHORIZE') {
1163
+ await this.logout();
1164
+ throw new Error('Wallet connection lost. Please reconnect.');
1165
+ }
1166
+ throw new Error(`Failed to sign+submit transaction: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
1167
+ }
1168
+ }
844
1169
  const account = await this.ensureAuthorized();
845
1170
  const connectedPubkey = new web3_js.PublicKey(account.publicKey);
846
1171
  const wallet = await this.ensureWallet();
@@ -907,16 +1232,16 @@ class SolanaMobileWalletProvider {
907
1232
  return signature;
908
1233
  }
909
1234
  catch (error) {
910
- 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')) ||
1235
+ if (((_b = error === null || error === void 0 ? void 0 : error.message) === null || _b === void 0 ? void 0 : _b.includes('not connected')) || ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.includes('not authorized')) ||
911
1236
  (error === null || error === void 0 ? void 0 : error.code) === 'ERROR_AUTHORIZATION_FAILED') {
912
1237
  await this.logout();
913
1238
  throw new Error('Wallet connection lost. Please reconnect.');
914
1239
  }
915
1240
  const isUserRejection = (error === null || error === void 0 ? void 0 : error.code) === 4001 ||
916
- ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.toLowerCase().includes('user rejected')) ||
917
- ((_d = error === null || error === void 0 ? void 0 : error.message) === null || _d === void 0 ? void 0 : _d.toLowerCase().includes('user denied')) ||
918
- ((_e = error === null || error === void 0 ? void 0 : error.message) === null || _e === void 0 ? void 0 : _e.toLowerCase().includes('user cancelled')) ||
919
- ((_f = error === null || error === void 0 ? void 0 : error.message) === null || _f === void 0 ? void 0 : _f.toLowerCase().includes('user canceled'));
1241
+ ((_d = error === null || error === void 0 ? void 0 : error.message) === null || _d === void 0 ? void 0 : _d.toLowerCase().includes('user rejected')) ||
1242
+ ((_e = error === null || error === void 0 ? void 0 : error.message) === null || _e === void 0 ? void 0 : _e.toLowerCase().includes('user denied')) ||
1243
+ ((_f = error === null || error === void 0 ? void 0 : error.message) === null || _f === void 0 ? void 0 : _f.toLowerCase().includes('user cancelled')) ||
1244
+ ((_g = error === null || error === void 0 ? void 0 : error.message) === null || _g === void 0 ? void 0 : _g.toLowerCase().includes('user canceled'));
920
1245
  if (!isUserRejection) {
921
1246
  console.error('[SolanaMobileWallet] Transaction failed:', error);
922
1247
  }
@@ -1121,4 +1446,4 @@ class SolanaMobileWalletProvider {
1121
1446
  SolanaMobileWalletProvider.instance = null;
1122
1447
 
1123
1448
  exports.SolanaMobileWalletProvider = SolanaMobileWalletProvider;
1124
- //# sourceMappingURL=solana-mobile-wallet-provider-CN-D_H4l.js.map
1449
+ //# sourceMappingURL=solana-mobile-wallet-provider-VqIGfdMV.js.map