@dynamic-labs/sdk-react-core 3.0.3 → 4.0.0-alpha.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.
Files changed (102) hide show
  1. package/CHANGELOG.md +11 -10
  2. package/package.cjs +2 -2
  3. package/package.js +2 -2
  4. package/package.json +12 -12
  5. package/src/lib/components/index.d.ts +0 -1
  6. package/src/lib/context/ConnectWithOtpContext/ConnectWithOtpProvider.cjs +5 -2
  7. package/src/lib/context/ConnectWithOtpContext/ConnectWithOtpProvider.js +5 -2
  8. package/src/lib/context/ConnectWithOtpContext/utils/createSmsHandler.cjs +1 -70
  9. package/src/lib/context/ConnectWithOtpContext/utils/createSmsHandler.d.ts +2 -1
  10. package/src/lib/context/ConnectWithOtpContext/utils/createSmsHandler.js +1 -70
  11. package/src/lib/context/DynamicContext/DynamicContext.cjs +6 -5
  12. package/src/lib/context/DynamicContext/DynamicContext.js +6 -5
  13. package/src/lib/context/DynamicContext/hooks/useHandleLogout/useHandleLogout.cjs +68 -0
  14. package/src/lib/context/DynamicContext/hooks/useHandleLogout/useHandleLogout.js +68 -0
  15. package/src/lib/context/DynamicContext/hooks/useRegisterStorageService/useRegisterStorageService.cjs +2 -0
  16. package/src/lib/context/DynamicContext/hooks/useRegisterStorageService/useRegisterStorageService.js +3 -1
  17. package/src/lib/context/PhantomRedirectContext/useResponseHandlers.cjs +1 -1
  18. package/src/lib/context/PhantomRedirectContext/useResponseHandlers.js +1 -1
  19. package/src/lib/context/SocialRedirectContext/SocialRedirectContext.cjs +1 -1
  20. package/src/lib/context/SocialRedirectContext/SocialRedirectContext.js +1 -1
  21. package/src/lib/context/ViewContext/types/index.d.ts +1 -1
  22. package/src/lib/data/api/embeddedWallets/embeddedWallets.cjs +12 -5
  23. package/src/lib/data/api/embeddedWallets/embeddedWallets.d.ts +4 -3
  24. package/src/lib/data/api/embeddedWallets/embeddedWallets.js +14 -7
  25. package/src/lib/data/api/transactions/blockaid.cjs +23 -0
  26. package/src/lib/data/api/transactions/blockaid.js +19 -0
  27. package/src/lib/events/auth.d.ts +2 -0
  28. package/src/lib/locale/en/translation.cjs +34 -0
  29. package/src/lib/locale/en/translation.d.ts +34 -0
  30. package/src/lib/locale/en/translation.js +34 -0
  31. package/src/lib/shared/assets/caution-triangle.cjs +54 -0
  32. package/src/lib/shared/assets/caution-triangle.js +30 -0
  33. package/src/lib/shared/assets/exclamation-circle.cjs +54 -0
  34. package/src/lib/shared/assets/exclamation-circle.js +30 -0
  35. package/src/lib/shared/assets/exclamation.cjs +52 -0
  36. package/src/lib/shared/assets/exclamation.js +28 -0
  37. package/src/lib/shared/assets/index.d.ts +5 -0
  38. package/src/lib/shared/assets/warning-orange.cjs +54 -0
  39. package/src/lib/shared/assets/warning-orange.js +30 -0
  40. package/src/lib/shared/assets/warning-red.cjs +54 -0
  41. package/src/lib/shared/assets/warning-red.js +30 -0
  42. package/src/lib/styles/index.shadow.cjs +1 -1
  43. package/src/lib/styles/index.shadow.js +1 -1
  44. package/src/lib/utils/constants/localStorage.cjs +6 -0
  45. package/src/lib/utils/constants/localStorage.d.ts +3 -0
  46. package/src/lib/utils/constants/localStorage.js +5 -1
  47. package/src/lib/utils/functions/getNewVerifiedCredentialsFromDiff/getNewVerifiedCredentialsFromDiff.cjs +11 -0
  48. package/src/lib/utils/functions/getNewVerifiedCredentialsFromDiff/getNewVerifiedCredentialsFromDiff.d.ts +2 -0
  49. package/src/lib/utils/functions/getNewVerifiedCredentialsFromDiff/getNewVerifiedCredentialsFromDiff.js +7 -0
  50. package/src/lib/utils/functions/getNewVerifiedCredentialsFromDiff/index.d.ts +1 -0
  51. package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.cjs +1 -1
  52. package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.js +1 -1
  53. package/src/lib/utils/hooks/authenticationHooks/useConnectAndSignSplitSteps/useConnectAndSignSplitSteps.cjs +1 -1
  54. package/src/lib/utils/hooks/authenticationHooks/useConnectAndSignSplitSteps/useConnectAndSignSplitSteps.js +1 -1
  55. package/src/lib/utils/hooks/authenticationHooks/useSignConnectOnlyUser/useSignConnectOnlyUser.cjs +1 -1
  56. package/src/lib/utils/hooks/authenticationHooks/useSignConnectOnlyUser/useSignConnectOnlyUser.js +1 -1
  57. package/src/lib/utils/hooks/index.d.ts +1 -0
  58. package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.cjs +1 -0
  59. package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js +1 -0
  60. package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.cjs +9 -2
  61. package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.js +9 -2
  62. package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/utils.cjs +15 -2
  63. package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/utils.d.ts +3 -1
  64. package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/utils.js +15 -3
  65. package/src/lib/utils/hooks/useEmbeddedWalletSessionKeys/useEmbeddedWalletSessionKeys.cjs +82 -26
  66. package/src/lib/utils/hooks/useEmbeddedWalletSessionKeys/useEmbeddedWalletSessionKeys.d.ts +19 -2
  67. package/src/lib/utils/hooks/useEmbeddedWalletSessionKeys/useEmbeddedWalletSessionKeys.js +82 -26
  68. package/src/lib/utils/hooks/useEndUserWarning/index.d.ts +1 -0
  69. package/src/lib/utils/hooks/useEndUserWarning/useEndUserWarning.cjs +37 -0
  70. package/src/lib/utils/hooks/useEndUserWarning/useEndUserWarning.d.ts +5 -0
  71. package/src/lib/utils/hooks/useEndUserWarning/useEndUserWarning.js +33 -0
  72. package/src/lib/utils/hooks/useExternalAuth/useExternalAuth.cjs +5 -2
  73. package/src/lib/utils/hooks/useExternalAuth/useExternalAuth.js +5 -2
  74. package/src/lib/utils/hooks/useSetWalletConnectorFetchers/useSetWalletConnectorFetchers.cjs +2 -2
  75. package/src/lib/utils/hooks/useSetWalletConnectorFetchers/useSetWalletConnectorFetchers.d.ts +2 -1
  76. package/src/lib/utils/hooks/useSetWalletConnectorFetchers/useSetWalletConnectorFetchers.js +2 -2
  77. package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.cjs +7 -3
  78. package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.d.ts +2 -1
  79. package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.js +7 -3
  80. package/src/lib/utils/hooks/useTelegramLogin/useTelegramLogin.cjs +25 -24
  81. package/src/lib/utils/hooks/useTelegramLogin/useTelegramLogin.d.ts +7 -1
  82. package/src/lib/utils/hooks/useTelegramLogin/useTelegramLogin.js +25 -24
  83. package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.cjs +4 -1
  84. package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.js +4 -1
  85. package/src/lib/views/EmailVerification/EmailVerification.cjs +4 -1
  86. package/src/lib/views/EmailVerification/EmailVerification.js +4 -1
  87. package/src/lib/views/GlobalWalletMaliciousView/GlobalWalletMaliciousView.cjs +139 -0
  88. package/src/lib/views/GlobalWalletMaliciousView/GlobalWalletMaliciousView.d.ts +11 -0
  89. package/src/lib/views/GlobalWalletMaliciousView/GlobalWalletMaliciousView.js +134 -0
  90. package/src/lib/views/SmsVerification/useSmsVerification/useSmsVerification.cjs +5 -2
  91. package/src/lib/views/SmsVerification/useSmsVerification/useSmsVerification.js +5 -2
  92. package/src/lib/views/viewToComponentMap.cjs +2 -0
  93. package/src/lib/views/viewToComponentMap.d.ts +1 -0
  94. package/src/lib/views/viewToComponentMap.js +2 -0
  95. package/src/lib/widgets/DynamicWidget/views/GlobalWalletView/GlobalWalletView.cjs +31 -8
  96. package/src/lib/widgets/DynamicWidget/views/GlobalWalletView/GlobalWalletView.js +31 -8
  97. package/src/lib/components/TelegramAutoLogin/TelegramAutoLogin.cjs +0 -99
  98. package/src/lib/components/TelegramAutoLogin/TelegramAutoLogin.d.ts +0 -1
  99. package/src/lib/components/TelegramAutoLogin/TelegramAutoLogin.js +0 -95
  100. package/src/lib/components/TelegramAutoLogin/index.d.ts +0 -1
  101. package/src/lib/utils/constants/sessionStorage.cjs +0 -12
  102. package/src/lib/utils/constants/sessionStorage.js +0 -7
