@moon-x/react-native-sdk 0.10.0 → 0.12.0
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/README.md +6 -8
- package/dist/index.d.mts +30 -7
- package/dist/index.d.ts +30 -7
- package/dist/index.js +88 -42
- package/dist/index.mjs +75 -30
- package/package.json +2 -2
- package/plugin/index.js +2 -2
package/README.md
CHANGED
|
@@ -75,7 +75,7 @@ import { MoonXProvider } from "@moon-x/react-native-sdk";
|
|
|
75
75
|
export default function Root() {
|
|
76
76
|
return (
|
|
77
77
|
<MoonXProvider
|
|
78
|
-
publishableKey={process.env.
|
|
78
|
+
publishableKey={process.env.EXPO_PUBLIC_MOONX_PUBLISHABLE_KEY!}
|
|
79
79
|
config={{
|
|
80
80
|
iframeUrl: "https://iframe.moonx-dev.com",
|
|
81
81
|
oauthRedirectUri: "myapp://oauth-callback",
|
|
@@ -319,17 +319,15 @@ your app's package name + signing-cert SHA-256 fingerprint.
|
|
|
319
319
|
#### 1. Publish `assetlinks.json` at the rpId apex
|
|
320
320
|
|
|
321
321
|
If `passkeyDomains` is `myapp.com`, host at
|
|
322
|
-
`https://myapp.com/.well-known/assetlinks.json`.
|
|
323
|
-
|
|
324
|
-
|
|
322
|
+
`https://myapp.com/.well-known/assetlinks.json`. Passkeys need the
|
|
323
|
+
`delegate_permission/common.get_login_creds` relation. Add
|
|
324
|
+
`delegate_permission/common.handle_all_urls` separately only if the app also
|
|
325
|
+
uses Android App Links:
|
|
325
326
|
|
|
326
327
|
```json
|
|
327
328
|
[
|
|
328
329
|
{
|
|
329
|
-
"relation": [
|
|
330
|
-
"delegate_permission/common.handle_all_urls",
|
|
331
|
-
"delegate_permission/common.get_login_creds"
|
|
332
|
-
],
|
|
330
|
+
"relation": ["delegate_permission/common.get_login_creds"],
|
|
333
331
|
"target": {
|
|
334
332
|
"namespace": "android_app",
|
|
335
333
|
"package_name": "com.example.myapp",
|
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, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSendTransactionParams, EthereumSendTransactionResult, EthereumGetBalanceParams, EthereumGetBalanceResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaGetBalanceParams, SolanaGetBalanceResult } from '@moon-x/core/types';
|
|
6
|
+
import { PublicWallet, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSendTransactionParams, EthereumSendTransactionResult, EthereumGetBalanceParams, EthereumGetBalanceResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaGetBalanceParams, SolanaGetBalanceResult, 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, ListEphemeralSignersResult, Network, ProvisionEphemeralSignerParams, ProvisionEphemeralSignerResult, PublicWallet, RevokeEphemeralSignerParams, SolanaGetBalanceParams, SolanaGetBalanceResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, WalletConnectConfig } from '@moon-x/core/types';
|
|
8
8
|
export { UseEphemeralSignerResult, useAddPasskey, useCreateWallet, useEphemeralSigner, useImportKey, useLoginWithEmail, useLogout, usePasskeyStatus, useRegisterPasskey, useRemovePasskey, useUser, useWallets } from '@moon-x/core/react';
|
|
9
9
|
|
|
@@ -78,16 +78,16 @@ interface RNAuthSDK {
|
|
|
78
78
|
success: boolean;
|
|
79
79
|
message: string;
|
|
80
80
|
}>;
|
|
81
|
-
createWallet: (walletType: "solana" | "ethereum", options?: {
|
|
81
|
+
createWallet: (walletType: "solana" | "ethereum" | "tron", options?: {
|
|
82
82
|
createAdditional?: boolean;
|
|
83
83
|
walletIndex?: number;
|
|
84
84
|
}) => Promise<{
|
|
85
85
|
wallet: PublicWallet;
|
|
86
86
|
}>;
|
|
87
|
-
importKey: (walletType: "solana" | "ethereum", key: string) => Promise<{
|
|
87
|
+
importKey: (walletType: "solana" | "ethereum" | "tron", key: string) => Promise<{
|
|
88
88
|
wallet: PublicWallet;
|
|
89
89
|
}>;
|
|
90
|
-
getWallets: (walletType: "solana" | "ethereum") => Promise<{
|
|
90
|
+
getWallets: (walletType: "solana" | "ethereum" | "tron") => Promise<{
|
|
91
91
|
wallets: any[];
|
|
92
92
|
walletType: string;
|
|
93
93
|
}>;
|
|
@@ -201,7 +201,7 @@ interface SensitiveFlowMountApi {
|
|
|
201
201
|
bridge: WebViewBridge;
|
|
202
202
|
cancel: () => void;
|
|
203
203
|
}
|
|
204
|
-
interface
|
|
204
|
+
interface MoonXContextValue {
|
|
205
205
|
sdk: RNAuthSDK;
|
|
206
206
|
_bridge: WebViewBridge;
|
|
207
207
|
_relyingPartyOrigin: RelyingPartyOriginInput;
|
|
@@ -209,7 +209,30 @@ interface MoonKeyContextValue {
|
|
|
209
209
|
_oauthRedirectUri?: string;
|
|
210
210
|
}
|
|
211
211
|
declare const MoonXProvider: React.FC<MoonXProviderProps>;
|
|
212
|
-
declare const
|
|
212
|
+
declare const useMoonXContext: () => MoonXContextValue;
|
|
213
|
+
|
|
214
|
+
interface UseAppConfigReturn {
|
|
215
|
+
appConfig: AppConfigResponse | null;
|
|
216
|
+
isLoading: boolean;
|
|
217
|
+
error: string | null;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Fetch the per-app config (`sdk_settings`, terms/privacy URLs, logo,
|
|
221
|
+
* ...) over the WebView bridge and return the whole `AppConfigResponse`
|
|
222
|
+
* alongside `{ isLoading, error }`.
|
|
223
|
+
*
|
|
224
|
+
* Deliberately mirrors the web SDK's `useAppConfig`
|
|
225
|
+
* (`@moon-x/react-sdk`'s `internal/use-app-config.ts`) return shape so
|
|
226
|
+
* app code that gates login methods on `sdk_settings` or renders a
|
|
227
|
+
* terms-acceptance footer moves between web and RN with a 1-line import
|
|
228
|
+
* swap — same philosophy as `useMoonX`. We return the full response
|
|
229
|
+
* rather than destructuring convenience fields for exactly that reason.
|
|
230
|
+
*
|
|
231
|
+
* `publishableKey` is optional (unlike web, where the consumer always
|
|
232
|
+
* threads it): the RN provider already holds the key, so we default to
|
|
233
|
+
* `sdk.publishableKey`. Pass it only to override.
|
|
234
|
+
*/
|
|
235
|
+
declare const useAppConfig: (publishableKey?: string) => UseAppConfigReturn;
|
|
213
236
|
|
|
214
237
|
type State$1 = {
|
|
215
238
|
status: "idle";
|
|
@@ -283,4 +306,4 @@ declare const useLoginWithOAuth: (params?: {
|
|
|
283
306
|
*/
|
|
284
307
|
declare const useMoonX: () => RNAuthSDK;
|
|
285
308
|
|
|
286
|
-
export { type MoonXConfig, MoonXProvider, type MoonXProviderProps, type RNAuthSDK, useAttachOAuth, useDetachOAuth, useExportKey, useLoginWithOAuth,
|
|
309
|
+
export { type MoonXConfig, MoonXProvider, type MoonXProviderProps, type RNAuthSDK, useAppConfig, useAttachOAuth, useDetachOAuth, useExportKey, useLoginWithOAuth, useMoonX, useMoonXContext };
|
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, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSendTransactionParams, EthereumSendTransactionResult, EthereumGetBalanceParams, EthereumGetBalanceResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaGetBalanceParams, SolanaGetBalanceResult } from '@moon-x/core/types';
|
|
6
|
+
import { PublicWallet, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSendTransactionParams, EthereumSendTransactionResult, EthereumGetBalanceParams, EthereumGetBalanceResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaGetBalanceParams, SolanaGetBalanceResult, 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, ListEphemeralSignersResult, Network, ProvisionEphemeralSignerParams, ProvisionEphemeralSignerResult, PublicWallet, RevokeEphemeralSignerParams, SolanaGetBalanceParams, SolanaGetBalanceResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, WalletConnectConfig } from '@moon-x/core/types';
|
|
8
8
|
export { UseEphemeralSignerResult, useAddPasskey, useCreateWallet, useEphemeralSigner, useImportKey, useLoginWithEmail, useLogout, usePasskeyStatus, useRegisterPasskey, useRemovePasskey, useUser, useWallets } from '@moon-x/core/react';
|
|
9
9
|
|
|
@@ -78,16 +78,16 @@ interface RNAuthSDK {
|
|
|
78
78
|
success: boolean;
|
|
79
79
|
message: string;
|
|
80
80
|
}>;
|
|
81
|
-
createWallet: (walletType: "solana" | "ethereum", options?: {
|
|
81
|
+
createWallet: (walletType: "solana" | "ethereum" | "tron", options?: {
|
|
82
82
|
createAdditional?: boolean;
|
|
83
83
|
walletIndex?: number;
|
|
84
84
|
}) => Promise<{
|
|
85
85
|
wallet: PublicWallet;
|
|
86
86
|
}>;
|
|
87
|
-
importKey: (walletType: "solana" | "ethereum", key: string) => Promise<{
|
|
87
|
+
importKey: (walletType: "solana" | "ethereum" | "tron", key: string) => Promise<{
|
|
88
88
|
wallet: PublicWallet;
|
|
89
89
|
}>;
|
|
90
|
-
getWallets: (walletType: "solana" | "ethereum") => Promise<{
|
|
90
|
+
getWallets: (walletType: "solana" | "ethereum" | "tron") => Promise<{
|
|
91
91
|
wallets: any[];
|
|
92
92
|
walletType: string;
|
|
93
93
|
}>;
|
|
@@ -201,7 +201,7 @@ interface SensitiveFlowMountApi {
|
|
|
201
201
|
bridge: WebViewBridge;
|
|
202
202
|
cancel: () => void;
|
|
203
203
|
}
|
|
204
|
-
interface
|
|
204
|
+
interface MoonXContextValue {
|
|
205
205
|
sdk: RNAuthSDK;
|
|
206
206
|
_bridge: WebViewBridge;
|
|
207
207
|
_relyingPartyOrigin: RelyingPartyOriginInput;
|
|
@@ -209,7 +209,30 @@ interface MoonKeyContextValue {
|
|
|
209
209
|
_oauthRedirectUri?: string;
|
|
210
210
|
}
|
|
211
211
|
declare const MoonXProvider: React.FC<MoonXProviderProps>;
|
|
212
|
-
declare const
|
|
212
|
+
declare const useMoonXContext: () => MoonXContextValue;
|
|
213
|
+
|
|
214
|
+
interface UseAppConfigReturn {
|
|
215
|
+
appConfig: AppConfigResponse | null;
|
|
216
|
+
isLoading: boolean;
|
|
217
|
+
error: string | null;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Fetch the per-app config (`sdk_settings`, terms/privacy URLs, logo,
|
|
221
|
+
* ...) over the WebView bridge and return the whole `AppConfigResponse`
|
|
222
|
+
* alongside `{ isLoading, error }`.
|
|
223
|
+
*
|
|
224
|
+
* Deliberately mirrors the web SDK's `useAppConfig`
|
|
225
|
+
* (`@moon-x/react-sdk`'s `internal/use-app-config.ts`) return shape so
|
|
226
|
+
* app code that gates login methods on `sdk_settings` or renders a
|
|
227
|
+
* terms-acceptance footer moves between web and RN with a 1-line import
|
|
228
|
+
* swap — same philosophy as `useMoonX`. We return the full response
|
|
229
|
+
* rather than destructuring convenience fields for exactly that reason.
|
|
230
|
+
*
|
|
231
|
+
* `publishableKey` is optional (unlike web, where the consumer always
|
|
232
|
+
* threads it): the RN provider already holds the key, so we default to
|
|
233
|
+
* `sdk.publishableKey`. Pass it only to override.
|
|
234
|
+
*/
|
|
235
|
+
declare const useAppConfig: (publishableKey?: string) => UseAppConfigReturn;
|
|
213
236
|
|
|
214
237
|
type State$1 = {
|
|
215
238
|
status: "idle";
|
|
@@ -283,4 +306,4 @@ declare const useLoginWithOAuth: (params?: {
|
|
|
283
306
|
*/
|
|
284
307
|
declare const useMoonX: () => RNAuthSDK;
|
|
285
308
|
|
|
286
|
-
export { type MoonXConfig, MoonXProvider, type MoonXProviderProps, type RNAuthSDK, useAttachOAuth, useDetachOAuth, useExportKey, useLoginWithOAuth,
|
|
309
|
+
export { type MoonXConfig, MoonXProvider, type MoonXProviderProps, type RNAuthSDK, useAppConfig, useAttachOAuth, useDetachOAuth, useExportKey, useLoginWithOAuth, useMoonX, useMoonXContext };
|
package/dist/index.js
CHANGED
|
@@ -31,25 +31,26 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
MoonXProvider: () => MoonXProvider,
|
|
34
|
-
PostMessageMethod: () =>
|
|
35
|
-
PostMessageType: () =>
|
|
36
|
-
useAddPasskey: () =>
|
|
34
|
+
PostMessageMethod: () => import_utils9.PostMessageMethod,
|
|
35
|
+
PostMessageType: () => import_utils9.PostMessageType,
|
|
36
|
+
useAddPasskey: () => import_react6.useAddPasskey,
|
|
37
|
+
useAppConfig: () => useAppConfig,
|
|
37
38
|
useAttachOAuth: () => useAttachOAuth,
|
|
38
|
-
useCreateWallet: () =>
|
|
39
|
+
useCreateWallet: () => import_react6.useCreateWallet,
|
|
39
40
|
useDetachOAuth: () => useDetachOAuth,
|
|
40
|
-
useEphemeralSigner: () =>
|
|
41
|
+
useEphemeralSigner: () => import_react6.useEphemeralSigner,
|
|
41
42
|
useExportKey: () => useExportKey,
|
|
42
|
-
useImportKey: () =>
|
|
43
|
-
useLoginWithEmail: () =>
|
|
43
|
+
useImportKey: () => import_react6.useImportKey,
|
|
44
|
+
useLoginWithEmail: () => import_react6.useLoginWithEmail,
|
|
44
45
|
useLoginWithOAuth: () => useLoginWithOAuth,
|
|
45
|
-
useLogout: () =>
|
|
46
|
-
useMoonKeyContext: () => useMoonKeyContext,
|
|
46
|
+
useLogout: () => import_react6.useLogout,
|
|
47
47
|
useMoonX: () => useMoonX,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
useMoonXContext: () => useMoonXContext,
|
|
49
|
+
usePasskeyStatus: () => import_react6.usePasskeyStatus,
|
|
50
|
+
useRegisterPasskey: () => import_react6.useRegisterPasskey,
|
|
51
|
+
useRemovePasskey: () => import_react6.useRemovePasskey,
|
|
52
|
+
useUser: () => import_react6.useUser,
|
|
53
|
+
useWallets: () => import_react6.useWallets
|
|
53
54
|
});
|
|
54
55
|
module.exports = __toCommonJS(index_exports);
|
|
55
56
|
|
|
@@ -75,7 +76,7 @@ var import_sdk2 = require("@moon-x/core/sdk");
|
|
|
75
76
|
|
|
76
77
|
// src/platform/async-storage-kv.ts
|
|
77
78
|
var import_async_storage = __toESM(require("@react-native-async-storage/async-storage"));
|
|
78
|
-
var createAsyncStorageKv = (prefix = "
|
|
79
|
+
var createAsyncStorageKv = (prefix = "moonx:") => ({
|
|
79
80
|
get: async (key) => import_async_storage.default.getItem(prefix + key),
|
|
80
81
|
set: async (key, value) => import_async_storage.default.setItem(prefix + key, value),
|
|
81
82
|
remove: async (key) => import_async_storage.default.removeItem(prefix + key)
|
|
@@ -581,7 +582,7 @@ var WebViewBridge = class {
|
|
|
581
582
|
var import_react2 = require("@moon-x/core/react");
|
|
582
583
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
583
584
|
var DEFAULT_IFRAME_URL = "https://iframe.moonx-dev.com";
|
|
584
|
-
var
|
|
585
|
+
var MoonXContext = (0, import_react.createContext)(null);
|
|
585
586
|
var MoonXProvider = ({
|
|
586
587
|
publishableKey,
|
|
587
588
|
config,
|
|
@@ -788,7 +789,7 @@ var MoonXProvider = ({
|
|
|
788
789
|
]
|
|
789
790
|
);
|
|
790
791
|
const closeLabel = config?.sensitiveModalCopy?.closeLabel ?? "Done";
|
|
791
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
792
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MoonXContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react2.SDKProvider, { value: sdk, children: [
|
|
792
793
|
children,
|
|
793
794
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
794
795
|
import_react_native.Animated.View,
|
|
@@ -850,8 +851,8 @@ var MoonXProvider = ({
|
|
|
850
851
|
)
|
|
851
852
|
] }) });
|
|
852
853
|
};
|
|
853
|
-
var
|
|
854
|
-
const ctx = (0, import_react.useContext)(
|
|
854
|
+
var useMoonXContext = () => {
|
|
855
|
+
const ctx = (0, import_react.useContext)(MoonXContext);
|
|
855
856
|
if (!ctx) {
|
|
856
857
|
throw new Error("useMoonX must be used within a MoonXProvider");
|
|
857
858
|
}
|
|
@@ -929,11 +930,55 @@ var styles = import_react_native.StyleSheet.create({
|
|
|
929
930
|
});
|
|
930
931
|
|
|
931
932
|
// src/hooks/index.ts
|
|
932
|
-
var
|
|
933
|
+
var import_react6 = require("@moon-x/core/react");
|
|
933
934
|
|
|
934
|
-
// src/hooks/use-
|
|
935
|
+
// src/hooks/use-app-config.ts
|
|
935
936
|
var import_utils5 = require("@moon-x/core/utils");
|
|
936
937
|
var import_react3 = require("react");
|
|
938
|
+
var useAppConfig = (publishableKey) => {
|
|
939
|
+
const { sdk, _bridge } = useMoonXContext();
|
|
940
|
+
const resolvedKey = publishableKey ?? sdk.publishableKey;
|
|
941
|
+
const ready = sdk.ready;
|
|
942
|
+
const [appConfig, setAppConfig] = (0, import_react3.useState)(null);
|
|
943
|
+
const [isLoading, setIsLoading] = (0, import_react3.useState)(true);
|
|
944
|
+
const [error, setError] = (0, import_react3.useState)(null);
|
|
945
|
+
(0, import_react3.useEffect)(() => {
|
|
946
|
+
if (!resolvedKey) {
|
|
947
|
+
setIsLoading(false);
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
if (!ready) {
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
953
|
+
let cancelled = false;
|
|
954
|
+
const fetchAppConfig = async () => {
|
|
955
|
+
setIsLoading(true);
|
|
956
|
+
setError(null);
|
|
957
|
+
setAppConfig(null);
|
|
958
|
+
try {
|
|
959
|
+
const config = await _bridge.send(import_utils5.PostMessageType.AUTH, import_utils5.PostMessageMethod.GET_APP_CONFIG, {
|
|
960
|
+
publishableKey: resolvedKey
|
|
961
|
+
});
|
|
962
|
+
if (!cancelled) setAppConfig(config);
|
|
963
|
+
} catch (err) {
|
|
964
|
+
if (!cancelled) {
|
|
965
|
+
setError(err instanceof Error ? err.message : "Unknown error");
|
|
966
|
+
}
|
|
967
|
+
} finally {
|
|
968
|
+
if (!cancelled) setIsLoading(false);
|
|
969
|
+
}
|
|
970
|
+
};
|
|
971
|
+
fetchAppConfig();
|
|
972
|
+
return () => {
|
|
973
|
+
cancelled = true;
|
|
974
|
+
};
|
|
975
|
+
}, [resolvedKey, ready, _bridge]);
|
|
976
|
+
return { appConfig, isLoading, error };
|
|
977
|
+
};
|
|
978
|
+
|
|
979
|
+
// src/hooks/use-attach-oauth.ts
|
|
980
|
+
var import_utils6 = require("@moon-x/core/utils");
|
|
981
|
+
var import_react4 = require("react");
|
|
937
982
|
|
|
938
983
|
// src/lib/oauth-deep-link.ts
|
|
939
984
|
var openOAuthFlow = async ({
|
|
@@ -973,8 +1018,8 @@ var parseOAuthRedirect = async (redirectUrl) => {
|
|
|
973
1018
|
|
|
974
1019
|
// src/hooks/use-attach-oauth.ts
|
|
975
1020
|
var useAttachOAuth = (params) => {
|
|
976
|
-
const { sdk, _bridge, _oauthRedirectUri } =
|
|
977
|
-
const [state, setState] = (0,
|
|
1021
|
+
const { sdk, _bridge, _oauthRedirectUri } = useMoonXContext();
|
|
1022
|
+
const [state, setState] = (0, import_react4.useState)({ status: "idle" });
|
|
978
1023
|
return {
|
|
979
1024
|
state,
|
|
980
1025
|
attachOAuth: async (provider) => {
|
|
@@ -983,8 +1028,8 @@ var useAttachOAuth = (params) => {
|
|
|
983
1028
|
const redirectUri = params?.redirectUri || _oauthRedirectUri;
|
|
984
1029
|
if (!redirectUri) throw new Error("oauth_redirect_uri_missing");
|
|
985
1030
|
const startResult = await _bridge.send(
|
|
986
|
-
|
|
987
|
-
|
|
1031
|
+
import_utils6.PostMessageType.AUTH,
|
|
1032
|
+
import_utils6.PostMessageMethod.START_OAUTH,
|
|
988
1033
|
{
|
|
989
1034
|
publishableKey: sdk.publishableKey,
|
|
990
1035
|
provider,
|
|
@@ -1004,8 +1049,8 @@ var useAttachOAuth = (params) => {
|
|
|
1004
1049
|
if (parsed.error) throw new Error(parsed.error);
|
|
1005
1050
|
setState({ status: "verifying" });
|
|
1006
1051
|
await _bridge.send(
|
|
1007
|
-
|
|
1008
|
-
|
|
1052
|
+
import_utils6.PostMessageType.AUTH,
|
|
1053
|
+
import_utils6.PostMessageMethod.ATTACH_OAUTH,
|
|
1009
1054
|
{
|
|
1010
1055
|
publishableKey: sdk.publishableKey,
|
|
1011
1056
|
provider,
|
|
@@ -1026,14 +1071,14 @@ var useAttachOAuth = (params) => {
|
|
|
1026
1071
|
};
|
|
1027
1072
|
|
|
1028
1073
|
// src/hooks/use-detach-oauth.ts
|
|
1029
|
-
var
|
|
1074
|
+
var import_utils7 = require("@moon-x/core/utils");
|
|
1030
1075
|
var useDetachOAuth = () => {
|
|
1031
|
-
const { sdk, _bridge } =
|
|
1076
|
+
const { sdk, _bridge } = useMoonXContext();
|
|
1032
1077
|
return {
|
|
1033
1078
|
detachOAuth: async (idpUserId) => {
|
|
1034
1079
|
await _bridge.send(
|
|
1035
|
-
|
|
1036
|
-
|
|
1080
|
+
import_utils7.PostMessageType.AUTH,
|
|
1081
|
+
import_utils7.PostMessageMethod.DETACH_OAUTH,
|
|
1037
1082
|
{ publishableKey: sdk.publishableKey, idpUserId }
|
|
1038
1083
|
);
|
|
1039
1084
|
}
|
|
@@ -1043,7 +1088,7 @@ var useDetachOAuth = () => {
|
|
|
1043
1088
|
// src/hooks/use-export-key.ts
|
|
1044
1089
|
var import_sdk6 = require("@moon-x/core/sdk");
|
|
1045
1090
|
var useExportKey = () => {
|
|
1046
|
-
const { sdk, _bridge, _relyingPartyOrigin, _runSensitiveFlow } =
|
|
1091
|
+
const { sdk, _bridge, _relyingPartyOrigin, _runSensitiveFlow } = useMoonXContext();
|
|
1047
1092
|
return {
|
|
1048
1093
|
exportKey: async (wallet) => {
|
|
1049
1094
|
const { userHandleB64url, credentialIdB64url, tokens } = await (0, import_sdk6.getInternalPresenceTokens)({
|
|
@@ -1078,11 +1123,11 @@ var useExportKey = () => {
|
|
|
1078
1123
|
};
|
|
1079
1124
|
|
|
1080
1125
|
// src/hooks/use-login-with-oauth.ts
|
|
1081
|
-
var
|
|
1082
|
-
var
|
|
1126
|
+
var import_utils8 = require("@moon-x/core/utils");
|
|
1127
|
+
var import_react5 = require("react");
|
|
1083
1128
|
var useLoginWithOAuth = (params) => {
|
|
1084
|
-
const { sdk, _bridge, _oauthRedirectUri } =
|
|
1085
|
-
const [state, setState] = (0,
|
|
1129
|
+
const { sdk, _bridge, _oauthRedirectUri } = useMoonXContext();
|
|
1130
|
+
const [state, setState] = (0, import_react5.useState)({ status: "idle" });
|
|
1086
1131
|
return {
|
|
1087
1132
|
state,
|
|
1088
1133
|
loginWithOAuth: async (provider) => {
|
|
@@ -1093,8 +1138,8 @@ var useLoginWithOAuth = (params) => {
|
|
|
1093
1138
|
throw new Error("oauth_redirect_uri_missing");
|
|
1094
1139
|
}
|
|
1095
1140
|
const startResult = await _bridge.send(
|
|
1096
|
-
|
|
1097
|
-
|
|
1141
|
+
import_utils8.PostMessageType.AUTH,
|
|
1142
|
+
import_utils8.PostMessageMethod.START_OAUTH,
|
|
1098
1143
|
{
|
|
1099
1144
|
publishableKey: sdk.publishableKey,
|
|
1100
1145
|
provider,
|
|
@@ -1132,17 +1177,18 @@ var useLoginWithOAuth = (params) => {
|
|
|
1132
1177
|
};
|
|
1133
1178
|
};
|
|
1134
1179
|
|
|
1135
|
-
// src/hooks/use-
|
|
1136
|
-
var useMoonX = () =>
|
|
1180
|
+
// src/hooks/use-moonx.ts
|
|
1181
|
+
var useMoonX = () => useMoonXContext().sdk;
|
|
1137
1182
|
|
|
1138
1183
|
// src/index.ts
|
|
1139
|
-
var
|
|
1184
|
+
var import_utils9 = require("@moon-x/core/utils");
|
|
1140
1185
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1141
1186
|
0 && (module.exports = {
|
|
1142
1187
|
MoonXProvider,
|
|
1143
1188
|
PostMessageMethod,
|
|
1144
1189
|
PostMessageType,
|
|
1145
1190
|
useAddPasskey,
|
|
1191
|
+
useAppConfig,
|
|
1146
1192
|
useAttachOAuth,
|
|
1147
1193
|
useCreateWallet,
|
|
1148
1194
|
useDetachOAuth,
|
|
@@ -1152,8 +1198,8 @@ var import_utils8 = require("@moon-x/core/utils");
|
|
|
1152
1198
|
useLoginWithEmail,
|
|
1153
1199
|
useLoginWithOAuth,
|
|
1154
1200
|
useLogout,
|
|
1155
|
-
useMoonKeyContext,
|
|
1156
1201
|
useMoonX,
|
|
1202
|
+
useMoonXContext,
|
|
1157
1203
|
usePasskeyStatus,
|
|
1158
1204
|
useRegisterPasskey,
|
|
1159
1205
|
useRemovePasskey,
|
package/dist/index.mjs
CHANGED
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
|
|
39
39
|
// src/platform/async-storage-kv.ts
|
|
40
40
|
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
41
|
-
var createAsyncStorageKv = (prefix = "
|
|
41
|
+
var createAsyncStorageKv = (prefix = "moonx:") => ({
|
|
42
42
|
get: async (key) => AsyncStorage.getItem(prefix + key),
|
|
43
43
|
set: async (key, value) => AsyncStorage.setItem(prefix + key, value),
|
|
44
44
|
remove: async (key) => AsyncStorage.removeItem(prefix + key)
|
|
@@ -555,7 +555,7 @@ var WebViewBridge = class {
|
|
|
555
555
|
import { SDKProvider } from "@moon-x/core/react";
|
|
556
556
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
557
557
|
var DEFAULT_IFRAME_URL = "https://iframe.moonx-dev.com";
|
|
558
|
-
var
|
|
558
|
+
var MoonXContext = createContext(null);
|
|
559
559
|
var MoonXProvider = ({
|
|
560
560
|
publishableKey,
|
|
561
561
|
config,
|
|
@@ -762,7 +762,7 @@ var MoonXProvider = ({
|
|
|
762
762
|
]
|
|
763
763
|
);
|
|
764
764
|
const closeLabel = config?.sensitiveModalCopy?.closeLabel ?? "Done";
|
|
765
|
-
return /* @__PURE__ */ jsx(
|
|
765
|
+
return /* @__PURE__ */ jsx(MoonXContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxs(SDKProvider, { value: sdk, children: [
|
|
766
766
|
children,
|
|
767
767
|
/* @__PURE__ */ jsx(
|
|
768
768
|
Animated.View,
|
|
@@ -824,8 +824,8 @@ var MoonXProvider = ({
|
|
|
824
824
|
)
|
|
825
825
|
] }) });
|
|
826
826
|
};
|
|
827
|
-
var
|
|
828
|
-
const ctx = useContext(
|
|
827
|
+
var useMoonXContext = () => {
|
|
828
|
+
const ctx = useContext(MoonXContext);
|
|
829
829
|
if (!ctx) {
|
|
830
830
|
throw new Error("useMoonX must be used within a MoonXProvider");
|
|
831
831
|
}
|
|
@@ -917,9 +917,53 @@ import {
|
|
|
917
917
|
useWallets
|
|
918
918
|
} from "@moon-x/core/react";
|
|
919
919
|
|
|
920
|
-
// src/hooks/use-
|
|
920
|
+
// src/hooks/use-app-config.ts
|
|
921
921
|
import { PostMessageMethod as PostMessageMethod4, PostMessageType as PostMessageType4 } from "@moon-x/core/utils";
|
|
922
|
-
import { useState as useState2 } from "react";
|
|
922
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
923
|
+
var useAppConfig = (publishableKey) => {
|
|
924
|
+
const { sdk, _bridge } = useMoonXContext();
|
|
925
|
+
const resolvedKey = publishableKey ?? sdk.publishableKey;
|
|
926
|
+
const ready = sdk.ready;
|
|
927
|
+
const [appConfig, setAppConfig] = useState2(null);
|
|
928
|
+
const [isLoading, setIsLoading] = useState2(true);
|
|
929
|
+
const [error, setError] = useState2(null);
|
|
930
|
+
useEffect2(() => {
|
|
931
|
+
if (!resolvedKey) {
|
|
932
|
+
setIsLoading(false);
|
|
933
|
+
return;
|
|
934
|
+
}
|
|
935
|
+
if (!ready) {
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
let cancelled = false;
|
|
939
|
+
const fetchAppConfig = async () => {
|
|
940
|
+
setIsLoading(true);
|
|
941
|
+
setError(null);
|
|
942
|
+
setAppConfig(null);
|
|
943
|
+
try {
|
|
944
|
+
const config = await _bridge.send(PostMessageType4.AUTH, PostMessageMethod4.GET_APP_CONFIG, {
|
|
945
|
+
publishableKey: resolvedKey
|
|
946
|
+
});
|
|
947
|
+
if (!cancelled) setAppConfig(config);
|
|
948
|
+
} catch (err) {
|
|
949
|
+
if (!cancelled) {
|
|
950
|
+
setError(err instanceof Error ? err.message : "Unknown error");
|
|
951
|
+
}
|
|
952
|
+
} finally {
|
|
953
|
+
if (!cancelled) setIsLoading(false);
|
|
954
|
+
}
|
|
955
|
+
};
|
|
956
|
+
fetchAppConfig();
|
|
957
|
+
return () => {
|
|
958
|
+
cancelled = true;
|
|
959
|
+
};
|
|
960
|
+
}, [resolvedKey, ready, _bridge]);
|
|
961
|
+
return { appConfig, isLoading, error };
|
|
962
|
+
};
|
|
963
|
+
|
|
964
|
+
// src/hooks/use-attach-oauth.ts
|
|
965
|
+
import { PostMessageMethod as PostMessageMethod5, PostMessageType as PostMessageType5 } from "@moon-x/core/utils";
|
|
966
|
+
import { useState as useState3 } from "react";
|
|
923
967
|
|
|
924
968
|
// src/lib/oauth-deep-link.ts
|
|
925
969
|
var openOAuthFlow = async ({
|
|
@@ -959,8 +1003,8 @@ var parseOAuthRedirect = async (redirectUrl) => {
|
|
|
959
1003
|
|
|
960
1004
|
// src/hooks/use-attach-oauth.ts
|
|
961
1005
|
var useAttachOAuth = (params) => {
|
|
962
|
-
const { sdk, _bridge, _oauthRedirectUri } =
|
|
963
|
-
const [state, setState] =
|
|
1006
|
+
const { sdk, _bridge, _oauthRedirectUri } = useMoonXContext();
|
|
1007
|
+
const [state, setState] = useState3({ status: "idle" });
|
|
964
1008
|
return {
|
|
965
1009
|
state,
|
|
966
1010
|
attachOAuth: async (provider) => {
|
|
@@ -969,8 +1013,8 @@ var useAttachOAuth = (params) => {
|
|
|
969
1013
|
const redirectUri = params?.redirectUri || _oauthRedirectUri;
|
|
970
1014
|
if (!redirectUri) throw new Error("oauth_redirect_uri_missing");
|
|
971
1015
|
const startResult = await _bridge.send(
|
|
972
|
-
|
|
973
|
-
|
|
1016
|
+
PostMessageType5.AUTH,
|
|
1017
|
+
PostMessageMethod5.START_OAUTH,
|
|
974
1018
|
{
|
|
975
1019
|
publishableKey: sdk.publishableKey,
|
|
976
1020
|
provider,
|
|
@@ -990,8 +1034,8 @@ var useAttachOAuth = (params) => {
|
|
|
990
1034
|
if (parsed.error) throw new Error(parsed.error);
|
|
991
1035
|
setState({ status: "verifying" });
|
|
992
1036
|
await _bridge.send(
|
|
993
|
-
|
|
994
|
-
|
|
1037
|
+
PostMessageType5.AUTH,
|
|
1038
|
+
PostMessageMethod5.ATTACH_OAUTH,
|
|
995
1039
|
{
|
|
996
1040
|
publishableKey: sdk.publishableKey,
|
|
997
1041
|
provider,
|
|
@@ -1012,14 +1056,14 @@ var useAttachOAuth = (params) => {
|
|
|
1012
1056
|
};
|
|
1013
1057
|
|
|
1014
1058
|
// src/hooks/use-detach-oauth.ts
|
|
1015
|
-
import { PostMessageMethod as
|
|
1059
|
+
import { PostMessageMethod as PostMessageMethod6, PostMessageType as PostMessageType6 } from "@moon-x/core/utils";
|
|
1016
1060
|
var useDetachOAuth = () => {
|
|
1017
|
-
const { sdk, _bridge } =
|
|
1061
|
+
const { sdk, _bridge } = useMoonXContext();
|
|
1018
1062
|
return {
|
|
1019
1063
|
detachOAuth: async (idpUserId) => {
|
|
1020
1064
|
await _bridge.send(
|
|
1021
|
-
|
|
1022
|
-
|
|
1065
|
+
PostMessageType6.AUTH,
|
|
1066
|
+
PostMessageMethod6.DETACH_OAUTH,
|
|
1023
1067
|
{ publishableKey: sdk.publishableKey, idpUserId }
|
|
1024
1068
|
);
|
|
1025
1069
|
}
|
|
@@ -1029,7 +1073,7 @@ var useDetachOAuth = () => {
|
|
|
1029
1073
|
// src/hooks/use-export-key.ts
|
|
1030
1074
|
import { getInternalPresenceTokens as getInternalPresenceTokens2, SCOPES_EXPORT_KEY } from "@moon-x/core/sdk";
|
|
1031
1075
|
var useExportKey = () => {
|
|
1032
|
-
const { sdk, _bridge, _relyingPartyOrigin, _runSensitiveFlow } =
|
|
1076
|
+
const { sdk, _bridge, _relyingPartyOrigin, _runSensitiveFlow } = useMoonXContext();
|
|
1033
1077
|
return {
|
|
1034
1078
|
exportKey: async (wallet) => {
|
|
1035
1079
|
const { userHandleB64url, credentialIdB64url, tokens } = await getInternalPresenceTokens2({
|
|
@@ -1064,11 +1108,11 @@ var useExportKey = () => {
|
|
|
1064
1108
|
};
|
|
1065
1109
|
|
|
1066
1110
|
// src/hooks/use-login-with-oauth.ts
|
|
1067
|
-
import { PostMessageMethod as
|
|
1068
|
-
import { useState as
|
|
1111
|
+
import { PostMessageMethod as PostMessageMethod7, PostMessageType as PostMessageType7 } from "@moon-x/core/utils";
|
|
1112
|
+
import { useState as useState4 } from "react";
|
|
1069
1113
|
var useLoginWithOAuth = (params) => {
|
|
1070
|
-
const { sdk, _bridge, _oauthRedirectUri } =
|
|
1071
|
-
const [state, setState] =
|
|
1114
|
+
const { sdk, _bridge, _oauthRedirectUri } = useMoonXContext();
|
|
1115
|
+
const [state, setState] = useState4({ status: "idle" });
|
|
1072
1116
|
return {
|
|
1073
1117
|
state,
|
|
1074
1118
|
loginWithOAuth: async (provider) => {
|
|
@@ -1079,8 +1123,8 @@ var useLoginWithOAuth = (params) => {
|
|
|
1079
1123
|
throw new Error("oauth_redirect_uri_missing");
|
|
1080
1124
|
}
|
|
1081
1125
|
const startResult = await _bridge.send(
|
|
1082
|
-
|
|
1083
|
-
|
|
1126
|
+
PostMessageType7.AUTH,
|
|
1127
|
+
PostMessageMethod7.START_OAUTH,
|
|
1084
1128
|
{
|
|
1085
1129
|
publishableKey: sdk.publishableKey,
|
|
1086
1130
|
provider,
|
|
@@ -1118,16 +1162,17 @@ var useLoginWithOAuth = (params) => {
|
|
|
1118
1162
|
};
|
|
1119
1163
|
};
|
|
1120
1164
|
|
|
1121
|
-
// src/hooks/use-
|
|
1122
|
-
var useMoonX = () =>
|
|
1165
|
+
// src/hooks/use-moonx.ts
|
|
1166
|
+
var useMoonX = () => useMoonXContext().sdk;
|
|
1123
1167
|
|
|
1124
1168
|
// src/index.ts
|
|
1125
|
-
import { PostMessageMethod as
|
|
1169
|
+
import { PostMessageMethod as PostMessageMethod8, PostMessageType as PostMessageType8 } from "@moon-x/core/utils";
|
|
1126
1170
|
export {
|
|
1127
1171
|
MoonXProvider,
|
|
1128
|
-
|
|
1129
|
-
|
|
1172
|
+
PostMessageMethod8 as PostMessageMethod,
|
|
1173
|
+
PostMessageType8 as PostMessageType,
|
|
1130
1174
|
useAddPasskey,
|
|
1175
|
+
useAppConfig,
|
|
1131
1176
|
useAttachOAuth,
|
|
1132
1177
|
useCreateWallet,
|
|
1133
1178
|
useDetachOAuth,
|
|
@@ -1137,8 +1182,8 @@ export {
|
|
|
1137
1182
|
useLoginWithEmail,
|
|
1138
1183
|
useLoginWithOAuth,
|
|
1139
1184
|
useLogout,
|
|
1140
|
-
useMoonKeyContext,
|
|
1141
1185
|
useMoonX,
|
|
1186
|
+
useMoonXContext,
|
|
1142
1187
|
usePasskeyStatus,
|
|
1143
1188
|
useRegisterPasskey,
|
|
1144
1189
|
useRemovePasskey,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moon-x/react-native-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "MoonX React Native SDK — WebView-backed transport, react-native-passkeys, AsyncStorage. Mobile parity with @moon-x/react-sdk + @moon-x/core-sdk.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"typescript": "5.9.3"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@moon-x/core": "0.
|
|
52
|
+
"@moon-x/core": "0.14.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@expo/config-plugins": ">=10.0.0",
|
package/plugin/index.js
CHANGED
|
@@ -156,7 +156,7 @@ const withOAuthIntentFilter = (config, oauthRedirectScheme) => {
|
|
|
156
156
|
});
|
|
157
157
|
};
|
|
158
158
|
|
|
159
|
-
const
|
|
159
|
+
const withMoonX = (config, props = {}) => {
|
|
160
160
|
let next = config;
|
|
161
161
|
next = withAssociatedDomains(
|
|
162
162
|
next,
|
|
@@ -169,4 +169,4 @@ const withMoonKey = (config, props = {}) => {
|
|
|
169
169
|
return next;
|
|
170
170
|
};
|
|
171
171
|
|
|
172
|
-
module.exports =
|
|
172
|
+
module.exports = withMoonX;
|