@dynamic-labs/sdk-react-core 4.10.0 → 4.10.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 CHANGED
@@ -1,4 +1,6 @@
1
1
 
2
+ ### [4.10.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.10.0...v4.10.1) (2025-03-31)
3
+
2
4
  ## [4.10.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.9.12...v4.10.0) (2025-03-30)
3
5
 
4
6
 
package/package.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.10.0";
6
+ var version = "4.10.1";
7
7
  var dependencies = {
8
8
  "@dynamic-labs/sdk-api-core": "0.0.650",
9
9
  "@hcaptcha/react-hcaptcha": "1.4.4",
package/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client'
2
- var version = "4.10.0";
2
+ var version = "4.10.1";
3
3
  var dependencies = {
4
4
  "@dynamic-labs/sdk-api-core": "0.0.650",
5
5
  "@hcaptcha/react-hcaptcha": "1.4.4",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/sdk-react-core",
3
- "version": "4.10.0",
3
+ "version": "4.10.1",
4
4
  "dependencies": {
5
5
  "@dynamic-labs/sdk-api-core": "0.0.650",
6
6
  "@hcaptcha/react-hcaptcha": "1.4.4",
@@ -14,16 +14,16 @@
14
14
  "yup": "0.32.11",
15
15
  "react-international-phone": "4.2.5",
16
16
  "bs58": "5.0.0",
17
- "@dynamic-labs/assert-package-version": "4.10.0",
18
- "@dynamic-labs/iconic": "4.10.0",
19
- "@dynamic-labs/logger": "4.10.0",
20
- "@dynamic-labs/multi-wallet": "4.10.0",
21
- "@dynamic-labs/rpc-providers": "4.10.0",
22
- "@dynamic-labs/store": "4.10.0",
23
- "@dynamic-labs/types": "4.10.0",
24
- "@dynamic-labs/utils": "4.10.0",
25
- "@dynamic-labs/wallet-book": "4.10.0",
26
- "@dynamic-labs/wallet-connector-core": "4.10.0",
17
+ "@dynamic-labs/assert-package-version": "4.10.1",
18
+ "@dynamic-labs/iconic": "4.10.1",
19
+ "@dynamic-labs/logger": "4.10.1",
20
+ "@dynamic-labs/multi-wallet": "4.10.1",
21
+ "@dynamic-labs/rpc-providers": "4.10.1",
22
+ "@dynamic-labs/store": "4.10.1",
23
+ "@dynamic-labs/types": "4.10.1",
24
+ "@dynamic-labs/utils": "4.10.1",
25
+ "@dynamic-labs/wallet-book": "4.10.1",
26
+ "@dynamic-labs/wallet-connector-core": "4.10.1",
27
27
  "eventemitter3": "5.0.1"
28
28
  },
29
29
  "devDependencies": {
@@ -109,44 +109,13 @@ const useMfa = () => {
109
109
  const environmentId = dynamicContextProps.getEnvironmentId();
110
110
  return environmentId;
111
111
  }, []);
112
- const getUserDevices = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
113
- const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
114
- const devices = yield mfa.getUserMfaDevices({ environmentId });
115
- return devices;
116
- }), [checkUserIsVerifiedAndGetEnvironmentId]);
117
- const updateUserDevice = React.useCallback((deviceId) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
118
- const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
119
- yield mfa.updateUserMfaDevice({
120
- environmentId,
121
- mfaDeviceId: deviceId,
122
- });
123
- }), [checkUserIsVerifiedAndGetEnvironmentId]);
124
- const deleteUserDevice = React.useCallback((deviceId, mfaAuthToken) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
125
- const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
126
- yield mfa.deleteMfaDevice({
127
- environmentId,
128
- mfaAuthToken,
129
- mfaDeviceId: deviceId,
130
- });
131
- // Refresh the user JWT to get the updated MFA acknowledgement
132
- // since if it is completed we won't show the QR code again
133
- yield user$1.refreshUserJwt({ environmentId });
134
- }), [checkUserIsVerifiedAndGetEnvironmentId]);
135
- const addDevice = React.useCallback((...args_1) => _tslib.__awaiter(void 0, [...args_1], void 0, function* (type = sdkApiCore.MFADeviceType.Totp) {
136
- const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
137
- const { id, secret, uri } = yield mfa.addMfaDevice({
138
- environmentId,
139
- type,
140
- });
141
- return { id, secret, uri };
142
- }), [checkUserIsVerifiedAndGetEnvironmentId]);
143
- const authDevice = React.useCallback((code_1, ...args_2) => _tslib.__awaiter(void 0, [code_1, ...args_2], void 0, function* (code, type = sdkApiCore.MFADeviceType.Totp, deviceId) {
112
+ const handleMfaAuth = React.useCallback((code_1, ...args_1) => _tslib.__awaiter(void 0, [code_1, ...args_1], void 0, function* (code, type = sdkApiCore.MFADeviceType.Totp, deviceId, resultHandler) {
144
113
  try {
145
114
  const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
146
- let isValid = false;
115
+ let result;
147
116
  yield completeAuth({
148
117
  onValidUpdatedJwt: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
149
- isValid = true;
118
+ // This callback is used by authDevice
150
119
  }),
151
120
  updateJwtFunction: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
152
121
  const response = yield mfa.authMfaDevice({
@@ -161,22 +130,69 @@ const useMfa = () => {
161
130
  dynamicEvents.dynamicEvents.emit('mfaCompletionSuccess', {
162
131
  mfaToken: response.mfaToken,
163
132
  });
133
+ result = resultHandler(response);
164
134
  return {
165
135
  isEmailVerificationRequired: false,
166
136
  isSmsVerificationRequired: false,
167
137
  missingFields: [],
168
- // in the mfa flow, we only care about the user in the response
169
138
  updateUserProfileResponse: response,
170
139
  };
171
140
  }),
172
141
  });
173
- return isValid;
142
+ return result;
174
143
  }
175
144
  catch (error) {
176
145
  dynamicEvents.dynamicEvents.emit('mfaCompletionFailure', { error });
177
146
  throw error;
178
147
  }
179
148
  }), [checkUserIsVerifiedAndGetEnvironmentId, completeAuth]);
149
+ const getUserDevices = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
150
+ const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
151
+ const devices = yield mfa.getUserMfaDevices({ environmentId });
152
+ return devices;
153
+ }), [checkUserIsVerifiedAndGetEnvironmentId]);
154
+ const updateUserDevice = React.useCallback((deviceId) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
155
+ const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
156
+ yield mfa.updateUserMfaDevice({
157
+ environmentId,
158
+ mfaDeviceId: deviceId,
159
+ });
160
+ }), [checkUserIsVerifiedAndGetEnvironmentId]);
161
+ const deleteUserDevice = React.useCallback((deviceId, mfaAuthToken) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
162
+ const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
163
+ yield mfa.deleteMfaDevice({
164
+ environmentId,
165
+ mfaAuthToken,
166
+ mfaDeviceId: deviceId,
167
+ });
168
+ // Refresh the user JWT to get the updated MFA acknowledgement
169
+ // since if it is completed we won't show the QR code again
170
+ yield user$1.refreshUserJwt({ environmentId });
171
+ }), [checkUserIsVerifiedAndGetEnvironmentId]);
172
+ const addDevice = React.useCallback((...args_2) => _tslib.__awaiter(void 0, [...args_2], void 0, function* (type = sdkApiCore.MFADeviceType.Totp) {
173
+ const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
174
+ const { id, secret, uri } = yield mfa.addMfaDevice({
175
+ environmentId,
176
+ type,
177
+ });
178
+ return { id, secret, uri };
179
+ }), [checkUserIsVerifiedAndGetEnvironmentId]);
180
+ // @deprecated Use authenticateDevice instead.
181
+ // This function authenticates a device and returns a boolean value
182
+ // indicating if the authentication was successful.
183
+ const authDevice = React.useCallback((code_2, ...args_3) => _tslib.__awaiter(void 0, [code_2, ...args_3], void 0, function* (code, type = sdkApiCore.MFADeviceType.Totp, deviceId) {
184
+ let isValid = false;
185
+ yield handleMfaAuth(code, type, deviceId, () => {
186
+ isValid = true;
187
+ return true;
188
+ });
189
+ return isValid;
190
+ }), [handleMfaAuth]);
191
+ /**
192
+ * Authenticates a device and returns a single use MFA token
193
+ * if the authentication is successful.
194
+ */
195
+ const authenticateDevice = React.useCallback((_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ code, type = sdkApiCore.MFADeviceType.Totp, deviceId, }) { return handleMfaAuth(code, type, deviceId, (response) => response.mfaToken); }), [handleMfaAuth]);
180
196
  const authRecoveryCode = React.useCallback((code) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
181
197
  const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
182
198
  let isValid = false;
@@ -203,7 +219,7 @@ const useMfa = () => {
203
219
  });
