@dynamic-labs/sdk-react-core 4.66.0 → 4.67.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/package.cjs +3 -3
  3. package/package.js +3 -3
  4. package/package.json +14 -14
  5. package/src/index.d.ts +1 -1
  6. package/src/lib/client/extension/functions/hasElevatedAccessToken/hasElevatedAccessToken.cjs +18 -0
  7. package/src/lib/client/extension/functions/hasElevatedAccessToken/hasElevatedAccessToken.d.ts +1 -0
  8. package/src/lib/client/extension/functions/hasElevatedAccessToken/hasElevatedAccessToken.js +14 -0
  9. package/src/lib/client/extension/functions/hasElevatedAccessToken/index.d.ts +1 -0
  10. package/src/lib/client/extension/index.d.ts +1 -0
  11. package/src/lib/context/DynamicContext/DynamicContext.cjs +20 -19
  12. package/src/lib/context/DynamicContext/DynamicContext.js +20 -19
  13. package/src/lib/context/DynamicContext/types/SettingsOverrides.d.ts +10 -0
  14. package/src/lib/styles/index.shadow.cjs +1 -1
  15. package/src/lib/styles/index.shadow.js +1 -1
  16. package/src/lib/utils/constants/values.cjs +2 -0
  17. package/src/lib/utils/constants/values.js +2 -0
  18. package/src/lib/utils/functions/compareChains/compareChains.cjs +1 -0
  19. package/src/lib/utils/functions/compareChains/compareChains.js +1 -0
  20. package/src/lib/utils/hooks/index.d.ts +1 -1
  21. package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.cjs +2 -1
  22. package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.d.ts +2 -1
  23. package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.js +2 -1
  24. package/src/lib/utils/hooks/useNetworkConfigurationsFromProjectSettings/useNetworkConfigurationsFromProjectSettings.cjs +7 -2
  25. package/src/lib/utils/hooks/useNetworkConfigurationsFromProjectSettings/useNetworkConfigurationsFromProjectSettings.d.ts +2 -1
  26. package/src/lib/utils/hooks/useNetworkConfigurationsFromProjectSettings/useNetworkConfigurationsFromProjectSettings.js +7 -2
  27. package/src/lib/utils/hooks/useStepUpAuthentication/index.d.ts +1 -1
  28. package/src/lib/utils/hooks/useStepUpAuthentication/useStepUpAuthentication.cjs +102 -23
  29. package/src/lib/utils/hooks/useStepUpAuthentication/useStepUpAuthentication.d.ts +35 -15
  30. package/src/lib/utils/hooks/useStepUpAuthentication/useStepUpAuthentication.js +103 -24
  31. package/src/lib/utils/hooks/useWalletConnectorNetwork/useWalletConnectorNetwork.cjs +3 -2
  32. package/src/lib/utils/hooks/useWalletConnectorNetwork/useWalletConnectorNetwork.js +3 -2
  33. package/src/lib/views/CollectUserDataView/UserDataFields/UserPhoneField/UserPhoneField.cjs +10 -6
  34. package/src/lib/views/CollectUserDataView/UserDataFields/UserPhoneField/UserPhoneField.js +11 -7
  35. package/src/lib/views/SendBalanceView/SendBalanceView.cjs +1 -0
  36. package/src/lib/views/SendBalanceView/SendBalanceView.js +1 -0
  37. package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.cjs +21 -1
  38. package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.js +21 -1
  39. package/src/lib/views/WalletList/data.cjs +1 -0
  40. package/src/lib/views/WalletList/data.d.ts +1 -1
  41. package/src/lib/views/WalletList/data.js +1 -0
@@ -10,6 +10,7 @@ const DEFAULT_NUMBER_OF_WALLETS_TO_SHOW = 10;
10
10
  // https://www.iana.org/assignments/jwt/jwt.xhtml#claims
11
11
  // https://github.com/jaredhanson/id-blockchain-claims-in-jwt/blob/main/draft.md
