@moon-x/react-native-sdk 0.2.0 → 0.4.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 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
- ### 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.
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
 
@@ -160,6 +155,7 @@ discussion.
160
155
  | `useCreateWallet()` | Mint a new MPC wallet. Pass `{ walletType: "ethereum" \| "solana" }`. |
161
156
  | `useImportKey()` | Bring-your-own-key flow. |
162
157
  | `useExportKey()` | Show the user their private key via the visible-WebView modal pattern (see below). Plaintext never leaves the WebView's DOM. |
158
+ | `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. |
163
159
 
164
160
  ### Per-chain signing — `/ethereum` and `/solana` subpaths
165
161
 
package/dist/index.d.mts CHANGED
@@ -1,10 +1,11 @@
1
1
  import React, { ReactNode } from 'react';
2
+ import { RelyingPartyOriginInput } from '@moon-x/core/sdk';
2
3
  import { PostMessageType, PostMessageMethod } from '@moon-x/core/utils';
3
4
  export { PostMessageMethod, PostMessageType } from '@moon-x/core/utils';
4
5
  import * as _moon_x_core_types from '@moon-x/core/types';
5
6
  import { PublicWallet, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSendTransactionParams, EthereumSendTransactionResult, EthereumGetBalanceParams, EthereumGetBalanceResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaGetBalanceParams, SolanaGetBalanceResult } from '@moon-x/core/types';
6
- export { Chain, EthereumGetBalanceParams, EthereumGetBalanceResult, EthereumSendTransactionParams, EthereumSendTransactionResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, Network, PublicWallet, SolanaGetBalanceParams, SolanaGetBalanceResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, WalletConnectConfig } from '@moon-x/core/types';
7
- export { useAddPasskey, useCreateWallet, useImportKey, useLoginWithEmail, useLogout, usePasskeyStatus, useRegisterPasskey, useRemovePasskey, useUser, useWallets } from '@moon-x/core/react';
7
+ export { Chain, EphemeralSigner, EphemeralSignerChain, EphemeralSignerScheme, EphemeralSignerWallet, EthereumGetBalanceParams, EthereumGetBalanceResult, EthereumSendTransactionParams, EthereumSendTransactionResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, ListEphemeralSignersResult, Network, ProvisionEphemeralSignerParams, ProvisionEphemeralSignerResult, PublicWallet, RevokeEphemeralSignerParams, SolanaGetBalanceParams, SolanaGetBalanceResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, WalletConnectConfig } from '@moon-x/core/types';
8
+ export { UseEphemeralSignerResult, useAddPasskey, useCreateWallet, useEphemeralSigner, useImportKey, useLoginWithEmail, useLogout, usePasskeyStatus, useRegisterPasskey, useRemovePasskey, useUser, useWallets } from '@moon-x/core/react';
8
9
 
9
10
  interface WebViewRefLike {
10
11
  injectJavaScript: (script: string) => void;
@@ -129,6 +130,20 @@ interface MoonKeyConfig {
129
130
  * Deep-link URI scheme used as the OAuth redirect target.
130
131
  */
131
132
  oauthRedirectUri?: string;
133
+ /**
134
+ * **Optional override** for the host app's WebAuthn relying-party
135
+ * origin (e.g. `"https://wallet.acme.com"`). The SDK threads this into
136
+ * the internal presence-token orchestrator at
137
+ * `/auth/passkey/presence/begin` so the backend can rebuild the
138
+ * per-app WebAuthn RP config the native authenticator asserts against.
139
+ *
140
+ * Leave it unset in the common case: the SDK derives the origin
141
+ * automatically from the app's server-configured `rp_id` (fetched via
142
+ * the iframe) as `https://<rp_id>`, matching what the native passkey
143
+ * ceremony uses. Set this only if your app needs an origin that
144
+ * differs from the configured `rp_id`.
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
- * Security-policy knobs. Safe defaults (the entire `security` object
141
- * can be omitted for the strictest posture).
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: RelyingPartyOriginInput;
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
@@ -1,10 +1,11 @@
1
1
  import React, { ReactNode } from 'react';
2
+ import { RelyingPartyOriginInput } from '@moon-x/core/sdk';
2
3
  import { PostMessageType, PostMessageMethod } from '@moon-x/core/utils';
3
4
  export { PostMessageMethod, PostMessageType } from '@moon-x/core/utils';
4
5
  import * as _moon_x_core_types from '@moon-x/core/types';
5
6
  import { PublicWallet, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSendTransactionParams, EthereumSendTransactionResult, EthereumGetBalanceParams, EthereumGetBalanceResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaGetBalanceParams, SolanaGetBalanceResult } from '@moon-x/core/types';
6
- export { Chain, EthereumGetBalanceParams, EthereumGetBalanceResult, EthereumSendTransactionParams, EthereumSendTransactionResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, Network, PublicWallet, SolanaGetBalanceParams, SolanaGetBalanceResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, WalletConnectConfig } from '@moon-x/core/types';
7
- export { useAddPasskey, useCreateWallet, useImportKey, useLoginWithEmail, useLogout, usePasskeyStatus, useRegisterPasskey, useRemovePasskey, useUser, useWallets } from '@moon-x/core/react';
7
+ export { Chain, EphemeralSigner, EphemeralSignerChain, EphemeralSignerScheme, EphemeralSignerWallet, EthereumGetBalanceParams, EthereumGetBalanceResult, EthereumSendTransactionParams, EthereumSendTransactionResult, EthereumSign7702AuthorizationParams, EthereumSign7702AuthorizationResult, EthereumSignHashParams, EthereumSignHashResult, EthereumSignMessageParams, EthereumSignMessageResult, EthereumSignTransactionParams, EthereumSignTransactionResult, EthereumSignTypedDataParams, EthereumSignTypedDataResult, ListEphemeralSignersResult, Network, ProvisionEphemeralSignerParams, ProvisionEphemeralSignerResult, PublicWallet, RevokeEphemeralSignerParams, SolanaGetBalanceParams, SolanaGetBalanceResult, SolanaSendTransactionParams, SolanaSendTransactionResult, SolanaSignMessageParams, SolanaSignMessageResult, SolanaSignTransactionParams, SolanaSignTransactionResult, WalletConnectConfig } from '@moon-x/core/types';
8
+ export { UseEphemeralSignerResult, useAddPasskey, useCreateWallet, useEphemeralSigner, useImportKey, useLoginWithEmail, useLogout, usePasskeyStatus, useRegisterPasskey, useRemovePasskey, useUser, useWallets } from '@moon-x/core/react';
8
9
 
