@moon-x/react-native-sdk 0.23.0 → 0.25.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 +105 -5
- package/dist/ethereum.js +91 -15
- package/dist/ethereum.mjs +105 -14
- package/dist/index.d.mts +113 -4
- package/dist/index.d.ts +113 -4
- package/dist/index.js +1117 -254
- package/dist/index.mjs +1091 -213
- package/dist/solana.js +91 -15
- package/dist/solana.mjs +105 -14
- package/dist/tron.js +91 -15
- package/dist/tron.mjs +105 -14
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -30,44 +30,44 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
MOONPAY_CONSUMER_SESSION_ERROR_CODES: () =>
|
|
33
|
+
MOONPAY_CONSUMER_SESSION_ERROR_CODES: () => import_sdk12.MOONPAY_CONSUMER_SESSION_ERROR_CODES,
|
|
34
34
|
MoonKeyProvider: () => MoonXProvider,
|
|
35
35
|
MoonXProvider: () => MoonXProvider,
|
|
36
|
-
PostMessageMethod: () =>
|
|
37
|
-
PostMessageType: () =>
|
|
36
|
+
PostMessageMethod: () => import_utils11.PostMessageMethod,
|
|
37
|
+
PostMessageType: () => import_utils11.PostMessageType,
|
|
38
38
|
connectWalletConnect: () => connectWalletConnect,
|
|
39
39
|
listWalletConnectSessions: () => listWalletConnectSessions,
|
|
40
|
-
registerPresenceOtpCodeProvider: () =>
|
|
40
|
+
registerPresenceOtpCodeProvider: () => import_sdk13.registerPresenceOtpCodeProvider,
|
|
41
41
|
restoreWalletConnectSession: () => restoreWalletConnectSession,
|
|
42
|
-
useAddPasskey: () =>
|
|
42
|
+
useAddPasskey: () => import_react9.useAddPasskey,
|
|
43
43
|
useAppConfig: () => useAppConfig,
|
|
44
44
|
useAttachOAuth: () => useAttachOAuth,
|
|
45
|
-
useBulkImport: () =>
|
|
46
|
-
useCreateWallet: () =>
|
|
45
|
+
useBulkImport: () => import_react9.useBulkImport,
|
|
46
|
+
useCreateWallet: () => import_react9.useCreateWallet,
|
|
47
47
|
useDetachOAuth: () => useDetachOAuth,
|
|
48
|
-
useEphemeralSigner: () =>
|
|
48
|
+
useEphemeralSigner: () => import_react9.useEphemeralSigner,
|
|
49
49
|
useExportKey: () => useExportKey,
|
|
50
50
|
useExternalWallets: () => useExternalWallets,
|
|
51
51
|
useFundWallet: () => useFundWallet,
|
|
52
|
-
useImportKey: () =>
|
|
53
|
-
useLinkEmail: () =>
|
|
52
|
+
useImportKey: () => import_react9.useImportKey,
|
|
53
|
+
useLinkEmail: () => import_react9.useLinkEmail,
|
|
54
54
|
useLoginWithEmail: () => useLoginWithEmail,
|
|
55
55
|
useLoginWithOAuth: () => useLoginWithOAuth,
|
|
56
|
-
useLogout: () =>
|
|
56
|
+
useLogout: () => import_react9.useLogout,
|
|
57
57
|
useMoonKey: () => useMoonX,
|
|
58
58
|
useMoonX: () => useMoonX,
|
|
59
59
|
useMoonXContext: () => useMoonXContext,
|
|
60
|
-
usePasskeyStatus: () =>
|
|
61
|
-
useRegisterPasskey: () =>
|
|
62
|
-
useRemovePasskey: () =>
|
|
63
|
-
useUser: () =>
|
|
64
|
-
useWallets: () =>
|
|
60
|
+
usePasskeyStatus: () => import_react9.usePasskeyStatus,
|
|
61
|
+
useRegisterPasskey: () => import_react9.useRegisterPasskey,
|
|
62
|
+
useRemovePasskey: () => import_react9.useRemovePasskey,
|
|
63
|
+
useUser: () => import_react9.useUser,
|
|
64
|
+
useWallets: () => import_react9.useWallets
|
|
65
65
|
});
|
|
66
66
|
module.exports = __toCommonJS(index_exports);
|
|
67
67
|
|
|
68
68
|
// src/provider.tsx
|
|
69
|
-
var
|
|
70
|
-
var
|
|
69
|
+
var import_react2 = require("react");
|
|
70
|
+
var import_react_native2 = require("react-native");
|
|
71
71
|
var import_react_native_webview = require("react-native-webview");
|
|
72
72
|
|
|
73
73
|
// src/sdk/create-sdk-instance.ts
|
|
@@ -245,7 +245,8 @@ var getPasskeyMethods = (bridge, publishableKey, configuredRelyingPartyOrigin) =
|
|
|
245
245
|
passkey: createRNPasskey(),
|
|
246
246
|
publishableKey,
|
|
247
247
|
relyingPartyOrigin,
|
|
248
|
-
scopes: import_sdk4.SCOPES_ADD_PASSKEY
|
|
248
|
+
scopes: import_sdk4.SCOPES_ADD_PASSKEY,
|
|
249
|
+
requestOtpCode: params?.requestOtpCode
|
|
249
250
|
});
|
|
250
251
|
if (result.credentialIdB64url && !allowList.includes(result.credentialIdB64url)) {
|
|
251
252
|
throw new Error("unknown_passkey_for_this_account");
|
|
@@ -494,6 +495,59 @@ var getTronSDKMethods = (bridge, publishableKey, relyingPartyOrigin) => (0, impo
|
|
|
494
495
|
relyingPartyOrigin
|
|
495
496
|
});
|
|
496
497
|
|
|
498
|
+
// src/sdk/session-methods.ts
|
|
499
|
+
function getSessionMethods(bridge, publishableKey, relyingPartyOrigin, session, sessionResume) {
|
|
500
|
+
const auth = (callbacks) => getAuthenticationMethods(
|
|
501
|
+
bridge,
|
|
502
|
+
publishableKey,
|
|
503
|
+
callbacks?.setIsAuthenticated
|
|
504
|
+
);
|
|
505
|
+
const general = (callbacks, setUser) => getSDKMethods(
|
|
506
|
+
bridge,
|
|
507
|
+
publishableKey,
|
|
508
|
+
relyingPartyOrigin,
|
|
509
|
+
callbacks?.setIsAuthenticated,
|
|
510
|
+
setUser
|
|
511
|
+
);
|
|
512
|
+
const mutate = async (operation, profile) => {
|
|
513
|
+
const callbacks = session.beginAuthOperation();
|
|
514
|
+
try {
|
|
515
|
+
const result = await operation(callbacks);
|
|
516
|
+
if (profile === "await") await callbacks.refreshUser();
|
|
517
|
+
if (profile === "background") void callbacks.refreshUser();
|
|
518
|
+
return result;
|
|
519
|
+
} finally {
|
|
520
|
+
callbacks.finish();
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
const login = (operation, profile) => mutate(async (callbacks) => {
|
|
524
|
+
const release = await sessionResume?.beginLogin();
|
|
525
|
+
let succeeded = false;
|
|
526
|
+
try {
|
|
527
|
+
const result = await operation(callbacks);
|
|
528
|
+
succeeded = true;
|
|
529
|
+
return result;
|
|
530
|
+
} finally {
|
|
531
|
+
release?.(succeeded);
|
|
532
|
+
}
|
|
533
|
+
}, profile);
|
|
534
|
+
return {
|
|
535
|
+
loginWithCode: (params) => login((callbacks) => auth(callbacks).loginWithCode(params), "await"),
|
|
536
|
+
loginWithMoonPayCustomerToken: (params) => login((callbacks) => auth(callbacks).loginWithMoonPayCustomerToken(params), "background"),
|
|
537
|
+
verifyOAuth: (params) => login((callbacks) => auth(callbacks).verifyOAuth(params), "await"),
|
|
538
|
+
// Drop the resume key first, so a failed iframe logout cannot leave a key
|
|
539
|
+
// that brings the session back on the next launch.
|
|
540
|
+
logout: () => mutate((callbacks) => sessionResume ? sessionResume.logout(() => general(callbacks).logout()) : general(callbacks).logout(), "none"),
|
|
541
|
+
getUser: () => general(void 0, session.captureUserWrite()).getUser(),
|
|
542
|
+
linkEmailWithCode: async (params) => {
|
|
543
|
+
const refreshUser = session.captureUserRefresh();
|
|
544
|
+
const result = await auth().linkEmailWithCode(params);
|
|
545
|
+
await refreshUser();
|
|
546
|
+
return result;
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
}
|
|
550
|
+
|
|
497
551
|
// src/sdk/create-sdk-instance.ts
|
|
498
552
|
var makeRelyingPartyOriginResolver = (bridge, publishableKey, configuredOrigin) => {
|
|
499
553
|
let cached = configuredOrigin || null;
|
|
@@ -521,7 +575,9 @@ var createSdkInstance = ({
|
|
|
521
575
|
revalidatedAt,
|
|
522
576
|
setIsAuthenticated,
|
|
523
577
|
setUser,
|
|
524
|
-
refreshUser
|
|
578
|
+
refreshUser,
|
|
579
|
+
session,
|
|
580
|
+
sessionResume
|
|
525
581
|
}) => ({
|
|
526
582
|
publishableKey,
|
|
527
583
|
ready,
|
|
@@ -529,6 +585,11 @@ var createSdkInstance = ({
|
|
|
529
585
|
isAuthenticated,
|
|
530
586
|
user,
|
|
531
587
|
refreshUser,
|
|
588
|
+
sessionStatus: session?.getSnapshot().sessionStatus ?? (isAuthenticated ? "authenticated" : "restoring"),
|
|
589
|
+
sessionError: session?.getSnapshot().sessionError ?? null,
|
|
590
|
+
retrySession: session?.retrySession ?? (() => {
|
|
591
|
+
throw new Error("session_recovery_unavailable");
|
|
592
|
+
}),
|
|
532
593
|
...getAuthenticationMethods(
|
|
533
594
|
bridge,
|
|
534
595
|
publishableKey,
|
|
@@ -547,11 +608,348 @@ var createSdkInstance = ({
|
|
|
547
608
|
...getFundingSDKMethods(bridge, publishableKey),
|
|
548
609
|
...getSolanaSDKMethods(bridge, publishableKey, relyingPartyOrigin),
|
|
549
610
|
...getBitcoinSDKMethods(bridge, publishableKey, relyingPartyOrigin),
|
|
550
|
-
...getTronSDKMethods(bridge, publishableKey, relyingPartyOrigin)
|
|
611
|
+
...getTronSDKMethods(bridge, publishableKey, relyingPartyOrigin),
|
|
612
|
+
...session ? getSessionMethods(bridge, publishableKey, relyingPartyOrigin, session, sessionResume) : {}
|
|
551
613
|
});
|
|
552
614
|
|
|
553
615
|
// src/provider.tsx
|
|
554
|
-
var
|
|
616
|
+
var import_utils5 = require("@moon-x/core/utils");
|
|
617
|
+
|
|
618
|
+
// src/components/presence-otp-prompt.tsx
|
|
619
|
+
var import_react = require("react");
|
|
620
|
+
var import_react_native = require("react-native");
|
|
621
|
+
var import_sdk9 = require("@moon-x/core/sdk");
|
|
622
|
+
|
|
623
|
+
// src/components/presence-otp-gate.ts
|
|
624
|
+
var createPresenceOtpGate = () => {
|
|
625
|
+
let cancelledChallengeId = null;
|
|
626
|
+
return {
|
|
627
|
+
evaluate(request) {
|
|
628
|
+
if (request.attempt === 1) {
|
|
629
|
+
cancelledChallengeId = null;
|
|
630
|
+
}
|
|
631
|
+
if (request.challengeId && cancelledChallengeId === request.challengeId) {
|
|
632
|
+
return "cancelled";
|
|
633
|
+
}
|
|
634
|
+
return "prompt";
|
|
635
|
+
},
|
|
636
|
+
markCancelled(challengeId) {
|
|
637
|
+
cancelledChallengeId = challengeId ?? null;
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
};
|
|
641
|
+
|
|
642
|
+
// src/components/presence-otp-controller.ts
|
|
643
|
+
var IDLE_PRESENCE_OTP_STATE = {
|
|
644
|
+
request: null,
|
|
645
|
+
submitting: false,
|
|
646
|
+
invalidCode: false
|
|
647
|
+
};
|
|
648
|
+
var createPresenceOtpController = (onChange) => {
|
|
649
|
+
const gate = createPresenceOtpGate();
|
|
650
|
+
let active;
|
|
651
|
+
let pending = null;
|
|
652
|
+
const waiting = [];
|
|
653
|
+
let state = IDLE_PRESENCE_OTP_STATE;
|
|
654
|
+
let disposed = false;
|
|
655
|
+
const set = (next) => {
|
|
656
|
+
state = next;
|
|
657
|
+
if (!disposed) onChange(next);
|
|
658
|
+
};
|
|
659
|
+
const takePending = () => {
|
|
660
|
+
const current = pending;
|
|
661
|
+
pending = null;
|
|
662
|
+
return current;
|
|
663
|
+
};
|
|
664
|
+
const show = (next) => {
|
|
665
|
+
active = { challengeId: next.request.challengeId };
|
|
666
|
+
if (gate.evaluate(next.request) === "cancelled") {
|
|
667
|
+
next.reject(new Error("presence_otp_cancelled"));
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
takePending()?.reject(new Error("presence_otp_replaced"));
|
|
671
|
+
pending = next;
|
|
672
|
+
set({
|
|
673
|
+
request: next.request,
|
|
674
|
+
submitting: false,
|
|
675
|
+
invalidCode: next.request.error === "invalid code"
|
|
676
|
+
});
|
|
677
|
+
};
|
|
678
|
+
return {
|
|
679
|
+
getState: () => state,
|
|
680
|
+
requestCode: (request) => new Promise((resolve, reject) => {
|
|
681
|
+
if (disposed) {
|
|
682
|
+
reject(new Error("presence_otp_cancelled"));
|
|
683
|
+
return;
|
|
684
|
+
}
|
|
685
|
+
const next = { request, resolve, reject };
|
|
686
|
+
if (!active || active.challengeId === request.challengeId) {
|
|
687
|
+
show(next);
|
|
688
|
+
} else {
|
|
689
|
+
waiting.push(next);
|
|
690
|
+
}
|
|
691
|
+
}),
|
|
692
|
+
submit: (code) => {
|
|
693
|
+
const current = takePending();
|
|
694
|
+
if (!current) return false;
|
|
695
|
+
current.resolve(code);
|
|
696
|
+
set({ ...state, submitting: true, invalidCode: false });
|
|
697
|
+
return true;
|
|
698
|
+
},
|
|
699
|
+
cancel: () => {
|
|
700
|
+
if (state.submitting || !pending) return false;
|
|
701
|
+
gate.markCancelled(pending.request.challengeId);
|
|
702
|
+
takePending()?.reject(new Error("presence_otp_cancelled"));
|
|
703
|
+
set(IDLE_PRESENCE_OTP_STATE);
|
|
704
|
+
return true;
|
|
705
|
+
},
|
|
706
|
+
expire: (request) => {
|
|
707
|
+
if (pending?.request !== request) return;
|
|
708
|
+
takePending()?.reject(new Error("presence_otp_expired"));
|
|
709
|
+
set(IDLE_PRESENCE_OTP_STATE);
|
|
710
|
+
},
|
|
711
|
+
settled: (request) => {
|
|
712
|
+
if (!active || active.challengeId !== request.challengeId) return;
|
|
713
|
+
active = void 0;
|
|
714
|
+
takePending()?.reject(new Error("presence_otp_cancelled"));
|
|
715
|
+
const next = waiting.shift();
|
|
716
|
+
if (next) {
|
|
717
|
+
show(next);
|
|
718
|
+
} else {
|
|
719
|
+
set(IDLE_PRESENCE_OTP_STATE);
|
|
720
|
+
}
|
|
721
|
+
},
|
|
722
|
+
dispose: () => {
|
|
723
|
+
const error = new Error("presence_otp_cancelled");
|
|
724
|
+
takePending()?.reject(error);
|
|
725
|
+
for (const next of waiting.splice(0)) next.reject(error);
|
|
726
|
+
active = void 0;
|
|
727
|
+
state = IDLE_PRESENCE_OTP_STATE;
|
|
728
|
+
disposed = true;
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
// src/components/presence-otp-prompt.tsx
|
|
734
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
735
|
+
var DEFAULT_COPY = {
|
|
736
|
+
title: "Check your email",
|
|
737
|
+
description: "Enter the verification code we sent to confirm this wallet action.",
|
|
738
|
+
hint: "Didn't get it? Check spam, or cancel and try again in a minute.",
|
|
739
|
+
verify: "Verify",
|
|
740
|
+
verifying: "Verifying...",
|
|
741
|
+
cancel: "Cancel",
|
|
742
|
+
invalidCode: "That code was incorrect. Try again.",
|
|
743
|
+
incompleteCode: "Enter the 6-digit code."
|
|
744
|
+
};
|
|
745
|
+
var DEFAULT_COLORS = {
|
|
746
|
+
background: "#0a0a0a",
|
|
747
|
+
surface: "#141414",
|
|
748
|
+
border: "#333",
|
|
749
|
+
text: "#fafafa",
|
|
750
|
+
mutedText: "#a1a1aa",
|
|
751
|
+
accent: "#3b82f6",
|
|
752
|
+
accentText: "#fff",
|
|
753
|
+
error: "#f87171"
|
|
754
|
+
};
|
|
755
|
+
var OTP_LENGTH = 6;
|
|
756
|
+
var PresenceOtpPrompt = ({
|
|
757
|
+
publishableKey,
|
|
758
|
+
options
|
|
759
|
+
}) => {
|
|
760
|
+
const [state, setState] = (0, import_react.useState)(
|
|
761
|
+
IDLE_PRESENCE_OTP_STATE
|
|
762
|
+
);
|
|
763
|
+
const [code, setCode] = (0, import_react.useState)("");
|
|
764
|
+
const [incomplete, setIncomplete] = (0, import_react.useState)(false);
|
|
765
|
+
const controllerRef = (0, import_react.useRef)(null);
|
|
766
|
+
const copy = { ...DEFAULT_COPY, ...options?.copy };
|
|
767
|
+
const colors = { ...DEFAULT_COLORS, ...options?.colors };
|
|
768
|
+
(0, import_react.useEffect)(() => {
|
|
769
|
+
const controller = createPresenceOtpController(setState);
|
|
770
|
+
controllerRef.current = controller;
|
|
771
|
+
const unregister = (0, import_sdk9.registerPresenceOtpCodeProvider)(
|
|
772
|
+
publishableKey,
|
|
773
|
+
controller.requestCode,
|
|
774
|
+
controller.settled
|
|
775
|
+
);
|
|
776
|
+
return () => {
|
|
777
|
+
unregister();
|
|
778
|
+
controller.dispose();
|
|
779
|
+
controllerRef.current = null;
|
|
780
|
+
setState(IDLE_PRESENCE_OTP_STATE);
|
|
781
|
+
};
|
|
782
|
+
}, [publishableKey]);
|
|
783
|
+
(0, import_react.useEffect)(() => {
|
|
784
|
+
setCode("");
|
|
785
|
+
setIncomplete(false);
|
|
786
|
+
}, [state.request]);
|
|
787
|
+
(0, import_react.useEffect)(() => {
|
|
788
|
+
const request = state.request;
|
|
789
|
+
if (!request?.expiresAt || state.submitting) return;
|
|
790
|
+
const expire = () => controllerRef.current?.expire(request);
|
|
791
|
+
const remainingMs = request.expiresAt * 1e3 - Date.now();
|
|
792
|
+
if (remainingMs <= 0) {
|
|
793
|
+
expire();
|
|
794
|
+
return;
|
|
795
|
+
}
|
|
796
|
+
const timer = setTimeout(expire, remainingMs);
|
|
797
|
+
return () => clearTimeout(timer);
|
|
798
|
+
}, [state.request, state.submitting]);
|
|
799
|
+
const close = () => {
|
|
800
|
+
controllerRef.current?.cancel();
|
|
801
|
+
};
|
|
802
|
+
const submit = () => {
|
|
803
|
+
const normalized = code.trim();
|
|
804
|
+
if (!/^\d{6}$/.test(normalized)) {
|
|
805
|
+
setIncomplete(true);
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
controllerRef.current?.submit(normalized);
|
|
809
|
+
};
|
|
810
|
+
const submitting = state.submitting;
|
|
811
|
+
const error = incomplete ? copy.incompleteCode : state.invalidCode ? copy.invalidCode : null;
|
|
812
|
+
const complete = code.length === OTP_LENGTH;
|
|
813
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
814
|
+
import_react_native.Modal,
|
|
815
|
+
{
|
|
816
|
+
visible: state.request !== null,
|
|
817
|
+
transparent: true,
|
|
818
|
+
animationType: "fade",
|
|
819
|
+
onRequestClose: close,
|
|
820
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.View, { style: styles.backdrop, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react_native.View, { style: [styles.card, { backgroundColor: colors.background }], children: [
|
|
821
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: [styles.title, { color: colors.text }], children: copy.title }),
|
|
822
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: [styles.body, { color: colors.mutedText }], children: copy.description }),
|
|
823
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
824
|
+
import_react_native.TextInput,
|
|
825
|
+
{
|
|
826
|
+
autoFocus: true,
|
|
827
|
+
style: [
|
|
828
|
+
styles.input,
|
|
829
|
+
{
|
|
830
|
+
borderColor: colors.border,
|
|
831
|
+
backgroundColor: colors.surface,
|
|
832
|
+
color: colors.text
|
|
833
|
+
}
|
|
834
|
+
],
|
|
835
|
+
value: code,
|
|
836
|
+
onChangeText: (next) => {
|
|
837
|
+
setCode(next.replace(/\D/g, "").slice(0, OTP_LENGTH));
|
|
838
|
+
setIncomplete(false);
|
|
839
|
+
},
|
|
840
|
+
onSubmitEditing: submit,
|
|
841
|
+
editable: !submitting,
|
|
842
|
+
keyboardType: "number-pad",
|
|
843
|
+
textContentType: "oneTimeCode",
|
|
844
|
+
autoComplete: "sms-otp",
|
|
845
|
+
maxLength: OTP_LENGTH,
|
|
846
|
+
placeholder: "123456",
|
|
847
|
+
placeholderTextColor: colors.mutedText,
|
|
848
|
+
accessibilityLabel: "Verification code",
|
|
849
|
+
returnKeyType: "done"
|
|
850
|
+
}
|
|
851
|
+
),
|
|
852
|
+
error !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
853
|
+
import_react_native.Text,
|
|
854
|
+
{
|
|
855
|
+
style: [styles.error, { color: colors.error }],
|
|
856
|
+
accessibilityLiveRegion: "polite",
|
|
857
|
+
children: error
|
|
858
|
+
}
|
|
859
|
+
),
|
|
860
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
861
|
+
import_react_native.Pressable,
|
|
862
|
+
{
|
|
863
|
+
onPress: submit,
|
|
864
|
+
disabled: submitting || !complete,
|
|
865
|
+
style: [
|
|
866
|
+
styles.primaryButton,
|
|
867
|
+
{ backgroundColor: colors.accent },
|
|
868
|
+
(submitting || !complete) && styles.primaryButtonDisabled
|
|
869
|
+
],
|
|
870
|
+
accessibilityRole: "button",
|
|
871
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: [styles.primaryButtonText, { color: colors.accentText }], children: submitting ? copy.verifying : copy.verify })
|
|
872
|
+
}
|
|
873
|
+
),
|
|
874
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
875
|
+
import_react_native.Pressable,
|
|
876
|
+
{
|
|
877
|
+
onPress: close,
|
|
878
|
+
disabled: submitting,
|
|
879
|
+
style: [styles.ghostButton, submitting && styles.primaryButtonDisabled],
|
|
880
|
+
accessibilityRole: "button",
|
|
881
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: [styles.ghostButtonText, { color: colors.mutedText }], children: copy.cancel })
|
|
882
|
+
}
|
|
883
|
+
),
|
|
884
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: [styles.hint, { color: colors.mutedText }], children: copy.hint })
|
|
885
|
+
] }) })
|
|
886
|
+
}
|
|
887
|
+
);
|
|
888
|
+
};
|
|
889
|
+
var styles = import_react_native.StyleSheet.create({
|
|
890
|
+
backdrop: {
|
|
891
|
+
flex: 1,
|
|
892
|
+
alignItems: "center",
|
|
893
|
+
justifyContent: "center",
|
|
894
|
+
padding: 16,
|
|
895
|
+
backgroundColor: "rgba(0, 0, 0, 0.45)"
|
|
896
|
+
},
|
|
897
|
+
card: {
|
|
898
|
+
width: "100%",
|
|
899
|
+
maxWidth: 384,
|
|
900
|
+
padding: 24,
|
|
901
|
+
borderRadius: 14
|
|
902
|
+
},
|
|
903
|
+
title: {
|
|
904
|
+
fontSize: 20,
|
|
905
|
+
fontWeight: "600"
|
|
906
|
+
},
|
|
907
|
+
body: {
|
|
908
|
+
fontSize: 14,
|
|
909
|
+
marginTop: 8
|
|
910
|
+
},
|
|
911
|
+
input: {
|
|
912
|
+
marginTop: 16,
|
|
913
|
+
paddingVertical: 12,
|
|
914
|
+
paddingHorizontal: 16,
|
|
915
|
+
borderRadius: 12,
|
|
916
|
+
borderWidth: import_react_native.StyleSheet.hairlineWidth,
|
|
917
|
+
fontSize: 24,
|
|
918
|
+
letterSpacing: 8,
|
|
919
|
+
textAlign: "center"
|
|
920
|
+
},
|
|
921
|
+
error: {
|
|
922
|
+
fontSize: 13,
|
|
923
|
+
marginTop: 8
|
|
924
|
+
},
|
|
925
|
+
primaryButton: {
|
|
926
|
+
marginTop: 16,
|
|
927
|
+
paddingVertical: 12,
|
|
928
|
+
borderRadius: 12,
|
|
929
|
+
alignItems: "center"
|
|
930
|
+
},
|
|
931
|
+
primaryButtonDisabled: {
|
|
932
|
+
opacity: 0.5
|
|
933
|
+
},
|
|
934
|
+
primaryButtonText: {
|
|
935
|
+
fontSize: 16,
|
|
936
|
+
fontWeight: "600"
|
|
937
|
+
},
|
|
938
|
+
ghostButton: {
|
|
939
|
+
marginTop: 8,
|
|
940
|
+
paddingVertical: 12,
|
|
941
|
+
alignItems: "center"
|
|
942
|
+
},
|
|
943
|
+
ghostButtonText: {
|
|
944
|
+
fontSize: 15,
|
|
945
|
+
fontWeight: "500"
|
|
946
|
+
},
|
|
947
|
+
hint: {
|
|
948
|
+
fontSize: 12,
|
|
949
|
+
marginTop: 4,
|
|
950
|
+
textAlign: "center"
|
|
951
|
+
}
|
|
952
|
+
});
|
|
555
953
|
|
|
556
954
|
// src/transport/webview-bridge.ts
|
|
557
955
|
var import_utils3 = require("@moon-x/core/utils");
|
|
@@ -711,7 +1109,8 @@ var WebViewBridge = class {
|
|
|
711
1109
|
// ride out the iframe-app mount race; everything else makes a single attempt.
|
|
712
1110
|
async send(type, method, payload) {
|
|
713
1111
|
const isSigningPreparation = method === "GET_DEK_INFO" && payload !== null && typeof payload === "object" && "signingWalletId" in payload && payload.signingWalletId !== void 0;
|
|
714
|
-
|
|
1112
|
+
const isResumeCheck = method === "IS_AUTHENTICATED" && payload !== null && typeof payload === "object" && "resumeSessionId" in payload && payload.resumeSessionId !== void 0;
|
|
1113
|
+
if (isSigningPreparation || isResumeCheck || !RETRYABLE_METHODS.has(method)) {
|
|
715
1114
|
return this.sendOnce(
|
|
716
1115
|
type,
|
|
717
1116
|
method,
|
|
@@ -816,7 +1215,7 @@ var WebViewBridge = class {
|
|
|
816
1215
|
};
|
|
817
1216
|
|
|
818
1217
|
// src/provider.tsx
|
|
819
|
-
var
|
|
1218
|
+
var import_react3 = require("@moon-x/core/react");
|
|
820
1219
|
var import_lib2 = require("@moon-x/core/lib");
|
|
821
1220
|
|
|
822
1221
|
// src/webview-lifecycle.ts
|
|
@@ -838,55 +1237,545 @@ var webViewLifecycleReducer = (state, action) => {
|
|
|
838
1237
|
}
|
|
839
1238
|
};
|
|
840
1239
|
|
|
841
|
-
// src/session
|
|
842
|
-
|
|
843
|
-
let
|
|
1240
|
+
// src/native-session.ts
|
|
1241
|
+
function createNativeSession(reads) {
|
|
1242
|
+
let snapshot = {
|
|
1243
|
+
isAuthenticated: false,
|
|
1244
|
+
user: null,
|
|
1245
|
+
revalidatedAt: 0,
|
|
1246
|
+
sessionStatus: "restoring",
|
|
1247
|
+
sessionError: null
|
|
1248
|
+
};
|
|
1249
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
1250
|
+
const holds = /* @__PURE__ */ new Set();
|
|
1251
|
+
let holdSequence = 0;
|
|
1252
|
+
let replaceableFinish = null;
|
|
1253
|
+
let mounted = false;
|
|
1254
|
+
let ready = false;
|
|
1255
|
+
let pending = true;
|
|
844
1256
|
let generation = 0;
|
|
1257
|
+
let profileSequence = 0;
|
|
1258
|
+
let run = null;
|
|
1259
|
+
let timer;
|
|
1260
|
+
const publish = (patch) => {
|
|
1261
|
+
snapshot = { ...snapshot, ...patch };
|
|
1262
|
+
listeners.forEach((listener) => listener());
|
|
1263
|
+
};
|
|
1264
|
+
const cancelRestore = () => {
|
|
1265
|
+
run = null;
|
|
1266
|
+
clearTimeout(timer);
|
|
1267
|
+
timer = void 0;
|
|
1268
|
+
};
|
|
1269
|
+
const confirmedAt = () => Math.max(Date.now(), snapshot.revalidatedAt + 1);
|
|
1270
|
+
const captureUserWrite = () => {
|
|
1271
|
+
const capturedGeneration = generation;
|
|
1272
|
+
const sequence = ++profileSequence;
|
|
1273
|
+
return (user) => {
|
|
1274
|
+
if (!mounted || generation !== capturedGeneration || profileSequence !== sequence || !snapshot.isAuthenticated) return;
|
|
1275
|
+
if (user && typeof user === "object") publish({ user });
|
|
1276
|
+
};
|
|
1277
|
+
};
|
|
1278
|
+
const refreshUser = async () => {
|
|
1279
|
+
const write = captureUserWrite();
|
|
1280
|
+
try {
|
|
1281
|
+
write(await reads.getUser());
|
|
1282
|
+
} catch {
|
|
1283
|
+
}
|
|
1284
|
+
};
|
|
1285
|
+
const retrySession = () => {
|
|
1286
|
+
if (!mounted || run) return;
|
|
1287
|
+
pending = true;
|
|
1288
|
+
if (!ready || holds.size > 0) return;
|
|
1289
|
+
pending = false;
|
|
1290
|
+
const current = {};
|
|
1291
|
+
run = current;
|
|
1292
|
+
const capturedGeneration = generation;
|
|
1293
|
+
const isCurrent = () => mounted && ready && run === current && generation === capturedGeneration && holds.size === 0;
|
|
1294
|
+
let attempts = 0;
|
|
1295
|
+
let missing = 0;
|
|
1296
|
+
let lastError = null;
|
|
1297
|
+
let resumeSettled = !reads.resume;
|
|
1298
|
+
publish({ sessionStatus: "restoring", sessionError: null });
|
|
1299
|
+
const restore = async () => {
|
|
1300
|
+
if (!isCurrent()) return;
|
|
1301
|
+
attempts++;
|
|
1302
|
+
try {
|
|
1303
|
+
const session = await reads.getCurrentSession();
|
|
1304
|
+
if (!isCurrent()) return;
|
|
1305
|
+
if (session === null && !resumeSettled && reads.resume) {
|
|
1306
|
+
const resumed = await reads.resume();
|
|
1307
|
+
if (!isCurrent()) return;
|
|
1308
|
+
resumeSettled = true;
|
|
1309
|
+
if (resumed) {
|
|
1310
|
+
attempts--;
|
|
1311
|
+
void restore();
|
|
1312
|
+
return;
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
if (session === null) {
|
|
1316
|
+
missing++;
|
|
1317
|
+
} else {
|
|
1318
|
+
if (!session || typeof session !== "object" || !("accessToken" in session) || typeof session.accessToken !== "string" || !session.accessToken) {
|
|
1319
|
+
throw new Error("The session response is invalid. Retry the session check.");
|
|
1320
|
+
}
|
|
1321
|
+
publish({ isAuthenticated: true, sessionStatus: "authenticated", sessionError: null, revalidatedAt: confirmedAt() });
|
|
1322
|
+
await refreshUser();
|
|
1323
|
+
if (isCurrent()) run = null;
|
|
1324
|
+
return;
|
|
1325
|
+
}
|
|
1326
|
+
} catch (error) {
|
|
1327
|
+
if (!isCurrent()) return;
|
|
1328
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
1329
|
+
}
|
|
1330
|
+
if (!isCurrent()) return;
|
|
1331
|
+
if (attempts < 5) {
|
|
1332
|
+
timer = setTimeout(() => {
|
|
1333
|
+
timer = void 0;
|
|
1334
|
+
void restore();
|
|
1335
|
+
}, 200 * 2 ** (attempts - 1));
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
run = null;
|
|
1339
|
+
if (missing === 5) {
|
|
1340
|
+
generation++;
|
|
1341
|
+
profileSequence++;
|
|
1342
|
+
publish({ isAuthenticated: false, user: null, sessionStatus: "signed-out", sessionError: null, revalidatedAt: confirmedAt() });
|
|
1343
|
+
} else {
|
|
1344
|
+
publish({ sessionStatus: "error", sessionError: lastError ?? new Error("The session check failed. Retry the check.") });
|
|
1345
|
+
}
|
|
1346
|
+
};
|
|
1347
|
+
void restore();
|
|
1348
|
+
};
|
|
1349
|
+
const beginAuthFlow = ({ replaceSession = false } = {}) => {
|
|
1350
|
+
if (!mounted) throw new Error("provider_unmounted");
|
|
1351
|
+
if (replaceSession) {
|
|
1352
|
+
generation++;
|
|
1353
|
+
profileSequence++;
|
|
1354
|
+
}
|
|
1355
|
+
const capturedGeneration = generation;
|
|
1356
|
+
const id = ++holdSequence;
|
|
1357
|
+
holds.add(id);
|
|
1358
|
+
cancelRestore();
|
|
1359
|
+
pending = true;
|
|
1360
|
+
const finish = () => {
|
|
1361
|
+
if (!holds.delete(id)) return;
|
|
1362
|
+
if (holds.size === 0 && pending) retrySession();
|
|
1363
|
+
};
|
|
1364
|
+
if (replaceSession) {
|
|
1365
|
+
const previous = replaceableFinish;
|
|
1366
|
+
replaceableFinish = finish;
|
|
1367
|
+
previous?.();
|
|
1368
|
+
}
|
|
1369
|
+
return Object.assign(finish, {
|
|
1370
|
+
assertCurrent: () => {
|
|
1371
|
+
if (!mounted || generation !== capturedGeneration) throw new Error("session_changed");
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
};
|
|
845
1375
|
return {
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
return
|
|
1376
|
+
getSnapshot: () => snapshot,
|
|
1377
|
+
subscribe: (listener) => {
|
|
1378
|
+
listeners.add(listener);
|
|
1379
|
+
return () => {
|
|
1380
|
+
listeners.delete(listener);
|
|
1381
|
+
};
|
|
1382
|
+
},
|
|
1383
|
+
mount: () => {
|
|
1384
|
+
mounted = true;
|
|
1385
|
+
if (pending) retrySession();
|
|
1386
|
+
},
|
|
1387
|
+
unmount: () => {
|
|
1388
|
+
mounted = false;
|
|
1389
|
+
generation++;
|
|
1390
|
+
profileSequence++;
|
|
1391
|
+
holds.clear();
|
|
1392
|
+
cancelRestore();
|
|
1393
|
+
pending = true;
|
|
1394
|
+
},
|
|
1395
|
+
setReady: (value) => {
|
|
1396
|
+
if (ready === value) return;
|
|
1397
|
+
ready = value;
|
|
1398
|
+
if (value) {
|
|
1399
|
+
retrySession();
|
|
1400
|
+
return;
|
|
1401
|
+
}
|
|
1402
|
+
generation++;
|
|
1403
|
+
profileSequence++;
|
|
1404
|
+
cancelRestore();
|
|
1405
|
+
pending = true;
|
|
1406
|
+
publish({ sessionStatus: "restoring", sessionError: null });
|
|
1407
|
+
},
|
|
1408
|
+
retrySession,
|
|
1409
|
+
/** Replaces an active check: a suspended WebView can drop requests it had in flight. */
|
|
1410
|
+
restartSession: () => {
|
|
1411
|
+
cancelRestore();
|
|
1412
|
+
retrySession();
|
|
850
1413
|
},
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
1414
|
+
beginAuthFlow,
|
|
1415
|
+
captureUserWrite,
|
|
1416
|
+
captureUserRefresh: () => {
|
|
1417
|
+
const capturedGeneration = generation;
|
|
1418
|
+
return async () => {
|
|
1419
|
+
if (mounted && generation === capturedGeneration) await refreshUser();
|
|
1420
|
+
};
|
|
856
1421
|
},
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
1422
|
+
refreshUser,
|
|
1423
|
+
beginAuthOperation: () => {
|
|
1424
|
+
const finish = beginAuthFlow();
|
|
1425
|
+
const replaced = replaceableFinish;
|
|
1426
|
+
replaceableFinish = null;
|
|
1427
|
+
replaced?.();
|
|
1428
|
+
let capturedGeneration = ++generation;
|
|
1429
|
+
profileSequence++;
|
|
1430
|
+
const current = () => mounted && generation === capturedGeneration;
|
|
1431
|
+
return {
|
|
1432
|
+
finish,
|
|
1433
|
+
setIsAuthenticated: (value) => {
|
|
1434
|
+
if (!current()) return;
|
|
1435
|
+
capturedGeneration = ++generation;
|
|
1436
|
+
profileSequence++;
|
|
1437
|
+
pending = false;
|
|
1438
|
+
publish({
|
|
1439
|
+
isAuthenticated: value,
|
|
1440
|
+
user: null,
|
|
1441
|
+
sessionError: null,
|
|
1442
|
+
sessionStatus: value ? "authenticated" : "signed-out",
|
|
1443
|
+
revalidatedAt: confirmedAt()
|
|
1444
|
+
});
|
|
1445
|
+
},
|
|
1446
|
+
refreshUser: async () => {
|
|
1447
|
+
if (current()) await refreshUser();
|
|
1448
|
+
}
|
|
1449
|
+
};
|
|
860
1450
|
}
|
|
861
1451
|
};
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
// src/session-resume.ts
|
|
1455
|
+
var import_sdk10 = require("@moon-x/core/sdk");
|
|
1456
|
+
var import_utils4 = require("@moon-x/core/utils");
|
|
1457
|
+
var LOGOUT_TOMBSTONE = '{"loggedOut":true}';
|
|
1458
|
+
var sharedStates = /* @__PURE__ */ new Map();
|
|
1459
|
+
var sharedState = (publishableKey) => {
|
|
1460
|
+
let state = sharedStates.get(publishableKey);
|
|
1461
|
+
if (!state) {
|
|
1462
|
+
state = {
|
|
1463
|
+
queue: Promise.resolve(),
|
|
1464
|
+
blockCache: void 0,
|
|
1465
|
+
installId: void 0,
|
|
1466
|
+
logoutGeneration: 0,
|
|
1467
|
+
bindSequence: 0,
|
|
1468
|
+
loginsInProgress: 0,
|
|
1469
|
+
bindDeferred: false
|
|
1470
|
+
};
|
|
1471
|
+
sharedStates.set(publishableKey, state);
|
|
1472
|
+
}
|
|
1473
|
+
return state;
|
|
1474
|
+
};
|
|
1475
|
+
var storageKey = (publishableKey) => (
|
|
1476
|
+
// expo-secure-store keys allow only alphanumerics, ".", "-" and "_".
|
|
1477
|
+
`moonx.session_resume.${publishableKey.replace(/[^A-Za-z0-9._-]/g, "_")}`
|
|
1478
|
+
);
|
|
1479
|
+
var parseRecord = (raw) => {
|
|
1480
|
+
if (!raw) return null;
|
|
1481
|
+
try {
|
|
1482
|
+
const value = JSON.parse(raw);
|
|
1483
|
+
if (typeof value.privateKey !== "string" || typeof value.publicKey !== "string") return null;
|
|
1484
|
+
if ((0, import_sdk10.sessionResumePublicKeyOf)(value.privateKey) !== value.publicKey) return null;
|
|
1485
|
+
const sessionId = typeof value.sessionId === "string" && import_sdk10.SESSION_RESUME_SESSION_ID_PATTERN.test(value.sessionId) ? value.sessionId : void 0;
|
|
1486
|
+
return {
|
|
1487
|
+
privateKey: value.privateKey,
|
|
1488
|
+
publicKey: value.publicKey,
|
|
1489
|
+
...typeof value.installId === "string" ? { installId: value.installId } : {},
|
|
1490
|
+
...sessionId ? { sessionId } : {}
|
|
1491
|
+
};
|
|
1492
|
+
} catch {
|
|
1493
|
+
return null;
|
|
1494
|
+
}
|
|
1495
|
+
};
|
|
1496
|
+
var createNativeSessionResume = ({
|
|
1497
|
+
bridge,
|
|
1498
|
+
publishableKey,
|
|
1499
|
+
storage,
|
|
1500
|
+
blockStore
|
|
1501
|
+
}) => {
|
|
1502
|
+
const key = storageKey(publishableKey);
|
|
1503
|
+
const blockKey = `session_resume_blocked:${publishableKey}`;
|
|
1504
|
+
const shared = sharedState(publishableKey);
|
|
1505
|
+
const withLock = (run) => {
|
|
1506
|
+
const next = shared.queue.then(run, run);
|
|
1507
|
+
shared.queue = next.catch(() => void 0);
|
|
1508
|
+
return next;
|
|
1509
|
+
};
|
|
1510
|
+
const blockState = async () => {
|
|
1511
|
+
if (shared.blockCache === void 0) {
|
|
1512
|
+
const stored = await blockStore.get(blockKey);
|
|
1513
|
+
shared.blockCache = stored === null ? null : stored === "logout" ? "logout" : "blocked";
|
|
1514
|
+
}
|
|
1515
|
+
return shared.blockCache;
|
|
1516
|
+
};
|
|
1517
|
+
const isBlocked = async () => await blockState() !== null;
|
|
1518
|
+
const isLoggedOut = async () => await blockState() === "logout" || await storage.getItem(key) === LOGOUT_TOMBSTONE;
|
|
1519
|
+
const writeBlock = async (state) => {
|
|
1520
|
+
shared.blockCache = state;
|
|
1521
|
+
try {
|
|
1522
|
+
if (state) await blockStore.set(blockKey, state === "logout" ? "logout" : "1");
|
|
1523
|
+
else await blockStore.remove(blockKey);
|
|
1524
|
+
return true;
|
|
1525
|
+
} catch {
|
|
1526
|
+
return false;
|
|
1527
|
+
}
|
|
1528
|
+
};
|
|
1529
|
+
const setBlocked = async (value) => {
|
|
1530
|
+
let current;
|
|
1531
|
+
try {
|
|
1532
|
+
current = await blockState();
|
|
1533
|
+
} catch {
|
|
1534
|
+
return value ? writeBlock("logout") : false;
|
|
1535
|
+
}
|
|
1536
|
+
if (current === "logout") return value ? writeBlock("logout") : true;
|
|
1537
|
+
return writeBlock(value ? "blocked" : null);
|
|
1538
|
+
};
|
|
1539
|
+
const installKey = `session_resume_install:${publishableKey}`;
|
|
1540
|
+
const installId = async () => {
|
|
1541
|
+
if (shared.installId) return shared.installId;
|
|
1542
|
+
const stored = await blockStore.get(installKey);
|
|
1543
|
+
if (stored) return shared.installId = stored;
|
|
1544
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
1545
|
+
const created = Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
1546
|
+
await blockStore.set(installKey, created);
|
|
1547
|
+
return shared.installId = created;
|
|
1548
|
+
};
|
|
1549
|
+
const read = async () => {
|
|
1550
|
+
const record = parseRecord(await storage.getItem(key));
|
|
1551
|
+
if (!record) return null;
|
|
1552
|
+
if (record.installId === await installId()) return record;
|
|
1553
|
+
await clearKey();
|
|
1554
|
+
return null;
|
|
1555
|
+
};
|
|
1556
|
+
const write = async (record) => storage.setItem(key, JSON.stringify({ ...record, installId: await installId() }));
|
|
1557
|
+
const clearKey = async () => {
|
|
1558
|
+
for (let attempt = 0; attempt < 2; attempt++) {
|
|
1559
|
+
try {
|
|
1560
|
+
await storage.removeItem(key);
|
|
1561
|
+
await setBlocked(false);
|
|
1562
|
+
return "deleted";
|
|
1563
|
+
} catch {
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
let tombstoned = false;
|
|
1567
|
+
try {
|
|
1568
|
+
await storage.setItem(key, "{}");
|
|
1569
|
+
tombstoned = true;
|
|
1570
|
+
} catch {
|
|
1571
|
+
}
|
|
1572
|
+
const markerPersisted = await setBlocked(true);
|
|
1573
|
+
if (!tombstoned && !markerPersisted) {
|
|
1574
|
+
console.warn(
|
|
1575
|
+
"MoonX: could not invalidate the session resume key in either store; it is blocked until the app restarts."
|
|
1576
|
+
);
|
|
1577
|
+
return "unrecorded";
|
|
1578
|
+
}
|
|
1579
|
+
return "invalidated";
|
|
1580
|
+
};
|
|
1581
|
+
const invalidateUnreadable = async () => {
|
|
1582
|
+
if (await setBlocked(true)) return true;
|
|
1583
|
+
try {
|
|
1584
|
+
await storage.setItem(key, LOGOUT_TOMBSTONE);
|
|
1585
|
+
return true;
|
|
1586
|
+
} catch {
|
|
1587
|
+
return false;
|
|
1588
|
+
}
|
|
1589
|
+
};
|
|
1590
|
+
const replace = async (record) => {
|
|
1591
|
+
try {
|
|
1592
|
+
await write(record);
|
|
1593
|
+
return true;
|
|
1594
|
+
} catch {
|
|
1595
|
+
await clearKey();
|
|
1596
|
+
return false;
|
|
1597
|
+
}
|
|
1598
|
+
};
|
|
1599
|
+
const forgetRecordedSession = async (record) => {
|
|
1600
|
+
try {
|
|
1601
|
+
await write({ privateKey: record.privateKey, publicKey: record.publicKey });
|
|
1602
|
+
return true;
|
|
1603
|
+
} catch {
|
|
1604
|
+
return await clearKey() !== "unrecorded";
|
|
1605
|
+
}
|
|
1606
|
+
};
|
|
1607
|
+
const bind = async () => {
|
|
1608
|
+
if (shared.loginsInProgress > 0) {
|
|
1609
|
+
shared.bindDeferred = true;
|
|
1610
|
+
return;
|
|
1611
|
+
}
|
|
1612
|
+
const sequence = ++shared.bindSequence;
|
|
1613
|
+
const isLatest = () => shared.bindSequence === sequence;
|
|
1614
|
+
await withLock(async () => {
|
|
1615
|
+
if (!isLatest()) return;
|
|
1616
|
+
try {
|
|
1617
|
+
if (await isLoggedOut()) return;
|
|
1618
|
+
} catch {
|
|
1619
|
+
await invalidateUnreadable();
|
|
1620
|
+
return;
|
|
1621
|
+
}
|
|
1622
|
+
let record;
|
|
1623
|
+
try {
|
|
1624
|
+
record = await read();
|
|
1625
|
+
} catch {
|
|
1626
|
+
await invalidateUnreadable();
|
|
1627
|
+
return;
|
|
1628
|
+
}
|
|
1629
|
+
if (!record) {
|
|
1630
|
+
record = (0, import_sdk10.createSessionResumeKeyPair)();
|
|
1631
|
+
try {
|
|
1632
|
+
await write(record);
|
|
1633
|
+
} catch {
|
|
1634
|
+
return;
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
let result = null;
|
|
1638
|
+
try {
|
|
1639
|
+
result = await bridge.send(
|
|
1640
|
+
import_utils4.PostMessageType.AUTH,
|
|
1641
|
+
import_utils4.PostMessageMethod.SESSION_RESUME_BIND,
|
|
1642
|
+
{ publishableKey, publicKey: record.publicKey }
|
|
1643
|
+
);
|
|
1644
|
+
} catch {
|
|
1645
|
+
}
|
|
1646
|
+
if (!isLatest()) return;
|
|
1647
|
+
if (result?.bound && import_sdk10.SESSION_RESUME_SESSION_ID_PATTERN.test(result.sessionId)) {
|
|
1648
|
+
if (record.sessionId === result.sessionId || await replace({ ...record, sessionId: result.sessionId })) {
|
|
1649
|
+
await setBlocked(false);
|
|
1650
|
+
}
|
|
1651
|
+
return;
|
|
1652
|
+
}
|
|
1653
|
+
if (record.sessionId && result?.sessionId !== record.sessionId) {
|
|
1654
|
+
await replace({ privateKey: record.privateKey, publicKey: record.publicKey });
|
|
1655
|
+
}
|
|
1656
|
+
});
|
|
1657
|
+
};
|
|
1658
|
+
const resume = () => withLock(async () => {
|
|
1659
|
+
if (await isBlocked()) return false;
|
|
1660
|
+
const record = await read();
|
|
1661
|
+
const sessionId = record?.sessionId;
|
|
1662
|
+
if (!record || !sessionId) return false;
|
|
1663
|
+
const check = await bridge.send(
|
|
1664
|
+
import_utils4.PostMessageType.AUTH,
|
|
1665
|
+
import_utils4.PostMessageMethod.IS_AUTHENTICATED,
|
|
1666
|
+
{ publishableKey, resumeSessionId: sessionId }
|
|
1667
|
+
);
|
|
1668
|
+
if (check?.isAuthenticated === true) return true;
|
|
1669
|
+
if (check?.resumeRejected) {
|
|
1670
|
+
await clearKey();
|
|
1671
|
+
return false;
|
|
1672
|
+
}
|
|
1673
|
+
const challenge = check?.resumeChallenge;
|
|
1674
|
+
if (typeof challenge !== "string" || !import_sdk10.SESSION_RESUME_CHALLENGE_PATTERN.test(challenge)) return false;
|
|
1675
|
+
const signature = (0, import_sdk10.signSessionResume)(record.privateKey, sessionId, challenge);
|
|
1676
|
+
if (!signature) return false;
|
|
1677
|
+
const resumed = await bridge.send(
|
|
1678
|
+
import_utils4.PostMessageType.AUTH,
|
|
1679
|
+
import_utils4.PostMessageMethod.SESSION_RESUME,
|
|
1680
|
+
{ publishableKey, sessionId, challenge, signature }
|
|
1681
|
+
);
|
|
1682
|
+
if (resumed?.resumeRejected) {
|
|
1683
|
+
await clearKey();
|
|
1684
|
+
return false;
|
|
1685
|
+
}
|
|
1686
|
+
return resumed?.isAuthenticated === true;
|
|
1687
|
+
});
|
|
1688
|
+
const logout = (run) => withLock(async () => {
|
|
1689
|
+
shared.logoutGeneration++;
|
|
1690
|
+
if (await clearKey() !== "deleted") {
|
|
1691
|
+
console.warn("MoonX: could not delete the session resume key; continuing logout to revoke the session.");
|
|
1692
|
+
}
|
|
1693
|
+
if (!await writeBlock("logout")) {
|
|
1694
|
+
try {
|
|
1695
|
+
await storage.setItem(key, LOGOUT_TOMBSTONE);
|
|
1696
|
+
} catch {
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
return run();
|
|
1700
|
+
});
|
|
1701
|
+
const cancelPendingBinds = () => {
|
|
1702
|
+
shared.bindSequence++;
|
|
1703
|
+
};
|
|
1704
|
+
const forgetSession = () => withLock(async () => {
|
|
1705
|
+
let record;
|
|
1706
|
+
try {
|
|
1707
|
+
record = await read();
|
|
1708
|
+
} catch {
|
|
1709
|
+
if (!await invalidateUnreadable()) throw new Error("session_resume_storage_unavailable");
|
|
1710
|
+
return;
|
|
1711
|
+
}
|
|
1712
|
+
if (record?.sessionId && !await forgetRecordedSession(record) && !await invalidateUnreadable()) {
|
|
1713
|
+
throw new Error("session_resume_storage_unavailable");
|
|
1714
|
+
}
|
|
1715
|
+
});
|
|
1716
|
+
const clearLogoutBlock = (generation) => withLock(async () => {
|
|
1717
|
+
if (shared.logoutGeneration !== generation) return;
|
|
1718
|
+
try {
|
|
1719
|
+
if (await blockState() === "logout") await writeBlock(null);
|
|
1720
|
+
if (await storage.getItem(key) === LOGOUT_TOMBSTONE) await storage.removeItem(key);
|
|
1721
|
+
} catch {
|
|
1722
|
+
}
|
|
1723
|
+
});
|
|
1724
|
+
const beginLogin = async () => {
|
|
1725
|
+
shared.loginsInProgress++;
|
|
1726
|
+
const generation = shared.logoutGeneration;
|
|
1727
|
+
cancelPendingBinds();
|
|
1728
|
+
let released = false;
|
|
1729
|
+
const release = (succeeded = false) => {
|
|
1730
|
+
if (released) return;
|
|
1731
|
+
released = true;
|
|
1732
|
+
shared.loginsInProgress--;
|
|
1733
|
+
const cleared = succeeded ? clearLogoutBlock(generation) : Promise.resolve();
|
|
1734
|
+
if (shared.loginsInProgress === 0 && shared.bindDeferred) {
|
|
1735
|
+
shared.bindDeferred = false;
|
|
1736
|
+
void cleared.then(() => bind());
|
|
1737
|
+
}
|
|
1738
|
+
};
|
|
1739
|
+
try {
|
|
1740
|
+
await forgetSession();
|
|
1741
|
+
} catch (error) {
|
|
1742
|
+
release();
|
|
1743
|
+
throw error;
|
|
1744
|
+
}
|
|
1745
|
+
return release;
|
|
1746
|
+
};
|
|
1747
|
+
return { bind, beginLogin, cancelPendingBinds, resume, logout };
|
|
862
1748
|
};
|
|
863
1749
|
|
|
864
1750
|
// src/provider.tsx
|
|
865
|
-
var
|
|
1751
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
866
1752
|
var DEFAULT_IFRAME_URL = "https://x-iframe.moonpay.com";
|
|
867
|
-
var MoonXContext = (0,
|
|
1753
|
+
var MoonXContext = (0, import_react2.createContext)(null);
|
|
868
1754
|
var MoonXProvider = ({
|
|
869
1755
|
publishableKey,
|
|
870
1756
|
config,
|
|
871
1757
|
children
|
|
872
1758
|
}) => {
|
|
873
1759
|
(0, import_lib2.validatePublishableKey)(publishableKey);
|
|
1760
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(NativeProvider, { publishableKey, config, children }, JSON.stringify([publishableKey, config?.iframeUrl ?? DEFAULT_IFRAME_URL]));
|
|
1761
|
+
};
|
|
1762
|
+
var NativeProvider = ({ publishableKey, config, children }) => {
|
|
874
1763
|
const iframeUrl = config?.iframeUrl ?? DEFAULT_IFRAME_URL;
|
|
875
1764
|
const relyingPartyOrigin = config?.relyingPartyOrigin ?? "";
|
|
876
|
-
const webViewRef = (0,
|
|
877
|
-
const bridge = (0,
|
|
1765
|
+
const webViewRef = (0, import_react2.useRef)(null);
|
|
1766
|
+
const bridge = (0, import_react2.useMemo)(
|
|
878
1767
|
() => new WebViewBridge(
|
|
879
1768
|
webViewRef
|
|
880
1769
|
),
|
|
881
1770
|
[]
|
|
882
1771
|
);
|
|
883
|
-
const relyingPartyOriginResolver = (0,
|
|
1772
|
+
const relyingPartyOriginResolver = (0, import_react2.useMemo)(
|
|
884
1773
|
() => makeRelyingPartyOriginResolver(bridge, publishableKey, relyingPartyOrigin),
|
|
885
1774
|
[bridge, publishableKey, relyingPartyOrigin]
|
|
886
1775
|
);
|
|
887
|
-
const [sensitiveVisible, setSensitiveVisible] = (0,
|
|
888
|
-
const [captchaChallengeVisible, setCaptchaChallengeVisible] = (0,
|
|
889
|
-
const cancelRef = (0,
|
|
1776
|
+
const [sensitiveVisible, setSensitiveVisible] = (0, import_react2.useState)(false);
|
|
1777
|
+
const [captchaChallengeVisible, setCaptchaChallengeVisible] = (0, import_react2.useState)(false);
|
|
1778
|
+
const cancelRef = (0, import_react2.useRef)(null);
|
|
890
1779
|
const webViewVisible = sensitiveVisible || captchaChallengeVisible;
|
|
891
1780
|
const [
|
|
892
1781
|
{
|
|
@@ -895,76 +1784,78 @@ var MoonXProvider = ({
|
|
|
895
1784
|
key: webViewKey
|
|
896
1785
|
},
|
|
897
1786
|
dispatchWebViewLifecycle
|
|
898
|
-
] = (0,
|
|
899
|
-
const
|
|
900
|
-
const
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
1787
|
+
] = (0, import_react2.useReducer)(webViewLifecycleReducer, initialWebViewLifecycleState);
|
|
1788
|
+
const sessionResumeStorage = config?.sessionResumeStorage;
|
|
1789
|
+
const sessionResume = (0, import_react2.useMemo)(
|
|
1790
|
+
() => sessionResumeStorage ? createNativeSessionResume({
|
|
1791
|
+
bridge,
|
|
1792
|
+
publishableKey,
|
|
1793
|
+
storage: sessionResumeStorage,
|
|
1794
|
+
blockStore: createAsyncStorageKv()
|
|
1795
|
+
}) : void 0,
|
|
1796
|
+
[bridge, publishableKey, sessionResumeStorage]
|
|
907
1797
|
);
|
|
908
|
-
const
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
}, []);
|
|
923
|
-
(0,
|
|
924
|
-
|
|
1798
|
+
const session = (0, import_react2.useMemo)(
|
|
1799
|
+
() => createNativeSession({
|
|
1800
|
+
getCurrentSession: () => bridge.send(import_utils5.PostMessageType.AUTH, import_utils5.PostMessageMethod.GET_CURRENT_SESSION, { publishableKey }),
|
|
1801
|
+
getUser: () => bridge.send(import_utils5.PostMessageType.AUTH, import_utils5.PostMessageMethod.GET_USER, { publishableKey }),
|
|
1802
|
+
resume: sessionResume?.resume
|
|
1803
|
+
}),
|
|
1804
|
+
[bridge, publishableKey, sessionResume]
|
|
1805
|
+
);
|
|
1806
|
+
const sessionSnapshot = (0, import_react2.useSyncExternalStore)(session.subscribe, session.getSnapshot, session.getSnapshot);
|
|
1807
|
+
const { isAuthenticated, user, revalidatedAt } = sessionSnapshot;
|
|
1808
|
+
const { beginAuthFlow, refreshUser } = session;
|
|
1809
|
+
(0, import_react2.useLayoutEffect)(() => {
|
|
1810
|
+
session.mount();
|
|
1811
|
+
return session.unmount;
|
|
1812
|
+
}, [session]);
|
|
1813
|
+
(0, import_react2.useEffect)(() => {
|
|
1814
|
+
session.setReady(ready);
|
|
1815
|
+
}, [session, ready]);
|
|
1816
|
+
const { sessionStatus } = sessionSnapshot;
|
|
1817
|
+
(0, import_react2.useEffect)(() => {
|
|
1818
|
+
if (!sessionResume || !ready || sessionStatus !== "authenticated") return;
|
|
1819
|
+
void sessionResume.bind();
|
|
1820
|
+
}, [sessionResume, ready, sessionStatus, revalidatedAt]);
|
|
1821
|
+
(0, import_react2.useEffect)(() => {
|
|
1822
|
+
const subscription = import_react_native2.AppState.addEventListener("change", (nextState) => {
|
|
925
1823
|
if (nextState === "active") {
|
|
926
|
-
|
|
1824
|
+
session.restartSession();
|
|
927
1825
|
}
|
|
928
1826
|
});
|
|
929
1827
|
return () => subscription.remove();
|
|
930
|
-
}, []);
|
|
931
|
-
const { height: screenHeight } = (0,
|
|
1828
|
+
}, [session]);
|
|
1829
|
+
const { height: screenHeight } = (0, import_react_native2.useWindowDimensions)();
|
|
932
1830
|
const SHEET_TOP_OFFSET = 80;
|
|
933
|
-
const sheetTranslateY = (0,
|
|
934
|
-
const backdropOpacity = (0,
|
|
935
|
-
(0,
|
|
936
|
-
|
|
937
|
-
|
|
1831
|
+
const sheetTranslateY = (0, import_react2.useRef)(new import_react_native2.Animated.Value(screenHeight)).current;
|
|
1832
|
+
const backdropOpacity = (0, import_react2.useRef)(new import_react_native2.Animated.Value(0)).current;
|
|
1833
|
+
(0, import_react2.useEffect)(() => {
|
|
1834
|
+
import_react_native2.Animated.parallel([
|
|
1835
|
+
import_react_native2.Animated.timing(sheetTranslateY, {
|
|
938
1836
|
toValue: webViewVisible ? 0 : screenHeight,
|
|
939
1837
|
duration: 280,
|
|
940
1838
|
useNativeDriver: true
|
|
941
1839
|
}),
|
|
942
|
-
|
|
1840
|
+
import_react_native2.Animated.timing(backdropOpacity, {
|
|
943
1841
|
toValue: webViewVisible ? 0.5 : 0,
|
|
944
1842
|
duration: 280,
|
|
945
1843
|
useNativeDriver: true
|
|
946
1844
|
})
|
|
947
1845
|
]).start();
|
|
948
1846
|
}, [webViewVisible, sheetTranslateY, backdropOpacity, screenHeight]);
|
|
949
|
-
const initialSourceUri = (0,
|
|
1847
|
+
const initialSourceUri = (0, import_react2.useMemo)(() => {
|
|
950
1848
|
const base = iframeUrl.replace(/\/$/, "");
|
|
951
1849
|
const sep = base.includes("?") ? "&" : "?";
|
|
952
1850
|
return `${base}${sep}publishableKey=${encodeURIComponent(publishableKey)}`;
|
|
953
1851
|
}, [iframeUrl, publishableKey]);
|
|
954
|
-
const handleMessage = (0,
|
|
1852
|
+
const handleMessage = (0, import_react2.useCallback)(
|
|
955
1853
|
(event) => {
|
|
956
1854
|
bridge.handleMessage({ nativeEvent: { data: event.nativeEvent.data } });
|
|
957
1855
|
},
|
|
958
1856
|
[bridge]
|
|
959
1857
|
);
|
|
960
|
-
const
|
|
961
|
-
try {
|
|
962
|
-
const fetched = await sdkRef.current.getUser();
|
|
963
|
-
if (fetched) setUser(fetched);
|
|
964
|
-
} catch {
|
|
965
|
-
}
|
|
966
|
-
}, []);
|
|
967
|
-
const navigateWebView = (0, import_react.useCallback)(
|
|
1858
|
+
const navigateWebView = (0, import_react2.useCallback)(
|
|
968
1859
|
(path) => {
|
|
969
1860
|
const ref = webViewRef.current;
|
|
970
1861
|
if (!ref) return;
|
|
@@ -979,7 +1870,7 @@ var MoonXProvider = ({
|
|
|
979
1870
|
},
|
|
980
1871
|
[iframeUrl, publishableKey]
|
|
981
1872
|
);
|
|
982
|
-
const runSensitiveFlow = (0,
|
|
1873
|
+
const runSensitiveFlow = (0, import_react2.useCallback)(
|
|
983
1874
|
(options) => {
|
|
984
1875
|
setSensitiveVisible(true);
|
|
985
1876
|
navigateWebView(options.flowPath);
|
|
@@ -1021,7 +1912,7 @@ var MoonXProvider = ({
|
|
|
1021
1912
|
},
|
|
1022
1913
|
[bridge, navigateWebView]
|
|
1023
1914
|
);
|
|
1024
|
-
const sdk = (0,
|
|
1915
|
+
const sdk = (0, import_react2.useMemo)(
|
|
1025
1916
|
() => createSdkInstance({
|
|
1026
1917
|
bridge,
|
|
1027
1918
|
publishableKey,
|
|
@@ -1035,9 +1926,9 @@ var MoonXProvider = ({
|
|
|
1035
1926
|
user,
|
|
1036
1927
|
ready,
|
|
1037
1928
|
revalidatedAt,
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1929
|
+
refreshUser,
|
|
1930
|
+
session,
|
|
1931
|
+
sessionResume
|
|
1041
1932
|
}),
|
|
1042
1933
|
[
|
|
1043
1934
|
bridge,
|
|
@@ -1047,22 +1938,24 @@ var MoonXProvider = ({
|
|
|
1047
1938
|
user,
|
|
1048
1939
|
ready,
|
|
1049
1940
|
revalidatedAt,
|
|
1050
|
-
refreshUser
|
|
1941
|
+
refreshUser,
|
|
1942
|
+
session,
|
|
1943
|
+
sessionResume,
|
|
1944
|
+
sessionSnapshot
|
|
1051
1945
|
]
|
|
1052
1946
|
);
|
|
1053
|
-
const
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
}, [sdk]);
|
|
1057
|
-
(0, import_react.useEffect)(() => {
|
|
1947
|
+
const sessionResumeRef = (0, import_react2.useRef)(sessionResume);
|
|
1948
|
+
sessionResumeRef.current = sessionResume;
|
|
1949
|
+
(0, import_react2.useEffect)(() => {
|
|
1058
1950
|
return () => {
|
|
1951
|
+
sessionResumeRef.current?.cancelPendingBinds();
|
|
1059
1952
|
bridge.cleanup("provider_unmounted");
|
|
1060
1953
|
};
|
|
1061
1954
|
}, [bridge]);
|
|
1062
|
-
(0,
|
|
1955
|
+
(0, import_react2.useEffect)(
|
|
1063
1956
|
() => bridge.register(
|
|
1064
|
-
|
|
1065
|
-
|
|
1957
|
+
import_utils5.PostMessageType.INIT,
|
|
1958
|
+
import_utils5.PostMessageMethod.CAPTCHA_CHALLENGE_VISIBILITY,
|
|
1066
1959
|
(payload) => {
|
|
1067
1960
|
if (typeof payload?.visible === "boolean") {
|
|
1068
1961
|
setCaptchaChallengeVisible(payload.visible);
|
|
@@ -1071,21 +1964,17 @@ var MoonXProvider = ({
|
|
|
1071
1964
|
),
|
|
1072
1965
|
[bridge]
|
|
1073
1966
|
);
|
|
1074
|
-
(0,
|
|
1967
|
+
(0, import_react2.useEffect)(() => {
|
|
1075
1968
|
const unsubscribe = bridge.onResponseError((error) => {
|
|
1076
|
-
|
|
1077
|
-
error,
|
|
1078
|
-
authFlowsInFlight: authFlowsInFlightRef.current,
|
|
1079
|
-
revalidate: () => setRestoreNonce((value) => value + 1)
|
|
1080
|
-
});
|
|
1969
|
+
if (error.message === "no_session") session.retrySession();
|
|
1081
1970
|
});
|
|
1082
1971
|
return unsubscribe;
|
|
1083
|
-
}, [bridge,
|
|
1084
|
-
(0,
|
|
1972
|
+
}, [bridge, session]);
|
|
1973
|
+
(0, import_react2.useEffect)(() => {
|
|
1085
1974
|
let cancelled = false;
|
|
1086
1975
|
const unregister = bridge.register(
|
|
1087
|
-
|
|
1088
|
-
|
|
1976
|
+
import_utils5.PostMessageType.INIT,
|
|
1977
|
+
import_utils5.PostMessageMethod.READY,
|
|
1089
1978
|
() => {
|
|
1090
1979
|
if (!cancelled) dispatchWebViewLifecycle({ type: "ready" });
|
|
1091
1980
|
}
|
|
@@ -1099,65 +1988,7 @@ var MoonXProvider = ({
|
|
|
1099
1988
|
clearTimeout(fallback);
|
|
1100
1989
|
};
|
|
1101
1990
|
}, [bridge, webViewRecoveryNonce]);
|
|
1102
|
-
(0,
|
|
1103
|
-
if (!ready) return;
|
|
1104
|
-
const revalidationGeneration = sessionRevalidationGate.begin();
|
|
1105
|
-
let cancelled = false;
|
|
1106
|
-
let attempt = 0;
|
|
1107
|
-
const maxAttempts = 5;
|
|
1108
|
-
const timers = /* @__PURE__ */ new Set();
|
|
1109
|
-
const schedule = (callback, delay) => {
|
|
1110
|
-
const timer = setTimeout(() => {
|
|
1111
|
-
timers.delete(timer);
|
|
1112
|
-
callback();
|
|
1113
|
-
}, delay);
|
|
1114
|
-
timers.add(timer);
|
|
1115
|
-
};
|
|
1116
|
-
const tryRestore = async () => {
|
|
1117
|
-
if (cancelled || authFlowsInFlightRef.current > 0) return;
|
|
1118
|
-
attempt += 1;
|
|
1119
|
-
try {
|
|
1120
|
-
const session = await sdkRef.current.getCurrentSession();
|
|
1121
|
-
if (cancelled || authFlowsInFlightRef.current > 0) return;
|
|
1122
|
-
if (session) {
|
|
1123
|
-
setIsAuthenticated(true);
|
|
1124
|
-
try {
|
|
1125
|
-
const u = await sdkRef.current.getUser();
|
|
1126
|
-
if (!cancelled && u) setUser(u);
|
|
1127
|
-
} catch {
|
|
1128
|
-
}
|
|
1129
|
-
if (!cancelled) setRevalidatedAt(Date.now());
|
|
1130
|
-
sessionRevalidationGate.finish(revalidationGeneration);
|
|
1131
|
-
return;
|
|
1132
|
-
}
|
|
1133
|
-
if (attempt < maxAttempts) {
|
|
1134
|
-
const delay = 200 * 2 ** (attempt - 1);
|
|
1135
|
-
schedule(tryRestore, delay);
|
|
1136
|
-
} else if (!cancelled) {
|
|
1137
|
-
setIsAuthenticated(false);
|
|
1138
|
-
setUser(null);
|
|
1139
|
-
setRevalidatedAt(Date.now());
|
|
1140
|
-
sessionRevalidationGate.finish(revalidationGeneration);
|
|
1141
|
-
}
|
|
1142
|
-
} catch {
|
|
1143
|
-
if (authFlowsInFlightRef.current > 0) return;
|
|
1144
|
-
if (!cancelled && attempt < maxAttempts) {
|
|
1145
|
-
const delay = 200 * 2 ** (attempt - 1);
|
|
1146
|
-
schedule(tryRestore, delay);
|
|
1147
|
-
} else if (!cancelled) {
|
|
1148
|
-
setRevalidatedAt(Date.now());
|
|
1149
|
-
sessionRevalidationGate.finish(revalidationGeneration);
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
};
|
|
1153
|
-
schedule(tryRestore, restoreNonce > 0 ? 150 : 0);
|
|
1154
|
-
return () => {
|
|
1155
|
-
cancelled = true;
|
|
1156
|
-
timers.forEach(clearTimeout);
|
|
1157
|
-
timers.clear();
|
|
1158
|
-
};
|
|
1159
|
-
}, [ready, restoreNonce, sessionRevalidationGate]);
|
|
1160
|
-
const contextValue = (0, import_react.useMemo)(
|
|
1991
|
+
const contextValue = (0, import_react2.useMemo)(
|
|
1161
1992
|
() => ({
|
|
1162
1993
|
sdk,
|
|
1163
1994
|
_bridge: bridge,
|
|
@@ -1176,17 +2007,24 @@ var MoonXProvider = ({
|
|
|
1176
2007
|
]
|
|
1177
2008
|
);
|
|
1178
2009
|
const closeLabel = config?.sensitiveModalCopy?.closeLabel ?? "Done";
|
|
1179
|
-
return /* @__PURE__ */ (0,
|
|
2010
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MoonXContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react3.SDKProvider, { value: sdk, children: [
|
|
1180
2011
|
children,
|
|
1181
|
-
/* @__PURE__ */ (0,
|
|
1182
|
-
|
|
2012
|
+
config?.presenceOtpPrompt !== false && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2013
|
+
PresenceOtpPrompt,
|
|
1183
2014
|
{
|
|
1184
|
-
|
|
2015
|
+
publishableKey,
|
|
2016
|
+
options: config?.presenceOtpPrompt
|
|
2017
|
+
}
|
|
2018
|
+
),
|
|
2019
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2020
|
+
import_react_native2.Animated.View,
|
|
2021
|
+
{
|
|
2022
|
+
style: [styles2.backdrop, { opacity: backdropOpacity }],
|
|
1185
2023
|
pointerEvents: webViewVisible ? "auto" : "none",
|
|
1186
|
-
children: /* @__PURE__ */ (0,
|
|
1187
|
-
|
|
2024
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2025
|
+
import_react_native2.Pressable,
|
|
1188
2026
|
{
|
|
1189
|
-
style:
|
|
2027
|
+
style: import_react_native2.StyleSheet.absoluteFill,
|
|
1190
2028
|
onPress: () => {
|
|
1191
2029
|
if (sensitiveVisible) cancelRef.current?.();
|
|
1192
2030
|
}
|
|
@@ -1194,11 +2032,11 @@ var MoonXProvider = ({
|
|
|
1194
2032
|
)
|
|
1195
2033
|
}
|
|
1196
2034
|
),
|
|
1197
|
-
/* @__PURE__ */ (0,
|
|
1198
|
-
|
|
2035
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
2036
|
+
import_react_native2.Animated.View,
|
|
1199
2037
|
{
|
|
1200
2038
|
style: [
|
|
1201
|
-
|
|
2039
|
+
styles2.sheetContainer,
|
|
1202
2040
|
{
|
|
1203
2041
|
top: captchaChallengeVisible ? 0 : SHEET_TOP_OFFSET,
|
|
1204
2042
|
transform: [{ translateY: sheetTranslateY }]
|
|
@@ -1206,44 +2044,48 @@ var MoonXProvider = ({
|
|
|
1206
2044
|
],
|
|
1207
2045
|
pointerEvents: webViewVisible ? "auto" : "none",
|
|
1208
2046
|
children: [
|
|
1209
|
-
sensitiveVisible && /* @__PURE__ */ (0,
|
|
1210
|
-
/* @__PURE__ */ (0,
|
|
1211
|
-
/* @__PURE__ */ (0,
|
|
1212
|
-
/* @__PURE__ */ (0,
|
|
1213
|
-
/* @__PURE__ */ (0,
|
|
1214
|
-
|
|
2047
|
+
sensitiveVisible && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
2048
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.View, { style: styles2.sheetGrabber }),
|
|
2049
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles2.modalChrome, children: [
|
|
2050
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.View, { style: styles2.modalTitleSpacer }),
|
|
2051
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
2052
|
+
import_react_native2.Pressable,
|
|
1215
2053
|
{
|
|
1216
2054
|
onPress: () => cancelRef.current?.(),
|
|
1217
2055
|
hitSlop: 12,
|
|
1218
|
-
style:
|
|
1219
|
-
children: /* @__PURE__ */ (0,
|
|
2056
|
+
style: styles2.closeButton,
|
|
2057
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_react_native2.Text, { style: styles2.closeButtonText, children: closeLabel })
|
|
1220
2058
|
}
|
|
1221
2059
|
)
|
|
1222
2060
|
] })
|
|
1223
2061
|
] }),
|
|
1224
|
-
/* @__PURE__ */ (0,
|
|
2062
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
1225
2063
|
import_react_native_webview.WebView,
|
|
1226
2064
|
{
|
|
1227
2065
|
ref: webViewRef,
|
|
1228
2066
|
source: { uri: initialSourceUri },
|
|
1229
2067
|
onMessage: handleMessage,
|
|
1230
2068
|
onContentProcessDidTerminate: () => {
|
|
2069
|
+
session.setReady(false);
|
|
1231
2070
|
dispatchWebViewLifecycle({ type: "recover", remount: false });
|
|
2071
|
+
sessionResume?.cancelPendingBinds();
|
|
1232
2072
|
bridge.rejectAllPending("webview_process_terminated");
|
|
1233
2073
|
webViewRef.current?.reload();
|
|
1234
2074
|
},
|
|
1235
2075
|
onRenderProcessGone: () => {
|
|
2076
|
+
session.setReady(false);
|
|
1236
2077
|
dispatchWebViewLifecycle({ type: "recover", remount: true });
|
|
2078
|
+
sessionResume?.cancelPendingBinds();
|
|
1237
2079
|
bridge.rejectAllPending("webview_process_terminated");
|
|
1238
2080
|
},
|
|
1239
2081
|
webviewDebuggingEnabled: __DEV__,
|
|
1240
2082
|
javaScriptEnabled: true,
|
|
1241
2083
|
domStorageEnabled: true,
|
|
1242
|
-
sharedCookiesEnabled:
|
|
1243
|
-
thirdPartyCookiesEnabled:
|
|
2084
|
+
sharedCookiesEnabled: import_react_native2.Platform.OS === "ios",
|
|
2085
|
+
thirdPartyCookiesEnabled: import_react_native2.Platform.OS === "android",
|
|
1244
2086
|
startInLoadingState: false,
|
|
1245
2087
|
originWhitelist: ["https://*", "http://*"],
|
|
1246
|
-
style:
|
|
2088
|
+
style: styles2.webView
|
|
1247
2089
|
},
|
|
1248
2090
|
webViewKey
|
|
1249
2091
|
)
|
|
@@ -1253,13 +2095,13 @@ var MoonXProvider = ({
|
|
|
1253
2095
|
] }) });
|
|
1254
2096
|
};
|
|
1255
2097
|
var useMoonXContext = () => {
|
|
1256
|
-
const ctx = (0,
|
|
2098
|
+
const ctx = (0, import_react2.useContext)(MoonXContext);
|
|
1257
2099
|
if (!ctx) {
|
|
1258
2100
|
throw new Error("useMoonX must be used within a MoonXProvider");
|
|
1259
2101
|
}
|
|
1260
2102
|
return ctx;
|
|
1261
2103
|
};
|
|
1262
|
-
var
|
|
2104
|
+
var styles2 = import_react_native2.StyleSheet.create({
|
|
1263
2105
|
backdrop: {
|
|
1264
2106
|
position: "absolute",
|
|
1265
2107
|
top: 0,
|
|
@@ -1309,7 +2151,7 @@ var styles = import_react_native.StyleSheet.create({
|
|
|
1309
2151
|
paddingBottom: 12,
|
|
1310
2152
|
paddingHorizontal: 16,
|
|
1311
2153
|
backgroundColor: "#0a0a0a",
|
|
1312
|
-
borderBottomWidth:
|
|
2154
|
+
borderBottomWidth: import_react_native2.StyleSheet.hairlineWidth,
|
|
1313
2155
|
borderBottomColor: "#222"
|
|
1314
2156
|
},
|
|
1315
2157
|
// Empty flex spacer keeps the close button right-aligned without
|
|
@@ -1331,19 +2173,19 @@ var styles = import_react_native.StyleSheet.create({
|
|
|
1331
2173
|
});
|
|
1332
2174
|
|
|
1333
2175
|
// src/hooks/index.ts
|
|
1334
|
-
var
|
|
2176
|
+
var import_react9 = require("@moon-x/core/react");
|
|
1335
2177
|
|
|
1336
2178
|
// src/hooks/use-app-config.ts
|
|
1337
|
-
var
|
|
1338
|
-
var
|
|
2179
|
+
var import_utils6 = require("@moon-x/core/utils");
|
|
2180
|
+
var import_react4 = require("react");
|
|
1339
2181
|
var useAppConfig = (publishableKey) => {
|
|
1340
2182
|
const { sdk, _bridge } = useMoonXContext();
|
|
1341
2183
|
const resolvedKey = publishableKey ?? sdk.publishableKey;
|
|
1342
2184
|
const ready = sdk.ready;
|
|
1343
|
-
const [appConfig, setAppConfig] = (0,
|
|
1344
|
-
const [isLoading, setIsLoading] = (0,
|
|
1345
|
-
const [error, setError] = (0,
|
|
1346
|
-
(0,
|
|
2185
|
+
const [appConfig, setAppConfig] = (0, import_react4.useState)(null);
|
|
2186
|
+
const [isLoading, setIsLoading] = (0, import_react4.useState)(true);
|
|
2187
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
2188
|
+
(0, import_react4.useEffect)(() => {
|
|
1347
2189
|
if (!resolvedKey) {
|
|
1348
2190
|
setIsLoading(false);
|
|
1349
2191
|
return;
|
|
@@ -1357,7 +2199,7 @@ var useAppConfig = (publishableKey) => {
|
|
|
1357
2199
|
setError(null);
|
|
1358
2200
|
setAppConfig(null);
|
|
1359
2201
|
try {
|
|
1360
|
-
const config = await _bridge.send(
|
|
2202
|
+
const config = await _bridge.send(import_utils6.PostMessageType.AUTH, import_utils6.PostMessageMethod.GET_APP_CONFIG, {
|
|
1361
2203
|
publishableKey: resolvedKey
|
|
1362
2204
|
});
|
|
1363
2205
|
if (!cancelled) setAppConfig(config);
|
|
@@ -1378,8 +2220,8 @@ var useAppConfig = (publishableKey) => {
|
|
|
1378
2220
|
};
|
|
1379
2221
|
|
|
1380
2222
|
// src/hooks/use-attach-oauth.ts
|
|
1381
|
-
var
|
|
1382
|
-
var
|
|
2223
|
+
var import_utils7 = require("@moon-x/core/utils");
|
|
2224
|
+
var import_react5 = require("react");
|
|
1383
2225
|
|
|
1384
2226
|
// src/lib/oauth-deep-link.ts
|
|
1385
2227
|
var openOAuthFlow = async ({
|
|
@@ -1420,7 +2262,7 @@ var parseOAuthRedirect = async (redirectUrl) => {
|
|
|
1420
2262
|
// src/hooks/use-attach-oauth.ts
|
|
1421
2263
|
var useAttachOAuth = (params) => {
|
|
1422
2264
|
const { sdk, _bridge, _oauthRedirectUri } = useMoonXContext();
|
|
1423
|
-
const [state, setState] = (0,
|
|
2265
|
+
const [state, setState] = (0, import_react5.useState)({ status: "idle" });
|
|
1424
2266
|
return {
|
|
1425
2267
|
state,
|
|
1426
2268
|
attachOAuth: async (provider) => {
|
|
@@ -1429,8 +2271,8 @@ var useAttachOAuth = (params) => {
|
|
|
1429
2271
|
const redirectUri = params?.redirectUri || _oauthRedirectUri;
|
|
1430
2272
|
if (!redirectUri) throw new Error("oauth_redirect_uri_missing");
|
|
1431
2273
|
const startResult = await _bridge.send(
|
|
1432
|
-
|
|
1433
|
-
|
|
2274
|
+
import_utils7.PostMessageType.AUTH,
|
|
2275
|
+
import_utils7.PostMessageMethod.START_OAUTH,
|
|
1434
2276
|
{
|
|
1435
2277
|
publishableKey: sdk.publishableKey,
|
|
1436
2278
|
provider,
|
|
@@ -1450,8 +2292,8 @@ var useAttachOAuth = (params) => {
|
|
|
1450
2292
|
if (parsed.error) throw new Error(parsed.error);
|
|
1451
2293
|
setState({ status: "verifying" });
|
|
1452
2294
|
await _bridge.send(
|
|
1453
|
-
|
|
1454
|
-
|
|
2295
|
+
import_utils7.PostMessageType.AUTH,
|
|
2296
|
+
import_utils7.PostMessageMethod.ATTACH_OAUTH,
|
|
1455
2297
|
{
|
|
1456
2298
|
publishableKey: sdk.publishableKey,
|
|
1457
2299
|
provider,
|
|
@@ -1472,14 +2314,14 @@ var useAttachOAuth = (params) => {
|
|
|
1472
2314
|
};
|
|
1473
2315
|
|
|
1474
2316
|
// src/hooks/use-detach-oauth.ts
|
|
1475
|
-
var
|
|
2317
|
+
var import_utils8 = require("@moon-x/core/utils");
|
|
1476
2318
|
var useDetachOAuth = () => {
|
|
1477
2319
|
const { sdk, _bridge } = useMoonXContext();
|
|
1478
2320
|
return {
|
|
1479
2321
|
detachOAuth: async (idpUserId) => {
|
|
1480
2322
|
await _bridge.send(
|
|
1481
|
-
|
|
1482
|
-
|
|
2323
|
+
import_utils8.PostMessageType.AUTH,
|
|
2324
|
+
import_utils8.PostMessageMethod.DETACH_OAUTH,
|
|
1483
2325
|
{ publishableKey: sdk.publishableKey, idpUserId }
|
|
1484
2326
|
);
|
|
1485
2327
|
}
|
|
@@ -1487,8 +2329,8 @@ var useDetachOAuth = () => {
|
|
|
1487
2329
|
};
|
|
1488
2330
|
|
|
1489
2331
|
// src/hooks/use-export-key.ts
|
|
1490
|
-
var
|
|
1491
|
-
var
|
|
2332
|
+
var import_sdk11 = require("@moon-x/core/sdk");
|
|
2333
|
+
var import_utils9 = require("@moon-x/core/utils");
|
|
1492
2334
|
var parseExportKeyResult = (value) => {
|
|
1493
2335
|
if (!value || typeof value !== "object" || !("status" in value)) {
|
|
1494
2336
|
return { status: "failed", error: "invalid_export_key_result" };
|
|
@@ -1507,12 +2349,12 @@ var useExportKey = () => {
|
|
|
1507
2349
|
return {
|
|
1508
2350
|
exportKey: async (wallet) => {
|
|
1509
2351
|
try {
|
|
1510
|
-
const { userHandleB64url, credentialIdB64url, tokens } = await (0,
|
|
2352
|
+
const { userHandleB64url, credentialIdB64url, tokens } = await (0, import_sdk11.getInternalPresenceTokens)({
|
|
1511
2353
|
transport: _bridge,
|
|
1512
2354
|
passkey: createRNPasskey(),
|
|
1513
2355
|
publishableKey: sdk.publishableKey,
|
|
1514
2356
|
relyingPartyOrigin: _relyingPartyOrigin,
|
|
1515
|
-
scopes:
|
|
2357
|
+
scopes: import_sdk11.SCOPES_EXPORT_KEY
|
|
1516
2358
|
});
|
|
1517
2359
|
const keyshareReadToken = tokens.keyshare_read?.token ?? "";
|
|
1518
2360
|
const keyExportToken = tokens.key_export?.token ?? "";
|
|
@@ -1532,8 +2374,8 @@ var useExportKey = () => {
|
|
|
1532
2374
|
title: "Export key",
|
|
1533
2375
|
flowPath: `/export-key?${params.toString()}#${secrets.toString()}`,
|
|
1534
2376
|
onMount: ({ bridge, setResult }) => bridge.register(
|
|
1535
|
-
|
|
1536
|
-
|
|
2377
|
+
import_utils9.PostMessageType.WALLET,
|
|
2378
|
+
import_utils9.PostMessageMethod.EXPORT_KEY_RESULT,
|
|
1537
2379
|
(result) => {
|
|
1538
2380
|
setResult(parseExportKeyResult(result));
|
|
1539
2381
|
}
|
|
@@ -1556,13 +2398,13 @@ var useFundWallet = () => {
|
|
|
1556
2398
|
};
|
|
1557
2399
|
|
|
1558
2400
|
// src/hooks/use-login-with-email.ts
|
|
1559
|
-
var
|
|
1560
|
-
var
|
|
2401
|
+
var import_react6 = require("@moon-x/core/react");
|
|
2402
|
+
var import_react7 = require("react");
|
|
1561
2403
|
var useLoginWithEmail = (callbacks) => {
|
|
1562
|
-
const login = (0,
|
|
2404
|
+
const login = (0, import_react6.useLoginWithEmail)(callbacks);
|
|
1563
2405
|
const { _beginAuthFlow } = useMoonXContext();
|
|
1564
2406
|
const coreLoginWithCode = login.loginWithCode;
|
|
1565
|
-
const loginWithCode = (0,
|
|
2407
|
+
const loginWithCode = (0, import_react7.useCallback)(
|
|
1566
2408
|
async (params) => {
|
|
1567
2409
|
const finishAuthFlow = _beginAuthFlow();
|
|
1568
2410
|
try {
|
|
@@ -1577,56 +2419,77 @@ var useLoginWithEmail = (callbacks) => {
|
|
|
1577
2419
|
};
|
|
1578
2420
|
|
|
1579
2421
|
// src/hooks/use-login-with-oauth.ts
|
|
1580
|
-
var
|
|
1581
|
-
var
|
|
2422
|
+
var import_utils10 = require("@moon-x/core/utils");
|
|
2423
|
+
var import_react8 = require("react");
|
|
1582
2424
|
var useLoginWithOAuth = (params) => {
|
|
1583
2425
|
const { sdk, _bridge, _oauthRedirectUri, _beginAuthFlow } = useMoonXContext();
|
|
1584
|
-
const [state, setState] = (0,
|
|
2426
|
+
const [state, setState] = (0, import_react8.useState)({ status: "idle" });
|
|
2427
|
+
const activeFlow = (0, import_react8.useRef)(null);
|
|
2428
|
+
const mounted = (0, import_react8.useRef)(true);
|
|
2429
|
+
(0, import_react8.useEffect)(() => {
|
|
2430
|
+
mounted.current = true;
|
|
2431
|
+
return () => {
|
|
2432
|
+
mounted.current = false;
|
|
2433
|
+
};
|
|
2434
|
+
}, []);
|
|
1585
2435
|
return {
|
|
1586
2436
|
state,
|
|
1587
2437
|
loginWithOAuth: async (provider) => {
|
|
1588
|
-
const finishAuthFlow = _beginAuthFlow();
|
|
1589
|
-
|
|
2438
|
+
const finishAuthFlow = _beginAuthFlow({ replaceSession: true });
|
|
2439
|
+
const previousFlow = activeFlow.current;
|
|
2440
|
+
activeFlow.current = finishAuthFlow;
|
|
2441
|
+
previousFlow?.();
|
|
2442
|
+
const assertCurrent = () => {
|
|
2443
|
+
if (activeFlow.current !== finishAuthFlow) throw new Error("session_changed");
|
|
2444
|
+
finishAuthFlow.assertCurrent();
|
|
2445
|
+
};
|
|
2446
|
+
const update = (next) => {
|
|
2447
|
+
if (mounted.current && activeFlow.current === finishAuthFlow) setState(next);
|
|
2448
|
+
};
|
|
2449
|
+
update({ status: "starting" });
|
|
1590
2450
|
try {
|
|
1591
2451
|
const redirectUri = params?.redirectUri || _oauthRedirectUri;
|
|
1592
2452
|
if (!redirectUri) {
|
|
1593
2453
|
throw new Error("oauth_redirect_uri_missing");
|
|
1594
2454
|
}
|
|
1595
2455
|
const startResult = await _bridge.send(
|
|
1596
|
-
|
|
1597
|
-
|
|
2456
|
+
import_utils10.PostMessageType.AUTH,
|
|
2457
|
+
import_utils10.PostMessageMethod.START_OAUTH,
|
|
1598
2458
|
{
|
|
1599
2459
|
publishableKey: sdk.publishableKey,
|
|
1600
2460
|
provider,
|
|
1601
2461
|
login_redirect_url: redirectUri
|
|
1602
2462
|
}
|
|
1603
2463
|
);
|
|
2464
|
+
assertCurrent();
|
|
1604
2465
|
if (!startResult.redirect_url) {
|
|
1605
2466
|
throw new Error("start_oauth_failed");
|
|
1606
2467
|
}
|
|
1607
|
-
|
|
2468
|
+
update({ status: "redirecting" });
|
|
1608
2469
|
const { redirectUrl } = await openOAuthFlow({
|
|
1609
2470
|
authUrl: startResult.redirect_url,
|
|
1610
2471
|
redirectUri
|
|
1611
2472
|
});
|
|
1612
2473
|
const parsed = await parseOAuthRedirect(redirectUrl);
|
|
2474
|
+
assertCurrent();
|
|
1613
2475
|
if (parsed.error) throw new Error(parsed.error);
|
|
1614
2476
|
if (!parsed.code && !parsed.token) {
|
|
1615
2477
|
throw new Error("oauth_no_code_or_token");
|
|
1616
2478
|
}
|
|
1617
|
-
|
|
2479
|
+
update({ status: "verifying" });
|
|
1618
2480
|
const result = await sdk.verifyOAuth({
|
|
1619
2481
|
provider,
|
|
1620
2482
|
code: parsed.code,
|
|
1621
2483
|
token: parsed.token,
|
|
1622
2484
|
state: parsed.state
|
|
1623
2485
|
});
|
|
1624
|
-
|
|
2486
|
+
update({ status: "complete", user: result?.user ?? result ?? null });
|
|
1625
2487
|
} catch (e) {
|
|
1626
2488
|
const err = e instanceof Error ? e : new Error(String(e));
|
|
1627
|
-
|
|
2489
|
+
update({ status: "error", error: err });
|
|
1628
2490
|
throw err;
|
|
1629
2491
|
} finally {
|
|
2492
|
+
if (activeFlow.current === finishAuthFlow) activeFlow.current = null;
|
|
1630
2493
|
finishAuthFlow();
|
|
1631
2494
|
}
|
|
1632
2495
|
},
|
|
@@ -1638,17 +2501,17 @@ var useLoginWithOAuth = (params) => {
|
|
|
1638
2501
|
var useMoonX = () => useMoonXContext().sdk;
|
|
1639
2502
|
|
|
1640
2503
|
// src/external-wallets/use-external-wallets.ts
|
|
1641
|
-
var
|
|
2504
|
+
var import_react10 = require("react");
|
|
1642
2505
|
var useExternalWallets = (connectors) => {
|
|
1643
|
-
const [wallets, setWallets] = (0,
|
|
1644
|
-
const [connected, setConnected] = (0,
|
|
2506
|
+
const [wallets, setWallets] = (0, import_react10.useState)([]);
|
|
2507
|
+
const [connected, setConnected] = (0, import_react10.useState)(
|
|
1645
2508
|
null
|
|
1646
2509
|
);
|
|
1647
|
-
const [status, setStatus] = (0,
|
|
1648
|
-
const [error, setError] = (0,
|
|
1649
|
-
const [refreshNonce, setRefreshNonce] = (0,
|
|
1650
|
-
const unsubscribeRef = (0,
|
|
1651
|
-
(0,
|
|
2510
|
+
const [status, setStatus] = (0, import_react10.useState)("idle");
|
|
2511
|
+
const [error, setError] = (0, import_react10.useState)(null);
|
|
2512
|
+
const [refreshNonce, setRefreshNonce] = (0, import_react10.useState)(0);
|
|
2513
|
+
const unsubscribeRef = (0, import_react10.useRef)(null);
|
|
2514
|
+
(0, import_react10.useEffect)(() => {
|
|
1652
2515
|
let cancelled = false;
|
|
1653
2516
|
void Promise.all(
|
|
1654
2517
|
connectors.map(async (connector) => ({
|
|
@@ -1662,13 +2525,13 @@ var useExternalWallets = (connectors) => {
|
|
|
1662
2525
|
cancelled = true;
|
|
1663
2526
|
};
|
|
1664
2527
|
}, [connectors, refreshNonce]);
|
|
1665
|
-
(0,
|
|
2528
|
+
(0, import_react10.useEffect)(
|
|
1666
2529
|
() => () => {
|
|
1667
2530
|
unsubscribeRef.current?.();
|
|
1668
2531
|
},
|
|
1669
2532
|
[]
|
|
1670
2533
|
);
|
|
1671
|
-
const connect = (0,
|
|
2534
|
+
const connect = (0, import_react10.useCallback)(
|
|
1672
2535
|
async (id) => {
|
|
1673
2536
|
const connector = connectors.find((candidate) => candidate.info.id === id);
|
|
1674
2537
|
if (!connector) throw new Error(`External wallet "${id}" not found`);
|
|
@@ -1699,7 +2562,7 @@ var useExternalWallets = (connectors) => {
|
|
|
1699
2562
|
},
|
|
1700
2563
|
[connectors]
|
|
1701
2564
|
);
|
|
1702
|
-
const switchAccount = (0,
|
|
2565
|
+
const switchAccount = (0, import_react10.useCallback)(
|
|
1703
2566
|
async (address, chainId) => {
|
|
1704
2567
|
if (!connected) throw new Error("No external wallet connected");
|
|
1705
2568
|
const activeAccount = await connected.switchAccount(address, chainId);
|
|
@@ -1709,7 +2572,7 @@ var useExternalWallets = (connectors) => {
|
|
|
1709
2572
|
},
|
|
1710
2573
|
[connected]
|
|
1711
2574
|
);
|
|
1712
|
-
const disconnect = (0,
|
|
2575
|
+
const disconnect = (0, import_react10.useCallback)(async () => {
|
|
1713
2576
|
try {
|
|
1714
2577
|
await connected?.disconnect();
|
|
1715
2578
|
} finally {
|
|
@@ -1995,9 +2858,9 @@ var restoreWalletConnectSession = (options) => {
|
|
|
1995
2858
|
};
|
|
1996
2859
|
|
|
1997
2860
|
// src/index.ts
|
|
1998
|
-
var
|
|
1999
|
-
var
|
|
2000
|
-
var
|
|
2861
|
+
var import_sdk12 = require("@moon-x/core/sdk");
|
|
2862
|
+
var import_sdk13 = require("@moon-x/core/sdk");
|
|
2863
|
+
var import_utils11 = require("@moon-x/core/utils");
|
|
2001
2864
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2002
2865
|
0 && (module.exports = {
|
|
2003
2866
|
MOONPAY_CONSUMER_SESSION_ERROR_CODES,
|