12
12
  const ChainEnumToVerifiedCredentialName = {
13
+ ALEO: 'aleo',
13
14
  ALGO: 'algorand',
14
15
  BTC: 'bip122', // see: https://namespaces.chainagnostic.org/bip122/caip2
15
16
  COSMOS: 'cosmos',
@@ -22,6 +23,7 @@ const ChainEnumToVerifiedCredentialName = {
22
23
  TON: 'ton',
23
24
  };
24
25
  const VerifiedCredentialNameToChainEnum = {
26
+ aleo: sdkApiCore.ChainEnum.Aleo,
25
27
  algorand: sdkApiCore.ChainEnum.Algo,
26
28
  bip122: sdkApiCore.ChainEnum.Btc,
27
29
  cosmos: sdkApiCore.ChainEnum.Cosmos,
@@ -6,6 +6,7 @@ const DEFAULT_NUMBER_OF_WALLETS_TO_SHOW = 10;
6
6
  // https://www.iana.org/assignments/jwt/jwt.xhtml#claims
7
7
  // https://github.com/jaredhanson/id-blockchain-claims-in-jwt/blob/main/draft.md
8
8
  const ChainEnumToVerifiedCredentialName = {
9
+ ALEO: 'aleo',
9
10
  ALGO: 'algorand',
10
11
  BTC: 'bip122', // see: https://namespaces.chainagnostic.org/bip122/caip2
11
12
  COSMOS: 'cosmos',
@@ -18,6 +19,7 @@ const ChainEnumToVerifiedCredentialName = {
18
19
  TON: 'ton',
19
20
  };
20
21
  const VerifiedCredentialNameToChainEnum = {
22
+ aleo: ChainEnum.Aleo,
21
23
  algorand: ChainEnum.Algo,
22
24
  bip122: ChainEnum.Btc,
23
25
  cosmos: ChainEnum.Cosmos,
@@ -4,6 +4,7 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  const synonyms = {
7
+ aleo: 'ALEO',
7
8
  bip122: 'BTC',
8
9
  bitcoin: 'BTC',
9
10
  eip155: 'EVM',
@@ -1,5 +1,6 @@
1
1
  'use client'
2
2
  const synonyms = {
3
+ aleo: 'ALEO',
3
4
  bip122: 'BTC',
4
5
  bitcoin: 'BTC',
5
6
  eip155: 'EVM',
@@ -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 { StepUpAuthenticationState, UseStepUpAuthenticationParams, UseStepUpAuthenticationReturn, VerifyOtpParams, VerifyWalletParams, } from './useStepUpAuthentication';
112
+ export type { IsStepUpRequiredParams, StepUpAuthenticationState, UseStepUpAuthenticationParams, UseStepUpAuthenticationReturn, VerifyOtpParams, VerifyPasskeyMfaParams, VerifyTotpMfaParams, VerifyWalletParams, } from './useStepUpAuthentication';
@@ -545,7 +545,7 @@ const useDynamicWaas = () => {
545
545
  });
546
546
  yield refresh();
547
547
  });
548
- const upgradeToDynamicWaas = React.useCallback((_j) => _tslib.__awaiter(void 0, [_j], void 0, function* ({ privateKey, wallet, }) {
548
+ const upgradeToDynamicWaas = React.useCallback((_j) => _tslib.__awaiter(void 0, [_j], void 0, function* ({ privateKey, wallet, password, }) {
549
549
  isUpgrading.current = true;
550
550
  if (!primaryWallet) {
551
551
  throw new utils.DynamicError('Primary wallet not found');
@@ -568,6 +568,7 @@ const useDynamicWaas = () => {
568
568
  yield walletConnector.importPrivateKey({
569
569
  chainName,
570
570
  legacyWalletId: normalizedWalletId,
571
+ password,
571
572
  privateKey,
572
573
  publicAddressCheck: wallet.address,
573
574
  });
@@ -54,8 +54,9 @@ export declare const useDynamicWaas: () => {
54
54
  needsSettingsProcessing: boolean;
55
55
  processSignOnWalletSettings: () => Promise<void>;
56
56
  shouldInitializeWaas: boolean;
57
- upgradeToDynamicWaas: ({ privateKey, wallet, }: {
57
+ upgradeToDynamicWaas: ({ privateKey, wallet, password, }: {
58
58
  privateKey: string;
59
59
  wallet: Wallet<WalletConnectorCore.WalletConnector>;
60
+ password?: string;
60
61
  }) => Promise<void>;
61
62
  };
@@ -541,7 +541,7 @@ const useDynamicWaas = () => {
541
541
  });
542
542
  yield refresh();
543
543
  });
544
- const upgradeToDynamicWaas = useCallback((_j) => __awaiter(void 0, [_j], void 0, function* ({ privateKey, wallet, }) {
544
+ const upgradeToDynamicWaas = useCallback((_j) => __awaiter(void 0, [_j], void 0, function* ({ privateKey, wallet, password, }) {
545
545
  isUpgrading.current = true;
546
546
  if (!primaryWallet) {
547
547
  throw new DynamicError('Primary wallet not found');
@@ -564,6 +564,7 @@ const useDynamicWaas = () => {
564
564
  yield walletConnector.importPrivateKey({
565
565
  chainName,
566
566
  legacyWalletId: normalizedWalletId,
567
+ password,
567
568
  privateKey,
568
569
  publicAddressCheck: wallet.address,
569
570
  });
@@ -5,8 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var React = require('react');
7
7
 
8
- const useNetworkConfigurationsFromProjectSettings = ({ projectSettings, cosmosNetworkOverrides, evmNetworksOverrides, solanaNetworksOverrides, tronNetworksOverrides, aptosNetworksOverrides, stellarNetworksOverrides, tonNetworksOverrides, bitcoinNetworksOverrides, }) => React.useMemo(() => {
9
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
8
+ const useNetworkConfigurationsFromProjectSettings = ({ projectSettings, aleoNetworksOverrides, cosmosNetworkOverrides, evmNetworksOverrides, solanaNetworksOverrides, tronNetworksOverrides, aptosNetworksOverrides, stellarNetworksOverrides, tonNetworksOverrides, bitcoinNetworksOverrides, }) => React.useMemo(() => {
9
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
10
10
  const networks = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.networks;
11
11
  if (!networks)
12
12
  return {};
@@ -21,6 +21,7 @@ const useNetworkConfigurationsFromProjectSettings = ({ projectSettings, cosmosNe
21
21
  const aptos = networks.find((configurations) => configurations.chainName === 'aptos');
22
22
  const ton = networks.find((configurations) => configurations.chainName === 'ton');
23
23
  const bitcoin = networks.find((configurations) => configurations.chainName === 'bitcoin');
24
+ const aleo = networks.find((configurations) => configurations.chainName === 'aleo');
24
25
  let cosmosNetworks = (_a = cosmos === null || cosmos === void 0 ? void 0 : cosmos.networks) === null || _a === void 0 ? void 0 : _a.map((net) => createNetwork(net, Number.parseInt));
25
26
  cosmosNetworks = overrideNetworks(cosmosNetworkOverrides, cosmosNetworks);
26
27
  let evmNetworks = (_b = evm === null || evm === void 0 ? void 0 : evm.networks) === null || _b === void 0 ? void 0 : _b.map((net) => createNetwork(net, Number.parseInt));
@@ -48,7 +49,10 @@ const useNetworkConfigurationsFromProjectSettings = ({ projectSettings, cosmosNe
48
49
  stellarNetworks = overrideNetworks(stellarNetworksOverrides, stellarNetworks);
49
50
  let bitcoinNetworks = (_l = bitcoin === null || bitcoin === void 0 ? void 0 : bitcoin.networks) === null || _l === void 0 ? void 0 : _l.map((net) => createNetwork(net, Number.parseInt));
50
51
  bitcoinNetworks = overrideNetworks(bitcoinNetworksOverrides, bitcoinNetworks);
52
+ let aleoNetworks = (_m = aleo === null || aleo === void 0 ? void 0 : aleo.networks) === null || _m === void 0 ? void 0 : _m.map((net) => createNetwork(net));
53
+ aleoNetworks = overrideNetworks(aleoNetworksOverrides, aleoNetworks);
51
54
  const networkConfigurations = {
55
+ aleo: aleoNetworks,
52
56
  aptos: aptosNetworks,
53
57
  bitcoin: bitcoinNetworks,
54
58
  cosmos: cosmosNetworks,
@@ -64,6 +68,7 @@ const useNetworkConfigurationsFromProjectSettings = ({ projectSettings, cosmosNe
64
68
  return networkConfigurations;
65
69
  }, [
66
70
  projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.networks,
71
+ aleoNetworksOverrides,
67
72
  cosmosNetworkOverrides,
68
73
  evmNetworksOverrides,
69
74
  solanaNetworksOverrides,
@@ -2,6 +2,7 @@ import type { ProjectSettings } from '@dynamic-labs/sdk-api-core';
2
2
  import type { NetworksOverrides } from '../../../context/DynamicContext';
3
3
  type UseNetworkConfigurationsFromProjectSettingsProps = {
4
4
  projectSettings: ProjectSettings | undefined;
5
+ aleoNetworksOverrides?: NetworksOverrides;
5
6
  evmNetworksOverrides?: NetworksOverrides;
6
7
  cosmosNetworkOverrides?: NetworksOverrides;
7
8
  solanaNetworksOverrides?: NetworksOverrides;
@@ -11,5 +12,5 @@ type UseNetworkConfigurationsFromProjectSettingsProps = {
11
12
  tonNetworksOverrides?: NetworksOverrides;
12
13
  bitcoinNetworksOverrides?: NetworksOverrides;
13
14
  };
14
- export declare const useNetworkConfigurationsFromProjectSettings: ({ projectSettings, cosmosNetworkOverrides, evmNetworksOverrides, solanaNetworksOverrides, tronNetworksOverrides, aptosNetworksOverrides, stellarNetworksOverrides, tonNetworksOverrides, bitcoinNetworksOverrides, }: UseNetworkConfigurationsFromProjectSettingsProps) => {};
15
+ export declare const useNetworkConfigurationsFromProjectSettings: ({ projectSettings, aleoNetworksOverrides, cosmosNetworkOverrides, evmNetworksOverrides, solanaNetworksOverrides, tronNetworksOverrides, aptosNetworksOverrides, stellarNetworksOverrides, tonNetworksOverrides, bitcoinNetworksOverrides, }: UseNetworkConfigurationsFromProjectSettingsProps) => {};
15
16
  export {};
@@ -1,8 +1,8 @@
1
1
  'use client'
2
2
  import { useMemo } from 'react';
3
3
 
4
- const useNetworkConfigurationsFromProjectSettings = ({ projectSettings, cosmosNetworkOverrides, evmNetworksOverrides, solanaNetworksOverrides, tronNetworksOverrides, aptosNetworksOverrides, stellarNetworksOverrides, tonNetworksOverrides, bitcoinNetworksOverrides, }) => useMemo(() => {
5
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
4
+ const useNetworkConfigurationsFromProjectSettings = ({ projectSettings, aleoNetworksOverrides, cosmosNetworkOverrides, evmNetworksOverrides, solanaNetworksOverrides, tronNetworksOverrides, aptosNetworksOverrides, stellarNetworksOverrides, tonNetworksOverrides, bitcoinNetworksOverrides, }) => useMemo(() => {
5
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
6
6
  const networks = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.networks;
7
7
  if (!networks)
8
8
  return {};
@@ -17,6 +17,7 @@ const useNetworkConfigurationsFromProjectSettings = ({ projectSettings, cosmosNe
17
17
  const aptos = networks.find((configurations) => configurations.chainName === 'aptos');
18
18
  const ton = networks.find((configurations) => configurations.chainName === 'ton');
19
19
  const bitcoin = networks.find((configurations) => configurations.chainName === 'bitcoin');
20
+ const aleo = networks.find((configurations) => configurations.chainName === 'aleo');
20
21
  let cosmosNetworks = (_a = cosmos === null || cosmos === void 0 ? void 0 : cosmos.networks) === null || _a === void 0 ? void 0 : _a.map((net) => createNetwork(net, Number.parseInt));
21
22
  cosmosNetworks = overrideNetworks(cosmosNetworkOverrides, cosmosNetworks);
22
23
  let evmNetworks = (_b = evm === null || evm === void 0 ? void 0 : evm.networks) === null || _b === void 0 ? void 0 : _b.map((net) => createNetwork(net, Number.parseInt));
@@ -44,7 +45,10 @@ const useNetworkConfigurationsFromProjectSettings = ({ projectSettings, cosmosNe
44
45
  stellarNetworks = overrideNetworks(stellarNetworksOverrides, stellarNetworks);
45
46
  let bitcoinNetworks = (_l = bitcoin === null || bitcoin === void 0 ? void 0 : bitcoin.networks) === null || _l === void 0 ? void 0 : _l.map((net) => createNetwork(net, Number.parseInt));
46
47
  bitcoinNetworks = overrideNetworks(bitcoinNetworksOverrides, bitcoinNetworks);
48
+ let aleoNetworks = (_m = aleo === null || aleo === void 0 ? void 0 : aleo.networks) === null || _m === void 0 ? void 0 : _m.map((net) => createNetwork(net));
49
+ aleoNetworks = overrideNetworks(aleoNetworksOverrides, aleoNetworks);
47
50
  const networkConfigurations = {
51
+ aleo: aleoNetworks,
48
52
  aptos: aptosNetworks,
49
53
  bitcoin: bitcoinNetworks,
50
54
  cosmos: cosmosNetworks,
@@ -60,6 +64,7 @@ const useNetworkConfigurationsFromProjectSettings = ({ projectSettings, cosmosNe
60
64
  return networkConfigurations;
61
65
  }, [
62
66
  projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.networks,
67
+ aleoNetworksOverrides,
63
68
  cosmosNetworkOverrides,
64
69
  evmNetworksOverrides,
65
70
  solanaNetworksOverrides,
@@ -1,2 +1,2 @@
1
1
  export { useStepUpAuthentication } from './useStepUpAuthentication';
2
- export type { StepUpAuthenticationState, UseStepUpAuthenticationParams, UseStepUpAuthenticationReturn, VerifyOtpParams, VerifyWalletParams, } from './useStepUpAuthentication';
2
+ export type { IsStepUpRequiredParams, StepUpAuthenticationState, UseStepUpAuthenticationParams, UseStepUpAuthenticationReturn, VerifyOtpParams, VerifyPasskeyMfaParams, VerifyTotpMfaParams, VerifyWalletParams, } from './useStepUpAuthentication';
@@ -24,12 +24,13 @@ 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
31
  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');
33
34
  var useConnectAndSign = require('../authenticationHooks/useConnectAndSign/useConnectAndSign.cjs');
34
35
  var UserWalletsContext = require('../../../context/UserWalletsContext/UserWalletsContext.cjs');
35
36
 
@@ -72,47 +73,55 @@ const dispatchOtp = (credential) => _tslib.__awaiter(void 0, void 0, void 0, fun
72
73
  : sendSmsOtp(credential);
73
74
  });
74
75
  /**
75
- * Perform step-up authentication for an already-authenticated user via OTP.
76
+ * Perform step-up authentication for an already-authenticated user.
76
77
  *
77
- * Automatically selects the first sign-in enabled email or SMS credential on
78
- * the user, or targets a specific credential when `credentialId` is provided.
78
+ * Supports multiple verification methods:
79
+ * - **OTP** (email/SMS): `sendOtp()` then `verifyOtp()`
80
+ * - **Wallet**: `verifyWallet()` for wallet signature verification
81
+ * - **Passkey MFA**: `verifyPasskeyMfa()` for passkey-based MFA
82
+ * - **TOTP MFA**: `verifyTotpMfa()` for authenticator app codes
79
83
  *
80
- * @param params.credentialId - Optional id of a specific verified credential to
81
- * use. Must be an email or SMS credential. Defaults to the first sign-in
82
- * enabled email or SMS credential on the authenticated user.
84
+ * For OTP and wallet methods, automatically selects the first sign-in enabled
85
+ * credential, or targets a specific one when `credentialId` is provided.
83
86
  *
84
- * @returns `sendOtp` sends the OTP to the resolved credential.
85
- * @returns `verifyOtp` verifies the OTP code supplied by the user.
86
- * @returns `state` current loading / error / otpVerification state.
87
- * @returns `resetState` – resets state back to its initial value.
87
+ * @param params.credentialId - Optional id of a specific verified credential or
88
+ * wallet to use. For OTP, must be an email or SMS credential. Defaults to the
89
+ * first sign-in enabled email or SMS credential on the authenticated user.
88
90
  *
89
91
  * @example
90
92
  * ```tsx
91
- * const { sendOtp, verifyOtp, state } = useStepUpAuthentication();
92
- *
93
- * // Step 1: send OTP
93
+ * // OTP flow
94
+ * const { sendOtp, verifyOtp } = useStepUpAuthentication();
94
95
  * await sendOtp();
96
+ * const result = await verifyOtp({ verificationToken: '123456', requestedScopes: ['wallet:export'] });
97
+ *
98
+ * // Passkey MFA flow
99
+ * const { verifyPasskeyMfa } = useStepUpAuthentication();
100
+ * const result = await verifyPasskeyMfa({ requestedScopes: ['wallet:export'] });
95
101
  *
96
- * // Step 2: after the user enters the code
97
- * const result = await verifyOtp({ verificationToken: '123456' });
102
+ * // TOTP MFA flow
103
+ * const { verifyTotpMfa } = useStepUpAuthentication();
104
+ * const result = await verifyTotpMfa({ code: '123456', requestedScopes: ['wallet:export'] });
98
105
  * ```
99
106
  */
100
107
  const useStepUpAuthentication = ({ credentialId, } = {}) => {
101
108
  const user = useUser.useUser();
109
+ const environmentId = dynamicContextProps.useEnvironmentId();
102
110
  const [state, setState] = React.useState(INITIAL_STATE);
103
111
  const connectAndSign = useConnectAndSign.useConnectAndSign();
104
112
  const { userWallets } = UserWalletsContext.useInternalUserWallets();
105
113
  // Ref keeps the latest otpVerification available inside the verifyOtp
106
114
  // callback without creating a stale closure over state.
107
115
  const otpVerificationRef = React.useRef(null);
116
+ const isStepUpRequired = React.useCallback(({ scope }) => !hasElevatedAccessToken.hasElevatedAccessToken(scope), []);
108
117
  const resetState = React.useCallback(() => {
109
118
  otpVerificationRef.current = null;
110
119
  setState(INITIAL_STATE);
111
120
  }, []);
112
121
  const setError = React.useCallback((errorMessage) => {
113
122
  setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
114
- logger.logger.error(errorMessage);
115
- }, []);
123
+ logger.logger.error(errorMessage, { environmentId, userId: user === null || user === void 0 ? void 0 : user.id });
124
+ }, [environmentId, user === null || user === void 0 ? void 0 : user.id]);
116
125
  const sendOtp = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
117
126
  const credentials = user === null || user === void 0 ? void 0 : user.verifiedCredentials;
118
127
  if (!(credentials === null || credentials === void 0 ? void 0 : credentials.length)) {
@@ -138,10 +147,20 @@ const useStepUpAuthentication = ({ credentialId, } = {}) => {
138
147
  catch (error) {
139
148
  const errorMessage = error instanceof Error ? error.message : 'Failed to send OTP';
140
149
  setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
141
- logger.logger.error('Failed to send OTP for step-up authentication', { error });
150
+ logger.logger.error('Failed to send OTP for step-up authentication', {
151
+ environmentId,
152
+ error,
153
+ userId: user === null || user === void 0 ? void 0 : user.id,
154
+ });
142
155
  return null;
143
156
  }
144
- }), [credentialId, setError, user === null || user === void 0 ? void 0 : user.verifiedCredentials]);
157
+ }), [
158
+ credentialId,
159
+ environmentId,
160
+ setError,
161
+ user === null || user === void 0 ? void 0 : user.id,
162
+ user === null || user === void 0 ? void 0 : user.verifiedCredentials,
163
+ ]);
145
164
  const verifyOtp = React.useCallback((_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ requestedScopes, verificationToken, }) {
146
165
  const otpVerification = otpVerificationRef.current;
147
166
  if (!otpVerification) {
@@ -162,11 +181,13 @@ const useStepUpAuthentication = ({ credentialId, } = {}) => {
162
181
  const errorMessage = error instanceof Error ? error.message : 'Failed to verify OTP';
163
182
  setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
164
183
  logger.logger.error('Failed to verify OTP for step-up authentication', {
184
+ environmentId,
165
185
  error,
186
+ userId: user === null || user === void 0 ? void 0 : user.id,
166
187
  });
167
188
  return null;
168
189
  }
169
- }), [setError]);
190
+ }), [environmentId, setError, user === null || user === void 0 ? void 0 : user.id]);
170
191
  const verifyWallet = React.useCallback((_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ requestedScopes }) {
171
192
  setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
172
193
  const wallet = userWallets.find((w) => w.id === credentialId);
@@ -187,11 +208,69 @@ const useStepUpAuthentication = ({ credentialId, } = {}) => {
187
208
  : 'Failed to verify wallet for step-up authentication';
188
209
  setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
189
210
  logger.logger.error('Failed to verify wallet for step-up authentication', {
211
+ environmentId,
190
212
  error,
213
+ userId: user === null || user === void 0 ? void 0 : user.id,
214
+ });
215
+ }
216
+ }), [
217
+ connectAndSign,
218
+ credentialId,
219
+ environmentId,
220
+ setError,
221
+ user === null || user === void 0 ? void 0 : user.id,
222
+ userWallets,
223
+ ]);
224
+ const verifyPasskeyMfa = React.useCallback((_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ requestedScopes, }) {
225
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
226
+ try {
227
+ // requestedScopes is available in @dynamic-labs-sdk/client >= 0.14.0
228
+ const response = yield client.authenticatePasskeyMFA({
229
+ requestedScopes,
191
230
  });
231
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: false })));
232
+ return response;
233
+ }
234
+ catch (error) {
235
+ const errorMessage = error instanceof Error
236
+ ? error.message
237
+ : 'Failed to authenticate passkey for step-up authentication';
238
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
239
+ logger.logger.error('Failed to authenticate passkey for step-up authentication', { environmentId, error, userId: user === null || user === void 0 ? void 0 : user.id });
240
+ return null;
241
+ }
242
+ }), [environmentId, user === null || user === void 0 ? void 0 : user.id]);
243
+ const verifyTotpMfa = React.useCallback((_d) => _tslib.__awaiter(void 0, [_d], void 0, function* ({ code, deviceId, requestedScopes, }) {
244
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
245
+ try {
246
+ // requestedScopes is available in @dynamic-labs-sdk/client >= 0.14.0
247
+ const response = yield client.authenticateTotpMfaDevice({
248
+ code,
249
+ deviceId,
250
+ requestedScopes,
251
+ });
252
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: false })));
253
+ return response;
254
+ }
255
+ catch (error) {
256
+ const errorMessage = error instanceof Error
257
+ ? error.message
258
+ : 'Failed to authenticate TOTP device for step-up authentication';
259
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
260
+ logger.logger.error('Failed to authenticate TOTP device for step-up authentication', { environmentId, error, userId: user === null || user === void 0 ? void 0 : user.id });
261
+ return null;
192
262
  }
193
- }), [connectAndSign, credentialId, setError, userWallets]);
194
- return { resetState, sendOtp, state, verifyOtp, verifyWallet };
263
+ }), [environmentId, user === null || user === void 0 ? void 0 : user.id]);
264
+ return {
265
+ isStepUpRequired,
266
+ resetState,
267
+ sendOtp,
268
+ state,
269
+ verifyOtp,
270
+ verifyPasskeyMfa,
271
+ verifyTotpMfa,
272
+ verifyWallet,
273
+ };
195
274
  };
196
275
 
197
276
  exports.useStepUpAuthentication = useStepUpAuthentication;
@@ -12,40 +12,60 @@ export type VerifyOtpParams = {
12
12
  export type VerifyWalletParams = {
13
13
  requestedScopes?: TokenScope[];
14
14
  };
15
+ export type VerifyPasskeyMfaParams = {
16
+ requestedScopes?: TokenScope[];
17
+ };
18
+ export type VerifyTotpMfaParams = {
19
+ code: string;
20
+ deviceId?: string;
21
+ requestedScopes?: TokenScope[];
22
+ };
23
+ export type IsStepUpRequiredParams = {
24
+ scope: TokenScope;
25
+ };
15
26
  export type UseStepUpAuthenticationParams = {
16
27
  credentialId?: string;
17
28
  };
18
29
  export type UseStepUpAuthenticationReturn = {
30
+ isStepUpRequired: (params: IsStepUpRequiredParams) => boolean;
19
31
  resetState: () => void;
20
32
  sendOtp: () => Promise<OTPVerification | null>;
21
33
  state: StepUpAuthenticationState;
22
34
  verifyOtp: (params: VerifyOtpParams) => Promise<VerifyResponse | null>;
35
+ verifyPasskeyMfa: (params: VerifyPasskeyMfaParams) => Promise<VerifyResponse | null>;
36
+ verifyTotpMfa: (params: VerifyTotpMfaParams) => Promise<VerifyResponse | null>;
23
37
  verifyWallet: (params: VerifyWalletParams) => Promise<void>;
24
38
  };
25
39
  /**
26
- * Perform step-up authentication for an already-authenticated user via OTP.
40
+ * Perform step-up authentication for an already-authenticated user.
27
41
  *
28
- * Automatically selects the first sign-in enabled email or SMS credential on
29
- * the user, or targets a specific credential when `credentialId` is provided.
42
+ * Supports multiple verification methods:
43
+ * - **OTP** (email/SMS): `sendOtp()` then `verifyOtp()`
44
+ * - **Wallet**: `verifyWallet()` for wallet signature verification
45
+ * - **Passkey MFA**: `verifyPasskeyMfa()` for passkey-based MFA
46
+ * - **TOTP MFA**: `verifyTotpMfa()` for authenticator app codes
30
47
  *
31
- * @param params.credentialId - Optional id of a specific verified credential to
32
- * use. Must be an email or SMS credential. Defaults to the first sign-in
33
- * enabled email or SMS credential on the authenticated user.
48
+ * For OTP and wallet methods, automatically selects the first sign-in enabled
49
+ * credential, or targets a specific one when `credentialId` is provided.
34
50
  *
35
- * @returns `sendOtp` sends the OTP to the resolved credential.
36
- * @returns `verifyOtp` verifies the OTP code supplied by the user.
37
- * @returns `state` current loading / error / otpVerification state.
38
- * @returns `resetState` – resets state back to its initial value.
51
+ * @param params.credentialId - Optional id of a specific verified credential or
52
+ * wallet to use. For OTP, must be an email or SMS credential. Defaults to the
53
+ * first sign-in enabled email or SMS credential on the authenticated user.
39
54
  *
40
55
  * @example
41
56
  * ```tsx
42
- * const { sendOtp, verifyOtp, state } = useStepUpAuthentication();
43
- *
44
- * // Step 1: send OTP
57
+ * // OTP flow
58
+ * const { sendOtp, verifyOtp } = useStepUpAuthentication();
45
59
  * await sendOtp();
60
+ * const result = await verifyOtp({ verificationToken: '123456', requestedScopes: ['wallet:export'] });
61
+ *
62
+ * // Passkey MFA flow
63
+ * const { verifyPasskeyMfa } = useStepUpAuthentication();
64
+ * const result = await verifyPasskeyMfa({ requestedScopes: ['wallet:export'] });
46
65
  *
47
- * // Step 2: after the user enters the code
48
- * const result = await verifyOtp({ verificationToken: '123456' });
66
+ * // TOTP MFA flow
67
+ * const { verifyTotpMfa } = useStepUpAuthentication();
68
+ * const result = await verifyTotpMfa({ code: '123456', requestedScopes: ['wallet:export'] });
49
69
  * ```
50
70
  */
51
71
  export declare const useStepUpAuthentication: ({ credentialId, }?: UseStepUpAuthenticationParams) => UseStepUpAuthenticationReturn;