@moon-x/react-native-sdk 0.12.0 → 0.13.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 +133 -25
- package/dist/ethereum.d.mts +10 -2
- package/dist/ethereum.d.ts +10 -2
- package/dist/ethereum.js +296 -2
- package/dist/ethereum.mjs +316 -2
- package/dist/index.d.mts +130 -18
- package/dist/index.d.ts +130 -18
- package/dist/index.js +640 -112
- package/dist/index.mjs +621 -90
- package/dist/solana.d.mts +10 -1
- package/dist/solana.d.ts +10 -1
- package/dist/solana.js +298 -2
- package/dist/solana.mjs +318 -2
- package/dist/tron.d.mts +11 -0
- package/dist/tron.d.ts +11 -0
- package/dist/tron.js +330 -0
- package/dist/tron.mjs +327 -0
- package/dist/use-chain-export-key-C4vTffjx.d.mts +11 -0
- package/dist/use-chain-export-key-C7zBt98X.d.ts +11 -0
- package/dist/use-export-key-BIz_tV0k.d.mts +23 -0
- package/dist/use-export-key-BIz_tV0k.d.ts +23 -0
- package/package.json +12 -4
package/dist/tron.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as _moon_x_core_types from '@moon-x/core/types';
|
|
2
|
+
export { TronGetBalanceParams, TronGetBalanceResult, TronSendTransactionParams, TronSendTransactionResult, TronSignMessageParams, TronSignMessageResult, TronSignTransactionParams, TronSignTransactionResult, TronTransactionJson } from '@moon-x/core/types';
|
|
3
|
+
export { useCreateWallet, useGetBalance, useImportKey, useSendTransaction, useSignMessage, useSignTransaction, useWallets } from '@moon-x/core/react/tron';
|
|
4
|
+
export { u as useExportKey } from './use-chain-export-key-C7zBt98X.js';
|
|
5
|
+
import './use-export-key-BIz_tV0k.js';
|
|
6
|
+
|
|
7
|
+
declare const useFundWallet: () => {
|
|
8
|
+
fundWallet: (address: string, options?: _moon_x_core_types.TronFundingConfig | undefined) => Promise<_moon_x_core_types.FundingSession>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { useFundWallet };
|
package/dist/tron.js
ADDED
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/tron.ts
|
|
31
|
+
var tron_exports = {};
|
|
32
|
+
__export(tron_exports, {
|
|
33
|
+
useCreateWallet: () => import_tron.useCreateWallet,
|
|
34
|
+
useExportKey: () => useChainExportKey,
|
|
35
|
+
useFundWallet: () => useFundWallet,
|
|
36
|
+
useGetBalance: () => import_tron.useGetBalance,
|
|
37
|
+
useImportKey: () => import_tron.useImportKey,
|
|
38
|
+
useSendTransaction: () => import_tron.useSendTransaction,
|
|
39
|
+
useSignMessage: () => import_tron.useSignMessage,
|
|
40
|
+
useSignTransaction: () => import_tron.useSignTransaction,
|
|
41
|
+
useWallets: () => import_tron.useWallets
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(tron_exports);
|
|
44
|
+
var import_tron = require("@moon-x/core/react/tron");
|
|
45
|
+
|
|
46
|
+
// src/hooks/use-export-key.ts
|
|
47
|
+
var import_sdk8 = require("@moon-x/core/sdk");
|
|
48
|
+
var import_utils5 = require("@moon-x/core/utils");
|
|
49
|
+
|
|
50
|
+
// src/provider.tsx
|
|
51
|
+
var import_react = require("react");
|
|
52
|
+
var import_react_native = require("react-native");
|
|
53
|
+
var import_react_native_webview = require("react-native-webview");
|
|
54
|
+
|
|
55
|
+
// src/sdk/create-sdk-instance.ts
|
|
56
|
+
var import_utils2 = require("@moon-x/core/utils");
|
|
57
|
+
|
|
58
|
+
// src/sdk/sdk-authentication-methods.ts
|
|
59
|
+
var import_sdk = require("@moon-x/core/sdk");
|
|
60
|
+
|
|
61
|
+
// src/sdk/sdk-ethereum-methods.ts
|
|
62
|
+
var import_sdk2 = require("@moon-x/core/sdk");
|
|
63
|
+
|
|
64
|
+
// src/platform/async-storage-kv.ts
|
|
65
|
+
var import_async_storage = __toESM(require("@react-native-async-storage/async-storage"));
|
|
66
|
+
|
|
67
|
+
// src/platform/rn-passkey.ts
|
|
68
|
+
var import_react_native_passkeys = require("react-native-passkeys");
|
|
69
|
+
var createRNPasskey = () => ({
|
|
70
|
+
assert: async ({ rpId, challenge }) => {
|
|
71
|
+
const credential = await (0, import_react_native_passkeys.get)({
|
|
72
|
+
challenge,
|
|
73
|
+
rpId,
|
|
74
|
+
allowCredentials: [],
|
|
75
|
+
userVerification: "preferred"
|
|
76
|
+
});
|
|
77
|
+
if (!credential) throw new Error("passkey_assertion_cancelled");
|
|
78
|
+
const userHandle = credential.response.userHandle;
|
|
79
|
+
if (!userHandle) throw new Error("user_handle_missing");
|
|
80
|
+
return {
|
|
81
|
+
rawIdB64url: credential.rawId,
|
|
82
|
+
userHandleB64url: userHandle
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
assertForServer: async ({ optionsJSON }) => {
|
|
86
|
+
const credential = await (0, import_react_native_passkeys.get)({
|
|
87
|
+
challenge: optionsJSON.challenge,
|
|
88
|
+
rpId: optionsJSON.rpId,
|
|
89
|
+
allowCredentials: optionsJSON.allowCredentials ?? [],
|
|
90
|
+
userVerification: optionsJSON.userVerification ?? "preferred"
|
|
91
|
+
});
|
|
92
|
+
if (!credential) throw new Error("passkey_assertion_cancelled");
|
|
93
|
+
const sanitized = {
|
|
94
|
+
id: credential.id ?? credential.rawId,
|
|
95
|
+
rawId: credential.rawId,
|
|
96
|
+
type: credential.type ?? "public-key",
|
|
97
|
+
response: {
|
|
98
|
+
clientDataJSON: credential.response.clientDataJSON,
|
|
99
|
+
authenticatorData: credential.response.authenticatorData,
|
|
100
|
+
signature: credential.response.signature,
|
|
101
|
+
userHandle: void 0
|
|
102
|
+
},
|
|
103
|
+
clientExtensionResults: credential.clientExtensionResults ?? {},
|
|
104
|
+
authenticatorAttachment: credential.authenticatorAttachment
|
|
105
|
+
};
|
|
106
|
+
return sanitized;
|
|
107
|
+
},
|
|
108
|
+
assertForInternalPresence: async ({ optionsJSON }) => {
|
|
109
|
+
const credential = await (0, import_react_native_passkeys.get)({
|
|
110
|
+
challenge: optionsJSON.challenge,
|
|
111
|
+
rpId: optionsJSON.rpId,
|
|
112
|
+
allowCredentials: [],
|
|
113
|
+
userVerification: optionsJSON.userVerification ?? "preferred"
|
|
114
|
+
});
|
|
115
|
+
if (!credential) throw new Error("passkey_assertion_cancelled");
|
|
116
|
+
const userHandle = credential.response.userHandle;
|
|
117
|
+
if (!userHandle) throw new Error("user_handle_missing");
|
|
118
|
+
const sanitized = {
|
|
119
|
+
id: credential.id ?? credential.rawId,
|
|
120
|
+
rawId: credential.rawId,
|
|
121
|
+
type: credential.type ?? "public-key",
|
|
122
|
+
response: {
|
|
123
|
+
clientDataJSON: credential.response.clientDataJSON,
|
|
124
|
+
authenticatorData: credential.response.authenticatorData,
|
|
125
|
+
signature: credential.response.signature,
|
|
126
|
+
userHandle: void 0
|
|
127
|
+
},
|
|
128
|
+
clientExtensionResults: credential.clientExtensionResults ?? {},
|
|
129
|
+
authenticatorAttachment: credential.authenticatorAttachment
|
|
130
|
+
};
|
|
131
|
+
return {
|
|
132
|
+
response: sanitized,
|
|
133
|
+
userHandleB64url: userHandle,
|
|
134
|
+
credentialIdB64url: credential.rawId
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// src/sdk/sdk-funding-methods.ts
|
|
140
|
+
var import_sdk3 = require("@moon-x/core/sdk");
|
|
141
|
+
|
|
142
|
+
// src/sdk/sdk-passkey-methods.ts
|
|
143
|
+
var import_lib = require("@moon-x/core/lib");
|
|
144
|
+
var import_sdk4 = require("@moon-x/core/sdk");
|
|
145
|
+
var import_utils = require("@moon-x/core/utils");
|
|
146
|
+
var import_react_native_passkeys2 = require("react-native-passkeys");
|
|
147
|
+
|
|
148
|
+
// src/sdk/sdk-methods.ts
|
|
149
|
+
var import_sdk5 = require("@moon-x/core/sdk");
|
|
150
|
+
|
|
151
|
+
// src/sdk/sdk-solana-methods.ts
|
|
152
|
+
var import_sdk6 = require("@moon-x/core/sdk");
|
|
153
|
+
|
|
154
|
+
// src/sdk/sdk-tron-methods.ts
|
|
155
|
+
var import_sdk7 = require("@moon-x/core/sdk");
|
|
156
|
+
|
|
157
|
+
// src/provider.tsx
|
|
158
|
+
var import_utils4 = require("@moon-x/core/utils");
|
|
159
|
+
|
|
160
|
+
// src/transport/webview-bridge.ts
|
|
161
|
+
var import_utils3 = require("@moon-x/core/utils");
|
|
162
|
+
|
|
163
|
+
// src/provider.tsx
|
|
164
|
+
var import_react2 = require("@moon-x/core/react");
|
|
165
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
166
|
+
var MoonXContext = (0, import_react.createContext)(null);
|
|
167
|
+
var useMoonXContext = () => {
|
|
168
|
+
const ctx = (0, import_react.useContext)(MoonXContext);
|
|
169
|
+
if (!ctx) {
|
|
170
|
+
throw new Error("useMoonX must be used within a MoonXProvider");
|
|
171
|
+
}
|
|
172
|
+
return ctx;
|
|
173
|
+
};
|
|
174
|
+
var styles = import_react_native.StyleSheet.create({
|
|
175
|
+
backdrop: {
|
|
176
|
+
position: "absolute",
|
|
177
|
+
top: 0,
|
|
178
|
+
bottom: 0,
|
|
179
|
+
left: 0,
|
|
180
|
+
right: 0,
|
|
181
|
+
backgroundColor: "#000",
|
|
182
|
+
zIndex: 999
|
|
183
|
+
},
|
|
184
|
+
// Sheet-style container: rendered as a card that slides up from the
|
|
185
|
+
// bottom. `top` is set inline by the provider to leave room above
|
|
186
|
+
// for the host app's content visible through the dimmed backdrop.
|
|
187
|
+
// `bottom: 0` so the WebView fills the remaining height.
|
|
188
|
+
sheetContainer: {
|
|
189
|
+
position: "absolute",
|
|
190
|
+
bottom: 0,
|
|
191
|
+
left: 0,
|
|
192
|
+
right: 0,
|
|
193
|
+
backgroundColor: "#0a0a0a",
|
|
194
|
+
borderTopLeftRadius: 14,
|
|
195
|
+
borderTopRightRadius: 14,
|
|
196
|
+
overflow: "hidden",
|
|
197
|
+
zIndex: 1e3,
|
|
198
|
+
shadowColor: "#000",
|
|
199
|
+
shadowOpacity: 0.4,
|
|
200
|
+
shadowRadius: 20,
|
|
201
|
+
shadowOffset: { width: 0, height: -4 },
|
|
202
|
+
elevation: 16
|
|
203
|
+
},
|
|
204
|
+
sheetGrabber: {
|
|
205
|
+
width: 36,
|
|
206
|
+
height: 4,
|
|
207
|
+
borderRadius: 2,
|
|
208
|
+
backgroundColor: "#333",
|
|
209
|
+
alignSelf: "center",
|
|
210
|
+
marginTop: 8,
|
|
211
|
+
marginBottom: 4
|
|
212
|
+
},
|
|
213
|
+
webView: {
|
|
214
|
+
flex: 1
|
|
215
|
+
},
|
|
216
|
+
modalChrome: {
|
|
217
|
+
flexDirection: "row",
|
|
218
|
+
alignItems: "center",
|
|
219
|
+
justifyContent: "space-between",
|
|
220
|
+
paddingTop: 8,
|
|
221
|
+
paddingBottom: 12,
|
|
222
|
+
paddingHorizontal: 16,
|
|
223
|
+
backgroundColor: "#0a0a0a",
|
|
224
|
+
borderBottomWidth: import_react_native.StyleSheet.hairlineWidth,
|
|
225
|
+
borderBottomColor: "#222"
|
|
226
|
+
},
|
|
227
|
+
// Empty flex spacer keeps the close button right-aligned without
|
|
228
|
+
// a title taking up the left side. The iframe-app's flow page
|
|
229
|
+
// renders its own header inside the WebView, so a duplicate title
|
|
230
|
+
// here was redundant.
|
|
231
|
+
modalTitleSpacer: {
|
|
232
|
+
flex: 1
|
|
233
|
+
},
|
|
234
|
+
closeButton: {
|
|
235
|
+
paddingHorizontal: 8,
|
|
236
|
+
paddingVertical: 4
|
|
237
|
+
},
|
|
238
|
+
closeButtonText: {
|
|
239
|
+
color: "#3b82f6",
|
|
240
|
+
fontSize: 17,
|
|
241
|
+
fontWeight: "600"
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// src/hooks/use-export-key.ts
|
|
246
|
+
var parseExportKeyResult = (value) => {
|
|
247
|
+
if (!value || typeof value !== "object" || !("status" in value)) {
|
|
248
|
+
return { status: "failed", error: "invalid_export_key_result" };
|
|
249
|
+
}
|
|
250
|
+
const candidate = value;
|
|
251
|
+
if (candidate.status === "completed" || candidate.status === "cancelled") {
|
|
252
|
+
return { status: candidate.status };
|
|
253
|
+
}
|
|
254
|
+
if (candidate.status === "failed" && typeof candidate.error === "string") {
|
|
255
|
+
return { status: "failed", error: candidate.error };
|
|
256
|
+
}
|
|
257
|
+
return { status: "failed", error: "invalid_export_key_result" };
|
|
258
|
+
};
|
|
259
|
+
var useExportKey = () => {
|
|
260
|
+
const { sdk, _bridge, _relyingPartyOrigin, _runSensitiveFlow } = useMoonXContext();
|
|
261
|
+
return {
|
|
262
|
+
exportKey: async (wallet) => {
|
|
263
|
+
try {
|
|
264
|
+
const { userHandleB64url, credentialIdB64url, tokens } = await (0, import_sdk8.getInternalPresenceTokens)({
|
|
265
|
+
transport: _bridge,
|
|
266
|
+
passkey: createRNPasskey(),
|
|
267
|
+
publishableKey: sdk.publishableKey,
|
|
268
|
+
relyingPartyOrigin: _relyingPartyOrigin,
|
|
269
|
+
scopes: import_sdk8.SCOPES_EXPORT_KEY
|
|
270
|
+
});
|
|
271
|
+
const keyshareReadToken = tokens.keyshare_read?.token ?? "";
|
|
272
|
+
const params = new URLSearchParams({
|
|
273
|
+
publishableKey: sdk.publishableKey,
|
|
274
|
+
wallet_id: wallet.id ?? "",
|
|
275
|
+
wallet_type: wallet.wallet_type ?? ""
|
|
276
|
+
});
|
|
277
|
+
const secrets = new URLSearchParams({
|
|
278
|
+
user_handle_b64url: userHandleB64url,
|
|
279
|
+
credential_id_b64url: credentialIdB64url,
|
|
280
|
+
keyshare_read_token: keyshareReadToken
|
|
281
|
+
});
|
|
282
|
+
return await _runSensitiveFlow({
|
|
283
|
+
title: "Export key",
|
|
284
|
+
flowPath: `/export-key?${params.toString()}#${secrets.toString()}`,
|
|
285
|
+
onMount: ({ bridge, setResult }) => bridge.register(
|
|
286
|
+
import_utils5.PostMessageType.WALLET,
|
|
287
|
+
import_utils5.PostMessageMethod.EXPORT_KEY_RESULT,
|
|
288
|
+
(result) => {
|
|
289
|
+
setResult(parseExportKeyResult(result));
|
|
290
|
+
}
|
|
291
|
+
)
|
|
292
|
+
});
|
|
293
|
+
} catch (error) {
|
|
294
|
+
const message = error instanceof Error ? error.message : "export_key_failed";
|
|
295
|
+
return /cancel/i.test(message) ? { status: "cancelled" } : { status: "failed", error: message };
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
// src/hooks/use-chain-export-key.ts
|
|
302
|
+
var useChainExportKey = () => {
|
|
303
|
+
const { exportKey } = useExportKey();
|
|
304
|
+
return {
|
|
305
|
+
exportKey: ({ wallet }) => exportKey(wallet)
|
|
306
|
+
};
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
// src/hooks/use-chain-fund-wallet.ts
|
|
310
|
+
var createUseFundWallet = (walletType) => function useFundWallet2() {
|
|
311
|
+
const { sdk } = useMoonXContext();
|
|
312
|
+
return {
|
|
313
|
+
fundWallet: (address, options) => sdk.prepareFunding({ address, walletType, options })
|
|
314
|
+
};
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
// src/tron.ts
|
|
318
|
+
var useFundWallet = createUseFundWallet("tron");
|
|
319
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
320
|
+
0 && (module.exports = {
|
|
321
|
+
useCreateWallet,
|
|
322
|
+
useExportKey,
|
|
323
|
+
useFundWallet,
|
|
324
|
+
useGetBalance,
|
|
325
|
+
useImportKey,
|
|
326
|
+
useSendTransaction,
|
|
327
|
+
useSignMessage,
|
|
328
|
+
useSignTransaction,
|
|
329
|
+
useWallets
|
|
330
|
+
});
|
package/dist/tron.mjs
ADDED
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
// src/tron.ts
|
|
2
|
+
import {
|
|
3
|
+
useCreateWallet,
|
|
4
|
+
useGetBalance,
|
|
5
|
+
useImportKey,
|
|
6
|
+
useSendTransaction,
|
|
7
|
+
useSignMessage,
|
|
8
|
+
useSignTransaction,
|
|
9
|
+
useWallets
|
|
10
|
+
} from "@moon-x/core/react/tron";
|
|
11
|
+
|
|
12
|
+
// src/hooks/use-export-key.ts
|
|
13
|
+
import { getInternalPresenceTokens as getInternalPresenceTokens2, SCOPES_EXPORT_KEY } from "@moon-x/core/sdk";
|
|
14
|
+
import { PostMessageMethod as PostMessageMethod4, PostMessageType as PostMessageType4 } from "@moon-x/core/utils";
|
|
15
|
+
|
|
16
|
+
// src/provider.tsx
|
|
17
|
+
import {
|
|
18
|
+
createContext,
|
|
19
|
+
useCallback,
|
|
20
|
+
useContext,
|
|
21
|
+
useEffect,
|
|
22
|
+
useMemo,
|
|
23
|
+
useRef,
|
|
24
|
+
useState
|
|
25
|
+
} from "react";
|
|
26
|
+
import {
|
|
27
|
+
Animated,
|
|
28
|
+
AppState,
|
|
29
|
+
Platform,
|
|
30
|
+
Pressable,
|
|
31
|
+
StyleSheet,
|
|
32
|
+
Text,
|
|
33
|
+
useWindowDimensions,
|
|
34
|
+
View
|
|
35
|
+
} from "react-native";
|
|
36
|
+
import { WebView } from "react-native-webview";
|
|
37
|
+
|
|
38
|
+
// src/sdk/create-sdk-instance.ts
|
|
39
|
+
import { PostMessageMethod as PostMessageMethod2, PostMessageType as PostMessageType2 } from "@moon-x/core/utils";
|
|
40
|
+
|
|
41
|
+
// src/sdk/sdk-authentication-methods.ts
|
|
42
|
+
import { getHeadlessAuthenticationMethods } from "@moon-x/core/sdk";
|
|
43
|
+
|
|
44
|
+
// src/sdk/sdk-ethereum-methods.ts
|
|
45
|
+
import {
|
|
46
|
+
getHeadlessEthereumMethods
|
|
47
|
+
} from "@moon-x/core/sdk";
|
|
48
|
+
|
|
49
|
+
// src/platform/async-storage-kv.ts
|
|
50
|
+
import AsyncStorage from "@react-native-async-storage/async-storage";
|
|
51
|
+
|
|
52
|
+
// src/platform/rn-passkey.ts
|
|
53
|
+
import { get as passkeyGet } from "react-native-passkeys";
|
|
54
|
+
var createRNPasskey = () => ({
|
|
55
|
+
assert: async ({ rpId, challenge }) => {
|
|
56
|
+
const credential = await passkeyGet({
|
|
57
|
+
challenge,
|
|
58
|
+
rpId,
|
|
59
|
+
allowCredentials: [],
|
|
60
|
+
userVerification: "preferred"
|
|
61
|
+
});
|
|
62
|
+
if (!credential) throw new Error("passkey_assertion_cancelled");
|
|
63
|
+
const userHandle = credential.response.userHandle;
|
|
64
|
+
if (!userHandle) throw new Error("user_handle_missing");
|
|
65
|
+
return {
|
|
66
|
+
rawIdB64url: credential.rawId,
|
|
67
|
+
userHandleB64url: userHandle
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
assertForServer: async ({ optionsJSON }) => {
|
|
71
|
+
const credential = await passkeyGet({
|
|
72
|
+
challenge: optionsJSON.challenge,
|
|
73
|
+
rpId: optionsJSON.rpId,
|
|
74
|
+
allowCredentials: optionsJSON.allowCredentials ?? [],
|
|
75
|
+
userVerification: optionsJSON.userVerification ?? "preferred"
|
|
76
|
+
});
|
|
77
|
+
if (!credential) throw new Error("passkey_assertion_cancelled");
|
|
78
|
+
const sanitized = {
|
|
79
|
+
id: credential.id ?? credential.rawId,
|
|
80
|
+
rawId: credential.rawId,
|
|
81
|
+
type: credential.type ?? "public-key",
|
|
82
|
+
response: {
|
|
83
|
+
clientDataJSON: credential.response.clientDataJSON,
|
|
84
|
+
authenticatorData: credential.response.authenticatorData,
|
|
85
|
+
signature: credential.response.signature,
|
|
86
|
+
userHandle: void 0
|
|
87
|
+
},
|
|
88
|
+
clientExtensionResults: credential.clientExtensionResults ?? {},
|
|
89
|
+
authenticatorAttachment: credential.authenticatorAttachment
|
|
90
|
+
};
|
|
91
|
+
return sanitized;
|
|
92
|
+
},
|
|
93
|
+
assertForInternalPresence: async ({ optionsJSON }) => {
|
|
94
|
+
const credential = await passkeyGet({
|
|
95
|
+
challenge: optionsJSON.challenge,
|
|
96
|
+
rpId: optionsJSON.rpId,
|
|
97
|
+
allowCredentials: [],
|
|
98
|
+
userVerification: optionsJSON.userVerification ?? "preferred"
|
|
99
|
+
});
|
|
100
|
+
if (!credential) throw new Error("passkey_assertion_cancelled");
|
|
101
|
+
const userHandle = credential.response.userHandle;
|
|
102
|
+
if (!userHandle) throw new Error("user_handle_missing");
|
|
103
|
+
const sanitized = {
|
|
104
|
+
id: credential.id ?? credential.rawId,
|
|
105
|
+
rawId: credential.rawId,
|
|
106
|
+
type: credential.type ?? "public-key",
|
|
107
|
+
response: {
|
|
108
|
+
clientDataJSON: credential.response.clientDataJSON,
|
|
109
|
+
authenticatorData: credential.response.authenticatorData,
|
|
110
|
+
signature: credential.response.signature,
|
|
111
|
+
userHandle: void 0
|
|
112
|
+
},
|
|
113
|
+
clientExtensionResults: credential.clientExtensionResults ?? {},
|
|
114
|
+
authenticatorAttachment: credential.authenticatorAttachment
|
|
115
|
+
};
|
|
116
|
+
return {
|
|
117
|
+
response: sanitized,
|
|
118
|
+
userHandleB64url: userHandle,
|
|
119
|
+
credentialIdB64url: credential.rawId
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
// src/sdk/sdk-funding-methods.ts
|
|
125
|
+
import { getHeadlessFundingMethods } from "@moon-x/core/sdk";
|
|
126
|
+
|
|
127
|
+
// src/sdk/sdk-passkey-methods.ts
|
|
128
|
+
import { generatePasskeyUserId, toB64url } from "@moon-x/core/lib";
|
|
129
|
+
import {
|
|
130
|
+
flattenPresenceTokens,
|
|
131
|
+
getInternalPresenceTokens,
|
|
132
|
+
getPresenceToken,
|
|
133
|
+
SCOPES_ADD_PASSKEY
|
|
134
|
+
} from "@moon-x/core/sdk";
|
|
135
|
+
import { PostMessageMethod, PostMessageType } from "@moon-x/core/utils";
|
|
136
|
+
import { create as passkeyCreate } from "react-native-passkeys";
|
|
137
|
+
|
|
138
|
+
// src/sdk/sdk-methods.ts
|
|
139
|
+
import {
|
|
140
|
+
getHeadlessGeneralMethods
|
|
141
|
+
} from "@moon-x/core/sdk";
|
|
142
|
+
|
|
143
|
+
// src/sdk/sdk-solana-methods.ts
|
|
144
|
+
import {
|
|
145
|
+
getHeadlessSolanaMethods
|
|
146
|
+
} from "@moon-x/core/sdk";
|
|
147
|
+
|
|
148
|
+
// src/sdk/sdk-tron-methods.ts
|
|
149
|
+
import {
|
|
150
|
+
getHeadlessTronMethods
|
|
151
|
+
} from "@moon-x/core/sdk";
|
|
152
|
+
|
|
153
|
+
// src/provider.tsx
|
|
154
|
+
import { PostMessageMethod as PostMessageMethod3, PostMessageType as PostMessageType3 } from "@moon-x/core/utils";
|
|
155
|
+
|
|
156
|
+
// src/transport/webview-bridge.ts
|
|
157
|
+
import {
|
|
158
|
+
FORWARDED_ERROR_FIELDS
|
|
159
|
+
} from "@moon-x/core/utils";
|
|
160
|
+
|
|
161
|
+
// src/provider.tsx
|
|
162
|
+
import { SDKProvider } from "@moon-x/core/react";
|
|
163
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
164
|
+
var MoonXContext = createContext(null);
|
|
165
|
+
var useMoonXContext = () => {
|
|
166
|
+
const ctx = useContext(MoonXContext);
|
|
167
|
+
if (!ctx) {
|
|
168
|
+
throw new Error("useMoonX must be used within a MoonXProvider");
|
|
169
|
+
}
|
|
170
|
+
return ctx;
|
|
171
|
+
};
|
|
172
|
+
var styles = StyleSheet.create({
|
|
173
|
+
backdrop: {
|
|
174
|
+
position: "absolute",
|
|
175
|
+
top: 0,
|
|
176
|
+
bottom: 0,
|
|
177
|
+
left: 0,
|
|
178
|
+
right: 0,
|
|
179
|
+
backgroundColor: "#000",
|
|
180
|
+
zIndex: 999
|
|
181
|
+
},
|
|
182
|
+
// Sheet-style container: rendered as a card that slides up from the
|
|
183
|
+
// bottom. `top` is set inline by the provider to leave room above
|
|
184
|
+
// for the host app's content visible through the dimmed backdrop.
|
|
185
|
+
// `bottom: 0` so the WebView fills the remaining height.
|
|
186
|
+
sheetContainer: {
|
|
187
|
+
position: "absolute",
|
|
188
|
+
bottom: 0,
|
|
189
|
+
left: 0,
|
|
190
|
+
right: 0,
|
|
191
|
+
backgroundColor: "#0a0a0a",
|
|
192
|
+
borderTopLeftRadius: 14,
|
|
193
|
+
borderTopRightRadius: 14,
|
|
194
|
+
overflow: "hidden",
|
|
195
|
+
zIndex: 1e3,
|
|
196
|
+
shadowColor: "#000",
|
|
197
|
+
shadowOpacity: 0.4,
|
|
198
|
+
shadowRadius: 20,
|
|
199
|
+
shadowOffset: { width: 0, height: -4 },
|
|
200
|
+
elevation: 16
|
|
201
|
+
},
|
|
202
|
+
sheetGrabber: {
|
|
203
|
+
width: 36,
|
|
204
|
+
height: 4,
|
|
205
|
+
borderRadius: 2,
|
|
206
|
+
backgroundColor: "#333",
|
|
207
|
+
alignSelf: "center",
|
|
208
|
+
marginTop: 8,
|
|
209
|
+
marginBottom: 4
|
|
210
|
+
},
|
|
211
|
+
webView: {
|
|
212
|
+
flex: 1
|
|
213
|
+
},
|
|
214
|
+
modalChrome: {
|
|
215
|
+
flexDirection: "row",
|
|
216
|
+
alignItems: "center",
|
|
217
|
+
justifyContent: "space-between",
|
|
218
|
+
paddingTop: 8,
|
|
219
|
+
paddingBottom: 12,
|
|
220
|
+
paddingHorizontal: 16,
|
|
221
|
+
backgroundColor: "#0a0a0a",
|
|
222
|
+
borderBottomWidth: StyleSheet.hairlineWidth,
|
|
223
|
+
borderBottomColor: "#222"
|
|
224
|
+
},
|
|
225
|
+
// Empty flex spacer keeps the close button right-aligned without
|
|
226
|
+
// a title taking up the left side. The iframe-app's flow page
|
|
227
|
+
// renders its own header inside the WebView, so a duplicate title
|
|
228
|
+
// here was redundant.
|
|
229
|
+
modalTitleSpacer: {
|
|
230
|
+
flex: 1
|
|
231
|
+
},
|
|
232
|
+
closeButton: {
|
|
233
|
+
paddingHorizontal: 8,
|
|
234
|
+
paddingVertical: 4
|
|
235
|
+
},
|
|
236
|
+
closeButtonText: {
|
|
237
|
+
color: "#3b82f6",
|
|
238
|
+
fontSize: 17,
|
|
239
|
+
fontWeight: "600"
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
// src/hooks/use-export-key.ts
|
|
244
|
+
var parseExportKeyResult = (value) => {
|
|
245
|
+
if (!value || typeof value !== "object" || !("status" in value)) {
|
|
246
|
+
return { status: "failed", error: "invalid_export_key_result" };
|
|
247
|
+
}
|
|
248
|
+
const candidate = value;
|
|
249
|
+
if (candidate.status === "completed" || candidate.status === "cancelled") {
|
|
250
|
+
return { status: candidate.status };
|
|
251
|
+
}
|
|
252
|
+
if (candidate.status === "failed" && typeof candidate.error === "string") {
|
|
253
|
+
return { status: "failed", error: candidate.error };
|
|
254
|
+
}
|
|
255
|
+
return { status: "failed", error: "invalid_export_key_result" };
|
|
256
|
+
};
|
|
257
|
+
var useExportKey = () => {
|
|
258
|
+
const { sdk, _bridge, _relyingPartyOrigin, _runSensitiveFlow } = useMoonXContext();
|
|
259
|
+
return {
|
|
260
|
+
exportKey: async (wallet) => {
|
|
261
|
+
try {
|
|
262
|
+
const { userHandleB64url, credentialIdB64url, tokens } = await getInternalPresenceTokens2({
|
|
263
|
+
transport: _bridge,
|
|
264
|
+
passkey: createRNPasskey(),
|
|
265
|
+
publishableKey: sdk.publishableKey,
|
|
266
|
+
relyingPartyOrigin: _relyingPartyOrigin,
|
|
267
|
+
scopes: SCOPES_EXPORT_KEY
|
|
268
|
+
});
|
|
269
|
+
const keyshareReadToken = tokens.keyshare_read?.token ?? "";
|
|
270
|
+
const params = new URLSearchParams({
|
|
271
|
+
publishableKey: sdk.publishableKey,
|
|
272
|
+
wallet_id: wallet.id ?? "",
|
|
273
|
+
wallet_type: wallet.wallet_type ?? ""
|
|
274
|
+
});
|
|
275
|
+
const secrets = new URLSearchParams({
|
|
276
|
+
user_handle_b64url: userHandleB64url,
|
|
277
|
+
credential_id_b64url: credentialIdB64url,
|
|
278
|
+
keyshare_read_token: keyshareReadToken
|
|
279
|
+
});
|
|
280
|
+
return await _runSensitiveFlow({
|
|
281
|
+
title: "Export key",
|
|
282
|
+
flowPath: `/export-key?${params.toString()}#${secrets.toString()}`,
|
|
283
|
+
onMount: ({ bridge, setResult }) => bridge.register(
|
|
284
|
+
PostMessageType4.WALLET,
|
|
285
|
+
PostMessageMethod4.EXPORT_KEY_RESULT,
|
|
286
|
+
(result) => {
|
|
287
|
+
setResult(parseExportKeyResult(result));
|
|
288
|
+
}
|
|
289
|
+
)
|
|
290
|
+
});
|
|
291
|
+
} catch (error) {
|
|
292
|
+
const message = error instanceof Error ? error.message : "export_key_failed";
|
|
293
|
+
return /cancel/i.test(message) ? { status: "cancelled" } : { status: "failed", error: message };
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
|
|
299
|
+
// src/hooks/use-chain-export-key.ts
|
|
300
|
+
var useChainExportKey = () => {
|
|
301
|
+
const { exportKey } = useExportKey();
|
|
302
|
+
return {
|
|
303
|
+
exportKey: ({ wallet }) => exportKey(wallet)
|
|
304
|
+
};
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
// src/hooks/use-chain-fund-wallet.ts
|
|
308
|
+
var createUseFundWallet = (walletType) => function useFundWallet2() {
|
|
309
|
+
const { sdk } = useMoonXContext();
|
|
310
|
+
return {
|
|
311
|
+
fundWallet: (address, options) => sdk.prepareFunding({ address, walletType, options })
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
// src/tron.ts
|
|
316
|
+
var useFundWallet = createUseFundWallet("tron");
|
|
317
|
+
export {
|
|
318
|
+
useCreateWallet,
|
|
319
|
+
useChainExportKey as useExportKey,
|
|
320
|
+
useFundWallet,
|
|
321
|
+
useGetBalance,
|
|
322
|
+
useImportKey,
|
|
323
|
+
useSendTransaction,
|
|
324
|
+
useSignMessage,
|
|
325
|
+
useSignTransaction,
|
|
326
|
+
useWallets
|
|
327
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { E as ExportKeyResult } from './use-export-key-BIz_tV0k.mjs';
|
|
2
|
+
import { PublicWallet } from '@moon-x/core/types';
|
|
3
|
+
|
|
4
|
+
/** Chain-subpath facade matching the web SDK's `{ wallet }` call shape. */
|
|
5
|
+
declare const useChainExportKey: () => {
|
|
6
|
+
exportKey: ({ wallet }: {
|
|
7
|
+
wallet: PublicWallet;
|
|
8
|
+
}) => Promise<ExportKeyResult>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { useChainExportKey as u };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { E as ExportKeyResult } from './use-export-key-BIz_tV0k.js';
|
|
2
|
+
import { PublicWallet } from '@moon-x/core/types';
|
|
3
|
+
|
|
4
|
+
/** Chain-subpath facade matching the web SDK's `{ wallet }` call shape. */
|
|
5
|
+
declare const useChainExportKey: () => {
|
|
6
|
+
exportKey: ({ wallet }: {
|
|
7
|
+
wallet: PublicWallet;
|
|
8
|
+
}) => Promise<ExportKeyResult>;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { useChainExportKey as u };
|