@moon-x/react-sdk 0.1.0 → 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.mjs CHANGED
@@ -837,6 +837,7 @@ var useMoonKey = function useMoonKey() {
837
837
  status: "start"
838
838
  },
839
839
  getSessionTokens: coreSDK.getSessionTokens,
840
+ getPresenceToken: coreSDK.getPresenceToken,
840
841
  start: coreSDK.start || function() {
841
842
  return Promise.resolve(null);
842
843
  },
@@ -849,7 +850,7 @@ var useMoonKey = function useMoonKey() {
849
850
  };
850
851
  };
851
852
  // src/components/auth-provider.tsx
852
- import { getIframeOrigin as getIframeOrigin2, getIframeUrl as getIframeUrl3, PostMessageClient as PostMessageClient10, PostMessageMethod as PostMessageMethod28, PostMessageType as PostMessageType29 } from "@moon-x/core/utils";
853
+ import { getIframeOrigin as getIframeOrigin2, getIframeUrl as getIframeUrl3, PostMessageClient as PostMessageClient10, PostMessageMethod as PostMessageMethod27, PostMessageType as PostMessageType28 } from "@moon-x/core/utils";
853
854
  import { useCallback as useCallback11, useEffect as useEffect34, useMemo as useMemo4, useRef as useRef18, useState as useState51 } from "react";
854
855
  import { createPortal as createPortal2 } from "react-dom";
855
856
  // src/hooks/use-close-iframe.ts
@@ -885,13 +886,13 @@ var createPostMessageClient = function createPostMessageClient(contentWindow, _p
885
886
  };
886
887
  // src/hooks/use-oauth-callback-detection.ts
