@pooflabs/web 0.0.86 → 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-D-Wbwevj.js → index-B-x9RTF7.js} +2 -2
  3. package/dist/index-B-x9RTF7.js.map +1 -0
  4. package/dist/{index-BHkED2YI.js → index-BKN0IwAx.js} +3054 -300
  5. package/dist/index-BKN0IwAx.js.map +1 -0
  6. package/dist/{index-BQUfNEiY.esm.js → index-BTwX7FYW.esm.js} +417 -74
  7. package/dist/index-BTwX7FYW.esm.js.map +1 -0
  8. package/dist/{index-DUn32Hkh.js → index-DYBdUxnT.js} +3055 -301
  9. package/dist/index-DYBdUxnT.js.map +1 -0
  10. package/dist/{index-hEc5_KoM.js → index-Dj1tZr6X.js} +418 -73
  11. package/dist/index-Dj1tZr6X.js.map +1 -0
  12. package/dist/{index-DK28JaJm.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-Cfp30Jm_.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-DQqKPfDA.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-CbawPvh6.js → index.browser-D7-FFk3q.js} +506 -1876
  21. package/dist/index.browser-D7-FFk3q.js.map +1 -0
  22. package/dist/{index.browser-DD8pg_L2.js → index.browser-DlA-NKvf.js} +1223 -2565
  23. package/dist/index.browser-DlA-NKvf.js.map +1 -0
  24. package/dist/{index.browser-C9gHoUen.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-BItnSD47.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-7hiNiSyC.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-CjvLq_2_.js → phantom-wallet-provider-BlZZa_3s.js} +4 -4
  35. package/dist/{phantom-wallet-provider-CjvLq_2_.js.map → phantom-wallet-provider-BlZZa_3s.js.map} +1 -1
  36. package/dist/{phantom-wallet-provider-DE3vit2Z.esm.js → phantom-wallet-provider-Bz3qEFzX.esm.js} +4 -4
  37. package/dist/{phantom-wallet-provider-DE3vit2Z.esm.js.map → phantom-wallet-provider-Bz3qEFzX.esm.js.map} +1 -1
  38. package/dist/{privy-wallet-provider-DFZaQPss.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-ip2pqo_U.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-D7BbSpez.esm.js → solana-mobile-wallet-provider-EeQsBTdr.esm.js} +378 -16
  43. package/dist/solana-mobile-wallet-provider-EeQsBTdr.esm.js.map +1 -0
  44. package/dist/{solana-mobile-wallet-provider-DwER68Rz.js → solana-mobile-wallet-provider-VqIGfdMV.js} +378 -16
  45. package/dist/solana-mobile-wallet-provider-VqIGfdMV.js.map +1 -0
  46. package/package.json +1 -1
  47. package/dist/index-BHkED2YI.js.map +0 -1
  48. package/dist/index-BQUfNEiY.esm.js.map +0 -1
  49. package/dist/index-Cfp30Jm_.esm.js.map +0 -1
  50. package/dist/index-D-Wbwevj.js.map +0 -1
  51. package/dist/index-DK28JaJm.esm.js.map +0 -1
  52. package/dist/index-DKyWaxCB.esm.js +0 -6
  53. package/dist/index-DKyWaxCB.esm.js.map +0 -1
  54. package/dist/index-DUn32Hkh.js.map +0 -1
  55. package/dist/index-hEc5_KoM.js.map +0 -1
  56. package/dist/index.browser-C9gHoUen.esm.js.map +0 -1
  57. package/dist/index.browser-CbawPvh6.js.map +0 -1
  58. package/dist/index.browser-DD8pg_L2.js.map +0 -1
  59. package/dist/index.browser-DQqKPfDA.esm.js.map +0 -1
  60. package/dist/index.native-7hiNiSyC.js.map +0 -1
  61. package/dist/index.native-BItnSD47.esm.js.map +0 -1
  62. package/dist/privy-wallet-provider-DFZaQPss.js.map +0 -1
  63. package/dist/privy-wallet-provider-ip2pqo_U.esm.js.map +0 -1
  64. package/dist/solana-mobile-wallet-provider-D7BbSpez.esm.js.map +0 -1
  65. package/dist/solana-mobile-wallet-provider-DwER68Rz.js.map +0 -1
@@ -22,6 +22,21 @@ function _interopNamespaceDefault(e) {
22
22
  return Object.freeze(n);
23
23
  }
24
24
 
25
+ function _mergeNamespaces(n, m) {
26
+ m.forEach(function (e) {
27
+ e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
28
+ if (k !== 'default' && !(k in n)) {
29
+ var d = Object.getOwnPropertyDescriptor(e, k);
30
+ Object.defineProperty(n, k, d.get ? d : {
31
+ enumerable: true,
32
+ get: function () { return e[k]; }
33
+ });
34
+ }
35
+ });
36
+ });
37
+ return Object.freeze(n);
38
+ }
39
+
25
40
  var anchor__namespace = /*#__PURE__*/_interopNamespaceDefault(anchor);
26
41
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React$2);
27
42
 