@@ -1,10 +1,10 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../../../../_virtual/_tslib.js';
3
3
  import { useCallback } from 'react';
4
- import { StorageService } from '@dynamic-labs/utils';
5
- import { SECURE_ENCLAVE_WALLET_SESSION_KEYS, SECURE_ENCLAVE_WALLET_SESSION_KEYS_STORAGE_OPTIONS } from '../../constants/sessionStorage.js';
6
- import { p256Keygen } from '../useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/utils.js';
7
- import '@dynamic-labs/sdk-api-core';
4
+ import { StorageService, InvalidEmbeddedWalletSessionKeyError } from '@dynamic-labs/utils';
5
+ import { EmbeddedWalletVersionEnum } from '@dynamic-labs/sdk-api-core';
6
+ import { SECURE_ENCLAVE_WALLET_SESSION_KEYS, SECURE_ENCLAVE_WALLET_SESSION_KEYS_STORAGE_OPTIONS } from '../../constants/localStorage.js';
7
+ import { p256Sign, p256Keygen } from '../useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/utils.js';
8
8
  import '../../../shared/logger.js';
9
9
  import '@dynamic-labs/iconic';
10
10
  import '@dynamic-labs/wallet-connector-core';
@@ -20,39 +20,95 @@ import '@dynamic-labs/multi-wallet';
20
20
  import 'react-international-phone';
21
21
  import '../../../store/state/projectSettings/projectSettings.js';
22
22
  import { registerSessionKey } from '../../../data/api/embeddedWallets/embeddedWallets.js';