9
10
  interface WebViewRefLike {
10
11
  injectJavaScript: (script: string) => void;
@@ -129,6 +130,20 @@ interface MoonKeyConfig {
129
130
  * Deep-link URI scheme used as the OAuth redirect target.
130
131
  */
131
132
  oauthRedirectUri?: string;
133
+ /**
134
+ * **Optional override** for the host app's WebAuthn relying-party
135
+ * origin (e.g. `"https://wallet.acme.com"`). The SDK threads this into
136
+ * the internal presence-token orchestrator at
137
+ * `/auth/passkey/presence/begin` so the backend can rebuild the
138
+ * per-app WebAuthn RP config the native authenticator asserts against.
139
+ *
140
+ * Leave it unset in the common case: the SDK derives the origin
141
+ * automatically from the app's server-configured `rp_id` (fetched via
142
+ * the iframe) as `https://<rp_id>`, matching what the native passkey
143
+ * ceremony uses. Set this only if your app needs an origin that
144
+ * differs from the configured `rp_id`.
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
- * Security-policy knobs. Safe defaults (the entire `security` object
141
- * can be omitted for the strictest posture).
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: RelyingPartyOriginInput;
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
@@ -31,12 +31,13 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  MoonKeyProvider: () => MoonKeyProvider,
34
- PostMessageMethod: () => import_utils7.PostMessageMethod,
35
- PostMessageType: () => import_utils7.PostMessageType,
34
+ PostMessageMethod: () => import_utils8.PostMessageMethod,
35
+ PostMessageType: () => import_utils8.PostMessageType,
36
36
  useAddPasskey: () => import_react5.useAddPasskey,
37
37
  useAttachOAuth: () => useAttachOAuth,
38
38
  useCreateWallet: () => import_react5.useCreateWallet,
39
39
  useDetachOAuth: () => useDetachOAuth,
40
+ useEphemeralSigner: () => import_react5.useEphemeralSigner,
40
41
  useExportKey: () => useExportKey,
41
42
  useImportKey: () => import_react5.useImportKey,
42
43
  useLoginWithEmail: () => import_react5.useLoginWithEmail,
@@ -57,6 +58,9 @@ var import_react = require("react");
57
58
  var import_react_native = require("react-native");
58
59
  var import_react_native_webview = require("react-native-webview");
59
60
 
61
+ // src/sdk/create-sdk-instance.ts
62
+ var import_utils2 = require("@moon-x/core/utils");
63
+
60
64
  // src/sdk/sdk-authentication-methods.ts
61
65
  var import_sdk = require("@moon-x/core/sdk");
62
66
  var getAuthenticationMethods = (bridge, publishableKey, setIsAuthenticated, setUser) => (0, import_sdk.getHeadlessAuthenticationMethods)({
@@ -117,14 +121,44 @@ var createRNPasskey = () => ({
117
121
  authenticatorAttachment: credential.authenticatorAttachment
118
122
  };
119
123
  return sanitized;
124
+ },
125
+ assertForInternalPresence: async ({ optionsJSON }) => {
126
+ const credential = await (0, import_react_native_passkeys.get)({
127
+ challenge: optionsJSON.challenge,
128
+ rpId: optionsJSON.rpId,
129
+ allowCredentials: [],
130
+ userVerification: optionsJSON.userVerification ?? "preferred"
131
+ });
132
+ if (!credential) throw new Error("passkey_assertion_cancelled");
133
+ const userHandle = credential.response.userHandle;
134
+ if (!userHandle) throw new Error("user_handle_missing");
135
+ const sanitized = {
136
+ id: credential.id ?? credential.rawId,
137
+ rawId: credential.rawId,
138
+ type: credential.type ?? "public-key",
139
+ response: {
140
+ clientDataJSON: credential.response.clientDataJSON,
141
+ authenticatorData: credential.response.authenticatorData,
142
+ signature: credential.response.signature,
143
+ userHandle: void 0
144
+ },
145
+ clientExtensionResults: credential.clientExtensionResults ?? {},
146
+ authenticatorAttachment: credential.authenticatorAttachment
147
+ };
148
+ return {
149
+ response: sanitized,
150
+ userHandleB64url: userHandle,
151
+ credentialIdB64url: credential.rawId
152
+ };
120
153
  }
121
154
  });
122
155
 
123
156
  // src/sdk/sdk-ethereum-methods.ts
124
- var getEthereumSDKMethods = (bridge, publishableKey) => (0, import_sdk2.getHeadlessEthereumMethods)({
157
+ var getEthereumSDKMethods = (bridge, publishableKey, relyingPartyOrigin) => (0, import_sdk2.getHeadlessEthereumMethods)({
125
158
  transport: bridge,
126
159
  passkey: createRNPasskey(),
127
- publishableKey
160
+ publishableKey,
161
+ relyingPartyOrigin
128
162
  });
129
163
 
130
164
  // src/sdk/sdk-passkey-methods.ts
@@ -132,6 +166,7 @@ var import_lib = require("@moon-x/core/lib");
132
166
  var import_sdk3 = require("@moon-x/core/sdk");
133
167
  var import_utils = require("@moon-x/core/utils");
134
168
  var import_react_native_passkeys2 = require("react-native-passkeys");
169
+ var ADD_PASSKEY_SCOPES = ["passkey_enroll", "wrap_add"];
135
170
  var getPasskeyMethods = (bridge, publishableKey) => ({
136
171
  registerPasskey: async (params) => {
137
172
  const dekInfo = await bridge.send(
@@ -147,16 +182,22 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
147
182
  const isAdditional = (dekInfo.allow_credential_ids_b64url ?? []).length > 0;
148
183
  let unlock = null;
149
184
  if (isAdditional) {
150
- unlock = await (0, import_sdk3.assertPasskeyInParent)({
185
+ const result = await (0, import_sdk3.getInternalPresenceTokens)({
151
186
  transport: bridge,
152
187
  passkey: createRNPasskey(),
153
188
  publishableKey,
154
- requireFreshAssertion: true
189
+ relyingPartyOrigin,
190
+ scopes: ADD_PASSKEY_SCOPES
155
191
  });
156
192
  const allowList = dekInfo.allow_credential_ids_b64url ?? [];
157
- if (!allowList.includes(unlock.credentialIdB64url)) {
193
+ if (!allowList.includes(result.credentialIdB64url)) {
158
194
  throw new Error("unknown_passkey_for_this_account");
159
195
  }
196
+ unlock = {
197
+ userHandleB64url: result.userHandleB64url,
198
+ credentialIdB64url: result.credentialIdB64url,
199
+ presenceTokens: (0, import_sdk3.flattenPresenceTokens)(result)
200
+ };
160
201
  }
161
202
  const beginResult = await bridge.send(
162
203
  import_utils.PostMessageType.AUTH,
@@ -191,7 +232,8 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
191
232
  relyingPartyOrigin,
192
233
  token,
193
234
  credential,
194
- userIdB64url
235
+ userIdB64url,
236
+ presenceTokens: unlock?.presenceTokens
195
237
  }
196
238
  );
197
239
  if (isAdditional && unlock) {
@@ -203,7 +245,8 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
203
245
  unlockUserHandleB64url: unlock.userHandleB64url,
204
246
  unlockCredentialIdB64url: unlock.credentialIdB64url,
205
247
  newUserHandleB64url: userIdB64url,
206
- newCredentialIdB64url: credential.rawId
248
+ newCredentialIdB64url: credential.rawId,
249
+ presenceTokens: unlock.presenceTokens
207
250
  }
208
251
  );
209
252
  }
@@ -242,27 +285,46 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
242
285
 
243
286
  // src/sdk/sdk-methods.ts
244
287
  var import_sdk4 = require("@moon-x/core/sdk");
245
- var getSDKMethods = (bridge, publishableKey, setIsAuthenticated, setUser) => (0, import_sdk4.getHeadlessGeneralMethods)({
288
+ var getSDKMethods = (bridge, publishableKey, relyingPartyOrigin, setIsAuthenticated, setUser) => (0, import_sdk4.getHeadlessGeneralMethods)({
246
289
  transport: bridge,
247
290
  passkey: createRNPasskey(),
248
291
  storage: createAsyncStorageKv(),
249
292
  publishableKey,
293
+ relyingPartyOrigin,
250
294
  setIsAuthenticated,
251
295
  setUser
252
296
  });
253
297
 
254
298
  // src/sdk/sdk-solana-methods.ts
255
299
  var import_sdk5 = require("@moon-x/core/sdk");
256
- var getSolanaSDKMethods = (bridge, publishableKey) => (0, import_sdk5.getHeadlessSolanaMethods)({
300
+ var getSolanaSDKMethods = (bridge, publishableKey, relyingPartyOrigin) => (0, import_sdk5.getHeadlessSolanaMethods)({
257
301
  transport: bridge,
258
302
  passkey: createRNPasskey(),
259
- publishableKey
303
+ publishableKey,
304
+ relyingPartyOrigin
260
305
  });
261
306
 
262
307
  // src/sdk/create-sdk-instance.ts
308
+ var makeRelyingPartyOriginResolver = (bridge, publishableKey, configuredOrigin) => {
309
+ let cached = configuredOrigin || null;
310
+ return async () => {
311
+ if (cached) return cached;
312
+ const dekInfo = await bridge.send(
313
+ import_utils2.PostMessageType.AUTH,
314
+ import_utils2.PostMessageMethod.GET_DEK_INFO,
315
+ { publishableKey }
316
+ );
317
+ if (!dekInfo.rp_id) {
318
+ throw new Error("webauthn_rp_id_not_configured");
319
+ }
320
+ cached = `https://${dekInfo.rp_id}`;
321
+ return cached;
322
+ };
323
+ };
263
324
  var createSdkInstance = ({
264
325
  bridge,
265
326
  publishableKey,
327
+ relyingPartyOrigin,
266
328
  isAuthenticated,
267
329
  user,
268
330
  ready,
@@ -281,18 +343,23 @@ var createSdkInstance = ({
281
343
  setIsAuthenticated,
282
344
  setUser
283
345
  ),
284
- ...getSDKMethods(bridge, publishableKey, setIsAuthenticated, setUser),
346
+ ...getSDKMethods(
347
+ bridge,
348
+ publishableKey,
349
+ relyingPartyOrigin,
350
+ setIsAuthenticated,
351
+ setUser
352
+ ),
285
353
  ...getPasskeyMethods(bridge, publishableKey),
286
- ...getEthereumSDKMethods(bridge, publishableKey),
287
- ...getSolanaSDKMethods(bridge, publishableKey)
354
+ ...getEthereumSDKMethods(bridge, publishableKey, relyingPartyOrigin),
355
+ ...getSolanaSDKMethods(bridge, publishableKey, relyingPartyOrigin)
288
356
  });
289
357
 
290
358
  // src/provider.tsx
291
- var import_lib2 = require("@moon-x/core/lib");
292
- var import_utils3 = require("@moon-x/core/utils");
359
+ var import_utils4 = require("@moon-x/core/utils");
293
360
 
294
361
  // src/transport/webview-bridge.ts
295
- var import_utils2 = require("@moon-x/core/utils");
362
+ var import_utils3 = require("@moon-x/core/utils");
296
363
  var REQUEST_TIMEOUT_MS = 3e4;
297
364
  var generateUUID = () => {
298
365
  if (typeof crypto !== "undefined" && crypto.randomUUID) {
@@ -368,7 +435,7 @@ var WebViewBridge = class {
368
435
  resolver.resolve(message.data);
369
436
  } else {
370
437
  const err = new Error(message.error || "WebView bridge error");
371
- for (const key of import_utils2.FORWARDED_ERROR_FIELDS) {
438
+ for (const key of import_utils3.FORWARDED_ERROR_FIELDS) {
372
439
  const value = message[key];
373
440
  if (value !== void 0) {
374
441
  err[key] = value;
@@ -466,7 +533,7 @@ var MoonKeyProvider = ({
466
533
  children
467
534
  }) => {
468
535
  const iframeUrl = config?.iframeUrl ?? DEFAULT_IFRAME_URL;
469
- (0, import_lib2.setAssertCacheTtlMs)(config?.security?.assertionCacheTtlMs ?? 0);
536
+ const relyingPartyOrigin = config?.relyingPartyOrigin ?? "";
470
537
  const webViewRef = (0, import_react.useRef)(null);
471
538
  const bridge = (0, import_react.useMemo)(
472
539
  () => new WebViewBridge(
@@ -474,6 +541,10 @@ var MoonKeyProvider = ({
474
541
  ),
475
542
  []
476
543
  );
544
+ const relyingPartyOriginResolver = (0, import_react.useMemo)(
545
+ () => makeRelyingPartyOriginResolver(bridge, publishableKey, relyingPartyOrigin),
546
+ [bridge, publishableKey, relyingPartyOrigin]
547
+ );
477
548
  const [sensitiveVisible, setSensitiveVisible] = (0, import_react.useState)(false);
478
549
  const cancelRef = (0, import_react.useRef)(null);
479
550
  const [ready, setReady] = (0, import_react.useState)(false);
@@ -559,6 +630,12 @@ var MoonKeyProvider = ({
559
630
  () => createSdkInstance({
560
631
  bridge,
561
632
  publishableKey,
633
+ // Shared resolver — empty in the common case, then derives
634
+ // `https://<rp_id>` from the iframe at the first sensitive op and
635
+ // threads it into getInternalPresenceTokens, which forwards it on
636
+ // /presence/begin so the server can rebuild the per-app WebAuthn
637
+ // RP config.
638
+ relyingPartyOrigin: relyingPartyOriginResolver,
562
639
  isAuthenticated,
563
640
  user,
564
641
  ready,
@@ -566,7 +643,15 @@ var MoonKeyProvider = ({
566
643
  setUser,
567
644
  refreshUser
568
645
  }),
569
- [bridge, publishableKey, isAuthenticated, user, ready, refreshUser]
646
+ [
647
+ bridge,
648
+ publishableKey,
649
+ relyingPartyOriginResolver,
650
+ isAuthenticated,
651
+ user,
652
+ ready,
653
+ refreshUser
654
+ ]
570
655
  );
571
656
  const sdkRef = (0, import_react.useRef)(sdk);
572
657
  (0, import_react.useEffect)(() => {
@@ -580,8 +665,8 @@ var MoonKeyProvider = ({
580
665
  (0, import_react.useEffect)(() => {
581
666
  let cancelled = false;
582
667
  const unregister = bridge.register(
583
- import_utils3.PostMessageType.INIT,
584
- import_utils3.PostMessageMethod.READY,
668
+ import_utils4.PostMessageType.INIT,
669
+ import_utils4.PostMessageMethod.READY,
585
670
  () => {
586
671
  if (!cancelled) setReady(true);
587
672
  }
@@ -635,10 +720,17 @@ var MoonKeyProvider = ({
635
720
  () => ({
636
721
  sdk,
637
722
  _bridge: bridge,
723
+ _relyingPartyOrigin: relyingPartyOriginResolver,
638
724
  _runSensitiveFlow: runSensitiveFlow,
639
725
  _oauthRedirectUri: config?.oauthRedirectUri
640
726
  }),
641
- [sdk, bridge, runSensitiveFlow, config?.oauthRedirectUri]
727
+ [
728
+ sdk,
729
+ bridge,
730
+ relyingPartyOriginResolver,
731
+ runSensitiveFlow,
732
+ config?.oauthRedirectUri
733
+ ]
642
734
  );
643
735
  const closeLabel = config?.sensitiveModalCopy?.closeLabel ?? "Done";
644
736
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MoonKeyContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react2.SDKProvider, { value: sdk, children: [
@@ -785,7 +877,7 @@ var styles = import_react_native.StyleSheet.create({
785
877
  var import_react5 = require("@moon-x/core/react");
786
878
 
787
879
  // src/hooks/use-attach-oauth.ts
788
- var import_utils4 = require("@moon-x/core/utils");
880
+ var import_utils5 = require("@moon-x/core/utils");
789
881
  var import_react3 = require("react");
790
882
 
791
883
  // src/lib/oauth-deep-link.ts
@@ -836,8 +928,8 @@ var useAttachOAuth = (params) => {
836
928
  const redirectUri = params?.redirectUri || _oauthRedirectUri;
837
929
  if (!redirectUri) throw new Error("oauth_redirect_uri_missing");
838
930
  const startResult = await _bridge.send(
839
- import_utils4.PostMessageType.AUTH,
840
- import_utils4.PostMessageMethod.START_OAUTH,
931
+ import_utils5.PostMessageType.AUTH,
932
+ import_utils5.PostMessageMethod.START_OAUTH,
841
933
  {
842
934
  publishableKey: sdk.publishableKey,
843
935
  provider,
@@ -857,8 +949,8 @@ var useAttachOAuth = (params) => {
857
949
  if (parsed.error) throw new Error(parsed.error);
858
950
  setState({ status: "verifying" });
859
951
  await _bridge.send(
860
- import_utils4.PostMessageType.AUTH,
861
- import_utils4.PostMessageMethod.ATTACH_OAUTH,
952
+ import_utils5.PostMessageType.AUTH,
953
+ import_utils5.PostMessageMethod.ATTACH_OAUTH,
862
954
  {
863
955
  publishableKey: sdk.publishableKey,
864
956
  provider,
@@ -879,14 +971,14 @@ var useAttachOAuth = (params) => {
879
971
  };
880
972
 
881
973
  // src/hooks/use-detach-oauth.ts
882
- var import_utils5 = require("@moon-x/core/utils");
974
+ var import_utils6 = require("@moon-x/core/utils");
883
975
  var useDetachOAuth = () => {
884
976
  const { sdk, _bridge } = useMoonKeyContext();
885
977
  return {
886
978
  detachOAuth: async (idpUserId) => {
887
979
  await _bridge.send(
888
- import_utils5.PostMessageType.AUTH,
889
- import_utils5.PostMessageMethod.DETACH_OAUTH,
980
+ import_utils6.PostMessageType.AUTH,
981
+ import_utils6.PostMessageMethod.DETACH_OAUTH,
890
982
  { publishableKey: sdk.publishableKey, idpUserId }
891
983
  );
892
984
  }
@@ -894,24 +986,27 @@ var useDetachOAuth = () => {
894
986
  };
895
987
 
896
988
  // src/hooks/use-export-key.ts
897
- var import_lib3 = require("@moon-x/core/lib");
898
989
  var import_sdk6 = require("@moon-x/core/sdk");
990
+ var EXPORT_KEY_SCOPES = ["keyshare_read"];
899
991
  var useExportKey = () => {
900
- const { sdk, _bridge, _runSensitiveFlow } = useMoonKeyContext();
992
+ const { sdk, _bridge, _relyingPartyOrigin, _runSensitiveFlow } = useMoonKeyContext();
901
993
  return {
902
- exportKey: (wallet) => (0, import_lib3.withClearOnFailure)(async () => {
903
- const { userHandleB64url, credentialIdB64url } = await (0, import_sdk6.assertPasskeyInParent)({
994
+ exportKey: async (wallet) => {
995
+ const { userHandleB64url, credentialIdB64url, tokens } = await (0, import_sdk6.getInternalPresenceTokens)({
904
996
  transport: _bridge,
905
997
  passkey: createRNPasskey(),
906
998
  publishableKey: sdk.publishableKey,
907
- requireFreshAssertion: true
999
+ relyingPartyOrigin: _relyingPartyOrigin,
1000
+ scopes: EXPORT_KEY_SCOPES
908
1001
  });
1002
+ const keyshareReadToken = tokens.keyshare_read?.token ?? "";
909
1003
  const params = new URLSearchParams({
910
1004
  publishableKey: sdk.publishableKey,
911
1005
  wallet_id: wallet.id ?? "",
912
1006
  wallet_type: wallet.wallet_type ?? "",
913
1007
  user_handle_b64url: userHandleB64url,
914
- credential_id_b64url: credentialIdB64url
1008
+ credential_id_b64url: credentialIdB64url,
1009
+ keyshare_read_token: keyshareReadToken
915
1010
  });
916
1011
  await _runSensitiveFlow({
917
1012
  title: "Export key",
@@ -922,12 +1017,12 @@ var useExportKey = () => {
922
1017
  // happens when the user dismisses.
923
1018
  onMount: () => Promise.resolve()
924
1019
  });
925
- })
1020
+ }
926
1021
  };
927
1022
  };
928
1023
 
929
1024
  // src/hooks/use-login-with-oauth.ts
930
- var import_utils6 = require("@moon-x/core/utils");
1025
+ var import_utils7 = require("@moon-x/core/utils");
931
1026
  var import_react4 = require("react");
932
1027
  var useLoginWithOAuth = (params) => {
933
1028
  const { sdk, _bridge, _oauthRedirectUri } = useMoonKeyContext();
@@ -942,8 +1037,8 @@ var useLoginWithOAuth = (params) => {
942
1037
  throw new Error("oauth_redirect_uri_missing");
943
1038
  }
944
1039
  const startResult = await _bridge.send(
945
- import_utils6.PostMessageType.AUTH,
946
- import_utils6.PostMessageMethod.START_OAUTH,
1040
+ import_utils7.PostMessageType.AUTH,
1041
+ import_utils7.PostMessageMethod.START_OAUTH,
947
1042
  {
948
1043
  publishableKey: sdk.publishableKey,
949
1044
  provider,
@@ -985,7 +1080,7 @@ var useLoginWithOAuth = (params) => {
985
1080
  var useMoonKey = () => useMoonKeyContext().sdk;
986
1081
 
987
1082
  // src/index.ts
988
- var import_utils7 = require("@moon-x/core/utils");
1083
+ var import_utils8 = require("@moon-x/core/utils");
989
1084
  // Annotate the CommonJS export names for ESM import in node:
990
1085
  0 && (module.exports = {
991
1086
  MoonKeyProvider,
@@ -995,6 +1090,7 @@ var import_utils7 = require("@moon-x/core/utils");
995
1090
  useAttachOAuth,
996
1091
  useCreateWallet,
997
1092
  useDetachOAuth,
1093
+ useEphemeralSigner,
998
1094
  useExportKey,
999
1095
  useImportKey,
1000
1096
  useLoginWithEmail,
package/dist/index.mjs CHANGED
@@ -19,6 +19,9 @@ import {
19
19
  } from "react-native";
20
20
  import { WebView } from "react-native-webview";
21
21
 
22
+ // src/sdk/create-sdk-instance.ts
23
+ import { PostMessageMethod as PostMessageMethod2, PostMessageType as PostMessageType2 } from "@moon-x/core/utils";
24
+
22
25
  // src/sdk/sdk-authentication-methods.ts
23
26
  import { getHeadlessAuthenticationMethods } from "@moon-x/core/sdk";
24
27
  var getAuthenticationMethods = (bridge, publishableKey, setIsAuthenticated, setUser) => getHeadlessAuthenticationMethods({
@@ -29,7 +32,9 @@ var getAuthenticationMethods = (bridge, publishableKey, setIsAuthenticated, setU
29
32
  });
30
33
 
31
34
  // src/sdk/sdk-ethereum-methods.ts
32
- import { getHeadlessEthereumMethods } from "@moon-x/core/sdk";
35
+ import {
36
+ getHeadlessEthereumMethods
37
+ } from "@moon-x/core/sdk";
33
38
 
34
39
  // src/platform/async-storage-kv.ts
35
40
  import AsyncStorage from "@react-native-async-storage/async-storage";
@@ -79,21 +84,56 @@ var createRNPasskey = () => ({
79
84
  authenticatorAttachment: credential.authenticatorAttachment
80
85
  };
81
86
  return sanitized;
87
+ },
88
+ assertForInternalPresence: async ({ optionsJSON }) => {
89
+ const credential = await passkeyGet({
90
+ challenge: optionsJSON.challenge,
91
+ rpId: optionsJSON.rpId,
92
+ allowCredentials: [],
93
+ userVerification: optionsJSON.userVerification ?? "preferred"
94
+ });
95
+ if (!credential) throw new Error("passkey_assertion_cancelled");
96
+ const userHandle = credential.response.userHandle;
97
+ if (!userHandle) throw new Error("user_handle_missing");
98
+ const sanitized = {
99
+ id: credential.id ?? credential.rawId,
100
+ rawId: credential.rawId,
101
+ type: credential.type ?? "public-key",
102
+ response: {
103
+ clientDataJSON: credential.response.clientDataJSON,
104
+ authenticatorData: credential.response.authenticatorData,
105
+ signature: credential.response.signature,
106
+ userHandle: void 0
107
+ },
108
+ clientExtensionResults: credential.clientExtensionResults ?? {},
109
+ authenticatorAttachment: credential.authenticatorAttachment
110
+ };
111
+ return {
112
+ response: sanitized,
113
+ userHandleB64url: userHandle,
114
+ credentialIdB64url: credential.rawId
115
+ };
82
116
  }
83
117
  });
84
118
 
85
119
  // src/sdk/sdk-ethereum-methods.ts
86
- var getEthereumSDKMethods = (bridge, publishableKey) => getHeadlessEthereumMethods({
120
+ var getEthereumSDKMethods = (bridge, publishableKey, relyingPartyOrigin) => getHeadlessEthereumMethods({
87
121
  transport: bridge,
88
122
  passkey: createRNPasskey(),
89
- publishableKey
123
+ publishableKey,
124
+ relyingPartyOrigin
90
125
  });
91
126
 
92
127
  // src/sdk/sdk-passkey-methods.ts
93
128
  import { generatePasskeyUserId, toB64url } from "@moon-x/core/lib";
94
- import { assertPasskeyInParent, getPresenceToken } from "@moon-x/core/sdk";
129
+ import {
130
+ flattenPresenceTokens,
131
+ getInternalPresenceTokens,
132
+ getPresenceToken
133
+ } from "@moon-x/core/sdk";
95
134
  import { PostMessageMethod, PostMessageType } from "@moon-x/core/utils";
96
135
  import { create as passkeyCreate } from "react-native-passkeys";
136
+ var ADD_PASSKEY_SCOPES = ["passkey_enroll", "wrap_add"];
97
137
  var getPasskeyMethods = (bridge, publishableKey) => ({
98
138
  registerPasskey: async (params) => {
99
139
  const dekInfo = await bridge.send(
@@ -109,16 +149,22 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
109
149
  const isAdditional = (dekInfo.allow_credential_ids_b64url ?? []).length > 0;
110
150
  let unlock = null;
111
151
  if (isAdditional) {
112
- unlock = await assertPasskeyInParent({
152
+ const result = await getInternalPresenceTokens({
113
153
  transport: bridge,
114
154
  passkey: createRNPasskey(),
115
155
  publishableKey,
116
- requireFreshAssertion: true
156
+ relyingPartyOrigin,
157
+ scopes: ADD_PASSKEY_SCOPES
117
158
  });
118
159
  const allowList = dekInfo.allow_credential_ids_b64url ?? [];
119
- if (!allowList.includes(unlock.credentialIdB64url)) {
160
+ if (!allowList.includes(result.credentialIdB64url)) {
120
161
  throw new Error("unknown_passkey_for_this_account");
121
162
  }
163
+ unlock = {
164
+ userHandleB64url: result.userHandleB64url,
165
+ credentialIdB64url: result.credentialIdB64url,
166
+ presenceTokens: flattenPresenceTokens(result)
167
+ };
122
168
  }
123
169
  const beginResult = await bridge.send(
124
170
  PostMessageType.AUTH,
@@ -153,7 +199,8 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
153
199
  relyingPartyOrigin,
154
200
  token,
155
201
  credential,
156
- userIdB64url
202
+ userIdB64url,
203
+ presenceTokens: unlock?.presenceTokens
157
204
  }
158
205
  );
159
206
  if (isAdditional && unlock) {
@@ -165,7 +212,8 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
165
212
  unlockUserHandleB64url: unlock.userHandleB64url,
166
213
  unlockCredentialIdB64url: unlock.credentialIdB64url,
167
214
  newUserHandleB64url: userIdB64url,
168
- newCredentialIdB64url: credential.rawId
215
+ newCredentialIdB64url: credential.rawId,
216
+ presenceTokens: unlock.presenceTokens
169
217
  }
170
218
  );
171
219
  }
@@ -203,28 +251,51 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
203
251
  });
204
252
 
205
253
  // src/sdk/sdk-methods.ts
206
- import { getHeadlessGeneralMethods } from "@moon-x/core/sdk";
207
- var getSDKMethods = (bridge, publishableKey, setIsAuthenticated, setUser) => getHeadlessGeneralMethods({
254
+ import {
255
+ getHeadlessGeneralMethods
256
+ } from "@moon-x/core/sdk";
257
+ var getSDKMethods = (bridge, publishableKey, relyingPartyOrigin, setIsAuthenticated, setUser) => getHeadlessGeneralMethods({
208
258
  transport: bridge,
209
259
  passkey: createRNPasskey(),
210
260
  storage: createAsyncStorageKv(),
211
261
  publishableKey,
262
+ relyingPartyOrigin,
212
263
  setIsAuthenticated,
213
264
  setUser
214
265
  });
215
266
 
216
267
  // src/sdk/sdk-solana-methods.ts
217
- import { getHeadlessSolanaMethods } from "@moon-x/core/sdk";
218
- var getSolanaSDKMethods = (bridge, publishableKey) => getHeadlessSolanaMethods({
268
+ import {
269
+ getHeadlessSolanaMethods
270
+ } from "@moon-x/core/sdk";
271
+ var getSolanaSDKMethods = (bridge, publishableKey, relyingPartyOrigin) => getHeadlessSolanaMethods({
219
272
  transport: bridge,
220
273
  passkey: createRNPasskey(),
221
- publishableKey
274
+ publishableKey,
275
+ relyingPartyOrigin
222
276
  });
223
277
 
224
278
  // src/sdk/create-sdk-instance.ts
279
+ var makeRelyingPartyOriginResolver = (bridge, publishableKey, configuredOrigin) => {
280
+ let cached = configuredOrigin || null;
281
+ return async () => {
282
+ if (cached) return cached;
283
+ const dekInfo = await bridge.send(
284
+ PostMessageType2.AUTH,
285
+ PostMessageMethod2.GET_DEK_INFO,
286
+ { publishableKey }
287
+ );
288
+ if (!dekInfo.rp_id) {
289
+ throw new Error("webauthn_rp_id_not_configured");
290
+ }
291
+ cached = `https://${dekInfo.rp_id}`;
292
+ return cached;
293
+ };
294
+ };
225
295
  var createSdkInstance = ({
226
296
  bridge,
227
297
  publishableKey,
298
+ relyingPartyOrigin,
228
299
  isAuthenticated,
229
300
  user,
230
301
  ready,
@@ -243,15 +314,20 @@ var createSdkInstance = ({
243
314
  setIsAuthenticated,
244
315
  setUser
245
316
  ),
246
- ...getSDKMethods(bridge, publishableKey, setIsAuthenticated, setUser),
317
+ ...getSDKMethods(
318
+ bridge,
319
+ publishableKey,
320
+ relyingPartyOrigin,
321
+ setIsAuthenticated,
322
+ setUser
323
+ ),
247
324
  ...getPasskeyMethods(bridge, publishableKey),
248
- ...getEthereumSDKMethods(bridge, publishableKey),
249
- ...getSolanaSDKMethods(bridge, publishableKey)
325
+ ...getEthereumSDKMethods(bridge, publishableKey, relyingPartyOrigin),
326
+ ...getSolanaSDKMethods(bridge, publishableKey, relyingPartyOrigin)
250
327
  });
251
328
 
252
329
  // src/provider.tsx
253
- import { setAssertCacheTtlMs } from "@moon-x/core/lib";
254
- import { PostMessageMethod as PostMessageMethod2, PostMessageType as PostMessageType2 } from "@moon-x/core/utils";
330
+ import { PostMessageMethod as PostMessageMethod3, PostMessageType as PostMessageType3 } from "@moon-x/core/utils";
255
331
 
256
332
  // src/transport/webview-bridge.ts
257
333
  import {
@@ -430,7 +506,7 @@ var MoonKeyProvider = ({
430
506
  children
431
507
  }) => {
432
508
  const iframeUrl = config?.iframeUrl ?? DEFAULT_IFRAME_URL;
433
- setAssertCacheTtlMs(config?.security?.assertionCacheTtlMs ?? 0);
509
+ const relyingPartyOrigin = config?.relyingPartyOrigin ?? "";
434
510
  const webViewRef = useRef(null);
435
511
  const bridge = useMemo(
436
512
  () => new WebViewBridge(
@@ -438,6 +514,10 @@ var MoonKeyProvider = ({
438
514
  ),
439
515
  []
440
516
  );
517
+ const relyingPartyOriginResolver = useMemo(
518
+ () => makeRelyingPartyOriginResolver(bridge, publishableKey, relyingPartyOrigin),
519
+ [bridge, publishableKey, relyingPartyOrigin]
520
+ );
441
521
  const [sensitiveVisible, setSensitiveVisible] = useState(false);
442
522
  const cancelRef = useRef(null);
443
523
  const [ready, setReady] = useState(false);
@@ -523,6 +603,12 @@ var MoonKeyProvider = ({
523
603
  () => createSdkInstance({
524
604
  bridge,
525
605
  publishableKey,
606
+ // Shared resolver — empty in the common case, then derives
607
+ // `https://<rp_id>` from the iframe at the first sensitive op and
608
+ // threads it into getInternalPresenceTokens, which forwards it on
609
+ // /presence/begin so the server can rebuild the per-app WebAuthn
610
+ // RP config.
611
+ relyingPartyOrigin: relyingPartyOriginResolver,
526
612
  isAuthenticated,
527
613
  user,
528
614
  ready,
@@ -530,7 +616,15 @@ var MoonKeyProvider = ({
530
616
  setUser,
531
617
  refreshUser
532
618
  }),
533
- [bridge, publishableKey, isAuthenticated, user, ready, refreshUser]
619
+ [
620
+ bridge,
621
+ publishableKey,
622
+ relyingPartyOriginResolver,
623
+ isAuthenticated,
624
+ user,
625
+ ready,
626
+ refreshUser
627
+ ]
534
628
  );
535
629
  const sdkRef = useRef(sdk);
536
630
  useEffect(() => {
@@ -544,8 +638,8 @@ var MoonKeyProvider = ({
544
638
  useEffect(() => {
545
639
  let cancelled = false;
546
640
  const unregister = bridge.register(
547
- PostMessageType2.INIT,
548
- PostMessageMethod2.READY,
641
+ PostMessageType3.INIT,
642
+ PostMessageMethod3.READY,
549
643
  () => {
550
644
  if (!cancelled) setReady(true);
551
645
  }
@@ -599,10 +693,17 @@ var MoonKeyProvider = ({
599
693
  () => ({
600
694
  sdk,
601
695
  _bridge: bridge,
696
+ _relyingPartyOrigin: relyingPartyOriginResolver,
602
697
  _runSensitiveFlow: runSensitiveFlow,
603
698
  _oauthRedirectUri: config?.oauthRedirectUri
604
699
  }),
605
- [sdk, bridge, runSensitiveFlow, config?.oauthRedirectUri]
700
+ [
701
+ sdk,
702
+ bridge,
703
+ relyingPartyOriginResolver,
704
+ runSensitiveFlow,
705
+ config?.oauthRedirectUri
706
+ ]
606
707
  );
607
708
  const closeLabel = config?.sensitiveModalCopy?.closeLabel ?? "Done";
608
709
  return /* @__PURE__ */ jsx(MoonKeyContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxs(SDKProvider, { value: sdk, children: [
@@ -749,6 +850,7 @@ var styles = StyleSheet.create({
749
850
  import {
750
851
  useAddPasskey,
751
852
  useCreateWallet,
853
+ useEphemeralSigner,
752
854
  useImportKey,
753
855
  useLoginWithEmail,
754
856
  useLogout,
@@ -760,7 +862,7 @@ import {
760
862
  } from "@moon-x/core/react";
761
863
 
762
864
  // src/hooks/use-attach-oauth.ts
763
- import { PostMessageMethod as PostMessageMethod3, PostMessageType as PostMessageType3 } from "@moon-x/core/utils";
865
+ import { PostMessageMethod as PostMessageMethod4, PostMessageType as PostMessageType4 } from "@moon-x/core/utils";
764
866
  import { useState as useState2 } from "react";
765
867
 
766
868
  // src/lib/oauth-deep-link.ts
@@ -811,8 +913,8 @@ var useAttachOAuth = (params) => {
811
913
  const redirectUri = params?.redirectUri || _oauthRedirectUri;
812
914
  if (!redirectUri) throw new Error("oauth_redirect_uri_missing");
813
915
  const startResult = await _bridge.send(
814
- PostMessageType3.AUTH,
815
- PostMessageMethod3.START_OAUTH,
916
+ PostMessageType4.AUTH,
917
+ PostMessageMethod4.START_OAUTH,
816
918
  {
817
919
  publishableKey: sdk.publishableKey,
818
920
  provider,
@@ -832,8 +934,8 @@ var useAttachOAuth = (params) => {
832
934
  if (parsed.error) throw new Error(parsed.error);
833
935
  setState({ status: "verifying" });
834
936
  await _bridge.send(
835
- PostMessageType3.AUTH,
836
- PostMessageMethod3.ATTACH_OAUTH,
937
+ PostMessageType4.AUTH,
938
+ PostMessageMethod4.ATTACH_OAUTH,
837
939
  {
838
940
  publishableKey: sdk.publishableKey,
839
941
  provider,
@@ -854,14 +956,14 @@ var useAttachOAuth = (params) => {
854
956
  };
855
957
 
856
958
  // src/hooks/use-detach-oauth.ts
857
- import { PostMessageMethod as PostMessageMethod4, PostMessageType as PostMessageType4 } from "@moon-x/core/utils";
959
+ import { PostMessageMethod as PostMessageMethod5, PostMessageType as PostMessageType5 } from "@moon-x/core/utils";
858
960
  var useDetachOAuth = () => {
859
961
  const { sdk, _bridge } = useMoonKeyContext();
860
962
  return {
861
963
  detachOAuth: async (idpUserId) => {
862
964
  await _bridge.send(
863
- PostMessageType4.AUTH,
864
- PostMessageMethod4.DETACH_OAUTH,
965
+ PostMessageType5.AUTH,
966
+ PostMessageMethod5.DETACH_OAUTH,
865
967
  { publishableKey: sdk.publishableKey, idpUserId }
866
968
  );
867
969
  }
@@ -869,24 +971,27 @@ var useDetachOAuth = () => {
869
971
  };
870
972
 
871
973
  // src/hooks/use-export-key.ts
872
- import { withClearOnFailure } from "@moon-x/core/lib";
873
- import { assertPasskeyInParent as assertPasskeyInParent2 } from "@moon-x/core/sdk";
974
+ import { getInternalPresenceTokens as getInternalPresenceTokens2 } from "@moon-x/core/sdk";
975
+ var EXPORT_KEY_SCOPES = ["keyshare_read"];
874
976
  var useExportKey = () => {
875
- const { sdk, _bridge, _runSensitiveFlow } = useMoonKeyContext();
977
+ const { sdk, _bridge, _relyingPartyOrigin, _runSensitiveFlow } = useMoonKeyContext();
876
978
  return {
877
- exportKey: (wallet) => withClearOnFailure(async () => {
878
- const { userHandleB64url, credentialIdB64url } = await assertPasskeyInParent2({
979
+ exportKey: async (wallet) => {
980
+ const { userHandleB64url, credentialIdB64url, tokens } = await getInternalPresenceTokens2({
879
981
  transport: _bridge,
880
982
  passkey: createRNPasskey(),
881
983
  publishableKey: sdk.publishableKey,
882
- requireFreshAssertion: true
984
+ relyingPartyOrigin: _relyingPartyOrigin,
985
+ scopes: EXPORT_KEY_SCOPES
883
986
  });
987
+ const keyshareReadToken = tokens.keyshare_read?.token ?? "";
884
988
  const params = new URLSearchParams({
885
989
  publishableKey: sdk.publishableKey,
886
990
  wallet_id: wallet.id ?? "",
887
991
  wallet_type: wallet.wallet_type ?? "",
888
992
  user_handle_b64url: userHandleB64url,
889
- credential_id_b64url: credentialIdB64url
993
+ credential_id_b64url: credentialIdB64url,
994
+ keyshare_read_token: keyshareReadToken
890
995
  });
891
996
  await _runSensitiveFlow({
892
997
  title: "Export key",
@@ -897,12 +1002,12 @@ var useExportKey = () => {
897
1002
  // happens when the user dismisses.
898
1003
  onMount: () => Promise.resolve()
899
1004
  });
900
- })
1005
+ }
901
1006
  };
902
1007
  };
903
1008
 
904
1009
  // src/hooks/use-login-with-oauth.ts
905
- import { PostMessageMethod as PostMessageMethod5, PostMessageType as PostMessageType5 } from "@moon-x/core/utils";
1010
+ import { PostMessageMethod as PostMessageMethod6, PostMessageType as PostMessageType6 } from "@moon-x/core/utils";
906
1011
  import { useState as useState3 } from "react";
907
1012
  var useLoginWithOAuth = (params) => {
908
1013
  const { sdk, _bridge, _oauthRedirectUri } = useMoonKeyContext();
@@ -917,8 +1022,8 @@ var useLoginWithOAuth = (params) => {
917
1022
  throw new Error("oauth_redirect_uri_missing");
918
1023
  }
919
1024
  const startResult = await _bridge.send(
920
- PostMessageType5.AUTH,
921
- PostMessageMethod5.START_OAUTH,
1025
+ PostMessageType6.AUTH,
1026
+ PostMessageMethod6.START_OAUTH,
922
1027
  {
923
1028
  publishableKey: sdk.publishableKey,
924
1029
  provider,
@@ -960,15 +1065,16 @@ var useLoginWithOAuth = (params) => {
960
1065
  var useMoonKey = () => useMoonKeyContext().sdk;
961
1066
 
962
1067
  // src/index.ts
963
- import { PostMessageMethod as PostMessageMethod6, PostMessageType as PostMessageType6 } from "@moon-x/core/utils";
1068
+ import { PostMessageMethod as PostMessageMethod7, PostMessageType as PostMessageType7 } from "@moon-x/core/utils";
964
1069
  export {
965
1070
  MoonKeyProvider,
966
- PostMessageMethod6 as PostMessageMethod,
967
- PostMessageType6 as PostMessageType,
1071
+ PostMessageMethod7 as PostMessageMethod,
1072
+ PostMessageType7 as PostMessageType,
968
1073
  useAddPasskey,
969
1074
  useAttachOAuth,
970
1075
  useCreateWallet,
971
1076
  useDetachOAuth,
1077
+ useEphemeralSigner,
972
1078
  useExportKey,
973
1079
  useImportKey,
974
1080
  useLoginWithEmail,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moon-x/react-native-sdk",
3
- "version": "0.2.0",
3
+ "version": "0.4.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.3.0"
52
+ "@moon-x/core": "0.6.0"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "@expo/config-plugins": ">=10.0.0",