887
888
  var useOAuthCallbackDetection = function useOAuthCallbackDetection(param) {
888
- var isMounted = param.isMounted, isReady = param.isReady, publishableKey = param.publishableKey, iframeRef = param.iframeRef, onOAuthSuccess = param.onOAuthSuccess, onOAuthError = param.onOAuthError, setCurrentFlow = param.setCurrentFlow, setFlowData = param.setFlowData, setStartFlow = param.setStartFlow;
889
+ var isMounted = param.isMounted, isIframeReady = param.isIframeReady, publishableKey = param.publishableKey, iframeRef = param.iframeRef, onOAuthSuccess = param.onOAuthSuccess, onOAuthError = param.onOAuthError, setCurrentFlow = param.setCurrentFlow, setFlowData = param.setFlowData, setStartFlow = param.setStartFlow;
889
890
  if (typeof window === "undefined") {
890
891
  return;
891
892
  }
892
893
  useEffect4(function() {
893
894
  if (typeof window === "undefined") return;
894
- if (!isMounted || !isReady) return;
895
+ if (!isMounted || !isIframeReady) return;
895
896
  var checkForOAuthCallback = function checkForOAuthCallback() {
896
897
  if (typeof window === "undefined") return;
897
898
  try {
@@ -903,7 +904,7 @@ var useOAuthCallbackDetection = function useOAuthCallbackDetection(param) {
903
904
  token: token
904
905
  });
905
906
  setStartFlow === null || setStartFlow === void 0 ? void 0 : setStartFlow(true);
906
- setTimeout(function() {
907
+ void function() {
907
908
  return _async_to_generator(function() {
908
909
  var _iframeRef_current, client, error;
909
910
  return _ts_generator(this, function(_state) {
@@ -950,7 +951,7 @@ var useOAuthCallbackDetection = function useOAuthCallbackDetection(param) {
950
951
  }
951
952
  });
952
953
  })();
953
- }, 1500);
954
+ }();
954
955
  try {
955
956
  var newUrl = new URL(window.location.href);
956
957
  newUrl.searchParams.delete("token");
@@ -970,7 +971,7 @@ var useOAuthCallbackDetection = function useOAuthCallbackDetection(param) {
970
971
  };
971
972
  }, [
972
973
  isMounted,
973
- isReady,
974
+ isIframeReady,
974
975
  publishableKey,
975
976
  iframeRef,
976
977
  onOAuthSuccess,
@@ -1411,7 +1412,7 @@ var getEthereumSDKMethods = function getEthereumSDKMethods(publishableKey, getIs
1411
1412
  // src/sdk/sdk-methods.ts
1412
1413
  import { PostMessageMethod as PostMessageMethod6, PostMessageType as PostMessageType7 } from "@moon-x/core/utils";
1413
1414
  import { clearParentAssertCache } from "@moon-x/core/lib";
1414
- import { getHeadlessGeneralMethods } from "@moon-x/core/sdk";
1415
+ import { getHeadlessGeneralMethods, getPresenceToken as headlessGetPresenceToken } from "@moon-x/core/sdk";
1415
1416
  import { createIframeTransport as createIframeTransport3, createLocalStorageKv, createWebAuthnPasskey as createWebAuthnPasskey2 } from "@moon-x/core/web";
1416
1417
  import { authState as authState2 } from "@moon-x/core/lib";
1417
1418
  // src/sdk/sdk-authentication-methods.ts
@@ -1419,7 +1420,7 @@ import { PostMessageMethod as PostMessageMethod5, PostMessageType as PostMessage
1419
1420
  import { getHeadlessAuthenticationMethods } from "@moon-x/core/sdk";
1420
1421
  import { createIframeTransport as createIframeTransport2 } from "@moon-x/core/web";
1421
1422
  import { authState } from "@moon-x/core/lib";
1422
- var getAuthenticationMethods = function getAuthenticationMethods(publishableKey, isMounted, getIsReady, iframeRef, setFlowState, emailConfig, setIsAuthenticated, setUser) {
1423
+ var getAuthenticationMethods = function getAuthenticationMethods(publishableKey, isMounted, getIsReady, iframeRef, setFlowState, setIsAuthenticated, setUser) {
1423
1424
  var transport = createIframeTransport2({
1424
1425
  getContentWindow: function getContentWindow() {
1425
1426
  var _ref;
@@ -1434,7 +1435,6 @@ var getAuthenticationMethods = function getAuthenticationMethods(publishableKey,
1434
1435
  var headless = getHeadlessAuthenticationMethods({
1435
1436
  transport: transport,
1436
1437
  publishableKey: publishableKey,
1437
- emailConfig: emailConfig,
1438
1438
  setIsAuthenticated: setIsAuthenticated,
1439
1439
  setUser: setUser
1440
1440
  });
@@ -1443,12 +1443,12 @@ var getAuthenticationMethods = function getAuthenticationMethods(publishableKey,
1443
1443
  * Send a one-time passcode to the user's email address. Wraps the
1444
1444
  * shared headless `sendCode` with web's setFlowState lifecycle so
1445
1445
  * the email-otp-verify modal can render loading/error/waiting-code
1446
- * states. Same status names the global machine has used since
1447
- * before the refactor (for back-compat with `useMoonKey().flowState`
1448
- * consumers that haven't migrated to the local-state `useLoginWithEmail`).
1446
+ * states. Returns the platform response (including the authoritative
1447
+ * `expires_at` unix timestamp) so headless consumers can render an
1448
+ * accurate countdown without making it up.
1449
1449
  */ sendCode: function sendCode(params) {
1450
1450
  return _async_to_generator(function() {
1451
- var _iframeRef_current, error, errorObj;
1451
+ var _iframeRef_current, response, error, errorObj;
1452
1452
  return _ts_generator(this, function(_state) {
1453
1453
  switch(_state.label){
1454
1454
  case 0:
@@ -1480,13 +1480,13 @@ var getAuthenticationMethods = function getAuthenticationMethods(publishableKey,
1480
1480
  headless.sendCode(params)
1481
1481
  ];
1482
1482
  case 2:
1483
- _state.sent();
1483
+ response = _state.sent();
1484
1484
  setFlowState({
1485
1485
  status: "waiting-code-input"
1486
1486
  });
1487
1487
  return [
1488
- 3,
1489
- 4
1488
+ 2,
1489
+ response
1490
1490
  ];
1491
1491
  case 3:
1492
1492
  error = _state.sent();
@@ -1778,7 +1778,7 @@ var getAuthenticationMethods = function getAuthenticationMethods(publishableKey,
1778
1778
  };
1779
1779
  };
1780
1780
  // src/sdk/sdk-methods.ts
1781
- var getSDKMethods = function getSDKMethods(publishableKey, isMounted, getIsReady, iframeRef, setCurrentFlow, setFlowData, setStartFlow, setFlowState, emailConfig, setIsAuthenticated, setUser, closeCallbackRef) {
1781
+ var getSDKMethods = function getSDKMethods(publishableKey, isMounted, getIsReady, iframeRef, setCurrentFlow, setFlowData, setStartFlow, setFlowState, setIsAuthenticated, setUser, closeCallbackRef) {
1782
1782
  var transport = createIframeTransport3({
1783
1783
  getContentWindow: function getContentWindow() {
1784
1784
  var _ref;
@@ -1800,7 +1800,7 @@ var getSDKMethods = function getSDKMethods(publishableKey, isMounted, getIsReady
1800
1800
  setIsAuthenticated: setIsAuthenticated,
1801
1801
  setUser: setUser
1802
1802
  });
1803
- return _object_spread_props(_object_spread({}, getAuthenticationMethods(publishableKey, isMounted, getIsReady, iframeRef, setFlowState, emailConfig, setIsAuthenticated, setUser), headless), {
1803
+ return _object_spread_props(_object_spread({}, getAuthenticationMethods(publishableKey, isMounted, getIsReady, iframeRef, setFlowState, setIsAuthenticated, setUser), headless), {
1804
1804
  // Web override: logout must also reset the modal state machine
1805
1805
  // (`setCurrentFlow` / `setFlowData` / `setStartFlow`) AND clear the
1806
1806
  // localStorage id-token (idTokenStorage). The shared logout already
@@ -1873,6 +1873,35 @@ var getSDKMethods = function getSDKMethods(publishableKey, isMounted, getIsReady
1873
1873
  addPasskey: function addPasskey(_params) {
1874
1874
  return Promise.reject(new Error("addPasskey not initialized"));
1875
1875
  },
1876
+ // getPresenceToken: parent-side passkey step-up ceremony. Returns a
1877
+ // short-lived JWT (tt:"presence") that customer backends verify via
1878
+ // the app's JWKS to gate high-risk routes without rolling their own
1879
+ // session/step-up model. Must be invoked from inside a click handler so
1880
+ // transient activation is alive when WebAuthn fires.
1881
+ //
1882
+ // The strip of `response.userHandle` happens INSIDE getPresenceToken
1883
+ // (parent boundary, before iframe roundtrip). DEK material never
1884
+ // crosses the iframe → server boundary.
1885
+ getPresenceToken: function getPresenceToken() {
1886
+ return _async_to_generator(function() {
1887
+ var _iframeRef_current;
1888
+ return _ts_generator(this, function(_state) {
1889
+ if (!isMounted) throw new Error("SDK not ready");
1890
+ if (!getIsReady() || !((_iframeRef_current = iframeRef.current) === null || _iframeRef_current === void 0 ? void 0 : _iframeRef_current.contentWindow)) {
1891
+ throw new Error("SDK not ready");
1892
+ }
1893
+ return [
1894
+ 2,
1895
+ headlessGetPresenceToken({
1896
+ transport: transport,
1897
+ passkey: passkey,
1898
+ publishableKey: publishableKey,
1899
+ relyingPartyOrigin: window.location.origin
1900
+ })
1901
+ ];
1902
+ });
1903
+ })();
1904
+ },
1876
1905
  // hide: web-only — closes the parent-side modal. No shared analogue.
1877
1906
  hide: function hide() {
1878
1907
  if (!isMounted) return;
@@ -2424,7 +2453,7 @@ var createSDKInstance = function createSDKInstance(publishableKey, isMounted, is
2424
2453
  },
2425
2454
  onError: onError,
2426
2455
  onClose: onClose
2427
- }, getSDKMethods(publishableKey, isMounted, getCurrentIsReady, iframeRef, setCurrentFlow, setFlowData, setStartFlow, setFlowState, authProviderConfig === null || authProviderConfig === void 0 ? void 0 : authProviderConfig.emailConfig, setIsAuthenticated, setUser, closeCallbacksRef), getPasskeyMethods({
2456
+ }, getSDKMethods(publishableKey, isMounted, getCurrentIsReady, iframeRef, setCurrentFlow, setFlowData, setStartFlow, setFlowState, setIsAuthenticated, setUser, closeCallbacksRef), getPasskeyMethods({
2428
2457
  isMounted: isMounted,
2429
2458
  getIsReady: getCurrentIsReady,
2430
2459
  iframeRef: iframeRef,
@@ -2605,6 +2634,8 @@ var getWalletErrorMessage = function getWalletErrorMessage(errorResponse) {
2605
2634
  };
2606
2635
  // src/components/flows/add-passkey/add-passkey.tsx
2607
2636
  import { PostMessageMethod as PostMessageMethod11, PostMessageType as PostMessageType12 } from "@moon-x/core/utils";
2637
+ import { assertPasskeyInParent as assertPasskeyInParent4 } from "@moon-x/core/sdk";
2638
+ import { createWebAuthnPasskey as createWebAuthnPasskey5 } from "@moon-x/core/web";
2608
2639
  import { startRegistration } from "@simplewebauthn/browser";
2609
2640
  import { CheckCircle2, Fingerprint, KeyRound, Plus } from "lucide-react";
2610
2641
  import { useRef as useRef4, useState as useState11 } from "react";
@@ -2613,6 +2644,7 @@ import { PostMessageMethod as PostMessageMethod10, PostMessageType as PostMessag
2613
2644
  import { useEffect as useEffect5, useState as useState5 } from "react";
2614
2645
  // src/lib/iframe.ts
2615
2646
  import { PostMessageClient, PostMessageMethod as PostMessageMethod9, PostMessageType as PostMessageType10, getIframeOrigin, getIframeUrl } from "@moon-x/core";
2647
+ import { createIframeTransport as createIframeTransport6 } from "@moon-x/core/web";
2616
2648
  var getIframeClient = function getIframeClient(publishableKey) {
2617
2649
  var iframeId = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "moonkey-auth-iframe";
2618
2650
  var iframe = document.getElementById(iframeId);
@@ -2623,6 +2655,20 @@ var getIframeClient = function getIframeClient(publishableKey) {
2623
2655
  var iframeOrigin = getIframeOrigin(iframeUrl);
2624
2656
  return new PostMessageClient(iframe.contentWindow, iframeOrigin);
2625
2657
  };
2658
+ var getIframeTransport = function getIframeTransport() {
2659
+ var iframeId = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "moonkey-auth-iframe";
2660
+ return createIframeTransport6({
2661
+ getContentWindow: function getContentWindow() {
2662
+ var _ref;
2663
+ var iframe = document.getElementById(iframeId);
2664
+ return (_ref = iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow) !== null && _ref !== void 0 ? _ref : null;
2665
+ },
2666
+ isReady: function isReady() {
2667
+ var iframe = document.getElementById(iframeId);
2668
+ return !!(iframe === null || iframe === void 0 ? void 0 : iframe.contentWindow);
2669
+ }
2670
+ });
2671
+ };
2626
2672
  var closeIframe = function closeIframe(publishableKey) {
2627
2673
  var iframe = getIframeClient(publishableKey);
2628
2674
  if (!iframe) {
@@ -3638,14 +3684,50 @@ function AddressPill(param) {
3638
3684
  });
3639
3685
  }
3640
3686
  // src/components/vanilla-ui/error-box.tsx
3687
+ import { AlertCircle } from "lucide-react";
3641
3688
  import { jsx as jsx11, jsxs as jsxs7 } from "react/jsx-runtime";
3642
3689
  function ErrorBox(param) {
3643
- var children = param.children, icon = param.icon, className = param.className, style = param.style;
3644
- return /* @__PURE__ */ jsxs7("div", {
3690
+ var children = param.children, icon = param.icon, _param_variant = param.variant, variant = _param_variant === void 0 ? "boxed" : _param_variant, align = param.align, className = param.className, style = param.style;
3691
+ var a11yProps = {
3692
+ role: "alert",
3693
+ "aria-live": "polite"
3694
+ };
3695
+ if (variant === "inline") {
3696
+ var resolvedAlign = align !== null && align !== void 0 ? align : "left";
3697
+ var resolvedIcon = icon === null ? null : icon !== null && icon !== void 0 ? icon : /* @__PURE__ */ jsx11(AlertCircle, {
3698
+ size: 14,
3699
+ strokeWidth: 2,
3700
+ style: {
3701
+ flexShrink: 0
3702
+ },
3703
+ "aria-hidden": "true"
3704
+ });
3705
+ return /* @__PURE__ */ jsxs7("div", _object_spread_props(_object_spread({}, a11yProps), {
3706
+ className: cx("moonkey-text--error", className),
3707
+ style: _object_spread({
3708
+ fontSize: "0.875rem",
3709
+ color: "var(--moonkey-color-error)",
3710
+ textAlign: resolvedAlign,
3711
+ display: "flex",
3712
+ alignItems: "center",
3713
+ gap: "0.375rem"
3714
+ }, resolvedAlign === "center" && {
3715
+ justifyContent: "center"
3716
+ }, style),
3717
+ children: [
3718
+ resolvedIcon,
3719
+ /* @__PURE__ */ jsx11("span", {
3720
+ children: children
3721
+ })
3722
+ ]
3723
+ }));
3724
+ }
3725
+ return /* @__PURE__ */ jsxs7("div", _object_spread_props(_object_spread({}, a11yProps), {
3645
3726
  className: cx("moonkey-box moonkey-box--warning", className),
3646
3727
  style: style,
3647
3728
  children: [
3648
3729
  icon && /* @__PURE__ */ jsx11("span", {
3730
+ "aria-hidden": "true",
3649
3731
  style: {
3650
3732
  flexShrink: 0,
3651
3733
  marginTop: "0.125rem",
@@ -3656,14 +3738,17 @@ function ErrorBox(param) {
3656
3738
  children: icon
3657
3739
  }),
3658
3740
  /* @__PURE__ */ jsx11("span", {
3659
- style: {
3741
+ style: _object_spread({
3660
3742
  fontSize: "0.875rem",
3661
3743
  color: "var(--moonkey-color-error)"
3662
- },
3744
+ }, align === "center" && {
3745
+ textAlign: "center",
3746
+ flex: 1
3747
+ }),
3663
3748
  children: children
3664
3749
  })
3665
3750
  ]
3666
- });
3751
+ }));
3667
3752
  }
3668
3753
  // src/components/vanilla-ui/success-box.tsx
3669
3754
  import { jsx as jsx12, jsxs as jsxs8 } from "react/jsx-runtime";
@@ -3778,77 +3863,42 @@ var AddPasskey = function AddPasskey(param) {
3778
3863
  };
3779
3864
  var handleUnlock = function handleUnlock() {
3780
3865
  return _async_to_generator(function() {
3781
- var client, _dekInfo_allow_credential_ids_b64url, dekInfo, allowList, challenge, credential, assertion, credentialIdB64url, error;
3866
+ var _ref, userHandleB64url, credentialIdB64url, error;
3782
3867
  return _ts_generator(this, function(_state) {
3783
3868
  switch(_state.label){
3784
3869
  case 0:
3785
3870
  setErrorMessage(null);
3786
3871
  setStep("unlocking");
3787
- client = getIframeClient(publishableKey);
3788
- if (!client) {
3789
- setErrorMessage("SDK not initialized");
3790
- setStep("error");
3791
- return [
3792
- 2
3793
- ];
3794
- }
3795
3872
  _state.label = 1;
3796
3873
  case 1:
3797
3874
  _state.trys.push([
3798
3875
  1,
3799
- 4,
3876
+ 3,
3800
3877
  ,
3801
- 5
3878
+ 4
3802
3879
  ]);
3803
3880
  return [
3804
3881
  4,
3805
- client.send(PostMessageType12.AUTH, PostMessageMethod11.GET_DEK_INFO, {
3806
- publishableKey: publishableKey
3882
+ assertPasskeyInParent4({
3883
+ transport: getIframeTransport(),
3884
+ passkey: createWebAuthnPasskey5(),
3885
+ publishableKey: publishableKey,
3886
+ requireFreshAssertion: true,
3887
+ validateCredentialInAllowList: true
3807
3888
  })
3808
3889
  ];
3809
3890
  case 2:
3810
- dekInfo = _state.sent();
3811
- allowList = (_dekInfo_allow_credential_ids_b64url = dekInfo.allow_credential_ids_b64url) !== null && _dekInfo_allow_credential_ids_b64url !== void 0 ? _dekInfo_allow_credential_ids_b64url : [];
3812
- if (allowList.length === 0) {
3813
- throw new Error("passkey_required");
3814
- }
3815
- if (!dekInfo.rp_id) {
3816
- throw new Error("webauthn_rp_id_not_configured");
3817
- }
3818
- challenge = crypto.getRandomValues(new Uint8Array(32));
3819
- return [
3820
- 4,
3821
- navigator.credentials.get({
3822
- publicKey: {
3823
- challenge: challenge,
3824
- // Configured `webauthn.rp_id` (apex), not the page hostname,
3825
- // so credentials registered under the apex are surfaced even
3826
- // when the SDK is running on a subdomain.
3827
- rpId: dekInfo.rp_id,
3828
- userVerification: "preferred",
3829
- allowCredentials: []
3830
- }
3831
- })
3832
- ];
3833
- case 3:
3834
- credential = _state.sent();
3835
- if (!credential) throw new Error("passkey_assertion_cancelled");
3836
- assertion = credential.response;
3837
- if (!assertion.userHandle) throw new Error("user_handle_missing");
3838
- credentialIdB64url = bytesToB64url(new Uint8Array(credential.rawId));
3839
- if (!allowList.includes(credentialIdB64url)) {
3840
- throw new Error("unknown_passkey_for_this_account");
3841
- }
3891
+ _ref = _state.sent(), userHandleB64url = _ref.userHandleB64url, credentialIdB64url = _ref.credentialIdB64url;
3842
3892
  unlockResult.current = {
3843
- userHandleB64url: bytesToB64url(new Uint8Array(assertion.userHandle)),
3893
+ userHandleB64url: userHandleB64url,
3844
3894
  credentialIdB64url: credentialIdB64url
3845
3895
  };
3846
3896
  setStep("enroll-prompt");
3847
3897
  return [
3848
3898
  3,
3849
- 5
3899
+ 4
3850
3900
  ];
3851
- case 4:
3901
+ case 3:
3852
3902
  error = _state.sent();
3853
3903
  setStep("error");
3854
3904
  if (_instanceof(error, Error)) {
@@ -3864,9 +3914,9 @@ var AddPasskey = function AddPasskey(param) {
3864
3914
  }
3865
3915
  return [
3866
3916
  3,
3867
- 5
3917
+ 4
3868
3918
  ];
3869
- case 5:
3919
+ case 4:
3870
3920
  return [
3871
3921
  2
3872
3922
  ];
@@ -4256,7 +4306,7 @@ var formatCurrency = function formatCurrency(value) {
4256
4306
  // src/components/flows/email-otp-flow/email-otp-input.tsx
4257
4307
  import { Fragment as Fragment2, jsx as jsx17, jsxs as jsxs11 } from "react/jsx-runtime";
4258
4308
  var EmailOtpInput = function EmailOtpInput(param) {
4259
- var publishableKey = param.publishableKey, expiresIn = param.expiresIn, prefillEmail = param.prefillEmail, onSuccess = param.onSuccess, onError = param.onError;
4309
+ var publishableKey = param.publishableKey, prefillEmail = param.prefillEmail, onSuccess = param.onSuccess, onError = param.onError;
4260
4310
  var _useState12 = _sliced_to_array(useState12(false), 2), isProcessing = _useState12[0], setIsProcessing = _useState12[1];
4261
4311
  var _useState121 = _sliced_to_array(useState12(prefillEmail || ""), 2), email = _useState121[0], setEmail = _useState121[1];
4262
4312
  var _useState122 = _sliced_to_array(useState12(false), 2), hasPrefetched = _useState122[0], setHasPrefetched = _useState122[1];
@@ -4291,13 +4341,12 @@ var EmailOtpInput = function EmailOtpInput(param) {
4291
4341
  };
4292
4342
  var handleEmailSubmit = function handleEmailSubmit() {
4293
4343
  return _async_to_generator(function() {
4294
- var client, error;
4344
+ var client, response, error, errorObj;
4295
4345
  return _ts_generator(this, function(_state) {
4296
4346
  switch(_state.label){
4297
4347
  case 0:
4298
4348
  if (!isEmailValid) return [
4299
- 3,
4300
- 4
4349
+ 2
4301
4350
  ];
4302
4351
  setIsProcessing(true);
4303
4352
  _state.label = 1;
@@ -4305,8 +4354,8 @@ var EmailOtpInput = function EmailOtpInput(param) {
4305
4354
  _state.trys.push([
4306
4355
  1,
4307
4356
  3,
4308
- ,
4309
- 4
4357
+ 4,
4358
+ 5
4310
4359
  ]);
4311
4360
  client = getIframeClient(publishableKey);
4312
4361
  if (!client) {
@@ -4319,27 +4368,34 @@ var EmailOtpInput = function EmailOtpInput(param) {
4319
4368
  4,
4320
4369
  client.send(PostMessageType13.AUTH, PostMessageMethod12.LOGIN_CREATE, {
4321
4370
  publishableKey: publishableKey,
4322
- email: email,
4323
- expiresIn: expiresIn
4371
+ email: email
4324
4372
  })
4325
4373
  ];
4326
4374
  case 2:
4327
- _state.sent();
4328
- onSuccess(email);
4375
+ response = _state.sent();
4376
+ onSuccess({
4377
+ email: email,
4378
+ expires_at: response === null || response === void 0 ? void 0 : response.expires_at
4379
+ });
4329
4380
  return [
4330
4381
  3,
4331
- 4
4382
+ 5
4332
4383
  ];
4333
4384
  case 3:
4334
4385
  error = _state.sent();
4335
4386
  console.error("Failed to send OTP:", error);
4336
- setIsProcessing(false);
4337
- onError(error);
4387
+ errorObj = _instanceof(error, Error) ? error : new Error(String(error));
4388
+ onError(errorObj);
4338
4389
  return [
4339
4390
  3,
4340
- 4
4391
+ 5
4341
4392
  ];
4342
4393
  case 4:
4394
+ setIsProcessing(false);
4395
+ return [
4396
+ 7
4397
+ ];
4398
+ case 5:
4343
4399
  return [
4344
4400
  2
4345
4401
  ];
@@ -4760,16 +4816,17 @@ var i18n_default = i18n;
4760
4816
  // src/components/flows/email-otp-flow/email-otp-verify.tsx
4761
4817
  import { Fragment as Fragment3, jsx as jsx18, jsxs as jsxs12 } from "react/jsx-runtime";
4762
4818
  var EmailOtpVerify = function EmailOtpVerify(param) {
4763
- var config = param.config, publishableKey = param.publishableKey, language = param.language, expiresIn = param.expiresIn, emailOtpSendResponse = param.emailOtpSendResponse, onSuccess = param.onSuccess, onBackPress = param.onBackPress, onFlowStateChange = param.onFlowStateChange, propsIsDark = param.isDark;
4819
+ var config = param.config, publishableKey = param.publishableKey, language = param.language, emailOtpSendResponse = param.emailOtpSendResponse, onSuccess = param.onSuccess, onBackPress = param.onBackPress, onFlowStateChange = param.onFlowStateChange, propsIsDark = param.isDark;
4764
4820
  var _ref;
4765
4821
  var _config_config, _config_config_appearance, _config_config1, _config_config_appearance1, _config_config2, _config_config3, _config_config4, _config_config_emailConfig, _config_config5, _config_config_emailConfig1, _config_config6;
4766
4822
  var _useState13 = _sliced_to_array(useState13(""), 2), otp = _useState13[0], setOtp = _useState13[1];
4767
4823
  var _useState131 = _sliced_to_array(useState13(false), 2), isLoading = _useState131[0], setIsLoading = _useState131[1];
4768
4824
  var _useState132 = _sliced_to_array(useState13(false), 2), isResending = _useState132[0], setIsResending = _useState132[1];
4769
- var _useState133 = _sliced_to_array(useState13(expiresIn !== null && expiresIn !== void 0 ? expiresIn : DEFAULT_COUNTDOWN_TIME), 2), countdown = _useState133[0], setCountdown = _useState133[1];
4770
- var _useState134 = _sliced_to_array(useState13(false), 2), canResend = _useState134[0], setCanResend = _useState134[1];
4825
+ var _useState133 = _sliced_to_array(useState13(false), 2), canResend = _useState133[0], setCanResend = _useState133[1];
4826
+ var _useState134 = _sliced_to_array(useState13(0), 2), resendCooldownEpoch = _useState134[0], setResendCooldownEpoch = _useState134[1];
4771
4827
  var _useState135 = _sliced_to_array(useState13("idle"), 2), validationState = _useState135[0], setValidationState = _useState135[1];
4772
4828
  var _useState136 = _sliced_to_array(useState13(""), 2), errorMessage = _useState136[0], setErrorMessage = _useState136[1];
4829
+ var _useState137 = _sliced_to_array(useState13(null), 2), resendError = _useState137[0], setResendError = _useState137[1];
4773
4830
  var t = useTranslation().t;
4774
4831
  var isDark = propsIsDark !== void 0 ? propsIsDark : isDarkMode(config === null || config === void 0 ? void 0 : (_config_config = config.config) === null || _config_config === void 0 ? void 0 : _config_config.theme, config === null || config === void 0 ? void 0 : (_config_config1 = config.config) === null || _config_config1 === void 0 ? void 0 : (_config_config_appearance = _config_config1.appearance) === null || _config_config_appearance === void 0 ? void 0 : _config_config_appearance.displayMode, config === null || config === void 0 ? void 0 : (_config_config2 = config.config) === null || _config_config2 === void 0 ? void 0 : (_config_config_appearance1 = _config_config2.appearance) === null || _config_config_appearance1 === void 0 ? void 0 : _config_config_appearance1.backgroundColor);
4775
4832
  useEffect9(function() {
@@ -4779,39 +4836,20 @@ var EmailOtpVerify = function EmailOtpVerify(param) {
4779
4836
  }, [
4780
4837
  language
4781
4838
  ]);
4782
- useEffect9(function() {
4783
- if (countdown * 60 > 0) {
4784
- var timer = setTimeout(function() {
4785
- setCountdown(countdown * 60 - 1);
4786
- }, 1e3);
4787
- return function() {
4788
- return clearTimeout(timer);
4789
- };
4790
- } else {
4791
- setCanResend(true);
4792
- }
4793
- }, [
4794
- countdown
4795
- ]);
4796
4839
  var calculateResendCodeTime = function calculateResendCodeTime() {
4797
4840
  var _ref;
4798
4841
  var _config_config_emailConfig, _config_config;
4799
4842
  var resendCodeTime = (_ref = config === null || config === void 0 ? void 0 : (_config_config = config.config) === null || _config_config === void 0 ? void 0 : (_config_config_emailConfig = _config_config.emailConfig) === null || _config_config_emailConfig === void 0 ? void 0 : _config_config_emailConfig.resendCodeTime) !== null && _ref !== void 0 ? _ref : DEFAULT_COUNTDOWN_TIME;
4800
- if (resendCodeTime && resendCodeTime > 1) {
4801
- return resendCodeTime * 60;
4802
- }
4803
- return DEFAULT_COUNTDOWN_TIME * 60;
4843
+ return resendCodeTime > 0 ? resendCodeTime : DEFAULT_COUNTDOWN_TIME;
4804
4844
  };
4805
4845
  var handleResendCode = function handleResendCode() {
4806
4846
  return _async_to_generator(function() {
4807
- var client, error;
4847
+ var client, error, errorObj;
4808
4848
  return _ts_generator(this, function(_state) {
4809
4849
  switch(_state.label){
4810
4850
  case 0:
4811
4851
  setIsResending(true);
4812
- setValidationState("idle");
4813
- setErrorMessage("");
4814
- setOtp("");
4852
+ setResendError(null);
4815
4853
  _state.label = 1;
4816
4854
  case 1:
4817
4855
  _state.trys.push([
@@ -4822,8 +4860,11 @@ var EmailOtpVerify = function EmailOtpVerify(param) {
4822
4860
  ]);
4823
4861
  client = getIframeClient(publishableKey);
4824
4862
  if (!client) {
4825
- setValidationState("error");
4826
- setErrorMessage("Failed to resend OTP");
4863
+ setResendError("Failed to resend OTP");
4864
+ setResendCooldownEpoch(function(n) {
4865
+ return n + 1;
4866
+ });
4867
+ setCanResend(false);
4827
4868
  return [
4828
4869
  2
4829
4870
  ];
@@ -4832,13 +4873,17 @@ var EmailOtpVerify = function EmailOtpVerify(param) {
4832
4873
  4,
4833
4874
  client.send(PostMessageType14.AUTH, PostMessageMethod13.LOGIN_CREATE, {
4834
4875
  publishableKey: publishableKey,
4835
- email: emailOtpSendResponse.email,
4836
- expiresIn: expiresIn
4876
+ email: emailOtpSendResponse.email
4837
4877
  })
4838
4878
  ];
4839
4879
  case 2:
4840
4880
  _state.sent();
4841
- setCountdown(calculateResendCodeTime());
4881
+ setOtp("");
4882
+ setValidationState("idle");
4883
+ setErrorMessage("");
4884
+ setResendCooldownEpoch(function(n) {
4885
+ return n + 1;
4886
+ });
4842
4887
  setCanResend(false);
4843
4888
  return [
4844
4889
  3,
@@ -4846,8 +4891,16 @@ var EmailOtpVerify = function EmailOtpVerify(param) {
4846
4891
  ];
4847
4892
  case 3:
4848
4893
  error = _state.sent();
4849
- setValidationState("error");
4850
- setErrorMessage("Failed to re-send OTP");
4894
+ errorObj = _instanceof(error, Error) ? error : new Error(String(error));
4895
+ setResendError(errorObj.message || "Failed to re-send OTP");
4896
+ setResendCooldownEpoch(function(n) {
4897
+ return n + 1;
4898
+ });
4899
+ setCanResend(false);
4900
+ onFlowStateChange === null || onFlowStateChange === void 0 ? void 0 : onFlowStateChange({
4901
+ status: "error",
4902
+ error: errorObj
4903
+ });
4851
4904
  return [
4852
4905
  3,
4853
4906
  5
@@ -5060,12 +5113,10 @@ var EmailOtpVerify = function EmailOtpVerify(param) {
5060
5113
  ]
5061
5114
  })
5062
5115
  }),
5063
- validationState === "error" && /* @__PURE__ */ jsxs12("div", {
5064
- className: "moonkey-text--error moonkey-text--center",
5065
- children: [
5066
- "\u2717 ",
5067
- errorMessage
5068
- ]
5116
+ validationState === "error" && /* @__PURE__ */ jsx18(ErrorBox, {
5117
+ variant: "inline",
5118
+ align: "center",
5119
+ children: errorMessage
5069
5120
  }),
5070
5121
  canResend ? /* @__PURE__ */ jsxs12("div", {
5071
5122
  className: "moonkey-center-row",
@@ -5100,6 +5151,11 @@ var EmailOtpVerify = function EmailOtpVerify(param) {
5100
5151
  onComplete: function onComplete() {
5101
5152
  return setCanResend(true);
5102
5153
  }
5154
+ }, resendCooldownEpoch),
5155
+ resendError && /* @__PURE__ */ jsx18(ErrorBox, {
5156
+ variant: "inline",
5157
+ align: "center",
5158
+ children: resendError
5103
5159
  })
5104
5160
  ]
5105
5161
  })
@@ -5288,11 +5344,9 @@ var EmailOtpVerifyFlow = function EmailOtpVerifyFlow(param) {
5288
5344
  onComplete
5289
5345
  ]);
5290
5346
  if (currentStep === "verify") {
5291
- var _authConfig_config_emailConfig, _authConfig_config;
5292
5347
  return /* @__PURE__ */ jsx21(EmailOtpVerify, {
5293
5348
  config: authConfig,
5294
5349
  publishableKey: authConfig.publishableKey,
5295
- expiresIn: (_authConfig_config = authConfig.config) === null || _authConfig_config === void 0 ? void 0 : (_authConfig_config_emailConfig = _authConfig_config.emailConfig) === null || _authConfig_config_emailConfig === void 0 ? void 0 : _authConfig_config_emailConfig.expiresIn,
5296
5350
  emailOtpSendResponse: storedEmailOtpSendResponse,
5297
5351
  onSuccess: handleOtpVerifySuccess,
5298
5352
  onBackPress: onBackPress
@@ -5307,15 +5361,12 @@ var EmailOtpVerifyFlow = function EmailOtpVerifyFlow(param) {
5307
5361
  }
5308
5362
  };
5309
5363
  // src/components/flows/export-key/export-key.tsx
5310
- import { getIframeUrl as getIframeUrl2, PostMessageMethod as PostMessageMethod14, PostMessageType as PostMessageType15 } from "@moon-x/core/utils";
5364
+ import { getIframeUrl as getIframeUrl2 } from "@moon-x/core/utils";
5365
+ import { assertPasskeyInParent as assertPasskeyInParent5 } from "@moon-x/core/sdk";
5366
+ import { createWebAuthnPasskey as createWebAuthnPasskey6 } from "@moon-x/core/web";
5311
5367
  import { KeyRound as KeyRound2, ShieldOff, X } from "lucide-react";
5312
5368
  import { useEffect as useEffect11, useRef as useRef6, useState as useState15 } from "react";
5313
5369
  import { Fragment as Fragment4, jsx as jsx22, jsxs as jsxs15 } from "react/jsx-runtime";
5314
- var bytesToB64url2 = function bytesToB64url2(bytes) {
5315
- var bin = "";
5316
- for(var i = 0; i < bytes.byteLength; i++)bin += String.fromCharCode(bytes[i]);
5317
- return btoa(bin).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
5318
- };
5319
5370
  var ExportKey = function ExportKey(param) {
5320
5371
  var uiConfig = param.uiConfig, walletId = param.walletId, publishableKey = param.publishableKey, walletType = param.walletType, onCancel = param.onCancel, propsIsDark = param.isDark, propsAppConfig = param.appConfig, config = param.config;
5321
5372
  var _ref;
@@ -5492,78 +5543,51 @@ var ExportKey = function ExportKey(param) {
5492
5543
  };
5493
5544
  var handleReveal = function handleReveal() {
5494
5545
  return _async_to_generator(function() {
5495
- var client, _dekInfo_allow_credential_ids_b64url, dekInfo, challenge, credential, assertion, err, msg;
5546
+ var _ref, userHandleB64url, credentialIdB64url, err, msg;
5496
5547
  return _ts_generator(this, function(_state) {
5497
5548
  switch(_state.label){
5498
5549
  case 0:
5499
5550
  setRevealError(null);
5500
5551
  setIsRevealing(true);
5501
- client = getIframeClient(publishableKey);
5502
- if (!client) {
5503
- setRevealError("SDK not initialized");
5504
- setIsRevealing(false);
5505
- return [
5506
- 2
5507
- ];
5508
- }
5509
5552
  _state.label = 1;
5510
5553
  case 1:
5511
5554
  _state.trys.push([
5512
5555
  1,
5556
+ 3,
5513
5557
  4,
5514
- 5,
5515
- 6
5558
+ 5
5516
5559
  ]);
5517
5560
  return [
5518
5561
  4,
5519
- client.send(PostMessageType15.AUTH, PostMessageMethod14.GET_DEK_INFO, {
5520
- publishableKey: publishableKey
5562
+ assertPasskeyInParent5({
5563
+ transport: getIframeTransport(),
5564
+ passkey: createWebAuthnPasskey6(),
5565
+ publishableKey: publishableKey,
5566
+ requireFreshAssertion: true,
5567
+ validateCredentialInAllowList: true
5521
5568
  })
5522
5569
  ];
5523
5570
  case 2:
5524
- dekInfo = _state.sent();
5525
- if (((_dekInfo_allow_credential_ids_b64url = dekInfo.allow_credential_ids_b64url) !== null && _dekInfo_allow_credential_ids_b64url !== void 0 ? _dekInfo_allow_credential_ids_b64url : []).length === 0) {
5526
- throw new Error("passkey_required");
5527
- }
5528
- if (!dekInfo.rp_id) {
5529
- throw new Error("webauthn_rp_id_not_configured");
5530
- }
5531
- challenge = crypto.getRandomValues(new Uint8Array(32));
5532
- return [
5533
- 4,
5534
- navigator.credentials.get({
5535
- publicKey: {
5536
- challenge: challenge,
5537
- rpId: dekInfo.rp_id,
5538
- userVerification: "preferred",
5539
- allowCredentials: []
5540
- }
5541
- })
5542
- ];
5543
- case 3:
5544
- credential = _state.sent();
5545
- if (!credential) throw new Error("passkey_assertion_cancelled");
5546
- assertion = credential.response;
5547
- if (!assertion.userHandle) throw new Error("user_handle_missing");
5548
- setIframeUrl(getfinalIframeUrl("private_key", bytesToB64url2(new Uint8Array(assertion.userHandle)), bytesToB64url2(new Uint8Array(credential.rawId))));
5571
+ _ref = _state.sent(), userHandleB64url = _ref.userHandleB64url, credentialIdB64url = _ref.credentialIdB64url;
5572
+ setIframeUrl(getfinalIframeUrl("private_key", userHandleB64url, credentialIdB64url));
5549
5573
  return [
5550
5574
  3,
5551
- 6
5575
+ 5
5552
5576
  ];
5553
- case 4:
5577
+ case 3:
5554
5578
  err = _state.sent();
5555
- msg = _instanceof(err, Error) ? err.name === "NotAllowedError" ? "Passkey prompt was cancelled. Click Reveal Key to retry." : err.message === "passkey_required" ? "Enroll a passkey first." : err.message === "user_handle_missing" ? "Your authenticator didn't return a user handle. Pick a different passkey." : err.message : "Couldn't unlock the export.";
5579
+ msg = _instanceof(err, Error) ? err.name === "NotAllowedError" ? "Passkey prompt was cancelled. Click Reveal Key to retry." : err.message === "passkey_required" ? "Enroll a passkey first." : err.message === "user_handle_missing" ? "Your authenticator didn't return a user handle. Pick a different passkey." : err.message === "unknown_passkey_for_this_account" ? "That passkey isn't recognized for your account on this device. It may belong to a different account. Try again and pick one of your registered passkeys." : err.message : "Couldn't unlock the export.";
5556
5580
  setRevealError(msg);
5557
5581
  return [
5558
5582
  3,
5559
- 6
5583
+ 5
5560
5584
  ];
5561
- case 5:
5585
+ case 4:
5562
5586
  setIsRevealing(false);
5563
5587
  return [
5564
5588
  7
5565
5589
  ];
5566
- case 6:
5590
+ case 5:
5567
5591
  return [
5568
5592
  2
5569
5593
  ];
@@ -7017,7 +7041,7 @@ var FundingFlow = function FundingFlow(param) {
7017
7041
  return null;
7018
7042
  };
7019
7043
  // src/components/flows/import-wallet/import-wallet.tsx
7020
- import { PostMessageMethod as PostMessageMethod15, PostMessageType as PostMessageType16 } from "@moon-x/core";
7044
+ import { PostMessageMethod as PostMessageMethod14, PostMessageType as PostMessageType15 } from "@moon-x/core";
7021
7045
  import { CheckCircle2 as CheckCircle23, X as X5 } from "lucide-react";
7022
7046
  import { useState as useState21 } from "react";
7023
7047
  import { jsx as jsx32, jsxs as jsxs24 } from "react/jsx-runtime";
@@ -7069,7 +7093,7 @@ var ImportWallet = function ImportWallet(param) {
7069
7093
  }
7070
7094
  return [
7071
7095
  4,
7072
- client.send(PostMessageType16.WALLET, PostMessageMethod15.IMPORT_KEY, {
7096
+ client.send(PostMessageType15.WALLET, PostMessageMethod14.IMPORT_KEY, {
7073
7097
  walletType: walletType,
7074
7098
  key: trimmed,
7075
7099
  publishableKey: publishableKey,
@@ -7226,7 +7250,7 @@ var ImportWallet = function ImportWallet(param) {
7226
7250
  });
7227
7251
  };
7228
7252
  // src/components/flows/login-landing/login-landing.tsx
7229
- import { PostMessageMethod as PostMessageMethod18, PostMessageType as PostMessageType19 } from "@moon-x/core/utils";
7253
+ import { PostMessageMethod as PostMessageMethod17, PostMessageType as PostMessageType18 } from "@moon-x/core/utils";
7230
7254
  import React16 from "react";
7231
7255
  // src/components/social/social-login-button.tsx
7232
7256
  import { useState as useState22 } from "react";
@@ -8293,7 +8317,7 @@ var useWalletConnect = function useWalletConnect(param) {
8293
8317
  // src/components/wallet-connect/components/browser-extension-ui.tsx
8294
8318
  import { useEffect as useEffect16, useRef as useRef9, useState as useState26 } from "react";
8295
8319
  // src/internal/use-ethereum-wallet.ts
8296
- import { PostMessageClient as PostMessageClient2, PostMessageMethod as PostMessageMethod16, PostMessageType as PostMessageType17 } from "@moon-x/core/utils";
8320
+ import { PostMessageClient as PostMessageClient2, PostMessageMethod as PostMessageMethod15, PostMessageType as PostMessageType16 } from "@moon-x/core/utils";
8297
8321
  import { useCallback as useCallback8, useState as useState25 } from "react";
8298
8322
  import { createManualSiweMessage } from "@moon-x/core/lib";
8299
8323
  var parseChainId = function parseChainId(chainId) {
@@ -8421,7 +8445,7 @@ var useEthereumWallet = function useEthereumWallet(param) {
8421
8445
  ]);
8422
8446
  return [
8423
8447
  4,
8424
- client.send(PostMessageType17.EXTERNAL_WALLET, PostMessageMethod16.WALLET_REGISTRATION_NONCE, {
8448
+ client.send(PostMessageType16.EXTERNAL_WALLET, PostMessageMethod15.WALLET_REGISTRATION_NONCE, {
8425
8449
  publishableKey: publishableKey,
8426
8450
  publicAddress: walletAddress,
8427
8451
  walletType: "ethereum",
@@ -8498,7 +8522,7 @@ var useEthereumWallet = function useEthereumWallet(param) {
8498
8522
  case 10:
8499
8523
  return [
8500
8524
  4,
8501
- client.send(PostMessageType17.EXTERNAL_WALLET, PostMessageMethod16.VERIFY_SIWE_WALLET_REGISTRATION, {
8525
+ client.send(PostMessageType16.EXTERNAL_WALLET, PostMessageMethod15.VERIFY_SIWE_WALLET_REGISTRATION, {
8502
8526
  publishableKey: publishableKey,
8503
8527
  publicAddress: walletAddress,
8504
8528
  walletType: "ethereum",
@@ -8515,7 +8539,7 @@ var useEthereumWallet = function useEthereumWallet(param) {
8515
8539
  ];
8516
8540
  }
8517
8541
  parentClient = new PostMessageClient2(window.parent, "*");
8518
- parentClient.sendOneWay(PostMessageType17.EXTERNAL_WALLET, "WALLET_CONNECTED", _object_spread({}, verifyResult.sessionData));
8542
+ parentClient.sendOneWay(PostMessageType16.EXTERNAL_WALLET, "WALLET_CONNECTED", _object_spread({}, verifyResult.sessionData));
8519
8543
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(verifyResult.sessionData);
8520
8544
  return [
8521
8545
  3,
@@ -8591,7 +8615,7 @@ var useEthereumWallet = function useEthereumWallet(param) {
8591
8615
  ]);
8592
8616
  return [
8593
8617
  4,
8594
- client.send(PostMessageType17.EXTERNAL_WALLET, PostMessageMethod16.WALLET_REGISTRATION_NONCE, {
8618
+ client.send(PostMessageType16.EXTERNAL_WALLET, PostMessageMethod15.WALLET_REGISTRATION_NONCE, {
8595
8619
  publishableKey: publishableKey,
8596
8620
  publicAddress: walletAddress,
8597
8621
  walletType: "ethereum",
@@ -8668,7 +8692,7 @@ var useEthereumWallet = function useEthereumWallet(param) {
8668
8692
  case 10:
8669
8693
  return [
8670
8694
  4,
8671
- client.send(PostMessageType17.EXTERNAL_WALLET, PostMessageMethod16.VERIFY_SIWE_WALLET_REGISTRATION, {
8695
+ client.send(PostMessageType16.EXTERNAL_WALLET, PostMessageMethod15.VERIFY_SIWE_WALLET_REGISTRATION, {
8672
8696
  publishableKey: publishableKey,
8673
8697
  publicAddress: walletAddress,
8674
8698
  walletType: "ethereum",
@@ -10780,7 +10804,7 @@ var NetworkSelection = function NetworkSelection(param) {
10780
10804
  // src/components/flows/wallets-flow/solana-connection-ui.tsx
10781
10805
  import { useEffect as useEffect20, useRef as useRef12, useState as useState34 } from "react";
10782
10806
  // src/internal/use-solana-wallet.ts
10783
- import { PostMessageClient as PostMessageClient3, PostMessageMethod as PostMessageMethod17, PostMessageType as PostMessageType18 } from "@moon-x/core/utils";
10807
+ import { PostMessageClient as PostMessageClient3, PostMessageMethod as PostMessageMethod16, PostMessageType as PostMessageType17 } from "@moon-x/core/utils";
10784
10808
  import { useCallback as useCallback10, useState as useState33 } from "react";
10785
10809
  import { SiwsMessage } from "@moon-x/core/lib";
10786
10810
  var useSolanaWallet = function useSolanaWallet(param) {
@@ -10879,7 +10903,7 @@ var useSolanaWallet = function useSolanaWallet(param) {
10879
10903
  ]);
10880
10904
  return [
10881
10905
  4,
10882
- client.send(PostMessageType18.EXTERNAL_WALLET, PostMessageMethod17.WALLET_REGISTRATION_NONCE, {
10906
+ client.send(PostMessageType17.EXTERNAL_WALLET, PostMessageMethod16.WALLET_REGISTRATION_NONCE, {
10883
10907
  publishableKey: publishableKey,
10884
10908
  publicAddress: walletAddress,
10885
10909
  walletType: "solana",
@@ -10931,7 +10955,7 @@ var useSolanaWallet = function useSolanaWallet(param) {
10931
10955
  encodedSignature = bs58.default.encode(signatureResponse);
10932
10956
  return [
10933
10957
  4,
10934
- client.send(PostMessageType18.EXTERNAL_WALLET, PostMessageMethod17.VERIFY_SIWE_WALLET_REGISTRATION, {
10958
+ client.send(PostMessageType17.EXTERNAL_WALLET, PostMessageMethod16.VERIFY_SIWE_WALLET_REGISTRATION, {
10935
10959
  publishableKey: publishableKey,
10936
10960
  publicAddress: walletAddress,
10937
10961
  walletType: "solana",
@@ -11016,7 +11040,7 @@ var useSolanaWallet = function useSolanaWallet(param) {
11016
11040
  ]);
11017
11041
  return [
11018
11042
  4,
11019
- client.send(PostMessageType18.EXTERNAL_WALLET, PostMessageMethod17.WALLET_REGISTRATION_NONCE, {
11043
+ client.send(PostMessageType17.EXTERNAL_WALLET, PostMessageMethod16.WALLET_REGISTRATION_NONCE, {
11020
11044
  publishableKey: publishableKey,
11021
11045
  publicAddress: walletAddress,
11022
11046
  walletType: "solana",
@@ -11068,7 +11092,7 @@ var useSolanaWallet = function useSolanaWallet(param) {
11068
11092
  encodedSignature = bs58.default.encode(signatureResponse);
11069
11093
  return [
11070
11094
  4,
11071
- client.send(PostMessageType18.EXTERNAL_WALLET, PostMessageMethod17.VERIFY_SIWE_WALLET_REGISTRATION, {
11095
+ client.send(PostMessageType17.EXTERNAL_WALLET, PostMessageMethod16.VERIFY_SIWE_WALLET_REGISTRATION, {
11072
11096
  publishableKey: publishableKey,
11073
11097
  publicAddress: walletAddress,
11074
11098
  walletType: "solana",
@@ -11085,7 +11109,7 @@ var useSolanaWallet = function useSolanaWallet(param) {
11085
11109
  ];
11086
11110
  }
11087
11111
  parentClient = new PostMessageClient3(window.parent, "*");
11088
- parentClient.sendOneWay(PostMessageType18.EXTERNAL_WALLET, "WALLET_CONNECTED", _object_spread({}, verifyResult.sessionData));
11112
+ parentClient.sendOneWay(PostMessageType17.EXTERNAL_WALLET, "WALLET_CONNECTED", _object_spread({}, verifyResult.sessionData));
11089
11113
  onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(verifyResult.sessionData);
11090
11114
  return [
11091
11115
  3,
@@ -12153,7 +12177,7 @@ var TermsAndPrivacy = function TermsAndPrivacy(param) {
12153
12177
  import { jsx as jsx51, jsxs as jsxs41 } from "react/jsx-runtime";
12154
12178
  var LoginLanding = function LoginLanding(param) {
12155
12179
  var config = param.config, onCancel = param.onCancel, onMethodSelect = param.onMethodSelect, _param_embedded = param.embedded, embedded = _param_embedded === void 0 ? false : _param_embedded, _param_hideClose = param.hideClose, hideClose = _param_hideClose === void 0 ? false : _param_hideClose, propsIsDark = param.isDark, propsAppConfig = param.appConfig;
12156
- var _config_config, _config_config_appearance, _config_config1, _config_config_appearance1, _config_config2, _config_config3, _config_config4, _appConfig_privacy_policy_url, _appConfig_terms_of_service_url, _config_config5, _config_config6, _config_config_appearance_loginHeaderTitle, _config_config_appearance2, _config_config7, _config_config_appearance3, _config_config8, _config_config_appearance4, _config_config9, _config_config_appearance5, _config_config10, _config_config_emailConfig, _config_config11, _config_config_prefill, _config_config12, _config_config_prefill1, _config_config13;
12180
+ var _config_config, _config_config_appearance, _config_config1, _config_config_appearance1, _config_config2, _config_config3, _config_config4, _appConfig_privacy_policy_url, _appConfig_terms_of_service_url, _config_config5, _config_config6, _config_config_appearance_loginHeaderTitle, _config_config_appearance2, _config_config7, _config_config_appearance3, _config_config8, _config_config_appearance4, _config_config9, _config_config_appearance5, _config_config10, _config_config_prefill, _config_config11, _config_config_prefill1, _config_config12;
12157
12181
  var _useAppConfig = useAppConfig(propsAppConfig ? void 0 : config === null || config === void 0 ? void 0 : config.publishableKey), fetchedAppConfig = _useAppConfig.appConfig;
12158
12182
  var appConfig = propsAppConfig || fetchedAppConfig;
12159
12183
  var t = useTranslation().t;
@@ -12194,20 +12218,23 @@ var LoginLanding = function LoginLanding(param) {
12194
12218
  }
12195
12219
  };
12196
12220
  var _React16_useState = _sliced_to_array(React16.useState(false), 2), acceptedTerms = _React16_useState[0], setAcceptedTerms = _React16_useState[1];
12221
+ var _React16_useState1 = _sliced_to_array(React16.useState(null), 2), loginError = _React16_useState1[0], setLoginError = _React16_useState1[1];
12197
12222
  var hasAnyTermsUrl = !!(appConfig === null || appConfig === void 0 ? void 0 : (_appConfig_privacy_policy_url = appConfig.privacy_policy_url) === null || _appConfig_privacy_policy_url === void 0 ? void 0 : _appConfig_privacy_policy_url.startsWith("https://")) || !!(appConfig === null || appConfig === void 0 ? void 0 : (_appConfig_terms_of_service_url = appConfig.terms_of_service_url) === null || _appConfig_terms_of_service_url === void 0 ? void 0 : _appConfig_terms_of_service_url.startsWith("https://"));
12198
12223
  var requireTerms = (appConfig === null || appConfig === void 0 ? void 0 : appConfig.require_users_accept_terms) === true && hasAnyTermsUrl;
12199
12224
  var loginGated = requireTerms && !acceptedTerms;
12200
12225
  var handleSocialLogin = function handleSocialLogin(provider) {
12201
12226
  return _async_to_generator(function() {
12202
- var client, data, redirectUrl, url, popup, handleMessage, error;
12227
+ var client, data, redirectUrl, url, popup, handleMessage, error, message;
12203
12228
  return _ts_generator(this, function(_state) {
12204
12229
  switch(_state.label){
12205
12230
  case 0:
12206
12231
  if (loginGated) return [
12207
12232
  2
12208
12233
  ];
12234
+ setLoginError(null);
12209
12235
  client = getIframeClient(config === null || config === void 0 ? void 0 : config.publishableKey);
12210
12236
  if (!client) {
12237
+ setLoginError("Sign-in is not ready yet \u2014 please reload the page and try again.");
12211
12238
  return [
12212
12239
  2
12213
12240
  ];
@@ -12222,7 +12249,7 @@ var LoginLanding = function LoginLanding(param) {
12222
12249
  ]);
12223
12250
  return [
12224
12251
  4,
12225
- client.send(PostMessageType19.AUTH, PostMessageMethod18.START_OAUTH, {
12252
+ client.send(PostMessageType18.AUTH, PostMessageMethod17.START_OAUTH, {
12226
12253
  publishableKey: config === null || config === void 0 ? void 0 : config.publishableKey,
12227
12254
  provider: provider,
12228
12255
  login_redirect_url: window.location.href
@@ -12240,7 +12267,7 @@ var LoginLanding = function LoginLanding(param) {
12240
12267
  }
12241
12268
  popup = window.open(redirectUrl, "_self");
12242
12269
  if (!popup) {
12243
- console.error("Popup blocked");
12270
+ setLoginError("Your browser blocked the sign-in window. Please allow popups for this site and try again.");
12244
12271
  return [
12245
12272
  2
12246
12273
  ];
@@ -12262,6 +12289,8 @@ var LoginLanding = function LoginLanding(param) {
12262
12289
  case 3:
12263
12290
  error = _state.sent();
12264
12291
  console.error("OAuth failed:", error);
12292
+ message = _instanceof(error, Error) ? error.message : "Sign-in failed. Please try again.";
12293
+ setLoginError(message);
12265
12294
  return [
12266
12295
  3,
12267
12296
  4
@@ -12336,15 +12365,15 @@ var LoginLanding = function LoginLanding(param) {
12336
12365
  children: [
12337
12366
  showEmail && /* @__PURE__ */ jsx51(EmailOtpInput, {
12338
12367
  publishableKey: (config === null || config === void 0 ? void 0 : config.publishableKey) || "",
12339
- expiresIn: config === null || config === void 0 ? void 0 : (_config_config11 = config.config) === null || _config_config11 === void 0 ? void 0 : (_config_config_emailConfig = _config_config11.emailConfig) === null || _config_config_emailConfig === void 0 ? void 0 : _config_config_emailConfig.expiresIn,
12340
- prefillEmail: (config === null || config === void 0 ? void 0 : (_config_config12 = config.config) === null || _config_config12 === void 0 ? void 0 : (_config_config_prefill = _config_config12.prefill) === null || _config_config_prefill === void 0 ? void 0 : _config_config_prefill.type) === "email" ? config === null || config === void 0 ? void 0 : (_config_config13 = config.config) === null || _config_config13 === void 0 ? void 0 : (_config_config_prefill1 = _config_config13.prefill) === null || _config_config_prefill1 === void 0 ? void 0 : _config_config_prefill1.value : void 0,
12341
- onSuccess: function onSuccess(email) {
12368
+ prefillEmail: (config === null || config === void 0 ? void 0 : (_config_config11 = config.config) === null || _config_config11 === void 0 ? void 0 : (_config_config_prefill = _config_config11.prefill) === null || _config_config_prefill === void 0 ? void 0 : _config_config_prefill.type) === "email" ? config === null || config === void 0 ? void 0 : (_config_config12 = config.config) === null || _config_config12 === void 0 ? void 0 : (_config_config_prefill1 = _config_config12.prefill) === null || _config_config_prefill1 === void 0 ? void 0 : _config_config_prefill1.value : void 0,
12369
+ onSuccess: function onSuccess(response) {
12342
12370
  if (loginGated) return;
12343
- onMethodSelect === null || onMethodSelect === void 0 ? void 0 : onMethodSelect("email", {
12344
- email: email
12345
- });
12371
+ setLoginError(null);
12372
+ onMethodSelect === null || onMethodSelect === void 0 ? void 0 : onMethodSelect("email", response);
12346
12373
  },
12347
- onError: function onError() {}
12374
+ onError: function onError(err) {
12375
+ return setLoginError(err.message);
12376
+ }
12348
12377
  }),
12349
12378
  /* @__PURE__ */ jsxs41("div", {
12350
12379
  className: "moonkey-social-buttons moonkey-flex-col",
@@ -12370,6 +12399,11 @@ var LoginLanding = function LoginLanding(param) {
12370
12399
  })
12371
12400
  ]
12372
12401
  }),
12402
+ loginError && /* @__PURE__ */ jsx51(ErrorBox, {
12403
+ variant: "inline",
12404
+ align: "center",
12405
+ children: loginError
12406
+ }),
12373
12407
  /* @__PURE__ */ jsx51(TermsAndPrivacy, {
12374
12408
  appConfig: appConfig,
12375
12409
  accepted: acceptedTerms,
@@ -12474,7 +12508,7 @@ var OAuth = function OAuth(param) {
12474
12508
  });
12475
12509
  };
12476
12510
  // src/components/flows/passkey-enroll/passkey-enroll.tsx
12477
- import { PostMessageMethod as PostMessageMethod19, PostMessageType as PostMessageType20 } from "@moon-x/core/utils";
12511
+ import { PostMessageMethod as PostMessageMethod18, PostMessageType as PostMessageType19 } from "@moon-x/core/utils";
12478
12512
  import { startRegistration as startRegistration2 } from "@simplewebauthn/browser";
12479
12513
  import { CheckCircle2 as CheckCircle24, CloudCog, Fingerprint as Fingerprint2, ShieldCheck } from "lucide-react";
12480
12514
  import { useEffect as useEffect23, useRef as useRef13, useState as useState37 } from "react";
@@ -12557,7 +12591,7 @@ var PasskeyEnroll = function PasskeyEnroll(param) {
12557
12591
  ]);
12558
12592
  return [
12559
12593
  4,
12560
- client.send(PostMessageType20.AUTH, PostMessageMethod19.PASSKEY_REGISTER_BEGIN, {
12594
+ client.send(PostMessageType19.AUTH, PostMessageMethod18.PASSKEY_REGISTER_BEGIN, {
12561
12595
  publishableKey: publishableKey,
12562
12596
  // Full origin (scheme + host + non-default port). Backend
12563
12597
  // pulls the host out for the suffix check against the
@@ -12658,7 +12692,7 @@ var PasskeyEnroll = function PasskeyEnroll(param) {
12658
12692
  credential = _state.sent();
12659
12693
  return [
12660
12694
  4,
12661
- client.send(PostMessageType20.AUTH, PostMessageMethod19.PASSKEY_REGISTER_VERIFY, {
12695
+ client.send(PostMessageType19.AUTH, PostMessageMethod18.PASSKEY_REGISTER_VERIFY, {
12662
12696
  publishableKey: publishableKey,
12663
12697
  // Must match the value sent at register/begin so the backend
12664
12698
  // rebuilds the same RP config the cryptographic verification
@@ -12865,10 +12899,10 @@ var PasskeyEnroll = function PasskeyEnroll(param) {
12865
12899
  });
12866
12900
  };
12867
12901
  // src/components/flows/send-ethereum-transaction-flow/send-ethereum-transaction-flow.tsx
12868
- import { PostMessageClient as PostMessageClient4, PostMessageMethod as PostMessageMethod21, PostMessageType as PostMessageType22 } from "@moon-x/core/utils";
12902
+ import { PostMessageClient as PostMessageClient4, PostMessageMethod as PostMessageMethod20, PostMessageType as PostMessageType21 } from "@moon-x/core/utils";
12869
12903
  import { useState as useState40 } from "react";
12870
12904
  // src/components/flows/send-ethereum-transaction-flow/send-ethereum-transaction.tsx
12871
- import { PostMessageMethod as PostMessageMethod20, PostMessageType as PostMessageType21 } from "@moon-x/core/utils";
12905
+ import { PostMessageMethod as PostMessageMethod19, PostMessageType as PostMessageType20 } from "@moon-x/core/utils";
12872
12906
  import { ListCheck, X as X11, XCircle as XCircle2 } from "lucide-react";
12873
12907
  import { useEffect as useEffect24, useState as useState38 } from "react";
12874
12908
  import { jsx as jsx54, jsxs as jsxs44 } from "react/jsx-runtime";
@@ -12902,7 +12936,7 @@ var SendEthereumTransaction = function SendEthereumTransaction(param) {
12902
12936
  ]);
12903
12937
  return [
12904
12938
  4,
12905
- client.send(PostMessageType21.WALLET, PostMessageMethod20.GET_CONFIRM_ETHEREUM_TRANSACTION, {
12939
+ client.send(PostMessageType20.WALLET, PostMessageMethod19.GET_CONFIRM_ETHEREUM_TRANSACTION, {
12906
12940
  transaction: transaction,
12907
12941
  walletAddress: wallet === null || wallet === void 0 ? void 0 : wallet.public_address,
12908
12942
  rpcUrl: rpcUrl,
@@ -13684,7 +13718,7 @@ var SendEthereumTransactionFlow = function SendEthereumTransactionFlow(param) {
13684
13718
  _ref = _state.sent(), userHandleB64url = _ref.userHandleB64url, credentialIdB64url = _ref.credentialIdB64url;
13685
13719
  return [
13686
13720
  4,
13687
- client.send(PostMessageType22.WALLET, PostMessageMethod21.SIGN_TRANSACTION, {
13721
+ client.send(PostMessageType21.WALLET, PostMessageMethod20.SIGN_TRANSACTION, {
13688
13722
  publishableKey: publishableKey,
13689
13723
  serializedTransaction: sendTransactionRequest.serializedTransaction,
13690
13724
  wallet: wallet,
@@ -13732,7 +13766,7 @@ var SendEthereumTransactionFlow = function SendEthereumTransactionFlow(param) {
13732
13766
  setCurrentStep("success");
13733
13767
  if (options === null || options === void 0 ? void 0 : (_options_uiOptions = options.uiOptions) === null || _options_uiOptions === void 0 ? void 0 : _options_uiOptions.showWalletUI) {
13734
13768
  parentClient = new PostMessageClient4(window.parent, "*");
13735
- parentClient.sendOneWay(PostMessageType22.WALLET, PostMessageMethod21.SEND_TRANSACTION, {
13769
+ parentClient.sendOneWay(PostMessageType21.WALLET, PostMessageMethod20.SEND_TRANSACTION, {
13736
13770
  success: true,
13737
13771
  signature: signed.signature,
13738
13772
  transactionHash: hash,
@@ -13777,7 +13811,7 @@ var SendEthereumTransactionFlow = function SendEthereumTransactionFlow(param) {
13777
13811
  setIsSending(false);
13778
13812
  if (options === null || options === void 0 ? void 0 : (_options_uiOptions = options.uiOptions) === null || _options_uiOptions === void 0 ? void 0 : _options_uiOptions.showWalletUI) {
13779
13813
  var parentClient = new PostMessageClient4(window.parent, "*");
13780
- parentClient.sendOneWay(PostMessageType22.WALLET, PostMessageMethod21.SEND_TRANSACTION, {
13814
+ parentClient.sendOneWay(PostMessageType21.WALLET, PostMessageMethod20.SEND_TRANSACTION, {
13781
13815
  success: false,
13782
13816
  cancelled: true,
13783
13817
  error: "User cancelled transaction"
@@ -13842,10 +13876,10 @@ var SendEthereumTransactionFlow = function SendEthereumTransactionFlow(param) {
13842
13876
  }
13843
13877
  };
13844
13878
  // src/components/flows/send-transaction-flow/send-transaction-flow.tsx
13845
- import { PostMessageClient as PostMessageClient5, PostMessageMethod as PostMessageMethod23, PostMessageType as PostMessageType24 } from "@moon-x/core/utils";
13879
+ import { PostMessageClient as PostMessageClient5, PostMessageMethod as PostMessageMethod22, PostMessageType as PostMessageType23 } from "@moon-x/core/utils";
13846
13880
  import { useState as useState43 } from "react";
13847
13881
  // src/components/flows/send-transaction-flow/send-transaction.tsx
13848
- import { PostMessageMethod as PostMessageMethod22, PostMessageType as PostMessageType23 } from "@moon-x/core/utils";
13882
+ import { PostMessageMethod as PostMessageMethod21, PostMessageType as PostMessageType22 } from "@moon-x/core/utils";
13849
13883
  import { ListCheck as ListCheck2, X as X14, XCircle as XCircle4 } from "lucide-react";
13850
13884
  import { useEffect as useEffect26, useState as useState41 } from "react";
13851
13885
  import { getTransferInfoFromInstructions } from "@moon-x/core/lib";
@@ -13880,7 +13914,7 @@ var SendTransaction = function SendTransaction(param) {
13880
13914
  ]);
13881
13915
  return [
13882
13916
  4,
13883
- client.send(PostMessageType23.WALLET, PostMessageMethod22.GET_CONFIRM_TRANSACTION, {
13917
+ client.send(PostMessageType22.WALLET, PostMessageMethod21.GET_CONFIRM_TRANSACTION, {
13884
13918
  encodedMessage: encodedMessage,
13885
13919
  walletAddress: walletAddress,
13886
13920
  transaction: transaction,
@@ -14667,7 +14701,7 @@ var SendTransactionFlow = function SendTransactionFlow(param) {
14667
14701
  _ref = _state.sent(), userHandleB64url = _ref.userHandleB64url, credentialIdB64url = _ref.credentialIdB64url;
14668
14702
  return [
14669
14703
  4,
14670
- client.send(PostMessageType24.WALLET, PostMessageMethod23.SIGN_TRANSACTION, {
14704
+ client.send(PostMessageType23.WALLET, PostMessageMethod22.SIGN_TRANSACTION, {
14671
14705
  publishableKey: publishableKey,
14672
14706
  serializedTransaction: sendTransactionRequest.transaction,
14673
14707
  wallet: wallet,
@@ -14725,7 +14759,7 @@ var SendTransactionFlow = function SendTransactionFlow(param) {
14725
14759
  setCurrentStep("success");
14726
14760
  if (options === null || options === void 0 ? void 0 : (_options_uiOptions = options.uiOptions) === null || _options_uiOptions === void 0 ? void 0 : _options_uiOptions.showWalletUI) {
14727
14761
  parentClient = new PostMessageClient5(window.parent, "*");
14728
- parentClient.sendOneWay(PostMessageType24.WALLET, PostMessageMethod23.SEND_TRANSACTION, {
14762
+ parentClient.sendOneWay(PostMessageType23.WALLET, PostMessageMethod22.SEND_TRANSACTION, {
14729
14763
  success: true,
14730
14764
  signature: signed.signature,
14731
14765
  signedTransaction: signed.signedTransaction,
@@ -14830,7 +14864,7 @@ var SendTransactionFlow = function SendTransactionFlow(param) {
14830
14864
  }
14831
14865
  };
14832
14866
  // src/components/flows/sign-7702-authorization/sign-7702-authorization.tsx
14833
- import { PostMessageClient as PostMessageClient6, PostMessageMethod as PostMessageMethod24, PostMessageType as PostMessageType25 } from "@moon-x/core/utils";
14867
+ import { PostMessageClient as PostMessageClient6, PostMessageMethod as PostMessageMethod23, PostMessageType as PostMessageType24 } from "@moon-x/core/utils";
14834
14868
  import { Check as Check2, Copy as Copy2, X as X17, XCircle as XCircle6 } from "lucide-react";
14835
14869
  import { useEffect as useEffect28, useRef as useRef14, useState as useState44 } from "react";
14836
14870
  import { Fragment as Fragment11, jsx as jsx64, jsxs as jsxs52 } from "react/jsx-runtime";
@@ -14949,7 +14983,7 @@ var Sign7702Authorization = function Sign7702Authorization(param) {
14949
14983
  _ref = _state.sent(), userHandleB64url = _ref.userHandleB64url, credentialIdB64url = _ref.credentialIdB64url;
14950
14984
  return [
14951
14985
  4,
14952
- client.send(PostMessageType25.WALLET, PostMessageMethod24.SIGN_7702_AUTHORIZATION, {
14986
+ client.send(PostMessageType24.WALLET, PostMessageMethod23.SIGN_7702_AUTHORIZATION, {
14953
14987
  contractAddress: contractAddress,
14954
14988
  chainId: chainId,
14955
14989
  nonce: nonce,
@@ -14967,7 +15001,7 @@ var Sign7702Authorization = function Sign7702Authorization(param) {
14967
15001
  setIsSigning(false);
14968
15002
  if (options === null || options === void 0 ? void 0 : (_options_uiOptions = options.uiOptions) === null || _options_uiOptions === void 0 ? void 0 : _options_uiOptions.showWalletUI) {
14969
15003
  parentClient = new PostMessageClient6(window.parent, "*");
14970
- parentClient.sendOneWay(PostMessageType25.WALLET, PostMessageMethod24.SIGN_7702_AUTHORIZATION, _object_spread({
15004
+ parentClient.sendOneWay(PostMessageType24.WALLET, PostMessageMethod23.SIGN_7702_AUTHORIZATION, _object_spread({
14971
15005
  success: true
14972
15006
  }, result));
14973
15007
  }
@@ -15157,7 +15191,7 @@ var Sign7702Authorization = function Sign7702Authorization(param) {
15157
15191
  };
15158
15192
  var sign_7702_authorization_default = Sign7702Authorization;
15159
15193
  // src/components/flows/sign-message-flow/sign-message.tsx
15160
- import { PostMessageClient as PostMessageClient7, PostMessageMethod as PostMessageMethod25, PostMessageType as PostMessageType26 } from "@moon-x/core";
15194
+ import { PostMessageClient as PostMessageClient7, PostMessageMethod as PostMessageMethod24, PostMessageType as PostMessageType25 } from "@moon-x/core";
15161
15195
  import { Check as Check3, Copy as Copy3, X as X18, XCircle as XCircle7 } from "lucide-react";
15162
15196
  import { useRef as useRef15, useState as useState45 } from "react";
15163
15197
  import { Fragment as Fragment12, jsx as jsx65, jsxs as jsxs53 } from "react/jsx-runtime";
@@ -15304,7 +15338,7 @@ var SignMessage = function SignMessage(param) {
15304
15338
  _ref = _state.sent(), userHandleB64url = _ref.userHandleB64url, credentialIdB64url = _ref.credentialIdB64url;
15305
15339
  return [
15306
15340
  4,
15307
- client.send(PostMessageType26.WALLET, PostMessageMethod25.SIGN_MESSAGE, {
15341
+ client.send(PostMessageType25.WALLET, PostMessageMethod24.SIGN_MESSAGE, {
15308
15342
  message: message,
15309
15343
  publishableKey: publishableKey,
15310
15344
  uiOptions: uiOptions,
@@ -15325,7 +15359,7 @@ var SignMessage = function SignMessage(param) {
15325
15359
  processedResponse = _state.sent();
15326
15360
  if (uiOptions === null || uiOptions === void 0 ? void 0 : uiOptions.showWalletUI) {
15327
15361
  parentClient = new PostMessageClient7(window.parent, "*");
15328
- parentClient.sendOneWay(PostMessageType26.WALLET, PostMessageMethod25.SIGN_MESSAGE, {
15362
+ parentClient.sendOneWay(PostMessageType25.WALLET, PostMessageMethod24.SIGN_MESSAGE, {
15329
15363
  success: true,
15330
15364
  signature: result.signature
15331
15365
  });
@@ -15513,7 +15547,7 @@ var SignMessage = function SignMessage(param) {
15513
15547
  });
15514
15548
  };
15515
15549
  // src/components/flows/sign-transaction-flow/sign-transaction.tsx
15516
- import { PostMessageClient as PostMessageClient8, PostMessageMethod as PostMessageMethod26, PostMessageType as PostMessageType27 } from "@moon-x/core/utils";
15550
+ import { PostMessageClient as PostMessageClient8, PostMessageMethod as PostMessageMethod25, PostMessageType as PostMessageType26 } from "@moon-x/core/utils";
15517
15551
  import { Check as Check4, ChevronRight, Copy as Copy4, X as X19, XCircle as XCircle8 } from "lucide-react";
15518
15552
  import { useEffect as useEffect29, useRef as useRef16, useState as useState46 } from "react";
15519
15553
  import { parseTransaction } from "viem";
@@ -15631,7 +15665,7 @@ var SignTransaction = function SignTransaction(param) {
15631
15665
  _ref = _state.sent(), userHandleB64url = _ref.userHandleB64url, credentialIdB64url = _ref.credentialIdB64url;
15632
15666
  return [
15633
15667
  4,
15634
- client.send(PostMessageType27.WALLET, PostMessageMethod26.SIGN_TRANSACTION, {
15668
+ client.send(PostMessageType26.WALLET, PostMessageMethod25.SIGN_TRANSACTION, {
15635
15669
  serializedTransaction: serializedTransaction,
15636
15670
  publishableKey: publishableKey,
15637
15671
  options: options,
@@ -15648,7 +15682,7 @@ var SignTransaction = function SignTransaction(param) {
15648
15682
  setIsSigning(false);
15649
15683
  if (options === null || options === void 0 ? void 0 : (_options_uiOptions = options.uiOptions) === null || _options_uiOptions === void 0 ? void 0 : _options_uiOptions.showWalletUI) {
15650
15684
  parentClient = new PostMessageClient8(window.parent, "*");
15651
- parentClient.sendOneWay(PostMessageType27.WALLET, PostMessageMethod26.SIGN_TRANSACTION, _object_spread({
15685
+ parentClient.sendOneWay(PostMessageType26.WALLET, PostMessageMethod25.SIGN_TRANSACTION, _object_spread({
15652
15686
  success: true
15653
15687
  }, result));
15654
15688
  }
@@ -15849,7 +15883,7 @@ var SignTransaction = function SignTransaction(param) {
15849
15883
  });
15850
15884
  };
15851
15885
  // src/components/flows/sign-typed-data/sign-typed-data.tsx
15852
- import { PostMessageClient as PostMessageClient9, PostMessageMethod as PostMessageMethod27, PostMessageType as PostMessageType28 } from "@moon-x/core/utils";
15886
+ import { PostMessageClient as PostMessageClient9, PostMessageMethod as PostMessageMethod26, PostMessageType as PostMessageType27 } from "@moon-x/core/utils";
15853
15887
  import { Check as Check5, ChevronRight as ChevronRight2, Copy as Copy5, X as X20, XCircle as XCircle9 } from "lucide-react";
15854
15888
  import { useEffect as useEffect30, useRef as useRef17, useState as useState47 } from "react";
15855
15889
  import { Fragment as Fragment14, jsx as jsx67, jsxs as jsxs55 } from "react/jsx-runtime";
@@ -15972,7 +16006,7 @@ var SignTypedData = function SignTypedData(param) {
15972
16006
  _ref = _state.sent(), userHandleB64url = _ref.userHandleB64url, credentialIdB64url = _ref.credentialIdB64url;
15973
16007
  return [
15974
16008
  4,
15975
- client.send(PostMessageType28.WALLET, PostMessageMethod27.SIGN_TYPED_DATA, {
16009
+ client.send(PostMessageType27.WALLET, PostMessageMethod26.SIGN_TYPED_DATA, {
15976
16010
  domain: domain,
15977
16011
  types: types,
15978
16012
  primaryType: primaryType,
@@ -15990,7 +16024,7 @@ var SignTypedData = function SignTypedData(param) {
15990
16024
  setIsSigning(false);
15991
16025
  if (options === null || options === void 0 ? void 0 : (_options_uiOptions = options.uiOptions) === null || _options_uiOptions === void 0 ? void 0 : _options_uiOptions.showWalletUI) {
15992
16026
  parentClient = new PostMessageClient9(window.parent, "*");
15993
- parentClient.sendOneWay(PostMessageType28.WALLET, PostMessageMethod27.SIGN_TYPED_DATA, {
16027
+ parentClient.sendOneWay(PostMessageType27.WALLET, PostMessageMethod26.SIGN_TYPED_DATA, {
15994
16028
  success: true,
15995
16029
  signature: result.signature
15996
16030
  });
@@ -17227,12 +17261,17 @@ var AuthProvider = function AuthProvider(param) {
17227
17261
  }), 2), flowState = _useState515[0], setFlowState = _useState515[1];
17228
17262
  var _useState516 = _sliced_to_array(useState51(false), 2), isAuthenticated = _useState516[0], setIsAuthenticated = _useState516[1];
17229
17263
  var _useState517 = _sliced_to_array(useState51(null), 2), user = _useState517[0], setUser = _useState517[1];
17230
- var _useState518 = _sliced_to_array(useState51("landing"), 2), currentFlow = _useState518[0], setCurrentFlow = _useState518[1];
17231
- var _useState519 = _sliced_to_array(useState51(null), 2), flowData = _useState519[0], setFlowData = _useState519[1];
17232
- var _useState5110 = _sliced_to_array(useState51(null), 2), appConfig = _useState5110[0], setAppConfig = _useState5110[1];
17233
- var _useState5111 = _sliced_to_array(useState51(true), 2), isLoadingConfig = _useState5111[0], setIsLoadingConfig = _useState5111[1];
17234
- var _useState5112 = _sliced_to_array(useState51(false), 2), isIframeReady = _useState5112[0], setIsIframeReady = _useState5112[1];
17235
- var _useState5113 = _sliced_to_array(useState51(config === null || config === void 0 ? void 0 : config.appearance), 2), appearance = _useState5113[0], setAppearance = _useState5113[1];
17264
+ var _useState518 = _sliced_to_array(useState51(0), 2), revalidatedAt = _useState518[0], setRevalidatedAt = _useState518[1];
17265
+ var _useState519 = _sliced_to_array(useState51("landing"), 2), currentFlow = _useState519[0], setCurrentFlow = _useState519[1];
17266
+ var _useState5110 = _sliced_to_array(useState51(null), 2), flowData = _useState5110[0], setFlowData = _useState5110[1];
17267
+ var _useState5111 = _sliced_to_array(useState51(null), 2), appConfig = _useState5111[0], setAppConfig = _useState5111[1];
17268
+ var _useState5112 = _sliced_to_array(useState51(true), 2), isLoadingConfig = _useState5112[0], setIsLoadingConfig = _useState5112[1];
17269
+ var _useState5113 = _sliced_to_array(useState51(false), 2), isIframeReady = _useState5113[0], setIsIframeReady = _useState5113[1];
17270
+ var _useState5114 = _sliced_to_array(useState51(function() {
17271
+ if (typeof window === "undefined") return false;
17272
+ return new URLSearchParams(window.location.search).has("token");
17273
+ }), 1), hasOAuthCallbackToken = _useState5114[0];
17274
+ var _useState5115 = _sliced_to_array(useState51(config === null || config === void 0 ? void 0 : config.appearance), 2), appearance = _useState5115[0], setAppearance = _useState5115[1];
17236
17275
  var authCheckCacheRef = useRef18(null);
17237
17276
  var AUTH_CACHE_TTL = 5e3;
17238
17277
  var initialAuthCheckDone = useRef18(false);
@@ -17473,7 +17512,7 @@ var AuthProvider = function AuthProvider(param) {
17473
17512
  client = createPostMessageClient(iframeRef.current.contentWindow, publishableKey);
17474
17513
  return [
17475
17514
  4,
17476
- client.send(PostMessageType29.AUTH, PostMessageMethod28.IS_AUTHENTICATED, {
17515
+ client.send(PostMessageType28.AUTH, PostMessageMethod27.IS_AUTHENTICATED, {
17477
17516
  publishableKey: publishableKey
17478
17517
  })
17479
17518
  ];
@@ -17487,7 +17526,7 @@ var AuthProvider = function AuthProvider(param) {
17487
17526
  ];
17488
17527
  return [
17489
17528
  4,
17490
- client.send(PostMessageType29.AUTH, PostMessageMethod28.GET_USER, {
17529
+ client.send(PostMessageType28.AUTH, PostMessageMethod27.GET_USER, {
17491
17530
  publishableKey: publishableKey
17492
17531
  })
17493
17532
  ];
@@ -17535,6 +17574,7 @@ var AuthProvider = function AuthProvider(param) {
17535
17574
  ]);
17536
17575
  var handleAuthSuccess = useCallback11(function(response) {
17537
17576
  setIsAuthenticatedWithRef(true);
17577
+ setIsReady(true);
17538
17578
  var rawUserData = (response === null || response === void 0 ? void 0 : response.data) || response;
17539
17579
  if ((rawUserData === null || rawUserData === void 0 ? void 0 : rawUserData.id_token) || (rawUserData === null || rawUserData === void 0 ? void 0 : rawUserData.idToken)) {
17540
17580
  var idToken = rawUserData.id_token || rawUserData.idToken;
@@ -17565,6 +17605,7 @@ var AuthProvider = function AuthProvider(param) {
17565
17605
  var handleOAuthError = useCallback11(function(error) {
17566
17606
  setStartFlow(false);
17567
17607
  setFlowData(null);
17608
+ setIsReady(true);
17568
17609
  if (errorCallback) {
17569
17610
  errorCallback(error);
17570
17611
  }
@@ -17573,7 +17614,7 @@ var AuthProvider = function AuthProvider(param) {
17573
17614
  ]);
17574
17615
  useOAuthCallbackDetection({
17575
17616
  isMounted: isMounted,
17576
- isReady: isReady,
17617
+ isIframeReady: isIframeReady,
17577
17618
  publishableKey: publishableKey,
17578
17619
  iframeRef: iframeRef,
17579
17620
  onOAuthSuccess: handleOAuthSuccess,
@@ -17598,7 +17639,7 @@ var AuthProvider = function AuthProvider(param) {
17598
17639
  if (!isMounted) return;
17599
17640
  var handleReadyMessage = function handleReadyMessage(event) {
17600
17641
  var _event_data = event.data, type = _event_data.type, method = _event_data.method;
17601
- if (type === PostMessageType29.INIT && method === PostMessageMethod28.READY) {
17642
+ if (type === PostMessageType28.INIT && method === PostMessageMethod27.READY) {
17602
17643
  setIsIframeReady(true);
17603
17644
  }
17604
17645
  };
@@ -17613,6 +17654,10 @@ var AuthProvider = function AuthProvider(param) {
17613
17654
  var _iframeRef_current;
17614
17655
  if (!isIframeReady || !isMounted || !((_iframeRef_current = iframeRef.current) === null || _iframeRef_current === void 0 ? void 0 : _iframeRef_current.contentWindow)) return;
17615
17656
  if (initialAuthCheckDone.current) return;
17657
+ if (hasOAuthCallbackToken) {
17658
+ initialAuthCheckDone.current = true;
17659
+ return;
17660
+ }
17616
17661
  var checkAuthStatus = function checkAuthStatus() {
17617
17662
  return _async_to_generator(function() {
17618
17663
  var iframeOrigin, client, response, isAuth, userData, rawUserData, error;
@@ -17630,7 +17675,7 @@ var AuthProvider = function AuthProvider(param) {
17630
17675
  client = new PostMessageClient10(iframeRef.current.contentWindow, iframeOrigin);
17631
17676
  return [
17632
17677
  4,
17633
- client.send(PostMessageType29.AUTH, PostMessageMethod28.IS_AUTHENTICATED, {
17678
+ client.send(PostMessageType28.AUTH, PostMessageMethod27.IS_AUTHENTICATED, {
17634
17679
  publishableKey: publishableKey
17635
17680
  })
17636
17681
  ];
@@ -17644,7 +17689,7 @@ var AuthProvider = function AuthProvider(param) {
17644
17689
  ];
17645
17690
  return [
17646
17691
  4,
17647
- client.send(PostMessageType29.AUTH, PostMessageMethod28.GET_USER, {
17692
+ client.send(PostMessageType28.AUTH, PostMessageMethod27.GET_USER, {
17648
17693
  publishableKey: publishableKey
17649
17694
  })
17650
17695
  ];
@@ -17691,7 +17736,8 @@ var AuthProvider = function AuthProvider(param) {
17691
17736
  isIframeReady,
17692
17737
  isMounted,
17693
17738
  publishableKey,
17694
- setIsAuthenticatedWithRef
17739
+ setIsAuthenticatedWithRef,
17740
+ hasOAuthCallbackToken
17695
17741
  ]);
17696
17742
  var prevStartFlowRef = useRef18(startFlow);
17697
17743
  useEffect34(function() {
@@ -17705,6 +17751,38 @@ var AuthProvider = function AuthProvider(param) {
17705
17751
  startFlow,
17706
17752
  recheckAuthStatus
17707
17753
  ]);
17754
+ var recheckAuthStatusRef = useRef18(recheckAuthStatus);
17755
+ useEffect34(function() {
17756
+ recheckAuthStatusRef.current = recheckAuthStatus;
17757
+ }, [
17758
+ recheckAuthStatus
17759
+ ]);
17760
+ useEffect34(function() {
17761
+ if (typeof window === "undefined" || typeof document === "undefined") {
17762
+ return;
17763
+ }
17764
+ var trigger = function trigger() {
17765
+ setRevalidatedAt(Date.now());
17766
+ recheckAuthStatusRef.current(true);
17767
+ };
17768
+ var onVisibilityChange = function onVisibilityChange() {
17769
+ if (document.visibilityState === "visible") trigger();
17770
+ };
17771
+ var onPageShow = function onPageShow() {
17772
+ return trigger();
17773
+ };
17774
+ var onPopState = function onPopState() {
17775
+ return trigger();
17776
+ };
17777
+ document.addEventListener("visibilitychange", onVisibilityChange);
17778
+ window.addEventListener("pageshow", onPageShow);
17779
+ window.addEventListener("popstate", onPopState);
17780
+ return function() {
17781
+ document.removeEventListener("visibilitychange", onVisibilityChange);
17782
+ window.removeEventListener("pageshow", onPageShow);
17783
+ window.removeEventListener("popstate", onPopState);
17784
+ };
17785
+ }, []);
17708
17786
  var onError = useCallback11(function(callback) {
17709
17787
  if (!isMounted) {
17710
17788
  return;
@@ -17885,6 +17963,7 @@ var AuthProvider = function AuthProvider(param) {
17885
17963
  sdkInstanceRef.current.isAuthenticated = isAuthenticated;
17886
17964
  sdkInstanceRef.current.user = user;
17887
17965
  sdkInstanceRef.current.refreshUser = refreshUser;
17966
+ sdkInstanceRef.current.revalidatedAt = revalidatedAt;
17888
17967
  return sdkInstanceRef.current;
17889
17968
  }, [
17890
17969
  isMounted,
@@ -17895,7 +17974,8 @@ var AuthProvider = function AuthProvider(param) {
17895
17974
  isAuthenticated,
17896
17975
  user,
17897
17976
  setIsAuthenticatedWithRef,
17898
- refreshUser
17977
+ refreshUser,
17978
+ revalidatedAt
17899
17979
  ]);
17900
17980
  var iframeStyles = getIframeStyles(hideIframe, embeddableId);
17901
17981
  useCloseIframe(function() {
@@ -18001,7 +18081,7 @@ var MoonKeyContext = createContext(null);
18001
18081
  var MoonKeyProvider = function MoonKeyProvider(param) {
18002
18082
  var publishableKey = param.publishableKey, embeddableId = param.embeddableId, config = param.config, children = param.children;
18003
18083
  var _ref;
18004
- var _config_security, _config_walletConnect, _config_emailConfig, _config_emailConfig1, _config_emailConfig2, _config_emailConfig3, _config_emailConfig4, _config_emailConfig5;
18084
+ var _config_security, _config_walletConnect, _config_emailConfig, _config_emailConfig1, _config_emailConfig2, _config_emailConfig3, _config_emailConfig4;
18005
18085
  if ((config === null || config === void 0 ? void 0 : config.defaultChain) || (config === null || config === void 0 ? void 0 : config.supportedChains)) {
18006
18086
  validateChainConfig({
18007
18087
  defaultChain: config.defaultChain,
@@ -18105,11 +18185,10 @@ var MoonKeyProvider = function MoonKeyProvider(param) {
18105
18185
  theme: config === null || config === void 0 ? void 0 : config.theme,
18106
18186
  emailConfig: {
18107
18187
  skipVerifiedSuccess: (config === null || config === void 0 ? void 0 : (_config_emailConfig = config.emailConfig) === null || _config_emailConfig === void 0 ? void 0 : _config_emailConfig.skipVerifiedSuccess) || false,
18108
- expiresIn: (config === null || config === void 0 ? void 0 : (_config_emailConfig1 = config.emailConfig) === null || _config_emailConfig1 === void 0 ? void 0 : _config_emailConfig1.expiresIn) || 10,
18109
- verifiedDisplayTime: (config === null || config === void 0 ? void 0 : (_config_emailConfig2 = config.emailConfig) === null || _config_emailConfig2 === void 0 ? void 0 : _config_emailConfig2.verifiedDisplayTime) || 3e3,
18110
- verifyEmailTitle: (config === null || config === void 0 ? void 0 : (_config_emailConfig3 = config.emailConfig) === null || _config_emailConfig3 === void 0 ? void 0 : _config_emailConfig3.verifyEmailTitle) || "Verify email",
18111
- verifyEmailResendTitle: (config === null || config === void 0 ? void 0 : (_config_emailConfig4 = config.emailConfig) === null || _config_emailConfig4 === void 0 ? void 0 : _config_emailConfig4.verifyEmailResendTitle) || "Resend code",
18112
- resendCodeTime: (config === null || config === void 0 ? void 0 : (_config_emailConfig5 = config.emailConfig) === null || _config_emailConfig5 === void 0 ? void 0 : _config_emailConfig5.resendCodeTime) || 60
18188
+ verifiedDisplayTime: (config === null || config === void 0 ? void 0 : (_config_emailConfig1 = config.emailConfig) === null || _config_emailConfig1 === void 0 ? void 0 : _config_emailConfig1.verifiedDisplayTime) || 3e3,
18189
+ verifyEmailTitle: (config === null || config === void 0 ? void 0 : (_config_emailConfig2 = config.emailConfig) === null || _config_emailConfig2 === void 0 ? void 0 : _config_emailConfig2.verifyEmailTitle) || "Verify email",
18190
+ verifyEmailResendTitle: (config === null || config === void 0 ? void 0 : (_config_emailConfig3 = config.emailConfig) === null || _config_emailConfig3 === void 0 ? void 0 : _config_emailConfig3.verifyEmailResendTitle) || "Resend code",
18191
+ resendCodeTime: (config === null || config === void 0 ? void 0 : (_config_emailConfig4 = config.emailConfig) === null || _config_emailConfig4 === void 0 ? void 0 : _config_emailConfig4.resendCodeTime) || 60
18113
18192
  },
18114
18193
  passkeyEnrollConfig: config === null || config === void 0 ? void 0 : config.passkeyEnrollConfig,
18115
18194
  signMessageConfig: config === null || config === void 0 ? void 0 : config.signMessageConfig,