@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,10 +1,18 @@
1
- import { b as bufferExports } from './index-TzHXEf3-.esm.js';
2
- import { g as getPlatform, k as setAuthLoading, W as WebSessionManager, s as setCurrentUser, l as genAuthNonce, m as genSolanaMessage, n as createSessionWithSignature, d as base58, e as confirmAndCheckTransaction, c as convertRemainingAccounts, b as buildSetDocumentsTransaction, a as SOLANA_DEVNET_RPC_URL, S as SOLANA_MAINNET_RPC_URL, h as SURFNET_RPC_URL } from './index.native-DLziTime.esm.js';
1
+ import { b as bufferExports } from './index-_k6pjuwx.esm.js';
2
+ import { g as getPlatform, W as WebSessionManager, m as genAuthNonce, n as genSolanaMessage, s as setCurrentUser, o as createSessionWithSignature, l as setAuthLoading, e as confirmAndCheckTransaction, d as base58, c as convertRemainingAccounts, b as buildSetDocumentsTransaction, a as SOLANA_DEVNET_RPC_URL, S as SOLANA_MAINNET_RPC_URL, h as SURFNET_RPC_URL } from './index.native-19VsREMJ.esm.js';
3
3
  import { PublicKey, Connection, VersionedTransaction, VersionedMessage, Transaction } from '@solana/web3.js';
4
4
  import * as anchor from '@coral-xyz/anchor';
5
5
  import 'axios';
6
6
  import 'react';
7
7
 
8
+ /**
9
+ * Storage key for persisting the MWA auth_token across cold starts.
10
+ * Holds JSON `{ token: string, address: string }`. Cleared by
11
+ * `logout()`. Hydrated by the constructor on native so cold-start
12
+ * doesn't force the user back into Phantom's approval flow when the
13
+ * underlying wallet authorization is still valid.
14
+ */
15
+ const MWA_AUTH_TOKEN_STORAGE_KEY = 'tarobase_mwa_auth_token';
8
16
  const ED25519_SIGNATURE_LENGTH = 64;
9
17
  const STORED_AUTH_METHOD_KEY = 'tarobase_last_auth_method';
10
18
  const MWA_AUTH_METHOD = 'mobile-wallet-adapter';
