@dynamic-labs/sdk-react-core 4.0.0-alpha.10 → 4.0.0-alpha.12

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 (144) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/package.cjs +2 -2
  3. package/package.js +2 -2
  4. package/package.json +12 -12
  5. package/src/lib/Main.cjs +1 -1
  6. package/src/lib/Main.js +1 -1
  7. package/src/lib/components/SendBalancePageLayout/SendBalancePageLayout.cjs +6 -6
  8. package/src/lib/components/SendBalancePageLayout/SendBalancePageLayout.js +7 -7
  9. package/src/lib/components/TransactionCard/TransactionCard.cjs +77 -5
  10. package/src/lib/components/TransactionCard/TransactionCard.js +78 -6
  11. package/src/lib/components/TransactionStatusLayout/TransactionStatusLayout.cjs +1 -1
  12. package/src/lib/components/TransactionStatusLayout/TransactionStatusLayout.js +1 -1
  13. package/src/lib/components/UserProfile/UserProfile.cjs +1 -1
  14. package/src/lib/components/UserProfile/UserProfile.js +1 -1
  15. package/src/lib/components/UserProfileForm/UserProfileForm.cjs +1 -1
  16. package/src/lib/components/UserProfileForm/UserProfileForm.js +1 -1
  17. package/src/lib/components/WalletConnectorEvents/WalletConnectorEvents.cjs +127 -0
  18. package/src/lib/components/WalletConnectorEvents/WalletConnectorEvents.d.ts +1 -0
  19. package/src/lib/components/WalletConnectorEvents/WalletConnectorEvents.js +123 -0
  20. package/src/lib/components/WalletConnectorEvents/index.d.ts +1 -0
  21. package/src/lib/components/index.d.ts +1 -0
  22. package/src/lib/context/DynamicContext/DynamicContext.cjs +14 -11
  23. package/src/lib/context/DynamicContext/DynamicContext.js +6 -3
  24. package/src/lib/context/DynamicContext/hooks/useRegisterStorageService/useRegisterStorageService.cjs +8 -4
  25. package/src/lib/context/DynamicContext/hooks/useRegisterStorageService/useRegisterStorageService.js +9 -5
  26. package/src/lib/context/MockContext/MockContext.cjs +1 -1
  27. package/src/lib/context/MockContext/MockContext.js +1 -1
  28. package/src/lib/context/SocialRedirectContext/hooks/useRedirectSocialHandler/useRedirectSocialHandler.cjs +1 -3
  29. package/src/lib/context/SocialRedirectContext/hooks/useRedirectSocialHandler/useRedirectSocialHandler.js +1 -3
  30. package/src/lib/data/api/oauth/oauth.cjs +19 -10
  31. package/src/lib/data/api/oauth/oauth.js +19 -10
  32. package/src/lib/layout/DynamicAuthLayout/Header/header.cjs +1 -1
  33. package/src/lib/layout/DynamicAuthLayout/Header/header.js +1 -1
  34. package/src/lib/layout/DynamicAuthLayout/HelpContent/HelpHeader/HelpHeader.cjs +1 -1
  35. package/src/lib/layout/DynamicAuthLayout/HelpContent/HelpHeader/HelpHeader.js +1 -1
  36. package/src/lib/layouts/BridgeNextWalletToConnectLayout/BridgeNextWalletToConnectLayout.cjs +1 -1
  37. package/src/lib/layouts/BridgeNextWalletToConnectLayout/BridgeNextWalletToConnectLayout.js +1 -1
  38. package/src/lib/layouts/BridgeWelcomeLayout/BridgeWelcomeLayout.cjs +1 -1
  39. package/src/lib/layouts/BridgeWelcomeLayout/BridgeWelcomeLayout.js +1 -1
  40. package/src/lib/layouts/ConnectedWalletsListLayout/ConnectedWalletsListLayout.cjs +1 -1
  41. package/src/lib/layouts/ConnectedWalletsListLayout/ConnectedWalletsListLayout.js +1 -1
  42. package/src/lib/modals/SendBalanceModal/SendBalanceModal.cjs +1 -1
  43. package/src/lib/modals/SendBalanceModal/SendBalanceModal.js +1 -1
  44. package/src/lib/modals/SignMessageConfirmationModal/SignMessageConfirmationModal.cjs +1 -1
  45. package/src/lib/modals/SignMessageConfirmationModal/SignMessageConfirmationModal.js +1 -1
  46. package/src/lib/store/internalImplementation/utils/syncLegacyStorage/syncLegacyStorage.cjs +1 -1
  47. package/src/lib/store/internalImplementation/utils/syncLegacyStorage/syncLegacyStorage.js +1 -1
  48. package/src/lib/utils/functions/getExpiresAt/getExpiresAt.d.ts +1 -1
  49. package/src/lib/utils/functions/networksAndChains/networksAndChains.cjs +15 -22
  50. package/src/lib/utils/functions/networksAndChains/networksAndChains.d.ts +2 -5
  51. package/src/lib/utils/functions/networksAndChains/networksAndChains.js +15 -20
  52. package/src/lib/utils/hooks/index.d.ts +1 -1
  53. package/src/lib/utils/hooks/useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.cjs +2 -2
  54. package/src/lib/utils/hooks/useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.js +2 -2
  55. package/src/lib/utils/hooks/useCreateWalletConnectorOptions/index.d.ts +1 -0
  56. package/src/lib/utils/hooks/{useWalletConnectorOptions/useWalletConnectorOptions.cjs → useCreateWalletConnectorOptions/useCreateWalletConnectorOptions.cjs} +2 -2
  57. package/src/lib/utils/hooks/{useWalletConnectorOptions/useWalletConnectorOptions.d.ts → useCreateWalletConnectorOptions/useCreateWalletConnectorOptions.d.ts} +1 -1
  58. package/src/lib/utils/hooks/{useWalletConnectorOptions/useWalletConnectorOptions.js → useCreateWalletConnectorOptions/useCreateWalletConnectorOptions.js} +2 -2
  59. package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.cjs +33 -30
  60. package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useSecureEnclaveEmbeddedWallet.js +33 -30
  61. package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useTurnkey/useTurnkey.cjs +23 -11
  62. package/src/lib/utils/hooks/useEmbeddedWallet/useSecureEnclaveEmbeddedWallet/useTurnkey/useTurnkey.js +23 -11
  63. package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.cjs +4 -7
  64. package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.d.ts +1 -4
  65. package/src/lib/utils/hooks/useSocialAccounts/useSocialAccounts.js +4 -7
  66. package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.cjs +4 -4
  67. package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.d.ts +1 -2
  68. package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.js +4 -4
  69. package/src/lib/utils/hooks/useTelegramLogin/useTelegramLogin.cjs +1 -3
  70. package/src/lib/utils/hooks/useTelegramLogin/useTelegramLogin.js +1 -3
  71. package/src/lib/views/CoinbaseMPCClaimIntro/CoinbaseMPCClaimIntro.cjs +1 -1
  72. package/src/lib/views/CoinbaseMPCClaimIntro/CoinbaseMPCClaimIntro.js +1 -1
  73. package/src/lib/views/CollectUserDataView/OnboardingUserDataForm/OnboardingUserDataForm.cjs +1 -1
  74. package/src/lib/views/CollectUserDataView/OnboardingUserDataForm/OnboardingUserDataForm.js +1 -1
  75. package/src/lib/views/CreatePasswordView/CreatePasswordStep/CreatePasswordStep.cjs +1 -1
  76. package/src/lib/views/CreatePasswordView/CreatePasswordStep/CreatePasswordStep.js +1 -1
  77. package/src/lib/views/CreatePasswordView/SavePasswordStep/SavePasswordStep.cjs +1 -1
  78. package/src/lib/views/CreatePasswordView/SavePasswordStep/SavePasswordStep.js +1 -1
  79. package/src/lib/views/EmailVerification/EmailVerification.cjs +3 -1
  80. package/src/lib/views/EmailVerification/EmailVerification.js +3 -1
  81. package/src/lib/views/EnterPasswordView/EnterPasswordView.cjs +1 -1
  82. package/src/lib/views/EnterPasswordView/EnterPasswordView.js +1 -1
  83. package/src/lib/views/FarcasterQrCodeView/FarcasterQrCodeView.cjs +0 -1
  84. package/src/lib/views/FarcasterQrCodeView/FarcasterQrCodeView.js +0 -1
  85. package/src/lib/views/LoginView/sections/SocialSignInSection/DynamicSocialSignIn/DynamicSocialSignIn.cjs +0 -1
  86. package/src/lib/views/LoginView/sections/SocialSignInSection/DynamicSocialSignIn/DynamicSocialSignIn.js +0 -1
  87. package/src/lib/views/LoginView/sections/WalletSignInSection/WalletSimpleSignIn/WalletSimpleSignIn.cjs +2 -1
  88. package/src/lib/views/LoginView/sections/WalletSignInSection/WalletSimpleSignIn/WalletSimpleSignIn.js +2 -1
  89. package/src/lib/views/MfaChooseDeviceView/MfaChooseDeviceView.cjs +1 -1
  90. package/src/lib/views/MfaChooseDeviceView/MfaChooseDeviceView.js +1 -1
  91. package/src/lib/views/Passkey/PasskeyNewDomainDetectedView/PasskeyNewDomainDetectedView.cjs +1 -1
  92. package/src/lib/views/Passkey/PasskeyNewDomainDetectedView/PasskeyNewDomainDetectedView.js +1 -1
  93. package/src/lib/views/Passkey/PasskeyRecovery/InitRecovery/PasskeyInitRecovery.cjs +1 -1
  94. package/src/lib/views/Passkey/PasskeyRecovery/InitRecovery/PasskeyInitRecovery.js +1 -1
  95. package/src/lib/views/Passkey/RenamePasskeyView/RenamePasskeyView.cjs +1 -1
  96. package/src/lib/views/Passkey/RenamePasskeyView/RenamePasskeyView.js +1 -1
  97. package/src/lib/views/SendBalanceView/SendBalanceView.cjs +2 -3
  98. package/src/lib/views/SendBalanceView/SendBalanceView.js +3 -4
  99. package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.cjs +7 -4
  100. package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.js +7 -4
  101. package/src/lib/views/UserFieldEditorView/UserFieldEditorView.cjs +1 -1
  102. package/src/lib/views/UserFieldEditorView/UserFieldEditorView.js +1 -1
  103. package/src/lib/views/WalletList/WalletList.cjs +2 -2
  104. package/src/lib/views/WalletList/WalletList.js +2 -2
  105. package/src/lib/widgets/DynamicBridgeWidget/components/DynamicBridgeWalletCardBody/DynamicBridgeWalletCardBody.cjs +1 -1
  106. package/src/lib/widgets/DynamicBridgeWidget/components/DynamicBridgeWalletCardBody/DynamicBridgeWalletCardBody.js +1 -1
  107. package/src/lib/widgets/DynamicEmbeddedWidget/DynamicEmbeddedUserProfile/DynamicEmbeddedUserProfile.cjs +1 -1
  108. package/src/lib/widgets/DynamicEmbeddedWidget/DynamicEmbeddedUserProfile/DynamicEmbeddedUserProfile.js +1 -1
  109. package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveBitcoinWalletAddresses/ActiveBitcoinWalletAddresses.cjs +1 -1
  110. package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveBitcoinWalletAddresses/ActiveBitcoinWalletAddresses.js +1 -1
  111. package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletAddress/ActiveWalletAddress.cjs +1 -1
  112. package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletAddress/ActiveWalletAddress.js +1 -1
  113. package/src/lib/widgets/DynamicWidget/components/DynamicUserProfile/DynamicUserProfile.cjs +1 -1
  114. package/src/lib/widgets/DynamicWidget/components/DynamicUserProfile/DynamicUserProfile.js +1 -1
  115. package/src/lib/widgets/DynamicWidget/components/DynamicWidgetWallets/DynamicWidgetWallets.cjs +1 -1
  116. package/src/lib/widgets/DynamicWidget/components/DynamicWidgetWallets/DynamicWidgetWallets.js +1 -1
  117. package/src/lib/widgets/DynamicWidget/components/UnknownWalletInformation/UnknownWalletInformation.cjs +1 -1
  118. package/src/lib/widgets/DynamicWidget/components/UnknownWalletInformation/UnknownWalletInformation.js +1 -1
  119. package/src/lib/widgets/DynamicWidget/views/EditProfileView/EditProfileView.cjs +1 -1
  120. package/src/lib/widgets/DynamicWidget/views/EditProfileView/EditProfileView.js +1 -1
  121. package/src/lib/widgets/DynamicWidget/views/ManageMfaWidgetView/ManageMfaWidgetView.cjs +1 -1
  122. package/src/lib/widgets/DynamicWidget/views/ManageMfaWidgetView/ManageMfaWidgetView.js +1 -1
  123. package/src/lib/widgets/DynamicWidget/views/ManagePasskeysWidgetView/ManagePasskeysWidgetView.cjs +1 -1
  124. package/src/lib/widgets/DynamicWidget/views/ManagePasskeysWidgetView/ManagePasskeysWidgetView.js +1 -1
  125. package/src/lib/widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.cjs +1 -1
  126. package/src/lib/widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js +1 -1
  127. package/src/lib/utils/hooks/useWalletConnectorOptions/index.d.ts +0 -1
  128. /package/src/lib/utils/hooks/{useWalletConnectorOptions → useCreateWalletConnectorOptions}/utils/errors/ConnectorSetupError.cjs +0 -0
  129. /package/src/lib/utils/hooks/{useWalletConnectorOptions → useCreateWalletConnectorOptions}/utils/errors/ConnectorSetupError.d.ts +0 -0
  130. /package/src/lib/utils/hooks/{useWalletConnectorOptions → useCreateWalletConnectorOptions}/utils/errors/ConnectorSetupError.js +0 -0
  131. /package/src/lib/utils/hooks/{useWalletConnectorOptions → useCreateWalletConnectorOptions}/utils/errors/index.d.ts +0 -0
  132. /package/src/lib/utils/hooks/{useWalletConnectorOptions → useCreateWalletConnectorOptions}/utils/index.d.ts +0 -0
  133. /package/src/lib/utils/hooks/{useWalletConnectorOptions → useCreateWalletConnectorOptions}/utils/verifyMagicIsSetup/index.d.ts +0 -0
  134. /package/src/lib/utils/hooks/{useWalletConnectorOptions → useCreateWalletConnectorOptions}/utils/verifyMagicIsSetup/verifyMagicIsSetup.cjs +0 -0
  135. /package/src/lib/utils/hooks/{useWalletConnectorOptions → useCreateWalletConnectorOptions}/utils/verifyMagicIsSetup/verifyMagicIsSetup.d.ts +0 -0
  136. /package/src/lib/utils/hooks/{useWalletConnectorOptions → useCreateWalletConnectorOptions}/utils/verifyMagicIsSetup/verifyMagicIsSetup.js +0 -0
  137. /package/src/lib/utils/hooks/{useWalletConnectorOptions → useCreateWalletConnectorOptions}/utils/verifyRequiredConnectorsAreSetup/index.d.ts +0 -0
  138. /package/src/lib/utils/hooks/{useWalletConnectorOptions → useCreateWalletConnectorOptions}/utils/verifyRequiredConnectorsAreSetup/verifyRequiredConnectorsAreSetup.cjs +0 -0
  139. /package/src/lib/utils/hooks/{useWalletConnectorOptions → useCreateWalletConnectorOptions}/utils/verifyRequiredConnectorsAreSetup/verifyRequiredConnectorsAreSetup.d.ts +0 -0
  140. /package/src/lib/utils/hooks/{useWalletConnectorOptions → useCreateWalletConnectorOptions}/utils/verifyRequiredConnectorsAreSetup/verifyRequiredConnectorsAreSetup.js +0 -0
  141. /package/src/lib/utils/hooks/{useWalletConnectorOptions → useCreateWalletConnectorOptions}/utils/verifyZeroDevIsSetup/index.d.ts +0 -0
  142. /package/src/lib/utils/hooks/{useWalletConnectorOptions → useCreateWalletConnectorOptions}/utils/verifyZeroDevIsSetup/verifyZeroDevIsSetup.cjs +0 -0
  143. /package/src/lib/utils/hooks/{useWalletConnectorOptions → useCreateWalletConnectorOptions}/utils/verifyZeroDevIsSetup/verifyZeroDevIsSetup.d.ts +0 -0
  144. /package/src/lib/utils/hooks/{useWalletConnectorOptions → useCreateWalletConnectorOptions}/utils/verifyZeroDevIsSetup/verifyZeroDevIsSetup.js +0 -0