23
- import '../../../store/state/user/user.js';
23
+ import { useUser } from '../../../store/state/user/user.js';
24
24
  import '../../../locale/locale.js';
25
+ import { dynamicEvents } from '../../../events/dynamicEvents.js';
25
26
 
26
- const useEmbeddedWalletSessionKeys = (environmentId) => {
27
+ const useEmbeddedWalletSessionKeys = ({ environmentId, projectSettings, }) => {
28
+ const { user } = useUser();
29
+ // scenario 1: first time session register on first transaction.
30
+ // Keys will have been previously generated at this point in local storage but marked as not registered
31
+ // scenario 2: 2nd time register after expiration (key refresh)
32
+ // scenario 3: refresh/rerender page - session still active
33
+ // scenario 4: refresh/rerender page - session no longer active
27
34
  const registerEmbeddedWalletSessionKey = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* ({ ignoreRestore = false, } = {}) {
28
35
  // check if session keys are already stored in session storage
29
36
  const sessionKeysSS = StorageService.getItem(SECURE_ENCLAVE_WALLET_SESSION_KEYS, SECURE_ENCLAVE_WALLET_SESSION_KEYS_STORAGE_OPTIONS);
30
- if (sessionKeysSS && !ignoreRestore) {
31
- const sessionKeysInSS = JSON.parse(Buffer.from(sessionKeysSS, 'base64').toString());
32
- return sessionKeysInSS;
37
+ const decodedSessionKeys = sessionKeysSS
38
+ ? JSON.parse(Buffer.from(sessionKeysSS, 'base64').toString())
39
+ : undefined;
40
+ if (!decodedSessionKeys) {
41
+ dynamicEvents.emit('triggerLogout');
42
+ throw new Error('Could not find session keys. Re-authentication is required to create new session keys.');
33
43
  }
34
- const { publicKey, privateKey } = yield generateSessionKey();
35
- yield registerSessionKey({
36
- environmentId,
37
- publicKey,
38
- });
39
- return { privateKey, publicKey };
44
+ if (!user) {
45
+ throw new Error('User not found');
46
+ }
47
+ if (decodedSessionKeys.expirationDate &&
48
+ new Date() <= new Date(decodedSessionKeys.expirationDate) &&
49
+ !ignoreRestore) {
50
+ // scenario 3
51
+ return decodedSessionKeys;
52
+ }
53
+ let publicKey;
54
+ let privateKey;
55
+ let privateKeyJwk;
56
+ let prevSessionKeySignature = undefined;
57
+ if (!decodedSessionKeys.registered) {
58
+ // scenario 1
59
+ ({ publicKey, privateKey, privateKeyJwk } = decodedSessionKeys);
60
+ }
61
+ else {
62
+ // scenario 2 and 4
63
+ const { publicKey: nextPublicKey, privateKey: nextPrivateKey, privateKeyJwk: nextPrivateKeyJwk, } = yield generateSessionKey();
64
+ publicKey = nextPublicKey;
65
+ privateKey = nextPrivateKey;
66
+ privateKeyJwk = nextPrivateKeyJwk;
67
+ prevSessionKeySignature = yield p256Sign(decodedSessionKeys.privateKeyJwk, user.sessionId);
68
+ }
69
+ let resp;
70
+ try {
71
+ resp = yield registerSessionKey({
72
+ environmentId,
73
+ prevSessionKeySignature,
74
+ publicKey,
75
+ });
76
+ }
77
+ catch (error) {
78
+ if (error instanceof InvalidEmbeddedWalletSessionKeyError) {
79
+ // this can happen if the public key passed during initial registration
80
+ // does not match the root session public key that the backend expects
81
+ dynamicEvents.emit('triggerLogout');
82
+ }
83
+ throw error;
84
+ }
85
+ const expirationDate = new Date(resp.expiresAt * 1000);
86
+ StorageService.setItem(SECURE_ENCLAVE_WALLET_SESSION_KEYS, toEncodedFormat(publicKey, privateKey, privateKeyJwk, true, expirationDate), SECURE_ENCLAVE_WALLET_SESSION_KEYS_STORAGE_OPTIONS);
87
+ return { expirationDate, privateKey, publicKey };
40
88
  });
41
89
  const generateSessionKey = () => __awaiter(void 0, void 0, void 0, function* () {
42
- const { private: privateKey, public: publicKey } = yield p256Keygen();
90
+ const { private: privateKey, public: publicKey, privateJwk, } = yield p256Keygen();
43
91
  // convert to base64 and store the session keys in session storage
44
- const newSessionKeys = { privateKey, publicKey };
45
- const sessionKeysString = JSON.stringify(newSessionKeys);
46
- const sessionKeysBase64 = Buffer.from(sessionKeysString).toString('base64');
47
- StorageService.setItem(SECURE_ENCLAVE_WALLET_SESSION_KEYS, sessionKeysBase64, SECURE_ENCLAVE_WALLET_SESSION_KEYS_STORAGE_OPTIONS);
48
- return { privateKey, publicKey };
92
+ StorageService.setItem(SECURE_ENCLAVE_WALLET_SESSION_KEYS, toEncodedFormat(publicKey, privateKey, privateJwk, false), SECURE_ENCLAVE_WALLET_SESSION_KEYS_STORAGE_OPTIONS);
93
+ return { privateKey, privateKeyJwk: privateJwk, publicKey };
49
94
  });
95
+ const shouldRegisterSessionKeysOnSignin = () => {
96
+ var _a;
97
+ return ((_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _a === void 0 ? void 0 : _a.defaultWalletVersion) ===
98
+ EmbeddedWalletVersionEnum.V2;
99
+ };
100
+ const toEncodedFormat = (publicKey, privateKey, privateKeyJwk, registered, expirationDate) => {
101
+ const sessionKeys = {
102
+ expirationDate,
103
+ privateKey,
104
+ privateKeyJwk,
105
+ publicKey,
106
+ registered,
107
+ };
108
+ const sessionKeysString = JSON.stringify(sessionKeys);
109
+ return Buffer.from(sessionKeysString).toString('base64');
110
+ };
50
111
  const removeSessionKey = useCallback(() => StorageService.removeItem(SECURE_ENCLAVE_WALLET_SESSION_KEYS, SECURE_ENCLAVE_WALLET_SESSION_KEYS_STORAGE_OPTIONS), []);
51
- const shouldRegisterSessionKeysOnSignin = () => false;
52
- // TODO: uncomment this once we actually implement and enforce session key chaining
53
- // GVTY-2206
54
- // projectSettings?.sdk?.embeddedWallets?.defaultWalletVersion ===
55
- // EmbeddedWalletVersionEnum.V2;
56
112
  return {
57
113
  generateSessionKey,
58
114
  registerEmbeddedWalletSessionKey,
@@ -0,0 +1 @@
1
+ export { useEndUserWarning } from './useEndUserWarning';
@@ -0,0 +1,37 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var React = require('react');
7
+ var sdkApiCore = require('@dynamic-labs/sdk-api-core');
8
+ var logger = require('../../../shared/logger.cjs');
9
+ require('@dynamic-labs/iconic');
10
+ require('@dynamic-labs/wallet-connector-core');
11
+ require('react/jsx-runtime');
12
+ require('../../../context/ViewContext/ViewContext.cjs');
13
+ require('@dynamic-labs/wallet-book');
14
+ require('@dynamic-labs/utils');
15
+ require('../../constants/colors.cjs');
16
+ require('../../constants/values.cjs');
17
+ require('../../../store/state/loadingAndLifecycle.cjs');
18
+ require('../../../shared/consts/index.cjs');
19
+
20
+ let didLog = false;
21
+ const useEndUserWarning = ({ projectSettings, }) => {
22
+ React.useEffect(() => {
23
+ var _a;
24
+ if (!didLog && (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.environmentName) === sdkApiCore.EnvironmentEnum.Live) {
25
+ didLog = true;
26
+ logger.logger.info('%cWarning!', 'color: red; font-size: 32px;');
27
+ logger.logger.info('%cThis is a browser feature intended for developers. You are reading this message because you opened the browser console, a developer tool.\n\n%c1. Never share your tokens or sensitive information with anyone.\n2. Do not paste any code you do not fully understand.\n3. If someone instructed you to do this, it is likely a scam.\n\n%cInjecting code into your browser could result in loss of tokens or control of your account that cannot be recovered or protected.', 'font-size: 16px;', 'font-size: 12px;', 'color: red; font-size: 12px;');
28
+ if (((_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.general) === null || _a === void 0 ? void 0 : _a.supportUrls) &&
29
+ Object.values(projectSettings.general.supportUrls).length > 0) {
30
+ logger.logger.info(`%cFor more information, visit ${Object.values(projectSettings.general.supportUrls)[0]}`, 'font-size: 12px;');
31
+ }
32
+ }
33
+ // eslint-disable-next-line react-hooks/exhaustive-deps
34
+ }, [projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.environmentName]);
35
+ };
36
+
37
+ exports.useEndUserWarning = useEndUserWarning;
@@ -0,0 +1,5 @@
1
+ import { ProjectSettings } from '@dynamic-labs/sdk-api-core';
2
+ export declare const resetEndUserWarning: () => void;
3
+ export declare const useEndUserWarning: ({ projectSettings, }: {
4
+ projectSettings?: ProjectSettings;
5
+ }) => void;
@@ -0,0 +1,33 @@
1
+ 'use client'
2
+ import { useEffect } from 'react';
3
+ import { EnvironmentEnum } from '@dynamic-labs/sdk-api-core';
4
+ import { logger } from '../../../shared/logger.js';
5
+ import '@dynamic-labs/iconic';
6
+ import '@dynamic-labs/wallet-connector-core';
7
+ import 'react/jsx-runtime';
8
+ import '../../../context/ViewContext/ViewContext.js';
9
+ import '@dynamic-labs/wallet-book';
10
+ import '@dynamic-labs/utils';
11
+ import '../../constants/colors.js';
12
+ import '../../constants/values.js';
13
+ import '../../../store/state/loadingAndLifecycle.js';
14
+ import '../../../shared/consts/index.js';
15
+
16
+ let didLog = false;
17
+ const useEndUserWarning = ({ projectSettings, }) => {
18
+ useEffect(() => {
19
+ var _a;
20
+ if (!didLog && (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.environmentName) === EnvironmentEnum.Live) {
21
+ didLog = true;
22
+ logger.info('%cWarning!', 'color: red; font-size: 32px;');
23
+ logger.info('%cThis is a browser feature intended for developers. You are reading this message because you opened the browser console, a developer tool.\n\n%c1. Never share your tokens or sensitive information with anyone.\n2. Do not paste any code you do not fully understand.\n3. If someone instructed you to do this, it is likely a scam.\n\n%cInjecting code into your browser could result in loss of tokens or control of your account that cannot be recovered or protected.', 'font-size: 16px;', 'font-size: 12px;', 'color: red; font-size: 12px;');
24
+ if (((_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.general) === null || _a === void 0 ? void 0 : _a.supportUrls) &&
25
+ Object.values(projectSettings.general.supportUrls).length > 0) {
26
+ logger.info(`%cFor more information, visit ${Object.values(projectSettings.general.supportUrls)[0]}`, 'font-size: 12px;');
27
+ }
28
+ }
29
+ // eslint-disable-next-line react-hooks/exhaustive-deps
30
+ }, [projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.environmentName]);
31
+ };
32
+
33
+ export { useEndUserWarning };
@@ -95,8 +95,11 @@ require('../../../store/state/tokenBalances.cjs');
95
95
  var useInternalDynamicContext = require('../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.cjs');
96
96
 
97
97
  const useExternalAuth = () => {
98
- const { environmentId, setShowAuthFlow, setCallback } = useInternalDynamicContext.useInternalDynamicContext();
99
- const { generateSessionKey, shouldRegisterSessionKeysOnSignin } = useEmbeddedWalletSessionKeys.useEmbeddedWalletSessionKeys(environmentId);
98
+ const { environmentId, setShowAuthFlow, setCallback, projectSettings } = useInternalDynamicContext.useInternalDynamicContext();
99
+ const { generateSessionKey, shouldRegisterSessionKeysOnSignin } = useEmbeddedWalletSessionKeys.useEmbeddedWalletSessionKeys({
100
+ environmentId,
101
+ projectSettings,
102
+ });
100
103
  /**
101
104
  * Uses a properly-conifigured non-Dynamic external JWT and user ID to sign-in to Dynamic.
102
105
  * When successful, this should grant the user the ability to access Dynamic's functionality
@@ -91,8 +91,11 @@ import '../../../store/state/tokenBalances.js';
91
91
  import { useInternalDynamicContext } from '../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.js';
92
92
 
93
93
  const useExternalAuth = () => {
94
- const { environmentId, setShowAuthFlow, setCallback } = useInternalDynamicContext();
95
- const { generateSessionKey, shouldRegisterSessionKeysOnSignin } = useEmbeddedWalletSessionKeys(environmentId);
94
+ const { environmentId, setShowAuthFlow, setCallback, projectSettings } = useInternalDynamicContext();
95
+ const { generateSessionKey, shouldRegisterSessionKeysOnSignin } = useEmbeddedWalletSessionKeys({
96
+ environmentId,
97
+ projectSettings,
98
+ });
96
99
  /**
97
100
  * Uses a properly-conifigured non-Dynamic external JWT and user ID to sign-in to Dynamic.
98
101
  * When successful, this should grant the user the ability to access Dynamic's functionality
@@ -92,8 +92,8 @@ require('../../../context/ConnectWithOtpContext/constants.cjs');
92
92
  require('../../../context/ReinitializeContext/ReinitializeContextProvider.cjs');
93
93
  require('../../../store/state/tokenBalances.cjs');
94
94
 
95
- const useSetWalletConnectorFetchers = (walletOptions, environmentId) => {
96
- const { registerEmbeddedWalletSessionKey, removeSessionKey } = useEmbeddedWalletSessionKeys.useEmbeddedWalletSessionKeys(environmentId);
95
+ const useSetWalletConnectorFetchers = (walletOptions, environmentId, projectSettings) => {
96
+ const { registerEmbeddedWalletSessionKey, removeSessionKey } = useEmbeddedWalletSessionKeys.useEmbeddedWalletSessionKeys({ environmentId, projectSettings });
97
97
  if (!(walletOptions === null || walletOptions === void 0 ? void 0 : walletOptions.length))
98
98
  return;
99
99
  const { fetchAuthToken, fetchBackupCode, fetchPasscode } = getCoinbaseMPCConnectorFetchers.getCoinbaseMPCConnectorFetchers({ environmentId });
@@ -1,2 +1,3 @@
1
+ import { ProjectSettings } from '@dynamic-labs/sdk-api-core';
1
2
  import { WalletOption } from '../../../shared';
2
- export declare const useSetWalletConnectorFetchers: (walletOptions: WalletOption[] | undefined, environmentId: string) => void;
3
+ export declare const useSetWalletConnectorFetchers: (walletOptions: WalletOption[] | undefined, environmentId: string, projectSettings: ProjectSettings | undefined) => void;
@@ -88,8 +88,8 @@ import '../../../context/ConnectWithOtpContext/constants.js';
88
88
  import '../../../context/ReinitializeContext/ReinitializeContextProvider.js';
89
89
  import '../../../store/state/tokenBalances.js';
90
90
 
91
- const useSetWalletConnectorFetchers = (walletOptions, environmentId) => {
92
- const { registerEmbeddedWalletSessionKey, removeSessionKey } = useEmbeddedWalletSessionKeys(environmentId);
91
+ const useSetWalletConnectorFetchers = (walletOptions, environmentId, projectSettings) => {
92
+ const { registerEmbeddedWalletSessionKey, removeSessionKey } = useEmbeddedWalletSessionKeys({ environmentId, projectSettings });
93
93
  if (!(walletOptions === null || walletOptions === void 0 ? void 0 : walletOptions.length))
94
94
  return;
95
95
  const { fetchAuthToken, fetchBackupCode, fetchPasscode } = getCoinbaseMPCConnectorFetchers({ environmentId });
@@ -128,7 +128,10 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
128
128
  const { initAuth } = useUserAuth.useUserAuth({
129
129
  authMethod: 'social',
130
130
  });
131
- const { generateSessionKey, shouldRegisterSessionKeysOnSignin } = useEmbeddedWalletSessionKeys.useEmbeddedWalletSessionKeys(environmentId);
131
+ const { generateSessionKey, shouldRegisterSessionKeysOnSignin } = useEmbeddedWalletSessionKeys.useEmbeddedWalletSessionKeys({
132
+ environmentId,
133
+ projectSettings,
134
+ });
132
135
  const [isProcessing, setIsProcessing] = React.useState(false);
133
136
  const [error, setError] = React.useState();
134
137
  const clearError = () => {
@@ -283,7 +286,7 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
283
286
  }
284
287
  }
285
288
  });
286
- const completeConnection = (_d) => _tslib.__awaiter(void 0, [_d], void 0, function* ({ authMode, provider, state, authCode, captchaToken, verifier, telegramAuthToken, }) {
289
+ const completeConnection = (_d) => _tslib.__awaiter(void 0, [_d], void 0, function* ({ authMode, provider, state, authCode, captchaToken, verifier, telegramAuthToken, forceCreateUser = false, }) {
287
290
  try {
288
291
  let sessionPublicKey = undefined;
289
292
  if (shouldRegisterSessionKeysOnSignin()) {
@@ -293,10 +296,11 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
293
296
  if (authMode === 'signin') {
294
297
  if (provider === sdkApiCore.ProviderEnum.Telegram && telegramAuthToken) {
295
298
  const apiCall = () => oauth.telegramSignIn(environmentId, {
299
+ forceCreateUser,
296
300
  sessionPublicKey,
297
301
  telegramAuthToken,
298
302
  });
299
- yield signInAccount(provider, apiCall);
303
+ return yield signInAccount(provider, apiCall);
300
304
  }
301
305
  else if (provider === sdkApiCore.ProviderEnum.Telegram) {
302
306
  const apiCall = () => oauth.telegramSignIn(environmentId, {
@@ -18,7 +18,7 @@ export type ConnectSocialAccountProps = {
18
18
  };
19
19
  export declare const useSocialAuth: ({ sessionTimeout, onSettled, onError, onFarcasterUrl, }: UseSocialAuthProps) => {
20
20
  readonly checkValidProvider: (provider: ProviderEnum, authMode: SocialAuthMode) => boolean;
21
- readonly completeConnection: ({ authMode, provider, state, authCode, captchaToken, verifier, telegramAuthToken, }: {
21
+ readonly completeConnection: ({ authMode, provider, state, authCode, captchaToken, verifier, telegramAuthToken, forceCreateUser, }: {
22
22
  authMode: SocialAuthMode;
23
23
  provider: ProviderEnum;
24
24
  state: string;
@@ -26,6 +26,7 @@ export declare const useSocialAuth: ({ sessionTimeout, onSettled, onError, onFar
26
26
  authCode?: string | undefined;
27
27
  verifier?: string | undefined;
28
28
  telegramAuthToken?: string | undefined;
29
+ forceCreateUser?: boolean | undefined;
29
30
  }) => Promise<void>;
30
31
  readonly connectSocialAccount: ({ authMode, provider, validator, captchaToken, redirectUrl, telegramAuthToken, }: ConnectSocialAccountProps) => Promise<void>;
31
32
  readonly error: SocialOAuthError | undefined;
@@ -124,7 +124,10 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
124
124
  const { initAuth: initAuth$1 } = useUserAuth({
125
125
  authMethod: 'social',
126
126
  });
127
- const { generateSessionKey, shouldRegisterSessionKeysOnSignin } = useEmbeddedWalletSessionKeys(environmentId);
127
+ const { generateSessionKey, shouldRegisterSessionKeysOnSignin } = useEmbeddedWalletSessionKeys({
128
+ environmentId,
129
+ projectSettings,
130
+ });
128
131
  const [isProcessing, setIsProcessing] = useState(false);
129
132
  const [error, setError] = useState();
130
133
  const clearError = () => {
@@ -279,7 +282,7 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
279
282
  }
280
283
  }
281
284
  });
282
- const completeConnection = (_d) => __awaiter(void 0, [_d], void 0, function* ({ authMode, provider, state, authCode, captchaToken, verifier, telegramAuthToken, }) {
285
+ const completeConnection = (_d) => __awaiter(void 0, [_d], void 0, function* ({ authMode, provider, state, authCode, captchaToken, verifier, telegramAuthToken, forceCreateUser = false, }) {
283
286
  try {
284
287
  let sessionPublicKey = undefined;
285
288
  if (shouldRegisterSessionKeysOnSignin()) {
@@ -289,10 +292,11 @@ const useSocialAuth = ({ sessionTimeout, onSettled, onError, onFarcasterUrl, })
289
292
  if (authMode === 'signin') {
290
293
  if (provider === ProviderEnum.Telegram && telegramAuthToken) {
291
294
  const apiCall = () => telegramSignIn(environmentId, {
295
+ forceCreateUser,
292
296
  sessionPublicKey,
293
297
  telegramAuthToken,
294
298
  });
295
- yield signInAccount(provider, apiCall);
299
+ return yield signInAccount(provider, apiCall);
296
300
  }
297
301
  else if (provider === ProviderEnum.Telegram) {
298
302
  const apiCall = () => telegramSignIn(environmentId, {
@@ -4,7 +4,6 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var _tslib = require('../../../../../_virtual/_tslib.cjs');
7
- var React = require('react');
8
7
  var sdkApiCore = require('@dynamic-labs/sdk-api-core');
9
8
  require('../../constants/values.cjs');
10
9
  require('@dynamic-labs/utils');
@@ -16,6 +15,7 @@ require('@dynamic-labs/iconic');
16
15
  require('@dynamic-labs/wallet-connector-core');
17
16
  require('react/jsx-runtime');
18
17
  require('../../../context/ViewContext/ViewContext.cjs');
18
+ require('react');
19
19
  require('@dynamic-labs/wallet-book');
20
20
  require('../../../store/state/loadingAndLifecycle.cjs');
21
21
  require('../../../shared/consts/index.cjs');
@@ -99,30 +99,31 @@ const useTelegramLogin = () => {
99
99
  const { completeConnection } = useSocialAuth.useSocialAuth({
100
100
  sessionTimeout: 20000,
101
101
  });
102
- React.useEffect(() => {
103
- const telegramSignIn = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
104
- // in non-browser environments like Node.js
105
- // or during server-side rendering (e.g., with frameworks like Next.js).
106
- if (typeof window === 'undefined') {
107
- return;
108
- }
109
- const search = new URLSearchParams(window.location.search);
110
- const telegramAuthToken = search.get('telegramAuthToken');
111
- if (!isProviderEnabled.isProviderEnabled(providers, sdkApiCore.ProviderEnum.Telegram) ||
112
- user ||
113
- !telegramAuthToken ||
114
- !sdkHasLoaded) {
115
- return;
116
- }
117
- yield completeConnection({
118
- authMode: 'signin',
119
- provider: sdkApiCore.ProviderEnum.Telegram,
120
- state: '',
121
- telegramAuthToken,
122
- });
102
+ const telegramSignIn = (...args_1) => _tslib.__awaiter(void 0, [...args_1], void 0, function* ({ forceCreateUser = false, } = {}) {
103
+ // in non-browser environments like Node.js
104
+ // or during server-side rendering (e.g., with frameworks like Next.js).
105
+ if (typeof window === 'undefined') {
106
+ return;
107
+ }
108
+ const search = new URLSearchParams(window.location.search);
109
+ const telegramAuthToken = search.get('telegramAuthToken');
110
+ if (!isProviderEnabled.isProviderEnabled(providers, sdkApiCore.ProviderEnum.Telegram) ||
111
+ user ||
112
+ !telegramAuthToken ||
113
+ !sdkHasLoaded) {
114
+ return;
115
+ }
116
+ yield completeConnection({
117
+ authMode: 'signin',
118
+ forceCreateUser,
119
+ provider: sdkApiCore.ProviderEnum.Telegram,
120
+ state: '',
121
+ telegramAuthToken,
123
122
  });
124
- telegramSignIn();
125
- }, [sdkHasLoaded]);
123
+ });
124
+ return {
125
+ telegramSignIn,
126
+ };
126
127
  };
127
128
 
128
129
  exports.useTelegramLogin = useTelegramLogin;
@@ -1 +1,7 @@
1
- export declare const useTelegramLogin: () => void;
1
+ interface TelegramConfig {
2
+ forceCreateUser?: boolean;
3
+ }
4
+ export declare const useTelegramLogin: () => {
5
+ telegramSignIn: ({ forceCreateUser, }?: TelegramConfig) => Promise<void>;
6
+ };
7
+ export {};
@@ -1,6 +1,5 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../../../../_virtual/_tslib.js';
3
- import { useEffect } from 'react';
4
3
  import { ProviderEnum } from '@dynamic-labs/sdk-api-core';
5
4
  import '../../constants/values.js';
6
5
  import '@dynamic-labs/utils';
@@ -12,6 +11,7 @@ import '@dynamic-labs/iconic';
12
11
  import '@dynamic-labs/wallet-connector-core';
13
12
  import 'react/jsx-runtime';
14
13
  import '../../../context/ViewContext/ViewContext.js';
14
+ import 'react';
15
15
  import '@dynamic-labs/wallet-book';
16
16
  import '../../../store/state/loadingAndLifecycle.js';
17
17
  import '../../../shared/consts/index.js';
@@ -95,30 +95,31 @@ const useTelegramLogin = () => {
95
95
  const { completeConnection } = useSocialAuth({
96
96
  sessionTimeout: 20000,
97
97
  });
98
- useEffect(() => {
99
- const telegramSignIn = () => __awaiter(void 0, void 0, void 0, function* () {
100
- // in non-browser environments like Node.js
101
- // or during server-side rendering (e.g., with frameworks like Next.js).
102
- if (typeof window === 'undefined') {
103
- return;
104
- }
105
- const search = new URLSearchParams(window.location.search);
106
- const telegramAuthToken = search.get('telegramAuthToken');
107
- if (!isProviderEnabled(providers, ProviderEnum.Telegram) ||
108
- user ||
109
- !telegramAuthToken ||
110
- !sdkHasLoaded) {
111
- return;
112
- }
113
- yield completeConnection({
114
- authMode: 'signin',
115
- provider: ProviderEnum.Telegram,
116
- state: '',
117
- telegramAuthToken,
118
- });
98
+ const telegramSignIn = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* ({ forceCreateUser = false, } = {}) {
99
+ // in non-browser environments like Node.js
100
+ // or during server-side rendering (e.g., with frameworks like Next.js).
101
+ if (typeof window === 'undefined') {
102
+ return;
103
+ }
104
+ const search = new URLSearchParams(window.location.search);
105
+ const telegramAuthToken = search.get('telegramAuthToken');
106
+ if (!isProviderEnabled(providers, ProviderEnum.Telegram) ||
107
+ user ||
108
+ !telegramAuthToken ||
109
+ !sdkHasLoaded) {
110
+ return;
111
+ }
112
+ yield completeConnection({
113
+ authMode: 'signin',
114
+ forceCreateUser,
115
+ provider: ProviderEnum.Telegram,
116
+ state: '',
117
+ telegramAuthToken,
119
118
  });
120
- telegramSignIn();
121
- }, [sdkHasLoaded]);
119
+ });
120
+ return {
121
+ telegramSignIn,
122
+ };
122
123
  };
123
124
 
124
125
  export { useTelegramLogin };
@@ -110,7 +110,10 @@ const useVerifyWallet = ({ consumeNonce, displaySiweStatement, environmentId, pr
110
110
  const { multiWalletWidgetState, debugError, multiWallet: multiWalletEnabled, appName, primaryWalletId, setShowAuthFlow, setPrimaryWalletId, siweStatement, connectedWallets, authMode, user, setAuthMode, removeConnectedWalletsInfo, events, primaryWallet, enableConnectOnlyFallback, selectedWalletConnector, } = useInternalDynamicContext.useInternalDynamicContext();
111
111
  const { addedWalletsIds } = UserWalletsContext.useInternalUserWallets();
112
112
  const { initAuth } = useUserAuth.useUserAuth({ authMethod: 'wallet' });
113
- const { generateSessionKey, shouldRegisterSessionKeysOnSignin } = useEmbeddedWalletSessionKeys.useEmbeddedWalletSessionKeys(environmentId);
113
+ const { generateSessionKey, shouldRegisterSessionKeysOnSignin } = useEmbeddedWalletSessionKeys.useEmbeddedWalletSessionKeys({
114
+ environmentId,
115
+ projectSettings,
116
+ });
114
117
  // If the user is not already logged it means that we only need to verify
115
118
  // We need this boolean to distinguish between logic for verify or linking.
116
119
  const verifyOnly = !user;
@@ -106,7 +106,10 @@ const useVerifyWallet = ({ consumeNonce, displaySiweStatement, environmentId, pr
106
106
  const { multiWalletWidgetState, debugError, multiWallet: multiWalletEnabled, appName, primaryWalletId, setShowAuthFlow, setPrimaryWalletId, siweStatement, connectedWallets, authMode, user, setAuthMode, removeConnectedWalletsInfo, events, primaryWallet, enableConnectOnlyFallback, selectedWalletConnector, } = useInternalDynamicContext();
107
107
  const { addedWalletsIds } = useInternalUserWallets();
108
108
  const { initAuth } = useUserAuth({ authMethod: 'wallet' });
109
- const { generateSessionKey, shouldRegisterSessionKeysOnSignin } = useEmbeddedWalletSessionKeys(environmentId);
109
+ const { generateSessionKey, shouldRegisterSessionKeysOnSignin } = useEmbeddedWalletSessionKeys({
110
+ environmentId,
111
+ projectSettings,
112
+ });
110
113
  // If the user is not already logged it means that we only need to verify
111
114
  // We need this boolean to distinguish between logic for verify or linking.
112
115
  const verifyOnly = !user;
@@ -140,7 +140,10 @@ const EmailVerification = ({ isEmailRecoveryFlow = false, showRetryButton: _show
140
140
  const { initAuth, completeAuth, cancelAuth } = useUserAuth.useUserAuth({
141
141
  authMethod: 'email',
142
142
  });
143
- const { generateSessionKey, shouldRegisterSessionKeysOnSignin } = useEmbeddedWalletSessionKeys.useEmbeddedWalletSessionKeys(environmentId);
143
+ const { generateSessionKey, shouldRegisterSessionKeysOnSignin } = useEmbeddedWalletSessionKeys.useEmbeddedWalletSessionKeys({
144
+ environmentId,
145
+ projectSettings,
146
+ });
144
147
  // When true, causes the component to call emailVerificationX callback on unmount
145
148
  const callCallbackOnUnmount = React.useRef(true);
146
149
  useOnUnmount.useOnUnmount(() => {
@@ -136,7 +136,10 @@ const EmailVerification = ({ isEmailRecoveryFlow = false, showRetryButton: _show
136
136
  const { initAuth, completeAuth, cancelAuth } = useUserAuth({
137
137
  authMethod: 'email',
138
138
  });
139
- const { generateSessionKey, shouldRegisterSessionKeysOnSignin } = useEmbeddedWalletSessionKeys(environmentId);
139
+ const { generateSessionKey, shouldRegisterSessionKeysOnSignin } = useEmbeddedWalletSessionKeys({
140
+ environmentId,
141
+ projectSettings,
142
+ });
140
143
  // When true, causes the component to call emailVerificationX callback on unmount
141
144
  const callCallbackOnUnmount = useRef(true);
142
145
  useOnUnmount(() => {