@moon-x/react-native-sdk 0.2.0 → 0.3.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 +31 -36
- package/dist/index.d.mts +21 -22
- package/dist/index.d.ts +21 -22
- package/dist/index.js +101 -24
- package/dist/index.mjs +107 -26
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -93,42 +93,37 @@ The iframe-app detects WebView mode at runtime via
|
|
|
93
93
|
`window.ReactNativeWebView` and routes replies through the bridge
|
|
94
94
|
automatically; no iframe-app changes needed per integration.
|
|
95
95
|
|
|
96
|
-
###
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
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.
|
|
96
|
+
### Security
|
|
97
|
+
|
|
98
|
+
Every sensitive op (sign / send / create / import / export / addPasskey
|
|
99
|
+
/ removePasskey) drives the same server-verified presence ceremony per
|
|
100
|
+
call:
|
|
101
|
+
|
|
102
|
+
1. Server-issued WebAuthn challenge.
|
|
103
|
+
2. Fresh biometric assertion (stripping `response.userHandle` before
|
|
104
|
+
anything crosses the bridge to MoonX — DEK hygiene).
|
|
105
|
+
3. Server mints short-lived (30s) single-use JWTs scoped to the
|
|
106
|
+
specific endpoint set this op needs.
|
|
107
|
+
4. Each scoped JWT travels as `X-MoonX-Presence` on its matching
|
|
108
|
+
gated endpoint and is burned (`platform.app_presence_jti_used`) on
|
|
109
|
+
first use.
|
|
110
|
+
|
|
111
|
+
What this closes: captured userHandle + session JWT alone no longer
|
|
112
|
+
unlocks DEK material — every gated endpoint also needs a fresh
|
|
113
|
+
WebAuthn signature MoonX verifies against the credential's stored
|
|
114
|
+
public key. See `apps/platform/docs/notes/passkeys/presence-tokens.md`
|
|
115
|
+
in the backend repo for the full threat model.
|
|
116
|
+
|
|
117
|
+
The previously-configurable `config.security.assertionCacheTtlMs`
|
|
118
|
+
and per-call `requireFreshAssertion` flag were removed entirely when
|
|
119
|
+
presence-token gating shipped — they are no longer on the public
|
|
120
|
+
TypeScript surface. Every op is always-fresh by construction.
|
|
121
|
+
|
|
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.
|
|
132
127
|
|
|
133
128
|
## Hooks
|
|
134
129
|
|
package/dist/index.d.mts
CHANGED
|
@@ -129,6 +129,21 @@ interface MoonKeyConfig {
|
|
|
129
129
|
* Deep-link URI scheme used as the OAuth redirect target.
|
|
130
130
|
*/
|
|
131
131
|
oauthRedirectUri?: string;
|
|
132
|
+
/**
|
|
133
|
+
* **Required** for sensitive operations. The host app's effective
|
|
134
|
+
* WebAuthn relying-party origin (e.g. `"https://wallet.acme.com"`
|
|
135
|
+
* for an associated-domain config). The SDK threads this into the
|
|
136
|
+
* internal presence-token orchestrator at `/auth/passkey/presence/begin`
|
|
137
|
+
* so the backend can rebuild the per-app WebAuthn RP config that the
|
|
138
|
+
* native authenticator will assert against.
|
|
139
|
+
*
|
|
140
|
+
* Without it, the orchestrator submits an empty origin to the
|
|
141
|
+
* server, which rejects with `invalid_relying_party_origin` — i.e.
|
|
142
|
+
* sensitive operations (sign / send / create / import / export /
|
|
143
|
+
* addPasskey / removePasskey) will fail. The MoonKeyProvider will
|
|
144
|
+
* log a warning at mount time if this is omitted.
|
|
145
|
+
*/
|
|
146
|
+
relyingPartyOrigin?: string;
|
|
132
147
|
/**
|
|
133
148
|
* UI strings for the sensitive-flow modal chrome (close button,
|
|
134
149
|
* default title). Defaults are reasonable English copy.
|
|
@@ -137,26 +152,12 @@ interface MoonKeyConfig {
|
|
|
137
152
|
closeLabel?: string;
|
|
138
153
|
};
|
|
139
154
|
/**
|
|
140
|
-
*
|
|
141
|
-
*
|
|
155
|
+
* Reserved for future per-app security knobs. Currently no fields —
|
|
156
|
+
* the previously-configurable `assertionCacheTtlMs` was removed
|
|
157
|
+
* entirely when presence-token gating shipped (every sensitive op
|
|
158
|
+
* now drives a fresh WebAuthn ceremony, no cache to configure).
|
|
142
159
|
*/
|
|
143
|
-
security?:
|
|
144
|
-
/**
|
|
145
|
-
* TTL in milliseconds for the parent-side passkey assertion cache.
|
|
146
|
-
*
|
|
147
|
-
* Default: 0 (no cache — every sensitive op forces a fresh
|
|
148
|
-
* biometric prompt). This is the safe-by-default posture; the raw
|
|
149
|
-
* userHandle (the AES-GCM KEK that unwraps the user's DEK) never
|
|
150
|
-
* lingers in JS heap past the moment of use.
|
|
151
|
-
*
|
|
152
|
-
* Set to a positive number (e.g. 5 * 60 * 1000) only if the app
|
|
153
|
-
* has a UX that genuinely benefits from skipping the OS passkey
|
|
154
|
-
* prompt on routine ops within a window. Sensitive operations
|
|
155
|
-
* (export, addPasskey, removePasskey, and any call passing
|
|
156
|
-
* `requireFreshAssertion: true`) bypass the cache regardless.
|
|
157
|
-
*/
|
|
158
|
-
assertionCacheTtlMs?: number;
|
|
159
|
-
};
|
|
160
|
+
security?: Record<string, never>;
|
|
160
161
|
}
|
|
161
162
|
interface MoonKeyProviderProps {
|
|
162
163
|
publishableKey: string;
|
|
@@ -195,6 +196,7 @@ interface SensitiveFlowMountApi {
|
|
|
195
196
|
interface MoonKeyContextValue {
|
|
196
197
|
sdk: RNAuthSDK;
|
|
197
198
|
_bridge: WebViewBridge;
|
|
199
|
+
_relyingPartyOrigin: string;
|
|
198
200
|
_runSensitiveFlow: (options: SensitiveFlowOptions) => Promise<void>;
|
|
199
201
|
_oauthRedirectUri?: string;
|
|
200
202
|
}
|
|
@@ -234,9 +236,6 @@ declare const useDetachOAuth: () => {
|
|
|
234
236
|
* flow. The RN-side promise resolves when the user dismisses the
|
|
235
237
|
* modal (the only v1 completion signal — an iframe-app-emitted
|
|
236
238
|
* EXPORT_COMPLETE one-way is a planned enhancement).
|
|
237
|
-
*
|
|
238
|
-
* Sensitive op: forces a fresh biometric prompt regardless of the
|
|
239
|
-
* parent-side warm-cache state, matching the web SDK's posture.
|
|
240
239
|
*/
|
|
241
240
|
declare const useExportKey: () => {
|
|
242
241
|
exportKey: (wallet: PublicWallet) => Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -129,6 +129,21 @@ interface MoonKeyConfig {
|
|
|
129
129
|
* Deep-link URI scheme used as the OAuth redirect target.
|
|
130
130
|
*/
|
|
131
131
|
oauthRedirectUri?: string;
|
|
132
|
+
/**
|
|
133
|
+
* **Required** for sensitive operations. The host app's effective
|
|
134
|
+
* WebAuthn relying-party origin (e.g. `"https://wallet.acme.com"`
|
|
135
|
+
* for an associated-domain config). The SDK threads this into the
|
|
136
|
+
* internal presence-token orchestrator at `/auth/passkey/presence/begin`
|
|
137
|
+
* so the backend can rebuild the per-app WebAuthn RP config that the
|
|
138
|
+
* native authenticator will assert against.
|
|
139
|
+
*
|
|
140
|
+
* Without it, the orchestrator submits an empty origin to the
|
|
141
|
+
* server, which rejects with `invalid_relying_party_origin` — i.e.
|
|
142
|
+
* sensitive operations (sign / send / create / import / export /
|
|
143
|
+
* addPasskey / removePasskey) will fail. The MoonKeyProvider will
|
|
144
|
+
* log a warning at mount time if this is omitted.
|
|
145
|
+
*/
|
|
146
|
+
relyingPartyOrigin?: string;
|
|
132
147
|
/**
|
|
133
148
|
* UI strings for the sensitive-flow modal chrome (close button,
|
|
134
149
|
* default title). Defaults are reasonable English copy.
|
|
@@ -137,26 +152,12 @@ interface MoonKeyConfig {
|
|
|
137
152
|
closeLabel?: string;
|
|
138
153
|
};
|
|
139
154
|
/**
|
|
140
|
-
*
|
|
141
|
-
*
|
|
155
|
+
* Reserved for future per-app security knobs. Currently no fields —
|
|
156
|
+
* the previously-configurable `assertionCacheTtlMs` was removed
|
|
157
|
+
* entirely when presence-token gating shipped (every sensitive op
|
|
158
|
+
* now drives a fresh WebAuthn ceremony, no cache to configure).
|
|
142
159
|
*/
|
|
143
|
-
security?:
|
|
144
|
-
/**
|
|
145
|
-
* TTL in milliseconds for the parent-side passkey assertion cache.
|
|
146
|
-
*
|
|
147
|
-
* Default: 0 (no cache — every sensitive op forces a fresh
|
|
148
|
-
* biometric prompt). This is the safe-by-default posture; the raw
|
|
149
|
-
* userHandle (the AES-GCM KEK that unwraps the user's DEK) never
|
|
150
|
-
* lingers in JS heap past the moment of use.
|
|
151
|
-
*
|
|
152
|
-
* Set to a positive number (e.g. 5 * 60 * 1000) only if the app
|
|
153
|
-
* has a UX that genuinely benefits from skipping the OS passkey
|
|
154
|
-
* prompt on routine ops within a window. Sensitive operations
|
|
155
|
-
* (export, addPasskey, removePasskey, and any call passing
|
|
156
|
-
* `requireFreshAssertion: true`) bypass the cache regardless.
|
|
157
|
-
*/
|
|
158
|
-
assertionCacheTtlMs?: number;
|
|
159
|
-
};
|
|
160
|
+
security?: Record<string, never>;
|
|
160
161
|
}
|
|
161
162
|
interface MoonKeyProviderProps {
|
|
162
163
|
publishableKey: string;
|
|
@@ -195,6 +196,7 @@ interface SensitiveFlowMountApi {
|
|
|
195
196
|
interface MoonKeyContextValue {
|
|
196
197
|
sdk: RNAuthSDK;
|
|
197
198
|
_bridge: WebViewBridge;
|
|
199
|
+
_relyingPartyOrigin: string;
|
|
198
200
|
_runSensitiveFlow: (options: SensitiveFlowOptions) => Promise<void>;
|
|
199
201
|
_oauthRedirectUri?: string;
|
|
200
202
|
}
|
|
@@ -234,9 +236,6 @@ declare const useDetachOAuth: () => {
|
|
|
234
236
|
* flow. The RN-side promise resolves when the user dismisses the
|
|
235
237
|
* modal (the only v1 completion signal — an iframe-app-emitted
|
|
236
238
|
* EXPORT_COMPLETE one-way is a planned enhancement).
|
|
237
|
-
*
|
|
238
|
-
* Sensitive op: forces a fresh biometric prompt regardless of the
|
|
239
|
-
* parent-side warm-cache state, matching the web SDK's posture.
|
|
240
239
|
*/
|
|
241
240
|
declare const useExportKey: () => {
|
|
242
241
|
exportKey: (wallet: PublicWallet) => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -117,14 +117,44 @@ var createRNPasskey = () => ({
|
|
|
117
117
|
authenticatorAttachment: credential.authenticatorAttachment
|
|
118
118
|
};
|
|
119
119
|
return sanitized;
|
|
120
|
+
},
|
|
121
|
+
assertForInternalPresence: async ({ optionsJSON }) => {
|
|
122
|
+
const credential = await (0, import_react_native_passkeys.get)({
|
|
123
|
+
challenge: optionsJSON.challenge,
|
|
124
|
+
rpId: optionsJSON.rpId,
|
|
125
|
+
allowCredentials: [],
|
|
126
|
+
userVerification: optionsJSON.userVerification ?? "preferred"
|
|
127
|
+
});
|
|
128
|
+
if (!credential) throw new Error("passkey_assertion_cancelled");
|
|
129
|
+
const userHandle = credential.response.userHandle;
|
|
130
|
+
if (!userHandle) throw new Error("user_handle_missing");
|
|
131
|
+
const sanitized = {
|
|
132
|
+
id: credential.id ?? credential.rawId,
|
|
133
|
+
rawId: credential.rawId,
|
|
134
|
+
type: credential.type ?? "public-key",
|
|
135
|
+
response: {
|
|
136
|
+
clientDataJSON: credential.response.clientDataJSON,
|
|
137
|
+
authenticatorData: credential.response.authenticatorData,
|
|
138
|
+
signature: credential.response.signature,
|
|
139
|
+
userHandle: void 0
|
|
140
|
+
},
|
|
141
|
+
clientExtensionResults: credential.clientExtensionResults ?? {},
|
|
142
|
+
authenticatorAttachment: credential.authenticatorAttachment
|
|
143
|
+
};
|
|
144
|
+
return {
|
|
145
|
+
response: sanitized,
|
|
146
|
+
userHandleB64url: userHandle,
|
|
147
|
+
credentialIdB64url: credential.rawId
|
|
148
|
+
};
|
|
120
149
|
}
|
|
121
150
|
});
|
|
122
151
|
|
|
123
152
|
// src/sdk/sdk-ethereum-methods.ts
|
|
124
|
-
var getEthereumSDKMethods = (bridge, publishableKey) => (0, import_sdk2.getHeadlessEthereumMethods)({
|
|
153
|
+
var getEthereumSDKMethods = (bridge, publishableKey, relyingPartyOrigin) => (0, import_sdk2.getHeadlessEthereumMethods)({
|
|
125
154
|
transport: bridge,
|
|
126
155
|
passkey: createRNPasskey(),
|
|
127
|
-
publishableKey
|
|
156
|
+
publishableKey,
|
|
157
|
+
relyingPartyOrigin
|
|
128
158
|
});
|
|
129
159
|
|
|
130
160
|
// src/sdk/sdk-passkey-methods.ts
|
|
@@ -132,6 +162,7 @@ var import_lib = require("@moon-x/core/lib");
|
|
|
132
162
|
var import_sdk3 = require("@moon-x/core/sdk");
|
|
133
163
|
var import_utils = require("@moon-x/core/utils");
|
|
134
164
|
var import_react_native_passkeys2 = require("react-native-passkeys");
|
|
165
|
+
var ADD_PASSKEY_SCOPES = ["passkey_enroll", "wrap_add"];
|
|
135
166
|
var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
136
167
|
registerPasskey: async (params) => {
|
|
137
168
|
const dekInfo = await bridge.send(
|
|
@@ -147,16 +178,22 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
147
178
|
const isAdditional = (dekInfo.allow_credential_ids_b64url ?? []).length > 0;
|
|
148
179
|
let unlock = null;
|
|
149
180
|
if (isAdditional) {
|
|
150
|
-
|
|
181
|
+
const result = await (0, import_sdk3.getInternalPresenceTokens)({
|
|
151
182
|
transport: bridge,
|
|
152
183
|
passkey: createRNPasskey(),
|
|
153
184
|
publishableKey,
|
|
154
|
-
|
|
185
|
+
relyingPartyOrigin,
|
|
186
|
+
scopes: ADD_PASSKEY_SCOPES
|
|
155
187
|
});
|
|
156
188
|
const allowList = dekInfo.allow_credential_ids_b64url ?? [];
|
|
157
|
-
if (!allowList.includes(
|
|
189
|
+
if (!allowList.includes(result.credentialIdB64url)) {
|
|
158
190
|
throw new Error("unknown_passkey_for_this_account");
|
|
159
191
|
}
|
|
192
|
+
unlock = {
|
|
193
|
+
userHandleB64url: result.userHandleB64url,
|
|
194
|
+
credentialIdB64url: result.credentialIdB64url,
|
|
195
|
+
presenceTokens: (0, import_sdk3.flattenPresenceTokens)(result)
|
|
196
|
+
};
|
|
160
197
|
}
|
|
161
198
|
const beginResult = await bridge.send(
|
|
162
199
|
import_utils.PostMessageType.AUTH,
|
|
@@ -191,7 +228,8 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
191
228
|
relyingPartyOrigin,
|
|
192
229
|
token,
|
|
193
230
|
credential,
|
|
194
|
-
userIdB64url
|
|
231
|
+
userIdB64url,
|
|
232
|
+
presenceTokens: unlock?.presenceTokens
|
|
195
233
|
}
|
|
196
234
|
);
|
|
197
235
|
if (isAdditional && unlock) {
|
|
@@ -203,7 +241,8 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
203
241
|
unlockUserHandleB64url: unlock.userHandleB64url,
|
|
204
242
|
unlockCredentialIdB64url: unlock.credentialIdB64url,
|
|
205
243
|
newUserHandleB64url: userIdB64url,
|
|
206
|
-
newCredentialIdB64url: credential.rawId
|
|
244
|
+
newCredentialIdB64url: credential.rawId,
|
|
245
|
+
presenceTokens: unlock.presenceTokens
|
|
207
246
|
}
|
|
208
247
|
);
|
|
209
248
|
}
|
|
@@ -242,27 +281,30 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
242
281
|
|
|
243
282
|
// src/sdk/sdk-methods.ts
|
|
244
283
|
var import_sdk4 = require("@moon-x/core/sdk");
|
|
245
|
-
var getSDKMethods = (bridge, publishableKey, setIsAuthenticated, setUser) => (0, import_sdk4.getHeadlessGeneralMethods)({
|
|
284
|
+
var getSDKMethods = (bridge, publishableKey, relyingPartyOrigin, setIsAuthenticated, setUser) => (0, import_sdk4.getHeadlessGeneralMethods)({
|
|
246
285
|
transport: bridge,
|
|
247
286
|
passkey: createRNPasskey(),
|
|
248
287
|
storage: createAsyncStorageKv(),
|
|
249
288
|
publishableKey,
|
|
289
|
+
relyingPartyOrigin,
|
|
250
290
|
setIsAuthenticated,
|
|
251
291
|
setUser
|
|
252
292
|
});
|
|
253
293
|
|
|
254
294
|
// src/sdk/sdk-solana-methods.ts
|
|
255
295
|
var import_sdk5 = require("@moon-x/core/sdk");
|
|
256
|
-
var getSolanaSDKMethods = (bridge, publishableKey) => (0, import_sdk5.getHeadlessSolanaMethods)({
|
|
296
|
+
var getSolanaSDKMethods = (bridge, publishableKey, relyingPartyOrigin) => (0, import_sdk5.getHeadlessSolanaMethods)({
|
|
257
297
|
transport: bridge,
|
|
258
298
|
passkey: createRNPasskey(),
|
|
259
|
-
publishableKey
|
|
299
|
+
publishableKey,
|
|
300
|
+
relyingPartyOrigin
|
|
260
301
|
});
|
|
261
302
|
|
|
262
303
|
// src/sdk/create-sdk-instance.ts
|
|
263
304
|
var createSdkInstance = ({
|
|
264
305
|
bridge,
|
|
265
306
|
publishableKey,
|
|
307
|
+
relyingPartyOrigin,
|
|
266
308
|
isAuthenticated,
|
|
267
309
|
user,
|
|
268
310
|
ready,
|
|
@@ -281,14 +323,19 @@ var createSdkInstance = ({
|
|
|
281
323
|
setIsAuthenticated,
|
|
282
324
|
setUser
|
|
283
325
|
),
|
|
284
|
-
...getSDKMethods(
|
|
326
|
+
...getSDKMethods(
|
|
327
|
+
bridge,
|
|
328
|
+
publishableKey,
|
|
329
|
+
relyingPartyOrigin,
|
|
330
|
+
setIsAuthenticated,
|
|
331
|
+
setUser
|
|
332
|
+
),
|
|
285
333
|
...getPasskeyMethods(bridge, publishableKey),
|
|
286
|
-
...getEthereumSDKMethods(bridge, publishableKey),
|
|
287
|
-
...getSolanaSDKMethods(bridge, publishableKey)
|
|
334
|
+
...getEthereumSDKMethods(bridge, publishableKey, relyingPartyOrigin),
|
|
335
|
+
...getSolanaSDKMethods(bridge, publishableKey, relyingPartyOrigin)
|
|
288
336
|
});
|
|
289
337
|
|
|
290
338
|
// src/provider.tsx
|
|
291
|
-
var import_lib2 = require("@moon-x/core/lib");
|
|
292
339
|
var import_utils3 = require("@moon-x/core/utils");
|
|
293
340
|
|
|
294
341
|
// src/transport/webview-bridge.ts
|
|
@@ -466,7 +513,12 @@ var MoonKeyProvider = ({
|
|
|
466
513
|
children
|
|
467
514
|
}) => {
|
|
468
515
|
const iframeUrl = config?.iframeUrl ?? DEFAULT_IFRAME_URL;
|
|
469
|
-
|
|
516
|
+
const relyingPartyOrigin = config?.relyingPartyOrigin ?? "";
|
|
517
|
+
if (!relyingPartyOrigin && typeof console !== "undefined") {
|
|
518
|
+
console.warn(
|
|
519
|
+
"[MoonKey] config.relyingPartyOrigin is empty \u2014 every sensitive op (sign / send / createWallet / importKey / exportKey / addPasskey / removePasskey) will fail until this is set to your host app's WebAuthn relying-party origin (e.g. https://wallet.acme.com)."
|
|
520
|
+
);
|
|
521
|
+
}
|
|
470
522
|
const webViewRef = (0, import_react.useRef)(null);
|
|
471
523
|
const bridge = (0, import_react.useMemo)(
|
|
472
524
|
() => new WebViewBridge(
|
|
@@ -559,6 +611,13 @@ var MoonKeyProvider = ({
|
|
|
559
611
|
() => createSdkInstance({
|
|
560
612
|
bridge,
|
|
561
613
|
publishableKey,
|
|
614
|
+
// Host-app WebAuthn relying-party origin. Supplied via
|
|
615
|
+
// MoonKeyProviderProps.config.relyingPartyOrigin; the mount-time
|
|
616
|
+
// warning above flags the empty case. Threaded into every
|
|
617
|
+
// sensitive op's call to getInternalPresenceTokens, which
|
|
618
|
+
// forwards it on /presence/begin so the server can rebuild the
|
|
619
|
+
// per-app WebAuthn RP config.
|
|
620
|
+
relyingPartyOrigin,
|
|
562
621
|
isAuthenticated,
|
|
563
622
|
user,
|
|
564
623
|
ready,
|
|
@@ -566,7 +625,15 @@ var MoonKeyProvider = ({
|
|
|
566
625
|
setUser,
|
|
567
626
|
refreshUser
|
|
568
627
|
}),
|
|
569
|
-
[
|
|
628
|
+
[
|
|
629
|
+
bridge,
|
|
630
|
+
publishableKey,
|
|
631
|
+
relyingPartyOrigin,
|
|
632
|
+
isAuthenticated,
|
|
633
|
+
user,
|
|
634
|
+
ready,
|
|
635
|
+
refreshUser
|
|
636
|
+
]
|
|
570
637
|
);
|
|
571
638
|
const sdkRef = (0, import_react.useRef)(sdk);
|
|
572
639
|
(0, import_react.useEffect)(() => {
|
|
@@ -635,10 +702,17 @@ var MoonKeyProvider = ({
|
|
|
635
702
|
() => ({
|
|
636
703
|
sdk,
|
|
637
704
|
_bridge: bridge,
|
|
705
|
+
_relyingPartyOrigin: relyingPartyOrigin,
|
|
638
706
|
_runSensitiveFlow: runSensitiveFlow,
|
|
639
707
|
_oauthRedirectUri: config?.oauthRedirectUri
|
|
640
708
|
}),
|
|
641
|
-
[
|
|
709
|
+
[
|
|
710
|
+
sdk,
|
|
711
|
+
bridge,
|
|
712
|
+
relyingPartyOrigin,
|
|
713
|
+
runSensitiveFlow,
|
|
714
|
+
config?.oauthRedirectUri
|
|
715
|
+
]
|
|
642
716
|
);
|
|
643
717
|
const closeLabel = config?.sensitiveModalCopy?.closeLabel ?? "Done";
|
|
644
718
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MoonKeyContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react2.SDKProvider, { value: sdk, children: [
|
|
@@ -894,24 +968,27 @@ var useDetachOAuth = () => {
|
|
|
894
968
|
};
|
|
895
969
|
|
|
896
970
|
// src/hooks/use-export-key.ts
|
|
897
|
-
var import_lib3 = require("@moon-x/core/lib");
|
|
898
971
|
var import_sdk6 = require("@moon-x/core/sdk");
|
|
972
|
+
var EXPORT_KEY_SCOPES = ["keyshare_read"];
|
|
899
973
|
var useExportKey = () => {
|
|
900
|
-
const { sdk, _bridge, _runSensitiveFlow } = useMoonKeyContext();
|
|
974
|
+
const { sdk, _bridge, _relyingPartyOrigin, _runSensitiveFlow } = useMoonKeyContext();
|
|
901
975
|
return {
|
|
902
|
-
exportKey:
|
|
903
|
-
const { userHandleB64url, credentialIdB64url } = await (0, import_sdk6.
|
|
976
|
+
exportKey: async (wallet) => {
|
|
977
|
+
const { userHandleB64url, credentialIdB64url, tokens } = await (0, import_sdk6.getInternalPresenceTokens)({
|
|
904
978
|
transport: _bridge,
|
|
905
979
|
passkey: createRNPasskey(),
|
|
906
980
|
publishableKey: sdk.publishableKey,
|
|
907
|
-
|
|
981
|
+
relyingPartyOrigin: _relyingPartyOrigin,
|
|
982
|
+
scopes: EXPORT_KEY_SCOPES
|
|
908
983
|
});
|
|
984
|
+
const keyshareReadToken = tokens.keyshare_read?.token ?? "";
|
|
909
985
|
const params = new URLSearchParams({
|
|
910
986
|
publishableKey: sdk.publishableKey,
|
|
911
987
|
wallet_id: wallet.id ?? "",
|
|
912
988
|
wallet_type: wallet.wallet_type ?? "",
|
|
913
989
|
user_handle_b64url: userHandleB64url,
|
|
914
|
-
credential_id_b64url: credentialIdB64url
|
|
990
|
+
credential_id_b64url: credentialIdB64url,
|
|
991
|
+
keyshare_read_token: keyshareReadToken
|
|
915
992
|
});
|
|
916
993
|
await _runSensitiveFlow({
|
|
917
994
|
title: "Export key",
|
|
@@ -922,7 +999,7 @@ var useExportKey = () => {
|
|
|
922
999
|
// happens when the user dismisses.
|
|
923
1000
|
onMount: () => Promise.resolve()
|
|
924
1001
|
});
|
|
925
|
-
}
|
|
1002
|
+
}
|
|
926
1003
|
};
|
|
927
1004
|
};
|
|
928
1005
|
|
package/dist/index.mjs
CHANGED
|
@@ -79,21 +79,56 @@ var createRNPasskey = () => ({
|
|
|
79
79
|
authenticatorAttachment: credential.authenticatorAttachment
|
|
80
80
|
};
|
|
81
81
|
return sanitized;
|
|
82
|
+
},
|
|
83
|
+
assertForInternalPresence: async ({ optionsJSON }) => {
|
|
84
|
+
const credential = await passkeyGet({
|
|
85
|
+
challenge: optionsJSON.challenge,
|
|
86
|
+
rpId: optionsJSON.rpId,
|
|
87
|
+
allowCredentials: [],
|
|
88
|
+
userVerification: optionsJSON.userVerification ?? "preferred"
|
|
89
|
+
});
|
|
90
|
+
if (!credential) throw new Error("passkey_assertion_cancelled");
|
|
91
|
+
const userHandle = credential.response.userHandle;
|
|
92
|
+
if (!userHandle) throw new Error("user_handle_missing");
|
|
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 {
|
|
107
|
+
response: sanitized,
|
|
108
|
+
userHandleB64url: userHandle,
|
|
109
|
+
credentialIdB64url: credential.rawId
|
|
110
|
+
};
|
|
82
111
|
}
|
|
83
112
|
});
|
|
84
113
|
|
|
85
114
|
// src/sdk/sdk-ethereum-methods.ts
|
|
86
|
-
var getEthereumSDKMethods = (bridge, publishableKey) => getHeadlessEthereumMethods({
|
|
115
|
+
var getEthereumSDKMethods = (bridge, publishableKey, relyingPartyOrigin) => getHeadlessEthereumMethods({
|
|
87
116
|
transport: bridge,
|
|
88
117
|
passkey: createRNPasskey(),
|
|
89
|
-
publishableKey
|
|
118
|
+
publishableKey,
|
|
119
|
+
relyingPartyOrigin
|
|
90
120
|
});
|
|
91
121
|
|
|
92
122
|
// src/sdk/sdk-passkey-methods.ts
|
|
93
123
|
import { generatePasskeyUserId, toB64url } from "@moon-x/core/lib";
|
|
94
|
-
import {
|
|
124
|
+
import {
|
|
125
|
+
flattenPresenceTokens,
|
|
126
|
+
getInternalPresenceTokens,
|
|
127
|
+
getPresenceToken
|
|
128
|
+
} from "@moon-x/core/sdk";
|
|
95
129
|
import { PostMessageMethod, PostMessageType } from "@moon-x/core/utils";
|
|
96
130
|
import { create as passkeyCreate } from "react-native-passkeys";
|
|
131
|
+
var ADD_PASSKEY_SCOPES = ["passkey_enroll", "wrap_add"];
|
|
97
132
|
var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
98
133
|
registerPasskey: async (params) => {
|
|
99
134
|
const dekInfo = await bridge.send(
|
|
@@ -109,16 +144,22 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
109
144
|
const isAdditional = (dekInfo.allow_credential_ids_b64url ?? []).length > 0;
|
|
110
145
|
let unlock = null;
|
|
111
146
|
if (isAdditional) {
|
|
112
|
-
|
|
147
|
+
const result = await getInternalPresenceTokens({
|
|
113
148
|
transport: bridge,
|
|
114
149
|
passkey: createRNPasskey(),
|
|
115
150
|
publishableKey,
|
|
116
|
-
|
|
151
|
+
relyingPartyOrigin,
|
|
152
|
+
scopes: ADD_PASSKEY_SCOPES
|
|
117
153
|
});
|
|
118
154
|
const allowList = dekInfo.allow_credential_ids_b64url ?? [];
|
|
119
|
-
if (!allowList.includes(
|
|
155
|
+
if (!allowList.includes(result.credentialIdB64url)) {
|
|
120
156
|
throw new Error("unknown_passkey_for_this_account");
|
|
121
157
|
}
|
|
158
|
+
unlock = {
|
|
159
|
+
userHandleB64url: result.userHandleB64url,
|
|
160
|
+
credentialIdB64url: result.credentialIdB64url,
|
|
161
|
+
presenceTokens: flattenPresenceTokens(result)
|
|
162
|
+
};
|
|
122
163
|
}
|
|
123
164
|
const beginResult = await bridge.send(
|
|
124
165
|
PostMessageType.AUTH,
|
|
@@ -153,7 +194,8 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
153
194
|
relyingPartyOrigin,
|
|
154
195
|
token,
|
|
155
196
|
credential,
|
|
156
|
-
userIdB64url
|
|
197
|
+
userIdB64url,
|
|
198
|
+
presenceTokens: unlock?.presenceTokens
|
|
157
199
|
}
|
|
158
200
|
);
|
|
159
201
|
if (isAdditional && unlock) {
|
|
@@ -165,7 +207,8 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
165
207
|
unlockUserHandleB64url: unlock.userHandleB64url,
|
|
166
208
|
unlockCredentialIdB64url: unlock.credentialIdB64url,
|
|
167
209
|
newUserHandleB64url: userIdB64url,
|
|
168
|
-
newCredentialIdB64url: credential.rawId
|
|
210
|
+
newCredentialIdB64url: credential.rawId,
|
|
211
|
+
presenceTokens: unlock.presenceTokens
|
|
169
212
|
}
|
|
170
213
|
);
|
|
171
214
|
}
|
|
@@ -204,27 +247,30 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
204
247
|
|
|
205
248
|
// src/sdk/sdk-methods.ts
|
|
206
249
|
import { getHeadlessGeneralMethods } from "@moon-x/core/sdk";
|
|
207
|
-
var getSDKMethods = (bridge, publishableKey, setIsAuthenticated, setUser) => getHeadlessGeneralMethods({
|
|
250
|
+
var getSDKMethods = (bridge, publishableKey, relyingPartyOrigin, setIsAuthenticated, setUser) => getHeadlessGeneralMethods({
|
|
208
251
|
transport: bridge,
|
|
209
252
|
passkey: createRNPasskey(),
|
|
210
253
|
storage: createAsyncStorageKv(),
|
|
211
254
|
publishableKey,
|
|
255
|
+
relyingPartyOrigin,
|
|
212
256
|
setIsAuthenticated,
|
|
213
257
|
setUser
|
|
214
258
|
});
|
|
215
259
|
|
|
216
260
|
// src/sdk/sdk-solana-methods.ts
|
|
217
261
|
import { getHeadlessSolanaMethods } from "@moon-x/core/sdk";
|
|
218
|
-
var getSolanaSDKMethods = (bridge, publishableKey) => getHeadlessSolanaMethods({
|
|
262
|
+
var getSolanaSDKMethods = (bridge, publishableKey, relyingPartyOrigin) => getHeadlessSolanaMethods({
|
|
219
263
|
transport: bridge,
|
|
220
264
|
passkey: createRNPasskey(),
|
|
221
|
-
publishableKey
|
|
265
|
+
publishableKey,
|
|
266
|
+
relyingPartyOrigin
|
|
222
267
|
});
|
|
223
268
|
|
|
224
269
|
// src/sdk/create-sdk-instance.ts
|
|
225
270
|
var createSdkInstance = ({
|
|
226
271
|
bridge,
|
|
227
272
|
publishableKey,
|
|
273
|
+
relyingPartyOrigin,
|
|
228
274
|
isAuthenticated,
|
|
229
275
|
user,
|
|
230
276
|
ready,
|
|
@@ -243,14 +289,19 @@ var createSdkInstance = ({
|
|
|
243
289
|
setIsAuthenticated,
|
|
244
290
|
setUser
|
|
245
291
|
),
|
|
246
|
-
...getSDKMethods(
|
|
292
|
+
...getSDKMethods(
|
|
293
|
+
bridge,
|
|
294
|
+
publishableKey,
|
|
295
|
+
relyingPartyOrigin,
|
|
296
|
+
setIsAuthenticated,
|
|
297
|
+
setUser
|
|
298
|
+
),
|
|
247
299
|
...getPasskeyMethods(bridge, publishableKey),
|
|
248
|
-
...getEthereumSDKMethods(bridge, publishableKey),
|
|
249
|
-
...getSolanaSDKMethods(bridge, publishableKey)
|
|
300
|
+
...getEthereumSDKMethods(bridge, publishableKey, relyingPartyOrigin),
|
|
301
|
+
...getSolanaSDKMethods(bridge, publishableKey, relyingPartyOrigin)
|
|
250
302
|
});
|
|
251
303
|
|
|
252
304
|
// src/provider.tsx
|
|
253
|
-
import { setAssertCacheTtlMs } from "@moon-x/core/lib";
|
|
254
305
|
import { PostMessageMethod as PostMessageMethod2, PostMessageType as PostMessageType2 } from "@moon-x/core/utils";
|
|
255
306
|
|
|
256
307
|
// src/transport/webview-bridge.ts
|
|
@@ -430,7 +481,12 @@ var MoonKeyProvider = ({
|
|
|
430
481
|
children
|
|
431
482
|
}) => {
|
|
432
483
|
const iframeUrl = config?.iframeUrl ?? DEFAULT_IFRAME_URL;
|
|
433
|
-
|
|
484
|
+
const relyingPartyOrigin = config?.relyingPartyOrigin ?? "";
|
|
485
|
+
if (!relyingPartyOrigin && typeof console !== "undefined") {
|
|
486
|
+
console.warn(
|
|
487
|
+
"[MoonKey] config.relyingPartyOrigin is empty \u2014 every sensitive op (sign / send / createWallet / importKey / exportKey / addPasskey / removePasskey) will fail until this is set to your host app's WebAuthn relying-party origin (e.g. https://wallet.acme.com)."
|
|
488
|
+
);
|
|
489
|
+
}
|
|
434
490
|
const webViewRef = useRef(null);
|
|
435
491
|
const bridge = useMemo(
|
|
436
492
|
() => new WebViewBridge(
|
|
@@ -523,6 +579,13 @@ var MoonKeyProvider = ({
|
|
|
523
579
|
() => createSdkInstance({
|
|
524
580
|
bridge,
|
|
525
581
|
publishableKey,
|
|
582
|
+
// Host-app WebAuthn relying-party origin. Supplied via
|
|
583
|
+
// MoonKeyProviderProps.config.relyingPartyOrigin; the mount-time
|
|
584
|
+
// warning above flags the empty case. Threaded into every
|
|
585
|
+
// sensitive op's call to getInternalPresenceTokens, which
|
|
586
|
+
// forwards it on /presence/begin so the server can rebuild the
|
|
587
|
+
// per-app WebAuthn RP config.
|
|
588
|
+
relyingPartyOrigin,
|
|
526
589
|
isAuthenticated,
|
|
527
590
|
user,
|
|
528
591
|
ready,
|
|
@@ -530,7 +593,15 @@ var MoonKeyProvider = ({
|
|
|
530
593
|
setUser,
|
|
531
594
|
refreshUser
|
|
532
595
|
}),
|
|
533
|
-
[
|
|
596
|
+
[
|
|
597
|
+
bridge,
|
|
598
|
+
publishableKey,
|
|
599
|
+
relyingPartyOrigin,
|
|
600
|
+
isAuthenticated,
|
|
601
|
+
user,
|
|
602
|
+
ready,
|
|
603
|
+
refreshUser
|
|
604
|
+
]
|
|
534
605
|
);
|
|
535
606
|
const sdkRef = useRef(sdk);
|
|
536
607
|
useEffect(() => {
|
|
@@ -599,10 +670,17 @@ var MoonKeyProvider = ({
|
|
|
599
670
|
() => ({
|
|
600
671
|
sdk,
|
|
601
672
|
_bridge: bridge,
|
|
673
|
+
_relyingPartyOrigin: relyingPartyOrigin,
|
|
602
674
|
_runSensitiveFlow: runSensitiveFlow,
|
|
603
675
|
_oauthRedirectUri: config?.oauthRedirectUri
|
|
604
676
|
}),
|
|
605
|
-
[
|
|
677
|
+
[
|
|
678
|
+
sdk,
|
|
679
|
+
bridge,
|
|
680
|
+
relyingPartyOrigin,
|
|
681
|
+
runSensitiveFlow,
|
|
682
|
+
config?.oauthRedirectUri
|
|
683
|
+
]
|
|
606
684
|
);
|
|
607
685
|
const closeLabel = config?.sensitiveModalCopy?.closeLabel ?? "Done";
|
|
608
686
|
return /* @__PURE__ */ jsx(MoonKeyContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxs(SDKProvider, { value: sdk, children: [
|
|
@@ -869,24 +947,27 @@ var useDetachOAuth = () => {
|
|
|
869
947
|
};
|
|
870
948
|
|
|
871
949
|
// src/hooks/use-export-key.ts
|
|
872
|
-
import {
|
|
873
|
-
|
|
950
|
+
import { getInternalPresenceTokens as getInternalPresenceTokens2 } from "@moon-x/core/sdk";
|
|
951
|
+
var EXPORT_KEY_SCOPES = ["keyshare_read"];
|
|
874
952
|
var useExportKey = () => {
|
|
875
|
-
const { sdk, _bridge, _runSensitiveFlow } = useMoonKeyContext();
|
|
953
|
+
const { sdk, _bridge, _relyingPartyOrigin, _runSensitiveFlow } = useMoonKeyContext();
|
|
876
954
|
return {
|
|
877
|
-
exportKey:
|
|
878
|
-
const { userHandleB64url, credentialIdB64url } = await
|
|
955
|
+
exportKey: async (wallet) => {
|
|
956
|
+
const { userHandleB64url, credentialIdB64url, tokens } = await getInternalPresenceTokens2({
|
|
879
957
|
transport: _bridge,
|
|
880
958
|
passkey: createRNPasskey(),
|
|
881
959
|
publishableKey: sdk.publishableKey,
|
|
882
|
-
|
|
960
|
+
relyingPartyOrigin: _relyingPartyOrigin,
|
|
961
|
+
scopes: EXPORT_KEY_SCOPES
|
|
883
962
|
});
|
|
963
|
+
const keyshareReadToken = tokens.keyshare_read?.token ?? "";
|
|
884
964
|
const params = new URLSearchParams({
|
|
885
965
|
publishableKey: sdk.publishableKey,
|
|
886
966
|
wallet_id: wallet.id ?? "",
|
|
887
967
|
wallet_type: wallet.wallet_type ?? "",
|
|
888
968
|
user_handle_b64url: userHandleB64url,
|
|
889
|
-
credential_id_b64url: credentialIdB64url
|
|
969
|
+
credential_id_b64url: credentialIdB64url,
|
|
970
|
+
keyshare_read_token: keyshareReadToken
|
|
890
971
|
});
|
|
891
972
|
await _runSensitiveFlow({
|
|
892
973
|
title: "Export key",
|
|
@@ -897,7 +978,7 @@ var useExportKey = () => {
|
|
|
897
978
|
// happens when the user dismisses.
|
|
898
979
|
onMount: () => Promise.resolve()
|
|
899
980
|
});
|
|
900
|
-
}
|
|
981
|
+
}
|
|
901
982
|
};
|
|
902
983
|
};
|
|
903
984
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moon-x/react-native-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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.4.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@expo/config-plugins": ">=10.0.0",
|