@moon-x/react-native-sdk 0.0.1 → 0.2.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/dist/index.d.mts +13 -7
- package/dist/index.d.ts +13 -7
- package/dist/index.js +58 -56
- package/dist/index.mjs +57 -55
- package/package.json +3 -2
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,12 +125,6 @@ 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
|
*/
|
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,12 +125,6 @@ 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
|
*/
|
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,42 +95,28 @@ var createRNPasskey = () => ({
|
|
|
97
95
|
userHandleB64url: userHandle
|
|
98
96
|
};
|
|
99
97
|
},
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
challenge,
|
|
107
|
-
excludeCredentials
|
|
108
|
-
}) => {
|
|
109
|
-
const credential = await (0, import_react_native_passkeys.create)({
|
|
110
|
-
challenge,
|
|
111
|
-
rp: { id: rpId, name: rpName },
|
|
112
|
-
user: {
|
|
113
|
-
id: (0, import_lib.toB64url)(userId),
|
|
114
|
-
name: userName,
|
|
115
|
-
displayName: userDisplayName
|
|
116
|
-
},
|
|
117
|
-
pubKeyCredParams: [
|
|
118
|
-
{ type: "public-key", alg: -7 },
|
|
119
|
-
{ type: "public-key", alg: -257 }
|
|
120
|
-
],
|
|
121
|
-
authenticatorSelection: {
|
|
122
|
-
residentKey: "required",
|
|
123
|
-
userVerification: "preferred"
|
|
124
|
-
},
|
|
125
|
-
excludeCredentials: (excludeCredentials ?? []).map((id) => ({
|
|
126
|
-
id,
|
|
127
|
-
type: "public-key"
|
|
128
|
-
}))
|
|
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"
|
|
129
104
|
});
|
|
130
|
-
if (!credential) throw new Error("
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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
|
|
115
|
+
},
|
|
116
|
+
clientExtensionResults: credential.clientExtensionResults ?? {},
|
|
117
|
+
authenticatorAttachment: credential.authenticatorAttachment
|
|
135
118
|
};
|
|
119
|
+
return sanitized;
|
|
136
120
|
}
|
|
137
121
|
});
|
|
138
122
|
|
|
@@ -144,7 +128,7 @@ var getEthereumSDKMethods = (bridge, publishableKey) => (0, import_sdk2.getHeadl
|
|
|
144
128
|
});
|
|
145
129
|
|
|
146
130
|
// src/sdk/sdk-passkey-methods.ts
|
|
147
|
-
var
|
|
131
|
+
var import_lib = require("@moon-x/core/lib");
|
|
148
132
|
var import_sdk3 = require("@moon-x/core/sdk");
|
|
149
133
|
var import_utils = require("@moon-x/core/utils");
|
|
150
134
|
var import_react_native_passkeys2 = require("react-native-passkeys");
|
|
@@ -189,11 +173,11 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
189
173
|
if (!options || !token) {
|
|
190
174
|
throw new Error("passkey_register_begin_no_options");
|
|
191
175
|
}
|
|
192
|
-
const { userIdB64url } = (0,
|
|
176
|
+
const { userIdB64url } = (0, import_lib.generatePasskeyUserId)();
|
|
193
177
|
options.user.id = userIdB64url;
|
|
194
178
|
if (!options.challenge) {
|
|
195
179
|
const challengeBytes = crypto.getRandomValues(new Uint8Array(32));
|
|
196
|
-
options.challenge = (0,
|
|
180
|
+
options.challenge = (0, import_lib.toB64url)(challengeBytes);
|
|
197
181
|
}
|
|
198
182
|
const credential = await (0, import_react_native_passkeys2.create)(
|
|
199
183
|
options
|
|
@@ -224,6 +208,35 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
224
208
|
);
|
|
225
209
|
}
|
|
226
210
|
return { credential_id: credential.rawId };
|
|
211
|
+
},
|
|
212
|
+
// Parent-side passkey step-up. Mirrors the web SDK's
|
|
213
|
+
// `sdk.getPresenceToken()` — orchestrator is platform-agnostic; only
|
|
214
|
+
// the WebAuthn primitive differs (createRNPasskey() uses
|
|
215
|
+
// react-native-passkeys instead of @simplewebauthn/browser).
|
|
216
|
+
//
|
|
217
|
+
// DEK hygiene strip lives inside `createRNPasskey().assertForServer`,
|
|
218
|
+
// so the orchestrator never touches userHandle. Server gate
|
|
219
|
+
// (requireUserHandleStripped) catches any regression.
|
|
220
|
+
//
|
|
221
|
+
// The relying-party origin for RN apps is reconstructed from the
|
|
222
|
+
// app's configured rp_id (fetched via the iframe's GET_DEK_INFO) —
|
|
223
|
+
// RN has no window.location.origin to use. Same pattern as
|
|
224
|
+
// sdk-passkey-methods.ts::registerPasskey.
|
|
225
|
+
getPresenceToken: async () => {
|
|
226
|
+
const dekInfo = await bridge.send(
|
|
227
|
+
import_utils.PostMessageType.AUTH,
|
|
228
|
+
import_utils.PostMessageMethod.GET_DEK_INFO,
|
|
229
|
+
{ publishableKey }
|
|
230
|
+
);
|
|
231
|
+
if (!dekInfo.rp_id) {
|
|
232
|
+
throw new Error("webauthn_rp_id_not_configured");
|
|
233
|
+
}
|
|
234
|
+
return (0, import_sdk3.getPresenceToken)({
|
|
235
|
+
transport: bridge,
|
|
236
|
+
passkey: createRNPasskey(),
|
|
237
|
+
publishableKey,
|
|
238
|
+
relyingPartyOrigin: `https://${dekInfo.rp_id}`
|
|
239
|
+
});
|
|
227
240
|
}
|
|
228
241
|
});
|
|
229
242
|
|
|
@@ -250,7 +263,6 @@ var getSolanaSDKMethods = (bridge, publishableKey) => (0, import_sdk5.getHeadles
|
|
|
250
263
|
var createSdkInstance = ({
|
|
251
264
|
bridge,
|
|
252
265
|
publishableKey,
|
|
253
|
-
emailConfig,
|
|
254
266
|
isAuthenticated,
|
|
255
267
|
user,
|
|
256
268
|
ready,
|
|
@@ -266,7 +278,6 @@ var createSdkInstance = ({
|
|
|
266
278
|
...getAuthenticationMethods(
|
|
267
279
|
bridge,
|
|
268
280
|
publishableKey,
|
|
269
|
-
emailConfig,
|
|
270
281
|
setIsAuthenticated,
|
|
271
282
|
setUser
|
|
272
283
|
),
|
|
@@ -277,7 +288,7 @@ var createSdkInstance = ({
|
|
|
277
288
|
});
|
|
278
289
|
|
|
279
290
|
// src/provider.tsx
|
|
280
|
-
var
|
|
291
|
+
var import_lib2 = require("@moon-x/core/lib");
|
|
281
292
|
var import_utils3 = require("@moon-x/core/utils");
|
|
282
293
|
|
|
283
294
|
// src/transport/webview-bridge.ts
|
|
@@ -455,7 +466,7 @@ var MoonKeyProvider = ({
|
|
|
455
466
|
children
|
|
456
467
|
}) => {
|
|
457
468
|
const iframeUrl = config?.iframeUrl ?? DEFAULT_IFRAME_URL;
|
|
458
|
-
(0,
|
|
469
|
+
(0, import_lib2.setAssertCacheTtlMs)(config?.security?.assertionCacheTtlMs ?? 0);
|
|
459
470
|
const webViewRef = (0, import_react.useRef)(null);
|
|
460
471
|
const bridge = (0, import_react.useMemo)(
|
|
461
472
|
() => new WebViewBridge(
|
|
@@ -548,7 +559,6 @@ var MoonKeyProvider = ({
|
|
|
548
559
|
() => createSdkInstance({
|
|
549
560
|
bridge,
|
|
550
561
|
publishableKey,
|
|
551
|
-
emailConfig: config?.emailConfig,
|
|
552
562
|
isAuthenticated,
|
|
553
563
|
user,
|
|
554
564
|
ready,
|
|
@@ -556,15 +566,7 @@ var MoonKeyProvider = ({
|
|
|
556
566
|
setUser,
|
|
557
567
|
refreshUser
|
|
558
568
|
}),
|
|
559
|
-
[
|
|
560
|
-
bridge,
|
|
561
|
-
publishableKey,
|
|
562
|
-
config?.emailConfig,
|
|
563
|
-
isAuthenticated,
|
|
564
|
-
user,
|
|
565
|
-
ready,
|
|
566
|
-
refreshUser
|
|
567
|
-
]
|
|
569
|
+
[bridge, publishableKey, isAuthenticated, user, ready, refreshUser]
|
|
568
570
|
);
|
|
569
571
|
const sdkRef = (0, import_react.useRef)(sdk);
|
|
570
572
|
(0, import_react.useEffect)(() => {
|
|
@@ -892,12 +894,12 @@ var useDetachOAuth = () => {
|
|
|
892
894
|
};
|
|
893
895
|
|
|
894
896
|
// src/hooks/use-export-key.ts
|
|
895
|
-
var
|
|
897
|
+
var import_lib3 = require("@moon-x/core/lib");
|
|
896
898
|
var import_sdk6 = require("@moon-x/core/sdk");
|
|
897
899
|
var useExportKey = () => {
|
|
898
900
|
const { sdk, _bridge, _runSensitiveFlow } = useMoonKeyContext();
|
|
899
901
|
return {
|
|
900
|
-
exportKey: (wallet) => (0,
|
|
902
|
+
exportKey: (wallet) => (0, import_lib3.withClearOnFailure)(async () => {
|
|
901
903
|
const { userHandleB64url, credentialIdB64url } = await (0, import_sdk6.assertPasskeyInParent)({
|
|
902
904
|
transport: _bridge,
|
|
903
905
|
passkey: createRNPasskey(),
|
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,42 +57,28 @@ var createRNPasskey = () => ({
|
|
|
59
57
|
userHandleB64url: userHandle
|
|
60
58
|
};
|
|
61
59
|
},
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
challenge,
|
|
69
|
-
excludeCredentials
|
|
70
|
-
}) => {
|
|
71
|
-
const credential = await passkeyCreate({
|
|
72
|
-
challenge,
|
|
73
|
-
rp: { id: rpId, name: rpName },
|
|
74
|
-
user: {
|
|
75
|
-
id: toB64url(userId),
|
|
76
|
-
name: userName,
|
|
77
|
-
displayName: userDisplayName
|
|
78
|
-
},
|
|
79
|
-
pubKeyCredParams: [
|
|
80
|
-
{ type: "public-key", alg: -7 },
|
|
81
|
-
{ type: "public-key", alg: -257 }
|
|
82
|
-
],
|
|
83
|
-
authenticatorSelection: {
|
|
84
|
-
residentKey: "required",
|
|
85
|
-
userVerification: "preferred"
|
|
86
|
-
},
|
|
87
|
-
excludeCredentials: (excludeCredentials ?? []).map((id) => ({
|
|
88
|
-
id,
|
|
89
|
-
type: "public-key"
|
|
90
|
-
}))
|
|
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"
|
|
91
66
|
});
|
|
92
|
-
if (!credential) throw new Error("
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
|
77
|
+
},
|
|
78
|
+
clientExtensionResults: credential.clientExtensionResults ?? {},
|
|
79
|
+
authenticatorAttachment: credential.authenticatorAttachment
|
|
97
80
|
};
|
|
81
|
+
return sanitized;
|
|
98
82
|
}
|
|
99
83
|
});
|
|
100
84
|
|
|
@@ -106,10 +90,10 @@ var getEthereumSDKMethods = (bridge, publishableKey) => getHeadlessEthereumMetho
|
|
|
106
90
|
});
|
|
107
91
|
|
|
108
92
|
// src/sdk/sdk-passkey-methods.ts
|
|
109
|
-
import { generatePasskeyUserId, toB64url
|
|
110
|
-
import { assertPasskeyInParent } from "@moon-x/core/sdk";
|
|
93
|
+
import { generatePasskeyUserId, toB64url } from "@moon-x/core/lib";
|
|
94
|
+
import { assertPasskeyInParent, getPresenceToken } from "@moon-x/core/sdk";
|
|
111
95
|
import { PostMessageMethod, PostMessageType } from "@moon-x/core/utils";
|
|
112
|
-
import { create as
|
|
96
|
+
import { create as passkeyCreate } from "react-native-passkeys";
|
|
113
97
|
var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
114
98
|
registerPasskey: async (params) => {
|
|
115
99
|
const dekInfo = await bridge.send(
|
|
@@ -155,9 +139,9 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
155
139
|
options.user.id = userIdB64url;
|
|
156
140
|
if (!options.challenge) {
|
|
157
141
|
const challengeBytes = crypto.getRandomValues(new Uint8Array(32));
|
|
158
|
-
options.challenge =
|
|
142
|
+
options.challenge = toB64url(challengeBytes);
|
|
159
143
|
}
|
|
160
|
-
const credential = await
|
|
144
|
+
const credential = await passkeyCreate(
|
|
161
145
|
options
|
|
162
146
|
);
|
|
163
147
|
if (!credential) throw new Error("passkey_register_cancelled");
|
|
@@ -186,6 +170,35 @@ var getPasskeyMethods = (bridge, publishableKey) => ({
|
|
|
186
170
|
);
|
|
187
171
|
}
|
|
188
172
|
return { credential_id: credential.rawId };
|
|
173
|
+
},
|
|
174
|
+
// Parent-side passkey step-up. Mirrors the web SDK's
|
|
175
|
+
// `sdk.getPresenceToken()` — orchestrator is platform-agnostic; only
|
|
176
|
+
// the WebAuthn primitive differs (createRNPasskey() uses
|
|
177
|
+
// react-native-passkeys instead of @simplewebauthn/browser).
|
|
178
|
+
//
|
|
179
|
+
// DEK hygiene strip lives inside `createRNPasskey().assertForServer`,
|
|
180
|
+
// so the orchestrator never touches userHandle. Server gate
|
|
181
|
+
// (requireUserHandleStripped) catches any regression.
|
|
182
|
+
//
|
|
183
|
+
// The relying-party origin for RN apps is reconstructed from the
|
|
184
|
+
// app's configured rp_id (fetched via the iframe's GET_DEK_INFO) —
|
|
185
|
+
// RN has no window.location.origin to use. Same pattern as
|
|
186
|
+
// sdk-passkey-methods.ts::registerPasskey.
|
|
187
|
+
getPresenceToken: async () => {
|
|
188
|
+
const dekInfo = await bridge.send(
|
|
189
|
+
PostMessageType.AUTH,
|
|
190
|
+
PostMessageMethod.GET_DEK_INFO,
|
|
191
|
+
{ publishableKey }
|
|
192
|
+
);
|
|
193
|
+
if (!dekInfo.rp_id) {
|
|
194
|
+
throw new Error("webauthn_rp_id_not_configured");
|
|
195
|
+
}
|
|
196
|
+
return getPresenceToken({
|
|
197
|
+
transport: bridge,
|
|
198
|
+
passkey: createRNPasskey(),
|
|
199
|
+
publishableKey,
|
|
200
|
+
relyingPartyOrigin: `https://${dekInfo.rp_id}`
|
|
201
|
+
});
|
|
189
202
|
}
|
|
190
203
|
});
|
|
191
204
|
|
|
@@ -212,7 +225,6 @@ var getSolanaSDKMethods = (bridge, publishableKey) => getHeadlessSolanaMethods({
|
|
|
212
225
|
var createSdkInstance = ({
|
|
213
226
|
bridge,
|
|
214
227
|
publishableKey,
|
|
215
|
-
emailConfig,
|
|
216
228
|
isAuthenticated,
|
|
217
229
|
user,
|
|
218
230
|
ready,
|
|
@@ -228,7 +240,6 @@ var createSdkInstance = ({
|
|
|
228
240
|
...getAuthenticationMethods(
|
|
229
241
|
bridge,
|
|
230
242
|
publishableKey,
|
|
231
|
-
emailConfig,
|
|
232
243
|
setIsAuthenticated,
|
|
233
244
|
setUser
|
|
234
245
|
),
|
|
@@ -512,7 +523,6 @@ var MoonKeyProvider = ({
|
|
|
512
523
|
() => createSdkInstance({
|
|
513
524
|
bridge,
|
|
514
525
|
publishableKey,
|
|
515
|
-
emailConfig: config?.emailConfig,
|
|
516
526
|
isAuthenticated,
|
|
517
527
|
user,
|
|
518
528
|
ready,
|
|
@@ -520,15 +530,7 @@ var MoonKeyProvider = ({
|
|
|
520
530
|
setUser,
|
|
521
531
|
refreshUser
|
|
522
532
|
}),
|
|
523
|
-
[
|
|
524
|
-
bridge,
|
|
525
|
-
publishableKey,
|
|
526
|
-
config?.emailConfig,
|
|
527
|
-
isAuthenticated,
|
|
528
|
-
user,
|
|
529
|
-
ready,
|
|
530
|
-
refreshUser
|
|
531
|
-
]
|
|
533
|
+
[bridge, publishableKey, isAuthenticated, user, ready, refreshUser]
|
|
532
534
|
);
|
|
533
535
|
const sdkRef = useRef(sdk);
|
|
534
536
|
useEffect(() => {
|
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.2.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.3.0"
|
|
52
53
|
},
|
|
53
54
|
"peerDependencies": {
|
|
54
55
|
"@expo/config-plugins": ">=10.0.0",
|