@dynamic-labs/sdk-react-core 4.67.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 +14 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +12 -12
- package/src/index.d.ts +1 -1
- 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/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/hooks/index.d.ts +1 -1
- package/src/lib/utils/hooks/useAuthenticatePasskeyMFA/useAuthenticatePasskeyMFA.d.ts +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/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 +195 -24
- package/src/lib/utils/hooks/useStepUpAuthentication/useStepUpAuthentication.d.ts +10 -0
- package/src/lib/utils/hooks/useStepUpAuthentication/useStepUpAuthentication.js +189 -18
- 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/viewToComponentMap.d.ts +3 -2
|
@@ -109,4 +109,4 @@ export type { CheckWalletLockStateParams, UnlockWalletParams, UpdatePasswordPara
|
|
|
109
109
|
export { usePromptWalletUnlock } from './usePromptWalletUnlock';
|
|
110
110
|
export { useGetWalletPassword } from './useGetWalletPassword';
|
|
111
111
|
export { useStepUpAuthentication } from './useStepUpAuthentication';
|
|
112
|
-
export type { IsStepUpRequiredParams, StepUpAuthenticationState, UseStepUpAuthenticationParams, UseStepUpAuthenticationReturn, VerifyOtpParams, VerifyPasskeyMfaParams, VerifyTotpMfaParams, VerifyWalletParams, } from './useStepUpAuthentication';
|
|
112
|
+
export type { IsStepUpRequiredParams, PromptMfaParams, StepUpAuthenticationState, UseStepUpAuthenticationParams, UseStepUpAuthenticationReturn, VerifyOtpParams, VerifyPasskeyMfaParams, VerifyRecoveryCodeParams, VerifyTotpMfaParams, VerifyWalletParams, } from './useStepUpAuthentication';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { CreateMfaToken } from '@dynamic-labs/sdk-api-core';
|
|
1
|
+
import { CreateMfaToken, TokenScope } from '@dynamic-labs/sdk-api-core';
|
|
2
2
|
type UseAuthenticatePasskeyMFAProps = {
|
|
3
3
|
createMfaToken?: CreateMfaToken;
|
|
4
4
|
relatedOriginRpId?: string;
|
|
5
|
+
requestedScopes?: TokenScope[];
|
|
5
6
|
};
|
|
6
7
|
/**
|
|
7
8
|
* Authenticate passkey for MFA
|
|
@@ -35,7 +35,7 @@ var useUserAuth = require('../useUserAuth/useUserAuth.cjs');
|
|
|
35
35
|
|
|
36
36
|
const useMfa = () => {
|
|
37
37
|
const { completeAuth } = useUserAuth.useUserAuth({});
|
|
38
|
-
const handleMfaAuth = React.useCallback((_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ code, type, deviceId, createMfaToken, resultHandler, }) {
|
|
38
|
+
const handleMfaAuth = React.useCallback((_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ code, type, deviceId, createMfaToken, requestedScopes, resultHandler, }) {
|
|
39
39
|
let result;
|
|
40
40
|
yield completeAuth({
|
|
41
41
|
updateJwtFunction: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -46,6 +46,7 @@ const useMfa = () => {
|
|
|
46
46
|
code,
|
|
47
47
|
createMfaTokenOptions: createMfaToken,
|
|
48
48
|
deviceId,
|
|
49
|
+
requestedScopes,
|
|
49
50
|
});
|
|
50
51
|
result = resultHandler(response);
|
|
51
52
|
return {
|
|
@@ -103,11 +104,12 @@ const useMfa = () => {
|
|
|
103
104
|
});
|
|
104
105
|
return isValid;
|
|
105
106
|
}), [handleMfaAuth]);
|
|
106
|
-
const authenticateDevice = React.useCallback((_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ code, type = sdkApiCore.MFADeviceType.Totp, deviceId, createMfaToken, }) {
|
|
107
|
+
const authenticateDevice = React.useCallback((_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ code, type = sdkApiCore.MFADeviceType.Totp, deviceId, createMfaToken, requestedScopes, }) {
|
|
107
108
|
return handleMfaAuth({
|
|
108
109
|
code,
|
|
109
110
|
createMfaToken,
|
|
110
111
|
deviceId,
|
|
112
|
+
requestedScopes,
|
|
111
113
|
resultHandler: (response) => response.mfaToken,
|
|
112
114
|
type,
|
|
113
115
|
});
|
|
@@ -140,13 +142,14 @@ const useMfa = () => {
|
|
|
140
142
|
});
|
|
141
143
|
return isValid;
|
|
142
144
|
}), [completeAuth]);
|
|
143
|
-
const authenticateRecoveryCode = React.useCallback((_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ code, createMfaToken, }) {
|
|
145
|
+
const authenticateRecoveryCode = React.useCallback((_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ code, createMfaToken, requestedScopes, }) {
|
|
144
146
|
let mfaToken = undefined;
|
|
145
147
|
yield completeAuth({
|
|
146
148
|
updateJwtFunction: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
147
149
|
const response = yield client.authenticateMfaRecoveryCode({
|
|
148
150
|
code,
|
|
149
151
|
createMfaTokenOptions: createMfaToken,
|
|
152
|
+
requestedScopes,
|
|
150
153
|
});
|
|
151
154
|
if (!response) {
|
|
152
155
|
throw new Error('Failed to authenticate recovery code');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CreateMfaToken, MFADevice, MFADeviceType } from '@dynamic-labs/sdk-api-core';
|
|
1
|
+
import { CreateMfaToken, MFADevice, MFADeviceType, TokenScope } from '@dynamic-labs/sdk-api-core';
|
|
2
2
|
type UseMfaHookResult = {
|
|
3
3
|
/**
|
|
4
4
|
* Add a new device to the user's account.
|
|
@@ -22,19 +22,21 @@ type UseMfaHookResult = {
|
|
|
22
22
|
* Authenticates a recovery code and returns a single use MFA token
|
|
23
23
|
* if the authentication is successful and createMfaToken param is provided.
|
|
24
24
|
*/
|
|
25
|
-
authenticateRecoveryCode: ({ code, createMfaToken, }: {
|
|
25
|
+
authenticateRecoveryCode: ({ code, createMfaToken, requestedScopes, }: {
|
|
26
26
|
code: string;
|
|
27
27
|
createMfaToken?: CreateMfaToken;
|
|
28
|
+
requestedScopes?: TokenScope[];
|
|
28
29
|
}) => Promise<string | undefined>;
|
|
29
30
|
/**
|
|
30
31
|
* Authenticates a device and returns a single use MFA token
|
|
31
32
|
* if the authentication is successful and createMfaToken param is provided.
|
|
32
33
|
*/
|
|
33
|
-
authenticateDevice: ({ code, type, deviceId, createMfaToken, }: {
|
|
34
|
+
authenticateDevice: ({ code, type, deviceId, createMfaToken, requestedScopes, }: {
|
|
34
35
|
code: string;
|
|
35
36
|
type?: MFADeviceType;
|
|
36
37
|
deviceId?: string;
|
|
37
38
|
createMfaToken?: CreateMfaToken;
|
|
39
|
+
requestedScopes?: TokenScope[];
|
|
38
40
|
}) => Promise<string | undefined>;
|
|
39
41
|
completeAcknowledgement: () => Promise<void>;
|
|
40
42
|
/**
|
|
@@ -31,7 +31,7 @@ import { useUserAuth } from '../useUserAuth/useUserAuth.js';
|
|
|
31
31
|
|
|
32
32
|
const useMfa = () => {
|
|
33
33
|
const { completeAuth } = useUserAuth({});
|
|
34
|
-
const handleMfaAuth = useCallback((_a) => __awaiter(void 0, [_a], void 0, function* ({ code, type, deviceId, createMfaToken, resultHandler, }) {
|
|
34
|
+
const handleMfaAuth = useCallback((_a) => __awaiter(void 0, [_a], void 0, function* ({ code, type, deviceId, createMfaToken, requestedScopes, resultHandler, }) {
|
|
35
35
|
let result;
|
|
36
36
|
yield completeAuth({
|
|
37
37
|
updateJwtFunction: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -42,6 +42,7 @@ const useMfa = () => {
|
|
|
42
42
|
code,
|
|
43
43
|
createMfaTokenOptions: createMfaToken,
|
|
44
44
|
deviceId,
|
|
45
|
+
requestedScopes,
|
|
45
46
|
});
|
|
46
47
|
result = resultHandler(response);
|
|
47
48
|
return {
|
|
@@ -99,11 +100,12 @@ const useMfa = () => {
|
|
|
99
100
|
});
|
|
100
101
|
return isValid;
|
|
101
102
|
}), [handleMfaAuth]);
|
|
102
|
-
const authenticateDevice = useCallback((_b) => __awaiter(void 0, [_b], void 0, function* ({ code, type = MFADeviceType.Totp, deviceId, createMfaToken, }) {
|
|
103
|
+
const authenticateDevice = useCallback((_b) => __awaiter(void 0, [_b], void 0, function* ({ code, type = MFADeviceType.Totp, deviceId, createMfaToken, requestedScopes, }) {
|
|
103
104
|
return handleMfaAuth({
|
|
104
105
|
code,
|
|
105
106
|
createMfaToken,
|
|
106
107
|
deviceId,
|
|
108
|
+
requestedScopes,
|
|
107
109
|
resultHandler: (response) => response.mfaToken,
|
|
108
110
|
type,
|
|
109
111
|
});
|
|
@@ -136,13 +138,14 @@ const useMfa = () => {
|
|
|
136
138
|
});
|
|
137
139
|
return isValid;
|
|
138
140
|
}), [completeAuth]);
|
|
139
|
-
const authenticateRecoveryCode = useCallback((_c) => __awaiter(void 0, [_c], void 0, function* ({ code, createMfaToken, }) {
|
|
141
|
+
const authenticateRecoveryCode = useCallback((_c) => __awaiter(void 0, [_c], void 0, function* ({ code, createMfaToken, requestedScopes, }) {
|
|
140
142
|
let mfaToken = undefined;
|
|
141
143
|
yield completeAuth({
|
|
142
144
|
updateJwtFunction: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
143
145
|
const response = yield authenticateMfaRecoveryCode({
|
|
144
146
|
code,
|
|
145
147
|
createMfaTokenOptions: createMfaToken,
|
|
148
|
+
requestedScopes,
|
|
146
149
|
});
|
|
147
150
|
if (!response) {
|
|
148
151
|
throw new Error('Failed to authenticate recovery code');
|
|
@@ -3,193 +3,22 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
var
|
|
7
|
-
var React = require('react');
|
|
8
|
-
var client$1 = require('@dynamic-labs-sdk/client');
|
|
9
|
-
var sdkApiCore = require('@dynamic-labs/sdk-api-core');
|
|
10
|
-
var utils = require('@dynamic-labs/utils');
|
|
11
|
-
var useGetUserMfaMethods = require('../useGetUserMfaMethods/useGetUserMfaMethods.cjs');
|
|
12
|
-
var ViewContext = require('../../../context/ViewContext/ViewContext.cjs');
|
|
13
|
-
require('../../../context/DynamicContext/DynamicContext.cjs');
|
|
14
|
-
require('../../../store/state/loadingAndLifecycle/loadingAndLifecycle.cjs');
|
|
15
|
-
require('@dynamic-labs/iconic');
|
|
16
|
-
require('@dynamic-labs/wallet-connector-core');
|
|
17
|
-
require('react/jsx-runtime');
|
|
18
|
-
require('../../../shared/logger.cjs');
|
|
19
|
-
require('@dynamic-labs/wallet-book');
|
|
20
|
-
require('../../constants/colors.cjs');
|
|
21
|
-
require('../../constants/values.cjs');
|
|
22
|
-
require('../../../shared/consts/index.cjs');
|
|
23
|
-
var dynamicEvents = require('../../../events/dynamicEvents.cjs');
|
|
24
|
-
require('../../../context/CaptchaContext/CaptchaContext.cjs');
|
|
25
|
-
require('../../../context/ErrorContext/ErrorContext.cjs');
|
|
26
|
-
require('@dynamic-labs/multi-wallet');
|
|
27
|
-
require('react-international-phone');
|
|
28
|
-
require('../../../store/state/nonce/nonce.cjs');
|
|
29
|
-
require('@dynamic-labs-sdk/client/core');
|
|
30
|
-
var client = require('../../../client/client.cjs');
|
|
31
|
-
require('../../../config/ApiEndpoint.cjs');
|
|
32
|
-
require('@dynamic-labs/locale');
|
|
33
|
-
require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
|
|
34
|
-
require('../../../store/state/primaryWalletId/primaryWalletId.cjs');
|
|
35
|
-
require('../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
|
|
36
|
-
require('../../functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.cjs');
|
|
37
|
-
require('../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
|
|
38
|
-
require('../../../context/AccountExistsContext/AccountExistsContext.cjs');
|
|
39
|
-
require('../../../context/UserWalletsContext/UserWalletsContext.cjs');
|
|
40
|
-
require('../../../store/state/authMode/authMode.cjs');
|
|
41
|
-
require('../../../context/VerificationContext/VerificationContext.cjs');
|
|
42
|
-
require('react-dom');
|
|
43
|
-
require('../../functions/compareChains/compareChains.cjs');
|
|
44
|
-
require('../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.cjs');
|
|
45
|
-
require('../../../context/ThemeContext/ThemeContext.cjs');
|
|
46
|
-
require('../useUserUpdateRequest/useUpdateUser/userFieldsSchema.cjs');
|
|
47
|
-
require('bs58');
|
|
48
|
-
require('@dynamic-labs/types');
|
|
49
|
-
require('../../../context/SocialRedirectContext/SocialRedirectContext.cjs');
|
|
50
|
-
require('../../../context/LoadingContext/LoadingContext.cjs');
|
|
51
|
-
require('../../../context/WalletContext/WalletContext.cjs');
|
|
52
|
-
require('../useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/constants.cjs');
|
|
53
|
-
require('yup');
|
|
54
|
-
require('../../../context/MockContext/MockContext.cjs');
|
|
55
|
-
require('../../../views/CollectUserDataView/useFields.cjs');
|
|
56
|
-
require('../../../context/FieldsStateContext/FieldsStateContext.cjs');
|
|
57
|
-
require('../../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
|
|
58
|
-
require('@dynamic-labs/rpc-providers');
|
|
59
|
-
require('../../../store/state/walletOptions/walletOptions.cjs');
|
|
60
|
-
require('react-i18next');
|
|
61
|
-
require('../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
|
|
62
|
-
require('../../../components/Alert/Alert.cjs');
|
|
63
|
-
require('../../../components/ShadowDOM/ShadowDOM.cjs');
|
|
64
|
-
require('../../../components/IconButton/IconButton.cjs');
|
|
65
|
-
require('../../../components/InlineWidget/InlineWidget.cjs');
|
|
66
|
-
require('../../../components/Input/Input.cjs');
|
|
67
|
-
require('../../../components/IsBrowser/IsBrowser.cjs');
|
|
68
|
-
require('../../../components/MenuList/Dropdown/Dropdown.cjs');
|
|
69
|
-
require('../../../components/OverlayCard/OverlayCard.cjs');
|
|
70
|
-
require('../../../components/Transition/ZoomTransition/ZoomTransition.cjs');
|
|
71
|
-
require('../../../components/Transition/SlideInUpTransition/SlideInUpTransition.cjs');
|
|
72
|
-
require('../../../components/Transition/OpacityTransition/OpacityTransition.cjs');
|
|
73
|
-
require('../../../components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.cjs');
|
|
74
|
-
require('../../../components/Popper/Popper/Popper.cjs');
|
|
75
|
-
require('../../../components/Popper/PopperContext/PopperContext.cjs');
|
|
76
|
-
require('react-focus-lock');
|
|
77
|
-
require('qrcode');
|
|
78
|
-
require('formik');
|
|
79
|
-
require('../useSubdomainCheck/useSubdomainCheck.cjs');
|
|
80
|
-
require('../../../context/WalletGroupContext/WalletGroupContext.cjs');
|
|
81
|
-
require('../../../widgets/DynamicWidget/context/DynamicWidgetContext.cjs');
|
|
82
|
-
require('../useWalletBackup/useWalletBackup.cjs');
|
|
83
|
-
require('../useWalletBackup/types.cjs');
|
|
84
|
-
require('../useWalletBackup/cloudProviders.cjs');
|
|
85
|
-
require('../../../context/IpConfigurationContext/IpConfigurationContext.cjs');
|
|
86
|
-
require('../../../context/ConnectWithOtpContext/ConnectWithOtpContext.cjs');
|
|
87
|
-
require('../../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs');
|
|
88
|
-
require('@hcaptcha/react-hcaptcha');
|
|
89
|
-
require('../../../widgets/DynamicWidget/helpers/convertExchangeKeyAndProviderEnum.cjs');
|
|
90
|
-
require('../../../views/ExchangeWhitelistWarning/ExchangeWhitelistWarning.cjs');
|
|
91
|
-
require('../../../context/ErrorContext/hooks/useErrorText/useErrorText.cjs');
|
|
92
|
-
require('../../../context/FooterAnimationContext/index.cjs');
|
|
93
|
-
require('../../../views/MfaChooseDeviceView/useGetMfaOptions/useGetMfaOptions.cjs');
|
|
94
|
-
require('../../../context/PasskeyContext/PasskeyContext.cjs');
|
|
95
|
-
require('../../../context/OnrampContext/OnrampContext.cjs');
|
|
96
|
-
require('../../../store/state/sendBalances.cjs');
|
|
97
|
-
require('../../../store/state/connectorsInitializing/connectorsInitializing.cjs');
|
|
98
|
-
require('../../../components/OverlayCardBase/OverlayCardTarget/OverlayCardTarget.cjs');
|
|
99
|
-
require('../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
|
|
100
|
-
require('../../../views/TransactionConfirmationView/TransactionConfirmationView.cjs');
|
|
101
|
-
require('../../../widgets/DynamicWidget/components/PasskeyCard/PasskeyCard.cjs');
|
|
102
|
-
require('../../../widgets/DynamicWidget/views/CryptoComOnramp/CryptoComOnramp.cjs');
|
|
103
|
-
require('../../../../index.cjs');
|
|
104
|
-
require('../../../widgets/DynamicWidget/views/ReceiveWalletFunds/ReceiveWalletFunds.cjs');
|
|
105
|
-
require('../../../store/state/tokenBalances.cjs');
|
|
106
|
-
require('../../../store/state/multichainBalances.cjs');
|
|
107
|
-
var useAuthenticatePasskeyMFA = require('../useAuthenticatePasskeyMFA/useAuthenticatePasskeyMFA.cjs');
|
|
108
|
-
require('../../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
|
|
109
|
-
var useInternalDynamicContext = require('../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.cjs');
|
|
6
|
+
var useStepUpAuthentication = require('../useStepUpAuthentication/useStepUpAuthentication.cjs');
|
|
110
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Opens the Dynamic MFA modal (passkey or TOTP) and resolves when the user completes MFA.
|
|
10
|
+
*
|
|
11
|
+
* @deprecated Use `useStepUpAuthentication().promptMfa()` instead. Step-up authentication
|
|
12
|
+
* is the generic category; MFA is one verification method. The `promptMfa` method on
|
|
13
|
+
* `useStepUpAuthentication` provides the same behavior. This hook will be removed in the
|
|
14
|
+
* next major version.
|
|
15
|
+
*
|
|
16
|
+
* @returns A function that opens the MFA flow and returns a promise resolving to the
|
|
17
|
+
* MFA token (or `undefined` when using `requestedScopes` — use `getElevatedAccessToken({ scope })` after completion).
|
|
18
|
+
*/
|
|
111
19
|
const usePromptMfaAuth = () => {
|
|
112
|
-
const {
|
|
113
|
-
|
|
114
|
-
const getUserMfaMethods = useGetUserMfaMethods.useGetUserMfaMethods();
|
|
115
|
-
const authenticatePasskeyMFA = useAuthenticatePasskeyMFA.useAuthenticatePasskeyMFA();
|
|
116
|
-
const dynamicClient = client.useDynamicClient();
|
|
117
|
-
const promptMfaAuth = React.useCallback((props) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
118
|
-
const methods = yield getUserMfaMethods();
|
|
119
|
-
const allMethods = [
|
|
120
|
-
...methods.passkeys.map((passkey) => (Object.assign(Object.assign({}, passkey), { type: sdkApiCore.MFADeviceType.Passkey }))),
|
|
121
|
-
...methods.devices.map((device) => (Object.assign(Object.assign({}, device), { type: sdkApiCore.MFADeviceType.Totp }))),
|
|
122
|
-
];
|
|
123
|
-
if (!methods.userHasVerifiedMfaMethods || allMethods.length === 0) {
|
|
124
|
-
setShowAuthFlow(true);
|
|
125
|
-
pushView('mfa-choose-device', {
|
|
126
|
-
createMfaToken: props === null || props === void 0 ? void 0 : props.createMfaToken,
|
|
127
|
-
});
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
const lastCreatedMethod = allMethods.reduce((a, b) => {
|
|
131
|
-
if (a.createdAt && b.createdAt) {
|
|
132
|
-
return a.createdAt >= b.createdAt ? a : b;
|
|
133
|
-
}
|
|
134
|
-
if (b.createdAt) {
|
|
135
|
-
return b;
|
|
136
|
-
}
|
|
137
|
-
return a;
|
|
138
|
-
});
|
|
139
|
-
switch (lastCreatedMethod.type) {
|
|
140
|
-
case sdkApiCore.MFADeviceType.Passkey: {
|
|
141
|
-
const createMfaTokenOptions = (props === null || props === void 0 ? void 0 : props.createMfaToken)
|
|
142
|
-
? { singleUse: true }
|
|
143
|
-
: undefined;
|
|
144
|
-
// we're calling authenticatePasskeyMFA here because we don't want
|
|
145
|
-
// it to be called twice by the usePromise in the confirmPasskey view
|
|
146
|
-
const authenticatePasskeyPromise = authenticatePasskeyMFA({
|
|
147
|
-
createMfaToken: createMfaTokenOptions,
|
|
148
|
-
});
|
|
149
|
-
setShowAuthFlow(true);
|
|
150
|
-
pushView('passkey-confirm', {
|
|
151
|
-
authenticatePasskeyPromise,
|
|
152
|
-
createMfaToken: props === null || props === void 0 ? void 0 : props.createMfaToken,
|
|
153
|
-
});
|
|
154
|
-
// Return the promise so callers can await MFA completion
|
|
155
|
-
return authenticatePasskeyPromise;
|
|
156
|
-
}
|
|
157
|
-
case sdkApiCore.MFADeviceType.Totp: {
|
|
158
|
-
if (dynamicClient === null || dynamicClient === void 0 ? void 0 : dynamicClient.mfaToken) {
|
|
159
|
-
return dynamicClient === null || dynamicClient === void 0 ? void 0 : dynamicClient.mfaToken;
|
|
160
|
-
}
|
|
161
|
-
// If the mfaToken is not present, we need to open the MFA UI and wait for it to be available
|
|
162
|
-
const deferred = new utils.DeferredPromise();
|
|
163
|
-
// Open the MFA UI if the mfaToken is not available yet
|
|
164
|
-
setShowAuthFlow(true);
|
|
165
|
-
pushView('mfa-verification', {
|
|
166
|
-
createMfaToken: props === null || props === void 0 ? void 0 : props.createMfaToken,
|
|
167
|
-
});
|
|
168
|
-
const mfaCompletionSuccessOff = client$1.onEvent({
|
|
169
|
-
event: 'mfaCompletionSuccess',
|
|
170
|
-
listener: ({ mfaToken }) => deferred.resolve(mfaToken),
|
|
171
|
-
}, dynamicClient);
|
|
172
|
-
// Reject the promise if the auth flow is closed
|
|
173
|
-
const onAuthFlowCloseHandler = () => deferred.reject(new Error('MFA view closed'));
|
|
174
|
-
dynamicEvents.dynamicEvents.on('authFlowClose', onAuthFlowCloseHandler);
|
|
175
|
-
// Cleanup the event listeners
|
|
176
|
-
deferred.promise.finally(() => {
|
|
177
|
-
mfaCompletionSuccessOff();
|
|
178
|
-
dynamicEvents.dynamicEvents.off('authFlowClose', onAuthFlowCloseHandler);
|
|
179
|
-
});
|
|
180
|
-
return deferred.promise;
|
|
181
|
-
}
|
|
182
|
-
default:
|
|
183
|
-
throw new Error('Error determining MFA method to use');
|
|
184
|
-
}
|
|
185
|
-
}), [
|
|
186
|
-
authenticatePasskeyMFA,
|
|
187
|
-
dynamicClient,
|
|
188
|
-
getUserMfaMethods,
|
|
189
|
-
pushView,
|
|
190
|
-
setShowAuthFlow,
|
|
191
|
-
]);
|
|
192
|
-
return promptMfaAuth;
|
|
20
|
+
const { promptMfa } = useStepUpAuthentication.useStepUpAuthentication();
|
|
21
|
+
return promptMfa;
|
|
193
22
|
};
|
|
194
23
|
|
|
195
24
|
exports.usePromptMfaAuth = usePromptMfaAuth;
|
|
@@ -1,5 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
import { TokenScope } from '@dynamic-labs/sdk-api-core';
|
|
2
|
+
export type PromptMfaAuthProps = {
|
|
2
3
|
createMfaToken?: boolean;
|
|
4
|
+
requestedScopes?: TokenScope[];
|
|
3
5
|
};
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Opens the Dynamic MFA modal (passkey or TOTP) and resolves when the user completes MFA.
|
|
8
|
+
*
|
|
9
|
+
* @deprecated Use `useStepUpAuthentication().promptMfa()` instead. Step-up authentication
|
|
10
|
+
* is the generic category; MFA is one verification method. The `promptMfa` method on
|
|
11
|
+
* `useStepUpAuthentication` provides the same behavior. This hook will be removed in the
|
|
12
|
+
* next major version.
|
|
13
|
+
*
|
|
14
|
+
* @returns A function that opens the MFA flow and returns a promise resolving to the
|
|
15
|
+
* MFA token (or `undefined` when using `requestedScopes` — use `getElevatedAccessToken({ scope })` after completion).
|
|
16
|
+
*/
|
|
17
|
+
export declare const usePromptMfaAuth: () => (props?: import("../useStepUpAuthentication").PromptMfaParams | undefined) => Promise<string | undefined>;
|
|
@@ -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 { IsStepUpRequiredParams, StepUpAuthenticationState, UseStepUpAuthenticationParams, UseStepUpAuthenticationReturn, VerifyOtpParams, VerifyPasskeyMfaParams, VerifyTotpMfaParams, VerifyWalletParams, } from './useStepUpAuthentication';
|
|
2
|
+
export type { IsStepUpRequiredParams, PromptMfaParams, StepUpAuthenticationState, UseStepUpAuthenticationParams, UseStepUpAuthenticationReturn, VerifyOtpParams, VerifyPasskeyMfaParams, VerifyRecoveryCodeParams, VerifyTotpMfaParams, VerifyWalletParams, } from './useStepUpAuthentication';
|