@dynamic-labs/sdk-react-core 0.19.0-alpha.22 → 0.19.0-alpha.24

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,21 @@
1
1
 
2
+ ## [0.19.0-alpha.24](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.23...v0.19.0-alpha.24) (2023-10-24)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * check state from message receiver is same as generated oauth state ([#3675](https://github.com/dynamic-labs/DynamicAuth/issues/3675)) ([2407b6c](https://github.com/dynamic-labs/DynamicAuth/commit/2407b6cff09985bbd5b044e44ab600540a4c69cb))
8
+
9
+ ## [0.19.0-alpha.23](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.22...v0.19.0-alpha.23) (2023-10-24)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * better handling of CB wallet disconnect + upgrade to 3.7.2 ([#3659](https://github.com/dynamic-labs/DynamicAuth/issues/3659)) ([42a0857](https://github.com/dynamic-labs/DynamicAuth/commit/42a0857c66101cde901661e844c66ba324ff641b))
15
+ * calculate the settings override in real time ([#3671](https://github.com/dynamic-labs/DynamicAuth/issues/3671)) ([06cf28d](https://github.com/dynamic-labs/DynamicAuth/commit/06cf28d4dc29dda21312691985ed1b903d3120cc))
16
+ * handle rp.id edgecases for private domains due to webauthn restrictions on scoping to them ([#3658](https://github.com/dynamic-labs/DynamicAuth/issues/3658)) ([7067bc5](https://github.com/dynamic-labs/DynamicAuth/commit/7067bc5110afb8a010f13c2b2e0170faaa840995))
17
+ * twitter origin check should also look for current window location origin ([#3676](https://github.com/dynamic-labs/DynamicAuth/issues/3676)) ([6c30989](https://github.com/dynamic-labs/DynamicAuth/commit/6c30989d4cde3516a177f6290b5376c5d4c61cbc))
18
+
2
19
  ## [0.19.0-alpha.22](https://github.com/dynamic-labs/DynamicAuth/compare/v0.19.0-alpha.21...v0.19.0-alpha.22) (2023-10-23)
3
20
 
4
21
 
package/package.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var version = "0.19.0-alpha.22";
5
+ var version = "0.19.0-alpha.24";
6
6
  var dependencies = {
7
7
  "@dynamic-labs/iconic": "0.1.34",
8
8
  "@dynamic-labs/sdk-api": "0.0.291",
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
- var version = "0.19.0-alpha.22";
1
+ var version = "0.19.0-alpha.24";
2
2
  var dependencies = {
3
3
  "@dynamic-labs/iconic": "0.1.34",
4
4
  "@dynamic-labs/sdk-api": "0.0.291",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/sdk-react-core",
3
- "version": "0.19.0-alpha.22",
3
+ "version": "0.19.0-alpha.24",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -17,13 +17,13 @@
17
17
  "react-focus-lock": "2.9.2",
18
18
  "react-i18next": "^13.2.0",
19
19
  "yup": "0.32.11",
20
- "@dynamic-labs/logger": "0.19.0-alpha.22",
21
- "@dynamic-labs/multi-wallet": "0.19.0-alpha.22",
22
- "@dynamic-labs/rpc-providers": "0.19.0-alpha.22",
23
- "@dynamic-labs/types": "0.19.0-alpha.22",
24
- "@dynamic-labs/utils": "0.19.0-alpha.22",
25
- "@dynamic-labs/wallet-book": "0.19.0-alpha.22",
26
- "@dynamic-labs/wallet-connector-core": "0.19.0-alpha.22",
20
+ "@dynamic-labs/logger": "0.19.0-alpha.24",
21
+ "@dynamic-labs/multi-wallet": "0.19.0-alpha.24",
22
+ "@dynamic-labs/rpc-providers": "0.19.0-alpha.24",
23
+ "@dynamic-labs/types": "0.19.0-alpha.24",
24
+ "@dynamic-labs/utils": "0.19.0-alpha.24",
25
+ "@dynamic-labs/wallet-book": "0.19.0-alpha.24",
26
+ "@dynamic-labs/wallet-connector-core": "0.19.0-alpha.24",
27
27
  "eventemitter3": "5.0.1"
28
28
  },
29
29
  "devDependencies": {
package/src/index.cjs CHANGED
@@ -117,7 +117,6 @@ require('react-focus-lock');
117
117
  require('./lib/components/Transition/ZoomTransition/ZoomTransition.cjs');
118
118
  require('./lib/components/Transition/SlideInUpTransition/SlideInUpTransition.cjs');
119
119
  require('./lib/components/Transition/OpacityTransition/OpacityTransition.cjs');
120
- var useFetchProjectSettings = require('./lib/utils/hooks/useFetchProjectSettings/useFetchProjectSettings.cjs');
121
120
  require('./lib/config/ApiEndpoint.cjs');
122
121
  require('./lib/utils/hooks/useWallets/utils/verifyMagicIsSetup/verifyMagicIsSetup.cjs');
123
122
  var isSameWalletName = require('./lib/utils/functions/isSameWalletName/isSameWalletName.cjs');
@@ -292,7 +291,6 @@ Object.defineProperty(exports, 'DynamicJwtFromJSON', {
292
291
  get: function () { return sdkApi.DynamicJwtFromJSON; }
293
292
  });
294
293
  exports.ShadowDOM = ShadowDOM.ShadowDOM;
295
- exports.useFetchProjectSettings = useFetchProjectSettings.useFetchProjectSettings;
296
294
  exports.isSameWalletName = isSameWalletName.isSameWalletName;
297
295
  exports.MockContext = MockContext.MockContext;
298
296
  exports.MockContextProvider = MockContext.MockContextProvider;
package/src/index.d.ts CHANGED
@@ -23,7 +23,7 @@ export { classNames } from './lib/utils/functions/classNames';
23
23
  export { getNetwork } from './lib/utils/functions/getNetwork';
24
24
  export * from './lib/utils/functions/walletFilters';
25
25
  export { DynamicWidgetContextProvider } from './lib/widgets/DynamicWidget/context';
26
- export { useFetchProjectSettings, useWalletItemActions, useAuthenticateConnectedUser, useSocialAccounts, useEmbeddedWallet, useIsLoggedIn, } from './lib/utils/hooks';
26
+ export { useWalletItemActions, useAuthenticateConnectedUser, useSocialAccounts, useEmbeddedWallet, useIsLoggedIn, } from './lib/utils/hooks';
27
27
  export { useUserUpdateRequest } from './lib/utils/hooks';
28
28
  export { type VerifyEmailCallback, useEmailVerificationRequest, } from './lib/utils/hooks/authenticationHooks/';
29
29
  export type { UpdateUserFieldsArg } from './lib/utils/hooks/';
package/src/index.js CHANGED
@@ -113,7 +113,6 @@ import 'react-focus-lock';
113
113
  import './lib/components/Transition/ZoomTransition/ZoomTransition.js';
114
114
  import './lib/components/Transition/SlideInUpTransition/SlideInUpTransition.js';
115
115
  import './lib/components/Transition/OpacityTransition/OpacityTransition.js';
116
- export { useFetchProjectSettings } from './lib/utils/hooks/useFetchProjectSettings/useFetchProjectSettings.js';
117
116
  import './lib/config/ApiEndpoint.js';
118
117
  import './lib/utils/hooks/useWallets/utils/verifyMagicIsSetup/verifyMagicIsSetup.js';
119
118
  export { isSameWalletName } from './lib/utils/functions/isSameWalletName/isSameWalletName.js';
@@ -101,7 +101,8 @@ const SocialSignIn = ({ providers, onSelectProvider, isLoading, selectedProvider
101
101
  jsxRuntime.jsx(iconic.SocialIcon, { name: getProviderAsString(provider), variant: iconThemeVariant }), isSpinning: selectedProvider === provider, iconSize: 32 }), !insideCard && fullWidth && (jsxRuntime.jsxs(Typography.Typography, { variant: 'button_primary', children: ["Connect with ", capitalize.capitalize(getProviderAsString(provider))] }))] }, getProviderAsString(provider)));
102
102
  return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", { className: 'social-sign-in', style: {
103
103
  '--number-of-social-grid-items': numberOfSocialGridItems,
104
- }, "data-testid": testId, children: [defaultProvider && renderProviderItem(defaultProvider, true), socialProvidersToDisplayInline.map((provider) => renderProviderItem(provider, socialProvidersToDisplayInline.length < 2)), showCardButton && (jsxRuntime.jsx(IconListTile.IconListTile, { dataTestId: 'show-more-options', onClick: () => setShowCard(true), className: 'social-sign-in--tile', children: jsxRuntime.jsx(Icon.Icon, { color: 'text-primary', children: jsxRuntime.jsx(dotsHorizontal.ReactComponent, {}) }) }, 'show-more-options'))] }), jsxRuntime.jsx(OverlayCard.OverlayCard, { isOpen: showCard, onClickOverlay: closeCard, children: jsxRuntime.jsxs("div", { className: 'social-sign-in--card', children: [jsxRuntime.jsx(ModalHeader.ModalHeader, { trailing: closeButton, children: jsxRuntime.jsx(Typography.Typography, { weight: 'medium', variant: 'body_normal', color: 'primary', as: 'span', children: "Choose a social account" }) }), jsxRuntime.jsx("div", { className: 'social-sign-in--card--body', children: providers.map((provider) => renderProviderItem(provider, false, true)) })] }) })] }));
104
+ }, "data-testid": testId, children: [defaultProvider && renderProviderItem(defaultProvider, true), socialProvidersToDisplayInline.map((provider) => renderProviderItem(provider, socialProvidersToDisplayInline.length <
105
+ 4 - (defaultProvider ? 1 : 0))), showCardButton && (jsxRuntime.jsx(IconListTile.IconListTile, { dataTestId: 'show-more-options', onClick: () => setShowCard(true), className: 'social-sign-in--tile', children: jsxRuntime.jsx(Icon.Icon, { color: 'text-primary', children: jsxRuntime.jsx(dotsHorizontal.ReactComponent, {}) }) }, 'show-more-options'))] }), jsxRuntime.jsx(OverlayCard.OverlayCard, { isOpen: showCard, onClickOverlay: closeCard, children: jsxRuntime.jsxs("div", { className: 'social-sign-in--card', children: [jsxRuntime.jsx(ModalHeader.ModalHeader, { trailing: closeButton, children: jsxRuntime.jsx(Typography.Typography, { weight: 'medium', variant: 'body_normal', color: 'primary', as: 'span', children: "Choose a social account" }) }), jsxRuntime.jsx("div", { className: 'social-sign-in--card--body', children: providers.map((provider) => renderProviderItem(provider, false, true)) })] }) })] }));
105
106
  };