204
220
  return isValid;
205
221
  }), [checkUserIsVerifiedAndGetEnvironmentId, completeAuth]);
206
- const verifyDevice = React.useCallback((code_2, ...args_3) => _tslib.__awaiter(void 0, [code_2, ...args_3], void 0, function* (code, type = sdkApiCore.MFADeviceType.Totp) {
222
+ const verifyDevice = React.useCallback((code_3, ...args_4) => _tslib.__awaiter(void 0, [code_3, ...args_4], void 0, function* (code, type = sdkApiCore.MFADeviceType.Totp) {
207
223
  const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
208
224
  const device = yield mfa.verifyMfaDevice({
209
225
  code,
@@ -215,7 +231,7 @@ const useMfa = () => {
215
231
  }
216
232
  return device;
217
233
  }), [checkUserIsVerifiedAndGetEnvironmentId]);
218
- const getRecoveryCodes = React.useCallback((...args_4) => _tslib.__awaiter(void 0, [...args_4], void 0, function* (generateNewCodes = false) {
234
+ const getRecoveryCodes = React.useCallback((...args_5) => _tslib.__awaiter(void 0, [...args_5], void 0, function* (generateNewCodes = false) {
219
235
  const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
220
236
  const getRecoveryCodesFunc = generateNewCodes
221
237
  ? mfa.createNewRecoveryCodes
@@ -240,6 +256,7 @@ const useMfa = () => {
240
256
  addDevice,
241
257
  authDevice,
242
258
  authRecoveryCode,
259
+ authenticateDevice,
243
260
  completeAcknowledgement,
244
261
  deleteUserDevice,
245
262
  getRecoveryCodes,
@@ -7,6 +7,11 @@ export declare const useMfa: () => {
7
7
  }>;
8
8
  readonly authDevice: (code: string, type?: MFADeviceType, deviceId?: string) => Promise<boolean>;
9
9
  readonly authRecoveryCode: (code: string) => Promise<boolean>;
10
+ readonly authenticateDevice: ({ code, type, deviceId, }: {
11
+ code: string;
12
+ type?: MFADeviceType;
13
+ deviceId?: string;
14
+ }) => Promise<string | undefined>;
10
15
  readonly completeAcknowledgement: () => Promise<void>;
11
16
  readonly deleteUserDevice: (deviceId: string, mfaAuthToken: string) => Promise<void>;
12
17
  readonly getRecoveryCodes: (generateNewCodes?: boolean) => Promise<string[]>;
@@ -21,7 +21,7 @@ import '../../../store/state/projectSettings/projectSettings.js';
21
21
  import { getEnvironmentId } from '../../../store/state/dynamicContextProps/dynamicContextProps.js';
22
22
  import '../../../store/state/primaryWalletId/primaryWalletId.js';
23
23
  import { getUser } from '../../../store/state/user/user.js';
24
- import { getUserMfaDevices, updateUserMfaDevice, deleteMfaDevice, addMfaDevice, authMfaDevice, authMfaRecovery, verifyMfaDevice, createNewRecoveryCodes, getRecoveryCodes } from '../../../data/api/mfa/mfa.js';
24
+ import { authMfaDevice, getUserMfaDevices, updateUserMfaDevice, deleteMfaDevice, addMfaDevice, authMfaRecovery, verifyMfaDevice, createNewRecoveryCodes, getRecoveryCodes } from '../../../data/api/mfa/mfa.js';
25
25
  import '../../../locale/locale.js';
26
26
  import { refreshUserJwt } from '../../../data/api/user/user.js';
27
27
  import { useUserAuth } from '../useUserAuth/useUserAuth.js';
@@ -105,44 +105,13 @@ const useMfa = () => {
105
105
  const environmentId = getEnvironmentId();
106
106
  return environmentId;
107
107
  }, []);
108
- const getUserDevices = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
109
- const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
110
- const devices = yield getUserMfaDevices({ environmentId });
111
- return devices;
112
- }), [checkUserIsVerifiedAndGetEnvironmentId]);
113
- const updateUserDevice = useCallback((deviceId) => __awaiter(void 0, void 0, void 0, function* () {
114
- const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
115
- yield updateUserMfaDevice({
116
- environmentId,
117
- mfaDeviceId: deviceId,
118
- });
119
- }), [checkUserIsVerifiedAndGetEnvironmentId]);
120
- const deleteUserDevice = useCallback((deviceId, mfaAuthToken) => __awaiter(void 0, void 0, void 0, function* () {
121
- const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
122
- yield deleteMfaDevice({
123
- environmentId,
124
- mfaAuthToken,
125
- mfaDeviceId: deviceId,
126
- });
127
- // Refresh the user JWT to get the updated MFA acknowledgement
128
- // since if it is completed we won't show the QR code again
129
- yield refreshUserJwt({ environmentId });
130
- }), [checkUserIsVerifiedAndGetEnvironmentId]);
131
- const addDevice = useCallback((...args_1) => __awaiter(void 0, [...args_1], void 0, function* (type = MFADeviceType.Totp) {
132
- const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
133
- const { id, secret, uri } = yield addMfaDevice({
134
- environmentId,
135
- type,
136
- });
137
- return { id, secret, uri };
138
- }), [checkUserIsVerifiedAndGetEnvironmentId]);
139
- const authDevice = useCallback((code_1, ...args_2) => __awaiter(void 0, [code_1, ...args_2], void 0, function* (code, type = MFADeviceType.Totp, deviceId) {
108
+ const handleMfaAuth = useCallback((code_1, ...args_1) => __awaiter(void 0, [code_1, ...args_1], void 0, function* (code, type = MFADeviceType.Totp, deviceId, resultHandler) {
140
109
  try {
141
110
  const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
142
- let isValid = false;
111
+ let result;
143
112
  yield completeAuth({
144
113
  onValidUpdatedJwt: () => __awaiter(void 0, void 0, void 0, function* () {
145
- isValid = true;
114
+ // This callback is used by authDevice
146
115
  }),
147
116
  updateJwtFunction: () => __awaiter(void 0, void 0, void 0, function* () {
148
117
  const response = yield authMfaDevice({
@@ -157,22 +126,69 @@ const useMfa = () => {
157
126
  dynamicEvents.emit('mfaCompletionSuccess', {
158
127
  mfaToken: response.mfaToken,
159
128
  });
129
+ result = resultHandler(response);
160
130
  return {
161
131
  isEmailVerificationRequired: false,
162
132
  isSmsVerificationRequired: false,
163
133
  missingFields: [],
164
- // in the mfa flow, we only care about the user in the response
165
134
  updateUserProfileResponse: response,
166
135
  };
167
136
  }),
168
137
  });
169
- return isValid;
138
+ return result;
170
139
  }
171
140
  catch (error) {
172
141
  dynamicEvents.emit('mfaCompletionFailure', { error });
173
142
  throw error;
174
143
  }
175
144
  }), [checkUserIsVerifiedAndGetEnvironmentId, completeAuth]);
145
+ const getUserDevices = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
146
+ const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
147
+ const devices = yield getUserMfaDevices({ environmentId });
148
+ return devices;
149
+ }), [checkUserIsVerifiedAndGetEnvironmentId]);
150
+ const updateUserDevice = useCallback((deviceId) => __awaiter(void 0, void 0, void 0, function* () {
151
+ const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
152
+ yield updateUserMfaDevice({
153
+ environmentId,
154
+ mfaDeviceId: deviceId,
155
+ });
156
+ }), [checkUserIsVerifiedAndGetEnvironmentId]);
157
+ const deleteUserDevice = useCallback((deviceId, mfaAuthToken) => __awaiter(void 0, void 0, void 0, function* () {
158
+ const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
159
+ yield deleteMfaDevice({
160
+ environmentId,
161
+ mfaAuthToken,
162
+ mfaDeviceId: deviceId,
163
+ });
164
+ // Refresh the user JWT to get the updated MFA acknowledgement
165
+ // since if it is completed we won't show the QR code again
166
+ yield refreshUserJwt({ environmentId });
167
+ }), [checkUserIsVerifiedAndGetEnvironmentId]);
168
+ const addDevice = useCallback((...args_2) => __awaiter(void 0, [...args_2], void 0, function* (type = MFADeviceType.Totp) {
169
+ const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
170
+ const { id, secret, uri } = yield addMfaDevice({
171
+ environmentId,
172
+ type,
173
+ });
174
+ return { id, secret, uri };
175
+ }), [checkUserIsVerifiedAndGetEnvironmentId]);
176
+ // @deprecated Use authenticateDevice instead.
177
+ // This function authenticates a device and returns a boolean value
178
+ // indicating if the authentication was successful.
179
+ const authDevice = useCallback((code_2, ...args_3) => __awaiter(void 0, [code_2, ...args_3], void 0, function* (code, type = MFADeviceType.Totp, deviceId) {
180
+ let isValid = false;
181
+ yield handleMfaAuth(code, type, deviceId, () => {
182
+ isValid = true;
183
+ return true;
184
+ });
185
+ return isValid;
186
+ }), [handleMfaAuth]);
187
+ /**
188
+ * Authenticates a device and returns a single use MFA token
189
+ * if the authentication is successful.
190
+ */
191
+ const authenticateDevice = useCallback((_a) => __awaiter(void 0, [_a], void 0, function* ({ code, type = MFADeviceType.Totp, deviceId, }) { return handleMfaAuth(code, type, deviceId, (response) => response.mfaToken); }), [handleMfaAuth]);
176
192
  const authRecoveryCode = useCallback((code) => __awaiter(void 0, void 0, void 0, function* () {
177
193
  const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
178
194
  let isValid = false;
@@ -199,7 +215,7 @@ const useMfa = () => {
199
215
  });
200
216
  return isValid;
201
217
  }), [checkUserIsVerifiedAndGetEnvironmentId, completeAuth]);
202
- const verifyDevice = useCallback((code_2, ...args_3) => __awaiter(void 0, [code_2, ...args_3], void 0, function* (code, type = MFADeviceType.Totp) {
218
+ const verifyDevice = useCallback((code_3, ...args_4) => __awaiter(void 0, [code_3, ...args_4], void 0, function* (code, type = MFADeviceType.Totp) {
203
219
  const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
204
220
  const device = yield verifyMfaDevice({
205
221
  code,
@@ -211,7 +227,7 @@ const useMfa = () => {
211
227
  }
212
228
  return device;
213
229
  }), [checkUserIsVerifiedAndGetEnvironmentId]);
214
- const getRecoveryCodes$1 = useCallback((...args_4) => __awaiter(void 0, [...args_4], void 0, function* (generateNewCodes = false) {
230
+ const getRecoveryCodes$1 = useCallback((...args_5) => __awaiter(void 0, [...args_5], void 0, function* (generateNewCodes = false) {
215
231
  const environmentId = checkUserIsVerifiedAndGetEnvironmentId();
216
232
  const getRecoveryCodesFunc = generateNewCodes
217
233
  ? createNewRecoveryCodes
@@ -236,6 +252,7 @@ const useMfa = () => {
236
252
  addDevice,
237
253
  authDevice,
238
254
  authRecoveryCode,
255
+ authenticateDevice,
239
256
  completeAcknowledgement,
240
257
  deleteUserDevice,
241
258
  getRecoveryCodes: getRecoveryCodes$1,
@@ -56,8 +56,8 @@ const status = (connectStatusRequest_1, ...args_1) => _tslib.__awaiter(void 0, [
56
56
  return yield response.json();
57
57
  }
58
58
  catch (error) {
59
- logger.logger.warn(`Error fetching farcaster connect status trying again attempt: ${count}`, error);
60
- return { state: 'retry' };
59
+ logger.logger.warn(`Error fetching farcaster connect status, trying again. Attempt: ${count}`, error);
60
+ return { error: JSON.stringify(error), state: 'retry' };
61
61
  }
62
62
  });
63
63
  const watchStatus = (connectStatusRequest_2, ...args_2) => _tslib.__awaiter(void 0, [connectStatusRequest_2, ...args_2], void 0, function* (connectStatusRequest, { timeout = STATUS_TIMEOUT, interval = STATUS_INTERVAL } = {}) {
@@ -76,19 +76,26 @@ const watchStatus = (connectStatusRequest_2, ...args_2) => _tslib.__awaiter(void
76
76
  setTimeout(resolve, interval);
77
77
  };
78
78
  let count = 0;
79
+ let timeoutError = 'Unknown error';
79
80
  while (shouldPoll && Date.now() < deadline) {
80
81
  count++;
81
82
  const response = yield status(connectStatusRequest, count);
82
83
  if (response.state === 'completed') {
83
- return response;
84
+ return { data: response, type: 'success' };
84
85
  }
86
+ else if (response.state === 'retry') {
87
+ timeoutError = response.error;
88
+ }
89
+ // response.state === 'pending'
90
+ else
91
+ timeoutError = 'Timed out: Farcaster connection status still pending';
85
92
  yield new Promise(timeoutCallback);
86
93
  }
87
94
  if (!shouldPoll) {
88
- return 'cancelled';
95
+ return { type: 'cancelled' };
89
96
  }
90
- logger.logger.error(`Polling farcaster connect status timed out after ${STATUS_TIMEOUT}ms`);
91
- return 'timeout';
97
+ logger.logger.error(`Polling farcaster connect status timed out after ${timeout}ms`);
98
+ return { error: timeoutError, type: 'timeout' };
92
99
  });
93
100
 
94
101
  exports.connect = connect;
@@ -16,7 +16,7 @@ interface FarcasterConnectResponse {
16
16
  interface FarcasterConnectStatusRequest {
17
17
  channelToken: string;
18
18
  }
19
- interface FarcasterConnectStatusResponse {
19
+ interface FarcasterConnectStatusSuccessResponse {
20
20
  bio: string;
21
21
  custody: string;
22
22
  displayName: string;
@@ -28,12 +28,22 @@ interface FarcasterConnectStatusResponse {
28
28
  state: 'pending' | 'completed';
29
29
  username: string;
30
30
  }
31
+ type FarcasterConnectStatusResponse = {
32
+ type: 'success';
33
+ data: FarcasterConnectStatusSuccessResponse;
34
+ } | {
35
+ type: 'timeout';
36
+ error: string;
37
+ } | {
38
+ type: 'cancelled';
39
+ };
31
40
  export declare const connect: (connectRequest: FarcasterConnectRequest) => Promise<FarcasterConnectResponse | undefined>;
32
- export declare const status: (connectStatusRequest: FarcasterConnectStatusRequest, count?: number) => Promise<FarcasterConnectStatusResponse | {
41
+ export declare const status: (connectStatusRequest: FarcasterConnectStatusRequest, count?: number) => Promise<FarcasterConnectStatusSuccessResponse | {
42
+ error: string;
33
43
  state: 'retry';
34
44
  }>;
35
45
  export declare const watchStatus: (connectStatusRequest: FarcasterConnectStatusRequest, { timeout, interval }?: {
36
46
  timeout?: number | undefined;
37
47
  interval?: number | undefined;
38
- }) => Promise<FarcasterConnectStatusResponse | 'timeout' | 'rejected' | 'cancelled'>;
48
+ }) => Promise<FarcasterConnectStatusResponse>;
39
49
  export {};
@@ -52,8 +52,8 @@ const status = (connectStatusRequest_1, ...args_1) => __awaiter(void 0, [connect
52
52
  return yield response.json();
53
53
  }
54
54
  catch (error) {
55
- logger.warn(`Error fetching farcaster connect status trying again attempt: ${count}`, error);
56
- return { state: 'retry' };
55
+ logger.warn(`Error fetching farcaster connect status, trying again. Attempt: ${count}`, error);
56
+ return { error: JSON.stringify(error), state: 'retry' };
57
57
  }
58
58
  });
59
59
  const watchStatus = (connectStatusRequest_2, ...args_2) => __awaiter(void 0, [connectStatusRequest_2, ...args_2], void 0, function* (connectStatusRequest, { timeout = STATUS_TIMEOUT, interval = STATUS_INTERVAL } = {}) {
@@ -72,19 +72,26 @@ const watchStatus = (connectStatusRequest_2, ...args_2) => __awaiter(void 0, [co
72
72
  setTimeout(resolve, interval);
73
73
  };
74
74
  let count = 0;
75
+ let timeoutError = 'Unknown error';
75
76
  while (shouldPoll && Date.now() < deadline) {
76
77
  count++;
77
78
  const response = yield status(connectStatusRequest, count);
78
79
  if (response.state === 'completed') {
79
- return response;
80
+ return { data: response, type: 'success' };
80
81
  }
82
+ else if (response.state === 'retry') {
83
+ timeoutError = response.error;
84
+ }
85
+ // response.state === 'pending'
86
+ else
87
+ timeoutError = 'Timed out: Farcaster connection status still pending';
81
88
  yield new Promise(timeoutCallback);
82
89
  }
83
90
  if (!shouldPoll) {
84
- return 'cancelled';
91
+ return { type: 'cancelled' };
85
92
  }
86
- logger.error(`Polling farcaster connect status timed out after ${STATUS_TIMEOUT}ms`);
87
- return 'timeout';
93
+ logger.error(`Polling farcaster connect status timed out after ${timeout}ms`);
94
+ return { error: timeoutError, type: 'timeout' };
88
95
  });
89
96
 
90
97
  export { connect, status, watchStatus };
@@ -292,24 +292,25 @@ const useSocialAuth = ({ onSettled, onError, onFarcasterUrl, }) => {
292
292
  setShowAuthFlow(true);
293
293
  onFarcasterUrl === null || onFarcasterUrl === void 0 ? void 0 : onFarcasterUrl(data.url);
294
294
  }
295
- const status = yield farcaster.watchStatus({
295
+ const statusResponse = yield farcaster.watchStatus({
296
296
  channelToken: data.channelToken,
297
297
  });
298
- if (status === 'cancelled') {
298
+ if (statusResponse.type === 'cancelled') {
299
299
  setIsProcessing(false);
300
300
  return;
301
301
  }
302
- // Error
303
- if (status === 'timeout' ||
304
- status === 'rejected' ||
305
- !(status === null || status === void 0 ? void 0 : status.message) ||
306
- !(status === null || status === void 0 ? void 0 : status.custody) ||
307
- !(status === null || status === void 0 ? void 0 : status.signature) ||
308
- !(status === null || status === void 0 ? void 0 : status.nonce)) {
309
- handleError(sdkApiCore.ProviderEnum.Farcaster, types.SocialOAuthErrorCode.GENERAL_ERROR, "Farcaster didn't return valid data.", { raiseAuthFailure: authMode === 'signin' });
302
+ if (statusResponse.type === 'timeout') {
303
+ handleError(sdkApiCore.ProviderEnum.Farcaster, types.SocialOAuthErrorCode.GENERAL_ERROR, `Farcaster timed out while waiting for connection status. Error: ${statusResponse.error}`, { raiseAuthFailure: authMode === 'signin' });
310
304
  return;
311
305
  }
312
- const { custody: address, message, signature, nonce: nonce$1 } = status;
306
+ if (!statusResponse.data.message ||
307
+ !statusResponse.data.custody ||
308
+ !statusResponse.data.signature ||
309
+ !statusResponse.data.nonce) {
310
+ handleError(sdkApiCore.ProviderEnum.Farcaster, types.SocialOAuthErrorCode.GENERAL_ERROR, `Farcaster returned invalid data. Expected to be defined: message, custody, signature, nonce. Received: ${JSON.stringify(statusResponse.data)}`, { raiseAuthFailure: authMode === 'signin' });
311
+ return;
312
+ }
313
+ const { custody: address, message, signature, nonce: nonce$1, } = statusResponse.data;
313
314
  if (authMode === 'signin') {
314
315
  let sessionPublicKey = undefined;
315
316
  if (shouldRegisterSessionKeysOnSignin()) {
@@ -288,24 +288,25 @@ const useSocialAuth = ({ onSettled, onError, onFarcasterUrl, }) => {
288
288
  setShowAuthFlow(true);
289
289
  onFarcasterUrl === null || onFarcasterUrl === void 0 ? void 0 : onFarcasterUrl(data.url);
290
290
  }
291
- const status = yield watchStatus({
291
+ const statusResponse = yield watchStatus({
292
292
  channelToken: data.channelToken,
293
293
  });
294
- if (status === 'cancelled') {
294
+ if (statusResponse.type === 'cancelled') {
295
295
  setIsProcessing(false);
296
296
  return;
297
297
  }
298
- // Error
299
- if (status === 'timeout' ||
300
- status === 'rejected' ||
301
- !(status === null || status === void 0 ? void 0 : status.message) ||
302
- !(status === null || status === void 0 ? void 0 : status.custody) ||
303
- !(status === null || status === void 0 ? void 0 : status.signature) ||
304
- !(status === null || status === void 0 ? void 0 : status.nonce)) {
305
- handleError(ProviderEnum.Farcaster, SocialOAuthErrorCode.GENERAL_ERROR, "Farcaster didn't return valid data.", { raiseAuthFailure: authMode === 'signin' });
298
+ if (statusResponse.type === 'timeout') {
299
+ handleError(ProviderEnum.Farcaster, SocialOAuthErrorCode.GENERAL_ERROR, `Farcaster timed out while waiting for connection status. Error: ${statusResponse.error}`, { raiseAuthFailure: authMode === 'signin' });
306
300
  return;
307
301
  }
308
- const { custody: address, message, signature, nonce } = status;
302
+ if (!statusResponse.data.message ||
303
+ !statusResponse.data.custody ||
304
+ !statusResponse.data.signature ||
305
+ !statusResponse.data.nonce) {
306
+ handleError(ProviderEnum.Farcaster, SocialOAuthErrorCode.GENERAL_ERROR, `Farcaster returned invalid data. Expected to be defined: message, custody, signature, nonce. Received: ${JSON.stringify(statusResponse.data)}`, { raiseAuthFailure: authMode === 'signin' });
307
+ return;
308
+ }
309
+ const { custody: address, message, signature, nonce, } = statusResponse.data;
309
310
  if (authMode === 'signin') {
310
311
  let sessionPublicKey = undefined;
311
312
  if (shouldRegisterSessionKeysOnSignin()) {
@@ -102,14 +102,14 @@ require('../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
102
102
  const MfaVerificationView = ({ type, isInitialSetup = false, showBackButton = false, deviceId, }) => {
103
103
  const { t } = reactI18next.useTranslation();
104
104
  const { clearStackAndPush, pushView, goBack, canGoBack } = ViewContext.useViewContext();
105
- const { authDevice } = useMfa.useMfa();
105
+ const { authenticateDevice } = useMfa.useMfa();
106
106
  const [code, setCode] = React.useState('');
107
107
  const [error, setError] = React.useState();
108
108
  const [isRateLimited, setIsRateLimited] = React.useState(false);
109
- const { data: isValid, isLoading } = usePromise.usePromise(() => authDevice(code, type, deviceId), {
109
+ const { data: mfaToken, isLoading } = usePromise.usePromise(() => authenticateDevice({ code, deviceId, type }), {
110
110
  deps: [code],
111
111
  enabled: (code === null || code === void 0 ? void 0 : code.length) === 6,
112
- initialData: false,
112
+ initialData: undefined,
113
113
  onReject: (err) => {
114
114
  if (err instanceof utils.MfaRateLimitedError) {
115
115
  setIsRateLimited(true);
@@ -135,7 +135,7 @@ const MfaVerificationView = ({ type, isInitialSetup = false, showBackButton = fa
135
135
  setCode(code);
136
136
  };
137
137
  const onClickBack = canGoBack && showBackButton ? goBack : undefined;
138
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(OTPVerificationView.OTPVerificationView, { MainIcon: passwordHero.ReactComponent, error: error, isLoading: isLoading, onPinComplete: onSubmit, isValid: Boolean(isValid), onPinChange: onCodeChange, description: t('dyn_mfa.otp_verification_view.body'), onClickBack: onClickBack, disabled: isRateLimited }), !isInitialSetup && (jsxRuntime.jsx("div", { className: 'mfa-verification-view__choose-another-method', children: jsxRuntime.jsx(TextButton.TextButton, { className: 'mfa-verification-view__choose-another-method-button', onClick: () => pushView('mfa-choose-device', { isInitialSetup }), copykey: 'dyn_mfa.otp_verification_view.choose_another_method', children: t('dyn_mfa.otp_verification_view.choose_another_method') }) }))] }));
138
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(OTPVerificationView.OTPVerificationView, { MainIcon: passwordHero.ReactComponent, error: error, isLoading: isLoading, onPinComplete: onSubmit, isValid: Boolean(mfaToken), onPinChange: onCodeChange, description: t('dyn_mfa.otp_verification_view.body'), onClickBack: onClickBack, disabled: isRateLimited }), !isInitialSetup && (jsxRuntime.jsx("div", { className: 'mfa-verification-view__choose-another-method', children: jsxRuntime.jsx(TextButton.TextButton, { className: 'mfa-verification-view__choose-another-method-button', onClick: () => pushView('mfa-choose-device', { isInitialSetup }), copykey: 'dyn_mfa.otp_verification_view.choose_another_method', children: t('dyn_mfa.otp_verification_view.choose_another_method') }) }))] }));
139
139
  };
140
140
 
141
141
  exports.MfaVerificationView = MfaVerificationView;
@@ -98,14 +98,14 @@ import '../../shared/utils/functions/getInitialUrl/getInitialUrl.js';
98
98
  const MfaVerificationView = ({ type, isInitialSetup = false, showBackButton = false, deviceId, }) => {
99
99
  const { t } = useTranslation();
100
100
  const { clearStackAndPush, pushView, goBack, canGoBack } = useViewContext();
101
- const { authDevice } = useMfa();
101
+ const { authenticateDevice } = useMfa();
102
102
  const [code, setCode] = useState('');
103
103
  const [error, setError] = useState();
104
104
  const [isRateLimited, setIsRateLimited] = useState(false);
105
- const { data: isValid, isLoading } = usePromise(() => authDevice(code, type, deviceId), {
105
+ const { data: mfaToken, isLoading } = usePromise(() => authenticateDevice({ code, deviceId, type }), {
106
106
  deps: [code],
107
107
  enabled: (code === null || code === void 0 ? void 0 : code.length) === 6,
108
- initialData: false,
108
+ initialData: undefined,
109
109
  onReject: (err) => {
110
110
  if (err instanceof MfaRateLimitedError) {
111
111
  setIsRateLimited(true);
@@ -131,7 +131,7 @@ const MfaVerificationView = ({ type, isInitialSetup = false, showBackButton = fa
131
131
  setCode(code);
132
132
  };
133
133
  const onClickBack = canGoBack && showBackButton ? goBack : undefined;
134
- return (jsxs(Fragment, { children: [jsx(OTPVerificationView, { MainIcon: SvgPasswordHero, error: error, isLoading: isLoading, onPinComplete: onSubmit, isValid: Boolean(isValid), onPinChange: onCodeChange, description: t('dyn_mfa.otp_verification_view.body'), onClickBack: onClickBack, disabled: isRateLimited }), !isInitialSetup && (jsx("div", { className: 'mfa-verification-view__choose-another-method', children: jsx(TextButton, { className: 'mfa-verification-view__choose-another-method-button', onClick: () => pushView('mfa-choose-device', { isInitialSetup }), copykey: 'dyn_mfa.otp_verification_view.choose_another_method', children: t('dyn_mfa.otp_verification_view.choose_another_method') }) }))] }));
134
+ return (jsxs(Fragment, { children: [jsx(OTPVerificationView, { MainIcon: SvgPasswordHero, error: error, isLoading: isLoading, onPinComplete: onSubmit, isValid: Boolean(mfaToken), onPinChange: onCodeChange, description: t('dyn_mfa.otp_verification_view.body'), onClickBack: onClickBack, disabled: isRateLimited }), !isInitialSetup && (jsx("div", { className: 'mfa-verification-view__choose-another-method', children: jsx(TextButton, { className: 'mfa-verification-view__choose-another-method-button', onClick: () => pushView('mfa-choose-device', { isInitialSetup }), copykey: 'dyn_mfa.otp_verification_view.choose_another_method', children: t('dyn_mfa.otp_verification_view.choose_another_method') }) }))] }));
135
135
  };
136
136
 
137
137
  export { MfaVerificationView };