@@ -64,20 +72,11 @@ function isMwaAssociationRetryable(e) {
64
72
  * so a second attempt skips the consent sheet, jumps straight to
65
73
  * Verify/Approve, and completes inside the timeout.
66
74
  */
67
- async function withMwaAssociationRetry(label, fn) {
68
- const t0 = Date.now();
69
- console.log(`[MWA-DEBUG] ${label} attempt=1 start`);
75
+ async function withMwaAssociationRetry(fn) {
70
76
  try {
71
- const result = await fn();
72
- console.log(`[MWA-DEBUG] ${label} attempt=1 ok (${Date.now() - t0}ms)`);
73
- return result;
77
+ return await fn();
74
78
  }
75
79
  catch (e) {
76
- const info = findMwaError(e);
77
- console.log(`[MWA-DEBUG] ${label} attempt=1 err (${Date.now() - t0}ms)`, {
78
- outer: { name: e === null || e === void 0 ? void 0 : e.name, message: e === null || e === void 0 ? void 0 : e.message },
79
- mwa: info,
80
- });
81
80
  const retryable = isMwaAssociationRetryable(e);
82
81
  if (!retryable)
83
82
  throw e;
@@ -86,21 +85,11 @@ async function withMwaAssociationRetry(label, fn) {
86
85
  // so visibility-based waits fire too early. Use a fixed delay long
87
86
  // enough for Seeker to dismiss its sheet and the OS to release intent
88
87
  // state. 2.5s is empirically safe; tune from device traces if needed.
89
- console.log(`[MWA-DEBUG] ${label} retryable (${retryable.code}); waiting 2500ms before retry`);
90
88
  await new Promise(r => setTimeout(r, 2500));
91
- const t1 = Date.now();
92
- console.log(`[MWA-DEBUG] ${label} attempt=2 start`);
93
89
  try {
94
- const result = await fn();
95
- console.log(`[MWA-DEBUG] ${label} attempt=2 ok (${Date.now() - t1}ms)`);
96
- return result;
90
+ return await fn();
97
91
  }
98
92
  catch (e2) {
99
- const info2 = findMwaError(e2);
100
- console.log(`[MWA-DEBUG] ${label} attempt=2 err (${Date.now() - t1}ms)`, {
101
- outer: { name: e2 === null || e2 === void 0 ? void 0 : e2.name, message: e2 === null || e2 === void 0 ? void 0 : e2.message },
102
- mwa: info2,
103
- });
104
93
  // Only mask the error with the clean Seeker message when the
105
94
  // second failure is also an association-flavored error. If it's
106
95
  // a user cancel, wallet rejection, or unknown error, rethrow
@@ -139,7 +128,7 @@ async function withMwaAssociationRetry(label, fn) {
139
128
  * next tap is a new activation (a real retry). A timer-based retry would
140
129
  * just hit the same Chrome block. Cap at 3 attempts before giving up.
141
130
  */
142
- async function awaitSignInGestureAndSign(label, theme, signFn) {
131
+ async function awaitSignInGestureAndSign(theme, signFn) {
143
132
  if (typeof document === 'undefined' || typeof window === 'undefined') {
144
133
  // SSR / non-browser: skip the gesture, just call (the activation
145
134
  // model doesn't apply outside the browser).
@@ -306,18 +295,15 @@ async function awaitSignInGestureAndSign(label, theme, signFn) {
306
295
  finishReject(new Error('User cancelled wallet sign in'));
307
296
  };
308
297
  closeBtn.addEventListener('click', () => {
309
- console.log(`[MWA-DEBUG] ${label} gesture: close clicked`);
310
298
  handleCancel();
311
299
  });
312
300
  overlay.addEventListener('click', (e) => {
313
301
  if (e.target === overlay) {
314
- console.log(`[MWA-DEBUG] ${label} gesture: overlay clicked (cancel)`);
315
302
  handleCancel();
316
303
  }
317
304
  });
318
305
  const onKeydown = (e) => {
319
306
  if (e.key === 'Escape') {
320
- console.log(`[MWA-DEBUG] ${label} gesture: Escape pressed (cancel)`);
321
307
  handleCancel();
322
308
  }
323
309
  };
@@ -327,7 +313,6 @@ async function awaitSignInGestureAndSign(label, theme, signFn) {
327
313
  return;
328
314
  attemptCount++;
329
315
  const attempt = attemptCount;
330
- console.log(`[MWA-DEBUG] ${label} gesture: button click attempt=${attempt}`);
331
316
  // Disable to prevent double-clicks while the wallet popup is up.
332
317
  button.disabled = true;
333
318
  setButtonDisabledStyle();
@@ -339,29 +324,17 @@ async function awaitSignInGestureAndSign(label, theme, signFn) {
339
324
  // so Chrome's transient user activation propagates to the
340
325
  // protocol's window.location.assign(associationUrl) inside
341
326
  // launchAssociation(). Do not `await` before calling.
342
- const t0 = Date.now();
343
- console.log(`[MWA-DEBUG] ${label} gesture: signMessage start (attempt=${attempt})`);
344
327
  signFn().then((results) => {
345
- const elapsed = Date.now() - t0;
346
328
  if (!results || results.length === 0) {
347
- console.log(`[MWA-DEBUG] ${label} gesture: signMessage returned empty (attempt=${attempt}, ${elapsed}ms)`);
348
329
  finishReject(new Error('MWA returned no signature'));
349
330
  return;
350
331
  }
351
- console.log(`[MWA-DEBUG] ${label} gesture: signMessage ok (attempt=${attempt}, ${elapsed}ms)`);
352
332
  finishResolve(results[0]);
353
333
  }).catch((err) => {
354
- const elapsed = Date.now() - t0;
355
- const info = findMwaError(err);
356
- console.log(`[MWA-DEBUG] ${label} gesture: signMessage err (attempt=${attempt}, ${elapsed}ms)`, {
357
- outer: { name: err === null || err === void 0 ? void 0 : err.name, message: err === null || err === void 0 ? void 0 : err.message },
358
- mwa: info,
359
- });
360
334
  const retryable = isMwaAssociationRetryable(err);
361
335
  if (retryable && attempt < MAX_ATTEMPTS) {
362
336
  // Re-enable the button so the user's next tap provides a
363
337
  // fresh user activation. Show inline error text.
364
- console.log(`[MWA-DEBUG] ${label} gesture: retryable (${retryable.code}); awaiting user tap to retry (attempt ${attempt}/${MAX_ATTEMPTS})`);
365
338
  button.disabled = false;
366
339
  setButtonEnabledStyle();
367
340
  button.textContent = originalText;
@@ -371,7 +344,6 @@ async function awaitSignInGestureAndSign(label, theme, signFn) {
371
344
  }
372
345
  if (retryable) {
373
346
  // Hit the attempt cap with a still-retryable failure.
374
- console.log(`[MWA-DEBUG] ${label} gesture: retryable but attempt cap reached (${attempt})`);
375
347
  finishReject(new Error("Couldn't connect to your Seeker wallet. Please try again."));
376
348
  return;
377
349
  }
@@ -380,7 +352,6 @@ async function awaitSignInGestureAndSign(label, theme, signFn) {
380
352
  finishReject(err);
381
353
  });
382
354
  });
383
- console.log(`[MWA-DEBUG] ${label} gesture: modal shown`);
384
355
  });
385
356
  }
386
357
  /**
@@ -543,19 +514,66 @@ class SolanaMobileWalletProvider {
543
514
  constructor(networkUrl = null, config = {}) {
544
515
  /** LocalSolanaMobileWalletAdapterWallet, lazy-constructed in ensureWallet(). */
545
516
  this.wallet = null;
517
+ /**
518
+ * Cached MWA auth_token returned by `wallet.authorize()`. Reused by
519
+ * subsequent native transact() calls (signMessage / signTransaction)
520
+ * so the user doesn't get the wallet-pick popup on every operation.
521
+ * Persisted to platform storage and hydrated by the constructor on
522
+ * native; cleared by logout() and on `ERROR_REAUTHORIZE`.
523
+ */
524
+ this.nativeAuthToken = null;
525
+ /** Cached public key string for the connected MWA wallet (native). */
526
+ this.nativeAddress = null;
546
527
  this.networkUrl = networkUrl;
547
528
  this.config = config;
548
- if (typeof window === 'undefined') {
529
+ // Allow construction in true React Native environments: getPlatform().hasDOM
530
+ // is false there even though `typeof window === 'object'` (RN exposes a
531
+ // partial window global). Web/PWA paths still keep their original guard:
532
+ // they need real window+document for wallet-standard-mobile's deep-link
533
+ // mechanism, so missing-window in those builds remains a fail-fast.
534
+ const hasDOM = getPlatform().hasDOM;
535
+ if (!hasDOM && typeof window === 'undefined') {
536
+ throw new Error('SolanaMobileWalletProvider can only be instantiated in a browser or React Native environment');
537
+ }
538
+ if (hasDOM && typeof window === 'undefined') {
549
539
  throw new Error('SolanaMobileWalletProvider can only be instantiated in a browser environment');
550
540
  }
551
541
  if (SolanaMobileWalletProvider.instance) {
552
542
  return SolanaMobileWalletProvider.instance;
553
543
  }
544
+ // `appIdentity.uri` is what Phantom Android (and other MWA wallets)
545
+ // display in their approval modal. On web/PWA this is the page
546
+ // origin; on native there's no `window.location`, so fall back to
547
+ // a stable identifier the user can recognize. Apps can override
548
+ // entirely via `config.appIdentity.uri`.
549
+ const fallbackUri = hasDOM
550
+ ? getPlatform().getLocationOrigin()
551
+ : 'tarobase://app';
554
552
  this.appIdentity = config.appIdentity || {
555
553
  name: 'TaroBase App',
556
- uri: getPlatform().getLocationOrigin(),
554
+ uri: fallbackUri,
557
555
  };
558
556
  this.cluster = config.cluster || 'mainnet-beta';
557
+ // Hydrate cached MWA auth_token from storage on native so we can
558
+ // skip the wallet-pick popup after a cold-start when the underlying
559
+ // wallet authorization is still valid. Sync storage call per the
560
+ // PlatformAdapter contract; safe to swallow read errors (a fresh
561
+ // login() just re-authorizes).
562
+ if (!hasDOM) {
563
+ try {
564
+ const raw = getPlatform().storage.getItem(MWA_AUTH_TOKEN_STORAGE_KEY);
565
+ if (raw) {
566
+ const parsed = JSON.parse(raw);
567
+ if (typeof parsed.token === 'string' && typeof parsed.address === 'string') {
568
+ this.nativeAuthToken = parsed.token;
569
+ this.nativeAddress = parsed.address;
570
+ }
571
+ }
572
+ }
573
+ catch (_a) {
574
+ // Corrupt or unreadable cache — ignore. login() will re-auth.
575
+ }
576
+ }
559
577
  SolanaMobileWalletProvider.instance = this;
560
578
  }
561
579
  static getInstance(networkUrl, config) {
@@ -568,7 +586,7 @@ class SolanaMobileWalletProvider {
568
586
  async ensureWallet() {
569
587
  if (this.wallet)
570
588
  return this.wallet;
571
- const mod = await import('./index.browser-D8ttddP4.esm.js');
589
+ const mod = await import('./index.browser-Cndx2raY.esm.js');
572
590
  const chain = mapChainToWalletStandard(this.cluster);
573
591
  this.wallet = new mod.LocalSolanaMobileWalletAdapterWallet({
574
592
  appIdentity: this.appIdentity,
@@ -582,7 +600,7 @@ class SolanaMobileWalletProvider {
582
600
  // login()'s withMwaAssociationRetry handles this case; on second
583
601
  // failure it surfaces a clean error message to the host app.
584
602
  onWalletNotFound: async () => {
585
- console.warn('[MWA-DEBUG] ensureWallet onWalletNotFound (suppressed)');
603
+ // intentional no-op
586
604
  },
587
605
  });
588
606
  return this.wallet;
@@ -618,6 +636,134 @@ class SolanaMobileWalletProvider {
618
636
  getChain() {
619
637
  return mapChainToWalletStandard(this.cluster);
620
638
  }
639
+ /**
640
+ * Dynamically import and unwrap `transact` from the MWA web3js
641
+ * package. The package is externalized in rollup.config.js so this
642
+ * resolves to `lib/cjs/index.native.js` (TurboModule-backed) on
643
+ * Metro and `lib/esm/index.browser.js` (WebSocket) on webpack/vite
644
+ * per their respective platform conditions. Handles Metro's CJS-to-
645
+ * ESM interop variance (`mod.transact` vs `mod.default?.transact`).
646
+ */
647
+ async loadTransact() {
648
+ var _a;
649
+ const mod = await import('@solana-mobile/mobile-wallet-adapter-protocol-web3js');
650
+ const t = mod.transact || ((_a = mod.default) === null || _a === void 0 ? void 0 : _a.transact);
651
+ if (typeof t !== 'function') {
652
+ throw new Error('MWA transact API not available on this platform');
653
+ }
654
+ return t;
655
+ }
656
+ /**
657
+ * Cache and persist a fresh MWA auth_token + address. Called from
658
+ * `_loginNative` after a successful authorize. Storage failures are
659
+ * non-fatal (next cold-start re-auths).
660
+ */
661
+ persistNativeAuth(token, address) {
662
+ this.nativeAuthToken = token;
663
+ this.nativeAddress = address;
664
+ try {
665
+ getPlatform().storage.setItem(MWA_AUTH_TOKEN_STORAGE_KEY, JSON.stringify({ token, address }));
666
+ }
667
+ catch (_a) {
668
+ // non-fatal — token still in-memory for this process
669
+ }
670
+ }
671
+ /** Clear cached + persisted native auth state. */
672
+ clearNativeAuth() {
673
+ this.nativeAuthToken = null;
674
+ this.nativeAddress = null;
675
+ try {
676
+ getPlatform().storage.removeItem(MWA_AUTH_TOKEN_STORAGE_KEY);
677
+ }
678
+ catch (_a) {
679
+ // ignore
680
+ }
681
+ }
682
+ /**
683
+ * Classify an MWA-native error as a user cancellation. User-cancel
684
+ * shouldn't surface as a red console.error; callers can swallow or
685
+ * show a softer message. MWA spec codes plus the same substring
686
+ * checks the web path uses to catch wallet-specific phrasing.
687
+ */
688
+ isNativeUserCancel(err) {
689
+ var _a;
690
+ if (!err)
691
+ return false;
692
+ const code = err.code;
693
+ if (code === 'ERROR_NOT_SIGNED')
694
+ return true;
695
+ const msg = String((_a = err.message) !== null && _a !== void 0 ? _a : '').toLowerCase();
696
+ return /user (rejected|denied|cancelled|canceled|declined)/.test(msg);
697
+ }
698
+ /**
699
+ * Native MWA login via @solana-mobile/mobile-wallet-adapter-protocol-web3js.
700
+ * Used in true React Native (Expo) environments where wallet-standard-mobile's
701
+ * web universal-link path doesn't apply. Does authorize + signMessage in a
702
+ * single transact() roundtrip — intent-based MWA doesn't need the two-popup
703
+ * dance the web path uses (no Chrome activation-loss concern). Persists the
704
+ * resulting auth_token so cold-start can reauthorize without a fresh popup.
705
+ */
706
+ async _loginNative() {
707
+ const transact = await this.loadTransact();
708
+ const existingSession = await WebSessionManager.getSession();
709
+ const nonce = await genAuthNonce();
710
+ const result = await transact(async (wallet) => {
711
+ const auth = await wallet.authorize({
712
+ chain: this.getChain(),
713
+ identity: this.appIdentity,
714
+ });
715
+ if (!auth.accounts || auth.accounts.length === 0) {
716
+ throw new Error('MWA returned no accounts');
717
+ }
718
+ const account = auth.accounts[0];
719
+ // account.address is base64-encoded per MWA spec; convert to
720
+ // the base58 form Tarobase + the rest of the SDK use.
721
+ const base58Addr = new PublicKey(bufferExports.Buffer.from(account.address, 'base64')).toBase58();
722
+ // Reuse session if already valid for this address — skip the
723
+ // signMessages roundtrip entirely.
724
+ if (existingSession && existingSession.address === base58Addr) {
725
+ return {
726
+ base58Addr,
727
+ authToken: auth.auth_token,
728
+ signatureBase64: null,
729
+ };
730
+ }
731
+ const messageText = await genSolanaMessage(base58Addr, nonce);
732
+ const messageBytes = getPlatform().textEncode(messageText);
733
+ const signatures = await wallet.signMessages({
734
+ addresses: [account.address],
735
+ payloads: [messageBytes],
736
+ });
737
+ if (!signatures || signatures.length === 0) {
738
+ throw new Error('MWA returned no signature');
739
+ }
740
+ // Per spec, signMessages returns Uint8Array[] of signatures
741
+ // (one per payload), not message+signature concatenations.
742
+ const signatureBase64 = bufferExports.Buffer.from(signatures[0]).toString('base64');
743
+ return {
744
+ base58Addr,
745
+ authToken: auth.auth_token,
746
+ signatureBase64,
747
+ messageText,
748
+ };
749
+ });
750
+ this.persistNativeAuth(result.authToken, result.base58Addr);
751
+ // Existing valid session — short-circuit before re-creating server-side.
752
+ if (existingSession && existingSession.address === result.base58Addr) {
753
+ const user = { provider: this, address: result.base58Addr };
754
+ setCurrentUser(user);
755
+ return user;
756
+ }
757
+ // Create Tarobase session on the server.
758
+ if (!result.signatureBase64 || !result.messageText) {
759
+ throw new Error('MWA login completed without signature');
760
+ }
761
+ const createSessionResult = await createSessionWithSignature(result.base58Addr, result.messageText, result.signatureBase64);
762
+ await WebSessionManager.storeSession(result.base58Addr, createSessionResult.accessToken, createSessionResult.idToken, createSessionResult.refreshToken);
763
+ const user = { provider: this, address: result.base58Addr };
764
+ setCurrentUser(user);
765
+ return user;
766
+ }
621
767
  async login() {
622
768
  var _a, _b, _c, _d, _e;
623
769
  setAuthLoading(true);
@@ -628,6 +774,13 @@ class SolanaMobileWalletProvider {
628
774
  const prevAuthMethod = readAuthMethod();
629
775
  writeAuthMethod(MWA_AUTH_METHOD);
630
776
  try {
777
+ // True React Native: skip the wallet-standard-mobile path (which
778
+ // requires window.isSecureContext and a real DOM) and use the raw
779
+ // MWA protocol via Android intents.
780
+ if (!getPlatform().hasDOM) {
781
+ const user = await this._loginNative();
782
+ return user;
783
+ }
631
784
  const wallet = await this.ensureWallet();
632
785
  // Quick-check: wallet may already have authorization (e.g. from a
633
786
  // previous in-page login) and a matching Tarobase session — skip
@@ -656,7 +809,7 @@ class SolanaMobileWalletProvider {
656
809
  // consent on the second pass and completes quickly. See
657
810
  // withMwaAssociationRetry for details.
658
811
  const connectFeat = getConnectFeature(wallet);
659
- const { accounts } = await withMwaAssociationRetry('login:connect', () => connectFeat.connect());
812
+ const { accounts } = await withMwaAssociationRetry(() => connectFeat.connect());
660
813
  if (!accounts || accounts.length === 0) {
661
814
  throw new Error('MWA returned no accounts');
662
815
  }
@@ -689,7 +842,7 @@ class SolanaMobileWalletProvider {
689
842
  const messageText = await genSolanaMessage(base58Addr, nonce);
690
843
  const messageBytes = getPlatform().textEncode(messageText);
691
844
  const signMessageFeat = getSignMessageFeature(wallet);
692
- const signResult = await awaitSignInGestureAndSign('login:signMessage', this.config.theme, () => signMessageFeat.signMessage({ account, message: messageBytes }));
845
+ const signResult = await awaitSignInGestureAndSign(this.config.theme, () => signMessageFeat.signMessage({ account, message: messageBytes }));
693
846
  if (!signResult) {
694
847
  throw new Error('MWA returned no signature');
695
848
  }
@@ -729,6 +882,29 @@ class SolanaMobileWalletProvider {
729
882
  return null;
730
883
  }
731
884
  async logout() {
885
+ if (!getPlatform().hasDOM) {
886
+ // Native path: deauthorize the cached MWA auth_token if we have
887
+ // one (failures non-fatal — the wallet app may have been
888
+ // uninstalled or the token already revoked), then clear local
889
+ // and persisted state.
890
+ const token = this.nativeAuthToken;
891
+ if (token) {
892
+ try {
893
+ const transact = await this.loadTransact();
894
+ await transact(async (wallet) => {
895
+ await wallet.deauthorize({ auth_token: token });
896
+ });
897
+ }
898
+ catch (error) {
899
+ console.warn('[SolanaMobileWallet] Native deauthorize error:', error);
900
+ }
901
+ }
902
+ this.clearNativeAuth();
903
+ WebSessionManager.clearSession();
904
+ writeAuthMethod(null);
905
+ setCurrentUser(null);
906
+ return;
907
+ }
732
908
  try {
733
909
  const wallet = await this.ensureWallet();
734
910
  const disconnectFeat = getDisconnectFeature(wallet);
@@ -748,7 +924,42 @@ class SolanaMobileWalletProvider {
748
924
  setCurrentUser(null);
749
925
  }
750
926
  async signMessage(message) {
751
- var _a, _b;
927
+ var _a, _b, _c;
928
+ // Native: reauthorize with cached auth_token, then signMessages inside
929
+ // the same transact() session. No wallet-pick popup if the auth_token
930
+ // is still valid for the user's wallet.
931
+ if (!getPlatform().hasDOM) {
932
+ if (!this.nativeAuthToken || !this.nativeAddress) {
933
+ throw new Error('Wallet not connected. Call login() first.');
934
+ }
935
+ const transact = await this.loadTransact();
936
+ const messageBytes = getPlatform().textEncode(message);
937
+ const addressBase64 = new PublicKey(this.nativeAddress).toBuffer().toString('base64');
938
+ const authToken = this.nativeAuthToken;
939
+ try {
940
+ const signature = await transact(async (wallet) => {
941
+ await wallet.reauthorize({ auth_token: authToken, identity: this.appIdentity });
942
+ const sigs = await wallet.signMessages({
943
+ addresses: [addressBase64],
944
+ payloads: [messageBytes],
945
+ });
946
+ if (!sigs || sigs.length === 0)
947
+ throw new Error('MWA returned no signature');
948
+ return sigs[0];
949
+ });
950
+ return bufferExports.Buffer.from(signature).toString('base64');
951
+ }
952
+ catch (error) {
953
+ if (this.isNativeUserCancel(error)) {
954
+ throw new Error('User declined to sign');
955
+ }
956
+ if ((error === null || error === void 0 ? void 0 : error.code) === 'ERROR_AUTHORIZATION_FAILED' || (error === null || error === void 0 ? void 0 : error.code) === 'ERROR_REAUTHORIZE') {
957
+ await this.logout();
958
+ throw new Error('Wallet connection lost. Please reconnect.');
959
+ }
960
+ throw new Error(`Failed to sign message: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
961
+ }
962
+ }
752
963
  const account = await this.ensureAuthorized();
753
964
  const wallet = await this.ensureWallet();
754
965
  try {
@@ -762,7 +973,7 @@ class SolanaMobileWalletProvider {
762
973
  return bufferExports.Buffer.from(sigBytes).toString('base64');
763
974
  }
764
975
  catch (error) {
765
- 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')) ||
976
+ 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')) ||
766
977
  (error === null || error === void 0 ? void 0 : error.code) === 'ERROR_AUTHORIZATION_FAILED') {
767
978
  await this.logout();
768
979
  throw new Error('Wallet connection lost. Please reconnect.');
@@ -771,7 +982,58 @@ class SolanaMobileWalletProvider {
771
982
  }
772
983
  }
773
984
  async signTransaction(transaction) {
774
- var _a, _b;
985
+ var _a, _b, _c;
986
+ // Native: fill blockhash/feePayer if missing, then signTransactions
987
+ // inside a transact() session keyed by the cached auth_token.
988
+ if (!getPlatform().hasDOM) {
989
+ if (!this.nativeAuthToken || !this.nativeAddress) {
990
+ throw new Error('Wallet not connected. Call login() first.');
991
+ }
992
+ const connectedPubkey = new PublicKey(this.nativeAddress);
993
+ const isLegacyTransaction = 'recentBlockhash' in transaction && !('message' in transaction && 'staticAccountKeys' in transaction.message);
994
+ if (isLegacyTransaction) {
995
+ const legacyTx = transaction;
996
+ if (!legacyTx.recentBlockhash) {
997
+ const conn = new Connection(this.getRpcUrl(), 'confirmed');
998
+ const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash('confirmed');
999
+ legacyTx.recentBlockhash = blockhash;
1000
+ legacyTx.lastValidBlockHeight = lastValidBlockHeight;
1001
+ }
1002
+ if (!legacyTx.feePayer) {
1003
+ legacyTx.feePayer = connectedPubkey;
1004
+ }
1005
+ }
1006
+ else {
1007
+ const versionedTx = transaction;
1008
+ if (!versionedTx.message.recentBlockhash) {
1009
+ const conn = new Connection(this.getRpcUrl(), 'confirmed');
1010
+ const { blockhash } = await conn.getLatestBlockhash('confirmed');
1011
+ versionedTx.message.recentBlockhash = blockhash;
1012
+ }
1013
+ }
1014
+ const transact = await this.loadTransact();
1015
+ const authToken = this.nativeAuthToken;
1016
+ try {
1017
+ const signed = await transact(async (wallet) => {
1018
+ await wallet.reauthorize({ auth_token: authToken, identity: this.appIdentity });
1019
+ const results = await wallet.signTransactions({ transactions: [transaction] });
1020
+ if (!results || results.length === 0)
1021
+ throw new Error('MWA returned no signed transaction');
1022
+ return results[0];
1023
+ });
1024
+ return signed;
1025
+ }
1026
+ catch (error) {
1027
+ if (this.isNativeUserCancel(error)) {
1028
+ throw new Error('User declined to sign');
1029
+ }
1030
+ if ((error === null || error === void 0 ? void 0 : error.code) === 'ERROR_AUTHORIZATION_FAILED' || (error === null || error === void 0 ? void 0 : error.code) === 'ERROR_REAUTHORIZE') {
1031
+ await this.logout();
1032
+ throw new Error('Wallet connection lost. Please reconnect.');
1033
+ }
1034
+ throw new Error(`Failed to sign transaction: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
1035
+ }
1036
+ }
775
1037
  const account = await this.ensureAuthorized();
776
1038
  const connectedPubkey = new PublicKey(account.publicKey);
777
1039
  const wallet = await this.ensureWallet();
@@ -810,7 +1072,7 @@ class SolanaMobileWalletProvider {
810
1072
  return txFromWireBytes(new Uint8Array(signedBytes));
811
1073
  }
812
1074
  catch (error) {
813
- 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')) ||
1075
+ 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')) ||
814
1076
  (error === null || error === void 0 ? void 0 : error.code) === 'ERROR_AUTHORIZATION_FAILED') {
815
1077
  await this.logout();
816
1078
  throw new Error('Wallet connection lost. Please reconnect.');
@@ -819,7 +1081,70 @@ class SolanaMobileWalletProvider {
819
1081
  }
820
1082
  }
821
1083
  async signAndSubmitTransaction(transaction, feePayer) {
822
- var _a, _b, _c, _d, _e, _f;
1084
+ var _a, _b, _c, _d, _e, _f, _g;
1085
+ // Native: signAndSendTransactions inside a transact() session.
1086
+ // The wallet submits to its own RPC; we then await confirmation on
1087
+ // ours. Surfnet (custom RPC) needs manual submission because the
1088
+ // wallet won't route there — we fall back to sign-only + manual send.
1089
+ if (!getPlatform().hasDOM) {
1090
+ if (!this.nativeAuthToken || !this.nativeAddress) {
1091
+ throw new Error('Wallet not connected. Call login() first.');
1092
+ }
1093
+ const connectedPubkey = new PublicKey(this.nativeAddress);
1094
+ const rpcUrl = this.getRpcUrl();
1095
+ const connection = new Connection(rpcUrl, 'confirmed');
1096
+ const isSurfnet = rpcUrl === SURFNET_RPC_URL;
1097
+ const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
1098
+ const isLegacyTransaction = 'recentBlockhash' in transaction && !('message' in transaction && 'staticAccountKeys' in transaction.message);
1099
+ if (isLegacyTransaction) {
1100
+ const legacyTx = transaction;
1101
+ legacyTx.recentBlockhash = blockhash;
1102
+ legacyTx.lastValidBlockHeight = lastValidBlockHeight;
1103
+ if (!legacyTx.feePayer)
1104
+ legacyTx.feePayer = feePayer !== null && feePayer !== void 0 ? feePayer : connectedPubkey;
1105
+ }
1106
+ else {
1107
+ const versionedTx = transaction;
1108
+ versionedTx.message.recentBlockhash = blockhash;
1109
+ }
1110
+ const transact = await this.loadTransact();
1111
+ const authToken = this.nativeAuthToken;
1112
+ try {
1113
+ if (isSurfnet) {
1114
+ // Surfnet: sign only, submit manually to Surfnet RPC
1115
+ // (the wallet would route signAndSend to its own RPC).
1116
+ const signed = await transact(async (wallet) => {
1117
+ await wallet.reauthorize({ auth_token: authToken, identity: this.appIdentity });
1118
+ const results = await wallet.signTransactions({ transactions: [transaction] });
1119
+ if (!results || results.length === 0)
1120
+ throw new Error('MWA returned no signed transaction');
1121
+ return results[0];
1122
+ });
1123
+ const sig = await connection.sendRawTransaction(signed.serialize(), { preflightCommitment: 'confirmed' });
1124
+ await confirmAndCheckTransaction(connection, sig);
1125
+ return sig;
1126
+ }
1127
+ const sig = await transact(async (wallet) => {
1128
+ await wallet.reauthorize({ auth_token: authToken, identity: this.appIdentity });
1129
+ const results = await wallet.signAndSendTransactions({ transactions: [transaction] });
1130
+ if (!results || results.length === 0)
1131
+ throw new Error('MWA returned no signature');
1132
+ return results[0];
1133
+ });
1134
+ await confirmAndCheckTransaction(connection, sig);
1135
+ return sig;
1136
+ }
1137
+ catch (error) {
1138
+ if (this.isNativeUserCancel(error)) {
1139
+ throw new Error('User declined to sign');
1140
+ }
1141
+ if ((error === null || error === void 0 ? void 0 : error.code) === 'ERROR_AUTHORIZATION_FAILED' || (error === null || error === void 0 ? void 0 : error.code) === 'ERROR_REAUTHORIZE') {
1142
+ await this.logout();
1143
+ throw new Error('Wallet connection lost. Please reconnect.');
1144
+ }
1145
+ throw new Error(`Failed to sign+submit transaction: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
1146
+ }
1147
+ }
823
1148
  const account = await this.ensureAuthorized();
824
1149
  const connectedPubkey = new PublicKey(account.publicKey);
825
1150
  const wallet = await this.ensureWallet();
@@ -886,16 +1211,16 @@ class SolanaMobileWalletProvider {
886
1211
  return signature;
887
1212
  }
888
1213
  catch (error) {
889
- 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')) ||
1214
+ 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')) ||
890
1215
  (error === null || error === void 0 ? void 0 : error.code) === 'ERROR_AUTHORIZATION_FAILED') {
891
1216
  await this.logout();
892
1217
  throw new Error('Wallet connection lost. Please reconnect.');
893
1218
  }
894
1219
  const isUserRejection = (error === null || error === void 0 ? void 0 : error.code) === 4001 ||
895
- ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.toLowerCase().includes('user rejected')) ||
896
- ((_d = error === null || error === void 0 ? void 0 : error.message) === null || _d === void 0 ? void 0 : _d.toLowerCase().includes('user denied')) ||
897
- ((_e = error === null || error === void 0 ? void 0 : error.message) === null || _e === void 0 ? void 0 : _e.toLowerCase().includes('user cancelled')) ||
898
- ((_f = error === null || error === void 0 ? void 0 : error.message) === null || _f === void 0 ? void 0 : _f.toLowerCase().includes('user canceled'));
1220
+ ((_d = error === null || error === void 0 ? void 0 : error.message) === null || _d === void 0 ? void 0 : _d.toLowerCase().includes('user rejected')) ||
1221
+ ((_e = error === null || error === void 0 ? void 0 : error.message) === null || _e === void 0 ? void 0 : _e.toLowerCase().includes('user denied')) ||
1222
+ ((_f = error === null || error === void 0 ? void 0 : error.message) === null || _f === void 0 ? void 0 : _f.toLowerCase().includes('user cancelled')) ||
1223
+ ((_g = error === null || error === void 0 ? void 0 : error.message) === null || _g === void 0 ? void 0 : _g.toLowerCase().includes('user canceled'));
899
1224
  if (!isUserRejection) {
900
1225
  console.error('[SolanaMobileWallet] Transaction failed:', error);
901
1226
  }
@@ -1100,4 +1425,4 @@ class SolanaMobileWalletProvider {
1100
1425
  SolanaMobileWalletProvider.instance = null;
1101
1426
 
1102
1427
  export { SolanaMobileWalletProvider };
1103
- //# sourceMappingURL=solana-mobile-wallet-provider-B8rHfsPN.esm.js.map
1428
+ //# sourceMappingURL=solana-mobile-wallet-provider-EeQsBTdr.esm.js.map