@moon-x/react-native-sdk 0.12.0 → 0.13.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/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 +18 -10
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
# @moon-x/react-native-sdk
|
|
2
2
|
|
|
3
|
-
React Native SDK for [MoonX](https://moonx.com)
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Headless React Native SDK for [MoonX](https://moonx.com). Applications own
|
|
4
|
+
their authentication, wallet, funding, connection, and signing UI; the SDK
|
|
5
|
+
provides hooks, native ceremonies, session state, wallet operations, and a
|
|
6
|
+
WebView-backed trust boundary.
|
|
6
7
|
|
|
7
8
|
## Install
|
|
8
9
|
|
|
@@ -119,25 +120,33 @@ and per-call `requireFreshAssertion` flag were removed entirely when
|
|
|
119
120
|
presence-token gating shipped — they are no longer on the public
|
|
120
121
|
TypeScript surface. Every op is always-fresh by construction.
|
|
121
122
|
|
|
122
|
-
> **Note on RN-side migration status:** as of this writing the RN
|
|
123
|
-
> add-passkey (`sdk-passkey-methods.ts`) and export-key
|
|
124
|
-
> (`use-export-key.ts`) flows still use the older parent-only
|
|
125
|
-
> assertion path. The web SDK is fully migrated to the presence-token
|
|
126
|
-
> orchestrator; RN parity is on the to-do list.
|
|
127
|
-
|
|
128
123
|
## Hooks
|
|
129
124
|
|
|
130
125
|
### Authentication & user state
|
|
131
126
|
|
|
132
127
|
| Hook | What it does |
|
|
133
128
|
|---|---|
|
|
134
|
-
| `useMoonX()` | The
|
|
129
|
+
| `useMoonX()` | The active headless SDK instance: `{ ready, isAuthenticated, user, logout, getSessionTokens, refreshUser, ... }`. Web-only `start`, modal, and appearance methods are intentionally absent. |
|
|
135
130
|
| `useUser()` | Just `{ user, refreshUser }`. Re-subscribes to user changes. |
|
|
136
131
|
| `useLoginWithEmail({ onComplete?, onError? })` | Headless email-OTP. Returns `{ state, sendCode, loginWithCode, reset }`. `state` is a discriminated union: `idle` / `sending` / `awaiting-code` / `verifying` / `complete` / `error`. |
|
|
137
132
|
| `useLoginWithOAuth()` | Google + Apple flows via `expo-web-browser`. Returns `{ state, loginWithOAuth, reset }`. |
|
|
138
133
|
| `useLogout()` | `{ logout }` — also clears AsyncStorage + WebView session. |
|
|
139
134
|
| `useAttachOAuth()` / `useDetachOAuth()` | Link / unlink an OAuth provider on an existing user. |
|
|
140
135
|
|
|
136
|
+
`getSessionTokens()` returns `{ accessToken, identityToken, expiresAt }` or
|
|
137
|
+
`null`. Refresh tokens remain inside the WebView and are never exposed to the
|
|
138
|
+
host application.
|
|
139
|
+
|
|
140
|
+
`getCurrentSession()` returns the current session or `null` when the WebView
|
|
141
|
+
authoritatively reports that no session exists. It rejects on bridge/transport
|
|
142
|
+
failures. Callers that poll it directly should catch those failures and retain
|
|
143
|
+
their last-known auth state rather than treating an unavailable WebView as a
|
|
144
|
+
logout. This distinction was introduced with `@moon-x/core` 0.15.0.
|
|
145
|
+
|
|
146
|
+
The provider revalidates its hidden-WebView session on cold start and whenever
|
|
147
|
+
the native app returns to the foreground. `revalidatedAt` advances after each
|
|
148
|
+
probe so shared wallet hooks refresh app-owned wallet state.
|
|
149
|
+
|
|
141
150
|
### Passkeys
|
|
142
151
|
|
|
143
152
|
| Hook | What it does |
|
|
@@ -151,19 +160,56 @@ TypeScript surface. Every op is always-fresh by construction.
|
|
|
151
160
|
|
|
152
161
|
| Hook | What it does |
|
|
153
162
|
|---|---|
|
|
154
|
-
| `useWallets()` |
|
|
155
|
-
| `useCreateWallet()` |
|
|
163
|
+
| `useWallets(walletType)` | Generic chain-aware list hook for Ethereum, Solana, or Tron. Chain subpaths provide pinned `useWallets()` variants. |
|
|
164
|
+
| `useCreateWallet()` | Generic top-level lifecycle hook; chain subpaths provide pinned variants. |
|
|
156
165
|
| `useImportKey()` | Bring-your-own-key flow. |
|
|
157
166
|
| `useExportKey()` | Show the user their private key via the visible-WebView modal pattern (see below). Plaintext never leaves the WebView's DOM. |
|
|
158
167
|
| `useEphemeralSigner()` | Manage the user's WaaS ephemeral signers (SES) end-to-end. Returns `{ signers, isLoading, refresh, provision, revoke, lastProvisioned, error, reset, ... }`. Auto-refreshes the list after provision/revoke. |
|
|
159
168
|
|
|
160
|
-
|
|
169
|
+
The main entry and chain subpaths deliberately use different wallet-lifecycle
|
|
170
|
+
call shapes. The main entry is generic and takes an explicit chain; subpaths
|
|
171
|
+
pin the chain and match the web SDK facades:
|
|
172
|
+
|
|
173
|
+
| Import | Call | Result |
|
|
174
|
+
|---|---|---|
|
|
175
|
+
| Main entry | `importKey(walletType, key)` | `{ wallet: PublicWallet }` |
|
|
176
|
+
| `/ethereum`, `/solana`, `/tron` | `importKey(key)` | `PublicWallet` |
|
|
177
|
+
|
|
178
|
+
| Export | Call |
|
|
179
|
+
|---|---|
|
|
180
|
+
| Main entry | `exportKey(wallet)` |
|
|
181
|
+
| `/ethereum`, `/solana`, `/tron` | `exportKey({ wallet })` |
|
|
182
|
+
|
|
183
|
+
```ts
|
|
184
|
+
import {
|
|
185
|
+
useExportKey as useGenericExportKey,
|
|
186
|
+
useImportKey as useGenericImportKey,
|
|
187
|
+
} from "@moon-x/react-native-sdk";
|
|
188
|
+
import {
|
|
189
|
+
useExportKey as useEthereumExportKey,
|
|
190
|
+
useImportKey as useEthereumImportKey,
|
|
191
|
+
} from "@moon-x/react-native-sdk/ethereum";
|
|
192
|
+
|
|
193
|
+
const { importKey: importGeneric } = useGenericImportKey();
|
|
194
|
+
const { exportKey: exportGeneric } = useGenericExportKey();
|
|
195
|
+
const { importKey: importEthereum } = useEthereumImportKey();
|
|
196
|
+
const { exportKey: exportEthereum } = useEthereumExportKey();
|
|
197
|
+
|
|
198
|
+
const { wallet } = await importGeneric("ethereum", privateKey);
|
|
199
|
+
await exportGeneric(wallet);
|
|
200
|
+
|
|
201
|
+
const ethereumWallet = await importEthereum(privateKey);
|
|
202
|
+
await exportEthereum({ wallet: ethereumWallet });
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Per-chain wallets and signing — `/ethereum`, `/solana`, and `/tron`
|
|
161
206
|
|
|
162
207
|
Chain-aware hooks live under subpaths so they don't pull in the other chain's adapters if you only use one — same pattern as `@moon-x/react-sdk`:
|
|
163
208
|
|
|
164
209
|
```tsx
|
|
165
210
|
import { useSignMessage, useSignTransaction, useSendTransaction } from "@moon-x/react-native-sdk/ethereum";
|
|
166
211
|
import { useSignMessage as useSignSolanaMessage } from "@moon-x/react-native-sdk/solana";
|
|
212
|
+
import { useGetBalance as useTronBalance } from "@moon-x/react-native-sdk/tron";
|
|
167
213
|
```
|
|
168
214
|
|
|
169
215
|
**Ethereum hooks:**
|
|
@@ -180,26 +226,91 @@ import { useSignMessage as useSignSolanaMessage } from "@moon-x/react-native-sdk
|
|
|
180
226
|
- `useSignTransaction` — Signs a serialized base58 tx. Returns `{ signedTransaction: Uint8Array }`.
|
|
181
227
|
- `useSendTransaction` — Sign + broadcast.
|
|
182
228
|
- `useGetBalance` — Lamport balance.
|
|
229
|
+
- `useGetTokenAccounts` — SPL token accounts owned by the wallet.
|
|
230
|
+
|
|
231
|
+
**Tron hooks:**
|
|
232
|
+
- `useSignMessage` — TIP-191 message signing.
|
|
233
|
+
- `useSignTransaction` — signs a TronWeb transaction JSON object.
|
|
234
|
+
- `useSendTransaction` — signs and submits through the supplied fullnode URL.
|
|
235
|
+
- `useGetBalance` — native TRX balance.
|
|
236
|
+
|
|
237
|
+
All three subpaths also expose chain-pinned `useCreateWallet`, `useWallets`,
|
|
238
|
+
`useImportKey`, `useExportKey`, and `useFundWallet` hooks.
|
|
239
|
+
|
|
240
|
+
Sign, send, balance, and token-account results use the same wire contract as
|
|
241
|
+
the web SDK.
|
|
242
|
+
|
|
243
|
+
### Headless funding
|
|
244
|
+
|
|
245
|
+
`useFundWallet` returns the provider session instead of opening UI. Present the
|
|
246
|
+
returned URL in your own native or in-app browser:
|
|
247
|
+
|
|
248
|
+
```ts
|
|
249
|
+
import * as WebBrowser from "expo-web-browser";
|
|
250
|
+
import { useFundWallet } from "@moon-x/react-native-sdk/ethereum";
|
|
251
|
+
|
|
252
|
+
const { fundWallet } = useFundWallet();
|
|
253
|
+
const session = await fundWallet(wallet.public_address, {
|
|
254
|
+
chain: { id: 8453 },
|
|
255
|
+
amount: "25",
|
|
256
|
+
});
|
|
257
|
+
await WebBrowser.openBrowserAsync(session.url);
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### External wallets and WalletConnect
|
|
261
|
+
|
|
262
|
+
`useExternalWallets(connectors)` orchestrates host-supplied native wallet
|
|
263
|
+
connectors without rendering a picker. It exposes discovery, connection,
|
|
264
|
+
disconnection, account switching, and the connected wallet's signing/request
|
|
265
|
+
methods.
|
|
266
|
+
|
|
267
|
+
For WalletConnect, initialize a v2 SignClient in the host app and pass it to
|
|
268
|
+
`connectWalletConnect`. The SDK returns a pairing URI and approval promise;
|
|
269
|
+
the host owns QR/deep-link presentation:
|
|
270
|
+
|
|
271
|
+
```ts
|
|
272
|
+
import { connectWalletConnect } from "@moon-x/react-native-sdk";
|
|
273
|
+
|
|
274
|
+
const pairing = await connectWalletConnect({
|
|
275
|
+
client,
|
|
276
|
+
requiredNamespaces: {
|
|
277
|
+
eip155: {
|
|
278
|
+
chains: ["eip155:8453"],
|
|
279
|
+
methods: ["personal_sign", "eth_sendTransaction"],
|
|
280
|
+
events: ["accountsChanged", "chainChanged"],
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
if (pairing.uri) presentPairingUri(pairing.uri);
|
|
286
|
+
const wallet = await pairing.approval();
|
|
287
|
+
const signature = await wallet.signMessage?.("hello");
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
`pairing.uri` is optional because WalletConnect may approve from an existing
|
|
291
|
+
pairing without returning a new URI.
|
|
183
292
|
|
|
184
|
-
|
|
293
|
+
Use `listWalletConnectSessions` and `restoreWalletConnectSession` to discover
|
|
294
|
+
and restore approved sessions after a native app restart.
|
|
185
295
|
|
|
186
296
|
### Mobile-specific notes
|
|
187
297
|
|
|
188
|
-
- **No
|
|
298
|
+
- **No SDK-owned wallet picker.** External-wallet and WalletConnect primitives are headless; presentation stays in the host app.
|
|
189
299
|
- **`useExportKey` is a top-level hook on RN.** On web the same operation hangs off `useMoonX().exportKey()` inside a parent-side modal; on RN it toggles the always-mounted WebView into a full-screen visible state so the iframe-app renders the key UI itself.
|
|
190
300
|
|
|
191
301
|
## Visible-WebView pattern (sensitive flows)
|
|
192
302
|
|
|
193
|
-
`useExportKey`
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
303
|
+
`useExportKey` temporarily moves the always-mounted WebView from off-screen to
|
|
304
|
+
a full-screen view so the iframe-app can render the secret-sequestration UI.
|
|
305
|
+
The plaintext key never leaves the WebView's DOM — RN-side JS only sees the
|
|
306
|
+
terminal status and rendered pixels.
|
|
197
307
|
|
|
198
308
|
The hook surface is still headless from the consumer's perspective:
|
|
199
309
|
|
|
200
310
|
```ts
|
|
201
311
|
const { exportKey } = useExportKey();
|
|
202
|
-
await exportKey(wallet);
|
|
312
|
+
const result = await exportKey(wallet);
|
|
313
|
+
// { status: "completed" | "cancelled" | "failed", error?: string }
|
|
203
314
|
```
|
|
204
315
|
|
|
205
316
|
## Native config
|
|
@@ -438,13 +549,10 @@ rejects with `error validating origin`.
|
|
|
438
549
|
- Hermes is the supported JS engine. JSC will work for non-passkey
|
|
439
550
|
flows but isn't tested.
|
|
440
551
|
|
|
441
|
-
##
|
|
552
|
+
## Intentionally unsupported
|
|
442
553
|
|
|
443
|
-
- WalletConnect / external-wallet connectors
|
|
444
554
|
- "WithUI" SDK method variants (web-only — RN is headless)
|
|
445
|
-
-
|
|
446
|
-
user-dismiss (currently the modal's close button resolves the
|
|
447
|
-
promise; the post-back contract is a planned follow-up)
|
|
555
|
+
- React appearance/theming and auth/signing modals
|
|
448
556
|
- RN-mode bundle-ID origin whitelist on the iframe-app
|
|
449
557
|
(`window.ReactNativeWebView`-mode currently bypasses origin
|
|
450
558
|
whitelisting; publishableKey + session JWT are the gates in v1)
|
package/dist/ethereum.d.mts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as _moon_x_core_types from '@moon-x/core/types';
|
|
2
|
+
export { useCreateWallet, useGetBalance, useImportKey, useSendTransaction, useSign7702Authorization, useSignHash, useSignMessage, useSignTransaction, useSignTypedData, useWallets } from '@moon-x/core/react/ethereum';
|
|
3
|
+
export { u as useExportKey } from './use-chain-export-key-C4vTffjx.mjs';
|
|
4
|
+
import './use-export-key-BIz_tV0k.mjs';
|
|
5
|
+
|
|
6
|
+
declare const useFundWallet: () => {
|
|
7
|
+
fundWallet: (address: string, options?: _moon_x_core_types.EthereumFundingConfig | undefined) => Promise<_moon_x_core_types.FundingSession>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { useFundWallet };
|
package/dist/ethereum.d.ts
CHANGED
|
@@ -1,2 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import * as _moon_x_core_types from '@moon-x/core/types';
|
|
2
|
+
export { useCreateWallet, useGetBalance, useImportKey, useSendTransaction, useSign7702Authorization, useSignHash, useSignMessage, useSignTransaction, useSignTypedData, useWallets } from '@moon-x/core/react/ethereum';
|
|
3
|
+
export { u as useExportKey } from './use-chain-export-key-C7zBt98X.js';
|
|
4
|
+
import './use-export-key-BIz_tV0k.js';
|
|
5
|
+
|
|
6
|
+
declare const useFundWallet: () => {
|
|
7
|
+
fundWallet: (address: string, options?: _moon_x_core_types.EthereumFundingConfig | undefined) => Promise<_moon_x_core_types.FundingSession>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export { useFundWallet };
|
package/dist/ethereum.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,28 +17,320 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
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
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/ethereum.ts
|
|
21
31
|
var ethereum_exports = {};
|
|
22
32
|
__export(ethereum_exports, {
|
|
33
|
+
useCreateWallet: () => import_ethereum.useCreateWallet,
|
|
34
|
+
useExportKey: () => useChainExportKey,
|
|
35
|
+
useFundWallet: () => useFundWallet,
|
|
23
36
|
useGetBalance: () => import_ethereum.useGetBalance,
|
|
37
|
+
useImportKey: () => import_ethereum.useImportKey,
|
|
24
38
|
useSendTransaction: () => import_ethereum.useSendTransaction,
|
|
25
39
|
useSign7702Authorization: () => import_ethereum.useSign7702Authorization,
|
|
26
40
|
useSignHash: () => import_ethereum.useSignHash,
|
|
27
41
|
useSignMessage: () => import_ethereum.useSignMessage,
|
|
28
42
|
useSignTransaction: () => import_ethereum.useSignTransaction,
|
|
29
|
-
useSignTypedData: () => import_ethereum.useSignTypedData
|
|
43
|
+
useSignTypedData: () => import_ethereum.useSignTypedData,
|
|
44
|
+
useWallets: () => import_ethereum.useWallets
|
|
30
45
|
});
|
|
31
46
|
module.exports = __toCommonJS(ethereum_exports);
|
|
32
47
|
var import_ethereum = require("@moon-x/core/react/ethereum");
|
|
48
|
+
|
|
49
|
+
// src/hooks/use-export-key.ts
|
|
50
|
+
var import_sdk8 = require("@moon-x/core/sdk");
|
|
51
|
+
var import_utils5 = require("@moon-x/core/utils");
|
|
52
|
+
|
|
53
|
+
// src/provider.tsx
|
|
54
|
+
var import_react = require("react");
|
|
55
|
+
var import_react_native = require("react-native");
|
|
56
|
+
var import_react_native_webview = require("react-native-webview");
|
|
57
|
+
|
|
58
|
+
// src/sdk/create-sdk-instance.ts
|
|
59
|
+
var import_utils2 = require("@moon-x/core/utils");
|
|
60
|
+
|
|
61
|
+
// src/sdk/sdk-authentication-methods.ts
|
|
62
|
+
var import_sdk = require("@moon-x/core/sdk");
|
|
63
|
+
|
|
64
|
+
// src/sdk/sdk-ethereum-methods.ts
|
|
65
|
+
var import_sdk2 = require("@moon-x/core/sdk");
|
|
66
|
+
|
|
67
|
+
// src/platform/async-storage-kv.ts
|
|
68
|
+
var import_async_storage = __toESM(require("@react-native-async-storage/async-storage"));
|
|
69
|
+
|
|
70
|
+
// src/platform/rn-passkey.ts
|
|
71
|
+
var import_react_native_passkeys = require("react-native-passkeys");
|
|
72
|
+
var createRNPasskey = () => ({
|
|
73
|
+
assert: async ({ rpId, challenge }) => {
|
|
74
|
+
const credential = await (0, import_react_native_passkeys.get)({
|
|
75
|
+
challenge,
|
|
76
|
+
rpId,
|
|
77
|
+
allowCredentials: [],
|
|
78
|
+
userVerification: "preferred"
|
|
79
|
+
});
|
|
80
|
+
if (!credential) throw new Error("passkey_assertion_cancelled");
|
|
81
|
+
const userHandle = credential.response.userHandle;
|
|
82
|
+
if (!userHandle) throw new Error("user_handle_missing");
|
|
83
|
+
return {
|
|
84
|
+
rawIdB64url: credential.rawId,
|
|
85
|
+
userHandleB64url: userHandle
|
|
86
|
+
};
|
|
87
|
+
},
|
|
88
|
+
assertForServer: async ({ optionsJSON }) => {
|
|
89
|
+
const credential = await (0, import_react_native_passkeys.get)({
|
|
90
|
+
challenge: optionsJSON.challenge,
|
|
91
|
+
rpId: optionsJSON.rpId,
|
|
92
|
+
allowCredentials: optionsJSON.allowCredentials ?? [],
|
|
93
|
+
userVerification: optionsJSON.userVerification ?? "preferred"
|
|
94
|
+
});
|
|
95
|
+
if (!credential) throw new Error("passkey_assertion_cancelled");
|
|
96
|
+
const sanitized = {
|
|
97
|
+
id: credential.id ?? credential.rawId,
|
|
98
|
+
rawId: credential.rawId,
|
|
99
|
+
type: credential.type ?? "public-key",
|
|
100
|
+
response: {
|
|
101
|
+
clientDataJSON: credential.response.clientDataJSON,
|
|
102
|
+
authenticatorData: credential.response.authenticatorData,
|
|
103
|
+
signature: credential.response.signature,
|
|
104
|
+
userHandle: void 0
|
|
105
|
+
},
|
|
106
|
+
clientExtensionResults: credential.clientExtensionResults ?? {},
|
|
107
|
+
authenticatorAttachment: credential.authenticatorAttachment
|
|
108
|
+
};
|
|
109
|
+
return sanitized;
|
|
110
|
+
},
|
|
111
|
+
assertForInternalPresence: async ({ optionsJSON }) => {
|
|
112
|
+
const credential = await (0, import_react_native_passkeys.get)({
|
|
113
|
+
challenge: optionsJSON.challenge,
|
|
114
|
+
rpId: optionsJSON.rpId,
|
|
115
|
+
allowCredentials: [],
|
|
116
|
+
userVerification: optionsJSON.userVerification ?? "preferred"
|
|
117
|
+
});
|
|
118
|
+
if (!credential) throw new Error("passkey_assertion_cancelled");
|
|
119
|
+
const userHandle = credential.response.userHandle;
|
|
120
|
+
if (!userHandle) throw new Error("user_handle_missing");
|
|
121
|
+
const sanitized = {
|
|
122
|
+
id: credential.id ?? credential.rawId,
|
|
123
|
+
rawId: credential.rawId,
|
|
124
|
+
type: credential.type ?? "public-key",
|
|
125
|
+
response: {
|
|
126
|
+
clientDataJSON: credential.response.clientDataJSON,
|
|
127
|
+
authenticatorData: credential.response.authenticatorData,
|
|
128
|
+
signature: credential.response.signature,
|
|
129
|
+
userHandle: void 0
|
|
130
|
+
},
|
|
131
|
+
clientExtensionResults: credential.clientExtensionResults ?? {},
|
|
132
|
+
authenticatorAttachment: credential.authenticatorAttachment
|
|
133
|
+
};
|
|
134
|
+
return {
|
|
135
|
+
response: sanitized,
|
|
136
|
+
userHandleB64url: userHandle,
|
|
137
|
+
credentialIdB64url: credential.rawId
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// src/sdk/sdk-funding-methods.ts
|
|
143
|
+
var import_sdk3 = require("@moon-x/core/sdk");
|
|
144
|
+
|
|
145
|
+
// src/sdk/sdk-passkey-methods.ts
|
|
146
|
+
var import_lib = require("@moon-x/core/lib");
|
|
147
|
+
var import_sdk4 = require("@moon-x/core/sdk");
|
|
148
|
+
var import_utils = require("@moon-x/core/utils");
|
|
149
|
+
var import_react_native_passkeys2 = require("react-native-passkeys");
|
|
150
|
+
|
|
151
|
+
// src/sdk/sdk-methods.ts
|
|
152
|
+
var import_sdk5 = require("@moon-x/core/sdk");
|
|
153
|
+
|
|
154
|
+
// src/sdk/sdk-solana-methods.ts
|
|
155
|
+
var import_sdk6 = require("@moon-x/core/sdk");
|
|
156
|
+
|
|
157
|
+
// src/sdk/sdk-tron-methods.ts
|
|
158
|
+
var import_sdk7 = require("@moon-x/core/sdk");
|
|
159
|
+
|
|
160
|
+
// src/provider.tsx
|
|
161
|
+
var import_utils4 = require("@moon-x/core/utils");
|
|
162
|
+
|
|
163
|
+
// src/transport/webview-bridge.ts
|
|
164
|
+
var import_utils3 = require("@moon-x/core/utils");
|
|
165
|
+
|
|
166
|
+
// src/provider.tsx
|
|
167
|
+
var import_react2 = require("@moon-x/core/react");
|
|
168
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
169
|
+
var MoonXContext = (0, import_react.createContext)(null);
|
|
170
|
+
var useMoonXContext = () => {
|
|
171
|
+
const ctx = (0, import_react.useContext)(MoonXContext);
|
|
172
|
+
if (!ctx) {
|
|
173
|
+
throw new Error("useMoonX must be used within a MoonXProvider");
|
|
174
|
+
}
|
|
175
|
+
return ctx;
|
|
176
|
+
};
|
|
177
|
+
var styles = import_react_native.StyleSheet.create({
|
|
178
|
+
backdrop: {
|
|
179
|
+
position: "absolute",
|
|
180
|
+
top: 0,
|
|
181
|
+
bottom: 0,
|
|
182
|
+
left: 0,
|
|
183
|
+
right: 0,
|
|
184
|
+
backgroundColor: "#000",
|
|
185
|
+
zIndex: 999
|
|
186
|
+
},
|
|
187
|
+
// Sheet-style container: rendered as a card that slides up from the
|
|
188
|
+
// bottom. `top` is set inline by the provider to leave room above
|
|
189
|
+
// for the host app's content visible through the dimmed backdrop.
|
|
190
|
+
// `bottom: 0` so the WebView fills the remaining height.
|
|
191
|
+
sheetContainer: {
|
|
192
|
+
position: "absolute",
|
|
193
|
+
bottom: 0,
|
|
194
|
+
left: 0,
|
|
195
|
+
right: 0,
|
|
196
|
+
backgroundColor: "#0a0a0a",
|
|
197
|
+
borderTopLeftRadius: 14,
|
|
198
|
+
borderTopRightRadius: 14,
|
|
199
|
+
overflow: "hidden",
|
|
200
|
+
zIndex: 1e3,
|
|
201
|
+
shadowColor: "#000",
|
|
202
|
+
shadowOpacity: 0.4,
|
|
203
|
+
shadowRadius: 20,
|
|
204
|
+
shadowOffset: { width: 0, height: -4 },
|
|
205
|
+
elevation: 16
|
|
206
|
+
},
|
|
207
|
+
sheetGrabber: {
|
|
208
|
+
width: 36,
|
|
209
|
+
height: 4,
|
|
210
|
+
borderRadius: 2,
|
|
211
|
+
backgroundColor: "#333",
|
|
212
|
+
alignSelf: "center",
|
|
213
|
+
marginTop: 8,
|
|
214
|
+
marginBottom: 4
|
|
215
|
+
},
|
|
216
|
+
webView: {
|
|
217
|
+
flex: 1
|
|
218
|
+
},
|
|
219
|
+
modalChrome: {
|
|
220
|
+
flexDirection: "row",
|
|
221
|
+
alignItems: "center",
|
|
222
|
+
justifyContent: "space-between",
|
|
223
|
+
paddingTop: 8,
|
|
224
|
+
paddingBottom: 12,
|
|
225
|
+
paddingHorizontal: 16,
|
|
226
|
+
backgroundColor: "#0a0a0a",
|
|
227
|
+
borderBottomWidth: import_react_native.StyleSheet.hairlineWidth,
|
|
228
|
+
borderBottomColor: "#222"
|
|
229
|
+
},
|
|
230
|
+
// Empty flex spacer keeps the close button right-aligned without
|
|
231
|
+
// a title taking up the left side. The iframe-app's flow page
|
|
232
|
+
// renders its own header inside the WebView, so a duplicate title
|
|
233
|
+
// here was redundant.
|
|
234
|
+
modalTitleSpacer: {
|
|
235
|
+
flex: 1
|
|
236
|
+
},
|
|
237
|
+
closeButton: {
|
|
238
|
+
paddingHorizontal: 8,
|
|
239
|
+
paddingVertical: 4
|
|
240
|
+
},
|
|
241
|
+
closeButtonText: {
|
|
242
|
+
color: "#3b82f6",
|
|
243
|
+
fontSize: 17,
|
|
244
|
+
fontWeight: "600"
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// src/hooks/use-export-key.ts
|
|
249
|
+
var parseExportKeyResult = (value) => {
|
|
250
|
+
if (!value || typeof value !== "object" || !("status" in value)) {
|
|
251
|
+
return { status: "failed", error: "invalid_export_key_result" };
|
|
252
|
+
}
|
|
253
|
+
const candidate = value;
|
|
254
|
+
if (candidate.status === "completed" || candidate.status === "cancelled") {
|
|
255
|
+
return { status: candidate.status };
|
|
256
|
+
}
|
|
257
|
+
if (candidate.status === "failed" && typeof candidate.error === "string") {
|
|
258
|
+
return { status: "failed", error: candidate.error };
|
|
259
|
+
}
|
|
260
|
+
return { status: "failed", error: "invalid_export_key_result" };
|
|
261
|
+
};
|
|
262
|
+
var useExportKey = () => {
|
|
263
|
+
const { sdk, _bridge, _relyingPartyOrigin, _runSensitiveFlow } = useMoonXContext();
|
|
264
|
+
return {
|
|
265
|
+
exportKey: async (wallet) => {
|
|
266
|
+
try {
|
|
267
|
+
const { userHandleB64url, credentialIdB64url, tokens } = await (0, import_sdk8.getInternalPresenceTokens)({
|
|
268
|
+
transport: _bridge,
|
|
269
|
+
passkey: createRNPasskey(),
|
|
270
|
+
publishableKey: sdk.publishableKey,
|
|
271
|
+
relyingPartyOrigin: _relyingPartyOrigin,
|
|
272
|
+
scopes: import_sdk8.SCOPES_EXPORT_KEY
|
|
273
|
+
});
|
|
274
|
+
const keyshareReadToken = tokens.keyshare_read?.token ?? "";
|
|
275
|
+
const params = new URLSearchParams({
|
|
276
|
+
publishableKey: sdk.publishableKey,
|
|
277
|
+
wallet_id: wallet.id ?? "",
|
|
278
|
+
wallet_type: wallet.wallet_type ?? ""
|
|
279
|
+
});
|
|
280
|
+
const secrets = new URLSearchParams({
|
|
281
|
+
user_handle_b64url: userHandleB64url,
|
|
282
|
+
credential_id_b64url: credentialIdB64url,
|
|
283
|
+
keyshare_read_token: keyshareReadToken
|
|
284
|
+
});
|
|
285
|
+
return await _runSensitiveFlow({
|
|
286
|
+
title: "Export key",
|
|
287
|
+
flowPath: `/export-key?${params.toString()}#${secrets.toString()}`,
|
|
288
|
+
onMount: ({ bridge, setResult }) => bridge.register(
|
|
289
|
+
import_utils5.PostMessageType.WALLET,
|
|
290
|
+
import_utils5.PostMessageMethod.EXPORT_KEY_RESULT,
|
|
291
|
+
(result) => {
|
|
292
|
+
setResult(parseExportKeyResult(result));
|
|
293
|
+
}
|
|
294
|
+
)
|
|
295
|
+
});
|
|
296
|
+
} catch (error) {
|
|
297
|
+
const message = error instanceof Error ? error.message : "export_key_failed";
|
|
298
|
+
return /cancel/i.test(message) ? { status: "cancelled" } : { status: "failed", error: message };
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
// src/hooks/use-chain-export-key.ts
|
|
305
|
+
var useChainExportKey = () => {
|
|
306
|
+
const { exportKey } = useExportKey();
|
|
307
|
+
return {
|
|
308
|
+
exportKey: ({ wallet }) => exportKey(wallet)
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
// src/hooks/use-chain-fund-wallet.ts
|
|
313
|
+
var createUseFundWallet = (walletType) => function useFundWallet2() {
|
|
314
|
+
const { sdk } = useMoonXContext();
|
|
315
|
+
return {
|
|
316
|
+
fundWallet: (address, options) => sdk.prepareFunding({ address, walletType, options })
|
|
317
|
+
};
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
// src/ethereum.ts
|
|
321
|
+
var useFundWallet = createUseFundWallet("ethereum");
|
|
33
322
|
// Annotate the CommonJS export names for ESM import in node:
|
|
34
323
|
0 && (module.exports = {
|
|
324
|
+
useCreateWallet,
|
|
325
|
+
useExportKey,
|
|
326
|
+
useFundWallet,
|
|
35
327
|
useGetBalance,
|
|
328
|
+
useImportKey,
|
|
36
329
|
useSendTransaction,
|
|
37
330
|
useSign7702Authorization,
|
|
38
331
|
useSignHash,
|
|
39
332
|
useSignMessage,
|
|
40
333
|
useSignTransaction,
|
|
41
|
-
useSignTypedData
|
|
334
|
+
useSignTypedData,
|
|
335
|
+
useWallets
|
|
42
336
|
});
|