@moon-x/react-native-sdk 0.13.1 → 0.14.1

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.
package/dist/ethereum.js CHANGED
@@ -165,6 +165,7 @@ var import_utils3 = require("@moon-x/core/utils");
165
165
 
166
166
  // src/provider.tsx
167
167
  var import_react2 = require("@moon-x/core/react");
168
+ var import_lib2 = require("@moon-x/core/lib");
168
169
  var import_jsx_runtime = require("react/jsx-runtime");
169
170
  var MoonXContext = (0, import_react.createContext)(null);
170
171
  var useMoonXContext = () => {
package/dist/ethereum.mjs CHANGED
@@ -23,6 +23,7 @@ import {
23
23
  useContext,
24
24
  useEffect,
25
25
  useMemo,
26
+ useReducer,
26
27
  useRef,
27
28
  useState
28
29
  } from "react";
@@ -163,6 +164,7 @@ import {
163
164
 
164
165
  // src/provider.tsx
165
166
  import { SDKProvider } from "@moon-x/core/react";
167
+ import { validatePublishableKey } from "@moon-x/core/lib";
166
168
  import { jsx, jsxs } from "react/jsx-runtime";
167
169
  var MoonXContext = createContext(null);
168
170
  var useMoonXContext = () => {
package/dist/index.d.mts CHANGED
@@ -3,7 +3,7 @@ import { RelyingPartyOriginInput } from '@moon-x/core/sdk';
3
3
  import { PostMessageType, PostMessageMethod } from '@moon-x/core/utils';
4
4
  export { PostMessageMethod, PostMessageType } from '@moon-x/core/utils';
5
5
  import * as _moon_x_core_types from '@moon-x/core/types';
6
- import { PublicWallet, PrepareFundingParams, FundingSession, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSendTransactionParams, EthereumSendTransactionResult, EthereumGetBalanceParams, EthereumGetBalanceResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaGetBalanceParams, SolanaGetBalanceResult, SolanaGetTokenAccountsByOwnerParams, SolanaGetTokenAccountsByOwnerResult, TronSignMessageParams, TronSignMessageResult, TronSignTransactionParams, TronSignTransactionResult, TronSendTransactionParams, TronSendTransactionResult, TronGetBalanceParams, TronGetBalanceResult, AppConfigResponse } from '@moon-x/core/types';
6
+ import { PublicWallet, WalletImportSource, PrepareFundingParams, FundingSession, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSendTransactionParams, EthereumSendTransactionResult, EthereumGetBalanceParams, EthereumGetBalanceResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaGetBalanceParams, SolanaGetBalanceResult, SolanaGetTokenAccountsByOwnerParams, SolanaGetTokenAccountsByOwnerResult, TronSignMessageParams, TronSignMessageResult, TronSignTransactionParams, TronSignTransactionResult, TronSendTransactionParams, TronSendTransactionResult, TronGetBalanceParams, TronGetBalanceResult, AppConfigResponse } from '@moon-x/core/types';
7
7
  export { Chain, EphemeralSigner, EphemeralSignerChain, EphemeralSignerScheme, EphemeralSignerWallet, EthereumGetBalanceParams, EthereumGetBalanceResult, EthereumSendTransactionParams, EthereumSendTransactionResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, FundingSession, ListEphemeralSignersResult, Network, PrepareFundingParams, ProvisionEphemeralSignerParams, ProvisionEphemeralSignerResult, PublicWallet, RevokeEphemeralSignerParams, SolanaGetBalanceParams, SolanaGetBalanceResult, SolanaGetTokenAccountsByOwnerParams, SolanaGetTokenAccountsByOwnerResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, TronGetBalanceParams, TronGetBalanceResult, TronSendTransactionParams, TronSendTransactionResult, TronSignMessageParams, TronSignMessageResult, TronSignTransactionParams, TronSignTransactionResult, TronTransactionJson, WalletConnectConfig } from '@moon-x/core/types';
8
8
  import * as _moon_x_core_react from '@moon-x/core/react';
9
9
  import { UseLoginWithEmailCallbacks } from '@moon-x/core/react';
@@ -11,6 +11,10 @@ export { LoginWithEmailState, UseEphemeralSignerResult, UseLoginWithEmailCallbac
11
11
  export { E as ExportKeyResult, u as useExportKey } from './use-export-key-BIz_tV0k.mjs';
12
12
  import { WalletConnectClientLike, WalletConnectSessionLike } from '@moon-x/core/lib';
13
13
 
14
+ type ResponseErrorListener = (error: Error, context: {
15
+ type: PostMessageType;
16
+ method: string;
17
+ }) => void;
14
18
  interface WebViewRefLike {
15
19
  injectJavaScript: (script: string) => void;
16
20
  }
@@ -24,15 +28,19 @@ declare class WebViewBridge {
24
28
  private webViewRef;
25
29
  private pending;
26
30
  private oneWayHandlers;
31
+ private responseErrorListeners;
27
32
  constructor(webViewRef: {
28
33
  current: WebViewRefLike | null;
29
34
  });
30
35
  handleMessage: (event: WebViewMessageEventLike) => void;
31
36
  register<Payload>(type: PostMessageType, method: PostMessageMethod | string, handler: IncomingMessageHandler<Payload>): () => void;
37
+ onResponseError(listener: ResponseErrorListener): () => void;
32
38
  isReady(): boolean;
33
39
  send<Payload, Response>(type: PostMessageType, method: PostMessageMethod | string, payload?: Payload): Promise<Response>;
34
40
  private sendOnce;
35
41
  sendOneWay<Payload>(type: PostMessageType, method: PostMessageMethod | string, payload?: Payload): void;
42
+ rejectAllPending(reason: string): void;
43
+ private rejectPending;
36
44
  cleanup(reason?: string): void;
37
45
  }
38
46
 
@@ -91,7 +99,7 @@ interface RNAuthSDK {
91
99
  }) => Promise<{
92
100
  wallet: PublicWallet;
93
101
  }>;
94
- importKey: (walletType: "solana" | "ethereum" | "tron", key: string) => Promise<{
102
+ importKey: (walletType: "solana" | "ethereum" | "tron", source: string | WalletImportSource) => Promise<{
95
103
  wallet: PublicWallet;
96
104
  }>;
97
105
  getWallets: (walletType: "solana" | "ethereum" | "tron") => Promise<{
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import { RelyingPartyOriginInput } from '@moon-x/core/sdk';
3
3
  import { PostMessageType, PostMessageMethod } from '@moon-x/core/utils';
4
4
  export { PostMessageMethod, PostMessageType } from '@moon-x/core/utils';
5
5
  import * as _moon_x_core_types from '@moon-x/core/types';
6
- import { PublicWallet, PrepareFundingParams, FundingSession, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSendTransactionParams, EthereumSendTransactionResult, EthereumGetBalanceParams, EthereumGetBalanceResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaGetBalanceParams, SolanaGetBalanceResult, SolanaGetTokenAccountsByOwnerParams, SolanaGetTokenAccountsByOwnerResult, TronSignMessageParams, TronSignMessageResult, TronSignTransactionParams, TronSignTransactionResult, TronSendTransactionParams, TronSendTransactionResult, TronGetBalanceParams, TronGetBalanceResult, AppConfigResponse } from '@moon-x/core/types';
6
+ import { PublicWallet, WalletImportSource, PrepareFundingParams, FundingSession, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSendTransactionParams, EthereumSendTransactionResult, EthereumGetBalanceParams, EthereumGetBalanceResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaGetBalanceParams, SolanaGetBalanceResult, SolanaGetTokenAccountsByOwnerParams, SolanaGetTokenAccountsByOwnerResult, TronSignMessageParams, TronSignMessageResult, TronSignTransactionParams, TronSignTransactionResult, TronSendTransactionParams, TronSendTransactionResult, TronGetBalanceParams, TronGetBalanceResult, AppConfigResponse } from '@moon-x/core/types';
7
7
  export { Chain, EphemeralSigner, EphemeralSignerChain, EphemeralSignerScheme, EphemeralSignerWallet, EthereumGetBalanceParams, EthereumGetBalanceResult, EthereumSendTransactionParams, EthereumSendTransactionResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, FundingSession, ListEphemeralSignersResult, Network, PrepareFundingParams, ProvisionEphemeralSignerParams, ProvisionEphemeralSignerResult, PublicWallet, RevokeEphemeralSignerParams, SolanaGetBalanceParams, SolanaGetBalanceResult, SolanaGetTokenAccountsByOwnerParams, SolanaGetTokenAccountsByOwnerResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, TronGetBalanceParams, TronGetBalanceResult, TronSendTransactionParams, TronSendTransactionResult, TronSignMessageParams, TronSignMessageResult, TronSignTransactionParams, TronSignTransactionResult, TronTransactionJson, WalletConnectConfig } from '@moon-x/core/types';
8
8
  import * as _moon_x_core_react from '@moon-x/core/react';
9
9
  import { UseLoginWithEmailCallbacks } from '@moon-x/core/react';
@@ -11,6 +11,10 @@ export { LoginWithEmailState, UseEphemeralSignerResult, UseLoginWithEmailCallbac
11
11
  export { E as ExportKeyResult, u as useExportKey } from './use-export-key-BIz_tV0k.js';
12
12
  import { WalletConnectClientLike, WalletConnectSessionLike } from '@moon-x/core/lib';
13
13
 
14
+ type ResponseErrorListener = (error: Error, context: {
15
+ type: PostMessageType;
16
+ method: string;
17
+ }) => void;
14
18
  interface WebViewRefLike {
15
19
  injectJavaScript: (script: string) => void;
16
20
  }
@@ -24,15 +28,19 @@ declare class WebViewBridge {
24
28
  private webViewRef;
25
29
  private pending;
26
30
  private oneWayHandlers;
31
+ private responseErrorListeners;
27
32
  constructor(webViewRef: {
28
33
  current: WebViewRefLike | null;
29
34
  });
30
35
  handleMessage: (event: WebViewMessageEventLike) => void;
31
36
  register<Payload>(type: PostMessageType, method: PostMessageMethod | string, handler: IncomingMessageHandler<Payload>): () => void;
37
+ onResponseError(listener: ResponseErrorListener): () => void;
32
38
  isReady(): boolean;
33
39
  send<Payload, Response>(type: PostMessageType, method: PostMessageMethod | string, payload?: Payload): Promise<Response>;
34
40
  private sendOnce;
35
41
  sendOneWay<Payload>(type: PostMessageType, method: PostMessageMethod | string, payload?: Payload): void;
42
+ rejectAllPending(reason: string): void;
43
+ private rejectPending;
36
44
  cleanup(reason?: string): void;
37
45
  }
38
46
 
@@ -91,7 +99,7 @@ interface RNAuthSDK {
91
99
  }) => Promise<{
92
100
  wallet: PublicWallet;
93
101
  }>;
94
- importKey: (walletType: "solana" | "ethereum" | "tron", key: string) => Promise<{
102
+ importKey: (walletType: "solana" | "ethereum" | "tron", source: string | WalletImportSource) => Promise<{
95
103
  wallet: PublicWallet;
96
104
  }>;
97
105
  getWallets: (walletType: "solana" | "ethereum" | "tron") => Promise<{
package/dist/index.js CHANGED
@@ -484,6 +484,7 @@ var WebViewBridge = class {
484
484
  constructor(webViewRef) {
485
485
  this.pending = /* @__PURE__ */ new Map();
486
486
  this.oneWayHandlers = /* @__PURE__ */ new Map();
487
+ this.responseErrorListeners = /* @__PURE__ */ new Set();
487
488
  // Wire to <WebView onMessage={bridge.handleMessage}>. Demultiplexes
488
489
  // by request id; one-way messages (no id, or unknown id) fall through
489
490
  // to handlers registered via `register`.
@@ -510,6 +511,12 @@ var WebViewBridge = class {
510
511
  err[key] = value;
511
512
  }
512
513
  }
514
+ for (const listener of this.responseErrorListeners) {
515
+ try {
516
+ listener(err, { type: resolver.type, method: resolver.method });
517
+ } catch {
518
+ }
519
+ }
513
520
  resolver.reject(err);
514
521
  }
515
522
  return;
@@ -532,6 +539,15 @@ var WebViewBridge = class {
532
539
  }
533
540
  };
534
541
  }
542
+ // Subscribe to structured request rejections from the iframe-app.
543
+ // Returns an unsubscribe fn. Timeouts and local failures are NOT
544
+ // reported — only errors the iframe-app deliberately sent back.
545
+ onResponseError(listener) {
546
+ this.responseErrorListeners.add(listener);
547
+ return () => {
548
+ this.responseErrorListeners.delete(listener);
549
+ };
550
+ }
535
551
  // Conforms to the `Transport.isReady()` half of @moon-x/core/sdk's
536
552
  // interface — used by shared SDK factories to short-circuit before
537
553
  // attempting to inject JS into a not-yet-mounted WebView.
@@ -586,7 +602,9 @@ var WebViewBridge = class {
586
602
  this.pending.set(id, {
587
603
  resolve,
588
604
  reject,
589
- timeoutId
605
+ timeoutId,
606
+ type,
607
+ method
590
608
  });
591
609
  const envelope = { id, type, method, payload };
592
610
  try {
@@ -612,20 +630,62 @@ var WebViewBridge = class {
612
630
  } catch {
613
631
  }
614
632
  }
615
- // Reject every outstanding request — wire on unmount so dangling
616
- // promises don't dangle forever.
617
- cleanup(reason = "webview_unmounted") {
633
+ // Reject every outstanding request without touching registrations.
634
+ // Used when the WebView's web process dies and the page reloads: the
635
+ // in-flight requests can never be answered, but the one-way handlers
636
+ // and error listeners belong to still-mounted React effects and must
637
+ // survive the reload.
638
+ //
639
+ // Rejects with TimeoutError deliberately: "the reply will never come"
640
+ // is exactly what TimeoutError models, and it lets `send`'s retry loop
641
+ // re-send idempotent reads (RETRYABLE_METHODS) against the reloaded
642
+ // page instead of surfacing a one-off hard error. Mutating methods
643
+ // still fail fast, as they must — the request may or may not have
644
+ // been processed before the process died.
645
+ rejectAllPending(reason) {
646
+ this.rejectPending(() => new TimeoutError(reason));
647
+ }
648
+ rejectPending(createError) {
618
649
  for (const [id, resolver] of this.pending.entries()) {
619
650
  clearTimeout(resolver.timeoutId);
620
- resolver.reject(new Error(reason));
651
+ resolver.reject(createError());
621
652
  this.pending.delete(id);
622
653
  }
654
+ }
655
+ // Reject every outstanding request — wire on unmount so dangling
656
+ // promises don't dangle forever. Unmount is definitive, so use a plain
657
+ // Error rather than the retryable TimeoutError used for process death.
658
+ cleanup(reason = "webview_unmounted") {
659
+ this.rejectPending(() => new Error(reason));
623
660
  this.oneWayHandlers.clear();
661
+ this.responseErrorListeners.clear();
624
662
  }
625
663
  };
626
664
 
627
665
  // src/provider.tsx
628
666
  var import_react2 = require("@moon-x/core/react");
667
+ var import_lib2 = require("@moon-x/core/lib");
668
+
669
+ // src/webview-lifecycle.ts
670
+ var initialWebViewLifecycleState = {
671
+ ready: false,
672
+ recoveryNonce: 0,
673
+ key: 0
674
+ };
675
+ var webViewLifecycleReducer = (state, action) => {
676
+ switch (action.type) {
677
+ case "ready":
678
+ return state.ready ? state : { ...state, ready: true };
679
+ case "recover":
680
+ return {
681
+ ready: false,
682
+ recoveryNonce: state.recoveryNonce + 1,
683
+ key: state.key + (action.remount ? 1 : 0)
684
+ };
685
+ }
686
+ };
687
+
688
+ // src/provider.tsx
629
689
  var import_jsx_runtime = require("react/jsx-runtime");
630
690
  var DEFAULT_IFRAME_URL = "https://iframe.moonx-dev.com";
631
691
  var MoonXContext = (0, import_react.createContext)(null);
@@ -634,6 +694,7 @@ var MoonXProvider = ({
634
694
  config,
635
695
  children
636
696
  }) => {
697
+ (0, import_lib2.validatePublishableKey)(publishableKey);
637
698
  const iframeUrl = config?.iframeUrl ?? DEFAULT_IFRAME_URL;
638
699
  const relyingPartyOrigin = config?.relyingPartyOrigin ?? "";
639
700
  const webViewRef = (0, import_react.useRef)(null);
@@ -649,7 +710,14 @@ var MoonXProvider = ({
649
710
  );
650
711
  const [sensitiveVisible, setSensitiveVisible] = (0, import_react.useState)(false);
651
712
  const cancelRef = (0, import_react.useRef)(null);
652
- const [ready, setReady] = (0, import_react.useState)(false);
713
+ const [
714
+ {
715
+ ready,
716
+ recoveryNonce: webViewRecoveryNonce,
717
+ key: webViewKey
718
+ },
719
+ dispatchWebViewLifecycle
720
+ ] = (0, import_react.useReducer)(webViewLifecycleReducer, initialWebViewLifecycleState);
653
721
  const [isAuthenticated, setIsAuthenticated] = (0, import_react.useState)(false);
654
722
  const [user, setUser] = (0, import_react.useState)(null);
655
723
  const [revalidatedAt, setRevalidatedAt] = (0, import_react.useState)(0);
@@ -809,24 +877,34 @@ var MoonXProvider = ({
809
877
  bridge.cleanup("provider_unmounted");
810
878
  };
811
879
  }, [bridge]);
880
+ (0, import_react.useEffect)(() => {
881
+ const unsubscribe = bridge.onResponseError((error) => {
882
+ if (error.message !== "no_session") return;
883
+ if (authFlowsInFlightRef.current > 0) return;
884
+ setIsAuthenticated(false);
885
+ setUser(null);
886
+ setRestoreNonce((value) => value + 1);
887
+ });
888
+ return unsubscribe;
889
+ }, [bridge]);
812
890
  (0, import_react.useEffect)(() => {
813
891
  let cancelled = false;
814
892
  const unregister = bridge.register(
815
893
  import_utils4.PostMessageType.INIT,
816
894
  import_utils4.PostMessageMethod.READY,
817
895
  () => {
818
- if (!cancelled) setReady(true);
896
+ if (!cancelled) dispatchWebViewLifecycle({ type: "ready" });
819
897
  }
820
898
  );
821
899
  const fallback = setTimeout(() => {
822
- if (!cancelled) setReady(true);
900
+ if (!cancelled) dispatchWebViewLifecycle({ type: "ready" });
823
901
  }, 2e3);
824
902
  return () => {
825
903
  cancelled = true;
826
904
  unregister();
827
905
  clearTimeout(fallback);
828
906
  };
829
- }, [bridge]);
907
+ }, [bridge, webViewRecoveryNonce]);
830
908
  (0, import_react.useEffect)(() => {
831
909
  if (!ready) return;
832
910
  let cancelled = false;
@@ -947,6 +1025,15 @@ var MoonXProvider = ({
947
1025
  ref: webViewRef,
948
1026
  source: { uri: initialSourceUri },
949
1027
  onMessage: handleMessage,
1028
+ onContentProcessDidTerminate: () => {
1029
+ dispatchWebViewLifecycle({ type: "recover", remount: false });
1030
+ bridge.rejectAllPending("webview_process_terminated");
1031
+ webViewRef.current?.reload();
1032
+ },
1033
+ onRenderProcessGone: () => {
1034
+ dispatchWebViewLifecycle({ type: "recover", remount: true });
1035
+ bridge.rejectAllPending("webview_process_terminated");
1036
+ },
950
1037
  webviewDebuggingEnabled: __DEV__,
951
1038
  javaScriptEnabled: true,
952
1039
  domStorageEnabled: true,
@@ -955,7 +1042,8 @@ var MoonXProvider = ({
955
1042
  startInLoadingState: false,
956
1043
  originWhitelist: ["https://*", "http://*"],
957
1044
  style: styles.webView
958
- }
1045
+ },
1046
+ webViewKey
959
1047
  )
960
1048
  ]
961
1049
  }
@@ -1439,7 +1527,7 @@ var useExternalWallets = (connectors) => {
1439
1527
  };
1440
1528
 
1441
1529
  // src/external-wallets/wallet-connect.ts
1442
- var import_lib2 = require("@moon-x/core/lib");
1530
+ var import_lib3 = require("@moon-x/core/lib");
1443
1531
  var DEFAULT_REQUIRED_NAMESPACES = {
1444
1532
  eip155: {
1445
1533
  chains: ["eip155:1"],
@@ -1483,7 +1571,7 @@ var createConnection = ({
1483
1571
  chain,
1484
1572
  address
1485
1573
  }) => {
1486
- let accounts = (0, import_lib2.getWalletConnectAccounts)(session).map(toExternalAccount).filter((account) => account !== null);
1574
+ let accounts = (0, import_lib3.getWalletConnectAccounts)(session).map(toExternalAccount).filter((account) => account !== null);
1487
1575
  if (chain) accounts = accounts.filter((account) => account.chain === chain);
1488
1576
  if (accounts.length === 0) {
1489
1577
  throw new Error("WalletConnect session has no supported accounts");
@@ -1506,7 +1594,7 @@ var createConnection = ({
1506
1594
  activeAccount: active,
1507
1595
  request: async (method, params, chainId) => {
1508
1596
  const account = requireActiveAccount();
1509
- return (0, import_lib2.requestWalletConnect)(client, {
1597
+ return (0, import_lib3.requestWalletConnect)(client, {
1510
1598
  topic: session.topic,
1511
1599
  chainId: chainId ?? account.chainId ?? "eip155:1",
1512
1600
  method,
@@ -1520,7 +1608,7 @@ var createConnection = ({
1520
1608
  "Use request() with the wallet's supported Solana signing method"
1521
1609
  );
1522
1610
  }
1523
- return (0, import_lib2.requestWalletConnect)(client, {
1611
+ return (0, import_lib3.requestWalletConnect)(client, {
1524
1612
  topic: session.topic,
1525
1613
  chainId: account.chainId ?? "eip155:1",
1526
1614
  method: "personal_sign",
@@ -1535,7 +1623,7 @@ var createConnection = ({
1535
1623
  if (account.chain !== "ethereum") {
1536
1624
  throw new Error("Typed-data signing is only available for Ethereum");
1537
1625
  }
1538
- return (0, import_lib2.requestWalletConnect)(client, {
1626
+ return (0, import_lib3.requestWalletConnect)(client, {
1539
1627
  topic: session.topic,
1540
1628
  chainId: account.chainId ?? "eip155:1",
1541
1629
  method: "eth_signTypedData_v4",
@@ -1549,7 +1637,7 @@ var createConnection = ({
1549
1637
  "Use request() with the wallet's supported Solana signing method"
1550
1638
  );
1551
1639
  }
1552
- return (0, import_lib2.requestWalletConnect)(client, {
1640
+ return (0, import_lib3.requestWalletConnect)(client, {
1553
1641
  topic: session.topic,
1554
1642
  chainId: account.chainId ?? "eip155:1",
1555
1643
  method: "eth_signTransaction",
@@ -1563,7 +1651,7 @@ var createConnection = ({
1563
1651
  "Use request() with the wallet's supported Solana send method"
1564
1652
  );
1565
1653
  }
1566
- return (0, import_lib2.requestWalletConnect)(client, {
1654
+ return (0, import_lib3.requestWalletConnect)(client, {
1567
1655
  topic: session.topic,
1568
1656
  chainId: account.chainId ?? "eip155:1",
1569
1657
  method: "eth_sendTransaction",
@@ -1589,7 +1677,7 @@ var createConnection = ({
1589
1677
  disconnect: async () => {
1590
1678
  cleanup();
1591
1679
  publish([]);
1592
- await (0, import_lib2.disconnectWalletConnectSession)(client, session.topic);
1680
+ await (0, import_lib3.disconnectWalletConnectSession)(client, session.topic);
1593
1681
  },
1594
1682
  raw: { client, session }
1595
1683
  };
@@ -1611,7 +1699,7 @@ var createConnection = ({
1611
1699
  if (event.topic !== session.topic || !event.params?.namespaces) return;
1612
1700
  session.namespaces = event.params.namespaces;
1613
1701
  publish(
1614
- (0, import_lib2.getWalletConnectAccounts)(session).map(toExternalAccount).filter((account) => account !== null)
1702
+ (0, import_lib3.getWalletConnectAccounts)(session).map(toExternalAccount).filter((account) => account !== null)
1615
1703
  );
1616
1704
  };
1617
1705
  const onSessionEvent = (event) => {
@@ -1628,13 +1716,13 @@ var createConnection = ({
1628
1716
  publish([]);
1629
1717
  return;
1630
1718
  }
1631
- const approvedAccounts = (0, import_lib2.getWalletConnectAccounts)(session).map(toExternalAccount).filter(
1719
+ const approvedAccounts = (0, import_lib3.getWalletConnectAccounts)(session).map(toExternalAccount).filter(
1632
1720
  (account) => account !== null && (!chain || account.chain === chain)
1633
1721
  );
1634
1722
  const eventChainId = event.params.chainId;
1635
1723
  const next = values.map((value) => {
1636
1724
  if (value.includes(":")) {
1637
- const parsed = (0, import_lib2.parseWalletConnectAccount)(value);
1725
+ const parsed = (0, import_lib3.parseWalletConnectAccount)(value);
1638
1726
  const candidate = parsed ? toExternalAccount(parsed) : null;
1639
1727
  if (!candidate || eventChainId && candidate.chainId !== eventChainId) {
1640
1728
  return null;
@@ -1671,7 +1759,7 @@ var createConnection = ({
1671
1759
  return connection;
1672
1760
  };
1673
1761
  var connectWalletConnect = async (options) => {
1674
- const { uri, approval } = await (0, import_lib2.beginWalletConnectSession)(options.client, {
1762
+ const { uri, approval } = await (0, import_lib3.beginWalletConnectSession)(options.client, {
1675
1763
  requiredNamespaces: options.requiredNamespaces ?? DEFAULT_REQUIRED_NAMESPACES,
1676
1764
  optionalNamespaces: options.optionalNamespaces
1677
1765
  });
package/dist/index.mjs CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  useContext,
6
6
  useEffect,
7
7
  useMemo,
8
+ useReducer,
8
9
  useRef,
9
10
  useState
10
11
  } from "react";
@@ -453,6 +454,7 @@ var WebViewBridge = class {
453
454
  constructor(webViewRef) {
454
455
  this.pending = /* @__PURE__ */ new Map();
455
456
  this.oneWayHandlers = /* @__PURE__ */ new Map();
457
+ this.responseErrorListeners = /* @__PURE__ */ new Set();
456
458
  // Wire to <WebView onMessage={bridge.handleMessage}>. Demultiplexes
457
459
  // by request id; one-way messages (no id, or unknown id) fall through
458
460
  // to handlers registered via `register`.
@@ -479,6 +481,12 @@ var WebViewBridge = class {
479
481
  err[key] = value;
480
482
  }
481
483
  }
484
+ for (const listener of this.responseErrorListeners) {
485
+ try {
486
+ listener(err, { type: resolver.type, method: resolver.method });
487
+ } catch {
488
+ }
489
+ }
482
490
  resolver.reject(err);
483
491
  }
484
492
  return;
@@ -501,6 +509,15 @@ var WebViewBridge = class {
501
509
  }
502
510
  };
503
511
  }
512
+ // Subscribe to structured request rejections from the iframe-app.
513
+ // Returns an unsubscribe fn. Timeouts and local failures are NOT
514
+ // reported — only errors the iframe-app deliberately sent back.
515
+ onResponseError(listener) {
516
+ this.responseErrorListeners.add(listener);
517
+ return () => {
518
+ this.responseErrorListeners.delete(listener);
519
+ };
520
+ }
504
521
  // Conforms to the `Transport.isReady()` half of @moon-x/core/sdk's
505
522
  // interface — used by shared SDK factories to short-circuit before
506
523
  // attempting to inject JS into a not-yet-mounted WebView.
@@ -555,7 +572,9 @@ var WebViewBridge = class {
555
572
  this.pending.set(id, {
556
573
  resolve,
557
574
  reject,
558
- timeoutId
575
+ timeoutId,
576
+ type,
577
+ method
559
578
  });
560
579
  const envelope = { id, type, method, payload };
561
580
  try {
@@ -581,20 +600,62 @@ var WebViewBridge = class {
581
600
  } catch {
582
601
  }
583
602
  }
584
- // Reject every outstanding request — wire on unmount so dangling
585
- // promises don't dangle forever.
586
- cleanup(reason = "webview_unmounted") {
603
+ // Reject every outstanding request without touching registrations.
604
+ // Used when the WebView's web process dies and the page reloads: the
605
+ // in-flight requests can never be answered, but the one-way handlers
606
+ // and error listeners belong to still-mounted React effects and must
607
+ // survive the reload.
608
+ //
609
+ // Rejects with TimeoutError deliberately: "the reply will never come"
610
+ // is exactly what TimeoutError models, and it lets `send`'s retry loop
611
+ // re-send idempotent reads (RETRYABLE_METHODS) against the reloaded
612
+ // page instead of surfacing a one-off hard error. Mutating methods
613
+ // still fail fast, as they must — the request may or may not have
614
+ // been processed before the process died.
615
+ rejectAllPending(reason) {
616
+ this.rejectPending(() => new TimeoutError(reason));
617
+ }
618
+ rejectPending(createError) {
587
619
  for (const [id, resolver] of this.pending.entries()) {
588
620
  clearTimeout(resolver.timeoutId);
589
- resolver.reject(new Error(reason));
621
+ resolver.reject(createError());
590
622
  this.pending.delete(id);
591
623
  }
624
+ }
625
+ // Reject every outstanding request — wire on unmount so dangling
626
+ // promises don't dangle forever. Unmount is definitive, so use a plain
627
+ // Error rather than the retryable TimeoutError used for process death.
628
+ cleanup(reason = "webview_unmounted") {
629
+ this.rejectPending(() => new Error(reason));
592
630
  this.oneWayHandlers.clear();
631
+ this.responseErrorListeners.clear();
593
632
  }
594
633
  };
595
634
 
596
635
  // src/provider.tsx
597
636
  import { SDKProvider } from "@moon-x/core/react";
637
+ import { validatePublishableKey } from "@moon-x/core/lib";
638
+
639
+ // src/webview-lifecycle.ts
640
+ var initialWebViewLifecycleState = {
641
+ ready: false,
642
+ recoveryNonce: 0,
643
+ key: 0
644
+ };
645
+ var webViewLifecycleReducer = (state, action) => {
646
+ switch (action.type) {
647
+ case "ready":
648
+ return state.ready ? state : { ...state, ready: true };
649
+ case "recover":
650
+ return {
651
+ ready: false,
652
+ recoveryNonce: state.recoveryNonce + 1,
653
+ key: state.key + (action.remount ? 1 : 0)
654
+ };
655
+ }
656
+ };
657
+
658
+ // src/provider.tsx
598
659
  import { jsx, jsxs } from "react/jsx-runtime";
599
660
  var DEFAULT_IFRAME_URL = "https://iframe.moonx-dev.com";
600
661
  var MoonXContext = createContext(null);
@@ -603,6 +664,7 @@ var MoonXProvider = ({
603
664
  config,
604
665
  children
605
666
  }) => {
667
+ validatePublishableKey(publishableKey);
606
668
  const iframeUrl = config?.iframeUrl ?? DEFAULT_IFRAME_URL;
607
669
  const relyingPartyOrigin = config?.relyingPartyOrigin ?? "";
608
670
  const webViewRef = useRef(null);
@@ -618,7 +680,14 @@ var MoonXProvider = ({
618
680
  );
619
681
  const [sensitiveVisible, setSensitiveVisible] = useState(false);
620
682
  const cancelRef = useRef(null);
621
- const [ready, setReady] = useState(false);
683
+ const [
684
+ {
685
+ ready,
686
+ recoveryNonce: webViewRecoveryNonce,
687
+ key: webViewKey
688
+ },
689
+ dispatchWebViewLifecycle
690
+ ] = useReducer(webViewLifecycleReducer, initialWebViewLifecycleState);
622
691
  const [isAuthenticated, setIsAuthenticated] = useState(false);
623
692
  const [user, setUser] = useState(null);
624
693
  const [revalidatedAt, setRevalidatedAt] = useState(0);
@@ -778,24 +847,34 @@ var MoonXProvider = ({
778
847
  bridge.cleanup("provider_unmounted");
779
848
  };
780
849
  }, [bridge]);
850
+ useEffect(() => {
851
+ const unsubscribe = bridge.onResponseError((error) => {
852
+ if (error.message !== "no_session") return;
853
+ if (authFlowsInFlightRef.current > 0) return;
854
+ setIsAuthenticated(false);
855
+ setUser(null);
856
+ setRestoreNonce((value) => value + 1);
857
+ });
858
+ return unsubscribe;
859
+ }, [bridge]);
781
860
  useEffect(() => {
782
861
  let cancelled = false;
783
862
  const unregister = bridge.register(
784
863
  PostMessageType3.INIT,
785
864
  PostMessageMethod3.READY,
786
865
  () => {
787
- if (!cancelled) setReady(true);
866
+ if (!cancelled) dispatchWebViewLifecycle({ type: "ready" });
788
867
  }
789
868
  );
790
869
  const fallback = setTimeout(() => {
791
- if (!cancelled) setReady(true);
870
+ if (!cancelled) dispatchWebViewLifecycle({ type: "ready" });
792
871
  }, 2e3);
793
872
  return () => {
794
873
  cancelled = true;
795
874
  unregister();
796
875
  clearTimeout(fallback);
797
876
  };
798
- }, [bridge]);
877
+ }, [bridge, webViewRecoveryNonce]);
799
878
  useEffect(() => {
800
879
  if (!ready) return;
801
880
  let cancelled = false;
@@ -916,6 +995,15 @@ var MoonXProvider = ({
916
995
  ref: webViewRef,
917
996
  source: { uri: initialSourceUri },
918
997
  onMessage: handleMessage,
998
+ onContentProcessDidTerminate: () => {
999
+ dispatchWebViewLifecycle({ type: "recover", remount: false });
1000
+ bridge.rejectAllPending("webview_process_terminated");
1001
+ webViewRef.current?.reload();
1002
+ },
1003
+ onRenderProcessGone: () => {
1004
+ dispatchWebViewLifecycle({ type: "recover", remount: true });
1005
+ bridge.rejectAllPending("webview_process_terminated");
1006
+ },
919
1007
  webviewDebuggingEnabled: __DEV__,
920
1008
  javaScriptEnabled: true,
921
1009
  domStorageEnabled: true,
@@ -924,7 +1012,8 @@ var MoonXProvider = ({
924
1012
  startInLoadingState: false,
925
1013
  originWhitelist: ["https://*", "http://*"],
926
1014
  style: styles.webView
927
- }
1015
+ },
1016
+ webViewKey
928
1017
  )
929
1018
  ]
930
1019
  }
package/dist/solana.js CHANGED
@@ -163,6 +163,7 @@ var import_utils3 = require("@moon-x/core/utils");
163
163
 
164
164
  // src/provider.tsx
165
165
  var import_react2 = require("@moon-x/core/react");
166
+ var import_lib2 = require("@moon-x/core/lib");
166
167
  var import_jsx_runtime = require("react/jsx-runtime");
167
168
  var MoonXContext = (0, import_react.createContext)(null);
168
169
  var useMoonXContext = () => {
package/dist/solana.mjs CHANGED
@@ -21,6 +21,7 @@ import {
21
21
  useContext,
22
22
  useEffect,
23
23
  useMemo,
24
+ useReducer,
24
25
  useRef,
25
26
  useState
26
27
  } from "react";
@@ -161,6 +162,7 @@ import {
161
162
 
162
163
  // src/provider.tsx
163
164
  import { SDKProvider } from "@moon-x/core/react";
165
+ import { validatePublishableKey } from "@moon-x/core/lib";
164
166
  import { jsx, jsxs } from "react/jsx-runtime";
165
167
  var MoonXContext = createContext(null);
166
168
  var useMoonXContext = () => {
package/dist/tron.js CHANGED
@@ -162,6 +162,7 @@ var import_utils3 = require("@moon-x/core/utils");
162
162
 
163
163
  // src/provider.tsx
164
164
  var import_react2 = require("@moon-x/core/react");
165
+ var import_lib2 = require("@moon-x/core/lib");
165
166
  var import_jsx_runtime = require("react/jsx-runtime");
166
167
  var MoonXContext = (0, import_react.createContext)(null);
167
168
  var useMoonXContext = () => {
package/dist/tron.mjs CHANGED
@@ -20,6 +20,7 @@ import {
20
20
  useContext,
21
21
  useEffect,
22
22
  useMemo,
23
+ useReducer,
23
24
  useRef,
24
25
  useState
25
26
  } from "react";
@@ -160,6 +161,7 @@ import {
160
161
 
161
162
  // src/provider.tsx
162
163
  import { SDKProvider } from "@moon-x/core/react";
164
+ import { validatePublishableKey } from "@moon-x/core/lib";
163
165
  import { jsx, jsxs } from "react/jsx-runtime";
164
166
  var MoonXContext = createContext(null);
165
167
  var useMoonXContext = () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moon-x/react-native-sdk",
3
- "version": "0.13.1",
3
+ "version": "0.14.1",
4
4
  "description": "Headless MoonX React Native SDK with WebView-backed transport, native passkeys, and app-owned UI.",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",
@@ -44,9 +44,11 @@
44
44
  "@expo/config-plugins": "57.0.3",
45
45
  "@react-native-async-storage/async-storage": "2.2.0",
46
46
  "@types/react": "19.2.14",
47
+ "@types/react-dom": "19.2.3",
47
48
  "expo-linking": "57.0.3",
48
49
  "expo-web-browser": "57.0.1",
49
50
  "react": "19.2.3",
51
+ "react-dom": "19.2.3",
50
52
  "react-native": "0.86.0",
51
53
  "react-native-passkeys": "0.3.3",
52
54
  "react-native-webview": "13.16.1",
@@ -55,7 +57,7 @@
55
57
  "vitest": "4.1.0"
56
58
  },
57
59
  "dependencies": {
58
- "@moon-x/core": "0.16.0"
60
+ "@moon-x/core": "0.17.0"
59
61
  },
60
62
  "peerDependencies": {
61
63
  "@expo/config-plugins": ">=10.0.0",