106
107
 
107
108
  exports.SocialSignIn = SocialSignIn;
@@ -97,7 +97,8 @@ const SocialSignIn = ({ providers, onSelectProvider, isLoading, selectedProvider
97
97
  jsx(SocialIcon, { name: getProviderAsString(provider), variant: iconThemeVariant }), isSpinning: selectedProvider === provider, iconSize: 32 }), !insideCard && fullWidth && (jsxs(Typography, { variant: 'button_primary', children: ["Connect with ", capitalize(getProviderAsString(provider))] }))] }, getProviderAsString(provider)));
98
98
  return (jsxs(Fragment, { children: [jsxs("div", { className: 'social-sign-in', style: {
99
99
  '--number-of-social-grid-items': numberOfSocialGridItems,
100
- }, "data-testid": testId, children: [defaultProvider && renderProviderItem(defaultProvider, true), socialProvidersToDisplayInline.map((provider) => renderProviderItem(provider, socialProvidersToDisplayInline.length < 2)), showCardButton && (jsx(IconListTile, { dataTestId: 'show-more-options', onClick: () => setShowCard(true), className: 'social-sign-in--tile', children: jsx(Icon, { color: 'text-primary', children: jsx(SvgDotsHorizontal, {}) }) }, 'show-more-options'))] }), jsx(OverlayCard, { isOpen: showCard, onClickOverlay: closeCard, children: jsxs("div", { className: 'social-sign-in--card', children: [jsx(ModalHeader, { trailing: closeButton, children: jsx(Typography, { weight: 'medium', variant: 'body_normal', color: 'primary', as: 'span', children: "Choose a social account" }) }), jsx("div", { className: 'social-sign-in--card--body', children: providers.map((provider) => renderProviderItem(provider, false, true)) })] }) })] }));
100
+ }, "data-testid": testId, children: [defaultProvider && renderProviderItem(defaultProvider, true), socialProvidersToDisplayInline.map((provider) => renderProviderItem(provider, socialProvidersToDisplayInline.length <
101
+ 4 - (defaultProvider ? 1 : 0))), showCardButton && (jsx(IconListTile, { dataTestId: 'show-more-options', onClick: () => setShowCard(true), className: 'social-sign-in--tile', children: jsx(Icon, { color: 'text-primary', children: jsx(SvgDotsHorizontal, {}) }) }, 'show-more-options'))] }), jsx(OverlayCard, { isOpen: showCard, onClickOverlay: closeCard, children: jsxs("div", { className: 'social-sign-in--card', children: [jsx(ModalHeader, { trailing: closeButton, children: jsx(Typography, { weight: 'medium', variant: 'body_normal', color: 'primary', as: 'span', children: "Choose a social account" }) }), jsx("div", { className: 'social-sign-in--card--body', children: providers.map((provider) => renderProviderItem(provider, false, true)) })] }) })] }));
101
102
  };
