@moon-x/react-native-sdk 0.0.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 +462 -0
- package/app.plugin.js +4 -0
- package/dist/ethereum.d.mts +2 -0
- package/dist/ethereum.d.ts +2 -0
- package/dist/ethereum.js +42 -0
- package/dist/ethereum.mjs +19 -0
- package/dist/index.d.mts +273 -0
- package/dist/index.d.ts +273 -0
- package/dist/index.js +1008 -0
- package/dist/index.mjs +982 -0
- package/dist/solana.d.mts +1 -0
- package/dist/solana.d.ts +1 -0
- package/dist/solana.js +36 -0
- package/dist/solana.mjs +13 -0
- package/package.json +85 -0
- package/plugin/index.js +172 -0
package/README.md
ADDED
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
# @moon-x/react-native-sdk
|
|
2
|
+
|
|
3
|
+
React Native SDK for [MoonX](https://moonx.com) — feature parity with
|
|
4
|
+
[`@moon-x/react-sdk`](https://www.npmjs.com/package/@moon-x/react-sdk)
|
|
5
|
+
on mobile. WebView-backed transport, native passkeys, AsyncStorage.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
# bare RN
|
|
11
|
+
pnpm add @moon-x/react-native-sdk \
|
|
12
|
+
react-native-webview react-native-passkeys \
|
|
13
|
+
@react-native-async-storage/async-storage \
|
|
14
|
+
react-native-get-random-values react-native-url-polyfill \
|
|
15
|
+
buffer \
|
|
16
|
+
viem bs58
|
|
17
|
+
|
|
18
|
+
# Expo
|
|
19
|
+
pnpm add @moon-x/react-native-sdk \
|
|
20
|
+
react-native-webview react-native-passkeys \
|
|
21
|
+
@react-native-async-storage/async-storage \
|
|
22
|
+
react-native-get-random-values react-native-url-polyfill \
|
|
23
|
+
buffer \
|
|
24
|
+
expo-web-browser expo-linking \
|
|
25
|
+
viem bs58
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The SDK declares everything except `@moon-x/core` as **peer
|
|
29
|
+
dependencies**. Privy follows the same pattern; their docs are the
|
|
30
|
+
canonical install reference and apply 1:1 here:
|
|
31
|
+
|
|
32
|
+
- https://docs.privy.io/basics/react-native/installation
|
|
33
|
+
- https://docs.privy.io/basics/react-native/advanced/setup-passkeys
|
|
34
|
+
|
|
35
|
+
## Polyfills (order matters)
|
|
36
|
+
|
|
37
|
+
The SDK touches several globals that RN doesn't ship in every config.
|
|
38
|
+
Import the polyfills at the **top** of your app entry, before any
|
|
39
|
+
other code, so they're set up before anything else loads:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
// index.js / index.ts — must run first.
|
|
43
|
+
|
|
44
|
+
// crypto.getRandomValues — needed by passkey challenge generation,
|
|
45
|
+
// MPC keygen, and viem.
|
|
46
|
+
import "react-native-get-random-values";
|
|
47
|
+
|
|
48
|
+
// URL / URLSearchParams — needed by viem and the OAuth deep-link
|
|
49
|
+
// helpers.
|
|
50
|
+
import "react-native-url-polyfill/auto";
|
|
51
|
+
|
|
52
|
+
// Buffer — needed by bs58, ethers, viem's RLP path, and the SDK's
|
|
53
|
+
// Solana broadcast helper. RN does not provide a Buffer global; on
|
|
54
|
+
// Expo it's polyfilled implicitly but you should set it explicitly so
|
|
55
|
+
// bare-RN consumers and any later eject-from-Expo users don't break.
|
|
56
|
+
// Same pattern Privy documents.
|
|
57
|
+
import { Buffer } from "buffer";
|
|
58
|
+
(global as any).Buffer = (global as any).Buffer || Buffer;
|
|
59
|
+
|
|
60
|
+
import { registerRootComponent } from "expo";
|
|
61
|
+
import App from "./App";
|
|
62
|
+
registerRootComponent(App);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
`atob` / `btoa` and `TextEncoder` are built into Hermes (RN's default
|
|
66
|
+
JS engine since 0.71). The peerDep `react-native: ">=0.78.0"` covers
|
|
67
|
+
this — but if you're targeting an older runtime or have explicitly
|
|
68
|
+
opted into JSC, add `text-encoding` and `base-64` polyfills here too.
|
|
69
|
+
|
|
70
|
+
## Provider
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
import { MoonKeyProvider } from "@moon-x/react-native-sdk";
|
|
74
|
+
|
|
75
|
+
export default function Root() {
|
|
76
|
+
return (
|
|
77
|
+
<MoonKeyProvider
|
|
78
|
+
publishableKey={process.env.EXPO_PUBLIC_MOONKEY_PUBLISHABLE_KEY!}
|
|
79
|
+
config={{
|
|
80
|
+
iframeUrl: "https://iframe.moonx-dev.com",
|
|
81
|
+
oauthRedirectUri: "myapp://oauth-callback",
|
|
82
|
+
}}
|
|
83
|
+
>
|
|
84
|
+
<App />
|
|
85
|
+
</MoonKeyProvider>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`config.iframeUrl` is **required and explicit** — the RN SDK never
|
|
91
|
+
reads env vars to discover it. Use the same URL the web SDK points at.
|
|
92
|
+
The iframe-app detects WebView mode at runtime via
|
|
93
|
+
`window.ReactNativeWebView` and routes replies through the bridge
|
|
94
|
+
automatically; no iframe-app changes needed per integration.
|
|
95
|
+
|
|
96
|
+
### Optional `config.security.assertionCacheTtlMs`
|
|
97
|
+
|
|
98
|
+
The RN SDK's parent-side passkey assertion cache holds the WebAuthn
|
|
99
|
+
result (`userHandleB64url` — the AES-GCM key that wraps the user's
|
|
100
|
+
DEK) in JS memory for an integrator-configured TTL. **Defaults to `0`
|
|
101
|
+
— no cache, every sensitive op fires a fresh biometric.** This is the
|
|
102
|
+
safe posture; the raw userHandle never lingers in the RN process JS
|
|
103
|
+
heap past the moment of use.
|
|
104
|
+
|
|
105
|
+
Integrators who want a warm-UX trade-off opt back in:
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
<MoonKeyProvider
|
|
109
|
+
config={{
|
|
110
|
+
iframeUrl: "...",
|
|
111
|
+
oauthRedirectUri: "...",
|
|
112
|
+
security: { assertionCacheTtlMs: 5 * 60 * 1000 },
|
|
113
|
+
}}
|
|
114
|
+
>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Per-call override is exposed on every signing hook:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
await signTransaction({
|
|
121
|
+
transaction: tx,
|
|
122
|
+
wallet,
|
|
123
|
+
requireFreshAssertion: true, // force fresh biometric regardless of TTL
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Sensitive lifecycle ops (`useExportKey`, `useRegisterPasskey` on the
|
|
128
|
+
additional-passkey path, `useRemovePasskey`) ignore the cache
|
|
129
|
+
unconditionally. See the [parent-side assertion cache section in the
|
|
130
|
+
explainer](../../docs/notes/passkeys/explainer.md) for the trade-off
|
|
131
|
+
discussion.
|
|
132
|
+
|
|
133
|
+
## Hooks
|
|
134
|
+
|
|
135
|
+
### Authentication & user state
|
|
136
|
+
|
|
137
|
+
| Hook | What it does |
|
|
138
|
+
|---|---|
|
|
139
|
+
| `useMoonKey()` | The big one. `{ ready, isAuthenticated, user, start, logout, setAppearance, getSessionTokens, refreshUser, ... }` + every SDK method on the same instance. |
|
|
140
|
+
| `useUser()` | Just `{ user, refreshUser }`. Re-subscribes to user changes. |
|
|
141
|
+
| `useLoginWithEmail({ onComplete?, onError? })` | Headless email-OTP. Returns `{ state, sendCode, loginWithCode, reset }`. `state` is a discriminated union: `idle` / `sending` / `awaiting-code` / `verifying` / `complete` / `error`. |
|
|
142
|
+
| `useLoginWithOAuth()` | Google + Apple flows via `expo-web-browser`. Returns `{ state, loginWithOAuth, reset }`. |
|
|
143
|
+
| `useLogout()` | `{ logout }` — also clears AsyncStorage + WebView session. |
|
|
144
|
+
| `useAttachOAuth()` / `useDetachOAuth()` | Link / unlink an OAuth provider on an existing user. |
|
|
145
|
+
|
|
146
|
+
### Passkeys
|
|
147
|
+
|
|
148
|
+
| Hook | What it does |
|
|
149
|
+
|---|---|
|
|
150
|
+
| `usePasskeyStatus()` | `{ status, refresh }`. `status.passkeys` lists the user's enrolled passkeys with provider labels. |
|
|
151
|
+
| `useRegisterPasskey()` | First-time passkey enrollment via the native ceremony (iOS ASAuthorization, Android Credential Manager). |
|
|
152
|
+
| `useAddPasskey()` | Add an additional passkey to an authenticated user. |
|
|
153
|
+
| `useRemovePasskey()` | Remove a passkey by its credential ID. |
|
|
154
|
+
|
|
155
|
+
### Wallets
|
|
156
|
+
|
|
157
|
+
| Hook | What it does |
|
|
158
|
+
|---|---|
|
|
159
|
+
| `useWallets()` | `{ wallets, loading }` — both Ethereum and Solana, fetched once on mount. |
|
|
160
|
+
| `useCreateWallet()` | Mint a new MPC wallet. Pass `{ walletType: "ethereum" \| "solana" }`. |
|
|
161
|
+
| `useImportKey()` | Bring-your-own-key flow. |
|
|
162
|
+
| `useExportKey()` | Show the user their private key via the visible-WebView modal pattern (see below). Plaintext never leaves the WebView's DOM. |
|
|
163
|
+
|
|
164
|
+
### Per-chain signing — `/ethereum` and `/solana` subpaths
|
|
165
|
+
|
|
166
|
+
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`:
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
import { useSignMessage, useSignTransaction, useSendTransaction } from "@moon-x/react-native-sdk/ethereum";
|
|
170
|
+
import { useSignMessage as useSignSolanaMessage } from "@moon-x/react-native-sdk/solana";
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
**Ethereum hooks:**
|
|
174
|
+
- `useSignMessage` — EIP-191 `personal_sign`. Returns `{ signature: "0x..." }`.
|
|
175
|
+
- `useSignTransaction` — Signs an EIP-1559 tx. Returns `{ signature, serializedSigned, hash }`.
|
|
176
|
+
- `useSignTypedData` — EIP-712. Returns `{ signature: "0x..." }`.
|
|
177
|
+
- `useSignHash` — Raw ECDSA digest sign (Privy parity — `secp256k1_sign`).
|
|
178
|
+
- `useSign7702Authorization` — EIP-7702 delegation auth.
|
|
179
|
+
- `useSendTransaction` — Sign + broadcast via the configured RPC.
|
|
180
|
+
- `useGetBalance` — Native token balance.
|
|
181
|
+
|
|
182
|
+
**Solana hooks:**
|
|
183
|
+
- `useSignMessage` — Ed25519 signature.
|
|
184
|
+
- `useSignTransaction` — Signs a serialized base58 tx. Returns `{ signedTransaction: Uint8Array }`.
|
|
185
|
+
- `useSendTransaction` — Sign + broadcast.
|
|
186
|
+
- `useGetBalance` — Lamport balance.
|
|
187
|
+
|
|
188
|
+
Same return shapes as the web SDK — the wire contract is identical.
|
|
189
|
+
|
|
190
|
+
### Mobile-specific notes
|
|
191
|
+
|
|
192
|
+
- **No `useConnectWallet`.** External-wallet connection (MetaMask, Phantom, WalletConnect) is web-only — MoonX wallets are the only thing you can sign with from the RN SDK.
|
|
193
|
+
- **`useExportKey` is a top-level hook on RN.** On web the same operation hangs off `useMoonKey().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.
|
|
194
|
+
|
|
195
|
+
## Visible-WebView pattern (sensitive flows)
|
|
196
|
+
|
|
197
|
+
`useExportKey` (and future `useImportKey`, `useAddPasskey`) toggle the
|
|
198
|
+
WebView from off-screen to a full-screen modal so the iframe-app can
|
|
199
|
+
render the secret-sequestration UI. The plaintext key never leaves the
|
|
200
|
+
WebView's DOM — RN-side JS only sees the rendered pixels.
|
|
201
|
+
|
|
202
|
+
The hook surface is still headless from the consumer's perspective:
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
const { exportKey } = useExportKey();
|
|
206
|
+
await exportKey(wallet); // shows modal, resolves on user-dismiss
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Native config
|
|
210
|
+
|
|
211
|
+
The SDK ships an **Expo config plugin** (`app.plugin.js`) that writes
|
|
212
|
+
the iOS and Android edits described below at `expo prebuild` time. The
|
|
213
|
+
plugin is **Expo-only** — bare React Native projects (`react-native
|
|
214
|
+
init`, no `expo` dependency) ignore it entirely and must apply the
|
|
215
|
+
same edits by hand. Pick the path that matches your project.
|
|
216
|
+
|
|
217
|
+
### Path A: Expo (recommended)
|
|
218
|
+
|
|
219
|
+
Add the plugin to `app.json`:
|
|
220
|
+
|
|
221
|
+
```json
|
|
222
|
+
{
|
|
223
|
+
"expo": {
|
|
224
|
+
"scheme": "myapp",
|
|
225
|
+
"plugins": [
|
|
226
|
+
["@moon-x/react-native-sdk", {
|
|
227
|
+
"passkeyDomains": ["myapp.com"],
|
|
228
|
+
"oauthRedirectScheme": "myapp"
|
|
229
|
+
}]
|
|
230
|
+
]
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Then run `pnpm prebuild` (or `pnpm prebuild --clean` to regenerate
|
|
236
|
+
native code from scratch). The plugin produces:
|
|
237
|
+
|
|
238
|
+
- **iOS** — `webcredentials:<domain>` Associated Domains entitlement
|
|
239
|
+
for each `passkeyDomains` entry.
|
|
240
|
+
- **iOS** — `ITSAppUsesNonExemptEncryption = false` (App Store export
|
|
241
|
+
compliance).
|
|
242
|
+
- **Android** — `<meta-data android:name="asset_statements">` inside
|
|
243
|
+
`<application>` in `AndroidManifest.xml`, plus a matching
|
|
244
|
+
`<string name="asset_statements">` resource in `res/values/strings.xml`
|
|
245
|
+
pointing at `https://<passkeyDomain>/.well-known/assetlinks.json` for
|
|
246
|
+
every entry in `passkeyDomains`. Required by Credential Manager —
|
|
247
|
+
without it, `[50152] RP ID cannot be validated.`
|
|
248
|
+
- **Android** — `<intent-filter>` on `MainActivity` for the
|
|
249
|
+
`oauthRedirectScheme` deep link.
|
|
250
|
+
|
|
251
|
+
Re-run `pnpm prebuild` whenever you change the plugin options.
|
|
252
|
+
|
|
253
|
+
### Path B: Bare React Native (no Expo prebuild)
|
|
254
|
+
|
|
255
|
+
The plugin does nothing here — `app.json` and `app.plugin.js` aren't
|
|
256
|
+
consulted. Apply each edit manually:
|
|
257
|
+
|
|
258
|
+
**`ios/<App>/<App>.entitlements`** — add:
|
|
259
|
+
|
|
260
|
+
```xml
|
|
261
|
+
<key>com.apple.developer.associated-domains</key>
|
|
262
|
+
<array>
|
|
263
|
+
<string>webcredentials:myapp.com</string>
|
|
264
|
+
</array>
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
Also ensure `https://myapp.com/.well-known/apple-app-site-association`
|
|
268
|
+
declares `webcredentials` for your bundle ID.
|
|
269
|
+
|
|
270
|
+
**`ios/<App>/Info.plist`** — add:
|
|
271
|
+
|
|
272
|
+
```xml
|
|
273
|
+
<key>ITSAppUsesNonExemptEncryption</key>
|
|
274
|
+
<false/>
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
**`android/app/src/main/AndroidManifest.xml`** — inside the existing
|
|
278
|
+
`<application>` element add:
|
|
279
|
+
|
|
280
|
+
```xml
|
|
281
|
+
<meta-data
|
|
282
|
+
android:name="asset_statements"
|
|
283
|
+
android:resource="@string/asset_statements" />
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Inside `<activity android:name=".MainActivity">` add an additional
|
|
287
|
+
intent filter for your OAuth deep link (alongside the default LAUNCHER
|
|
288
|
+
filter, do **not** replace it):
|
|
289
|
+
|
|
290
|
+
```xml
|
|
291
|
+
<intent-filter android:autoVerify="false">
|
|
292
|
+
<action android:name="android.intent.action.VIEW" />
|
|
293
|
+
<category android:name="android.intent.category.DEFAULT" />
|
|
294
|
+
<category android:name="android.intent.category.BROWSABLE" />
|
|
295
|
+
<data android:scheme="myapp" />
|
|
296
|
+
</intent-filter>
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
**`android/app/src/main/res/values/strings.xml`** — add:
|
|
300
|
+
|
|
301
|
+
```xml
|
|
302
|
+
<string name="asset_statements" translatable="false">
|
|
303
|
+
[{ \"include\": \"https://myapp.com/.well-known/assetlinks.json\" }]
|
|
304
|
+
</string>
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
For multiple `passkeyDomains`, comma-separate the include objects
|
|
308
|
+
inside the same JSON array (escape every `"` as `\"`):
|
|
309
|
+
|
|
310
|
+
```xml
|
|
311
|
+
<string name="asset_statements" translatable="false">
|
|
312
|
+
[{ \"include\": \"https://myapp.com/.well-known/assetlinks.json\" }, { \"include\": \"https://staging.myapp.com/.well-known/assetlinks.json\" }]
|
|
313
|
+
</string>
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Android passkeys: Digital Asset Links
|
|
317
|
+
|
|
318
|
+
Android Credential Manager has **no developer-mode bypass** like
|
|
319
|
+
iOS Associated Domains does — every WebAuthn ceremony is validated
|
|
320
|
+
against `https://<rpId>/.well-known/assetlinks.json`, which must list
|
|
321
|
+
your app's package name + signing-cert SHA-256 fingerprint.
|
|
322
|
+
|
|
323
|
+
#### 1. Publish `assetlinks.json` at the rpId apex
|
|
324
|
+
|
|
325
|
+
If `passkeyDomains` is `myapp.com`, host at
|
|
326
|
+
`https://myapp.com/.well-known/assetlinks.json`. Both relation strings
|
|
327
|
+
below are recommended per the
|
|
328
|
+
[official Android docs](https://developer.android.com/identity/sign-in/credential-manager#add-support-dal):
|
|
329
|
+
|
|
330
|
+
```json
|
|
331
|
+
[
|
|
332
|
+
{
|
|
333
|
+
"relation": [
|
|
334
|
+
"delegate_permission/common.handle_all_urls",
|
|
335
|
+
"delegate_permission/common.get_login_creds"
|
|
336
|
+
],
|
|
337
|
+
"target": {
|
|
338
|
+
"namespace": "android_app",
|
|
339
|
+
"package_name": "com.example.myapp",
|
|
340
|
+
"sha256_cert_fingerprints": [
|
|
341
|
+
"<debug-keystore-sha-256>",
|
|
342
|
+
"<upload-keystore-sha-256>",
|
|
343
|
+
"<play-app-signing-sha-256>"
|
|
344
|
+
]
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
]
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
The file must be served as `Content-Type: application/json` over HTTPS
|
|
351
|
+
with a valid certificate.
|
|
352
|
+
|
|
353
|
+
#### 2. Get every signing fingerprint you need
|
|
354
|
+
|
|
355
|
+
```sh
|
|
356
|
+
cd android && ./gradlew signingReport
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
Copy the `SHA-256` line from each `Variant:` block. Three flavors to
|
|
360
|
+
include:
|
|
361
|
+
|
|
362
|
+
- **Debug**: every developer's local builds. If you don't commit a
|
|
363
|
+
shared `debug.keystore`, every developer's machine generates a
|
|
364
|
+
different one — fix is to commit a single keystore to the repo
|
|
365
|
+
(debug keystores are public-secret per the spec; password is
|
|
366
|
+
`android`). See `apps/rn-demo/.gitignore` for the negation pattern
|
|
367
|
+
that lets `android/app/debug.keystore` survive `expo prebuild`.
|
|
368
|
+
React Native's template ships a community-default `debug.keystore`
|
|
369
|
+
with SHA-256
|
|
370
|
+
`FA:C6:17:45:DC:09:03:78:6F:B9:ED:E6:2A:96:2B:39:9F:73:48:F0:BB:6F:89:9B:83:32:66:75:91:03:3B:9C` —
|
|
371
|
+
if you copy that file in (it's in `react-native-passkey`,
|
|
372
|
+
`react-native-fast-image`, etc.), every dev's debug build matches a
|
|
373
|
+
single SHA.
|
|
374
|
+
- **Release / upload key**: builds you upload to Play Console. Local
|
|
375
|
+
release builds are signed with this until Google takes over.
|
|
376
|
+
- **Play App Signing key**: once your first release uploads, Google
|
|
377
|
+
strips your upload key and re-signs with their managed key. The
|
|
378
|
+
resulting fingerprint is the one users actually run. Find it in
|
|
379
|
+
**Play Console → Setup → App integrity → App signing key
|
|
380
|
+
certificate**. Add this SHA-256 the moment your first internal-track
|
|
381
|
+
upload completes — without it, GPM rejects validation on installs
|
|
382
|
+
shipped through Play.
|
|
383
|
+
|
|
384
|
+
#### 3. Verify before debugging
|
|
385
|
+
|
|
386
|
+
Before reinstalling and re-attempting the ceremony, sanity-check the
|
|
387
|
+
file with Google's official Digital Asset Links validator:
|
|
388
|
+
|
|
389
|
+
```sh
|
|
390
|
+
curl 'https://digitalassetlinks.googleapis.com/v1/assetlinks:check?source.web.site=https://myapp.com&relation=delegate_permission/common.get_login_creds&target.android_app.package_name=com.example.myapp&target.android_app.certificate.sha256_fingerprint=<SHA-WITH-COLONS>'
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
Expected: `{ "linked": true, ... }`. If this returns `linked: false`,
|
|
394
|
+
the on-device validator will also fail — fix the file first.
|
|
395
|
+
|
|
396
|
+
#### 4. Register the Android fingerprint with the moon-x backend
|
|
397
|
+
|
|
398
|
+
The backend needs to know which Android signing certs are allowed to
|
|
399
|
+
act as the relying party for your app — Credential Manager substitutes
|
|
400
|
+
`android:apk-key-hash:<base64url(sha256_of_signing_cert)>` for the
|
|
401
|
+
WebAuthn `clientDataJSON.origin` instead of the HTTPS origin a browser
|
|
402
|
+
sends, and the platform does an exact-match check.
|
|
403
|
+
|
|
404
|
+
Set the `webauthn.android_apk_key_hashes` app setting to a JSON array
|
|
405
|
+
of every Android signing cert SHA-256 (hex, with or without colons —
|
|
406
|
+
both forms accepted; same values you put in `assetlinks.json`):
|
|
407
|
+
|
|
408
|
+
```json
|
|
409
|
+
["FA:C6:17:45:DC:09:...", "AA:BB:CC:..."]
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
Symptom when missing: passkey ceremony succeeds at the OS level (you
|
|
413
|
+
see and pass the biometric prompt), then the backend's verify step
|
|
414
|
+
rejects with `error validating origin`.
|
|
415
|
+
|
|
416
|
+
#### 5. Troubleshooting
|
|
417
|
+
|
|
418
|
+
| Symptom | Likely cause | Fix |
|
|
419
|
+
|---|---|---|
|
|
420
|
+
| Native dialog opens, user taps, response never returns; logcat shows `[50152] RP ID cannot be validated.` | `assetlinks.json` not reachable, wrong package_name, wrong SHA, OR a stale negative DAL cache from an earlier failure | Verify file with Google's validator (step 3); **uninstall and reinstall** the app — clearing `com.google.android.gms` data does NOT evict the per-package DAL cache, only a reinstall does. |
|
|
421
|
+
| `error validating origin` from the backend after the OS ceremony succeeds | Android signing fingerprint not registered with the backend | Add the SHA to `webauthn.android_apk_key_hashes` (step 4). |
|
|
422
|
+
| Spec-correct setup that worked in dev fails for users installing from Play | Play App Signing key SHA missing | Add the Play App Signing fingerprint from Play Console to `assetlinks.json` AND `webauthn.android_apk_key_hashes`. |
|
|
423
|
+
| `androidx.credentials.exceptions.domerrors.DataError@<hash>` with no detail | Older `react-native-passkeys` doesn't surface the underlying DOM error | Watch logcat directly: `adb logcat \| grep -E "Auth.Api.Credentials\|Fido"` — the real error code (e.g. `[50152]`) is visible there. |
|
|
424
|
+
| Persistent failure even though everything looks correct | DAL cache from a prior bad attempt | `adb uninstall <package>` then reinstall. **Do not** rely on `adb shell pm clear com.google.android.gms` — it logs the user out of Google but leaves the per-package DAL cache. |
|
|
425
|
+
|
|
426
|
+
#### 6. Min versions / known issues
|
|
427
|
+
|
|
428
|
+
- Google Password Manager validates more strictly than the WebAuthn
|
|
429
|
+
spec requires. Some debug-keystore + assetlinks setups that pass
|
|
430
|
+
Google's centralized DAL validator still fail GPM's on-device check
|
|
431
|
+
on first install. Reinstall after publishing `assetlinks.json` is
|
|
432
|
+
the most reliable workaround.
|
|
433
|
+
- Real device testing is recommended: emulator + GMS sometimes
|
|
434
|
+
exhibits subtly different validation behaviour.
|
|
435
|
+
- Android 13+ is what we test against. The Credential Manager
|
|
436
|
+
backport on 9-12 works for most flows but isn't continuously
|
|
437
|
+
exercised here.
|
|
438
|
+
|
|
439
|
+
## Min OS versions
|
|
440
|
+
|
|
441
|
+
- iOS 16+ (passkeys via ASAuthorization)
|
|
442
|
+
- Android 9+ (passkeys via Credential Manager)
|
|
443
|
+
- React Native 0.78+ (React 19 support)
|
|
444
|
+
- Hermes is the supported JS engine. JSC will work for non-passkey
|
|
445
|
+
flows but isn't tested.
|
|
446
|
+
|
|
447
|
+
## What's deferred from v1
|
|
448
|
+
|
|
449
|
+
- WalletConnect / external-wallet connectors
|
|
450
|
+
- "WithUI" SDK method variants (web-only — RN is headless)
|
|
451
|
+
- Iframe-app emitting `EXPORT_COMPLETE` one-way postMessage on
|
|
452
|
+
user-dismiss (currently the modal's close button resolves the
|
|
453
|
+
promise; the post-back contract is a planned follow-up)
|
|
454
|
+
- RN-mode bundle-ID origin whitelist on the iframe-app
|
|
455
|
+
(`window.ReactNativeWebView`-mode currently bypasses origin
|
|
456
|
+
whitelisting; publishableKey + session JWT are the gates in v1)
|
|
457
|
+
|
|
458
|
+
## Reference
|
|
459
|
+
|
|
460
|
+
- Web parity: [`@moon-x/react-sdk`](https://www.npmjs.com/package/@moon-x/react-sdk)
|
|
461
|
+
- Wire protocol: `packages/core/src/utils/post-message.ts`
|
|
462
|
+
- Architecture: `packages/react-native-sdk/AGENTS.md`
|
package/app.plugin.js
ADDED
package/dist/ethereum.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/ethereum.ts
|
|
21
|
+
var ethereum_exports = {};
|
|
22
|
+
__export(ethereum_exports, {
|
|
23
|
+
useGetBalance: () => import_ethereum.useGetBalance,
|
|
24
|
+
useSendTransaction: () => import_ethereum.useSendTransaction,
|
|
25
|
+
useSign7702Authorization: () => import_ethereum.useSign7702Authorization,
|
|
26
|
+
useSignHash: () => import_ethereum.useSignHash,
|
|
27
|
+
useSignMessage: () => import_ethereum.useSignMessage,
|
|
28
|
+
useSignTransaction: () => import_ethereum.useSignTransaction,
|
|
29
|
+
useSignTypedData: () => import_ethereum.useSignTypedData
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(ethereum_exports);
|
|
32
|
+
var import_ethereum = require("@moon-x/core/react/ethereum");
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
35
|
+
useGetBalance,
|
|
36
|
+
useSendTransaction,
|
|
37
|
+
useSign7702Authorization,
|
|
38
|
+
useSignHash,
|
|
39
|
+
useSignMessage,
|
|
40
|
+
useSignTransaction,
|
|
41
|
+
useSignTypedData
|
|
42
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/ethereum.ts
|
|
2
|
+
import {
|
|
3
|
+
useGetBalance,
|
|
4
|
+
useSendTransaction,
|
|
5
|
+
useSign7702Authorization,
|
|
6
|
+
useSignHash,
|
|
7
|
+
useSignMessage,
|
|
8
|
+
useSignTransaction,
|
|
9
|
+
useSignTypedData
|
|
10
|
+
} from "@moon-x/core/react/ethereum";
|
|
11
|
+
export {
|
|
12
|
+
useGetBalance,
|
|
13
|
+
useSendTransaction,
|
|
14
|
+
useSign7702Authorization,
|
|
15
|
+
useSignHash,
|
|
16
|
+
useSignMessage,
|
|
17
|
+
useSignTransaction,
|
|
18
|
+
useSignTypedData
|
|
19
|
+
};
|