@@ -6770,28 +6785,6 @@ class WebSessionManager {
6770
6785
  static async storeSession(address, accessToken, idToken, refreshToken) {
6771
6786
  if (typeof window === "undefined")
6772
6787
  return;
6773
- // JWT-wallet binding: refuse to store a session whose idToken is bound
6774
- // to a different wallet than `address`. Prevents races that would otherwise
6775
- // leave localStorage with mismatched address/token state.
6776
- try {
6777
- const payloadB64 = idToken.split(".")[1];
6778
- if (payloadB64) {
6779
- const payload = JSON.parse(this.decodeBase64Url(payloadB64));
6780
- const tokenWallet = payload["custom:walletAddress"];
6781
- if (tokenWallet && tokenWallet !== address) {
6782
- throw new Error(`[WebSessionManager] Refusing to store session: address (${address}) does not match idToken custom:walletAddress (${tokenWallet})`);
6783
- }
6784
- if (!tokenWallet) {
6785
- console.warn("[WebSessionManager] storeSession: idToken has no custom:walletAddress claim — writing without validation");
6786
- }
6787
- }
6788
- }
6789
- catch (err) {
6790
- if (typeof (err === null || err === void 0 ? void 0 : err.message) === "string" && err.message.includes("Refusing to store session")) {
6791
- throw err;
6792
- }
6793
- console.warn("[WebSessionManager] storeSession: failed to decode idToken for validation:", err);
6794
- }
6795
6788
  const config = await getConfig();
6796
6789
  const currentAppId = config.appId;
6797
6790
  localStorage.setItem(this.TAROBASE_SESSION_STORAGE_KEY, JSON.stringify({
@@ -9490,11 +9483,11 @@ function requireSrc$1 () {
9490
9483
  }
9491
9484
 
9492
9485
  var bs58$1;
9493
- var hasRequiredBs58;
9486
+ var hasRequiredBs58$1;
9494
9487
 
9495
- function requireBs58 () {
9496
- if (hasRequiredBs58) return bs58$1;
9497
- hasRequiredBs58 = 1;
9488
+ function requireBs58$1 () {
9489
+ if (hasRequiredBs58$1) return bs58$1;
9490
+ hasRequiredBs58$1 = 1;
9498
9491
  var basex = requireSrc$1();
9499
9492
  var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
9500
9493
 
@@ -9502,8 +9495,8 @@ function requireBs58 () {
9502
9495
  return bs58$1;
9503
9496
  }
9504
9497
 
9505
- var bs58Exports = requireBs58();
9506
- var bs58 = /*@__PURE__*/getDefaultExportFromCjs(bs58Exports);
9498
+ var bs58Exports$1 = requireBs58$1();
9499
+ var bs58$2 = /*@__PURE__*/getDefaultExportFromCjs(bs58Exports$1);
9507
9500
 
9508
9501
  // ─────────────────────────────────────────────────────────────
9509
9502
  // Local implementation of getSimulationComputeUnits
@@ -9765,7 +9758,7 @@ function loadKeypairFromEnv() {
9765
9758
  try {
9766
9759
  const secretKey = secret.trim().startsWith("[")
9767
9760
  ? Uint8Array.from(JSON.parse(secret))
9768
- : bs58.decode(secret.trim());
9761
+ : bs58$2.decode(secret.trim());
9769
9762
  return web3_js.Keypair.fromSecretKey(secretKey);
9770
9763
  }
9771
9764
  catch (err) {
@@ -11710,28 +11703,6 @@ class ReactNativeSessionManager {
11710
11703
  /* STORE */
11711
11704
  /* ------------------------------------------------------------------ */
11712
11705
  static async storeSession(address, accessToken, idToken, refreshToken) {
11713
- // JWT-wallet binding: refuse to store a session whose idToken is bound
11714
- // to a different wallet than `address`. Prevents races that would otherwise
11715
- // leave storage with mismatched address/token state.
11716
- try {
11717
- const payloadB64 = idToken.split(".")[1];
11718
- if (payloadB64) {
11719
- const payload = JSON.parse(this.decodeBase64Url(payloadB64));
11720
- const tokenWallet = payload["custom:walletAddress"];
11721
- if (tokenWallet && tokenWallet !== address) {
11722
- throw new Error(`[ReactNativeSessionManager] Refusing to store session: address (${address}) does not match idToken custom:walletAddress (${tokenWallet})`);
11723
- }
11724
- if (!tokenWallet) {
11725
- console.warn("[ReactNativeSessionManager] storeSession: idToken has no custom:walletAddress claim — writing without validation");
11726
- }
11727
- }
11728
- }
11729
- catch (err) {
11730
- if (typeof (err === null || err === void 0 ? void 0 : err.message) === "string" && err.message.includes("Refusing to store session")) {
11731
- throw err;
11732
- }
11733
- console.warn("[ReactNativeSessionManager] storeSession: failed to decode idToken for validation:", err);
11734
- }
11735
11706
  const config = await getConfig();
11736
11707
  const currentAppId = config.appId;
11737
11708
  this.getStorage().setItem(this.TAROBASE_SESSION_STORAGE_KEY, JSON.stringify({
@@ -15730,7 +15701,7 @@ async function loadDependencies() {
15730
15701
  const [reactModule, reactDomModule, phantomModule] = await Promise.all([
15731
15702
  import('react'),
15732
15703
  import('react-dom/client'),
15733
- Promise.resolve().then(function () { return require('./index-BHkED2YI.js'); })
15704
+ Promise.resolve().then(function () { return require('./index-BKN0IwAx.js'); })
15734
15705
  ]);
15735
15706
  // Extract default export from ESM module namespace
15736
15707
  // Dynamic import() returns { default: Module, ...exports }, not the module directly
@@ -20388,16 +20359,26 @@ function requireSrc () {
20388
20359
  return src;
20389
20360
  }
20390
20361
 
20391
- var srcExports = requireSrc();
20392
- var basex = /*@__PURE__*/getDefaultExportFromCjs$1(srcExports);
20362
+ var bs58;
20363
+ var hasRequiredBs58;
20393
20364
 
20394
- var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
20395
- var base58 = basex(ALPHABET);
20365
+ function requireBs58 () {
20366
+ if (hasRequiredBs58) return bs58;
20367
+ hasRequiredBs58 = 1;
20368
+ var basex = requireSrc();
20369
+ var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
20370
+
20371
+ bs58 = basex(ALPHABET);
20372
+ return bs58;
20373
+ }
20374
+
20375
+ var bs58Exports = requireBs58();
20376
+ var base58 = /*@__PURE__*/getDefaultExportFromCjs$1(bs58Exports);
20396
20377
 
20397
- var index = /*#__PURE__*/Object.freeze({
20378
+ var index = /*#__PURE__*/_mergeNamespaces({
20398
20379
  __proto__: null,
20399
20380
  default: base58
20400
- });
20381
+ }, [bs58Exports]);
20401
20382
 
20402
20383
  const SURFNET_RPC_URL$1 = "https://surfpool.fly.dev";
20403
20384
  let React;
@@ -21286,6 +21267,14 @@ var privyWalletProvider = /*#__PURE__*/Object.freeze({
21286
21267
  PrivyWalletProvider: PrivyWalletProvider
21287
21268
  });
21288
21269
 
21270
+ /**
21271
+ * Storage key for persisting the MWA auth_token across cold starts.
21272
+ * Holds JSON `{ token: string, address: string }`. Cleared by
21273
+ * `logout()`. Hydrated by the constructor on native so cold-start
21274
+ * doesn't force the user back into Phantom's approval flow when the
21275
+ * underlying wallet authorization is still valid.
21276
+ */
21277
+ const MWA_AUTH_TOKEN_STORAGE_KEY = 'tarobase_mwa_auth_token';
21289
21278
  /**
21290
21279
  * Detects whether the current environment is a mobile browser capable of
21291
21280
  * Mobile Wallet Adapter (MWA) communication.
@@ -21780,7 +21769,7 @@ async function registerMobileWalletAdapter(config) {
21780
21769
  if (typeof window === 'undefined')
21781
21770
  return;
21782
21771
  try {
21783
- const walletStandardMobile = await Promise.resolve().then(function () { return require('./index.browser-DD8pg_L2.js'); });
21772
+ const walletStandardMobile = await Promise.resolve().then(function () { return require('./index.browser-DlA-NKvf.js'); });
21784
21773
  const registerMwa = walletStandardMobile.registerMwa || ((_a = walletStandardMobile.default) === null || _a === void 0 ? void 0 : _a.registerMwa);
21785
21774
  if (!registerMwa) {
21786
21775
  console.warn('[SolanaMobileWallet] registerMwa not found in @solana-mobile/wallet-standard-mobile');
@@ -21847,19 +21836,66 @@ class SolanaMobileWalletProvider {
21847
21836
  constructor(networkUrl = null, config = {}) {
21848
21837
  /** LocalSolanaMobileWalletAdapterWallet, lazy-constructed in ensureWallet(). */
21849
21838
  this.wallet = null;
21839
+ /**
21840
+ * Cached MWA auth_token returned by `wallet.authorize()`. Reused by
21841
+ * subsequent native transact() calls (signMessage / signTransaction)
21842
+ * so the user doesn't get the wallet-pick popup on every operation.
21843
+ * Persisted to platform storage and hydrated by the constructor on
21844
+ * native; cleared by logout() and on `ERROR_REAUTHORIZE`.
21845
+ */
21846
+ this.nativeAuthToken = null;
21847
+ /** Cached public key string for the connected MWA wallet (native). */
21848
+ this.nativeAddress = null;
21850
21849
  this.networkUrl = networkUrl;
21851
21850
  this.config = config;
21852
- if (typeof window === 'undefined') {
21851
+ // Allow construction in true React Native environments: getPlatform().hasDOM
21852
+ // is false there even though `typeof window === 'object'` (RN exposes a
21853
+ // partial window global). Web/PWA paths still keep their original guard:
21854
+ // they need real window+document for wallet-standard-mobile's deep-link
21855
+ // mechanism, so missing-window in those builds remains a fail-fast.
21856
+ const hasDOM = getPlatform().hasDOM;
21857
+ if (!hasDOM && typeof window === 'undefined') {
21858
+ throw new Error('SolanaMobileWalletProvider can only be instantiated in a browser or React Native environment');
21859
+ }
21860
+ if (hasDOM && typeof window === 'undefined') {
21853
21861
  throw new Error('SolanaMobileWalletProvider can only be instantiated in a browser environment');
21854
21862
  }
21855
21863
  if (SolanaMobileWalletProvider.instance) {
21856
21864
  return SolanaMobileWalletProvider.instance;
21857
21865
  }
21866
+ // `appIdentity.uri` is what Phantom Android (and other MWA wallets)
21867
+ // display in their approval modal. On web/PWA this is the page
21868
+ // origin; on native there's no `window.location`, so fall back to
21869
+ // a stable identifier the user can recognize. Apps can override
21870
+ // entirely via `config.appIdentity.uri`.
21871
+ const fallbackUri = hasDOM
21872
+ ? getPlatform().getLocationOrigin()
21873
+ : 'tarobase://app';
21858
21874
  this.appIdentity = config.appIdentity || {
21859
21875
  name: 'TaroBase App',
21860
- uri: getPlatform().getLocationOrigin(),
21876
+ uri: fallbackUri,
21861
21877
  };
21862
21878
  this.cluster = config.cluster || 'mainnet-beta';
21879
+ // Hydrate cached MWA auth_token from storage on native so we can
21880
+ // skip the wallet-pick popup after a cold-start when the underlying
21881
+ // wallet authorization is still valid. Sync storage call per the
21882
+ // PlatformAdapter contract; safe to swallow read errors (a fresh
21883
+ // login() just re-authorizes).
21884
+ if (!hasDOM) {
21885
+ try {
21886
+ const raw = getPlatform().storage.getItem(MWA_AUTH_TOKEN_STORAGE_KEY);
21887
+ if (raw) {
21888
+ const parsed = JSON.parse(raw);
21889
+ if (typeof parsed.token === 'string' && typeof parsed.address === 'string') {
21890
+ this.nativeAuthToken = parsed.token;
21891
+ this.nativeAddress = parsed.address;
21892
+ }
21893
+ }
21894
+ }
21895
+ catch (_a) {
21896
+ // Corrupt or unreadable cache — ignore. login() will re-auth.
21897
+ }
21898
+ }
21863
21899
  SolanaMobileWalletProvider.instance = this;
21864
21900
  }
21865
21901
  static getInstance(networkUrl, config) {
@@ -21872,7 +21908,7 @@ class SolanaMobileWalletProvider {
21872
21908
  async ensureWallet() {
21873
21909
  if (this.wallet)
21874
21910
  return this.wallet;
21875
- const mod = await Promise.resolve().then(function () { return require('./index.browser-DD8pg_L2.js'); });
21911
+ const mod = await Promise.resolve().then(function () { return require('./index.browser-DlA-NKvf.js'); });
21876
21912
  const chain = mapChainToWalletStandard(this.cluster);
21877
21913
  this.wallet = new mod.LocalSolanaMobileWalletAdapterWallet({
21878
21914
  appIdentity: this.appIdentity,
@@ -21922,6 +21958,134 @@ class SolanaMobileWalletProvider {
21922
21958
  getChain() {
21923
21959
  return mapChainToWalletStandard(this.cluster);
21924
21960
  }
21961
+ /**
21962
+ * Dynamically import and unwrap `transact` from the MWA web3js
21963
+ * package. The package is externalized in rollup.config.js so this
21964
+ * resolves to `lib/cjs/index.native.js` (TurboModule-backed) on
21965
+ * Metro and `lib/esm/index.browser.js` (WebSocket) on webpack/vite
21966
+ * per their respective platform conditions. Handles Metro's CJS-to-
21967
+ * ESM interop variance (`mod.transact` vs `mod.default?.transact`).
21968
+ */
21969
+ async loadTransact() {
21970
+ var _a;
21971
+ const mod = await import('@solana-mobile/mobile-wallet-adapter-protocol-web3js');
21972
+ const t = mod.transact || ((_a = mod.default) === null || _a === void 0 ? void 0 : _a.transact);
21973
+ if (typeof t !== 'function') {
21974
+ throw new Error('MWA transact API not available on this platform');
21975
+ }
21976
+ return t;
21977
+ }
21978
+ /**
21979
+ * Cache and persist a fresh MWA auth_token + address. Called from
21980
+ * `_loginNative` after a successful authorize. Storage failures are
21981
+ * non-fatal (next cold-start re-auths).
21982
+ */
21983
+ persistNativeAuth(token, address) {
21984
+ this.nativeAuthToken = token;
21985
+ this.nativeAddress = address;
21986
+ try {
21987
+ getPlatform().storage.setItem(MWA_AUTH_TOKEN_STORAGE_KEY, JSON.stringify({ token, address }));
21988
+ }
21989
+ catch (_a) {
21990
+ // non-fatal — token still in-memory for this process
21991
+ }
21992
+ }
21993
+ /** Clear cached + persisted native auth state. */
21994
+ clearNativeAuth() {
21995
+ this.nativeAuthToken = null;
21996
+ this.nativeAddress = null;
21997
+ try {
21998
+ getPlatform().storage.removeItem(MWA_AUTH_TOKEN_STORAGE_KEY);
21999
+ }
22000
+ catch (_a) {
22001
+ // ignore
22002
+ }
22003
+ }
22004
+ /**
22005
+ * Classify an MWA-native error as a user cancellation. User-cancel
22006
+ * shouldn't surface as a red console.error; callers can swallow or
22007
+ * show a softer message. MWA spec codes plus the same substring
22008
+ * checks the web path uses to catch wallet-specific phrasing.
22009
+ */
22010
+ isNativeUserCancel(err) {
22011
+ var _a;
22012
+ if (!err)
22013
+ return false;
22014
+ const code = err.code;
22015
+ if (code === 'ERROR_NOT_SIGNED')
22016
+ return true;
22017
+ const msg = String((_a = err.message) !== null && _a !== void 0 ? _a : '').toLowerCase();
22018
+ return /user (rejected|denied|cancelled|canceled|declined)/.test(msg);
22019
+ }
22020
+ /**
22021
+ * Native MWA login via @solana-mobile/mobile-wallet-adapter-protocol-web3js.
22022
+ * Used in true React Native (Expo) environments where wallet-standard-mobile's
22023
+ * web universal-link path doesn't apply. Does authorize + signMessage in a
22024
+ * single transact() roundtrip — intent-based MWA doesn't need the two-popup
22025
+ * dance the web path uses (no Chrome activation-loss concern). Persists the
22026
+ * resulting auth_token so cold-start can reauthorize without a fresh popup.
22027
+ */
22028
+ async _loginNative() {
22029
+ const transact = await this.loadTransact();
22030
+ const existingSession = await WebSessionManager.getSession();
22031
+ const nonce = await genAuthNonce();
22032
+ const result = await transact(async (wallet) => {
22033
+ const auth = await wallet.authorize({
22034
+ chain: this.getChain(),
22035
+ identity: this.appIdentity,
22036
+ });
22037
+ if (!auth.accounts || auth.accounts.length === 0) {
22038
+ throw new Error('MWA returned no accounts');
22039
+ }
22040
+ const account = auth.accounts[0];
22041
+ // account.address is base64-encoded per MWA spec; convert to
22042
+ // the base58 form Tarobase + the rest of the SDK use.
22043
+ const base58Addr = new web3_js.PublicKey(bufferExports.Buffer.from(account.address, 'base64')).toBase58();
22044
+ // Reuse session if already valid for this address — skip the
22045
+ // signMessages roundtrip entirely.
22046
+ if (existingSession && existingSession.address === base58Addr) {
22047
+ return {
22048
+ base58Addr,
22049
+ authToken: auth.auth_token,
22050
+ signatureBase64: null,
22051
+ };
22052
+ }
22053
+ const messageText = await genSolanaMessage(base58Addr, nonce);
22054
+ const messageBytes = getPlatform().textEncode(messageText);
22055
+ const signatures = await wallet.signMessages({
22056
+ addresses: [account.address],
22057
+ payloads: [messageBytes],
22058
+ });
22059
+ if (!signatures || signatures.length === 0) {
22060
+ throw new Error('MWA returned no signature');
22061
+ }
22062
+ // Per spec, signMessages returns Uint8Array[] of signatures
22063
+ // (one per payload), not message+signature concatenations.
22064
+ const signatureBase64 = bufferExports.Buffer.from(signatures[0]).toString('base64');
22065
+ return {
22066
+ base58Addr,
22067
+ authToken: auth.auth_token,
22068
+ signatureBase64,
22069
+ messageText,
22070
+ };
22071
+ });
22072
+ this.persistNativeAuth(result.authToken, result.base58Addr);
22073
+ // Existing valid session — short-circuit before re-creating server-side.
22074
+ if (existingSession && existingSession.address === result.base58Addr) {
22075
+ const user = { provider: this, address: result.base58Addr };
22076
+ setCurrentUser(user);
22077
+ return user;
22078
+ }
22079
+ // Create Tarobase session on the server.
22080
+ if (!result.signatureBase64 || !result.messageText) {
22081
+ throw new Error('MWA login completed without signature');
22082
+ }
22083
+ const createSessionResult = await createSessionWithSignature(result.base58Addr, result.messageText, result.signatureBase64);
22084
+ await WebSessionManager.storeSession(result.base58Addr, createSessionResult.accessToken, createSessionResult.idToken, createSessionResult.refreshToken);
22085
+ const user = { provider: this, address: result.base58Addr };
22086
+ setCurrentUser(user);
22087
+ return user;
22088
+ }
21925
22089
  async login() {
21926
22090
  var _a, _b, _c, _d, _e;
21927
22091
  setAuthLoading(true);
@@ -21932,6 +22096,13 @@ class SolanaMobileWalletProvider {
21932
22096
  const prevAuthMethod = readAuthMethod();
21933
22097
  writeAuthMethod(MWA_AUTH_METHOD);
21934
22098
  try {
22099
+ // True React Native: skip the wallet-standard-mobile path (which
22100
+ // requires window.isSecureContext and a real DOM) and use the raw
22101
+ // MWA protocol via Android intents.
22102
+ if (!getPlatform().hasDOM) {
22103
+ const user = await this._loginNative();
22104
+ return user;
22105
+ }
21935
22106
  const wallet = await this.ensureWallet();
21936
22107
  // Quick-check: wallet may already have authorization (e.g. from a
21937
22108
  // previous in-page login) and a matching Tarobase session — skip
@@ -22033,6 +22204,29 @@ class SolanaMobileWalletProvider {
22033
22204
  return null;
22034
22205
  }
22035
22206
  async logout() {
22207
+ if (!getPlatform().hasDOM) {
22208
+ // Native path: deauthorize the cached MWA auth_token if we have
22209
+ // one (failures non-fatal — the wallet app may have been
22210
+ // uninstalled or the token already revoked), then clear local
22211
+ // and persisted state.
22212
+ const token = this.nativeAuthToken;
22213
+ if (token) {
22214
+ try {
22215
+ const transact = await this.loadTransact();
22216
+ await transact(async (wallet) => {
22217
+ await wallet.deauthorize({ auth_token: token });
22218
+ });
22219
+ }
22220
+ catch (error) {
22221
+ console.warn('[SolanaMobileWallet] Native deauthorize error:', error);
22222
+ }
22223
+ }
22224
+ this.clearNativeAuth();
22225
+ WebSessionManager.clearSession();
22226
+ writeAuthMethod(null);
22227
+ setCurrentUser(null);
22228
+ return;
22229
+ }
22036
22230
  try {
22037
22231
  const wallet = await this.ensureWallet();
22038
22232
  const disconnectFeat = getDisconnectFeature(wallet);
@@ -22052,7 +22246,42 @@ class SolanaMobileWalletProvider {
22052
22246
  setCurrentUser(null);
22053
22247
  }
22054
22248
  async signMessage(message) {
22055
- var _a, _b;
22249
+ var _a, _b, _c;
22250
+ // Native: reauthorize with cached auth_token, then signMessages inside
22251
+ // the same transact() session. No wallet-pick popup if the auth_token
22252
+ // is still valid for the user's wallet.
22253
+ if (!getPlatform().hasDOM) {
22254
+ if (!this.nativeAuthToken || !this.nativeAddress) {
22255
+ throw new Error('Wallet not connected. Call login() first.');
22256
+ }
22257
+ const transact = await this.loadTransact();
22258
+ const messageBytes = getPlatform().textEncode(message);
22259
+ const addressBase64 = new web3_js.PublicKey(this.nativeAddress).toBuffer().toString('base64');
22260
+ const authToken = this.nativeAuthToken;
22261
+ try {
22262
+ const signature = await transact(async (wallet) => {
22263
+ await wallet.reauthorize({ auth_token: authToken, identity: this.appIdentity });
22264
+ const sigs = await wallet.signMessages({
22265
+ addresses: [addressBase64],
22266
+ payloads: [messageBytes],
22267
+ });
22268
+ if (!sigs || sigs.length === 0)
22269
+ throw new Error('MWA returned no signature');
22270
+ return sigs[0];
22271
+ });
22272
+ return bufferExports.Buffer.from(signature).toString('base64');
22273
+ }
22274
+ catch (error) {
22275
+ if (this.isNativeUserCancel(error)) {
22276
+ throw new Error('User declined to sign');
22277
+ }
22278
+ if ((error === null || error === void 0 ? void 0 : error.code) === 'ERROR_AUTHORIZATION_FAILED' || (error === null || error === void 0 ? void 0 : error.code) === 'ERROR_REAUTHORIZE') {
22279
+ await this.logout();
22280
+ throw new Error('Wallet connection lost. Please reconnect.');
22281
+ }
22282
+ throw new Error(`Failed to sign message: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
22283
+ }
22284
+ }
22056
22285
  const account = await this.ensureAuthorized();
22057
22286
  const wallet = await this.ensureWallet();
22058
22287
  try {
@@ -22066,7 +22295,7 @@ class SolanaMobileWalletProvider {
22066
22295
  return bufferExports.Buffer.from(sigBytes).toString('base64');
22067
22296
  }
22068
22297
  catch (error) {
22069
- 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')) ||
22298
+ 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')) ||
22070
22299
  (error === null || error === void 0 ? void 0 : error.code) === 'ERROR_AUTHORIZATION_FAILED') {
22071
22300
  await this.logout();
22072
22301
  throw new Error('Wallet connection lost. Please reconnect.');
@@ -22075,7 +22304,58 @@ class SolanaMobileWalletProvider {
22075
22304
  }
22076
22305
  }
22077
22306
  async signTransaction(transaction) {
22078
- var _a, _b;
22307
+ var _a, _b, _c;
22308
+ // Native: fill blockhash/feePayer if missing, then signTransactions
22309
+ // inside a transact() session keyed by the cached auth_token.
22310
+ if (!getPlatform().hasDOM) {
22311
+ if (!this.nativeAuthToken || !this.nativeAddress) {
22312
+ throw new Error('Wallet not connected. Call login() first.');
22313
+ }
22314
+ const connectedPubkey = new web3_js.PublicKey(this.nativeAddress);
22315
+ const isLegacyTransaction = 'recentBlockhash' in transaction && !('message' in transaction && 'staticAccountKeys' in transaction.message);
22316
+ if (isLegacyTransaction) {
22317
+ const legacyTx = transaction;
22318
+ if (!legacyTx.recentBlockhash) {
22319
+ const conn = new web3_js.Connection(this.getRpcUrl(), 'confirmed');
22320
+ const { blockhash, lastValidBlockHeight } = await conn.getLatestBlockhash('confirmed');
22321
+ legacyTx.recentBlockhash = blockhash;
22322
+ legacyTx.lastValidBlockHeight = lastValidBlockHeight;
22323
+ }
22324
+ if (!legacyTx.feePayer) {
22325
+ legacyTx.feePayer = connectedPubkey;
22326
+ }
22327
+ }
22328
+ else {
22329
+ const versionedTx = transaction;
22330
+ if (!versionedTx.message.recentBlockhash) {
22331
+ const conn = new web3_js.Connection(this.getRpcUrl(), 'confirmed');
22332
+ const { blockhash } = await conn.getLatestBlockhash('confirmed');
22333
+ versionedTx.message.recentBlockhash = blockhash;
22334
+ }
22335
+ }
22336
+ const transact = await this.loadTransact();
22337
+ const authToken = this.nativeAuthToken;
22338
+ try {
22339
+ const signed = await transact(async (wallet) => {
22340
+ await wallet.reauthorize({ auth_token: authToken, identity: this.appIdentity });
22341
+ const results = await wallet.signTransactions({ transactions: [transaction] });
22342
+ if (!results || results.length === 0)
22343
+ throw new Error('MWA returned no signed transaction');
22344
+ return results[0];
22345
+ });
22346
+ return signed;
22347
+ }
22348
+ catch (error) {
22349
+ if (this.isNativeUserCancel(error)) {
22350
+ throw new Error('User declined to sign');
22351
+ }
22352
+ if ((error === null || error === void 0 ? void 0 : error.code) === 'ERROR_AUTHORIZATION_FAILED' || (error === null || error === void 0 ? void 0 : error.code) === 'ERROR_REAUTHORIZE') {
22353
+ await this.logout();
22354
+ throw new Error('Wallet connection lost. Please reconnect.');
22355
+ }
22356
+ throw new Error(`Failed to sign transaction: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
22357
+ }
22358
+ }
22079
22359
  const account = await this.ensureAuthorized();
22080
22360
  const connectedPubkey = new web3_js.PublicKey(account.publicKey);
22081
22361
  const wallet = await this.ensureWallet();
@@ -22114,7 +22394,7 @@ class SolanaMobileWalletProvider {
22114
22394
  return txFromWireBytes(new Uint8Array(signedBytes));
22115
22395
  }
22116
22396
  catch (error) {
22117
- 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')) ||
22397
+ 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')) ||
22118
22398
  (error === null || error === void 0 ? void 0 : error.code) === 'ERROR_AUTHORIZATION_FAILED') {
22119
22399
  await this.logout();
22120
22400
  throw new Error('Wallet connection lost. Please reconnect.');
@@ -22123,7 +22403,70 @@ class SolanaMobileWalletProvider {
22123
22403
  }
22124
22404
  }
22125
22405
  async signAndSubmitTransaction(transaction, feePayer) {
22126
- var _a, _b, _c, _d, _e, _f;
22406
+ var _a, _b, _c, _d, _e, _f, _g;
22407
+ // Native: signAndSendTransactions inside a transact() session.
22408
+ // The wallet submits to its own RPC; we then await confirmation on
22409
+ // ours. Surfnet (custom RPC) needs manual submission because the
22410
+ // wallet won't route there — we fall back to sign-only + manual send.
22411
+ if (!getPlatform().hasDOM) {
22412
+ if (!this.nativeAuthToken || !this.nativeAddress) {
22413
+ throw new Error('Wallet not connected. Call login() first.');
22414
+ }
22415
+ const connectedPubkey = new web3_js.PublicKey(this.nativeAddress);
22416
+ const rpcUrl = this.getRpcUrl();
22417
+ const connection = new web3_js.Connection(rpcUrl, 'confirmed');
22418
+ const isSurfnet = rpcUrl === SURFNET_RPC_URL$2;
22419
+ const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash('confirmed');
22420
+ const isLegacyTransaction = 'recentBlockhash' in transaction && !('message' in transaction && 'staticAccountKeys' in transaction.message);
22421
+ if (isLegacyTransaction) {
22422
+ const legacyTx = transaction;
22423
+ legacyTx.recentBlockhash = blockhash;
22424
+ legacyTx.lastValidBlockHeight = lastValidBlockHeight;
22425
+ if (!legacyTx.feePayer)
22426
+ legacyTx.feePayer = feePayer !== null && feePayer !== void 0 ? feePayer : connectedPubkey;
22427
+ }
22428
+ else {
22429
+ const versionedTx = transaction;
22430
+ versionedTx.message.recentBlockhash = blockhash;
22431
+ }
22432
+ const transact = await this.loadTransact();
22433
+ const authToken = this.nativeAuthToken;
22434
+ try {
22435
+ if (isSurfnet) {
22436
+ // Surfnet: sign only, submit manually to Surfnet RPC
22437
+ // (the wallet would route signAndSend to its own RPC).
22438
+ const signed = await transact(async (wallet) => {
22439
+ await wallet.reauthorize({ auth_token: authToken, identity: this.appIdentity });
22440
+ const results = await wallet.signTransactions({ transactions: [transaction] });
22441
+ if (!results || results.length === 0)
22442
+ throw new Error('MWA returned no signed transaction');
22443
+ return results[0];
22444
+ });
22445
+ const sig = await connection.sendRawTransaction(signed.serialize(), { preflightCommitment: 'confirmed' });
22446
+ await confirmAndCheckTransaction(connection, sig);
22447
+ return sig;
22448
+ }
22449
+ const sig = await transact(async (wallet) => {
22450
+ await wallet.reauthorize({ auth_token: authToken, identity: this.appIdentity });
22451
+ const results = await wallet.signAndSendTransactions({ transactions: [transaction] });
22452
+ if (!results || results.length === 0)
22453
+ throw new Error('MWA returned no signature');
22454
+ return results[0];
22455
+ });
22456
+ await confirmAndCheckTransaction(connection, sig);
22457
+ return sig;
22458
+ }
22459
+ catch (error) {
22460
+ if (this.isNativeUserCancel(error)) {
22461
+ throw new Error('User declined to sign');
22462
+ }
22463
+ if ((error === null || error === void 0 ? void 0 : error.code) === 'ERROR_AUTHORIZATION_FAILED' || (error === null || error === void 0 ? void 0 : error.code) === 'ERROR_REAUTHORIZE') {
22464
+ await this.logout();
22465
+ throw new Error('Wallet connection lost. Please reconnect.');
22466
+ }
22467
+ throw new Error(`Failed to sign+submit transaction: ${(_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : error}`);
22468
+ }
22469
+ }
22127
22470
  const account = await this.ensureAuthorized();
22128
22471
  const connectedPubkey = new web3_js.PublicKey(account.publicKey);
22129
22472
  const wallet = await this.ensureWallet();
@@ -22190,16 +22533,16 @@ class SolanaMobileWalletProvider {
22190
22533
  return signature;
22191
22534
  }
22192
22535
  catch (error) {
22193
- 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')) ||
22536
+ 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')) ||
22194
22537
  (error === null || error === void 0 ? void 0 : error.code) === 'ERROR_AUTHORIZATION_FAILED') {
22195
22538
  await this.logout();
22196
22539
  throw new Error('Wallet connection lost. Please reconnect.');
22197
22540
  }
22198
22541
  const isUserRejection = (error === null || error === void 0 ? void 0 : error.code) === 4001 ||
22199
- ((_c = error === null || error === void 0 ? void 0 : error.message) === null || _c === void 0 ? void 0 : _c.toLowerCase().includes('user rejected')) ||
22200
- ((_d = error === null || error === void 0 ? void 0 : error.message) === null || _d === void 0 ? void 0 : _d.toLowerCase().includes('user denied')) ||
22201
- ((_e = error === null || error === void 0 ? void 0 : error.message) === null || _e === void 0 ? void 0 : _e.toLowerCase().includes('user cancelled')) ||
22202
- ((_f = error === null || error === void 0 ? void 0 : error.message) === null || _f === void 0 ? void 0 : _f.toLowerCase().includes('user canceled'));
22542
+ ((_d = error === null || error === void 0 ? void 0 : error.message) === null || _d === void 0 ? void 0 : _d.toLowerCase().includes('user rejected')) ||
22543
+ ((_e = error === null || error === void 0 ? void 0 : error.message) === null || _e === void 0 ? void 0 : _e.toLowerCase().includes('user denied')) ||
22544
+ ((_f = error === null || error === void 0 ? void 0 : error.message) === null || _f === void 0 ? void 0 : _f.toLowerCase().includes('user cancelled')) ||
22545
+ ((_g = error === null || error === void 0 ? void 0 : error.message) === null || _g === void 0 ? void 0 : _g.toLowerCase().includes('user canceled'));
22203
22546
  if (!isUserRejection) {
22204
22547
  console.error('[SolanaMobileWallet] Transaction failed:', error);
22205
22548
  }
@@ -22766,6 +23109,7 @@ exports.bufferExports = bufferExports;
22766
23109
  exports.buildSetDocumentsTransaction = buildSetDocumentsTransaction;
22767
23110
  exports.clearCache = clearCache;
22768
23111
  exports.closeAllSubscriptions = closeAllSubscriptions;
23112
+ exports.commonjsRequire = commonjsRequire;
22769
23113
  exports.convertRemainingAccounts = convertRemainingAccounts;
22770
23114
  exports.count = count;
22771
23115
  exports.createSessionWithPrivy = createSessionWithPrivy;
@@ -22793,6 +23137,7 @@ exports.onAuthStateChanged = onAuthStateChanged;
22793
23137
  exports.reconnectWithNewAuth = reconnectWithNewAuth;
22794
23138
  exports.refreshSession = refreshSession;
22795
23139
  exports.registerMobileWalletAdapter = registerMobileWalletAdapter;
23140
+ exports.require$$0 = require$$0;
22796
23141
  exports.runExpression = runExpression;
22797
23142
  exports.runExpressionMany = runExpressionMany;
22798
23143
  exports.runQuery = runQuery;
@@ -22807,4 +23152,4 @@ exports.signSessionCreateMessage = signSessionCreateMessage;
22807
23152
  exports.signTransaction = signTransaction;
22808
23153
  exports.subscribe = subscribe;
22809
23154
  exports.useAuth = useAuth;
22810
- //# sourceMappingURL=index-hEc5_KoM.js.map
23155
+ //# sourceMappingURL=index-Dj1tZr6X.js.map