@dynamic-labs/sdk-react-core 4.63.1 → 4.65.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 (51) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/package.cjs +2 -2
  3. package/package.js +2 -2
  4. package/package.json +13 -13
  5. package/src/index.cjs +2 -0
  6. package/src/index.d.ts +2 -1
  7. package/src/index.js +1 -0
  8. package/src/lib/components/LegacySafariCssOverrides/LegacySafariCssOverrides.cjs +1 -1
  9. package/src/lib/components/LegacySafariCssOverrides/LegacySafariCssOverrides.d.ts +5 -1
  10. package/src/lib/components/LegacySafariCssOverrides/LegacySafariCssOverrides.js +1 -1
  11. package/src/lib/components/ShadowDOM/ShadowDOM.cjs +6 -6
  12. package/src/lib/components/ShadowDOM/ShadowDOM.d.ts +4 -1
  13. package/src/lib/components/ShadowDOM/ShadowDOM.js +6 -6
  14. package/src/lib/context/DynamicContext/DynamicContext.cjs +4 -2
  15. package/src/lib/context/DynamicContext/DynamicContext.js +4 -2
  16. package/src/lib/context/DynamicContext/types/DynamicContextProps.d.ts +6 -0
  17. package/src/lib/context/DynamicContext/types/IDynamicContext.d.ts +1 -0
  18. package/src/lib/context/DynamicContext/types/IInternalDynamicContext.d.ts +5 -1
  19. package/src/lib/context/ThemeContext/ThemeContext.cjs +3 -3
  20. package/src/lib/context/ThemeContext/ThemeContext.d.ts +1 -0
  21. package/src/lib/context/ThemeContext/ThemeContext.js +3 -3
  22. package/src/lib/context/ThemeContext/utils/stylesheetBuilder/stylesheetBuilder.cjs +8 -2
  23. package/src/lib/context/ThemeContext/utils/stylesheetBuilder/stylesheetBuilder.d.ts +2 -2
  24. package/src/lib/context/ThemeContext/utils/stylesheetBuilder/stylesheetBuilder.js +8 -2
  25. package/src/lib/data/api/wallets/wallets.cjs +62 -11
  26. package/src/lib/data/api/wallets/wallets.d.ts +1 -0
  27. package/src/lib/data/api/wallets/wallets.js +62 -12
  28. package/src/lib/shared/types/connectionAndSignature.d.ts +2 -1
  29. package/src/lib/shared/types/wallets.d.ts +2 -1
  30. package/src/lib/utils/functions/compareChains/compareChains.cjs +1 -0
  31. package/src/lib/utils/functions/compareChains/compareChains.js +1 -0
  32. package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.cjs +6 -5
  33. package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.d.ts +3 -1
  34. package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.js +6 -5
  35. package/src/lib/utils/hooks/index.d.ts +2 -0
  36. package/src/lib/utils/hooks/useClientSessionKeys/useClientSessionKeys.cjs +20 -1
  37. package/src/lib/utils/hooks/useClientSessionKeys/useClientSessionKeys.js +20 -1
  38. package/src/lib/utils/hooks/useStepUpAuthentication/index.d.ts +2 -0
  39. package/src/lib/utils/hooks/useStepUpAuthentication/useStepUpAuthentication.cjs +197 -0
  40. package/src/lib/utils/hooks/useStepUpAuthentication/useStepUpAuthentication.d.ts +51 -0
  41. package/src/lib/utils/hooks/useStepUpAuthentication/useStepUpAuthentication.js +193 -0
  42. package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.cjs +8 -3
  43. package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.d.ts +1 -1
  44. package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.js +9 -4
  45. package/src/lib/utils/hooks/useWalletPassword/useWalletPassword.cjs +30 -0
  46. package/src/lib/utils/hooks/useWalletPassword/useWalletPassword.d.ts +6 -0
  47. package/src/lib/utils/hooks/useWalletPassword/useWalletPassword.js +30 -0
  48. package/src/lib/views/SendBalanceView/SendBalanceView.cjs +1 -0
  49. package/src/lib/views/SendBalanceView/SendBalanceView.js +1 -0
  50. package/src/lib/widgets/DynamicWidget/views/AccountAndSecuritySettingsView/MfaSection/MfaSection.cjs +17 -21
  51. package/src/lib/widgets/DynamicWidget/views/AccountAndSecuritySettingsView/MfaSection/MfaSection.js +17 -21
