@moon-x/react-native-sdk 0.0.1 → 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 +34 -29
- package/dist/index.d.ts +34 -29
- package/dist/index.js +144 -65
- package/dist/index.mjs +152 -69
- package/package.json +3 -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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
2
|
import { PostMessageType, PostMessageMethod } from '@moon-x/core/utils';
|
|
3
3
|
export { PostMessageMethod, PostMessageType } from '@moon-x/core/utils';
|
|
4
|
+
import * as _moon_x_core_types from '@moon-x/core/types';
|
|
4
5
|
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';
|
|
5
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';
|
|
6
7
|
export { useAddPasskey, useCreateWallet, useImportKey, useLoginWithEmail, useLogout, usePasskeyStatus, useRegisterPasskey, useRemovePasskey, useUser, useWallets } from '@moon-x/core/react';
|
|
@@ -35,7 +36,7 @@ interface RNAuthSDK {
|
|
|
35
36
|
sendCode: (params: {
|
|
36
37
|
email: string;
|
|
37
38
|
disableSignup?: boolean;
|
|
38
|
-
}) => Promise<
|
|
39
|
+
}) => Promise<_moon_x_core_types.SendEmailOtpResponse>;
|
|
39
40
|
loginWithCode: (params: {
|
|
40
41
|
code: string;
|
|
41
42
|
}) => Promise<void>;
|
|
@@ -54,6 +55,17 @@ interface RNAuthSDK {
|
|
|
54
55
|
refreshToken: string;
|
|
55
56
|
accessToken: string;
|
|
56
57
|
} | null>;
|
|
58
|
+
/**
|
|
59
|
+
* Run a passkey-asserted step-up ceremony and return a short-lived
|
|
60
|
+
* presence token (JWT, `tt:"presence"`) that customer backends verify
|
|
61
|
+
* over JWKS to gate high-risk routes. Must be invoked synchronously
|
|
62
|
+
* from a press handler — WebAuthn requires transient activation.
|
|
63
|
+
* Throws if the user has no enrolled passkey or cancels the prompt.
|
|
64
|
+
*/
|
|
65
|
+
getPresenceToken: () => Promise<{
|
|
66
|
+
presenceToken: string;
|
|
67
|
+
expiresAt: number;
|
|
68
|
+
}>;
|
|
57
69
|
logout: () => Promise<{
|
|
58
70
|
success: boolean;
|
|
59
71
|
message: string;
|
|
@@ -113,16 +125,25 @@ interface MoonKeyConfig {
|
|
|
113
125
|
* automatically; no per-deployment changes needed.
|
|
114
126
|
*/
|
|
115
127
|
iframeUrl?: string;
|
|
116
|
-
/**
|
|
117
|
-
* Email OTP options forwarded to the iframe-app on `sendCode`.
|
|
118
|
-
*/
|
|
119
|
-
emailConfig?: {
|
|
120
|
-
expiresIn?: number;
|
|
121
|
-
};
|
|
122
128
|
/**
|
|
123
129
|
* Deep-link URI scheme used as the OAuth redirect target.
|
|
124
130
|
*/
|
|
125
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;
|
|
126
147
|
/**
|
|
127
148
|
* UI strings for the sensitive-flow modal chrome (close button,
|
|
128
149
|
* default title). Defaults are reasonable English copy.
|
|
@@ -131,26 +152,12 @@ interface MoonKeyConfig {
|
|
|
131
152
|
closeLabel?: string;
|
|
132
153
|
};
|
|
133
154
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
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).
|
|
136
159
|
*/
|
|
137
|
-
security?:
|
|
138
|
-
/**
|
|
139
|
-
* TTL in milliseconds for the parent-side passkey assertion cache.
|
|
140
|
-
*
|
|
141
|
-
* Default: 0 (no cache — every sensitive op forces a fresh
|
|
142
|
-
* biometric prompt). This is the safe-by-default posture; the raw
|
|
143
|
-
* userHandle (the AES-GCM KEK that unwraps the user's DEK) never
|
|
144
|
-
* lingers in JS heap past the moment of use.
|
|
145
|
-
*
|
|
146
|
-
* Set to a positive number (e.g. 5 * 60 * 1000) only if the app
|
|
147
|
-
* has a UX that genuinely benefits from skipping the OS passkey
|
|
148
|
-
* prompt on routine ops within a window. Sensitive operations
|
|
149
|
-
* (export, addPasskey, removePasskey, and any call passing
|
|
150
|
-
* `requireFreshAssertion: true`) bypass the cache regardless.
|
|
151
|
-
*/
|
|
152
|
-
assertionCacheTtlMs?: number;
|
|
153
|
-
};
|
|
160
|
+
security?: Record<string, never>;
|
|
154
161
|
}
|
|
155
162
|
interface MoonKeyProviderProps {
|
|
156
163
|
publishableKey: string;
|
|
@@ -189,6 +196,7 @@ interface SensitiveFlowMountApi {
|
|
|
189
196
|
interface MoonKeyContextValue {
|
|
190
197
|
sdk: RNAuthSDK;
|
|
191
198
|
_bridge: WebViewBridge;
|
|
199
|
+
_relyingPartyOrigin: string;
|
|
192
200
|
_runSensitiveFlow: (options: SensitiveFlowOptions) => Promise<void>;
|
|
193
201
|
_oauthRedirectUri?: string;
|
|
194
202
|
}
|
|
@@ -228,9 +236,6 @@ declare const useDetachOAuth: () => {
|
|
|
228
236
|
* flow. The RN-side promise resolves when the user dismisses the
|
|
229
237
|
* modal (the only v1 completion signal — an iframe-app-emitted
|
|
230
238
|
* EXPORT_COMPLETE one-way is a planned enhancement).
|
|
231
|
-
*
|
|
232
|
-
* Sensitive op: forces a fresh biometric prompt regardless of the
|
|
233
|
-
* parent-side warm-cache state, matching the web SDK's posture.
|
|
234
239
|
*/
|
|
235
240
|
declare const useExportKey: () => {
|
|
236
241
|
exportKey: (wallet: PublicWallet) => Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
2
|
import { PostMessageType, PostMessageMethod } from '@moon-x/core/utils';
|
|
3
3
|
export { PostMessageMethod, PostMessageType } from '@moon-x/core/utils';
|
|
4
|
+
import * as _moon_x_core_types from '@moon-x/core/types';
|
|
4
5
|
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';
|
|
5
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';
|
|
6
7
|
export { useAddPasskey, useCreateWallet, useImportKey, useLoginWithEmail, useLogout, usePasskeyStatus, useRegisterPasskey, useRemovePasskey, useUser, useWallets } from '@moon-x/core/react';
|
|
@@ -35,7 +36,7 @@ interface RNAuthSDK {
|
|
|
35
36
|
sendCode: (params: {
|
|
36
37
|
email: string;
|
|
37
38
|
disableSignup?: boolean;
|
|
38
|
-
}) => Promise<
|
|
39
|
+
}) => Promise<_moon_x_core_types.SendEmailOtpResponse>;
|
|
39
40
|
loginWithCode: (params: {
|
|
40
41
|
code: string;
|
|
41
42
|
}) => Promise<void>;
|
|
@@ -54,6 +55,17 @@ interface RNAuthSDK {
|
|
|
54
55
|
refreshToken: string;
|
|
55
56
|
accessToken: string;
|
|
56
57
|
} | null>;
|
|
58
|
+
/**
|
|
59
|
+
* Run a passkey-asserted step-up ceremony and return a short-lived
|
|
60
|
+
* presence token (JWT, `tt:"presence"`) that customer backends verify
|
|
61
|
+
* over JWKS to gate high-risk routes. Must be invoked synchronously
|
|
62
|
+
* from a press handler — WebAuthn requires transient activation.
|
|
63
|
+
* Throws if the user has no enrolled passkey or cancels the prompt.
|
|
64
|
+
*/
|
|
65
|
+
getPresenceToken: () => Promise<{
|
|
66
|
+
presenceToken: string;
|
|
67
|
+
expiresAt: number;
|
|
68
|
+
}>;
|
|
57
69
|
logout: () => Promise<{
|
|
58
70
|
success: boolean;
|
|
59
71
|
message: string;
|
|
@@ -113,16 +125,25 @@ interface MoonKeyConfig {
|
|
|
113
125
|
* automatically; no per-deployment changes needed.
|
|
114
126
|
*/
|
|
115
127
|
iframeUrl?: string;
|
|
116
|
-
/**
|
|
117
|
-
* Email OTP options forwarded to the iframe-app on `sendCode`.
|
|
118
|
-
*/
|
|
119
|
-
emailConfig?: {
|
|
120
|
-
expiresIn?: number;
|
|
121
|
-
};
|
|
122
128
|
/**
|
|
123
129
|
* Deep-link URI scheme used as the OAuth redirect target.
|
|
124
130
|
*/
|
|
125
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;
|
|
126
147
|
/**
|
|
127
148
|
* UI strings for the sensitive-flow modal chrome (close button,
|
|
128
149
|
* default title). Defaults are reasonable English copy.
|
|
@@ -131,26 +152,12 @@ interface MoonKeyConfig {
|
|
|
131
152
|
closeLabel?: string;
|
|
132
153
|
};
|
|
133
154
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
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).
|
|
136
159
|
*/
|
|
137
|
-
security?:
|
|
138
|
-
/**
|
|
139
|
-
* TTL in milliseconds for the parent-side passkey assertion cache.
|
|
140
|
-
*
|
|
141
|
-
* Default: 0 (no cache — every sensitive op forces a fresh
|
|
142
|
-
* biometric prompt). This is the safe-by-default posture; the raw
|
|
143
|
-
* userHandle (the AES-GCM KEK that unwraps the user's DEK) never
|
|
144
|
-
* lingers in JS heap past the moment of use.
|
|
145
|
-
*
|
|
146
|
-
* Set to a positive number (e.g. 5 * 60 * 1000) only if the app
|
|
147
|
-
* has a UX that genuinely benefits from skipping the OS passkey
|
|
148
|
-
* prompt on routine ops within a window. Sensitive operations
|
|
149
|
-
* (export, addPasskey, removePasskey, and any call passing
|
|
150
|
-
* `requireFreshAssertion: true`) bypass the cache regardless.
|
|
151
|
-
*/
|
|
152
|
-
assertionCacheTtlMs?: number;
|
|
153
|
-
};
|
|
160
|
+
security?: Record<string, never>;
|
|
154
161
|
}
|
|
155
162
|
interface MoonKeyProviderProps {
|
|
156
163
|
publishableKey: string;
|
|
@@ -189,6 +196,7 @@ interface SensitiveFlowMountApi {
|
|
|
189
196
|
interface MoonKeyContextValue {
|
|
190
197
|
sdk: RNAuthSDK;
|
|
191
198
|
_bridge: WebViewBridge;
|
|
199
|
+
_relyingPartyOrigin: string;
|
|
192
200
|
_runSensitiveFlow: (options: SensitiveFlowOptions) => Promise<void>;
|
|
193
201
|
_oauthRedirectUri?: string;
|
|
194
202
|
}
|
|
@@ -228,9 +236,6 @@ declare const useDetachOAuth: () => {
|
|
|
228
236
|
* flow. The RN-side promise resolves when the user dismisses the
|
|
229
237
|
* modal (the only v1 completion signal — an iframe-app-emitted
|
|
230
238
|
* EXPORT_COMPLETE one-way is a planned enhancement).
|
|
231
|
-
*
|
|
232
|
-
* Sensitive op: forces a fresh biometric prompt regardless of the
|
|
233
|
-
* parent-side warm-cache state, matching the web SDK's posture.
|
|
234
239
|
*/
|
|
235
240
|
declare const useExportKey: () => {
|
|
236
241
|
exportKey: (wallet: PublicWallet) => Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -59,10 +59,9 @@ var import_react_native_webview = require("react-native-webview");
|
|
|
59
59
|
|
|
60
60
|
// src/sdk/sdk-authentication-methods.ts
|
|
61
61
|
var import_sdk = require("@moon-x/core/sdk");
|
|
62
|
-
var getAuthenticationMethods = (bridge, publishableKey,
|
|
62
|
+
var getAuthenticationMethods = (bridge, publishableKey, setIsAuthenticated, setUser) => (0, import_sdk.getHeadlessAuthenticationMethods)({
|
|
63
63
|
transport: bridge,
|
|
64
64
|
publishableKey,
|
|
65
|
-
emailConfig,
|
|
66
65
|
setIsAuthenticated,
|
|
67
66
|
setUser
|
|
68
67
|
});
|
|
@@ -80,7 +79,6 @@ var createAsyncStorageKv = (prefix = "moonkey:") => ({
|
|
|
80
79
|
|
|
81
80
|
// src/platform/rn-passkey.ts
|
|
82
81
|
var import_react_native_passkeys = require("react-native-passkeys");
|
|
83
|
-
var import_lib = require("@moon-x/core/lib");
|
|
84
82
|
var createRNPasskey = () => ({
|
|
85
83
|
assert: async ({ rpId, challenge }) => {
|
|
86
84
|
const credential = await (0, import_react_native_passkeys.get)({
|
|
@@ -97,57 +95,74 @@ var createRNPasskey = () => ({
|
|
|
97
95
|
userHandleB64url: userHandle
|
|
98
96
|
};
|
|
99
97
|
},
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
pubKeyCredParams: [
|
|
118
|
-
{ type: "public-key", alg: -7 },
|
|
119
|
-
{ type: "public-key", alg: -257 }
|
|
120
|
-
],
|
|
121
|
-
authenticatorSelection: {
|
|
122
|
-
residentKey: "required",
|
|
123
|
-
userVerification: "preferred"
|
|
98
|
+
assertForServer: async ({ optionsJSON }) => {
|
|
99
|
+
const credential = await (0, import_react_native_passkeys.get)({
|
|
100
|
+
challenge: optionsJSON.challenge,
|
|
101
|
+
rpId: optionsJSON.rpId,
|
|
102
|
+
allowCredentials: optionsJSON.allowCredentials ?? [],
|
|
103
|
+
userVerification: optionsJSON.userVerification ?? "preferred"
|
|
104
|
+
});
|
|
105
|
+
if (!credential) throw new Error("passkey_assertion_cancelled");
|
|
106
|
+
const sanitized = {
|
|
107
|
+
id: credential.id ?? credential.rawId,
|
|
108
|
+
rawId: credential.rawId,
|
|
109
|
+
type: credential.type ?? "public-key",
|
|
110
|
+
response: {
|
|
111
|
+
clientDataJSON: credential.response.clientDataJSON,
|
|
112
|
+
authenticatorData: credential.response.authenticatorData,
|
|
113
|
+
signature: credential.response.signature,
|
|
114
|
+
userHandle: void 0
|
|
124
115
|
},
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
116
|
+
clientExtensionResults: credential.clientExtensionResults ?? {},
|
|
117
|
+
authenticatorAttachment: credential.authenticatorAttachment
|
|
118
|
+
};
|
|
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"
|
|
129
127
|
});
|
|
130
|
-
if (!credential) throw new Error("
|
|
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
|
+
};
|
|
131
144
|
return {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
145
|
+
response: sanitized,
|
|
146
|
+
userHandleB64url: userHandle,
|
|
147
|
+
credentialIdB64url: credential.rawId
|
|
135
148
|
};
|
|
136
149
|
}
|
|
137
150
|
});
|
|
138
151
|
|
|
139
152
|
// src/sdk/sdk-ethereum-methods.ts
|
|
140
|
-
var getEthereumSDKMethods = (bridge, publishableKey) => (0, import_sdk2.getHeadlessEthereumMethods)({
|
|
153
|
+
var getEthereumSDKMethods = (bridge, publishableKey, relyingPartyOrigin) => (0, import_sdk2.getHeadlessEthereumMethods)({
|
|
141
154
|
transport: bridge,
|
|
142
155
|
passkey: createRNPasskey(),
|
|
143
|
-
publishableKey
|
|
156
|
+
publishableKey,
|
|
157
|
+
relyingPartyOrigin
|
|
144
158
|
});
|
|
145
159
|
|
|
146
160
|
// src/sdk/sdk-passkey-methods.ts
|
|
147
|
-
var
|
|
161
|
+
var import_lib = require("@moon-x/core/lib");
|
|
148
162
|
var import_sdk3 = require("@moon-x/core/sdk");
|
|
149
163
|
var import_utils = require("@moon-x/core/utils");
|
|
150
164
|
var import_react_native_passkeys2 = require("react-native-passkeys");
|
|
165
|
+
var ADD_PASSKEY_SCOPES = ["passkey_enroll", "wrap_add"];
|
|
151
166
|
var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
152
167
|
registerPasskey: async (params) => {
|
|
153
168
|
const dekInfo = await bridge.send(
|
|
@@ -163,16 +178,22 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
163
178
|
const isAdditional = (dekInfo.allow_credential_ids_b64url ?? []).length > 0;
|
|
164
179
|
let unlock = null;
|
|
165
180
|
if (isAdditional) {
|
|
166
|
-
|
|
181
|
+
const result = await (0, import_sdk3.getInternalPresenceTokens)({
|
|
167
182
|
transport: bridge,
|
|
168
183
|
passkey: createRNPasskey(),
|
|
169
184
|
publishableKey,
|
|
170
|
-
|
|
185
|
+
relyingPartyOrigin,
|
|
186
|
+
scopes: ADD_PASSKEY_SCOPES
|
|
171
187
|
});
|
|
172
188
|
const allowList = dekInfo.allow_credential_ids_b64url ?? [];
|
|
173
|
-
if (!allowList.includes(
|
|
189
|
+
if (!allowList.includes(result.credentialIdB64url)) {
|
|
174
190
|
throw new Error("unknown_passkey_for_this_account");
|
|
175
191
|
}
|
|
192
|
+
unlock = {
|
|
193
|
+
userHandleB64url: result.userHandleB64url,
|
|
194
|
+
credentialIdB64url: result.credentialIdB64url,
|
|
195
|
+
presenceTokens: (0, import_sdk3.flattenPresenceTokens)(result)
|
|
196
|
+
};
|
|
176
197
|
}
|
|
177
198
|
const beginResult = await bridge.send(
|
|
178
199
|
import_utils.PostMessageType.AUTH,
|
|
@@ -189,11 +210,11 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
189
210
|
if (!options || !token) {
|
|
190
211
|
throw new Error("passkey_register_begin_no_options");
|
|
191
212
|
}
|
|
192
|
-
const { userIdB64url } = (0,
|
|
213
|
+
const { userIdB64url } = (0, import_lib.generatePasskeyUserId)();
|
|
193
214
|
options.user.id = userIdB64url;
|
|
194
215
|
if (!options.challenge) {
|
|
195
216
|
const challengeBytes = crypto.getRandomValues(new Uint8Array(32));
|
|
196
|
-
options.challenge = (0,
|
|
217
|
+
options.challenge = (0, import_lib.toB64url)(challengeBytes);
|
|
197
218
|
}
|
|
198
219
|
const credential = await (0, import_react_native_passkeys2.create)(
|
|
199
220
|
options
|
|
@@ -207,7 +228,8 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
207
228
|
relyingPartyOrigin,
|
|
208
229
|
token,
|
|
209
230
|
credential,
|
|
210
|
-
userIdB64url
|
|
231
|
+
userIdB64url,
|
|
232
|
+
presenceTokens: unlock?.presenceTokens
|
|
211
233
|
}
|
|
212
234
|
);
|
|
213
235
|
if (isAdditional && unlock) {
|
|
@@ -219,38 +241,70 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
219
241
|
unlockUserHandleB64url: unlock.userHandleB64url,
|
|
220
242
|
unlockCredentialIdB64url: unlock.credentialIdB64url,
|
|
221
243
|
newUserHandleB64url: userIdB64url,
|
|
222
|
-
newCredentialIdB64url: credential.rawId
|
|
244
|
+
newCredentialIdB64url: credential.rawId,
|
|
245
|
+
presenceTokens: unlock.presenceTokens
|
|
223
246
|
}
|
|
224
247
|
);
|
|
225
248
|
}
|
|
226
249
|
return { credential_id: credential.rawId };
|
|
250
|
+
},
|
|
251
|
+
// Parent-side passkey step-up. Mirrors the web SDK's
|
|
252
|
+
// `sdk.getPresenceToken()` — orchestrator is platform-agnostic; only
|
|
253
|
+
// the WebAuthn primitive differs (createRNPasskey() uses
|
|
254
|
+
// react-native-passkeys instead of @simplewebauthn/browser).
|
|
255
|
+
//
|
|
256
|
+
// DEK hygiene strip lives inside `createRNPasskey().assertForServer`,
|
|
257
|
+
// so the orchestrator never touches userHandle. Server gate
|
|
258
|
+
// (requireUserHandleStripped) catches any regression.
|
|
259
|
+
//
|
|
260
|
+
// The relying-party origin for RN apps is reconstructed from the
|
|
261
|
+
// app's configured rp_id (fetched via the iframe's GET_DEK_INFO) —
|
|
262
|
+
// RN has no window.location.origin to use. Same pattern as
|
|
263
|
+
// sdk-passkey-methods.ts::registerPasskey.
|
|
264
|
+
getPresenceToken: async () => {
|
|
265
|
+
const dekInfo = await bridge.send(
|
|
266
|
+
import_utils.PostMessageType.AUTH,
|
|
267
|
+
import_utils.PostMessageMethod.GET_DEK_INFO,
|
|
268
|
+
{ publishableKey }
|
|
269
|
+
);
|
|
270
|
+
if (!dekInfo.rp_id) {
|
|
271
|
+
throw new Error("webauthn_rp_id_not_configured");
|
|
272
|
+
}
|
|
273
|
+
return (0, import_sdk3.getPresenceToken)({
|
|
274
|
+
transport: bridge,
|
|
275
|
+
passkey: createRNPasskey(),
|
|
276
|
+
publishableKey,
|
|
277
|
+
relyingPartyOrigin: `https://${dekInfo.rp_id}`
|
|
278
|
+
});
|
|
227
279
|
}
|
|
228
280
|
});
|
|
229
281
|
|
|
230
282
|
// src/sdk/sdk-methods.ts
|
|
231
283
|
var import_sdk4 = require("@moon-x/core/sdk");
|
|
232
|
-
var getSDKMethods = (bridge, publishableKey, setIsAuthenticated, setUser) => (0, import_sdk4.getHeadlessGeneralMethods)({
|
|
284
|
+
var getSDKMethods = (bridge, publishableKey, relyingPartyOrigin, setIsAuthenticated, setUser) => (0, import_sdk4.getHeadlessGeneralMethods)({
|
|
233
285
|
transport: bridge,
|
|
234
286
|
passkey: createRNPasskey(),
|
|
235
287
|
storage: createAsyncStorageKv(),
|
|
236
288
|
publishableKey,
|
|
289
|
+
relyingPartyOrigin,
|
|
237
290
|
setIsAuthenticated,
|
|
238
291
|
setUser
|
|
239
292
|
});
|
|
240
293
|
|
|
241
294
|
// src/sdk/sdk-solana-methods.ts
|
|
242
295
|
var import_sdk5 = require("@moon-x/core/sdk");
|
|
243
|
-
var getSolanaSDKMethods = (bridge, publishableKey) => (0, import_sdk5.getHeadlessSolanaMethods)({
|
|
296
|
+
var getSolanaSDKMethods = (bridge, publishableKey, relyingPartyOrigin) => (0, import_sdk5.getHeadlessSolanaMethods)({
|
|
244
297
|
transport: bridge,
|
|
245
298
|
passkey: createRNPasskey(),
|
|
246
|
-
publishableKey
|
|
299
|
+
publishableKey,
|
|
300
|
+
relyingPartyOrigin
|
|
247
301
|
});
|
|
248
302
|
|
|
249
303
|
// src/sdk/create-sdk-instance.ts
|
|
250
304
|
var createSdkInstance = ({
|
|
251
305
|
bridge,
|
|
252
306
|
publishableKey,
|
|
253
|
-
|
|
307
|
+
relyingPartyOrigin,
|
|
254
308
|
isAuthenticated,
|
|
255
309
|
user,
|
|
256
310
|
ready,
|
|
@@ -266,18 +320,22 @@ var createSdkInstance = ({
|
|
|
266
320
|
...getAuthenticationMethods(
|
|
267
321
|
bridge,
|
|
268
322
|
publishableKey,
|
|
269
|
-
emailConfig,
|
|
270
323
|
setIsAuthenticated,
|
|
271
324
|
setUser
|
|
272
325
|
),
|
|
273
|
-
...getSDKMethods(
|
|
326
|
+
...getSDKMethods(
|
|
327
|
+
bridge,
|
|
328
|
+
publishableKey,
|
|
329
|
+
relyingPartyOrigin,
|
|
330
|
+
setIsAuthenticated,
|
|
331
|
+
setUser
|
|
332
|
+
),
|
|
274
333
|
...getPasskeyMethods(bridge, publishableKey),
|
|
275
|
-
...getEthereumSDKMethods(bridge, publishableKey),
|
|
276
|
-
...getSolanaSDKMethods(bridge, publishableKey)
|
|
334
|
+
...getEthereumSDKMethods(bridge, publishableKey, relyingPartyOrigin),
|
|
335
|
+
...getSolanaSDKMethods(bridge, publishableKey, relyingPartyOrigin)
|
|
277
336
|
});
|
|
278
337
|
|
|
279
338
|
// src/provider.tsx
|
|
280
|
-
var import_lib3 = require("@moon-x/core/lib");
|
|
281
339
|
var import_utils3 = require("@moon-x/core/utils");
|
|
282
340
|
|
|
283
341
|
// src/transport/webview-bridge.ts
|
|
@@ -455,7 +513,12 @@ var MoonKeyProvider = ({
|
|
|
455
513
|
children
|
|
456
514
|
}) => {
|
|
457
515
|
const iframeUrl = config?.iframeUrl ?? DEFAULT_IFRAME_URL;
|
|
458
|
-
|
|
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
|
+
}
|
|
459
522
|
const webViewRef = (0, import_react.useRef)(null);
|
|
460
523
|
const bridge = (0, import_react.useMemo)(
|
|
461
524
|
() => new WebViewBridge(
|
|
@@ -548,7 +611,13 @@ var MoonKeyProvider = ({
|
|
|
548
611
|
() => createSdkInstance({
|
|
549
612
|
bridge,
|
|
550
613
|
publishableKey,
|
|
551
|
-
|
|
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,
|
|
552
621
|
isAuthenticated,
|
|
553
622
|
user,
|
|
554
623
|
ready,
|
|
@@ -559,7 +628,7 @@ var MoonKeyProvider = ({
|
|
|
559
628
|
[
|
|
560
629
|
bridge,
|
|
561
630
|
publishableKey,
|
|
562
|
-
|
|
631
|
+
relyingPartyOrigin,
|
|
563
632
|
isAuthenticated,
|
|
564
633
|
user,
|
|
565
634
|
ready,
|
|
@@ -633,10 +702,17 @@ var MoonKeyProvider = ({
|
|
|
633
702
|
() => ({
|
|
634
703
|
sdk,
|
|
635
704
|
_bridge: bridge,
|
|
705
|
+
_relyingPartyOrigin: relyingPartyOrigin,
|
|
636
706
|
_runSensitiveFlow: runSensitiveFlow,
|
|
637
707
|
_oauthRedirectUri: config?.oauthRedirectUri
|
|
638
708
|
}),
|
|
639
|
-
[
|
|
709
|
+
[
|
|
710
|
+
sdk,
|
|
711
|
+
bridge,
|
|
712
|
+
relyingPartyOrigin,
|
|
713
|
+
runSensitiveFlow,
|
|
714
|
+
config?.oauthRedirectUri
|
|
715
|
+
]
|
|
640
716
|
);
|
|
641
717
|
const closeLabel = config?.sensitiveModalCopy?.closeLabel ?? "Done";
|
|
642
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: [
|
|
@@ -892,24 +968,27 @@ var useDetachOAuth = () => {
|
|
|
892
968
|
};
|
|
893
969
|
|
|
894
970
|
// src/hooks/use-export-key.ts
|
|
895
|
-
var import_lib4 = require("@moon-x/core/lib");
|
|
896
971
|
var import_sdk6 = require("@moon-x/core/sdk");
|
|
972
|
+
var EXPORT_KEY_SCOPES = ["keyshare_read"];
|
|
897
973
|
var useExportKey = () => {
|
|
898
|
-
const { sdk, _bridge, _runSensitiveFlow } = useMoonKeyContext();
|
|
974
|
+
const { sdk, _bridge, _relyingPartyOrigin, _runSensitiveFlow } = useMoonKeyContext();
|
|
899
975
|
return {
|
|
900
|
-
exportKey:
|
|
901
|
-
const { userHandleB64url, credentialIdB64url } = await (0, import_sdk6.
|
|
976
|
+
exportKey: async (wallet) => {
|
|
977
|
+
const { userHandleB64url, credentialIdB64url, tokens } = await (0, import_sdk6.getInternalPresenceTokens)({
|
|
902
978
|
transport: _bridge,
|
|
903
979
|
passkey: createRNPasskey(),
|
|
904
980
|
publishableKey: sdk.publishableKey,
|
|
905
|
-
|
|
981
|
+
relyingPartyOrigin: _relyingPartyOrigin,
|
|
982
|
+
scopes: EXPORT_KEY_SCOPES
|
|
906
983
|
});
|
|
984
|
+
const keyshareReadToken = tokens.keyshare_read?.token ?? "";
|
|
907
985
|
const params = new URLSearchParams({
|
|
908
986
|
publishableKey: sdk.publishableKey,
|
|
909
987
|
wallet_id: wallet.id ?? "",
|
|
910
988
|
wallet_type: wallet.wallet_type ?? "",
|
|
911
989
|
user_handle_b64url: userHandleB64url,
|
|
912
|
-
credential_id_b64url: credentialIdB64url
|
|
990
|
+
credential_id_b64url: credentialIdB64url,
|
|
991
|
+
keyshare_read_token: keyshareReadToken
|
|
913
992
|
});
|
|
914
993
|
await _runSensitiveFlow({
|
|
915
994
|
title: "Export key",
|
|
@@ -920,7 +999,7 @@ var useExportKey = () => {
|
|
|
920
999
|
// happens when the user dismisses.
|
|
921
1000
|
onMount: () => Promise.resolve()
|
|
922
1001
|
});
|
|
923
|
-
}
|
|
1002
|
+
}
|
|
924
1003
|
};
|
|
925
1004
|
};
|
|
926
1005
|
|
package/dist/index.mjs
CHANGED
|
@@ -21,10 +21,9 @@ import { WebView } from "react-native-webview";
|
|
|
21
21
|
|
|
22
22
|
// src/sdk/sdk-authentication-methods.ts
|
|
23
23
|
import { getHeadlessAuthenticationMethods } from "@moon-x/core/sdk";
|
|
24
|
-
var getAuthenticationMethods = (bridge, publishableKey,
|
|
24
|
+
var getAuthenticationMethods = (bridge, publishableKey, setIsAuthenticated, setUser) => getHeadlessAuthenticationMethods({
|
|
25
25
|
transport: bridge,
|
|
26
26
|
publishableKey,
|
|
27
|
-
emailConfig,
|
|
28
27
|
setIsAuthenticated,
|
|
29
28
|
setUser
|
|
30
29
|
});
|
|
@@ -41,8 +40,7 @@ var createAsyncStorageKv = (prefix = "moonkey:") => ({
|
|
|
41
40
|
});
|
|
42
41
|
|
|
43
42
|
// src/platform/rn-passkey.ts
|
|
44
|
-
import {
|
|
45
|
-
import { toB64url } from "@moon-x/core/lib";
|
|
43
|
+
import { get as passkeyGet } from "react-native-passkeys";
|
|
46
44
|
var createRNPasskey = () => ({
|
|
47
45
|
assert: async ({ rpId, challenge }) => {
|
|
48
46
|
const credential = await passkeyGet({
|
|
@@ -59,57 +57,78 @@ var createRNPasskey = () => ({
|
|
|
59
57
|
userHandleB64url: userHandle
|
|
60
58
|
};
|
|
61
59
|
},
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
pubKeyCredParams: [
|
|
80
|
-
{ type: "public-key", alg: -7 },
|
|
81
|
-
{ type: "public-key", alg: -257 }
|
|
82
|
-
],
|
|
83
|
-
authenticatorSelection: {
|
|
84
|
-
residentKey: "required",
|
|
85
|
-
userVerification: "preferred"
|
|
60
|
+
assertForServer: async ({ optionsJSON }) => {
|
|
61
|
+
const credential = await passkeyGet({
|
|
62
|
+
challenge: optionsJSON.challenge,
|
|
63
|
+
rpId: optionsJSON.rpId,
|
|
64
|
+
allowCredentials: optionsJSON.allowCredentials ?? [],
|
|
65
|
+
userVerification: optionsJSON.userVerification ?? "preferred"
|
|
66
|
+
});
|
|
67
|
+
if (!credential) throw new Error("passkey_assertion_cancelled");
|
|
68
|
+
const sanitized = {
|
|
69
|
+
id: credential.id ?? credential.rawId,
|
|
70
|
+
rawId: credential.rawId,
|
|
71
|
+
type: credential.type ?? "public-key",
|
|
72
|
+
response: {
|
|
73
|
+
clientDataJSON: credential.response.clientDataJSON,
|
|
74
|
+
authenticatorData: credential.response.authenticatorData,
|
|
75
|
+
signature: credential.response.signature,
|
|
76
|
+
userHandle: void 0
|
|
86
77
|
},
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
78
|
+
clientExtensionResults: credential.clientExtensionResults ?? {},
|
|
79
|
+
authenticatorAttachment: credential.authenticatorAttachment
|
|
80
|
+
};
|
|
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"
|
|
91
89
|
});
|
|
92
|
-
if (!credential) throw new Error("
|
|
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
|
+
};
|
|
93
106
|
return {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
107
|
+
response: sanitized,
|
|
108
|
+
userHandleB64url: userHandle,
|
|
109
|
+
credentialIdB64url: credential.rawId
|
|
97
110
|
};
|
|
98
111
|
}
|
|
99
112
|
});
|
|
100
113
|
|
|
101
114
|
// src/sdk/sdk-ethereum-methods.ts
|
|
102
|
-
var getEthereumSDKMethods = (bridge, publishableKey) => getHeadlessEthereumMethods({
|
|
115
|
+
var getEthereumSDKMethods = (bridge, publishableKey, relyingPartyOrigin) => getHeadlessEthereumMethods({
|
|
103
116
|
transport: bridge,
|
|
104
117
|
passkey: createRNPasskey(),
|
|
105
|
-
publishableKey
|
|
118
|
+
publishableKey,
|
|
119
|
+
relyingPartyOrigin
|
|
106
120
|
});
|
|
107
121
|
|
|
108
122
|
// src/sdk/sdk-passkey-methods.ts
|
|
109
|
-
import { generatePasskeyUserId, toB64url
|
|
110
|
-
import {
|
|
123
|
+
import { generatePasskeyUserId, toB64url } from "@moon-x/core/lib";
|
|
124
|
+
import {
|
|
125
|
+
flattenPresenceTokens,
|
|
126
|
+
getInternalPresenceTokens,
|
|
127
|
+
getPresenceToken
|
|
128
|
+
} from "@moon-x/core/sdk";
|
|
111
129
|
import { PostMessageMethod, PostMessageType } from "@moon-x/core/utils";
|
|
112
|
-
import { create as
|
|
130
|
+
import { create as passkeyCreate } from "react-native-passkeys";
|
|
131
|
+
var ADD_PASSKEY_SCOPES = ["passkey_enroll", "wrap_add"];
|
|
113
132
|
var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
114
133
|
registerPasskey: async (params) => {
|
|
115
134
|
const dekInfo = await bridge.send(
|
|
@@ -125,16 +144,22 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
125
144
|
const isAdditional = (dekInfo.allow_credential_ids_b64url ?? []).length > 0;
|
|
126
145
|
let unlock = null;
|
|
127
146
|
if (isAdditional) {
|
|
128
|
-
|
|
147
|
+
const result = await getInternalPresenceTokens({
|
|
129
148
|
transport: bridge,
|
|
130
149
|
passkey: createRNPasskey(),
|
|
131
150
|
publishableKey,
|
|
132
|
-
|
|
151
|
+
relyingPartyOrigin,
|
|
152
|
+
scopes: ADD_PASSKEY_SCOPES
|
|
133
153
|
});
|
|
134
154
|
const allowList = dekInfo.allow_credential_ids_b64url ?? [];
|
|
135
|
-
if (!allowList.includes(
|
|
155
|
+
if (!allowList.includes(result.credentialIdB64url)) {
|
|
136
156
|
throw new Error("unknown_passkey_for_this_account");
|
|
137
157
|
}
|
|
158
|
+
unlock = {
|
|
159
|
+
userHandleB64url: result.userHandleB64url,
|
|
160
|
+
credentialIdB64url: result.credentialIdB64url,
|
|
161
|
+
presenceTokens: flattenPresenceTokens(result)
|
|
162
|
+
};
|
|
138
163
|
}
|
|
139
164
|
const beginResult = await bridge.send(
|
|
140
165
|
PostMessageType.AUTH,
|
|
@@ -155,9 +180,9 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
155
180
|
options.user.id = userIdB64url;
|
|
156
181
|
if (!options.challenge) {
|
|
157
182
|
const challengeBytes = crypto.getRandomValues(new Uint8Array(32));
|
|
158
|
-
options.challenge =
|
|
183
|
+
options.challenge = toB64url(challengeBytes);
|
|
159
184
|
}
|
|
160
|
-
const credential = await
|
|
185
|
+
const credential = await passkeyCreate(
|
|
161
186
|
options
|
|
162
187
|
);
|
|
163
188
|
if (!credential) throw new Error("passkey_register_cancelled");
|
|
@@ -169,7 +194,8 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
169
194
|
relyingPartyOrigin,
|
|
170
195
|
token,
|
|
171
196
|
credential,
|
|
172
|
-
userIdB64url
|
|
197
|
+
userIdB64url,
|
|
198
|
+
presenceTokens: unlock?.presenceTokens
|
|
173
199
|
}
|
|
174
200
|
);
|
|
175
201
|
if (isAdditional && unlock) {
|
|
@@ -181,38 +207,70 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
181
207
|
unlockUserHandleB64url: unlock.userHandleB64url,
|
|
182
208
|
unlockCredentialIdB64url: unlock.credentialIdB64url,
|
|
183
209
|
newUserHandleB64url: userIdB64url,
|
|
184
|
-
newCredentialIdB64url: credential.rawId
|
|
210
|
+
newCredentialIdB64url: credential.rawId,
|
|
211
|
+
presenceTokens: unlock.presenceTokens
|
|
185
212
|
}
|
|
186
213
|
);
|
|
187
214
|
}
|
|
188
215
|
return { credential_id: credential.rawId };
|
|
216
|
+
},
|
|
217
|
+
// Parent-side passkey step-up. Mirrors the web SDK's
|
|
218
|
+
// `sdk.getPresenceToken()` — orchestrator is platform-agnostic; only
|
|
219
|
+
// the WebAuthn primitive differs (createRNPasskey() uses
|
|
220
|
+
// react-native-passkeys instead of @simplewebauthn/browser).
|
|
221
|
+
//
|
|
222
|
+
// DEK hygiene strip lives inside `createRNPasskey().assertForServer`,
|
|
223
|
+
// so the orchestrator never touches userHandle. Server gate
|
|
224
|
+
// (requireUserHandleStripped) catches any regression.
|
|
225
|
+
//
|
|
226
|
+
// The relying-party origin for RN apps is reconstructed from the
|
|
227
|
+
// app's configured rp_id (fetched via the iframe's GET_DEK_INFO) —
|
|
228
|
+
// RN has no window.location.origin to use. Same pattern as
|
|
229
|
+
// sdk-passkey-methods.ts::registerPasskey.
|
|
230
|
+
getPresenceToken: async () => {
|
|
231
|
+
const dekInfo = await bridge.send(
|
|
232
|
+
PostMessageType.AUTH,
|
|
233
|
+
PostMessageMethod.GET_DEK_INFO,
|
|
234
|
+
{ publishableKey }
|
|
235
|
+
);
|
|
236
|
+
if (!dekInfo.rp_id) {
|
|
237
|
+
throw new Error("webauthn_rp_id_not_configured");
|
|
238
|
+
}
|
|
239
|
+
return getPresenceToken({
|
|
240
|
+
transport: bridge,
|
|
241
|
+
passkey: createRNPasskey(),
|
|
242
|
+
publishableKey,
|
|
243
|
+
relyingPartyOrigin: `https://${dekInfo.rp_id}`
|
|
244
|
+
});
|
|
189
245
|
}
|
|
190
246
|
});
|
|
191
247
|
|
|
192
248
|
// src/sdk/sdk-methods.ts
|
|
193
249
|
import { getHeadlessGeneralMethods } from "@moon-x/core/sdk";
|
|
194
|
-
var getSDKMethods = (bridge, publishableKey, setIsAuthenticated, setUser) => getHeadlessGeneralMethods({
|
|
250
|
+
var getSDKMethods = (bridge, publishableKey, relyingPartyOrigin, setIsAuthenticated, setUser) => getHeadlessGeneralMethods({
|
|
195
251
|
transport: bridge,
|
|
196
252
|
passkey: createRNPasskey(),
|
|
197
253
|
storage: createAsyncStorageKv(),
|
|
198
254
|
publishableKey,
|
|
255
|
+
relyingPartyOrigin,
|
|
199
256
|
setIsAuthenticated,
|
|
200
257
|
setUser
|
|
201
258
|
});
|
|
202
259
|
|
|
203
260
|
// src/sdk/sdk-solana-methods.ts
|
|
204
261
|
import { getHeadlessSolanaMethods } from "@moon-x/core/sdk";
|
|
205
|
-
var getSolanaSDKMethods = (bridge, publishableKey) => getHeadlessSolanaMethods({
|
|
262
|
+
var getSolanaSDKMethods = (bridge, publishableKey, relyingPartyOrigin) => getHeadlessSolanaMethods({
|
|
206
263
|
transport: bridge,
|
|
207
264
|
passkey: createRNPasskey(),
|
|
208
|
-
publishableKey
|
|
265
|
+
publishableKey,
|
|
266
|
+
relyingPartyOrigin
|
|
209
267
|
});
|
|
210
268
|
|
|
211
269
|
// src/sdk/create-sdk-instance.ts
|
|
212
270
|
var createSdkInstance = ({
|
|
213
271
|
bridge,
|
|
214
272
|
publishableKey,
|
|
215
|
-
|
|
273
|
+
relyingPartyOrigin,
|
|
216
274
|
isAuthenticated,
|
|
217
275
|
user,
|
|
218
276
|
ready,
|
|
@@ -228,18 +286,22 @@ var createSdkInstance = ({
|
|
|
228
286
|
...getAuthenticationMethods(
|
|
229
287
|
bridge,
|
|
230
288
|
publishableKey,
|
|
231
|
-
emailConfig,
|
|
232
289
|
setIsAuthenticated,
|
|
233
290
|
setUser
|
|
234
291
|
),
|
|
235
|
-
...getSDKMethods(
|
|
292
|
+
...getSDKMethods(
|
|
293
|
+
bridge,
|
|
294
|
+
publishableKey,
|
|
295
|
+
relyingPartyOrigin,
|
|
296
|
+
setIsAuthenticated,
|
|
297
|
+
setUser
|
|
298
|
+
),
|
|
236
299
|
...getPasskeyMethods(bridge, publishableKey),
|
|
237
|
-
...getEthereumSDKMethods(bridge, publishableKey),
|
|
238
|
-
...getSolanaSDKMethods(bridge, publishableKey)
|
|
300
|
+
...getEthereumSDKMethods(bridge, publishableKey, relyingPartyOrigin),
|
|
301
|
+
...getSolanaSDKMethods(bridge, publishableKey, relyingPartyOrigin)
|
|
239
302
|
});
|
|
240
303
|
|
|
241
304
|
// src/provider.tsx
|
|
242
|
-
import { setAssertCacheTtlMs } from "@moon-x/core/lib";
|
|
243
305
|
import { PostMessageMethod as PostMessageMethod2, PostMessageType as PostMessageType2 } from "@moon-x/core/utils";
|
|
244
306
|
|
|
245
307
|
// src/transport/webview-bridge.ts
|
|
@@ -419,7 +481,12 @@ var MoonKeyProvider = ({
|
|
|
419
481
|
children
|
|
420
482
|
}) => {
|
|
421
483
|
const iframeUrl = config?.iframeUrl ?? DEFAULT_IFRAME_URL;
|
|
422
|
-
|
|
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
|
+
}
|
|
423
490
|
const webViewRef = useRef(null);
|
|
424
491
|
const bridge = useMemo(
|
|
425
492
|
() => new WebViewBridge(
|
|
@@ -512,7 +579,13 @@ var MoonKeyProvider = ({
|
|
|
512
579
|
() => createSdkInstance({
|
|
513
580
|
bridge,
|
|
514
581
|
publishableKey,
|
|
515
|
-
|
|
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,
|
|
516
589
|
isAuthenticated,
|
|
517
590
|
user,
|
|
518
591
|
ready,
|
|
@@ -523,7 +596,7 @@ var MoonKeyProvider = ({
|
|
|
523
596
|
[
|
|
524
597
|
bridge,
|
|
525
598
|
publishableKey,
|
|
526
|
-
|
|
599
|
+
relyingPartyOrigin,
|
|
527
600
|
isAuthenticated,
|
|
528
601
|
user,
|
|
529
602
|
ready,
|
|
@@ -597,10 +670,17 @@ var MoonKeyProvider = ({
|
|
|
597
670
|
() => ({
|
|
598
671
|
sdk,
|
|
599
672
|
_bridge: bridge,
|
|
673
|
+
_relyingPartyOrigin: relyingPartyOrigin,
|
|
600
674
|
_runSensitiveFlow: runSensitiveFlow,
|
|
601
675
|
_oauthRedirectUri: config?.oauthRedirectUri
|
|
602
676
|
}),
|
|
603
|
-
[
|
|
677
|
+
[
|
|
678
|
+
sdk,
|
|
679
|
+
bridge,
|
|
680
|
+
relyingPartyOrigin,
|
|
681
|
+
runSensitiveFlow,
|
|
682
|
+
config?.oauthRedirectUri
|
|
683
|
+
]
|
|
604
684
|
);
|
|
605
685
|
const closeLabel = config?.sensitiveModalCopy?.closeLabel ?? "Done";
|
|
606
686
|
return /* @__PURE__ */ jsx(MoonKeyContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxs(SDKProvider, { value: sdk, children: [
|
|
@@ -867,24 +947,27 @@ var useDetachOAuth = () => {
|
|
|
867
947
|
};
|
|
868
948
|
|
|
869
949
|
// src/hooks/use-export-key.ts
|
|
870
|
-
import {
|
|
871
|
-
|
|
950
|
+
import { getInternalPresenceTokens as getInternalPresenceTokens2 } from "@moon-x/core/sdk";
|
|
951
|
+
var EXPORT_KEY_SCOPES = ["keyshare_read"];
|
|
872
952
|
var useExportKey = () => {
|
|
873
|
-
const { sdk, _bridge, _runSensitiveFlow } = useMoonKeyContext();
|
|
953
|
+
const { sdk, _bridge, _relyingPartyOrigin, _runSensitiveFlow } = useMoonKeyContext();
|
|
874
954
|
return {
|
|
875
|
-
exportKey:
|
|
876
|
-
const { userHandleB64url, credentialIdB64url } = await
|
|
955
|
+
exportKey: async (wallet) => {
|
|
956
|
+
const { userHandleB64url, credentialIdB64url, tokens } = await getInternalPresenceTokens2({
|
|
877
957
|
transport: _bridge,
|
|
878
958
|
passkey: createRNPasskey(),
|
|
879
959
|
publishableKey: sdk.publishableKey,
|
|
880
|
-
|
|
960
|
+
relyingPartyOrigin: _relyingPartyOrigin,
|
|
961
|
+
scopes: EXPORT_KEY_SCOPES
|
|
881
962
|
});
|
|
963
|
+
const keyshareReadToken = tokens.keyshare_read?.token ?? "";
|
|
882
964
|
const params = new URLSearchParams({
|
|
883
965
|
publishableKey: sdk.publishableKey,
|
|
884
966
|
wallet_id: wallet.id ?? "",
|
|
885
967
|
wallet_type: wallet.wallet_type ?? "",
|
|
886
968
|
user_handle_b64url: userHandleB64url,
|
|
887
|
-
credential_id_b64url: credentialIdB64url
|
|
969
|
+
credential_id_b64url: credentialIdB64url,
|
|
970
|
+
keyshare_read_token: keyshareReadToken
|
|
888
971
|
});
|
|
889
972
|
await _runSensitiveFlow({
|
|
890
973
|
title: "Export key",
|
|
@@ -895,7 +978,7 @@ var useExportKey = () => {
|
|
|
895
978
|
// happens when the user dismisses.
|
|
896
979
|
onMount: () => Promise.resolve()
|
|
897
980
|
});
|
|
898
|
-
}
|
|
981
|
+
}
|
|
899
982
|
};
|
|
900
983
|
};
|
|
901
984
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moon-x/react-native-sdk",
|
|
3
|
-
"version": "0.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
|
+
"license": "UNLICENSED",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"module": "dist/index.mjs",
|
|
7
8
|
"types": "dist/index.d.ts",
|
|
@@ -48,7 +49,7 @@
|
|
|
48
49
|
"typescript": "5.9.3"
|
|
49
50
|
},
|
|
50
51
|
"dependencies": {
|
|
51
|
-
"@moon-x/core": "0.
|
|
52
|
+
"@moon-x/core": "0.4.0"
|
|
52
53
|
},
|
|
53
54
|
"peerDependencies": {
|
|
54
55
|
"@expo/config-plugins": ">=10.0.0",
|