@@ -45,6 +45,7 @@ var errors = require('../../../constants/errors.cjs');
45
45
  require('../../../../context/VerificationContext/VerificationContext.cjs');
46
46
  require('react-dom');
47
47
  var useElementById = require('../../useElementById/useElementById.cjs');
48
+ var findPrimaryEmbeddedChain = require('../../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.cjs');
48
49
  var WalletContext = require('../../../../context/WalletContext/WalletContext.cjs');
49
50
  var useIsTurnkeyWallet = require('../../useIsTurnkeyWallet/useIsTurnkeyWallet.cjs');
50
51
  var turnkeyExport = require('../../../../views/EmbeddedReveal/utils/turnkeyExport/turnkeyExport.cjs');
@@ -125,7 +126,7 @@ const isConnectorSessionKeyActive = (connector) => {
125
126
  * }
126
127
  */
127
128
  const useSecureEnclaveEmbeddedWallet = () => {
128
- var _a, _b, _c, _d;
129
+ var _a, _b, _c, _d, _e;
129
130
  const { projectSettings, primaryWallet, user: user$1, environmentId, walletConnectorOptions, } = useInternalDynamicContext.useInternalDynamicContext();
130
131
  const { addedWalletsIds } = UserWalletsContext.useInternalUserWallets();
131
132
  const { createTurnkeyWallet } = useTurnkey.useTurnkey();
@@ -149,13 +150,14 @@ const useSecureEnclaveEmbeddedWallet = () => {
149
150
  * @returns Promise<Wallet | undefined>
150
151
  */
151
152
  const createEmbeddedWallet = React.useCallback((chains, options) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
152
- var _e;
153
+ var _f;
153
154
  if (!user$1) {
154
155
  throw new utils.DynamicError(errors.USER_NOT_LOGGED_IN);
155
156
  }
156
157
  const userWalletsCredentials = getUserWalletsFromVerifiedCredentials.getUserWalletsFromVerifiedCredentials(user$1);
157
- const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(user$1, chains);
158
- const isManualMode = ((_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _e === void 0 ? void 0 : _e.automaticEmbeddedWalletCreation) === false;
158
+ const primaryChain = findPrimaryEmbeddedChain.findPrimaryEmbeddedChain(projectSettings);
159
+ const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(user$1, chains !== null && chains !== void 0 ? chains : [primaryChain]);
160
+ const isManualMode = ((_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _f === void 0 ? void 0 : _f.automaticEmbeddedWalletCreation) === false;
159
161
  // if user has a wallet and it's not embedded,
160
162
  // throw error to follow another flow and set up the right wallet
161
163
  // However, if the user is in manual mode continue.
@@ -174,14 +176,15 @@ const useSecureEnclaveEmbeddedWallet = () => {
174
176
  * @param chain - chain parameter to create the wallet for
175
177
  * @returns Promise<UserProfile | undefined>
176
178
  */
177
- const createEmbeddedWalletAccount = React.useCallback((_f) => _tslib.__awaiter(void 0, [_f], void 0, function* ({ chain }) {
178
- var _g, _h, _j;
179
+ const createEmbeddedWalletAccount = React.useCallback((_g) => _tslib.__awaiter(void 0, [_g], void 0, function* ({ chain }) {
180
+ var _h, _j, _k;
179
181
  if (!user$1) {
180
182
  throw new Error(errors.USER_NOT_LOGGED_IN);
181
183
  }
182
184
  validateTurnkeyProviderEnabled.validateTurnkeyProviderEnabled(projectSettings);
183
- const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(user$1);
184
- const turnkeyWalletId = (_g = embeddedWalletVerifiedCredential === null || embeddedWalletVerifiedCredential === void 0 ? void 0 : embeddedWalletVerifiedCredential.walletProperties) === null || _g === void 0 ? void 0 : _g.turnkeyHDWalletId;
185
+ const primaryChain = findPrimaryEmbeddedChain.findPrimaryEmbeddedChain(projectSettings);
186
+ const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(user$1, [primaryChain]);
187
+ const turnkeyWalletId = (_h = embeddedWalletVerifiedCredential === null || embeddedWalletVerifiedCredential === void 0 ? void 0 : embeddedWalletVerifiedCredential.walletProperties) === null || _h === void 0 ? void 0 : _h.turnkeyHDWalletId;
185
188
  if (!turnkeyWalletId) {
186
189
  throw new utils.DynamicError('No HD wallet was found for this user to derive a wallet account. Use createEmbeddedWallet first', 'NoHdWalletFound');
187
190
  }
@@ -190,14 +193,14 @@ const useSecureEnclaveEmbeddedWallet = () => {
190
193
  environmentId,
191
194
  });
192
195
  if (walletConnectorCore.isSessionKeyCompatibleWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector)) {
193
- yield ((_h = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _h === void 0 ? void 0 : _h.createOrRestoreSession({
196
+ yield ((_j = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _j === void 0 ? void 0 : _j.createOrRestoreSession({
194
197
  ignoreRestore: true,
195
198
  }));
196
199
  }
197
200
  else if (yield shouldInitRecovery()) {
198
201
  yield initPasskeyRecoveryProcess('email');
199
202
  }
200
- const signedRequest = yield ((_j = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _j === void 0 ? void 0 : _j.stampCreateWalletAccountRequest({
203
+ const signedRequest = yield ((_k = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _k === void 0 ? void 0 : _k.stampCreateWalletAccountRequest({
201
204
  request: requestToStamp,
202
205
  }));
203
206
  const verifiedUser = yield embeddedWallets.createEmbeddedWalletAccount({
@@ -225,7 +228,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
225
228
  * @returns Promise<'session_created' | 'session_restored'> - returns a string indicating the status of the session
226
229
  */
227
230
  const createOrRestoreSession = React.useCallback((options) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
228
- var _k, _l, _m, _o, _p, _q;
231
+ var _l, _m, _o, _p, _q, _r;
229
232
  if (!user$1) {
230
233
  throw new utils.DynamicError(errors.USER_NOT_LOGGED_IN);
231
234
  }
@@ -244,12 +247,12 @@ const useSecureEnclaveEmbeddedWallet = () => {
244
247
  }
245
248
  const turnkeyAuthIframeContainerRef = createRootElement(constants.iframeContainerId);
246
249
  // try to restore session if possible
247
- if (passkeyRecovery.canRestoreEmbeddedWalletSession((_k = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _k === void 0 ? void 0 : _k.sessionKeyDuration)) {
250
+ if (passkeyRecovery.canRestoreEmbeddedWalletSession((_l = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _l === void 0 ? void 0 : _l.sessionKeyDuration)) {
248
251
  try {
249
252
  const sessionRestored = yield passkeyRecovery.restoreEmbeddedWalletSession({
250
253
  iframeContainer: turnkeyAuthIframeContainerRef.current,
251
254
  iframeElementId: constants.iframeElementId,
252
- sessionExpiration: getEmbeddedWalletSessionExpiration.getEmbeddedWalletSessionExpiration((_m = (_l = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _l === void 0 ? void 0 : _l.embeddedWallets) === null || _m === void 0 ? void 0 : _m.sessionKeyDuration),
255
+ sessionExpiration: getEmbeddedWalletSessionExpiration.getEmbeddedWalletSessionExpiration((_o = (_m = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _m === void 0 ? void 0 : _m.embeddedWallets) === null || _o === void 0 ? void 0 : _o.sessionKeyDuration),
253
256
  user: user$1,
254
257
  wallet: primaryWallet,
255
258
  });
@@ -268,7 +271,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
268
271
  if (!userHasEmbeddedWallet() || !hasRecoveryEmail) {
269
272
  throw new utils.DynamicError('User does not have a secure enclave wallet or a verified email', errors.INVALID_WALLET_DATA);
270
273
  }
271
- const organizationId = (_q = (_p = (_o = user$1 === null || user$1 === void 0 ? void 0 : user$1.verifiedCredentials) === null || _o === void 0 ? void 0 : _o.find(({ walletName }) => walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey'))) === null || _p === void 0 ? void 0 : _p.walletProperties) === null || _q === void 0 ? void 0 : _q.turnkeySubOrganizationId;
274
+ const organizationId = (_r = (_q = (_p = user$1 === null || user$1 === void 0 ? void 0 : user$1.verifiedCredentials) === null || _p === void 0 ? void 0 : _p.find(({ walletName }) => walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey'))) === null || _q === void 0 ? void 0 : _q.walletProperties) === null || _r === void 0 ? void 0 : _r.turnkeySubOrganizationId;
272
275
  yield turnkeyRecoveryHandler.verifyRecoveryCode(options.oneTimeCode, organizationId);
273
276
  const sessionSettings = {
274
277
  createdAt: new Date().getTime(),
@@ -292,12 +295,12 @@ const useSecureEnclaveEmbeddedWallet = () => {
292
295
  * @returns Promise<WebAuthnAttestation>
293
296
  */
294
297
  const createPasskey = React.useCallback((options) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
295
- var _r, _s;
298
+ var _s, _t;
296
299
  if (!user$1) {
297
300
  throw new utils.DynamicError(errors.USER_NOT_LOGGED_IN);
298
301
  }
299
302
  validateTurnkeyProviderEnabled.validateTurnkeyProviderEnabled(projectSettings);
300
- const turnkeyWallet = findTurnkeyWallet.findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_r = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _r === void 0 ? void 0 : _r.chainConfigurations, user$1.verifiedCredentials);
303
+ const turnkeyWallet = findTurnkeyWallet.findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_s = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _s === void 0 ? void 0 : _s.chainConfigurations, user$1.verifiedCredentials);
301
304
  if (!(turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletConnector)) {
302
305
  throw new utils.DynamicError('Wallet connector not found', errors.INVALID_WALLET_DATA);
303
306
  }
@@ -312,7 +315,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
312
315
  if (!('id' in turnkeyWallet) || !hasEmailVC) {
313
316
  return walletConnector.getWebAuthnAttestation();
314
317
  }
315
- const turnkeySubOrganizationId = (_s = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _s === void 0 ? void 0 : _s.turnkeySubOrganizationId;
318
+ const turnkeySubOrganizationId = (_t = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _t === void 0 ? void 0 : _t.turnkeySubOrganizationId;
316
319
  if (!turnkeySubOrganizationId) {
317
320
  throw new utils.DynamicError('No sub organization id found for the wallet', errors.INVALID_WALLET_DATA);
318
321
  }
@@ -376,16 +379,16 @@ const useSecureEnclaveEmbeddedWallet = () => {
376
379
  * and the html container id to render the iframe into
377
380
  * @returns Promise<string> - returns the embedded wallet recovery phrase or private key
378
381
  */
379
- const revealEmbeddedWalletKey = React.useCallback((_t) => _tslib.__awaiter(void 0, [_t], void 0, function* ({ type, htmlContainerId, }) {
380
- var _u, _v, _w, _x, _y, _z;
382
+ const revealEmbeddedWalletKey = React.useCallback((_u) => _tslib.__awaiter(void 0, [_u], void 0, function* ({ type, htmlContainerId, }) {
383
+ var _v, _w, _x, _y, _z, _0;
381
384
  if (!user$1) {
382
385
  throw new utils.DynamicError(errors.USER_NOT_LOGGED_IN);
383
386
  }
384
387
  yield turnkeyExport.cleanupExport({
385
388
  wallet: wallet,
386
389
  });
387
- const turnkeyWallet = findTurnkeyWallet.findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_u = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _u === void 0 ? void 0 : _u.chainConfigurations, user$1 === null || user$1 === void 0 ? void 0 : user$1.verifiedCredentials);
388
- const turnkeyHDWalletId = (_v = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _v === void 0 ? void 0 : _v.turnkeyHDWalletId;
390
+ const turnkeyWallet = findTurnkeyWallet.findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_v = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _v === void 0 ? void 0 : _v.chainConfigurations, user$1 === null || user$1 === void 0 ? void 0 : user$1.verifiedCredentials);
391
+ const turnkeyHDWalletId = (_w = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _w === void 0 ? void 0 : _w.turnkeyHDWalletId;
389
392
  if (type === 'recoveryPhrase' && !turnkeyHDWalletId) {
390
393
  type = 'privateKey';
391
394
  }
@@ -394,7 +397,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
394
397
  // since it will show unrelated turnkey content
395
398
  iframeContainerElement.current.style.display = 'none';
396
399
  if (walletConnectorCore.isSessionKeyCompatibleWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector)) {
397
- yield ((_w = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _w === void 0 ? void 0 : _w.createOrRestoreSession());
400
+ yield ((_x = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _x === void 0 ? void 0 : _x.createOrRestoreSession());
398
401
  }
399
402
  yield turnkeyExport.initExport({
400
403
  iframeContainer: iframeContainerElement.current,
@@ -409,11 +412,11 @@ const useSecureEnclaveEmbeddedWallet = () => {
409
412
  wallet: wallet,
410
413
  });
411
414
  }
412
- catch (_0) {
415
+ catch (_1) {
413
416
  if (walletConnectorCore.isSessionKeyCompatibleWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector) &&
414
- ((_x = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _x === void 0 ? void 0 : _x.removeSessionKeys)) {
415
- yield ((_y = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _y === void 0 ? void 0 : _y.removeSessionKeys());
416
- yield ((_z = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _z === void 0 ? void 0 : _z.createOrRestoreSession({
417
+ ((_y = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _y === void 0 ? void 0 : _y.removeSessionKeys)) {
418
+ yield ((_z = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _z === void 0 ? void 0 : _z.removeSessionKeys());
419
+ yield ((_0 = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _0 === void 0 ? void 0 : _0.createOrRestoreSession({
417
420
  ignoreRestore: true,
418
421
  }));
419
422
  }
@@ -432,7 +435,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
432
435
  createRootElement,
433
436
  environmentId,
434
437
  wallet,
435
- (_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _d === void 0 ? void 0 : _d.chainConfigurations,
438
+ (_e = (_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _d === void 0 ? void 0 : _d.embeddedWallets) === null || _e === void 0 ? void 0 : _e.chainConfigurations,
436
439
  user$1,
437
440
  walletConnectorOptions,
438
441
  ]);
@@ -441,11 +444,11 @@ const useSecureEnclaveEmbeddedWallet = () => {
441
444
  * @returns Promise<'code_sent'>
442
445
  */
443
446
  const sendOneTimeCode = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
444
- var _1, _2;
447
+ var _2, _3;
445
448
  if (!user$1) {
446
449
  throw new utils.DynamicError(errors.USER_NOT_LOGGED_IN);
447
450
  }
448
- const targetTurnkeyWallet = findTurnkeyWallet.findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_1 = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _1 === void 0 ? void 0 : _1.chainConfigurations, user$1.verifiedCredentials);
451
+ const targetTurnkeyWallet = findTurnkeyWallet.findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_2 = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _2 === void 0 ? void 0 : _2.chainConfigurations, user$1.verifiedCredentials);
449
452
  if (!targetTurnkeyWallet || !('id' in targetTurnkeyWallet)) {
450
453
  throw new utils.DynamicError('User does not have a valid secure enclave wallet', errors.INVALID_WALLET_DATA);
451
454
  }
@@ -456,7 +459,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
456
459
  throw new utils.DynamicError('Session is active. No need to create a new one', errors.ACTIVE_SESSION);
457
460
  }
458
461
  const turnkeyAuthIframeContainerRef = createRootElement(constants.iframeContainerId);
459
- const publicKey = yield turnkeyAuthenticatorHandler.initRecovery('email', turnkeyAuthIframeContainerRef.current, constants.iframeElementId, getEmbeddedWalletSessionExpiration.getEmbeddedWalletSessionExpiration((_2 = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _2 === void 0 ? void 0 : _2.sessionKeyDuration));
462
+ const publicKey = yield turnkeyAuthenticatorHandler.initRecovery('email', turnkeyAuthIframeContainerRef.current, constants.iframeElementId, getEmbeddedWalletSessionExpiration.getEmbeddedWalletSessionExpiration((_3 = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _3 === void 0 ? void 0 : _3.sessionKeyDuration));
460
463
  if (!publicKey) {
461
464
  throw new utils.DynamicError(errors.ERROR_SENDING_CODE);
462
465
  }
@@ -41,6 +41,7 @@ import { USER_NOT_LOGGED_IN, ACTIVE_SESSION, SESSION_RESTORED, INVALID_REQUEST,
41
41
  import '../../../../context/VerificationContext/VerificationContext.js';
42
42
  import 'react-dom';
43
43
  import { useElementById } from '../../useElementById/useElementById.js';
44
+ import { findPrimaryEmbeddedChain } from '../../../../views/Passkey/utils/findPrimaryEmbeddedChain/findPrimaryEmbeddedChain.js';
44
45
  import { useWalletContext } from '../../../../context/WalletContext/WalletContext.js';
45
46
  import { useIsTurnkeyWallet } from '../../useIsTurnkeyWallet/useIsTurnkeyWallet.js';
46
47
  import { cleanupExport, initExport, exportCredential } from '../../../../views/EmbeddedReveal/utils/turnkeyExport/turnkeyExport.js';
@@ -121,7 +122,7 @@ const isConnectorSessionKeyActive = (connector) => {
121
122
  * }
122
123
  */
123
124
  const useSecureEnclaveEmbeddedWallet = () => {
124
- var _a, _b, _c, _d;
125
+ var _a, _b, _c, _d, _e;
125
126
  const { projectSettings, primaryWallet, user, environmentId, walletConnectorOptions, } = useInternalDynamicContext();
126
127
  const { addedWalletsIds } = useInternalUserWallets();
127
128
  const { createTurnkeyWallet } = useTurnkey();
@@ -145,13 +146,14 @@ const useSecureEnclaveEmbeddedWallet = () => {
145
146
  * @returns Promise<Wallet | undefined>
146
147
  */
147
148
  const createEmbeddedWallet = useCallback((chains, options) => __awaiter(void 0, void 0, void 0, function* () {
148
- var _e;
149
+ var _f;
149
150
  if (!user) {
150
151
  throw new DynamicError(USER_NOT_LOGGED_IN);
151
152
  }
152
153
  const userWalletsCredentials = getUserWalletsFromVerifiedCredentials(user);
153
- const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(user, chains);
154
- const isManualMode = ((_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _e === void 0 ? void 0 : _e.automaticEmbeddedWalletCreation) === false;
154
+ const primaryChain = findPrimaryEmbeddedChain(projectSettings);
155
+ const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(user, chains !== null && chains !== void 0 ? chains : [primaryChain]);
156
+ const isManualMode = ((_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _f === void 0 ? void 0 : _f.automaticEmbeddedWalletCreation) === false;
155
157
  // if user has a wallet and it's not embedded,
156
158
  // throw error to follow another flow and set up the right wallet
157
159
  // However, if the user is in manual mode continue.
@@ -170,14 +172,15 @@ const useSecureEnclaveEmbeddedWallet = () => {
170
172
  * @param chain - chain parameter to create the wallet for
171
173
  * @returns Promise<UserProfile | undefined>
172
174
  */
173
- const createEmbeddedWalletAccount$1 = useCallback((_f) => __awaiter(void 0, [_f], void 0, function* ({ chain }) {
174
- var _g, _h, _j;
175
+ const createEmbeddedWalletAccount$1 = useCallback((_g) => __awaiter(void 0, [_g], void 0, function* ({ chain }) {
176
+ var _h, _j, _k;
175
177
  if (!user) {
176
178
  throw new Error(USER_NOT_LOGGED_IN);
177
179
  }
178
180
  validateTurnkeyProviderEnabled(projectSettings);
179
- const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(user);
180
- const turnkeyWalletId = (_g = embeddedWalletVerifiedCredential === null || embeddedWalletVerifiedCredential === void 0 ? void 0 : embeddedWalletVerifiedCredential.walletProperties) === null || _g === void 0 ? void 0 : _g.turnkeyHDWalletId;
181
+ const primaryChain = findPrimaryEmbeddedChain(projectSettings);
182
+ const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(user, [primaryChain]);
183
+ const turnkeyWalletId = (_h = embeddedWalletVerifiedCredential === null || embeddedWalletVerifiedCredential === void 0 ? void 0 : embeddedWalletVerifiedCredential.walletProperties) === null || _h === void 0 ? void 0 : _h.turnkeyHDWalletId;
181
184
  if (!turnkeyWalletId) {
182
185
  throw new DynamicError('No HD wallet was found for this user to derive a wallet account. Use createEmbeddedWallet first', 'NoHdWalletFound');
183
186
  }
@@ -186,14 +189,14 @@ const useSecureEnclaveEmbeddedWallet = () => {
186
189
  environmentId,
187
190
  });
188
191
  if (isSessionKeyCompatibleWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector)) {
189
- yield ((_h = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _h === void 0 ? void 0 : _h.createOrRestoreSession({
192
+ yield ((_j = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _j === void 0 ? void 0 : _j.createOrRestoreSession({
190
193
  ignoreRestore: true,
191
194
  }));
192
195
  }
193
196
  else if (yield shouldInitRecovery()) {
194
197
  yield initPasskeyRecoveryProcess('email');
195
198
  }
196
- const signedRequest = yield ((_j = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _j === void 0 ? void 0 : _j.stampCreateWalletAccountRequest({
199
+ const signedRequest = yield ((_k = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _k === void 0 ? void 0 : _k.stampCreateWalletAccountRequest({
197
200
  request: requestToStamp,
198
201
  }));
199
202
  const verifiedUser = yield createEmbeddedWalletAccount({
@@ -221,7 +224,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
221
224
  * @returns Promise<'session_created' | 'session_restored'> - returns a string indicating the status of the session
222
225
  */
223
226
  const createOrRestoreSession = useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
224
- var _k, _l, _m, _o, _p, _q;
227
+ var _l, _m, _o, _p, _q, _r;
225
228
  if (!user) {
226
229
  throw new DynamicError(USER_NOT_LOGGED_IN);
227
230
  }
@@ -240,12 +243,12 @@ const useSecureEnclaveEmbeddedWallet = () => {
240
243
  }
241
244
  const turnkeyAuthIframeContainerRef = createRootElement(iframeContainerId);
242
245
  // try to restore session if possible
243
- if (canRestoreEmbeddedWalletSession((_k = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _k === void 0 ? void 0 : _k.sessionKeyDuration)) {
246
+ if (canRestoreEmbeddedWalletSession((_l = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _l === void 0 ? void 0 : _l.sessionKeyDuration)) {
244
247
  try {
245
248
  const sessionRestored = yield restoreEmbeddedWalletSession({
246
249
  iframeContainer: turnkeyAuthIframeContainerRef.current,
247
250
  iframeElementId,
248
- sessionExpiration: getEmbeddedWalletSessionExpiration((_m = (_l = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _l === void 0 ? void 0 : _l.embeddedWallets) === null || _m === void 0 ? void 0 : _m.sessionKeyDuration),
251
+ sessionExpiration: getEmbeddedWalletSessionExpiration((_o = (_m = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _m === void 0 ? void 0 : _m.embeddedWallets) === null || _o === void 0 ? void 0 : _o.sessionKeyDuration),
249
252
  user,
250
253
  wallet: primaryWallet,
251
254
  });
@@ -264,7 +267,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
264
267
  if (!userHasEmbeddedWallet() || !hasRecoveryEmail) {
265
268
  throw new DynamicError('User does not have a secure enclave wallet or a verified email', INVALID_WALLET_DATA);
266
269
  }
267
- const organizationId = (_q = (_p = (_o = user === null || user === void 0 ? void 0 : user.verifiedCredentials) === null || _o === void 0 ? void 0 : _o.find(({ walletName }) => walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey'))) === null || _p === void 0 ? void 0 : _p.walletProperties) === null || _q === void 0 ? void 0 : _q.turnkeySubOrganizationId;
270
+ const organizationId = (_r = (_q = (_p = user === null || user === void 0 ? void 0 : user.verifiedCredentials) === null || _p === void 0 ? void 0 : _p.find(({ walletName }) => walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey'))) === null || _q === void 0 ? void 0 : _q.walletProperties) === null || _r === void 0 ? void 0 : _r.turnkeySubOrganizationId;
268
271
  yield turnkeyRecoveryHandler.verifyRecoveryCode(options.oneTimeCode, organizationId);
269
272
  const sessionSettings = {
270
273
  createdAt: new Date().getTime(),
@@ -288,12 +291,12 @@ const useSecureEnclaveEmbeddedWallet = () => {
288
291
  * @returns Promise<WebAuthnAttestation>
289
292
  */
290
293
  const createPasskey = useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
291
- var _r, _s;
294
+ var _s, _t;
292
295
  if (!user) {
293
296
  throw new DynamicError(USER_NOT_LOGGED_IN);
294
297
  }
295
298
  validateTurnkeyProviderEnabled(projectSettings);
296
- const turnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_r = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _r === void 0 ? void 0 : _r.chainConfigurations, user.verifiedCredentials);
299
+ const turnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_s = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _s === void 0 ? void 0 : _s.chainConfigurations, user.verifiedCredentials);
297
300
  if (!(turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletConnector)) {
298
301
  throw new DynamicError('Wallet connector not found', INVALID_WALLET_DATA);
299
302
  }
@@ -308,7 +311,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
308
311
  if (!('id' in turnkeyWallet) || !hasEmailVC) {
309
312
  return walletConnector.getWebAuthnAttestation();
310
313
  }
311
- const turnkeySubOrganizationId = (_s = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _s === void 0 ? void 0 : _s.turnkeySubOrganizationId;
314
+ const turnkeySubOrganizationId = (_t = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _t === void 0 ? void 0 : _t.turnkeySubOrganizationId;
312
315
  if (!turnkeySubOrganizationId) {
313
316
  throw new DynamicError('No sub organization id found for the wallet', INVALID_WALLET_DATA);
314
317
  }
@@ -372,16 +375,16 @@ const useSecureEnclaveEmbeddedWallet = () => {
372
375
  * and the html container id to render the iframe into
373
376
  * @returns Promise<string> - returns the embedded wallet recovery phrase or private key
374
377
  */
375
- const revealEmbeddedWalletKey = useCallback((_t) => __awaiter(void 0, [_t], void 0, function* ({ type, htmlContainerId, }) {
376
- var _u, _v, _w, _x, _y, _z;
378
+ const revealEmbeddedWalletKey = useCallback((_u) => __awaiter(void 0, [_u], void 0, function* ({ type, htmlContainerId, }) {
379
+ var _v, _w, _x, _y, _z, _0;
377
380
  if (!user) {
378
381
  throw new DynamicError(USER_NOT_LOGGED_IN);
379
382
  }
380
383
  yield cleanupExport({
381
384
  wallet: wallet,
382
385
  });
383
- const turnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_u = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _u === void 0 ? void 0 : _u.chainConfigurations, user === null || user === void 0 ? void 0 : user.verifiedCredentials);
384
- const turnkeyHDWalletId = (_v = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _v === void 0 ? void 0 : _v.turnkeyHDWalletId;
386
+ const turnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_v = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _v === void 0 ? void 0 : _v.chainConfigurations, user === null || user === void 0 ? void 0 : user.verifiedCredentials);
387
+ const turnkeyHDWalletId = (_w = turnkeyWallet === null || turnkeyWallet === void 0 ? void 0 : turnkeyWallet.walletProperties) === null || _w === void 0 ? void 0 : _w.turnkeyHDWalletId;
385
388
  if (type === 'recoveryPhrase' && !turnkeyHDWalletId) {
386
389
  type = 'privateKey';
387
390
  }
@@ -390,7 +393,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
390
393
  // since it will show unrelated turnkey content
391
394
  iframeContainerElement.current.style.display = 'none';
392
395
  if (isSessionKeyCompatibleWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector)) {
393
- yield ((_w = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _w === void 0 ? void 0 : _w.createOrRestoreSession());
396
+ yield ((_x = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _x === void 0 ? void 0 : _x.createOrRestoreSession());
394
397
  }
395
398
  yield initExport({
396
399
  iframeContainer: iframeContainerElement.current,
@@ -405,11 +408,11 @@ const useSecureEnclaveEmbeddedWallet = () => {
405
408
  wallet: wallet,
406
409
  });
407
410
  }
408
- catch (_0) {
411
+ catch (_1) {
409
412
  if (isSessionKeyCompatibleWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector) &&
410
- ((_x = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _x === void 0 ? void 0 : _x.removeSessionKeys)) {
411
- yield ((_y = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _y === void 0 ? void 0 : _y.removeSessionKeys());
412
- yield ((_z = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _z === void 0 ? void 0 : _z.createOrRestoreSession({
413
+ ((_y = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _y === void 0 ? void 0 : _y.removeSessionKeys)) {
414
+ yield ((_z = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _z === void 0 ? void 0 : _z.removeSessionKeys());
415
+ yield ((_0 = wallet === null || wallet === void 0 ? void 0 : wallet.connector) === null || _0 === void 0 ? void 0 : _0.createOrRestoreSession({
413
416
  ignoreRestore: true,
414
417
  }));
415
418
  }
@@ -428,7 +431,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
428
431
  createRootElement,
429
432
  environmentId,
430
433
  wallet,
431
- (_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _d === void 0 ? void 0 : _d.chainConfigurations,
434
+ (_e = (_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _d === void 0 ? void 0 : _d.embeddedWallets) === null || _e === void 0 ? void 0 : _e.chainConfigurations,
432
435
  user,
433
436
  walletConnectorOptions,
434
437
  ]);
@@ -437,11 +440,11 @@ const useSecureEnclaveEmbeddedWallet = () => {
437
440
  * @returns Promise<'code_sent'>
438
441
  */
439
442
  const sendOneTimeCode = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
440
- var _1, _2;
443
+ var _2, _3;
441
444
  if (!user) {
442
445
  throw new DynamicError(USER_NOT_LOGGED_IN);
443
446
  }
444
- const targetTurnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_1 = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _1 === void 0 ? void 0 : _1.chainConfigurations, user.verifiedCredentials);
447
+ const targetTurnkeyWallet = findTurnkeyWalletByPrimaryChain(walletConnectorOptions, (_2 = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _2 === void 0 ? void 0 : _2.chainConfigurations, user.verifiedCredentials);
445
448
  if (!targetTurnkeyWallet || !('id' in targetTurnkeyWallet)) {
446
449
  throw new DynamicError('User does not have a valid secure enclave wallet', INVALID_WALLET_DATA);
447
450
  }
@@ -452,7 +455,7 @@ const useSecureEnclaveEmbeddedWallet = () => {
452
455
  throw new DynamicError('Session is active. No need to create a new one', ACTIVE_SESSION);
453
456
  }
454
457
  const turnkeyAuthIframeContainerRef = createRootElement(iframeContainerId);
455
- const publicKey = yield turnkeyAuthenticatorHandler.initRecovery('email', turnkeyAuthIframeContainerRef.current, iframeElementId, getEmbeddedWalletSessionExpiration((_2 = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _2 === void 0 ? void 0 : _2.sessionKeyDuration));
458
+ const publicKey = yield turnkeyAuthenticatorHandler.initRecovery('email', turnkeyAuthIframeContainerRef.current, iframeElementId, getEmbeddedWalletSessionExpiration((_3 = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _3 === void 0 ? void 0 : _3.sessionKeyDuration));
456
459
  if (!publicKey) {
457
460
  throw new DynamicError(ERROR_SENDING_CODE);
458
461
  }
@@ -99,17 +99,26 @@ const useTurnkey = () => {
99
99
  const { createDynamicEmbeddedWalletMutation } = useCreateDynamicEmbeddedWalletMutation.useCreateDynamicEmbeddedWalletMutation();
100
100
  const { getEOAWallet } = useSmartWallets.useSmartWallets();
101
101
  const startHeadlessEmbeddedWalletCreationFlow = React.useCallback((chains, options) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
102
- yield createDynamicEmbeddedWalletMutation({
103
- chains,
104
- environmentId,
105
- options,
106
- walletConnectorOptions,
107
- withAuthenticator: false,
108
- });
109
- setShowAuthFlow(false, { performMultiWalletChecks: false }); // close email otp pin modal
110
102
  return new Promise((resolve, reject) => {
111
- dynamicEvents.dynamicEvents.once('embeddedWalletCreated', (wallet) => resolve(wallet));
103
+ // register the event listeners before calling create embedded wallet
104
+ // as the event might fire before the listeners are registered.
105
+ dynamicEvents.dynamicEvents.once('embeddedWalletCreated', (wallet) => {
106
+ resolve(wallet);
107
+ });
112
108
  dynamicEvents.dynamicEvents.once('embeddedWalletFailed', (error) => reject(error));
109
+ createDynamicEmbeddedWalletMutation({
110
+ chains,
111
+ environmentId,
112
+ options,
113
+ walletConnectorOptions,
114
+ withAuthenticator: false,
115
+ })
116
+ .then(() => {
117
+ setShowAuthFlow(false, { performMultiWalletChecks: false }); // close email otp pin modal
118
+ })
119
+ .catch((error) => {
120
+ reject(error);
121
+ });
113
122
  });
114
123
  }), [
115
124
  createDynamicEmbeddedWalletMutation,
@@ -185,7 +194,10 @@ const useTurnkey = () => {
185
194
  const isManualMode = ((_c = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _c === void 0 ? void 0 : _c.automaticEmbeddedWalletCreation) === false;
186
195
  const shouldCreateV2WalletsByDefault = ((_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _d === void 0 ? void 0 : _d.defaultWalletVersion) ===
187
196
  sdkApiCore.EmbeddedWalletVersionEnum.V2;
188
- const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(user, chains);
197
+ const primaryChain = findPrimaryEmbeddedChain.findPrimaryEmbeddedChain(projectSettings);
198
+ // if embedded wallet already exists
199
+ // get the one with the primary chain if `chains` is undefined
200
+ const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(user, chains !== null && chains !== void 0 ? chains : [primaryChain]);
189
201
  const userWalletsCredentials = getUserWalletsFromVerifiedCredentials.getUserWalletsFromVerifiedCredentials(user);
190
202
  // If the user doesn't have a wallet, or if the customer is in Manual
191
203
  // Mode, we should attempt to create a new wallet. Note that if in manual
@@ -212,7 +224,7 @@ const useTurnkey = () => {
212
224
  if (embeddedWalletVerifiedCredential &&
213
225
  user.newUser &&
214
226
  ((_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _f === void 0 ? void 0 : _f.automaticEmbeddedWalletCreation)) {
215
- const walletConnector = findPasskeyEmailWalletConnector.findPasskeyEmailWalletConnector(walletConnectorOptions, findPrimaryEmbeddedChain.findPrimaryEmbeddedChain(projectSettings));
227
+ const walletConnector = findPasskeyEmailWalletConnector.findPasskeyEmailWalletConnector(walletConnectorOptions, primaryChain);
216
228
  if (!walletConnector) {
217
229
  throw new Error('Could not find the embedded wallet connector');
218
230
  }
@@ -95,17 +95,26 @@ const useTurnkey = () => {
95
95
  const { createDynamicEmbeddedWalletMutation } = useCreateDynamicEmbeddedWalletMutation();
96
96
  const { getEOAWallet } = useSmartWallets();
97
97
  const startHeadlessEmbeddedWalletCreationFlow = useCallback((chains, options) => __awaiter(void 0, void 0, void 0, function* () {
98
- yield createDynamicEmbeddedWalletMutation({
99
- chains,
100
- environmentId,
101
- options,
102
- walletConnectorOptions,
103
- withAuthenticator: false,
104
- });
105
- setShowAuthFlow(false, { performMultiWalletChecks: false }); // close email otp pin modal
106
98
  return new Promise((resolve, reject) => {
107
- dynamicEvents.once('embeddedWalletCreated', (wallet) => resolve(wallet));
99
+ // register the event listeners before calling create embedded wallet
100
+ // as the event might fire before the listeners are registered.
101
+ dynamicEvents.once('embeddedWalletCreated', (wallet) => {
102
+ resolve(wallet);
103
+ });
108
104
  dynamicEvents.once('embeddedWalletFailed', (error) => reject(error));
105
+ createDynamicEmbeddedWalletMutation({
106
+ chains,
107
+ environmentId,
108
+ options,
109
+ walletConnectorOptions,
110
+ withAuthenticator: false,
111
+ })
112
+ .then(() => {
113
+ setShowAuthFlow(false, { performMultiWalletChecks: false }); // close email otp pin modal
114
+ })
115
+ .catch((error) => {
116
+ reject(error);
117
+ });
109
118
  });
110
119
  }), [
111
120
  createDynamicEmbeddedWalletMutation,
@@ -181,7 +190,10 @@ const useTurnkey = () => {
181
190
  const isManualMode = ((_c = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _c === void 0 ? void 0 : _c.automaticEmbeddedWalletCreation) === false;
182
191
  const shouldCreateV2WalletsByDefault = ((_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _d === void 0 ? void 0 : _d.defaultWalletVersion) ===
183
192
  EmbeddedWalletVersionEnum.V2;
184
- const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(user, chains);
193
+ const primaryChain = findPrimaryEmbeddedChain(projectSettings);
194
+ // if embedded wallet already exists
195
+ // get the one with the primary chain if `chains` is undefined
196
+ const embeddedWalletVerifiedCredential = findEmbeddedWalletFromVerifiedCredentials(user, chains !== null && chains !== void 0 ? chains : [primaryChain]);
185
197
  const userWalletsCredentials = getUserWalletsFromVerifiedCredentials(user);
186
198
  // If the user doesn't have a wallet, or if the customer is in Manual
187
199
  // Mode, we should attempt to create a new wallet. Note that if in manual
@@ -208,7 +220,7 @@ const useTurnkey = () => {
208
220
  if (embeddedWalletVerifiedCredential &&
209
221
  user.newUser &&
210
222
  ((_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _f === void 0 ? void 0 : _f.automaticEmbeddedWalletCreation)) {
211
- const walletConnector = findPasskeyEmailWalletConnector(walletConnectorOptions, findPrimaryEmbeddedChain(projectSettings));
223
+ const walletConnector = findPasskeyEmailWalletConnector(walletConnectorOptions, primaryChain);
212
224
  if (!walletConnector) {
213
225
  throw new Error('Could not find the embedded wallet connector');
214
226
  }
@@ -89,15 +89,12 @@ require('../../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
89
89
  var useInternalDynamicContext = require('../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext.cjs');
90
90
 
91
91
  // Hook exposed to customers and used internally to handle social account linking
92
- const useSocialAccounts = ({ sessionTimeout } = {
93
- sessionTimeout: 20000,
94
- }) => {
92
+ const useSocialAccounts = () => {
95
93
  var _a;
96
94
  const { environmentId, user, projectSettings } = useInternalDynamicContext.useInternalDynamicContext();
97
95
  const { setView } = ViewContext.useViewContext();
98
96
  const { handleError, setError, setIsProcessing, checkValidProvider, error, isProcessing, connectSocialAccount, } = useSocialAuth.useSocialAuth({
99
97
  onFarcasterUrl: (url) => setView('farcaster-connect-view', { url }),
100
- sessionTimeout,
101
98
  });
102
99
  const verifiedOAuthCredentialsMap = React.useMemo(() => {
103
100
  var _a, _b;
@@ -137,7 +134,7 @@ const useSocialAccounts = ({ sessionTimeout } = {
137
134
  });
138
135
  }), [checkValidOAuthLinking, connectSocialAccount]);
139
136
  const unlinkSocialAccount = React.useCallback((provider) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
140
- var _b;
137
+ var _b, _c;
141
138
  setError(undefined);
142
139
  setIsProcessing(true);
143
140
  if (!checkValidProvider(provider, 'unlink')) {
@@ -149,11 +146,11 @@ const useSocialAccounts = ({ sessionTimeout } = {
149
146
  return;
150
147
  }
151
148
  try {
152
- const primaryWalletId = utils.StorageService.getItem(localStorage.PRIMARY_WALLET_ID);
149
+ const primaryWalletId = (_b = utils.StorageService.getItem(localStorage.PRIMARY_WALLET_ID)) !== null && _b !== void 0 ? _b : undefined;
153
150
  const response = yield oauth.unlinkOAuth({
154
151
  environmentId,
155
152
  primaryWalletId,
156
- verifiedCrentialId: (_b = verifiedCredential.id) !== null && _b !== void 0 ? _b : '',
153
+ verifiedCrentialId: (_c = verifiedCredential.id) !== null && _c !== void 0 ? _c : '',
157
154
  });
158
155
  if (!response) {
159
156
  handleError(provider, types.SocialOAuthErrorCode.UNLINK_ERROR, `Failed to unlink social account: ${provider} | ${verifiedCredential.id}`, { raiseAuthFailure: false });
@@ -1,15 +1,12 @@
1
1
  import { ProviderEnum } from '@dynamic-labs/sdk-api-core';
2
2
  import { SocialAccountInformation } from '@dynamic-labs/types';
3
- type UseSocialAccountsProps = {
4
- sessionTimeout: number;
5
- };
6
3
  type ConnectSocialProps = {
7
4
  /**
8
5
  * Overrides the redirectUrl provided by DynamicContextProvider
9
6
  */
10
7
  redirectUrl?: string;
11
8
  };
12
- export declare const useSocialAccounts: ({ sessionTimeout }?: UseSocialAccountsProps) => {
9
+ export declare const useSocialAccounts: () => {
13
10
  readonly error: import("@dynamic-labs/types").SocialOAuthError | undefined;
14
11
  readonly getLinkedAccountInformation: (provider: ProviderEnum) => SocialAccountInformation | undefined;
15
12
  readonly isLinked: (provider: ProviderEnum) => boolean;