102
103
 
103
104
  export { SocialSignIn };
@@ -1,6 +1,6 @@
1
1
  import { __awaiter } from '../../../_virtual/_tslib.js';
2
2
  import { NoAccessError, AccountExistsError, EmailVerificationError, UserHasAccountWithEmailError, DynamicError, EmailAlreadyExistsError, UsernameAlreadyExistsError, EmailProviderError, WalletUsedError, WalletNotDeployedError, ChainalysisError, GateBlockedError, SocialAccountAlreadyExistsError } from '@dynamic-labs/utils';
3
- import { SDKApi, Configuration, UnprocessableEntityErrorCode, ChainEnum, EmbeddedWalletProviderEnum, VerifyRequestFromJSON, WalletProviderEnum, AuthModeEnum } from '@dynamic-labs/sdk-api';
3
+ import { UnprocessableEntityErrorCode, ChainEnum, EmbeddedWalletProviderEnum, SDKApi, Configuration, VerifyRequestFromJSON, WalletProviderEnum, AuthModeEnum } from '@dynamic-labs/sdk-api';
4
4
  import { VERSION, API_VERSION } from '../../version.js';
5
5
  import ApiEndpoint from '../config/ApiEndpoint.js';
6
6
  import { logger } from '../shared/logger.js';
@@ -31,6 +31,9 @@ const useFetchProjectSettings = ({ authToken, environmentId, maxRetries = 2, dyn
31
31
  removeLsSettings();
32
32
  }
33
33
  const overrideSettings = (projectSettings, overrides) => {
34
+ if (!projectSettings) {
35
+ return undefined;
36
+ }
34
37
  let overrideSettings = projectSettings;
35
38
  if (overrides) {
36
39
  if (overrides.views) {
@@ -65,12 +68,11 @@ const useFetchProjectSettings = ({ authToken, environmentId, maxRetries = 2, dyn
65
68
  .then((response) => {
66
69
  if (!response)
67
70
  throw new utils.DynamicError('Settings are not defined');
68
- const settingsWithOverrides = overrideSettings(response, dynamicContextProps.settings.overrides);
69
71
  const expiry = new Date().getTime() + 60000 * 5;
70
72
  setLsSettings({
71
73
  environmentId,
72
74
  expiry: expiry,
73
- settings: settingsWithOverrides,
75
+ settings: response,
74
76
  });
75
77
  })
76
78
  .catch(() => {
@@ -81,7 +83,12 @@ const useFetchProjectSettings = ({ authToken, environmentId, maxRetries = 2, dyn
81
83
  });
82
84
  }
83
85
  }, [environmentId, isLoading, lsSettingsExists, maxRetries, retries]);
84
- return { isLoading, projectSettings: lsSettings === null || lsSettings === void 0 ? void 0 : lsSettings.settings, removeLsSettings };
86
+ const settingsWithOverride = React.useMemo(() => overrideSettings(lsSettings === null || lsSettings === void 0 ? void 0 : lsSettings.settings, dynamicContextProps.settings.overrides), [lsSettings === null || lsSettings === void 0 ? void 0 : lsSettings.settings, dynamicContextProps.settings.overrides]);
87
+ return {
88
+ isLoading,
89
+ projectSettings: settingsWithOverride,
90
+ removeLsSettings,
91
+ };
85
92
  };
86
93
 
87
94
  exports.useFetchProjectSettings = useFetchProjectSettings;
@@ -1,4 +1,4 @@
1
- import { useState, useEffect } from 'react';
1
+ import { useState, useEffect, useMemo } from 'react';
2
2
  import { DynamicError } from '@dynamic-labs/utils';
3
3
  import { sendDynamicProps, fetchProjectSettings } from '../../../data/api.js';
4
4
  import '@dynamic-labs/sdk-api';
@@ -27,6 +27,9 @@ const useFetchProjectSettings = ({ authToken, environmentId, maxRetries = 2, dyn
27
27
  removeLsSettings();
28
28
  }
29
29
  const overrideSettings = (projectSettings, overrides) => {
30
+ if (!projectSettings) {
31
+ return undefined;
32
+ }
30
33
  let overrideSettings = projectSettings;
31
34
  if (overrides) {
32
35
  if (overrides.views) {
@@ -61,12 +64,11 @@ const useFetchProjectSettings = ({ authToken, environmentId, maxRetries = 2, dyn
61
64
  .then((response) => {
62
65
  if (!response)
63
66
  throw new DynamicError('Settings are not defined');
64
- const settingsWithOverrides = overrideSettings(response, dynamicContextProps.settings.overrides);
65
67
  const expiry = new Date().getTime() + 60000 * 5;
66
68
  setLsSettings({
67
69
  environmentId,
68
70
  expiry: expiry,
69
- settings: settingsWithOverrides,
71
+ settings: response,
70
72
  });
71
73
  })
72
74
  .catch(() => {
@@ -77,7 +79,12 @@ const useFetchProjectSettings = ({ authToken, environmentId, maxRetries = 2, dyn
77
79
  });
78
80
  }
79
81
  }, [environmentId, isLoading, lsSettingsExists, maxRetries, retries]);
80
- return { isLoading, projectSettings: lsSettings === null || lsSettings === void 0 ? void 0 : lsSettings.settings, removeLsSettings };
82
+ const settingsWithOverride = useMemo(() => overrideSettings(lsSettings === null || lsSettings === void 0 ? void 0 : lsSettings.settings, dynamicContextProps.settings.overrides), [lsSettings === null || lsSettings === void 0 ? void 0 : lsSettings.settings, dynamicContextProps.settings.overrides]);
83
+ return {
84
+ isLoading,
85
+ projectSettings: settingsWithOverride,
86
+ removeLsSettings,
87
+ };
81
88
  };
82
89
 
83
90
  export { useFetchProjectSettings };
@@ -194,16 +194,18 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, }) => {
194
194
  if (!(apiProvider === null || apiProvider === void 0 ? void 0 : apiProvider.redirectUrl)) {
195
195
  return;
196
196
  }
197
- let expectedOrigin = '';
198
- try {
199
- const redirectUri = new URL(apiProvider.redirectUrl);
200
- expectedOrigin = redirectUri.origin;
201
- }
202
- catch (e) {
203
- logger.logger.error('Failed to parse social provider redirect url', {
204
- error: e,
205
- });
206
- return;
197
+ let expectedOrigin = window.location.origin;
198
+ if (!providersWithoutWindowOpenerRefence.includes(provider)) {
199
+ try {
200
+ const redirectUri = new URL(apiProvider.redirectUrl);
201
+ expectedOrigin = redirectUri.origin;
202
+ }
203
+ catch (e) {
204
+ logger.logger.error('Failed to parse social provider redirect url', {
205
+ error: e,
206
+ });
207
+ return;
208
+ }
207
209
  }
208
210
  const isExpectedOrigin = event.origin === expectedOrigin;
209
211
  const isValidMessage = isAuthorizationMessage &&
@@ -219,11 +221,17 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, }) => {
219
221
  return;
220
222
  }
221
223
  clearListeners();
222
- const { code, error } = message;
224
+ const { code, error, state: authState } = message;
223
225
  if (error && error !== 'undefined') {
224
226
  handleError(types.SocialOAuthErrorCode.OAUTH_ERROR, `Failed to connect ${provider} social account: ${error}`);
225
227
  return;
226
228
  }
229
+ // check that the state we receive from message is the same state we calculated earlier
230
+ // this could be an attack
231
+ if (state !== authState) {
232
+ handleError(types.SocialOAuthErrorCode.OAUTH_ERROR, `Failed to connect ${provider} social account: Invalid random state`);
233
+ return;
234
+ }
227
235
  if (!code) {
228
236
  handleError(types.SocialOAuthErrorCode.NO_AUTH_CODE, `Failed to connect ${provider} social account: no authorization code`);
229
237
  return;
@@ -190,16 +190,18 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, }) => {
190
190
  if (!(apiProvider === null || apiProvider === void 0 ? void 0 : apiProvider.redirectUrl)) {
191
191
  return;
192
192
  }
193
- let expectedOrigin = '';
194
- try {
195
- const redirectUri = new URL(apiProvider.redirectUrl);
196
- expectedOrigin = redirectUri.origin;
197
- }
198
- catch (e) {
199
- logger.error('Failed to parse social provider redirect url', {
200
- error: e,
201
- });
202
- return;
193
+ let expectedOrigin = window.location.origin;
194
+ if (!providersWithoutWindowOpenerRefence.includes(provider)) {
195
+ try {
196
+ const redirectUri = new URL(apiProvider.redirectUrl);
197
+ expectedOrigin = redirectUri.origin;
198
+ }
199
+ catch (e) {
200
+ logger.error('Failed to parse social provider redirect url', {
201
+ error: e,
202
+ });
203
+ return;
204
+ }
203
205
  }
204
206
  const isExpectedOrigin = event.origin === expectedOrigin;
205
207
  const isValidMessage = isAuthorizationMessage &&
@@ -215,11 +217,17 @@ const useSocialAuth = ({ sessionTimeout, authMode, onSettled, onError, }) => {
215
217
  return;
216
218
  }
217
219
  clearListeners();
218
- const { code, error } = message;
220
+ const { code, error, state: authState } = message;
219
221
  if (error && error !== 'undefined') {
220
222
  handleError(SocialOAuthErrorCode.OAUTH_ERROR, `Failed to connect ${provider} social account: ${error}`);
221
223
  return;
222
224
  }
225
+ // check that the state we receive from message is the same state we calculated earlier
226
+ // this could be an attack
227
+ if (state !== authState) {
228
+ handleError(SocialOAuthErrorCode.OAUTH_ERROR, `Failed to connect ${provider} social account: Invalid random state`);
229
+ return;
230
+ }
223
231
  if (!code) {
224
232
  handleError(SocialOAuthErrorCode.NO_AUTH_CODE, `Failed to connect ${provider} social account: no authorization code`);
225
233
  return;