@dynamic-labs/sdk-react-core 4.66.0 → 4.67.1
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/CHANGELOG.md +33 -0
- package/package.cjs +3 -3
- package/package.js +3 -3
- package/package.json +14 -14
- package/src/index.d.ts +1 -1
- package/src/lib/client/extension/functions/hasElevatedAccessToken/hasElevatedAccessToken.cjs +18 -0
- package/src/lib/client/extension/functions/hasElevatedAccessToken/hasElevatedAccessToken.d.ts +1 -0
- package/src/lib/client/extension/functions/hasElevatedAccessToken/hasElevatedAccessToken.js +14 -0
- package/src/lib/client/extension/functions/hasElevatedAccessToken/index.d.ts +1 -0
- package/src/lib/client/extension/index.d.ts +1 -0
- package/src/lib/components/SendBalancePageLayout/components/TokensBalanceDropdown/TokensBalanceDropdown.cjs +31 -11
- package/src/lib/components/SendBalancePageLayout/components/TokensBalanceDropdown/TokensBalanceDropdown.js +31 -11
- package/src/lib/context/DynamicContext/DynamicContext.cjs +20 -19
- package/src/lib/context/DynamicContext/DynamicContext.js +20 -19
- package/src/lib/context/DynamicContext/types/SettingsOverrides.d.ts +10 -0
- package/src/lib/shared/utils/functions/chain/getChainIcon.cjs +1 -0
- package/src/lib/shared/utils/functions/chain/getChainIcon.js +2 -1
- package/src/lib/styles/index.shadow.cjs +1 -1
- package/src/lib/styles/index.shadow.js +1 -1
- package/src/lib/utils/constants/values.cjs +2 -0
- package/src/lib/utils/constants/values.js +2 -0
- package/src/lib/utils/functions/compareChains/compareChains.cjs +1 -0
- package/src/lib/utils/functions/compareChains/compareChains.js +1 -0
- package/src/lib/utils/hooks/index.d.ts +1 -1
- package/src/lib/utils/hooks/useAuthenticatePasskeyMFA/useAuthenticatePasskeyMFA.d.ts +2 -1
- package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.cjs +2 -1
- package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.d.ts +2 -1
- package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.js +2 -1
- package/src/lib/utils/hooks/useMfa/useMfa.cjs +6 -3
- package/src/lib/utils/hooks/useMfa/useMfa.d.ts +5 -3
- package/src/lib/utils/hooks/useMfa/useMfa.js +6 -3
- package/src/lib/utils/hooks/useNetworkConfigurationsFromProjectSettings/useNetworkConfigurationsFromProjectSettings.cjs +7 -2
- package/src/lib/utils/hooks/useNetworkConfigurationsFromProjectSettings/useNetworkConfigurationsFromProjectSettings.d.ts +2 -1
- package/src/lib/utils/hooks/useNetworkConfigurationsFromProjectSettings/useNetworkConfigurationsFromProjectSettings.js +7 -2
- package/src/lib/utils/hooks/usePromptMfaAuth/usePromptMfaAuth.cjs +14 -185
- package/src/lib/utils/hooks/usePromptMfaAuth/usePromptMfaAuth.d.ts +15 -3
- package/src/lib/utils/hooks/usePromptMfaAuth/usePromptMfaAuth.js +14 -185
- package/src/lib/utils/hooks/useStepUpAuthentication/index.d.ts +1 -1
- package/src/lib/utils/hooks/useStepUpAuthentication/useStepUpAuthentication.cjs +283 -33
- package/src/lib/utils/hooks/useStepUpAuthentication/useStepUpAuthentication.d.ts +45 -15
- package/src/lib/utils/hooks/useStepUpAuthentication/useStepUpAuthentication.js +279 -29
- package/src/lib/utils/hooks/useWalletConnectorNetwork/useWalletConnectorNetwork.cjs +3 -2
- package/src/lib/utils/hooks/useWalletConnectorNetwork/useWalletConnectorNetwork.js +3 -2
- package/src/lib/views/CollectUserDataView/UserDataFields/UserPhoneField/UserPhoneField.cjs +10 -6
- package/src/lib/views/CollectUserDataView/UserDataFields/UserPhoneField/UserPhoneField.js +11 -7
- package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.cjs +10 -9
- package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.js +10 -9
- package/src/lib/views/MfaChooseDeviceView/MfaChooseDeviceView.cjs +4 -3
- package/src/lib/views/MfaChooseDeviceView/MfaChooseDeviceView.d.ts +2 -0
- package/src/lib/views/MfaChooseDeviceView/MfaChooseDeviceView.js +4 -3
- package/src/lib/views/MfaVerificationView/MfaVerificationView.cjs +3 -1
- package/src/lib/views/MfaVerificationView/MfaVerificationView.d.ts +3 -2
- package/src/lib/views/MfaVerificationView/MfaVerificationView.js +3 -1
- package/src/lib/views/Passkey/ConfirmPasskeyView/ConfirmPasskeyView.cjs +2 -1
- package/src/lib/views/Passkey/ConfirmPasskeyView/ConfirmPasskeyView.d.ts +3 -1
- package/src/lib/views/Passkey/ConfirmPasskeyView/ConfirmPasskeyView.js +2 -1
- package/src/lib/views/SendBalanceView/SendBalanceView.cjs +1 -0
- package/src/lib/views/SendBalanceView/SendBalanceView.js +1 -0
- package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.cjs +21 -1
- package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.js +21 -1
- package/src/lib/views/WalletList/data.cjs +1 -0
- package/src/lib/views/WalletList/data.d.ts +1 -1
- package/src/lib/views/WalletList/data.js +1 -0
- package/src/lib/views/viewToComponentMap.d.ts +3 -2
|
@@ -1,191 +1,20 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
import {
|
|
3
|
-
import { useCallback } from 'react';
|
|
4
|
-
import { onEvent } from '@dynamic-labs-sdk/client';
|
|
5
|
-
import { MFADeviceType } from '@dynamic-labs/sdk-api-core';
|
|
6
|
-
import { DeferredPromise } from '@dynamic-labs/utils';
|
|
7
|
-
import { useGetUserMfaMethods } from '../useGetUserMfaMethods/useGetUserMfaMethods.js';
|
|
8
|
-
import { useViewContext } from '../../../context/ViewContext/ViewContext.js';
|
|
9
|
-
import '../../../context/DynamicContext/DynamicContext.js';
|
|
10
|
-
import '../../../store/state/loadingAndLifecycle/loadingAndLifecycle.js';
|
|
11
|
-
import '@dynamic-labs/iconic';
|
|
12
|
-
import '@dynamic-labs/wallet-connector-core';
|
|
13
|
-
import 'react/jsx-runtime';
|
|
14
|
-
import '../../../shared/logger.js';
|
|
15
|
-
import '@dynamic-labs/wallet-book';
|
|
16
|
-
import '../../constants/colors.js';
|
|
17
|
-
import '../../constants/values.js';
|
|
18
|
-
import '../../../shared/consts/index.js';
|
|
19
|
-
import { dynamicEvents } from '../../../events/dynamicEvents.js';
|
|
20
|
-
import '../../../context/CaptchaContext/CaptchaContext.js';
|
|
21
|
-
import '../../../context/ErrorContext/ErrorContext.js';
|
|
22
|
-
import '@dynamic-labs/multi-wallet';
|
|
23
|
-
import 'react-international-phone';
|
|
24
|
-
import '../../../store/state/nonce/nonce.js';
|
|
25
|
-
import '@dynamic-labs-sdk/client/core';
|
|
26
|
-
import { useDynamicClient } from '../../../client/client.js';
|
|
27
|
-
import '../../../config/ApiEndpoint.js';
|
|
28
|
-
import '@dynamic-labs/locale';
|
|
29
|
-
import '../../../store/state/dynamicContextProps/dynamicContextProps.js';
|
|
30
|
-
import '../../../store/state/primaryWalletId/primaryWalletId.js';
|
|
31
|
-
import '../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
|
|
32
|
-
import '../../functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.js';
|
|
33
|
-
import '../../../context/AccessDeniedContext/AccessDeniedContext.js';
|
|
34
|
-
import '../../../context/AccountExistsContext/AccountExistsContext.js';
|
|
35
|
-
import '../../../context/UserWalletsContext/UserWalletsContext.js';
|
|
36
|
-
import '../../../store/state/authMode/authMode.js';
|
|
37
|
-
import '../../../context/VerificationContext/VerificationContext.js';
|
|
38
|
-
import 'react-dom';
|
|
39
|
-
import '../../functions/compareChains/compareChains.js';
|
|
40
|
-
import '../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.js';
|
|
41
|
-
import '../../../context/ThemeContext/ThemeContext.js';
|
|
42
|
-
import '../useUserUpdateRequest/useUpdateUser/userFieldsSchema.js';
|
|
43
|
-
import 'bs58';
|
|
44
|
-
import '@dynamic-labs/types';
|
|
45
|
-
import '../../../context/SocialRedirectContext/SocialRedirectContext.js';
|
|
46
|
-
import '../../../context/LoadingContext/LoadingContext.js';
|
|
47
|
-
import '../../../context/WalletContext/WalletContext.js';
|
|
48
|
-
import '../useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.js';
|
|
49
|
-
import 'yup';
|
|
50
|
-
import '../../../context/MockContext/MockContext.js';
|
|
51
|
-
import '../../../views/CollectUserDataView/useFields.js';
|
|
52
|
-
import '../../../context/FieldsStateContext/FieldsStateContext.js';
|
|
53
|
-
import '../../../context/UserFieldEditorContext/UserFieldEditorContext.js';
|
|
54
|
-
import '@dynamic-labs/rpc-providers';
|
|
55
|
-
import '../../../store/state/walletOptions/walletOptions.js';
|
|
56
|
-
import 'react-i18next';
|
|
57
|
-
import '../../../components/Accordion/components/AccordionItem/AccordionItem.js';
|
|
58
|
-
import '../../../components/Alert/Alert.js';
|
|
59
|
-
import '../../../components/ShadowDOM/ShadowDOM.js';
|
|
60
|
-
import '../../../components/IconButton/IconButton.js';
|
|
61
|
-
import '../../../components/InlineWidget/InlineWidget.js';
|
|
62
|
-
import '../../../components/Input/Input.js';
|
|
63
|
-
import '../../../components/IsBrowser/IsBrowser.js';
|
|
64
|
-
import '../../../components/MenuList/Dropdown/Dropdown.js';
|
|
65
|
-
import '../../../components/OverlayCard/OverlayCard.js';
|
|
66
|
-
import '../../../components/Transition/ZoomTransition/ZoomTransition.js';
|
|
67
|
-
import '../../../components/Transition/SlideInUpTransition/SlideInUpTransition.js';
|
|
68
|
-
import '../../../components/Transition/OpacityTransition/OpacityTransition.js';
|
|
69
|
-
import '../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.js';
|
|
70
|
-
import '../../../components/Popper/Popper/Popper.js';
|
|
71
|
-
import '../../../components/Popper/PopperContext/PopperContext.js';
|
|
72
|
-
import 'react-focus-lock';
|
|
73
|
-
import 'qrcode';
|
|
74
|
-
import 'formik';
|
|
75
|
-
import '../useSubdomainCheck/useSubdomainCheck.js';
|
|
76
|
-
import '../../../context/WalletGroupContext/WalletGroupContext.js';
|
|
77
|
-
import '../../../widgets/DynamicWidget/context/DynamicWidgetContext.js';
|
|
78
|
-
import '../useWalletBackup/useWalletBackup.js';
|
|
79
|
-
import '../useWalletBackup/types.js';
|
|
80
|
-
import '../useWalletBackup/cloudProviders.js';
|
|
81
|
-
import '../../../context/IpConfigurationContext/IpConfigurationContext.js';
|
|
82
|
-
import '../../../context/ConnectWithOtpContext/ConnectWithOtpContext.js';
|
|
83
|
-
import '../../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.js';
|
|
84
|
-
import '@hcaptcha/react-hcaptcha';
|
|
85
|
-
import '../../../widgets/DynamicWidget/helpers/convertExchangeKeyAndProviderEnum.js';
|
|
86
|
-
import '../../../views/ExchangeWhitelistWarning/ExchangeWhitelistWarning.js';
|
|
87
|
-
import '../../../context/ErrorContext/hooks/useErrorText/useErrorText.js';
|
|
88
|
-
import '../../../context/FooterAnimationContext/index.js';
|
|
89
|
-
import '../../../views/MfaChooseDeviceView/useGetMfaOptions/useGetMfaOptions.js';
|
|
90
|
-
import '../../../context/PasskeyContext/PasskeyContext.js';
|
|
91
|
-
import '../../../context/OnrampContext/OnrampContext.js';
|
|
92
|
-
import '../../../store/state/sendBalances.js';
|
|
93
|
-
import '../../../store/state/connectorsInitializing/connectorsInitializing.js';
|
|
94
|
-
import '../../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.js';
|
|
95
|
-
import '../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.js';
|
|
96
|
-
import '../../../views/TransactionConfirmationView/TransactionConfirmationView.js';
|
|
97
|
-
import '../../../widgets/DynamicWidget/components/PasskeyCard/PasskeyCard.js';
|
|
98
|
-
import '../../../widgets/DynamicWidget/views/CryptoComOnramp/CryptoComOnramp.js';
|
|
99
|
-
import '../../../../index.js';
|
|
100
|
-
import '../../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.js';
|
|
101
|
-
import '../../../store/state/tokenBalances.js';
|
|
102
|
-
import '../../../store/state/multichainBalances.js';
|
|
103
|
-
import { useAuthenticatePasskeyMFA } from '../useAuthenticatePasskeyMFA/useAuthenticatePasskeyMFA.js';
|
|
104
|
-
import '../../../shared/utils/functions/getInitialUrl/getInitialUrl.js';
|
|
105
|
-
import { useInternalDynamicContext } from '../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.js';
|
|
2
|
+
import { useStepUpAuthentication } from '../useStepUpAuthentication/useStepUpAuthentication.js';
|
|
106
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Opens the Dynamic MFA modal (passkey or TOTP) and resolves when the user completes MFA.
|
|
6
|
+
*
|
|
7
|
+
* @deprecated Use `useStepUpAuthentication().promptMfa()` instead. Step-up authentication
|
|
8
|
+
* is the generic category; MFA is one verification method. The `promptMfa` method on
|
|
9
|
+
* `useStepUpAuthentication` provides the same behavior. This hook will be removed in the
|
|
10
|
+
* next major version.
|
|
11
|
+
*
|
|
12
|
+
* @returns A function that opens the MFA flow and returns a promise resolving to the
|
|
13
|
+
* MFA token (or `undefined` when using `requestedScopes` — use `getElevatedAccessToken({ scope })` after completion).
|
|
14
|
+
*/
|
|
107
15
|
const usePromptMfaAuth = () => {
|
|
108
|
-
const {
|
|
109
|
-
|
|
110
|
-
const getUserMfaMethods = useGetUserMfaMethods();
|
|
111
|
-
const authenticatePasskeyMFA = useAuthenticatePasskeyMFA();
|
|
112
|
-
const dynamicClient = useDynamicClient();
|
|
113
|
-
const promptMfaAuth = useCallback((props) => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
|
-
const methods = yield getUserMfaMethods();
|
|
115
|
-
const allMethods = [
|
|
116
|
-
...methods.passkeys.map((passkey) => (Object.assign(Object.assign({}, passkey), { type: MFADeviceType.Passkey }))),
|
|
117
|
-
...methods.devices.map((device) => (Object.assign(Object.assign({}, device), { type: MFADeviceType.Totp }))),
|
|
118
|
-
];
|
|
119
|
-
if (!methods.userHasVerifiedMfaMethods || allMethods.length === 0) {
|
|
120
|
-
setShowAuthFlow(true);
|
|
121
|
-
pushView('mfa-choose-device', {
|
|
122
|
-
createMfaToken: props === null || props === void 0 ? void 0 : props.createMfaToken,
|
|
123
|
-
});
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
const lastCreatedMethod = allMethods.reduce((a, b) => {
|
|
127
|
-
if (a.createdAt && b.createdAt) {
|
|
128
|
-
return a.createdAt >= b.createdAt ? a : b;
|
|
129
|
-
}
|
|
130
|
-
if (b.createdAt) {
|
|
131
|
-
return b;
|
|
132
|
-
}
|
|
133
|
-
return a;
|
|
134
|
-
});
|
|
135
|
-
switch (lastCreatedMethod.type) {
|
|
136
|
-
case MFADeviceType.Passkey: {
|
|
137
|
-
const createMfaTokenOptions = (props === null || props === void 0 ? void 0 : props.createMfaToken)
|
|
138
|
-
? { singleUse: true }
|
|
139
|
-
: undefined;
|
|
140
|
-
// we're calling authenticatePasskeyMFA here because we don't want
|
|
141
|
-
// it to be called twice by the usePromise in the confirmPasskey view
|
|
142
|
-
const authenticatePasskeyPromise = authenticatePasskeyMFA({
|
|
143
|
-
createMfaToken: createMfaTokenOptions,
|
|
144
|
-
});
|
|
145
|
-
setShowAuthFlow(true);
|
|
146
|
-
pushView('passkey-confirm', {
|
|
147
|
-
authenticatePasskeyPromise,
|
|
148
|
-
createMfaToken: props === null || props === void 0 ? void 0 : props.createMfaToken,
|
|
149
|
-
});
|
|
150
|
-
// Return the promise so callers can await MFA completion
|
|
151
|
-
return authenticatePasskeyPromise;
|
|
152
|
-
}
|
|
153
|
-
case MFADeviceType.Totp: {
|
|
154
|
-
if (dynamicClient === null || dynamicClient === void 0 ? void 0 : dynamicClient.mfaToken) {
|
|
155
|
-
return dynamicClient === null || dynamicClient === void 0 ? void 0 : dynamicClient.mfaToken;
|
|
156
|
-
}
|
|
157
|
-
// If the mfaToken is not present, we need to open the MFA UI and wait for it to be available
|
|
158
|
-
const deferred = new DeferredPromise();
|
|
159
|
-
// Open the MFA UI if the mfaToken is not available yet
|
|
160
|
-
setShowAuthFlow(true);
|
|
161
|
-
pushView('mfa-verification', {
|
|
162
|
-
createMfaToken: props === null || props === void 0 ? void 0 : props.createMfaToken,
|
|
163
|
-
});
|
|
164
|
-
const mfaCompletionSuccessOff = onEvent({
|
|
165
|
-
event: 'mfaCompletionSuccess',
|
|
166
|
-
listener: ({ mfaToken }) => deferred.resolve(mfaToken),
|
|
167
|
-
}, dynamicClient);
|
|
168
|
-
// Reject the promise if the auth flow is closed
|
|
169
|
-
const onAuthFlowCloseHandler = () => deferred.reject(new Error('MFA view closed'));
|
|
170
|
-
dynamicEvents.on('authFlowClose', onAuthFlowCloseHandler);
|
|
171
|
-
// Cleanup the event listeners
|
|
172
|
-
deferred.promise.finally(() => {
|
|
173
|
-
mfaCompletionSuccessOff();
|
|
174
|
-
dynamicEvents.off('authFlowClose', onAuthFlowCloseHandler);
|
|
175
|
-
});
|
|
176
|
-
return deferred.promise;
|
|
177
|
-
}
|
|
178
|
-
default:
|
|
179
|
-
throw new Error('Error determining MFA method to use');
|
|
180
|
-
}
|
|
181
|
-
}), [
|
|
182
|
-
authenticatePasskeyMFA,
|
|
183
|
-
dynamicClient,
|
|
184
|
-
getUserMfaMethods,
|
|
185
|
-
pushView,
|
|
186
|
-
setShowAuthFlow,
|
|
187
|
-
]);
|
|
188
|
-
return promptMfaAuth;
|
|
16
|
+
const { promptMfa } = useStepUpAuthentication();
|
|
17
|
+
return promptMfa;
|
|
189
18
|
};
|
|
190
19
|
|
|
191
20
|
export { usePromptMfaAuth };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { useStepUpAuthentication } from './useStepUpAuthentication';
|
|
2
|
-
export type { StepUpAuthenticationState, UseStepUpAuthenticationParams, UseStepUpAuthenticationReturn, VerifyOtpParams, VerifyWalletParams, } from './useStepUpAuthentication';
|
|
2
|
+
export type { IsStepUpRequiredParams, PromptMfaParams, StepUpAuthenticationState, UseStepUpAuthenticationParams, UseStepUpAuthenticationReturn, VerifyOtpParams, VerifyPasskeyMfaParams, VerifyRecoveryCodeParams, VerifyTotpMfaParams, VerifyWalletParams, } from './useStepUpAuthentication';
|
|
@@ -5,18 +5,18 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
|
|
6
6
|
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
7
7
|
var React = require('react');
|
|
8
|
-
var client = require('@dynamic-labs-sdk/client');
|
|
8
|
+
var client$1 = require('@dynamic-labs-sdk/client');
|
|
9
9
|
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
10
|
+
var utils = require('@dynamic-labs/utils');
|
|
10
11
|
require('@dynamic-labs-sdk/client/core');
|
|
11
|
-
require('../../../client/client.cjs');
|
|
12
|
+
var client = require('../../../client/client.cjs');
|
|
12
13
|
require('../../../config/ApiEndpoint.cjs');
|
|
13
14
|
require('@dynamic-labs/iconic');
|
|
14
15
|
require('@dynamic-labs/wallet-connector-core');
|
|
15
16
|
require('react/jsx-runtime');
|
|
16
|
-
require('../../../context/ViewContext/ViewContext.cjs');
|
|
17
|
+
var ViewContext = require('../../../context/ViewContext/ViewContext.cjs');
|
|
17
18
|
var logger = require('../../../shared/logger.cjs');
|
|
18
19
|
require('@dynamic-labs/wallet-book');
|
|
19
|
-
require('@dynamic-labs/utils');
|
|
20
20
|
require('../../constants/colors.cjs');
|
|
21
21
|
require('../../constants/values.cjs');
|
|
22
22
|
require('../../../shared/consts/index.cjs');
|
|
@@ -24,21 +24,99 @@ require('@dynamic-labs/multi-wallet');
|
|
|
24
24
|
require('react-international-phone');
|
|
25
25
|
require('../../../store/state/nonce/nonce.cjs');
|
|
26
26
|
require('@dynamic-labs/locale');
|
|
27
|
-
require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
|
|
27
|
+
var dynamicContextProps = require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
|
|
28
28
|
require('../../../store/state/primaryWalletId/primaryWalletId.cjs');
|
|
29
29
|
require('../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
|
|
30
30
|
require('../../functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.cjs');
|
|
31
|
-
require('../../../events/dynamicEvents.cjs');
|
|
31
|
+
var dynamicEvents = require('../../../events/dynamicEvents.cjs');
|
|
32
32
|
var useUser = require('../../../client/extension/user/useUser/useUser.cjs');
|
|
33
|
+
var hasElevatedAccessToken = require('../../../client/extension/functions/hasElevatedAccessToken/hasElevatedAccessToken.cjs');
|
|
34
|
+
require('../../../context/DynamicContext/DynamicContext.cjs');
|
|
35
|
+
require('../../../store/state/loadingAndLifecycle/loadingAndLifecycle.cjs');
|
|
33
36
|
var useConnectAndSign = require('../authenticationHooks/useConnectAndSign/useConnectAndSign.cjs');
|
|
37
|
+
require('../../../context/ErrorContext/ErrorContext.cjs');
|
|
38
|
+
require('../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
|
|
39
|
+
require('../../../context/AccountExistsContext/AccountExistsContext.cjs');
|
|
34
40
|
var UserWalletsContext = require('../../../context/UserWalletsContext/UserWalletsContext.cjs');
|
|
41
|
+
require('../../../store/state/authMode/authMode.cjs');
|
|
42
|
+
require('../../../context/CaptchaContext/CaptchaContext.cjs');
|
|
43
|
+
require('../../../context/VerificationContext/VerificationContext.cjs');
|
|
44
|
+
require('react-dom');
|
|
45
|
+
require('../../functions/compareChains/compareChains.cjs');
|
|
46
|
+
require('../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.cjs');
|
|
47
|
+
require('../../../context/ThemeContext/ThemeContext.cjs');
|
|
48
|
+
require('../useUserUpdateRequest/useUpdateUser/userFieldsSchema.cjs');
|
|
49
|
+
require('bs58');
|
|
50
|
+
require('@dynamic-labs/types');
|
|
51
|
+
require('../../../context/SocialRedirectContext/SocialRedirectContext.cjs');
|
|
52
|
+
require('../../../context/LoadingContext/LoadingContext.cjs');
|
|
53
|
+
require('../../../context/WalletContext/WalletContext.cjs');
|
|
54
|
+
require('../useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.cjs');
|
|
55
|
+
require('yup');
|
|
56
|
+
require('../../../context/MockContext/MockContext.cjs');
|
|
57
|
+
require('../../../views/CollectUserDataView/useFields.cjs');
|
|
58
|
+
require('../../../context/FieldsStateContext/FieldsStateContext.cjs');
|
|
59
|
+
require('../../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
|
|
60
|
+
require('@dynamic-labs/rpc-providers');
|
|
61
|
+
require('../../../store/state/walletOptions/walletOptions.cjs');
|
|
62
|
+
require('react-i18next');
|
|
63
|
+
require('../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
|
|
64
|
+
require('../../../components/Alert/Alert.cjs');
|
|
65
|
+
require('../../../components/ShadowDOM/ShadowDOM.cjs');
|
|
66
|
+
require('../../../components/IconButton/IconButton.cjs');
|
|
67
|
+
require('../../../components/InlineWidget/InlineWidget.cjs');
|
|
68
|
+
require('../../../components/Input/Input.cjs');
|
|
69
|
+
require('../../../components/IsBrowser/IsBrowser.cjs');
|
|
70
|
+
require('../../../components/MenuList/Dropdown/Dropdown.cjs');
|
|
71
|
+
require('../../../components/OverlayCard/OverlayCard.cjs');
|
|
72
|
+
require('../../../components/Transition/ZoomTransition/ZoomTransition.cjs');
|
|
73
|
+
require('../../../components/Transition/SlideInUpTransition/SlideInUpTransition.cjs');
|
|
74
|
+
require('../../../components/Transition/OpacityTransition/OpacityTransition.cjs');
|
|
75
|
+
require('../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.cjs');
|
|
76
|
+
require('../../../components/Popper/Popper/Popper.cjs');
|
|
77
|
+
require('../../../components/Popper/PopperContext/PopperContext.cjs');
|
|
78
|
+
require('react-focus-lock');
|
|
79
|
+
require('qrcode');
|
|
80
|
+
require('formik');
|
|
81
|
+
require('../useSubdomainCheck/useSubdomainCheck.cjs');
|
|
82
|
+
require('../../../context/WalletGroupContext/WalletGroupContext.cjs');
|
|
83
|
+
require('../../../widgets/DynamicWidget/context/DynamicWidgetContext.cjs');
|
|
84
|
+
require('../useWalletBackup/useWalletBackup.cjs');
|
|
85
|
+
require('../useWalletBackup/types.cjs');
|
|
86
|
+
require('../useWalletBackup/cloudProviders.cjs');
|
|
87
|
+
require('../../../context/IpConfigurationContext/IpConfigurationContext.cjs');
|
|
88
|
+
require('../../../context/ConnectWithOtpContext/ConnectWithOtpContext.cjs');
|
|
89
|
+
require('../../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs');
|
|
90
|
+
require('@hcaptcha/react-hcaptcha');
|
|
91
|
+
require('../../../widgets/DynamicWidget/helpers/convertExchangeKeyAndProviderEnum.cjs');
|
|
92
|
+
require('../../../views/ExchangeWhitelistWarning/ExchangeWhitelistWarning.cjs');
|
|
93
|
+
require('../../../context/ErrorContext/hooks/useErrorText/useErrorText.cjs');
|
|
94
|
+
require('../../../context/FooterAnimationContext/index.cjs');
|
|
95
|
+
require('../../../views/MfaChooseDeviceView/useGetMfaOptions/useGetMfaOptions.cjs');
|
|
96
|
+
require('../../../context/PasskeyContext/PasskeyContext.cjs');
|
|
97
|
+
require('../../../context/OnrampContext/OnrampContext.cjs');
|
|
98
|
+
require('../../../store/state/sendBalances.cjs');
|
|
99
|
+
require('../../../store/state/connectorsInitializing/connectorsInitializing.cjs');
|
|
100
|
+
require('../../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.cjs');
|
|
101
|
+
require('../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
|
|
102
|
+
require('../../../views/TransactionConfirmationView/TransactionConfirmationView.cjs');
|
|
103
|
+
require('../../../widgets/DynamicWidget/components/PasskeyCard/PasskeyCard.cjs');
|
|
104
|
+
require('../../../widgets/DynamicWidget/views/CryptoComOnramp/CryptoComOnramp.cjs');
|
|
105
|
+
require('../../../../index.cjs');
|
|
106
|
+
require('../../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.cjs');
|
|
107
|
+
require('../../../store/state/tokenBalances.cjs');
|
|
108
|
+
require('../../../store/state/multichainBalances.cjs');
|
|
109
|
+
var useGetUserMfaMethods = require('../useGetUserMfaMethods/useGetUserMfaMethods.cjs');
|
|
110
|
+
var useAuthenticatePasskeyMFA = require('../useAuthenticatePasskeyMFA/useAuthenticatePasskeyMFA.cjs');
|
|
111
|
+
require('../../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
|
|
112
|
+
var useInternalDynamicContext = require('../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.cjs');
|
|
35
113
|
|
|
36
114
|
const INITIAL_STATE = {
|
|
37
115
|
error: null,
|
|
38
116
|
isLoading: false,
|
|
39
117
|
otpVerification: null,
|
|
40
118
|
};
|
|
41
|
-
const isCountryCode = (value) => value !== undefined && value in client.supportedCountries;
|
|
119
|
+
const isCountryCode = (value) => value !== undefined && value in client$1.supportedCountries;
|
|
42
120
|
const isOtpCapableCredential = (cred) => cred.format === sdkApiCore.JwtVerifiedCredentialFormatEnum.Email ||
|
|
43
121
|
cred.format === sdkApiCore.JwtVerifiedCredentialFormatEnum.PhoneNumber;
|
|
44
122
|
const resolveTargetCredential = (credentials, credentialId) => {
|
|
@@ -52,19 +130,19 @@ const sendEmailOtp = (credential) => _tslib.__awaiter(void 0, void 0, void 0, fu
|
|
|
52
130
|
if (!credential.email) {
|
|
53
131
|
throw new Error('Email credential is missing email address');
|
|
54
132
|
}
|
|
55
|
-
return client.sendEmailOTP({ email: credential.email });
|
|
133
|
+
return client$1.sendEmailOTP({ email: credential.email });
|
|
56
134
|
});
|
|
57
135
|
const sendSmsOtp = (credential) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
58
136
|
var _a;
|
|
59
137
|
const normalizedPhoneCountryCode = (_a = credential.phoneCountryCode) === null || _a === void 0 ? void 0 : _a.replace(/^\+/, '');
|
|
60
|
-
const matchedCountryCode = Object.keys(client.supportedCountries).find((key) => client.supportedCountries[key].code === normalizedPhoneCountryCode);
|
|
138
|
+
const matchedCountryCode = Object.keys(client$1.supportedCountries).find((key) => client$1.supportedCountries[key].code === normalizedPhoneCountryCode);
|
|
61
139
|
const isoCountryCode = isCountryCode(credential.isoCountryCode)
|
|
62
140
|
? credential.isoCountryCode
|
|
63
141
|
: matchedCountryCode;
|
|
64
142
|
if (!credential.phoneNumber || !isoCountryCode) {
|
|
65
143
|
throw new Error('SMS credential is missing phone number or country code');
|
|
66
144
|
}
|
|
67
|
-
return client.sendSmsOTP({ isoCountryCode, phoneNumber: credential.phoneNumber });
|
|
145
|
+
return client$1.sendSmsOTP({ isoCountryCode, phoneNumber: credential.phoneNumber });
|
|
68
146
|
});
|
|
69
147
|
const dispatchOtp = (credential) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
70
148
|
return credential.format === sdkApiCore.JwtVerifiedCredentialFormatEnum.Email
|
|
@@ -72,47 +150,60 @@ const dispatchOtp = (credential) => _tslib.__awaiter(void 0, void 0, void 0, fun
|
|
|
72
150
|
: sendSmsOtp(credential);
|
|
73
151
|
});
|
|
74
152
|
/**
|
|
75
|
-
* Perform step-up authentication for an already-authenticated user
|
|
153
|
+
* Perform step-up authentication for an already-authenticated user.
|
|
76
154
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
155
|
+
* Supports multiple verification methods:
|
|
156
|
+
* - **OTP** (email/SMS): `sendOtp()` then `verifyOtp()`
|
|
157
|
+
* - **Wallet**: `verifyWallet()` for wallet signature verification
|
|
158
|
+
* - **Passkey MFA**: `verifyPasskeyMfa()` for passkey-based MFA
|
|
159
|
+
* - **TOTP MFA**: `verifyTotpMfa()` for authenticator app codes
|
|
79
160
|
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* enabled email or SMS credential on the authenticated user.
|
|
161
|
+
* For OTP and wallet methods, automatically selects the first sign-in enabled
|
|
162
|
+
* credential, or targets a specific one when `credentialId` is provided.
|
|
83
163
|
*
|
|
84
|
-
* @
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
* @returns `resetState` – resets state back to its initial value.
|
|
164
|
+
* @param params.credentialId - Optional id of a specific verified credential or
|
|
165
|
+
* wallet to use. For OTP, must be an email or SMS credential. Defaults to the
|
|
166
|
+
* first sign-in enabled email or SMS credential on the authenticated user.
|
|
88
167
|
*
|
|
89
168
|
* @example
|
|
90
169
|
* ```tsx
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* // Step 1: send OTP
|
|
170
|
+
* // OTP flow
|
|
171
|
+
* const { sendOtp, verifyOtp } = useStepUpAuthentication();
|
|
94
172
|
* await sendOtp();
|
|
173
|
+
* const result = await verifyOtp({ verificationToken: '123456', requestedScopes: ['wallet:export'] });
|
|
174
|
+
*
|
|
175
|
+
* // Passkey MFA flow
|
|
176
|
+
* const { verifyPasskeyMfa } = useStepUpAuthentication();
|
|
177
|
+
* const result = await verifyPasskeyMfa({ requestedScopes: ['wallet:export'] });
|
|
95
178
|
*
|
|
96
|
-
* //
|
|
97
|
-
* const
|
|
179
|
+
* // TOTP MFA flow
|
|
180
|
+
* const { verifyTotpMfa } = useStepUpAuthentication();
|
|
181
|
+
* const result = await verifyTotpMfa({ code: '123456', requestedScopes: ['wallet:export'] });
|
|
98
182
|
* ```
|
|
99
183
|
*/
|
|
100
184
|
const useStepUpAuthentication = ({ credentialId, } = {}) => {
|
|
101
185
|
const user = useUser.useUser();
|
|
186
|
+
const environmentId = dynamicContextProps.useEnvironmentId();
|
|
102
187
|
const [state, setState] = React.useState(INITIAL_STATE);
|
|
103
188
|
const connectAndSign = useConnectAndSign.useConnectAndSign();
|
|
104
189
|
const { userWallets } = UserWalletsContext.useInternalUserWallets();
|
|
190
|
+
const { setShowAuthFlow } = useInternalDynamicContext.useInternalDynamicContext();
|
|
191
|
+
const { pushView } = ViewContext.useViewContext();
|
|
192
|
+
const getUserMfaMethods = useGetUserMfaMethods.useGetUserMfaMethods();
|
|
193
|
+
const authenticatePasskeyMFA = useAuthenticatePasskeyMFA.useAuthenticatePasskeyMFA();
|
|
194
|
+
const dynamicClient = client.useDynamicClient();
|
|
105
195
|
// Ref keeps the latest otpVerification available inside the verifyOtp
|
|
106
196
|
// callback without creating a stale closure over state.
|
|
107
197
|
const otpVerificationRef = React.useRef(null);
|
|
198
|
+
const isStepUpRequired = React.useCallback(({ scope }) => !hasElevatedAccessToken.hasElevatedAccessToken(scope), []);
|
|
108
199
|
const resetState = React.useCallback(() => {
|
|
109
200
|
otpVerificationRef.current = null;
|
|
110
201
|
setState(INITIAL_STATE);
|
|
111
202
|
}, []);
|
|
112
203
|
const setError = React.useCallback((errorMessage) => {
|
|
113
204
|
setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
|
|
114
|
-
logger.logger.error(errorMessage);
|
|
115
|
-
}, []);
|
|
205
|
+
logger.logger.error(errorMessage, { environmentId, userId: user === null || user === void 0 ? void 0 : user.id });
|
|
206
|
+
}, [environmentId, user === null || user === void 0 ? void 0 : user.id]);
|
|
116
207
|
const sendOtp = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
117
208
|
const credentials = user === null || user === void 0 ? void 0 : user.verifiedCredentials;
|
|
118
209
|
if (!(credentials === null || credentials === void 0 ? void 0 : credentials.length)) {
|
|
@@ -138,10 +229,20 @@ const useStepUpAuthentication = ({ credentialId, } = {}) => {
|
|
|
138
229
|
catch (error) {
|
|
139
230
|
const errorMessage = error instanceof Error ? error.message : 'Failed to send OTP';
|
|
140
231
|
setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
|
|
141
|
-
logger.logger.error('Failed to send OTP for step-up authentication', {
|
|
232
|
+
logger.logger.error('Failed to send OTP for step-up authentication', {
|
|
233
|
+
environmentId,
|
|
234
|
+
error,
|
|
235
|
+
userId: user === null || user === void 0 ? void 0 : user.id,
|
|
236
|
+
});
|
|
142
237
|
return null;
|
|
143
238
|
}
|
|
144
|
-
}), [
|
|
239
|
+
}), [
|
|
240
|
+
credentialId,
|
|
241
|
+
environmentId,
|
|
242
|
+
setError,
|
|
243
|
+
user === null || user === void 0 ? void 0 : user.id,
|
|
244
|
+
user === null || user === void 0 ? void 0 : user.verifiedCredentials,
|
|
245
|
+
]);
|
|
145
246
|
const verifyOtp = React.useCallback((_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ requestedScopes, verificationToken, }) {
|
|
146
247
|
const otpVerification = otpVerificationRef.current;
|
|
147
248
|
if (!otpVerification) {
|
|
@@ -150,7 +251,7 @@ const useStepUpAuthentication = ({ credentialId, } = {}) => {
|
|
|
150
251
|
}
|
|
151
252
|
setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
|
|
152
253
|
try {
|
|
153
|
-
const response = yield client.verifyOTP({
|
|
254
|
+
const response = yield client$1.verifyOTP({
|
|
154
255
|
otpVerification,
|
|
155
256
|
requestedScopes,
|
|
156
257
|
verificationToken,
|
|
@@ -162,11 +263,13 @@ const useStepUpAuthentication = ({ credentialId, } = {}) => {
|
|
|
162
263
|
const errorMessage = error instanceof Error ? error.message : 'Failed to verify OTP';
|
|
163
264
|
setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
|
|
164
265
|
logger.logger.error('Failed to verify OTP for step-up authentication', {
|
|
266
|
+
environmentId,
|
|
165
267
|
error,
|
|
268
|
+
userId: user === null || user === void 0 ? void 0 : user.id,
|
|
166
269
|
});
|
|
167
270
|
return null;
|
|
168
271
|
}
|
|
169
|
-
}), [setError]);
|
|
272
|
+
}), [environmentId, setError, user === null || user === void 0 ? void 0 : user.id]);
|
|
170
273
|
const verifyWallet = React.useCallback((_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ requestedScopes }) {
|
|
171
274
|
setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
|
|
172
275
|
const wallet = userWallets.find((w) => w.id === credentialId);
|
|
@@ -187,11 +290,158 @@ const useStepUpAuthentication = ({ credentialId, } = {}) => {
|
|
|
187
290
|
: 'Failed to verify wallet for step-up authentication';
|
|
188
291
|
setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
|
|
189
292
|
logger.logger.error('Failed to verify wallet for step-up authentication', {
|
|
293
|
+
environmentId,
|
|
190
294
|
error,
|
|
295
|
+
userId: user === null || user === void 0 ? void 0 : user.id,
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
}), [connectAndSign, credentialId, environmentId, setError, user, userWallets]);
|
|
299
|
+
const verifyPasskeyMfa = React.useCallback((_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ requestedScopes, }) {
|
|
300
|
+
setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
|
|
301
|
+
try {
|
|
302
|
+
const response = yield client$1.authenticatePasskeyMFA({
|
|
303
|
+
requestedScopes,
|
|
304
|
+
});
|
|
305
|
+
setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: false })));
|
|
306
|
+
return response;
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
const errorMessage = error instanceof Error
|
|
310
|
+
? error.message
|
|
311
|
+
: 'Failed to authenticate passkey for step-up authentication';
|
|
312
|
+
setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
|
|
313
|
+
logger.logger.error('Failed to authenticate passkey for step-up authentication', { environmentId, error, userId: user === null || user === void 0 ? void 0 : user.id });
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
}), [environmentId, user]);
|
|
317
|
+
const verifyTotpMfa = React.useCallback((_d) => _tslib.__awaiter(void 0, [_d], void 0, function* ({ code, deviceId, requestedScopes, }) {
|
|
318
|
+
setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
|
|
319
|
+
try {
|
|
320
|
+
const response = yield client$1.authenticateTotpMfaDevice({
|
|
321
|
+
code,
|
|
322
|
+
deviceId,
|
|
323
|
+
requestedScopes,
|
|
324
|
+
});
|
|
325
|
+
setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: false })));
|
|
326
|
+
return response;
|
|
327
|
+
}
|
|
328
|
+
catch (error) {
|
|
329
|
+
const errorMessage = error instanceof Error
|
|
330
|
+
? error.message
|
|
331
|
+
: 'Failed to authenticate TOTP device for step-up authentication';
|
|
332
|
+
setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
|
|
333
|
+
logger.logger.error('Failed to authenticate TOTP device for step-up authentication', { environmentId, error, userId: user === null || user === void 0 ? void 0 : user.id });
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
}), [environmentId, user]);
|
|
337
|
+
const verifyRecoveryCode = React.useCallback((_e) => _tslib.__awaiter(void 0, [_e], void 0, function* ({ code, requestedScopes, }) {
|
|
338
|
+
setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
|
|
339
|
+
try {
|
|
340
|
+
const response = yield client$1.authenticateMfaRecoveryCode({
|
|
341
|
+
code,
|
|
342
|
+
requestedScopes,
|
|
191
343
|
});
|
|
344
|
+
setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: false })));
|
|
345
|
+
return response;
|
|
346
|
+
}
|
|
347
|
+
catch (error) {
|
|
348
|
+
const errorMessage = error instanceof Error
|
|
349
|
+
? error.message
|
|
350
|
+
: 'Failed to authenticate recovery code for step-up authentication';
|
|
351
|
+
setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
|
|
352
|
+
logger.logger.error('Failed to authenticate recovery code for step-up authentication', { environmentId, error, userId: user === null || user === void 0 ? void 0 : user.id });
|
|
353
|
+
return null;
|
|
354
|
+
}
|
|
355
|
+
}), [environmentId, user]);
|
|
356
|
+
const promptMfa = React.useCallback((props) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
357
|
+
var _f;
|
|
358
|
+
const methods = yield getUserMfaMethods();
|
|
359
|
+
const allMethods = [
|
|
360
|
+
...methods.passkeys.map((passkey) => (Object.assign(Object.assign({}, passkey), { type: sdkApiCore.MFADeviceType.Passkey }))),
|
|
361
|
+
...methods.devices.map((device) => (Object.assign(Object.assign({}, device), { type: sdkApiCore.MFADeviceType.Totp }))),
|
|
362
|
+
];
|
|
363
|
+
if (!methods.userHasVerifiedMfaMethods || allMethods.length === 0) {
|
|
364
|
+
setShowAuthFlow(true);
|
|
365
|
+
pushView('mfa-choose-device', {
|
|
366
|
+
createMfaToken: props === null || props === void 0 ? void 0 : props.createMfaToken,
|
|
367
|
+
requestedScopes: props === null || props === void 0 ? void 0 : props.requestedScopes,
|
|
368
|
+
});
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
const lastCreatedMethod = allMethods.reduce((a, b) => {
|
|
372
|
+
if (!a)
|
|
373
|
+
return b;
|
|
374
|
+
if (!b)
|
|
375
|
+
return a;
|
|
376
|
+
if (a.createdAt && b.createdAt) {
|
|
377
|
+
return a.createdAt >= b.createdAt ? a : b;
|
|
378
|
+
}
|
|
379
|
+
if (b.createdAt) {
|
|
380
|
+
return b;
|
|
381
|
+
}
|
|
382
|
+
return a;
|
|
383
|
+
}, allMethods[0]);
|
|
384
|
+
switch (lastCreatedMethod.type) {
|
|
385
|
+
case sdkApiCore.MFADeviceType.Passkey: {
|
|
386
|
+
const createMfaTokenOptions = (props === null || props === void 0 ? void 0 : props.createMfaToken)
|
|
387
|
+
? { singleUse: true }
|
|
388
|
+
: undefined;
|
|
389
|
+
const authenticatePasskeyPromise = authenticatePasskeyMFA({
|
|
390
|
+
createMfaToken: createMfaTokenOptions,
|
|
391
|
+
requestedScopes: props === null || props === void 0 ? void 0 : props.requestedScopes,
|
|
392
|
+
});
|
|
393
|
+
setShowAuthFlow(true);
|
|
394
|
+
pushView('passkey-confirm', {
|
|
395
|
+
authenticatePasskeyPromise,
|
|
396
|
+
createMfaToken: props === null || props === void 0 ? void 0 : props.createMfaToken,
|
|
397
|
+
requestedScopes: props === null || props === void 0 ? void 0 : props.requestedScopes,
|
|
398
|
+
});
|
|
399
|
+
return authenticatePasskeyPromise;
|
|
400
|
+
}
|
|
401
|
+
case sdkApiCore.MFADeviceType.Totp: {
|
|
402
|
+
if ((dynamicClient === null || dynamicClient === void 0 ? void 0 : dynamicClient.mfaToken) && !((_f = props === null || props === void 0 ? void 0 : props.requestedScopes) === null || _f === void 0 ? void 0 : _f.length)) {
|
|
403
|
+
return dynamicClient === null || dynamicClient === void 0 ? void 0 : dynamicClient.mfaToken;
|
|
404
|
+
}
|
|
405
|
+
const deferred = new utils.DeferredPromise();
|
|
406
|
+
setShowAuthFlow(true);
|
|
407
|
+
pushView('mfa-verification', {
|
|
408
|
+
createMfaToken: props === null || props === void 0 ? void 0 : props.createMfaToken,
|
|
409
|
+
requestedScopes: props === null || props === void 0 ? void 0 : props.requestedScopes,
|
|
410
|
+
});
|
|
411
|
+
const mfaCompletionSuccessOff = client$1.onEvent({
|
|
412
|
+
event: 'mfaCompletionSuccess',
|
|
413
|
+
listener: ({ mfaToken }) => deferred.resolve(mfaToken),
|
|
414
|
+
}, dynamicClient);
|
|
415
|
+
const onAuthFlowCloseHandler = () => deferred.reject(new Error('MFA view closed'));
|
|
416
|
+
dynamicEvents.dynamicEvents.on('authFlowClose', onAuthFlowCloseHandler);
|
|
417
|
+
deferred.promise.finally(() => {
|
|
418
|
+
mfaCompletionSuccessOff();
|
|
419
|
+
dynamicEvents.dynamicEvents.off('authFlowClose', onAuthFlowCloseHandler);
|
|
420
|
+
});
|
|
421
|
+
return deferred.promise;
|
|
422
|
+
}
|
|
423
|
+
default:
|
|
424
|
+
throw new Error('Error determining MFA method to use');
|
|
192
425
|
}
|
|
193
|
-
}), [
|
|
194
|
-
|
|
426
|
+
}), [
|
|
427
|
+
authenticatePasskeyMFA,
|
|
428
|
+
dynamicClient,
|
|
429
|
+
getUserMfaMethods,
|
|
430
|
+
pushView,
|
|
431
|
+
setShowAuthFlow,
|
|
432
|
+
]);
|
|
433
|
+
return {
|
|
434
|
+
isStepUpRequired,
|
|
435
|
+
promptMfa,
|
|
436
|
+
resetState,
|
|
437
|
+
sendOtp,
|
|
438
|
+
state,
|
|
439
|
+
verifyOtp,
|
|
440
|
+
verifyPasskeyMfa,
|
|
441
|
+
verifyRecoveryCode,
|
|
442
|
+
verifyTotpMfa,
|
|
443
|
+
verifyWallet,
|
|
444
|
+
};
|
|
195
445
|
};
|
|
196
446
|
|
|
197
447
|
exports.useStepUpAuthentication = useStepUpAuthentication;
|