@@ -0,0 +1,197 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../../../_virtual/_tslib.cjs');
7
+ var React = require('react');
8
+ var client = require('@dynamic-labs-sdk/client');
9
+ var sdkApiCore = require('@dynamic-labs/sdk-api-core');
10
+ require('@dynamic-labs-sdk/client/core');
11
+ require('../../../client/client.cjs');
12
+ require('../../../config/ApiEndpoint.cjs');
13
+ require('@dynamic-labs/iconic');
14
+ require('@dynamic-labs/wallet-connector-core');
15
+ require('react/jsx-runtime');
16
+ require('../../../context/ViewContext/ViewContext.cjs');
17
+ var logger = require('../../../shared/logger.cjs');
18
+ require('@dynamic-labs/wallet-book');
19
+ require('@dynamic-labs/utils');
20
+ require('../../constants/colors.cjs');
21
+ require('../../constants/values.cjs');
22
+ require('../../../shared/consts/index.cjs');
23
+ require('@dynamic-labs/multi-wallet');
24
+ require('react-international-phone');
25
+ require('../../../store/state/nonce/nonce.cjs');
26
+ require('@dynamic-labs/locale');
27
+ require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
28
+ require('../../../store/state/primaryWalletId/primaryWalletId.cjs');
29
+ require('../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
30
+ require('../../functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.cjs');
31
+ require('../../../events/dynamicEvents.cjs');
32
+ var useUser = require('../../../client/extension/user/useUser/useUser.cjs');
33
+ var useConnectAndSign = require('../authenticationHooks/useConnectAndSign/useConnectAndSign.cjs');
34
+ var UserWalletsContext = require('../../../context/UserWalletsContext/UserWalletsContext.cjs');
35
+
36
+ const INITIAL_STATE = {
37
+ error: null,
38
+ isLoading: false,
39
+ otpVerification: null,
40
+ };
41
+ const isCountryCode = (value) => value !== undefined && value in client.supportedCountries;
42
+ const isOtpCapableCredential = (cred) => cred.format === sdkApiCore.JwtVerifiedCredentialFormatEnum.Email ||
43
+ cred.format === sdkApiCore.JwtVerifiedCredentialFormatEnum.PhoneNumber;
44
+ const resolveTargetCredential = (credentials, credentialId) => {
45
+ var _a, _b;
46
+ if (credentialId) {
47
+ return ((_a = credentials.find((cred) => cred.id === credentialId)) !== null && _a !== void 0 ? _a : `Credential with id "${credentialId}" not found`);
48
+ }
49
+ return ((_b = credentials.find((cred) => cred.signInEnabled && isOtpCapableCredential(cred))) !== null && _b !== void 0 ? _b : 'No sign-in enabled email or SMS credential found for step-up authentication');
50
+ };
51
+ const sendEmailOtp = (credential) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
52
+ if (!credential.email) {
53
+ throw new Error('Email credential is missing email address');
54
+ }
55
+ return client.sendEmailOTP({ email: credential.email });
56
+ });
57
+ const sendSmsOtp = (credential) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
58
+ var _a;
59
+ 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);
61
+ const isoCountryCode = isCountryCode(credential.isoCountryCode)
62
+ ? credential.isoCountryCode
63
+ : matchedCountryCode;
64
+ if (!credential.phoneNumber || !isoCountryCode) {
65
+ throw new Error('SMS credential is missing phone number or country code');
66
+ }
67
+ return client.sendSmsOTP({ isoCountryCode, phoneNumber: credential.phoneNumber });
68
+ });
69
+ const dispatchOtp = (credential) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
70
+ return credential.format === sdkApiCore.JwtVerifiedCredentialFormatEnum.Email
71
+ ? sendEmailOtp(credential)
72
+ : sendSmsOtp(credential);
73
+ });
74
+ /**
75
+ * Perform step-up authentication for an already-authenticated user via OTP.
76
+ *
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.
79
+ *
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.
83
+ *
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.
88
+ *
89
+ * @example
90
+ * ```tsx
91
+ * const { sendOtp, verifyOtp, state } = useStepUpAuthentication();
92
+ *
93
+ * // Step 1: send OTP
94
+ * await sendOtp();
95
+ *
96
+ * // Step 2: after the user enters the code
97
+ * const result = await verifyOtp({ verificationToken: '123456' });
98
+ * ```
99
+ */
100
+ const useStepUpAuthentication = ({ credentialId, } = {}) => {
101
+ const user = useUser.useUser();
102
+ const [state, setState] = React.useState(INITIAL_STATE);
103
+ const connectAndSign = useConnectAndSign.useConnectAndSign();
104
+ const { userWallets } = UserWalletsContext.useInternalUserWallets();
105
+ // Ref keeps the latest otpVerification available inside the verifyOtp
106
+ // callback without creating a stale closure over state.
107
+ const otpVerificationRef = React.useRef(null);
108
+ const resetState = React.useCallback(() => {
109
+ otpVerificationRef.current = null;
110
+ setState(INITIAL_STATE);
111
+ }, []);
112
+ const setError = React.useCallback((errorMessage) => {
113
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
114
+ logger.logger.error(errorMessage);
115
+ }, []);
116
+ const sendOtp = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
117
+ const credentials = user === null || user === void 0 ? void 0 : user.verifiedCredentials;
118
+ if (!(credentials === null || credentials === void 0 ? void 0 : credentials.length)) {
119
+ setError('No verified credentials found for the authenticated user');
120
+ return null;
121
+ }
122
+ const result = resolveTargetCredential(credentials, credentialId);
123
+ if (typeof result === 'string') {
124
+ setError(result);
125
+ return null;
126
+ }
127
+ if (!isOtpCapableCredential(result)) {
128
+ setError(`Credential format "${result.format}" does not support OTP verification. Only email and SMS credentials are supported`);
129
+ return null;
130
+ }
131
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
132
+ try {
133
+ const otpVerification = yield dispatchOtp(result);
134
+ otpVerificationRef.current = otpVerification;
135
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: false, otpVerification })));
136
+ return otpVerification;
137
+ }
138
+ catch (error) {
139
+ const errorMessage = error instanceof Error ? error.message : 'Failed to send OTP';
140
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
141
+ logger.logger.error('Failed to send OTP for step-up authentication', { error });
142
+ return null;
143
+ }
144
+ }), [credentialId, setError, user === null || user === void 0 ? void 0 : user.verifiedCredentials]);
145
+ const verifyOtp = React.useCallback((_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ requestedScopes, verificationToken, }) {
146
+ const otpVerification = otpVerificationRef.current;
147
+ if (!otpVerification) {
148
+ setError('OTP verification has not been initiated. Call sendOtp() first');
149
+ return null;
150
+ }
151
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
152
+ try {
153
+ const response = yield client.verifyOTP({
154
+ otpVerification,
155
+ requestedScopes,
156
+ verificationToken,
157
+ });
158
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: false })));
159
+ return response;
160
+ }
161
+ catch (error) {
162
+ const errorMessage = error instanceof Error ? error.message : 'Failed to verify OTP';
163
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
164
+ logger.logger.error('Failed to verify OTP for step-up authentication', {
165
+ error,
166
+ });
167
+ return null;
168
+ }
169
+ }), [setError]);
170
+ const verifyWallet = React.useCallback((_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ requestedScopes }) {
171
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
172
+ const wallet = userWallets.find((w) => w.id === credentialId);
173
+ if (!wallet) {
174
+ setError(`Wallet with id "${credentialId}" not found`);
175
+ return;
176
+ }
177
+ try {
178
+ yield connectAndSign({
179
+ requestedScopes,
180
+ walletConnector: wallet.connector,
181
+ });
182
+ setState((prev) => (Object.assign(Object.assign({}, prev), { isLoading: false })));
183
+ }
184
+ catch (error) {
185
+ const errorMessage = error instanceof Error
186
+ ? error.message
187
+ : 'Failed to verify wallet for step-up authentication';
188
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
189
+ logger.logger.error('Failed to verify wallet for step-up authentication', {
190
+ error,
191
+ });
192
+ }
193
+ }), [connectAndSign, credentialId, setError, userWallets]);
194
+ return { resetState, sendOtp, state, verifyOtp, verifyWallet };
195
+ };
196
+
197
+ exports.useStepUpAuthentication = useStepUpAuthentication;
@@ -0,0 +1,51 @@
1
+ import type { OTPVerification } from '@dynamic-labs-sdk/client';
2
+ import { TokenScope, VerifyResponse } from '@dynamic-labs/sdk-api-core';
3
+ export type StepUpAuthenticationState = {
4
+ error: string | null;
5
+ isLoading: boolean;
6
+ otpVerification: OTPVerification | null;
7
+ };
8
+ export type VerifyOtpParams = {
9
+ requestedScopes?: TokenScope[];
10
+ verificationToken: string;
11
+ };
12
+ export type VerifyWalletParams = {
13
+ requestedScopes?: TokenScope[];
14
+ };
15
+ export type UseStepUpAuthenticationParams = {
16
+ credentialId?: string;
17
+ };
18
+ export type UseStepUpAuthenticationReturn = {
19
+ resetState: () => void;
20
+ sendOtp: () => Promise<OTPVerification | null>;
21
+ state: StepUpAuthenticationState;
22
+ verifyOtp: (params: VerifyOtpParams) => Promise<VerifyResponse | null>;
23
+ verifyWallet: (params: VerifyWalletParams) => Promise<void>;
24
+ };
25
+ /**
26
+ * Perform step-up authentication for an already-authenticated user via OTP.
27
+ *
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.
30
+ *
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.
34
+ *
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.
39
+ *
40
+ * @example
41
+ * ```tsx
42
+ * const { sendOtp, verifyOtp, state } = useStepUpAuthentication();
43
+ *
44
+ * // Step 1: send OTP
45
+ * await sendOtp();
46
+ *
47
+ * // Step 2: after the user enters the code
48
+ * const result = await verifyOtp({ verificationToken: '123456' });
49
+ * ```
50
+ */
51
+ export declare const useStepUpAuthentication: ({ credentialId, }?: UseStepUpAuthenticationParams) => UseStepUpAuthenticationReturn;
@@ -0,0 +1,193 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../../../_virtual/_tslib.js';
3
+ import { useState, useRef, useCallback } from 'react';
4
+ import { verifyOTP, sendEmailOTP, supportedCountries, sendSmsOTP } from '@dynamic-labs-sdk/client';
5
+ import { JwtVerifiedCredentialFormatEnum } from '@dynamic-labs/sdk-api-core';
6
+ import '@dynamic-labs-sdk/client/core';
7
+ import '../../../client/client.js';
8
+ import '../../../config/ApiEndpoint.js';
9
+ import '@dynamic-labs/iconic';
10
+ import '@dynamic-labs/wallet-connector-core';
11
+ import 'react/jsx-runtime';
12
+ import '../../../context/ViewContext/ViewContext.js';
13
+ import { logger } from '../../../shared/logger.js';
14
+ import '@dynamic-labs/wallet-book';
15
+ import '@dynamic-labs/utils';
16
+ import '../../constants/colors.js';
17
+ import '../../constants/values.js';
18
+ import '../../../shared/consts/index.js';
19
+ import '@dynamic-labs/multi-wallet';
20
+ import 'react-international-phone';
21
+ import '../../../store/state/nonce/nonce.js';
22
+ import '@dynamic-labs/locale';
23
+ import '../../../store/state/dynamicContextProps/dynamicContextProps.js';
24
+ import '../../../store/state/primaryWalletId/primaryWalletId.js';
25
+ import '../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
26
+ import '../../functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.js';
27
+ import '../../../events/dynamicEvents.js';
28
+ import { useUser } from '../../../client/extension/user/useUser/useUser.js';
29
+ import { useConnectAndSign } from '../authenticationHooks/useConnectAndSign/useConnectAndSign.js';
30
+ import { useInternalUserWallets } from '../../../context/UserWalletsContext/UserWalletsContext.js';
31
+
32
+ const INITIAL_STATE = {
33
+ error: null,
34
+ isLoading: false,
35
+ otpVerification: null,
36
+ };
37
+ const isCountryCode = (value) => value !== undefined && value in supportedCountries;
38
+ const isOtpCapableCredential = (cred) => cred.format === JwtVerifiedCredentialFormatEnum.Email ||
39
+ cred.format === JwtVerifiedCredentialFormatEnum.PhoneNumber;
40
+ const resolveTargetCredential = (credentials, credentialId) => {
41
+ var _a, _b;
42
+ if (credentialId) {
43
+ return ((_a = credentials.find((cred) => cred.id === credentialId)) !== null && _a !== void 0 ? _a : `Credential with id "${credentialId}" not found`);
44
+ }
45
+ return ((_b = credentials.find((cred) => cred.signInEnabled && isOtpCapableCredential(cred))) !== null && _b !== void 0 ? _b : 'No sign-in enabled email or SMS credential found for step-up authentication');
46
+ };
47
+ const sendEmailOtp = (credential) => __awaiter(void 0, void 0, void 0, function* () {
48
+ if (!credential.email) {
49
+ throw new Error('Email credential is missing email address');
50
+ }
51
+ return sendEmailOTP({ email: credential.email });
52
+ });
53
+ const sendSmsOtp = (credential) => __awaiter(void 0, void 0, void 0, function* () {
54
+ var _a;
55
+ const normalizedPhoneCountryCode = (_a = credential.phoneCountryCode) === null || _a === void 0 ? void 0 : _a.replace(/^\+/, '');
56
+ const matchedCountryCode = Object.keys(supportedCountries).find((key) => supportedCountries[key].code === normalizedPhoneCountryCode);
57
+ const isoCountryCode = isCountryCode(credential.isoCountryCode)
58
+ ? credential.isoCountryCode
59
+ : matchedCountryCode;
60
+ if (!credential.phoneNumber || !isoCountryCode) {
61
+ throw new Error('SMS credential is missing phone number or country code');
62
+ }
63
+ return sendSmsOTP({ isoCountryCode, phoneNumber: credential.phoneNumber });
64
+ });
65
+ const dispatchOtp = (credential) => __awaiter(void 0, void 0, void 0, function* () {
66
+ return credential.format === JwtVerifiedCredentialFormatEnum.Email
67
+ ? sendEmailOtp(credential)
68
+ : sendSmsOtp(credential);
69
+ });
70
+ /**
71
+ * Perform step-up authentication for an already-authenticated user via OTP.
72
+ *
73
+ * Automatically selects the first sign-in enabled email or SMS credential on
74
+ * the user, or targets a specific credential when `credentialId` is provided.
75
+ *
76
+ * @param params.credentialId - Optional id of a specific verified credential to
77
+ * use. Must be an email or SMS credential. Defaults to the first sign-in
78
+ * enabled email or SMS credential on the authenticated user.
79
+ *
80
+ * @returns `sendOtp` – sends the OTP to the resolved credential.
81
+ * @returns `verifyOtp` – verifies the OTP code supplied by the user.
82
+ * @returns `state` – current loading / error / otpVerification state.
83
+ * @returns `resetState` – resets state back to its initial value.
84
+ *
85
+ * @example
86
+ * ```tsx
87
+ * const { sendOtp, verifyOtp, state } = useStepUpAuthentication();
88
+ *
89
+ * // Step 1: send OTP
90
+ * await sendOtp();
91
+ *
92
+ * // Step 2: after the user enters the code
93
+ * const result = await verifyOtp({ verificationToken: '123456' });
94
+ * ```
95
+ */
96
+ const useStepUpAuthentication = ({ credentialId, } = {}) => {
97
+ const user = useUser();
98
+ const [state, setState] = useState(INITIAL_STATE);
99
+ const connectAndSign = useConnectAndSign();
100
+ const { userWallets } = useInternalUserWallets();
101
+ // Ref keeps the latest otpVerification available inside the verifyOtp
102
+ // callback without creating a stale closure over state.
103
+ const otpVerificationRef = useRef(null);
104
+ const resetState = useCallback(() => {
105
+ otpVerificationRef.current = null;
106
+ setState(INITIAL_STATE);
107
+ }, []);
108
+ const setError = useCallback((errorMessage) => {
109
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
110
+ logger.error(errorMessage);
111
+ }, []);
112
+ const sendOtp = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
113
+ const credentials = user === null || user === void 0 ? void 0 : user.verifiedCredentials;
114
+ if (!(credentials === null || credentials === void 0 ? void 0 : credentials.length)) {
115
+ setError('No verified credentials found for the authenticated user');
116
+ return null;
117
+ }
118
+ const result = resolveTargetCredential(credentials, credentialId);
119
+ if (typeof result === 'string') {
120
+ setError(result);
121
+ return null;
122
+ }
123
+ if (!isOtpCapableCredential(result)) {
124
+ setError(`Credential format "${result.format}" does not support OTP verification. Only email and SMS credentials are supported`);
125
+ return null;
126
+ }
127
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
128
+ try {
129
+ const otpVerification = yield dispatchOtp(result);
130
+ otpVerificationRef.current = otpVerification;
131
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: false, otpVerification })));
132
+ return otpVerification;
133
+ }
134
+ catch (error) {
135
+ const errorMessage = error instanceof Error ? error.message : 'Failed to send OTP';
136
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
137
+ logger.error('Failed to send OTP for step-up authentication', { error });
138
+ return null;
139
+ }
140
+ }), [credentialId, setError, user === null || user === void 0 ? void 0 : user.verifiedCredentials]);
141
+ const verifyOtp = useCallback((_a) => __awaiter(void 0, [_a], void 0, function* ({ requestedScopes, verificationToken, }) {
142
+ const otpVerification = otpVerificationRef.current;
143
+ if (!otpVerification) {
144
+ setError('OTP verification has not been initiated. Call sendOtp() first');
145
+ return null;
146
+ }
147
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
148
+ try {
149
+ const response = yield verifyOTP({
150
+ otpVerification,
151
+ requestedScopes,
152
+ verificationToken,
153
+ });
154
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: false })));
155
+ return response;
156
+ }
157
+ catch (error) {
158
+ const errorMessage = error instanceof Error ? error.message : 'Failed to verify OTP';
159
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
160
+ logger.error('Failed to verify OTP for step-up authentication', {
161
+ error,
162
+ });
163
+ return null;
164
+ }
165
+ }), [setError]);
166
+ const verifyWallet = useCallback((_b) => __awaiter(void 0, [_b], void 0, function* ({ requestedScopes }) {
167
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
168
+ const wallet = userWallets.find((w) => w.id === credentialId);
169
+ if (!wallet) {
170
+ setError(`Wallet with id "${credentialId}" not found`);
171
+ return;
172
+ }
173
+ try {
174
+ yield connectAndSign({
175
+ requestedScopes,
176
+ walletConnector: wallet.connector,
177
+ });
178
+ setState((prev) => (Object.assign(Object.assign({}, prev), { isLoading: false })));
179
+ }
180
+ catch (error) {
181
+ const errorMessage = error instanceof Error
182
+ ? error.message
183
+ : 'Failed to verify wallet for step-up authentication';
184
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
185
+ logger.error('Failed to verify wallet for step-up authentication', {
186
+ error,
187
+ });
188
+ }
189
+ }), [connectAndSign, credentialId, setError, userWallets]);
190
+ return { resetState, sendOtp, state, verifyOtp, verifyWallet };
191
+ };
192
+
193
+ export { useStepUpAuthentication };
@@ -134,7 +134,7 @@ const useVerifyWallet = ({ displaySiweStatement, environmentId, projectSettings,
134
134
  // We need this boolean to distinguish between logic for verify or linking.
135
135
  const verifyOnly = !user;
136
136
  const shouldFallbackToConnectOnly = enableConnectOnlyFallback && (verifyOnly || !multiWalletEnabled);
137
- const generateJWT = (walletConnector, walletProvider, getAddressOpts, publicWalletAddress, captchaToken, oauth, signedMessageOverride, messageToSignOverride) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
137
+ const generateJWT = (walletConnector, walletProvider, getAddressOpts, publicWalletAddress, captchaToken, oauth, signedMessageOverride, messageToSignOverride, requestedScopes) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
138
138
  const verifyArgs = yield getVerifyArgs.getVerifyArgs({
139
139
  displaySiweStatement,
140
140
  environmentId,
@@ -156,6 +156,11 @@ const useVerifyWallet = ({ displaySiweStatement, environmentId, projectSettings,
156
156
  verifyResponse = wallets.verifyWallet(environmentId, Object.assign(Object.assign({}, verifyArgs), { captchaToken,
157
157
  oauth }));
158
158
  }
159
+ else if (user && requestedScopes) {
160
+ verifyResponse = wallets.walletsVerify(environmentId, Object.assign(Object.assign({}, verifyArgs), { captchaToken,
161
+ oauth,
162
+ requestedScopes }));
163
+ }
159
164
  else {
160
165
  verifyResponse = wallets.linkWallet(environmentId, verifyArgs);
161
166
  }
@@ -285,7 +290,7 @@ const useVerifyWallet = ({ displaySiweStatement, environmentId, projectSettings,
285
290
  setErrorMessage(e.code);
286
291
  }
287
292
  };
288
- return (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ walletConnector, getAddressOpts, publicWalletAddress, captchaToken, oauth, signedMessageOverride, messageToSignOverride, }) {
293
+ return (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ walletConnector, getAddressOpts, publicWalletAddress, captchaToken, oauth, signedMessageOverride, messageToSignOverride, requestedScopes, }) {
289
294
  const walletProvider = walletConnectorCore.getWalletProvider(walletConnector);
290
295
  dynamicEvents.dynamicEvents.emit('authInit', {
291
296
  address: publicWalletAddress,
@@ -294,7 +299,7 @@ const useVerifyWallet = ({ displaySiweStatement, environmentId, projectSettings,
294
299
  type: 'wallet',
295
300
  });
296
301
  try {
297
- const { verifyFunction, verifyArgs } = yield generateJWT(walletConnector, walletProvider, getAddressOpts, publicWalletAddress, captchaToken, oauth, signedMessageOverride, messageToSignOverride);
302
+ const { verifyFunction, verifyArgs } = yield generateJWT(walletConnector, walletProvider, getAddressOpts, publicWalletAddress, captchaToken, oauth, signedMessageOverride, messageToSignOverride, requestedScopes);
298
303
  yield initAuth({
299
304
  isSignIn: verifyOnly,
300
305
  onError: (e) => {
@@ -7,5 +7,5 @@ type UseVerifyWalletArgs = {
7
7
  displaySiweStatement: boolean;
8
8
  setIsSingleWalletAccount: Dispatch<SetStateAction<boolean>>;
9
9
  };
10
- export declare const useVerifyWallet: ({ displaySiweStatement, environmentId, projectSettings, setIsSingleWalletAccount, }: UseVerifyWalletArgs) => ({ walletConnector, getAddressOpts, publicWalletAddress, captchaToken, oauth, signedMessageOverride, messageToSignOverride, }: VerifyCallbackArgs) => Promise<void>;
10
+ export declare const useVerifyWallet: ({ displaySiweStatement, environmentId, projectSettings, setIsSingleWalletAccount, }: UseVerifyWalletArgs) => ({ walletConnector, getAddressOpts, publicWalletAddress, captchaToken, oauth, signedMessageOverride, messageToSignOverride, requestedScopes, }: VerifyCallbackArgs) => Promise<void>;
11
11
  export {};
@@ -34,7 +34,7 @@ import '../../../client/client.js';
34
34
  import '@dynamic-labs-sdk/client';
35
35
  import '../../../config/ApiEndpoint.js';
36
36
  import '@dynamic-labs/locale';
37
- import { verifyWallet, linkWallet } from '../../../data/api/wallets/wallets.js';
37
+ import { verifyWallet, walletsVerify, linkWallet } from '../../../data/api/wallets/wallets.js';
38
38
  import '../../functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.js';
39
39
  import { useAccessDeniedContext } from '../../../context/AccessDeniedContext/AccessDeniedContext.js';
40
40
  import { useAccountExistsContext } from '../../../context/AccountExistsContext/AccountExistsContext.js';
@@ -130,7 +130,7 @@ const useVerifyWallet = ({ displaySiweStatement, environmentId, projectSettings,
130
130
  // We need this boolean to distinguish between logic for verify or linking.
131
131
  const verifyOnly = !user;
132
132
  const shouldFallbackToConnectOnly = enableConnectOnlyFallback && (verifyOnly || !multiWalletEnabled);
133
- const generateJWT = (walletConnector, walletProvider, getAddressOpts, publicWalletAddress, captchaToken, oauth, signedMessageOverride, messageToSignOverride) => __awaiter(void 0, void 0, void 0, function* () {
133
+ const generateJWT = (walletConnector, walletProvider, getAddressOpts, publicWalletAddress, captchaToken, oauth, signedMessageOverride, messageToSignOverride, requestedScopes) => __awaiter(void 0, void 0, void 0, function* () {
134
134
  const verifyArgs = yield getVerifyArgs({
135
135
  displaySiweStatement,
136
136
  environmentId,
@@ -152,6 +152,11 @@ const useVerifyWallet = ({ displaySiweStatement, environmentId, projectSettings,
152
152
  verifyResponse = verifyWallet(environmentId, Object.assign(Object.assign({}, verifyArgs), { captchaToken,
153
153
  oauth }));
154
154
  }
155
+ else if (user && requestedScopes) {
156
+ verifyResponse = walletsVerify(environmentId, Object.assign(Object.assign({}, verifyArgs), { captchaToken,
157
+ oauth,
158
+ requestedScopes }));
159
+ }
155
160
  else {
156
161
  verifyResponse = linkWallet(environmentId, verifyArgs);
157
162
  }
@@ -281,7 +286,7 @@ const useVerifyWallet = ({ displaySiweStatement, environmentId, projectSettings,
281
286
  setErrorMessage(e.code);
282
287
  }
283
288
  };
284
- return (_a) => __awaiter(void 0, [_a], void 0, function* ({ walletConnector, getAddressOpts, publicWalletAddress, captchaToken, oauth, signedMessageOverride, messageToSignOverride, }) {
289
+ return (_a) => __awaiter(void 0, [_a], void 0, function* ({ walletConnector, getAddressOpts, publicWalletAddress, captchaToken, oauth, signedMessageOverride, messageToSignOverride, requestedScopes, }) {
285
290
  const walletProvider = getWalletProvider(walletConnector);
286
291
  dynamicEvents.emit('authInit', {
287
292
  address: publicWalletAddress,
@@ -290,7 +295,7 @@ const useVerifyWallet = ({ displaySiweStatement, environmentId, projectSettings,
290
295
  type: 'wallet',
291
296
  });
292
297
  try {
293
- const { verifyFunction, verifyArgs } = yield generateJWT(walletConnector, walletProvider, getAddressOpts, publicWalletAddress, captchaToken, oauth, signedMessageOverride, messageToSignOverride);
298
+ const { verifyFunction, verifyArgs } = yield generateJWT(walletConnector, walletProvider, getAddressOpts, publicWalletAddress, captchaToken, oauth, signedMessageOverride, messageToSignOverride, requestedScopes);
294
299
  yield initAuth({
295
300
  isSignIn: verifyOnly,
296
301
  onError: (e) => {
@@ -30,6 +30,35 @@ const useWalletPassword = () => {
30
30
  const resetState = React.useCallback(() => {
31
31
  setState(INITIAL_STATE);
32
32
  }, []);
33
+ const setPassword = React.useCallback((params) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
34
+ const { accountAddress, chainName, newPassword } = params;
35
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
36
+ try {
37
+ const connector = getWaasWalletConnector(chainName);
38
+ if (!connector) {
39
+ const errorMessage = 'Wallet connector not found';
40
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
41
+ logger.logger.error(errorMessage, { accountAddress, chainName });
42
+ return false;
43
+ }
44
+ yield connector.setPassword({
45
+ accountAddress,
46
+ newPassword,
47
+ });
48
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: false })));
49
+ return true;
50
+ }
51
+ catch (error) {
52
+ const errorMessage = error instanceof Error ? error.message : 'Failed to set password';
53
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
54
+ logger.logger.error('Failed to set wallet password', {
55
+ accountAddress,
56
+ chainName,
57
+ error,
58
+ });
59
+ return false;
60
+ }
61
+ }), [getWaasWalletConnector]);
33
62
  const updatePassword = React.useCallback((params) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
34
63
  const { accountAddress, chainName, newPassword, existingPassword } = params;
35
64
  setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
@@ -143,6 +172,7 @@ const useWalletPassword = () => {
143
172
  return {
144
173
  checkWalletLockState,
145
174
  resetState,
175
+ setPassword,
146
176
  state,
147
177
  unlockWallet,
148
178
  updatePassword,
@@ -1,5 +1,10 @@
1
1
  import { WalletRecoveryState } from '@dynamic-labs-wallet/browser-wallet-client';
2
2
  import { ChainEnum } from '@dynamic-labs/sdk-api-core';
3
+ export type SetPasswordParams = {
4
+ accountAddress: string;
5
+ chainName: ChainEnum;
6
+ newPassword: string;
7
+ };
3
8
  export type UpdatePasswordParams = {
4
9
  accountAddress: string;
5
10
  chainName: ChainEnum;
@@ -21,6 +26,7 @@ export type WalletPasswordState = {
21
26
  recoveryState: WalletRecoveryState | null;
22
27
  };
23
28
  export type UseWalletPasswordReturn = {
29
+ setPassword: (params: SetPasswordParams) => Promise<boolean>;
24
30
  updatePassword: (params: UpdatePasswordParams) => Promise<boolean>;
25
31
  unlockWallet: (params: UnlockWalletParams) => Promise<boolean>;
26
32
  checkWalletLockState: (params: CheckWalletLockStateParams) => Promise<WalletRecoveryState | null>;
@@ -26,6 +26,35 @@ const useWalletPassword = () => {
26
26
  const resetState = useCallback(() => {
27
27
  setState(INITIAL_STATE);
28
28
  }, []);
29
+ const setPassword = useCallback((params) => __awaiter(void 0, void 0, void 0, function* () {
30
+ const { accountAddress, chainName, newPassword } = params;
31
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
32
+ try {
33
+ const connector = getWaasWalletConnector(chainName);
34
+ if (!connector) {
35
+ const errorMessage = 'Wallet connector not found';
36
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
37
+ logger.error(errorMessage, { accountAddress, chainName });
38
+ return false;
39
+ }
40
+ yield connector.setPassword({
41
+ accountAddress,
42
+ newPassword,
43
+ });
44
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: false })));
45
+ return true;
46
+ }
47
+ catch (error) {
48
+ const errorMessage = error instanceof Error ? error.message : 'Failed to set password';
49
+ setState((prev) => (Object.assign(Object.assign({}, prev), { error: errorMessage, isLoading: false })));
50
+ logger.error('Failed to set wallet password', {
51
+ accountAddress,
52
+ chainName,
53
+ error,
54
+ });
55
+ return false;
56
+ }
57
+ }), [getWaasWalletConnector]);
29
58
  const updatePassword = useCallback((params) => __awaiter(void 0, void 0, void 0, function* () {
30
59
  const { accountAddress, chainName, newPassword, existingPassword } = params;
31
60
  setState((prev) => (Object.assign(Object.assign({}, prev), { error: null, isLoading: true })));
@@ -139,6 +168,7 @@ const useWalletPassword = () => {
139
168
  return {
140
169
  checkWalletLockState,
141
170
  resetState,
171
+ setPassword,
142
172
  state,
143
173
  unlockWallet,
144
174
  updatePassword,
@@ -132,6 +132,7 @@ const getSupportedChainName = (connectedChain) => {
132
132
  BTC: sdkApiCore.ChainEnum.Btc,
133
133
  EVM: sdkApiCore.ChainEnum.Evm,
134
134
  SOL: sdkApiCore.ChainEnum.Sol,
135
+ STELLAR: sdkApiCore.ChainEnum.Stellar,
135
136
  SUI: sdkApiCore.ChainEnum.Sui,
136
137
  TON: sdkApiCore.ChainEnum.Ton,
137
138
  TRON: sdkApiCore.ChainEnum.Tron,
@@ -128,6 +128,7 @@ const getSupportedChainName = (connectedChain) => {
128
128
  BTC: ChainEnum.Btc,
129
129
  EVM: ChainEnum.Evm,
130
130
  SOL: ChainEnum.Sol,
131
+ STELLAR: ChainEnum.Stellar,
131
132
  SUI: ChainEnum.Sui,
132
133
  TON: ChainEnum.Ton,
133
134
  TRON: ChainEnum.Tron,