@dynamic-labs/sdk-react-core 4.88.2 → 4.88.3

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 (30) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +12 -12
  5. package/src/lib/context/ConnectWithOtpContext/ConnectWithOtpProvider.cjs +8 -0
  6. package/src/lib/context/ConnectWithOtpContext/ConnectWithOtpProvider.js +8 -0
  7. package/src/lib/context/ConnectWithOtpContext/hooks/useRestoreOtpVerificationState/index.d.ts +1 -0
  8. package/src/lib/context/ConnectWithOtpContext/hooks/useRestoreOtpVerificationState/useRestoreOtpVerificationState.cjs +48 -0
  9. package/src/lib/context/ConnectWithOtpContext/hooks/useRestoreOtpVerificationState/useRestoreOtpVerificationState.d.ts +16 -0
  10. package/src/lib/context/ConnectWithOtpContext/hooks/useRestoreOtpVerificationState/useRestoreOtpVerificationState.js +44 -0
  11. package/src/lib/context/ConnectWithOtpContext/utils/buildEmailOtpHandler/buildEmailOtpHandler.cjs +88 -0
  12. package/src/lib/context/ConnectWithOtpContext/utils/buildEmailOtpHandler/buildEmailOtpHandler.d.ts +16 -0
  13. package/src/lib/context/ConnectWithOtpContext/utils/buildEmailOtpHandler/buildEmailOtpHandler.js +84 -0
  14. package/src/lib/context/ConnectWithOtpContext/utils/buildEmailOtpHandler/index.d.ts +1 -0
  15. package/src/lib/context/ConnectWithOtpContext/utils/buildSmsOtpHandler/buildSmsOtpHandler.cjs +67 -0
  16. package/src/lib/context/ConnectWithOtpContext/utils/buildSmsOtpHandler/buildSmsOtpHandler.d.ts +17 -0
  17. package/src/lib/context/ConnectWithOtpContext/utils/buildSmsOtpHandler/buildSmsOtpHandler.js +63 -0
  18. package/src/lib/context/ConnectWithOtpContext/utils/buildSmsOtpHandler/index.d.ts +1 -0
  19. package/src/lib/context/ConnectWithOtpContext/utils/createEmailHandler.cjs +23 -47
  20. package/src/lib/context/ConnectWithOtpContext/utils/createEmailHandler.d.ts +1 -1
  21. package/src/lib/context/ConnectWithOtpContext/utils/createEmailHandler.js +23 -47
  22. package/src/lib/context/ConnectWithOtpContext/utils/createSmsHandler.cjs +19 -34
  23. package/src/lib/context/ConnectWithOtpContext/utils/createSmsHandler.d.ts +1 -1
  24. package/src/lib/context/ConnectWithOtpContext/utils/createSmsHandler.js +19 -34
  25. package/src/lib/context/ConnectWithOtpContext/utils/otpVerificationStorage/index.d.ts +2 -0
  26. package/src/lib/context/ConnectWithOtpContext/utils/otpVerificationStorage/otpVerificationStorage.cjs +60 -0
  27. package/src/lib/context/ConnectWithOtpContext/utils/otpVerificationStorage/otpVerificationStorage.d.ts +30 -0
  28. package/src/lib/context/ConnectWithOtpContext/utils/otpVerificationStorage/otpVerificationStorage.js +54 -0
  29. package/src/lib/utils/hooks/useCreateWalletConnectorOptions/useCreateWalletConnectorOptions.cjs +10 -2
  30. package/src/lib/utils/hooks/useCreateWalletConnectorOptions/useCreateWalletConnectorOptions.js +10 -2
package/CHANGELOG.md CHANGED
@@ -1,4 +1,12 @@
1
1
 
2
+ ### [4.88.3](https://github.com/dynamic-labs/dynamic-auth/compare/v4.88.2...v4.88.3) (2026-06-09)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * **ethereum:** bump @walletconnect/ethereum-provider to 2.23.2 ([#11497](https://github.com/dynamic-labs/dynamic-auth/issues/11497)) ([fb42c38](https://github.com/dynamic-labs/dynamic-auth/commit/fb42c3877f55d2dfaa3a3a46f8178a6b4a0e55d0))
8
+ * persist OTP verification state in sessionStorage to survive webview remounts ([#11499](https://github.com/dynamic-labs/dynamic-auth/issues/11499)) ([aa330df](https://github.com/dynamic-labs/dynamic-auth/commit/aa330dfc41e8fc81b823cce08b7c9b93588fc52c))
9
+
2
10
  ### [4.88.2](https://github.com/dynamic-labs/dynamic-auth/compare/v4.88.1...v4.88.2) (2026-06-06)
3
11
 
4
12
 
package/package.cjs CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.88.2";
6
+ var version = "4.88.3";
7
7
  var dependencies = {
8
8
  "@dynamic-labs/sdk-api-core": "0.0.1015",
9
9
  "@dynamic-labs-sdk/client": "1.7.0",
package/package.js CHANGED
@@ -1,5 +1,5 @@
1
1
  'use client'
2
- var version = "4.88.2";
2
+ var version = "4.88.3";
3
3
  var dependencies = {
4
4
  "@dynamic-labs/sdk-api-core": "0.0.1015",
5
5
  "@dynamic-labs-sdk/client": "1.7.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/sdk-react-core",
3
- "version": "4.88.2",
3
+ "version": "4.88.3",
4
4
  "dependencies": {
5
5
  "@dynamic-labs/sdk-api-core": "0.0.1015",
6
6
  "@dynamic-labs-sdk/client": "1.7.0",
@@ -17,17 +17,17 @@
17
17
  "yup": "0.32.11",
18
18
  "react-international-phone": "4.5.0",
19
19
  "bs58": "5.0.0",
20
- "@dynamic-labs/assert-package-version": "4.88.2",
21
- "@dynamic-labs/iconic": "4.88.2",
22
- "@dynamic-labs/locale": "4.88.2",
23
- "@dynamic-labs/logger": "4.88.2",
24
- "@dynamic-labs/multi-wallet": "4.88.2",
25
- "@dynamic-labs/rpc-providers": "4.88.2",
26
- "@dynamic-labs/store": "4.88.2",
27
- "@dynamic-labs/types": "4.88.2",
28
- "@dynamic-labs/utils": "4.88.2",
29
- "@dynamic-labs/wallet-book": "4.88.2",
30
- "@dynamic-labs/wallet-connector-core": "4.88.2",
20
+ "@dynamic-labs/assert-package-version": "4.88.3",
21
+ "@dynamic-labs/iconic": "4.88.3",
22
+ "@dynamic-labs/locale": "4.88.3",
23
+ "@dynamic-labs/logger": "4.88.3",
24
+ "@dynamic-labs/multi-wallet": "4.88.3",
25
+ "@dynamic-labs/rpc-providers": "4.88.3",
26
+ "@dynamic-labs/store": "4.88.3",
27
+ "@dynamic-labs/types": "4.88.3",
28
+ "@dynamic-labs/utils": "4.88.3",
29
+ "@dynamic-labs/wallet-book": "4.88.3",
30
+ "@dynamic-labs/wallet-connector-core": "4.88.3",
31
31
  "eventemitter3": "5.0.1"
32
32
  },
33
33
  "devDependencies": {
@@ -89,8 +89,10 @@ require('../../utils/hooks/useWalletBackup/types.cjs');
89
89
  require('../../utils/hooks/useWalletBackup/cloudProviders.cjs');
90
90
  require('../IpConfigurationContext/IpConfigurationContext.cjs');
91
91
  var ConnectWithOtpContext = require('./ConnectWithOtpContext.cjs');
92
+ var useRestoreOtpVerificationState = require('./hooks/useRestoreOtpVerificationState/useRestoreOtpVerificationState.cjs');
92
93
  var createEmailHandler = require('./utils/createEmailHandler.cjs');
93
94
  var createSmsHandler = require('./utils/createSmsHandler.cjs');
95
+ var otpVerificationStorage = require('./utils/otpVerificationStorage/otpVerificationStorage.cjs');
94
96
  require('../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs');
95
97
  require('@hcaptcha/react-hcaptcha');
96
98
  require('../../widgets/DynamicWidget/helpers/convertExchangeKeyAndProviderEnum.cjs');
@@ -126,6 +128,11 @@ const ConnectWithOtpProvider = ({ children }) => {
126
128
  projectSettings,
127
129
  });
128
130
  const lastVerificationHandlerRef = React.useRef(null);
131
+ useRestoreOtpVerificationState.useRestoreOtpVerificationState({
132
+ embeddedWalletSessionKeys,
133
+ environmentId,
134
+ handlerRef: lastVerificationHandlerRef,
135
+ });
129
136
  const providers = (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) || [];
130
137
  const mapProvider = {
131
138
  [sdkApiCore.ProviderEnum.Dynamic]: {
@@ -187,6 +194,7 @@ const ConnectWithOtpProvider = ({ children }) => {
187
194
  //EMAIL
188
195
  dynamicEvents.dynamicEvents.emit('emailVerificationResult', verified, destination);
189
196
  }
197
+ otpVerificationStorage.clearOtpVerificationState();
190
198
  // Avoid calling authSuccess if we're only verifying
191
199
  if (!(options === null || options === void 0 ? void 0 : options.skipSetUserAndAuthToken)) {
192
200
  setCallback('authSuccess');
@@ -85,8 +85,10 @@ import '../../utils/hooks/useWalletBackup/types.js';
85
85
  import '../../utils/hooks/useWalletBackup/cloudProviders.js';
86
86
  import '../IpConfigurationContext/IpConfigurationContext.js';
87
87
  import { ConnectWithOtpContext } from './ConnectWithOtpContext.js';
88
+ import { useRestoreOtpVerificationState } from './hooks/useRestoreOtpVerificationState/useRestoreOtpVerificationState.js';
88
89
  import { createEmailHandler } from './utils/createEmailHandler.js';
89
90
  import { createSmsHandler } from './utils/createSmsHandler.js';
91
+ import { clearOtpVerificationState } from './utils/otpVerificationStorage/otpVerificationStorage.js';
90
92
  import '../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.js';
91
93
  import '@hcaptcha/react-hcaptcha';
92
94
  import '../../widgets/DynamicWidget/helpers/convertExchangeKeyAndProviderEnum.js';
@@ -122,6 +124,11 @@ const ConnectWithOtpProvider = ({ children }) => {
122
124
  projectSettings,
123
125
  });
124
126
  const lastVerificationHandlerRef = useRef(null);
127
+ useRestoreOtpVerificationState({
128
+ embeddedWalletSessionKeys,
129
+ environmentId,
130
+ handlerRef: lastVerificationHandlerRef,
131
+ });
125
132
  const providers = (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) || [];
126
133
  const mapProvider = {
127
134
  [ProviderEnum.Dynamic]: {
@@ -183,6 +190,7 @@ const ConnectWithOtpProvider = ({ children }) => {
183
190
  //EMAIL
184
191
  dynamicEvents.emit('emailVerificationResult', verified, destination);
185
192
  }
193
+ clearOtpVerificationState();
186
194
  // Avoid calling authSuccess if we're only verifying
187
195
  if (!(options === null || options === void 0 ? void 0 : options.skipSetUserAndAuthToken)) {
188
196
  setCallback('authSuccess');
@@ -0,0 +1 @@
1
+ export { useRestoreOtpVerificationState } from './useRestoreOtpVerificationState';
@@ -0,0 +1,48 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var React = require('react');
7
+ var buildEmailOtpHandler = require('../../utils/buildEmailOtpHandler/buildEmailOtpHandler.cjs');
8
+ var buildSmsOtpHandler = require('../../utils/buildSmsOtpHandler/buildSmsOtpHandler.cjs');
9
+ var otpVerificationStorage = require('../../utils/otpVerificationStorage/otpVerificationStorage.cjs');
10
+
11
+ /**
12
+ * Restores a persisted OTP verification handler from localStorage on mount.
13
+ * This handles the case where the webview was killed by Android on low-memory
14
+ * devices and needs to resume an in-progress OTP flow.
15
+ */
16
+ const useRestoreOtpVerificationState = ({ embeddedWalletSessionKeys, environmentId, handlerRef, }) => {
17
+ React.useEffect(() => {
18
+ if (handlerRef.current) {
19
+ return;
20
+ }
21
+ const persisted = otpVerificationStorage.restoreOtpVerificationState();
22
+ if (!persisted) {
23
+ return;
24
+ }
25
+ if (persisted.type === 'email') {
26
+ handlerRef.current = buildEmailOtpHandler.buildEmailOtpHandler({
27
+ captchaToken: persisted.captchaToken,
28
+ email: persisted.destination,
29
+ embeddedWalletSessionKeys,
30
+ environmentId,
31
+ initialVerificationUUID: persisted.verificationUUID,
32
+ });
33
+ }
34
+ else {
35
+ handlerRef.current = buildSmsOtpHandler.buildSmsOtpHandler({
36
+ captchaToken: persisted.captchaToken,
37
+ embeddedWalletSessionKeys,
38
+ environmentId,
39
+ phone: persisted.destination,
40
+ verificationUUID: persisted.verificationUUID,
41
+ });
42
+ }
43
+ // Only needs to run once on mount
44
+ // eslint-disable-next-line react-hooks/exhaustive-deps
45
+ }, []);
46
+ };
47
+
48
+ exports.useRestoreOtpVerificationState = useRestoreOtpVerificationState;
@@ -0,0 +1,16 @@
1
+ import { MutableRefObject } from 'react';
2
+ import { PhoneData } from '@dynamic-labs/types';
3
+ import { useEmbeddedWalletSessionKeys } from '../../../../utils/hooks';
4
+ import { ProviderVerificationHandler } from '../../types';
5
+ type UseRestoreOtpVerificationStateParams = {
6
+ embeddedWalletSessionKeys: ReturnType<typeof useEmbeddedWalletSessionKeys>;
7
+ environmentId: string;
8
+ handlerRef: MutableRefObject<ProviderVerificationHandler<string | PhoneData> | null>;
9
+ };
10
+ /**
11
+ * Restores a persisted OTP verification handler from localStorage on mount.
12
+ * This handles the case where the webview was killed by Android on low-memory
13
+ * devices and needs to resume an in-progress OTP flow.
14
+ */
15
+ export declare const useRestoreOtpVerificationState: ({ embeddedWalletSessionKeys, environmentId, handlerRef, }: UseRestoreOtpVerificationStateParams) => void;
16
+ export {};
@@ -0,0 +1,44 @@
1
+ 'use client'
2
+ import { useEffect } from 'react';
3
+ import { buildEmailOtpHandler } from '../../utils/buildEmailOtpHandler/buildEmailOtpHandler.js';
4
+ import { buildSmsOtpHandler } from '../../utils/buildSmsOtpHandler/buildSmsOtpHandler.js';
5
+ import { restoreOtpVerificationState } from '../../utils/otpVerificationStorage/otpVerificationStorage.js';
6
+
7
+ /**
8
+ * Restores a persisted OTP verification handler from localStorage on mount.
9
+ * This handles the case where the webview was killed by Android on low-memory
10
+ * devices and needs to resume an in-progress OTP flow.
11
+ */
12
+ const useRestoreOtpVerificationState = ({ embeddedWalletSessionKeys, environmentId, handlerRef, }) => {
13
+ useEffect(() => {
14
+ if (handlerRef.current) {
15
+ return;
16
+ }
17
+ const persisted = restoreOtpVerificationState();
18
+ if (!persisted) {
19
+ return;
20
+ }
21
+ if (persisted.type === 'email') {
22
+ handlerRef.current = buildEmailOtpHandler({
23
+ captchaToken: persisted.captchaToken,
24
+ email: persisted.destination,
25
+ embeddedWalletSessionKeys,
26
+ environmentId,
27
+ initialVerificationUUID: persisted.verificationUUID,
28
+ });
29
+ }
30
+ else {
31
+ handlerRef.current = buildSmsOtpHandler({
32
+ captchaToken: persisted.captchaToken,
33
+ embeddedWalletSessionKeys,
34
+ environmentId,
35
+ phone: persisted.destination,
36
+ verificationUUID: persisted.verificationUUID,
37
+ });
38
+ }
39
+ // Only needs to run once on mount
40
+ // eslint-disable-next-line react-hooks/exhaustive-deps
41
+ }, []);
42
+ };
43
+
44
+ export { useRestoreOtpVerificationState };
@@ -0,0 +1,88 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../../../../_virtual/_tslib.cjs');
7
+ require('@dynamic-labs-sdk/client/core');
8
+ require('@dynamic-labs/sdk-api-core');
9
+ require('react');
10
+ require('eventemitter3');
11
+ require('@dynamic-labs/utils');
12
+ require('@dynamic-labs-sdk/client');
13
+ require('../../../../config/ApiEndpoint.cjs');
14
+ require('@dynamic-labs/iconic');
15
+ require('@dynamic-labs/wallet-connector-core');
16
+ require('react/jsx-runtime');
17
+ require('../../../ViewContext/ViewContext.cjs');
18
+ require('../../../../shared/logger.cjs');
19
+ require('@dynamic-labs/wallet-book');
20
+ require('../../../../utils/constants/colors.cjs');
21
+ require('../../../../utils/constants/values.cjs');
22
+ require('../../../../shared/consts/index.cjs');
23
+ require('@dynamic-labs/multi-wallet');
24
+ require('react-international-phone');
25
+ require('../../../../store/state/nonce/nonce.cjs');
26
+ var email = require('../../../../data/api/email/email.cjs');
27
+ require('@dynamic-labs/locale');
28
+ require('../../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
29
+ require('../../../../store/state/primaryWalletId/primaryWalletId.cjs');
30
+ require('../../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
31
+ require('../../../../utils/functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.cjs');
32
+ require('../../../../events/dynamicEvents.cjs');
33
+ var storeTokenAndUser = require('../../../../client/extension/storeTokenAndUser/storeTokenAndUser.cjs');
34
+ var generateSessionKeys = require('../../../../client/extension/functions/generateSessionKeys/generateSessionKeys.cjs');
35
+ var otpVerificationStorage = require('../otpVerificationStorage/otpVerificationStorage.cjs');
36
+
37
+ /**
38
+ * Builds a ProviderVerificationHandler for email OTP from the given parameters.
39
+ * Used both after creating a new email verification and when restoring a
40
+ * persisted verification state after a webview remount.
41
+ */
42
+ const buildEmailOtpHandler = ({ captchaToken, email: email$1, embeddedWalletSessionKeys: { shouldRegisterSessionKeysOnSignin, generateSessionKey, }, environmentId, initialVerificationUUID, }) => {
43
+ // Mutable so retry can update the UUID for subsequent verify calls
44
+ let verificationUUID = initialVerificationUUID;
45
+ return {
46
+ retry: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
47
+ const retryEmailVerificationResponse = yield email.retryEmailVerification({
48
+ email: email$1,
49
+ environmentId,
50
+ verificationUUID,
51
+ });
52
+ // eslint-disable-next-line prefer-destructuring
53
+ verificationUUID = retryEmailVerificationResponse.verificationUUID;
54
+ otpVerificationStorage.persistOtpVerificationState({
55
+ captchaToken,
56
+ destination: email$1,
57
+ type: 'email',
58
+ verificationUUID,
59
+ });
60
+ }),
61
+ type: 'email',
62
+ verify: (oneTimePassword, options) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
63
+ let sessionPublicKey = undefined;
64
+ if (shouldRegisterSessionKeysOnSignin()) {
65
+ const keypair = yield generateSessionKey();
66
+ sessionPublicKey = keypair.publicKey;
67
+ }
68
+ yield generateSessionKeys.generateSessionKeys();
69
+ const response = yield email.signInWithEmailVerification({
70
+ captchaToken,
71
+ environmentId,
72
+ sessionPublicKey,
73
+ verificationToken: oneTimePassword,
74
+ verificationUUID,
75
+ });
76
+ if (!(options === null || options === void 0 ? void 0 : options.skipSetUserAndAuthToken)) {
77
+ storeTokenAndUser.storeTokenAndUser(response);
78
+ }
79
+ return {
80
+ destination: email$1,
81
+ response: response,
82
+ verified: true,
83
+ };
84
+ }),
85
+ };
86
+ };
87
+
88
+ exports.buildEmailOtpHandler = buildEmailOtpHandler;
@@ -0,0 +1,16 @@
1
+ import { useEmbeddedWalletSessionKeys } from '../../../../utils/hooks';
2
+ import { ProviderVerificationHandler } from '../../types';
3
+ type BuildEmailOtpHandlerParams = {
4
+ captchaToken: string | undefined;
5
+ email: string;
6
+ embeddedWalletSessionKeys: ReturnType<typeof useEmbeddedWalletSessionKeys>;
7
+ environmentId: string;
8
+ initialVerificationUUID: string;
9
+ };
10
+ /**
11
+ * Builds a ProviderVerificationHandler for email OTP from the given parameters.
12
+ * Used both after creating a new email verification and when restoring a
13
+ * persisted verification state after a webview remount.
14
+ */
15
+ export declare const buildEmailOtpHandler: ({ captchaToken, email, embeddedWalletSessionKeys: { shouldRegisterSessionKeysOnSignin, generateSessionKey, }, environmentId, initialVerificationUUID, }: BuildEmailOtpHandlerParams) => ProviderVerificationHandler<string>;
16
+ export {};
@@ -0,0 +1,84 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../../../../_virtual/_tslib.js';
3
+ import '@dynamic-labs-sdk/client/core';
4
+ import '@dynamic-labs/sdk-api-core';
5
+ import 'react';
6
+ import 'eventemitter3';
7
+ import '@dynamic-labs/utils';
8
+ import '@dynamic-labs-sdk/client';
9
+ import '../../../../config/ApiEndpoint.js';
10
+ import '@dynamic-labs/iconic';
11
+ import '@dynamic-labs/wallet-connector-core';
12
+ import 'react/jsx-runtime';
13
+ import '../../../ViewContext/ViewContext.js';
14
+ import '../../../../shared/logger.js';
15
+ import '@dynamic-labs/wallet-book';
16
+ import '../../../../utils/constants/colors.js';
17
+ import '../../../../utils/constants/values.js';
18
+ import '../../../../shared/consts/index.js';
19
+ import '@dynamic-labs/multi-wallet';
20
+ import 'react-international-phone';
21
+ import '../../../../store/state/nonce/nonce.js';
22
+ import { retryEmailVerification, signInWithEmailVerification } from '../../../../data/api/email/email.js';
23
+ import '@dynamic-labs/locale';
24
+ import '../../../../store/state/dynamicContextProps/dynamicContextProps.js';
25
+ import '../../../../store/state/primaryWalletId/primaryWalletId.js';
26
+ import '../../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
27
+ import '../../../../utils/functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.js';
28
+ import '../../../../events/dynamicEvents.js';
29
+ import { storeTokenAndUser } from '../../../../client/extension/storeTokenAndUser/storeTokenAndUser.js';
30
+ import { generateSessionKeys } from '../../../../client/extension/functions/generateSessionKeys/generateSessionKeys.js';
31
+ import { persistOtpVerificationState } from '../otpVerificationStorage/otpVerificationStorage.js';
32
+
33
+ /**
34
+ * Builds a ProviderVerificationHandler for email OTP from the given parameters.
35
+ * Used both after creating a new email verification and when restoring a
36
+ * persisted verification state after a webview remount.
37
+ */
38
+ const buildEmailOtpHandler = ({ captchaToken, email, embeddedWalletSessionKeys: { shouldRegisterSessionKeysOnSignin, generateSessionKey, }, environmentId, initialVerificationUUID, }) => {
39
+ // Mutable so retry can update the UUID for subsequent verify calls
40
+ let verificationUUID = initialVerificationUUID;
41
+ return {
42
+ retry: () => __awaiter(void 0, void 0, void 0, function* () {
43
+ const retryEmailVerificationResponse = yield retryEmailVerification({
44
+ email,
45
+ environmentId,
46
+ verificationUUID,
47
+ });
48
+ // eslint-disable-next-line prefer-destructuring
49
+ verificationUUID = retryEmailVerificationResponse.verificationUUID;
50
+ persistOtpVerificationState({
51
+ captchaToken,
52
+ destination: email,
53
+ type: 'email',
54
+ verificationUUID,
55
+ });
56
+ }),
57
+ type: 'email',
58
+ verify: (oneTimePassword, options) => __awaiter(void 0, void 0, void 0, function* () {
59
+ let sessionPublicKey = undefined;
60
+ if (shouldRegisterSessionKeysOnSignin()) {
61
+ const keypair = yield generateSessionKey();
62
+ sessionPublicKey = keypair.publicKey;
63
+ }
64
+ yield generateSessionKeys();
65
+ const response = yield signInWithEmailVerification({
66
+ captchaToken,
67
+ environmentId,
68
+ sessionPublicKey,
69
+ verificationToken: oneTimePassword,
70
+ verificationUUID,
71
+ });
72
+ if (!(options === null || options === void 0 ? void 0 : options.skipSetUserAndAuthToken)) {
73
+ storeTokenAndUser(response);
74
+ }
75
+ return {
76
+ destination: email,
77
+ response: response,
78
+ verified: true,
79
+ };
80
+ }),
81
+ };
82
+ };
83
+
84
+ export { buildEmailOtpHandler };
@@ -0,0 +1 @@
1
+ export { buildEmailOtpHandler } from './buildEmailOtpHandler';
@@ -0,0 +1,67 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../../../../_virtual/_tslib.cjs');
7
+ require('@dynamic-labs-sdk/client/core');
8
+ require('@dynamic-labs/sdk-api-core');
9
+ require('react');
10
+ require('eventemitter3');
11
+ require('@dynamic-labs/utils');
12
+ require('@dynamic-labs-sdk/client');
13
+ require('../../../../config/ApiEndpoint.cjs');
14
+ require('@dynamic-labs/iconic');
15
+ require('@dynamic-labs/wallet-connector-core');
16
+ require('react/jsx-runtime');
17
+ require('../../../ViewContext/ViewContext.cjs');
18
+ require('../../../../shared/logger.cjs');
19
+ require('@dynamic-labs/wallet-book');
20
+ require('../../../../utils/constants/colors.cjs');
21
+ require('../../../../utils/constants/values.cjs');
22
+ require('../../../../shared/consts/index.cjs');
23
+ require('@dynamic-labs/multi-wallet');
24
+ require('react-international-phone');
25
+ require('../../../../store/state/nonce/nonce.cjs');
26
+ var sms = require('../../../../data/api/sms/sms.cjs');
27
+ require('../../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
28
+ require('../../../../store/state/primaryWalletId/primaryWalletId.cjs');
29
+ require('../../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
30
+ require('../../../../utils/functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.cjs');
31
+ require('../../../../events/dynamicEvents.cjs');
32
+ var storeTokenAndUser = require('../../../../client/extension/storeTokenAndUser/storeTokenAndUser.cjs');
33
+ var generateSessionKeys = require('../../../../client/extension/functions/generateSessionKeys/generateSessionKeys.cjs');
34
+
35
+ /**
36
+ * Builds a ProviderVerificationHandler for SMS OTP from the given parameters.
37
+ * Used both after creating a new SMS verification and when restoring a
38
+ * persisted verification state after a webview remount.
39
+ */
40
+ const buildSmsOtpHandler = ({ captchaToken, embeddedWalletSessionKeys: { shouldRegisterSessionKeysOnSignin, generateSessionKey, }, environmentId, phone, verificationUUID, }) => ({
41
+ type: 'sms',
42
+ verify: (oneTimePassword, options) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
43
+ let sessionPublicKey = undefined;
44
+ if (shouldRegisterSessionKeysOnSignin()) {
45
+ const keypair = yield generateSessionKey();
46
+ sessionPublicKey = keypair.publicKey;
47
+ }
48
+ yield generateSessionKeys.generateSessionKeys();
49
+ const response = yield sms.signInWithSmsVerification({
50
+ captchaToken,
51
+ environmentId,
52
+ sessionPublicKey,
53
+ verificationToken: oneTimePassword,
54
+ verificationUUID,
55
+ });
56
+ if (!(options === null || options === void 0 ? void 0 : options.skipSetUserAndAuthToken)) {
57
+ storeTokenAndUser.storeTokenAndUser(response);
58
+ }
59
+ return {
60
+ destination: phone,
61
+ response: response,
62
+ verified: true,
63
+ };
64
+ }),
65
+ });
66
+
67
+ exports.buildSmsOtpHandler = buildSmsOtpHandler;
@@ -0,0 +1,17 @@
1
+ import { PhoneData } from '@dynamic-labs/types';
2
+ import { useEmbeddedWalletSessionKeys } from '../../../../utils/hooks';
3
+ import { ProviderVerificationHandler } from '../../types';
4
+ type BuildSmsOtpHandlerParams = {
5
+ captchaToken: string | undefined;
6
+ embeddedWalletSessionKeys: ReturnType<typeof useEmbeddedWalletSessionKeys>;
7
+ environmentId: string;
8
+ phone: PhoneData;
9
+ verificationUUID: string;
10
+ };
11
+ /**
12
+ * Builds a ProviderVerificationHandler for SMS OTP from the given parameters.
13
+ * Used both after creating a new SMS verification and when restoring a
14
+ * persisted verification state after a webview remount.
15
+ */
16
+ export declare const buildSmsOtpHandler: ({ captchaToken, embeddedWalletSessionKeys: { shouldRegisterSessionKeysOnSignin, generateSessionKey, }, environmentId, phone, verificationUUID, }: BuildSmsOtpHandlerParams) => ProviderVerificationHandler<PhoneData>;
17
+ export {};
@@ -0,0 +1,63 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../../../../_virtual/_tslib.js';
3
+ import '@dynamic-labs-sdk/client/core';
4
+ import '@dynamic-labs/sdk-api-core';
5
+ import 'react';
6
+ import 'eventemitter3';
7
+ import '@dynamic-labs/utils';
8
+ import '@dynamic-labs-sdk/client';
9
+ import '../../../../config/ApiEndpoint.js';
10
+ import '@dynamic-labs/iconic';
11
+ import '@dynamic-labs/wallet-connector-core';
12
+ import 'react/jsx-runtime';
13
+ import '../../../ViewContext/ViewContext.js';
14
+ import '../../../../shared/logger.js';
15
+ import '@dynamic-labs/wallet-book';
16
+ import '../../../../utils/constants/colors.js';
17
+ import '../../../../utils/constants/values.js';
18
+ import '../../../../shared/consts/index.js';
19
+ import '@dynamic-labs/multi-wallet';
20
+ import 'react-international-phone';
21
+ import '../../../../store/state/nonce/nonce.js';
22
+ import { signInWithSmsVerification } from '../../../../data/api/sms/sms.js';
23
+ import '../../../../store/state/dynamicContextProps/dynamicContextProps.js';
24
+ import '../../../../store/state/primaryWalletId/primaryWalletId.js';
25
+ import '../../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
26
+ import '../../../../utils/functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.js';
27
+ import '../../../../events/dynamicEvents.js';
28
+ import { storeTokenAndUser } from '../../../../client/extension/storeTokenAndUser/storeTokenAndUser.js';
29
+ import { generateSessionKeys } from '../../../../client/extension/functions/generateSessionKeys/generateSessionKeys.js';
30
+
31
+ /**
32
+ * Builds a ProviderVerificationHandler for SMS OTP from the given parameters.
33
+ * Used both after creating a new SMS verification and when restoring a
34
+ * persisted verification state after a webview remount.
35
+ */
36
+ const buildSmsOtpHandler = ({ captchaToken, embeddedWalletSessionKeys: { shouldRegisterSessionKeysOnSignin, generateSessionKey, }, environmentId, phone, verificationUUID, }) => ({
37
+ type: 'sms',
38
+ verify: (oneTimePassword, options) => __awaiter(void 0, void 0, void 0, function* () {
39
+ let sessionPublicKey = undefined;
40
+ if (shouldRegisterSessionKeysOnSignin()) {
41
+ const keypair = yield generateSessionKey();
42
+ sessionPublicKey = keypair.publicKey;
43
+ }
44
+ yield generateSessionKeys();
45
+ const response = yield signInWithSmsVerification({
46
+ captchaToken,
47
+ environmentId,
48
+ sessionPublicKey,
49
+ verificationToken: oneTimePassword,
50
+ verificationUUID,
51
+ });
52
+ if (!(options === null || options === void 0 ? void 0 : options.skipSetUserAndAuthToken)) {
53
+ storeTokenAndUser(response);
54
+ }
55
+ return {
56
+ destination: phone,
57
+ response: response,
58
+ verified: true,
59
+ };
60
+ }),
61
+ });
62
+
63
+ export { buildSmsOtpHandler };
@@ -0,0 +1 @@
1
+ export { buildSmsOtpHandler } from './buildSmsOtpHandler';
@@ -4,15 +4,12 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var _tslib = require('../../../../../_virtual/_tslib.cjs');
7
- require('@dynamic-labs-sdk/client/core');
7
+ var email = require('../../../data/api/email/email.cjs');
8
8
  require('@dynamic-labs/sdk-api-core');
9
- require('react');
10
- require('eventemitter3');
11
9
  require('@dynamic-labs/utils');
12
- require('@dynamic-labs-sdk/client');
13
- require('../../../config/ApiEndpoint.cjs');
14
10
  require('@dynamic-labs/iconic');
15
11
  require('@dynamic-labs/wallet-connector-core');
12
+ require('react');
16
13
  require('react/jsx-runtime');
17
14
  require('../../ViewContext/ViewContext.cjs');
18
15
  require('../../../shared/logger.cjs');
@@ -20,63 +17,42 @@ require('@dynamic-labs/wallet-book');
20
17
  require('../../../utils/constants/colors.cjs');
21
18
  require('../../../utils/constants/values.cjs');
22
19
  require('../../../shared/consts/index.cjs');
20
+ require('@dynamic-labs-sdk/client/core');
21
+ require('eventemitter3');
22
+ require('@dynamic-labs-sdk/client');
23
+ require('../../../config/ApiEndpoint.cjs');
23
24
  require('@dynamic-labs/multi-wallet');
24
25
  require('react-international-phone');
25
26
  require('../../../store/state/nonce/nonce.cjs');
26
- var email = require('../../../data/api/email/email.cjs');
27
- require('@dynamic-labs/locale');
28
27
  require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
29
28
  require('../../../store/state/primaryWalletId/primaryWalletId.cjs');
30
29
  require('../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
31
30
  require('../../../utils/functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.cjs');
32
31
  require('../../../events/dynamicEvents.cjs');
33
- var storeTokenAndUser = require('../../../client/extension/storeTokenAndUser/storeTokenAndUser.cjs');
34
- var generateSessionKeys = require('../../../client/extension/functions/generateSessionKeys/generateSessionKeys.cjs');
32
+ require('@dynamic-labs/locale');
33
+ var buildEmailOtpHandler = require('./buildEmailOtpHandler/buildEmailOtpHandler.cjs');
34
+ var otpVerificationStorage = require('./otpVerificationStorage/otpVerificationStorage.cjs');
35
35
 
36
- const createEmailHandler = (environmentId, { shouldRegisterSessionKeysOnSignin, generateSessionKey, }) => (email$1, captchaToken) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
36
+ const createEmailHandler = (environmentId, embeddedWalletSessionKeys) => (email$1, captchaToken) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
37
37
  const createEmailVerificationResponse = yield email.createEmailVerification({
38
38
  captchaToken,
39
39
  email: email$1,
40
40
  environmentId,
41
41
  });
42
- let { verificationUUID } = createEmailVerificationResponse;
43
- return {
44
- retry: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
45
- const retryEmailVerificationResponse = yield email.retryEmailVerification({
46
- email: email$1,
47
- environmentId,
48
- verificationUUID,
49
- });
50
- // eslint-disable-next-line prefer-destructuring
51
- verificationUUID = retryEmailVerificationResponse.verificationUUID;
52
- }),
42
+ const { verificationUUID } = createEmailVerificationResponse;
43
+ otpVerificationStorage.persistOtpVerificationState({
44
+ captchaToken,
45
+ destination: email$1,
53
46
  type: 'email',
54
- verify: (oneTimePassword, options) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
55
- let sessionPublicKey = undefined;
56
- if (shouldRegisterSessionKeysOnSignin()) {
57
- const keypair = yield generateSessionKey();
58
- sessionPublicKey = keypair.publicKey;
59
- }
60
- yield generateSessionKeys.generateSessionKeys();
61
- const response = yield email.signInWithEmailVerification({
62
- captchaToken,
63
- environmentId,
64
- sessionPublicKey,
65
- verificationToken: oneTimePassword,
66
- verificationUUID,
67
- });
68
- // Skip setting the user auth token and only return the VerifyResponse
69
- // if needed because setUser can trigger view re-renders.
70
- if (!(options === null || options === void 0 ? void 0 : options.skipSetUserAndAuthToken)) {
71
- storeTokenAndUser.storeTokenAndUser(response);
72
- }
73
- return {
74
- destination: email$1,
75
- response: response,
76
- verified: true,
77
- };
78
- }),
79
- };
47
+ verificationUUID,
48
+ });
49
+ return buildEmailOtpHandler.buildEmailOtpHandler({
50
+ captchaToken,
51
+ email: email$1,
52
+ embeddedWalletSessionKeys,
53
+ environmentId,
54
+ initialVerificationUUID: verificationUUID,
55
+ });
80
56
  });
81
57
 
82
58
  exports.createEmailHandler = createEmailHandler;
@@ -1,3 +1,3 @@
1
1
  import { useEmbeddedWalletSessionKeys } from '../../../utils/hooks';
2
2
  import { ProviderHandler } from '../types';
3
- export declare const createEmailHandler: (environmentId: string, { shouldRegisterSessionKeysOnSignin, generateSessionKey, }: ReturnType<typeof useEmbeddedWalletSessionKeys>) => ProviderHandler<string>;
3
+ export declare const createEmailHandler: (environmentId: string, embeddedWalletSessionKeys: ReturnType<typeof useEmbeddedWalletSessionKeys>) => ProviderHandler<string>;
@@ -1,14 +1,11 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../../../../_virtual/_tslib.js';
3
- import '@dynamic-labs-sdk/client/core';
3
+ import { createEmailVerification } from '../../../data/api/email/email.js';
4
4
  import '@dynamic-labs/sdk-api-core';
5
- import 'react';
6
- import 'eventemitter3';
7
5
  import '@dynamic-labs/utils';
8
- import '@dynamic-labs-sdk/client';
9
- import '../../../config/ApiEndpoint.js';
10
6
  import '@dynamic-labs/iconic';
11
7
  import '@dynamic-labs/wallet-connector-core';
8
+ import 'react';
12
9
  import 'react/jsx-runtime';
13
10
  import '../../ViewContext/ViewContext.js';
14
11
  import '../../../shared/logger.js';
@@ -16,63 +13,42 @@ import '@dynamic-labs/wallet-book';
16
13
  import '../../../utils/constants/colors.js';
17
14
  import '../../../utils/constants/values.js';
18
15
  import '../../../shared/consts/index.js';
16
+ import '@dynamic-labs-sdk/client/core';
17
+ import 'eventemitter3';
18
+ import '@dynamic-labs-sdk/client';
19
+ import '../../../config/ApiEndpoint.js';
19
20
  import '@dynamic-labs/multi-wallet';
20
21
  import 'react-international-phone';
21
22
  import '../../../store/state/nonce/nonce.js';
22
- import { createEmailVerification, retryEmailVerification, signInWithEmailVerification } from '../../../data/api/email/email.js';
23
- import '@dynamic-labs/locale';
24
23
  import '../../../store/state/dynamicContextProps/dynamicContextProps.js';
25
24
  import '../../../store/state/primaryWalletId/primaryWalletId.js';
26
25
  import '../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
27
26
  import '../../../utils/functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.js';
28
27
  import '../../../events/dynamicEvents.js';
29
- import { storeTokenAndUser } from '../../../client/extension/storeTokenAndUser/storeTokenAndUser.js';
30
- import { generateSessionKeys } from '../../../client/extension/functions/generateSessionKeys/generateSessionKeys.js';
28
+ import '@dynamic-labs/locale';
29
+ import { buildEmailOtpHandler } from './buildEmailOtpHandler/buildEmailOtpHandler.js';
30
+ import { persistOtpVerificationState } from './otpVerificationStorage/otpVerificationStorage.js';
31
31
 
32
- const createEmailHandler = (environmentId, { shouldRegisterSessionKeysOnSignin, generateSessionKey, }) => (email, captchaToken) => __awaiter(void 0, void 0, void 0, function* () {
32
+ const createEmailHandler = (environmentId, embeddedWalletSessionKeys) => (email, captchaToken) => __awaiter(void 0, void 0, void 0, function* () {
33
33
  const createEmailVerificationResponse = yield createEmailVerification({
34
34
  captchaToken,
35
35
  email,
36
36
  environmentId,
37
37
  });
38
- let { verificationUUID } = createEmailVerificationResponse;
39
- return {
40
- retry: () => __awaiter(void 0, void 0, void 0, function* () {
41
- const retryEmailVerificationResponse = yield retryEmailVerification({
42
- email,
43
- environmentId,
44
- verificationUUID,
45
- });
46
- // eslint-disable-next-line prefer-destructuring
47
- verificationUUID = retryEmailVerificationResponse.verificationUUID;
48
- }),
38
+ const { verificationUUID } = createEmailVerificationResponse;
39
+ persistOtpVerificationState({
40
+ captchaToken,
41
+ destination: email,
49
42
  type: 'email',
50
- verify: (oneTimePassword, options) => __awaiter(void 0, void 0, void 0, function* () {
51
- let sessionPublicKey = undefined;
52
- if (shouldRegisterSessionKeysOnSignin()) {
53
- const keypair = yield generateSessionKey();
54
- sessionPublicKey = keypair.publicKey;
55
- }
56
- yield generateSessionKeys();
57
- const response = yield signInWithEmailVerification({
58
- captchaToken,
59
- environmentId,
60
- sessionPublicKey,
61
- verificationToken: oneTimePassword,
62
- verificationUUID,
63
- });
64
- // Skip setting the user auth token and only return the VerifyResponse
65
- // if needed because setUser can trigger view re-renders.
66
- if (!(options === null || options === void 0 ? void 0 : options.skipSetUserAndAuthToken)) {
67
- storeTokenAndUser(response);
68
- }
69
- return {
70
- destination: email,
71
- response: response,
72
- verified: true,
73
- };
74
- }),
75
- };
43
+ verificationUUID,
44
+ });
45
+ return buildEmailOtpHandler({
46
+ captchaToken,
47
+ email,
48
+ embeddedWalletSessionKeys,
49
+ environmentId,
50
+ initialVerificationUUID: verificationUUID,
51
+ });
76
52
  });
77
53
 
78
54
  export { createEmailHandler };
@@ -4,12 +4,12 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var _tslib = require('../../../../../_virtual/_tslib.cjs');
7
- require('@dynamic-labs-sdk/client/core');
7
+ require('@dynamic-labs-sdk/client');
8
+ require('@dynamic-labs/utils');
8
9
  require('@dynamic-labs/sdk-api-core');
10
+ require('@dynamic-labs-sdk/client/core');
9
11
  require('react');
10
12
  require('eventemitter3');
11
- require('@dynamic-labs/utils');
12
- require('@dynamic-labs-sdk/client');
13
13
  require('../../../config/ApiEndpoint.cjs');
14
14
  require('@dynamic-labs/iconic');
15
15
  require('@dynamic-labs/wallet-connector-core');
@@ -23,16 +23,16 @@ require('../../../shared/consts/index.cjs');
23
23
  require('@dynamic-labs/multi-wallet');
24
24
  require('react-international-phone');
25
25
  require('../../../store/state/nonce/nonce.cjs');
26
- var sms = require('../../../data/api/sms/sms.cjs');
27
26
  require('../../../store/state/dynamicContextProps/dynamicContextProps.cjs');
28
27
  require('../../../store/state/primaryWalletId/primaryWalletId.cjs');
29
28
  require('../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
30
29
  require('../../../utils/functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.cjs');
31
30
  require('../../../events/dynamicEvents.cjs');
32
- var storeTokenAndUser = require('../../../client/extension/storeTokenAndUser/storeTokenAndUser.cjs');
33
- var generateSessionKeys = require('../../../client/extension/functions/generateSessionKeys/generateSessionKeys.cjs');
31
+ var sms = require('../../../data/api/sms/sms.cjs');
32
+ var buildSmsOtpHandler = require('./buildSmsOtpHandler/buildSmsOtpHandler.cjs');
33
+ var otpVerificationStorage = require('./otpVerificationStorage/otpVerificationStorage.cjs');
34
34
 
35
- const createSmsHandler = (environmentId, { shouldRegisterSessionKeysOnSignin, generateSessionKey, }) => (phone, captchaToken) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
35
+ const createSmsHandler = (environmentId, embeddedWalletSessionKeys) => (phone, captchaToken) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
36
36
  const { verificationUUID } = yield sms.createSmsVerification({
37
37
  captchaToken,
38
38
  environmentId,
@@ -40,34 +40,19 @@ const createSmsHandler = (environmentId, { shouldRegisterSessionKeysOnSignin, ge
40
40
  phoneCountryCode: phone.dialCode,
41
41
  phoneNumber: phone.phone,
42
42
  });
43
- return {
43
+ otpVerificationStorage.persistOtpVerificationState({
44
+ captchaToken,
45
+ destination: phone,
44
46
  type: 'sms',
45
- verify: (oneTimePassword, options) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
46
- let sessionPublicKey = undefined;
47
- if (shouldRegisterSessionKeysOnSignin()) {
48
- const keypair = yield generateSessionKey();
49
- sessionPublicKey = keypair.publicKey;
50
- }
51
- yield generateSessionKeys.generateSessionKeys();
52
- const response = yield sms.signInWithSmsVerification({
53
- captchaToken,
54
- environmentId,
55
- sessionPublicKey,
56
- verificationToken: oneTimePassword,
57
- verificationUUID,
58
- });
59
- // Skip setting the user auth token and only return the VerifyResponse
60
- // if needed because setUser can trigger view re-renders.
61
- if (!(options === null || options === void 0 ? void 0 : options.skipSetUserAndAuthToken)) {
62
- storeTokenAndUser.storeTokenAndUser(response);
63
- }
64
- return {
65
- destination: phone,
66
- response: response,
67
- verified: true,
68
- };
69
- }),
70
- };
47
+ verificationUUID,
48
+ });
49
+ return buildSmsOtpHandler.buildSmsOtpHandler({
50
+ captchaToken,
51
+ embeddedWalletSessionKeys,
52
+ environmentId,
53
+ phone,
54
+ verificationUUID,
55
+ });
71
56
  });
72
57
 
73
58
  exports.createSmsHandler = createSmsHandler;
@@ -1,4 +1,4 @@
1
1
  import { PhoneData } from '@dynamic-labs/types';
2
2
  import { useEmbeddedWalletSessionKeys } from '../../../utils/hooks';
3
3
  import { ProviderHandler } from '../types';
4
- export declare const createSmsHandler: (environmentId: string, { shouldRegisterSessionKeysOnSignin, generateSessionKey, }: ReturnType<typeof useEmbeddedWalletSessionKeys>) => ProviderHandler<PhoneData>;
4
+ export declare const createSmsHandler: (environmentId: string, embeddedWalletSessionKeys: ReturnType<typeof useEmbeddedWalletSessionKeys>) => ProviderHandler<PhoneData>;
@@ -1,11 +1,11 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../../../../_virtual/_tslib.js';
3
- import '@dynamic-labs-sdk/client/core';
3
+ import '@dynamic-labs-sdk/client';
4
+ import '@dynamic-labs/utils';
4
5
  import '@dynamic-labs/sdk-api-core';
6
+ import '@dynamic-labs-sdk/client/core';
5
7
  import 'react';
6
8
  import 'eventemitter3';
7
- import '@dynamic-labs/utils';
8
- import '@dynamic-labs-sdk/client';
9
9
  import '../../../config/ApiEndpoint.js';
10
10
  import '@dynamic-labs/iconic';
11
11
  import '@dynamic-labs/wallet-connector-core';
@@ -19,16 +19,16 @@ import '../../../shared/consts/index.js';
19
19
  import '@dynamic-labs/multi-wallet';
20
20
  import 'react-international-phone';
21
21
  import '../../../store/state/nonce/nonce.js';
22
- import { createSmsVerification, signInWithSmsVerification } from '../../../data/api/sms/sms.js';
23
22
  import '../../../store/state/dynamicContextProps/dynamicContextProps.js';
24
23
  import '../../../store/state/primaryWalletId/primaryWalletId.js';
25
24
  import '../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
26
25
  import '../../../utils/functions/getWaasAddressTypeLabel/getWaasAddressTypeLabel.js';
27
26
  import '../../../events/dynamicEvents.js';
28
- import { storeTokenAndUser } from '../../../client/extension/storeTokenAndUser/storeTokenAndUser.js';
29
- import { generateSessionKeys } from '../../../client/extension/functions/generateSessionKeys/generateSessionKeys.js';
27
+ import { createSmsVerification } from '../../../data/api/sms/sms.js';
28
+ import { buildSmsOtpHandler } from './buildSmsOtpHandler/buildSmsOtpHandler.js';
29
+ import { persistOtpVerificationState } from './otpVerificationStorage/otpVerificationStorage.js';
30
30
 
31
- const createSmsHandler = (environmentId, { shouldRegisterSessionKeysOnSignin, generateSessionKey, }) => (phone, captchaToken) => __awaiter(void 0, void 0, void 0, function* () {
31
+ const createSmsHandler = (environmentId, embeddedWalletSessionKeys) => (phone, captchaToken) => __awaiter(void 0, void 0, void 0, function* () {
32
32
  const { verificationUUID } = yield createSmsVerification({
33
33
  captchaToken,
34
34
  environmentId,
@@ -36,34 +36,19 @@ const createSmsHandler = (environmentId, { shouldRegisterSessionKeysOnSignin, ge
36
36
  phoneCountryCode: phone.dialCode,
37
37
  phoneNumber: phone.phone,
38
38
  });
39
- return {
39
+ persistOtpVerificationState({
40
+ captchaToken,
41
+ destination: phone,
40
42
  type: 'sms',
41
- verify: (oneTimePassword, options) => __awaiter(void 0, void 0, void 0, function* () {
42
- let sessionPublicKey = undefined;
43
- if (shouldRegisterSessionKeysOnSignin()) {
44
- const keypair = yield generateSessionKey();
45
- sessionPublicKey = keypair.publicKey;
46
- }
47
- yield generateSessionKeys();
48
- const response = yield signInWithSmsVerification({
49
- captchaToken,
50
- environmentId,
51
- sessionPublicKey,
52
- verificationToken: oneTimePassword,
53
- verificationUUID,
54
- });
55
- // Skip setting the user auth token and only return the VerifyResponse
56
- // if needed because setUser can trigger view re-renders.
57
- if (!(options === null || options === void 0 ? void 0 : options.skipSetUserAndAuthToken)) {
58
- storeTokenAndUser(response);
59
- }
60
- return {
61
- destination: phone,
62
- response: response,
63
- verified: true,
64
- };
65
- }),
66
- };
43
+ verificationUUID,
44
+ });
45
+ return buildSmsOtpHandler({
46
+ captchaToken,
47
+ embeddedWalletSessionKeys,
48
+ environmentId,
49
+ phone,
50
+ verificationUUID,
51
+ });
67
52
  });
68
53
 
69
54
  export { createSmsHandler };
@@ -0,0 +1,2 @@
1
+ export { clearOtpVerificationState, persistOtpVerificationState, restoreOtpVerificationState, } from './otpVerificationStorage';
2
+ export type { PersistedOtpState } from './otpVerificationStorage';
@@ -0,0 +1,60 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var utils = require('@dynamic-labs/utils');
7
+
8
+ const STORAGE_KEY = 'dynamic_otp_verification_state';
9
+ // 5 minutes in milliseconds — matches the backend OTP expiry window.
10
+ const OTP_STATE_TTL_MS = 5 * 60 * 1000;
11
+ /**
12
+ * Persists OTP verification state to localStorage so it can survive
13
+ * webview remounts (e.g. Android WebView process kills on low-memory devices).
14
+ */
15
+ const persistOtpVerificationState = (state) => {
16
+ try {
17
+ const payload = Object.assign(Object.assign({}, state), { createdAt: Date.now() });
18
+ utils.StorageService.setItem(STORAGE_KEY, payload);
19
+ }
20
+ catch (_a) {
21
+ // Storage may not be available in all environments
22
+ }
23
+ };
24
+ /**
25
+ * Restores previously persisted OTP verification state, if any.
26
+ * Returns null when nothing is stored or storage is unavailable.
27
+ */
28
+ const restoreOtpVerificationState = () => {
29
+ var _a;
30
+ try {
31
+ const parsed = (_a = utils.StorageService.getItem(STORAGE_KEY)) !== null && _a !== void 0 ? _a : null;
32
+ if (!parsed) {
33
+ return null;
34
+ }
35
+ if (parsed.createdAt && Date.now() - parsed.createdAt > OTP_STATE_TTL_MS) {
36
+ utils.StorageService.removeItem(STORAGE_KEY);
37
+ return null;
38
+ }
39
+ return parsed;
40
+ }
41
+ catch (_b) {
42
+ return null;
43
+ }
44
+ };
45
+ /**
46
+ * Clears any persisted OTP verification state from localStorage.
47
+ * Called after successful verification or when starting a new OTP flow.
48
+ */
49
+ const clearOtpVerificationState = () => {
50
+ try {
51
+ utils.StorageService.removeItem(STORAGE_KEY);
52
+ }
53
+ catch (_a) {
54
+ // ignore
55
+ }
56
+ };
57
+
58
+ exports.clearOtpVerificationState = clearOtpVerificationState;
59
+ exports.persistOtpVerificationState = persistOtpVerificationState;
60
+ exports.restoreOtpVerificationState = restoreOtpVerificationState;
@@ -0,0 +1,30 @@
1
+ import { PhoneData } from '@dynamic-labs/types';
2
+ type PersistedEmailOtpState = {
3
+ type: 'email';
4
+ verificationUUID: string;
5
+ destination: string;
6
+ captchaToken?: string;
7
+ };
8
+ type PersistedSmsOtpState = {
9
+ type: 'sms';
10
+ verificationUUID: string;
11
+ destination: PhoneData;
12
+ captchaToken?: string;
13
+ };
14
+ export type PersistedOtpState = PersistedEmailOtpState | PersistedSmsOtpState;
15
+ /**
16
+ * Persists OTP verification state to localStorage so it can survive
17
+ * webview remounts (e.g. Android WebView process kills on low-memory devices).
18
+ */
19
+ export declare const persistOtpVerificationState: (state: PersistedOtpState) => void;
20
+ /**
21
+ * Restores previously persisted OTP verification state, if any.
22
+ * Returns null when nothing is stored or storage is unavailable.
23
+ */
24
+ export declare const restoreOtpVerificationState: () => PersistedOtpState | null;
25
+ /**
26
+ * Clears any persisted OTP verification state from localStorage.
27
+ * Called after successful verification or when starting a new OTP flow.
28
+ */
29
+ export declare const clearOtpVerificationState: () => void;
30
+ export {};
@@ -0,0 +1,54 @@
1
+ 'use client'
2
+ import { StorageService } from '@dynamic-labs/utils';
3
+
4
+ const STORAGE_KEY = 'dynamic_otp_verification_state';
5
+ // 5 minutes in milliseconds — matches the backend OTP expiry window.
6
+ const OTP_STATE_TTL_MS = 5 * 60 * 1000;
7
+ /**
8
+ * Persists OTP verification state to localStorage so it can survive
9
+ * webview remounts (e.g. Android WebView process kills on low-memory devices).
10
+ */
11
+ const persistOtpVerificationState = (state) => {
12
+ try {
13
+ const payload = Object.assign(Object.assign({}, state), { createdAt: Date.now() });
14
+ StorageService.setItem(STORAGE_KEY, payload);
15
+ }
16
+ catch (_a) {
17
+ // Storage may not be available in all environments
18
+ }
19
+ };
20
+ /**
21
+ * Restores previously persisted OTP verification state, if any.
22
+ * Returns null when nothing is stored or storage is unavailable.
23
+ */
24
+ const restoreOtpVerificationState = () => {
25
+ var _a;
26
+ try {
27
+ const parsed = (_a = StorageService.getItem(STORAGE_KEY)) !== null && _a !== void 0 ? _a : null;
28
+ if (!parsed) {
29
+ return null;
30
+ }
31
+ if (parsed.createdAt && Date.now() - parsed.createdAt > OTP_STATE_TTL_MS) {
32
+ StorageService.removeItem(STORAGE_KEY);
33
+ return null;
34
+ }
35
+ return parsed;
36
+ }
37
+ catch (_b) {
38
+ return null;
39
+ }
40
+ };
41
+ /**
42
+ * Clears any persisted OTP verification state from localStorage.
43
+ * Called after successful verification or when starting a new OTP flow.
44
+ */
45
+ const clearOtpVerificationState = () => {
46
+ try {
47
+ StorageService.removeItem(STORAGE_KEY);
48
+ }
49
+ catch (_a) {
50
+ // ignore
51
+ }
52
+ };
53
+
54
+ export { clearOtpVerificationState, persistOtpVerificationState, restoreOtpVerificationState };
@@ -40,6 +40,12 @@ const useCreateWalletConnectorOptions = (_a) => {
40
40
  const redirectUrl = settingsUtils.useRedirectUrl();
41
41
  const walletConnectorsKey = React.useMemo(() => { var _a; return (_a = serializeWalletConnectors.serializeWalletConnectors(walletConnectorsProp)) === null || _a === void 0 ? void 0 : _a.join(','); }, [walletConnectorsProp]);
42
42
  const isWalletBookLoaded = React.useMemo(() => walletBook.isWalletBookPopulated(walletBook$1), [walletBook$1]);
43
+ // networkConfigurations can get a fresh object identity on every render even when
44
+ // its content is unchanged (e.g. built inline upstream, churned by a host-app
45
+ // re-render storm). Depending on a stable content signature instead of the object
46
+ // reference keeps a render storm from rebuilding the (potentially 100s-strong)
47
+ // connector list every frame — mirrors walletConnectorsKey above.
48
+ const networkConfigurationsKey = React.useMemo(() => JSON.stringify(networkConfigurations !== null && networkConfigurations !== void 0 ? networkConfigurations : {}), [networkConfigurations]);
43
49
  const walletConnectorOptions = React.useMemo(() => {
44
50
  if (!projectSettings || !isWalletBookLoaded || !networkConfigurations)
45
51
  return [];
@@ -48,14 +54,16 @@ const useCreateWalletConnectorOptions = (_a) => {
48
54
  redirectUrl, settings: projectSettings, skipMemo: true, walletBook: walletBook$1, walletConnectorsProp: walletConnectorsProp !== null && walletConnectorsProp !== void 0 ? walletConnectorsProp : [] }, props),
49
55
  walletConnectorExtensions,
50
56
  });
51
- // Cannot include walletUiUtils in the dependency array because it will cause an infinite loop
57
+ // walletUiUtils is intentionally excluded (its unstable identity would cause an
58
+ // infinite loop); networkConfigurations is depended on via its content signature
59
+ // (networkConfigurationsKey) so an identity-only churn doesn't rebuild the list.
52
60
  // eslint-disable-next-line react-hooks/exhaustive-deps
53
61
  }, [
54
62
  projectSettings,
55
63
  redirectUrl,
56
64
  walletConnectorsKey,
57
65
  isWalletBookLoaded,
58
- networkConfigurations,
66
+ networkConfigurationsKey,
59
67
  ]);
60
68
  React.useEffect(() => {
61
69
  if (!projectSettings || walletConnectorOptions.length === 0)
@@ -36,6 +36,12 @@ const useCreateWalletConnectorOptions = (_a) => {
36
36
  const redirectUrl = useRedirectUrl();
37
37
  const walletConnectorsKey = useMemo(() => { var _a; return (_a = serializeWalletConnectors(walletConnectorsProp)) === null || _a === void 0 ? void 0 : _a.join(','); }, [walletConnectorsProp]);
38
38
  const isWalletBookLoaded = useMemo(() => isWalletBookPopulated(walletBook), [walletBook]);
39
+ // networkConfigurations can get a fresh object identity on every render even when
40
+ // its content is unchanged (e.g. built inline upstream, churned by a host-app
41
+ // re-render storm). Depending on a stable content signature instead of the object
42
+ // reference keeps a render storm from rebuilding the (potentially 100s-strong)
43
+ // connector list every frame — mirrors walletConnectorsKey above.
44
+ const networkConfigurationsKey = useMemo(() => JSON.stringify(networkConfigurations !== null && networkConfigurations !== void 0 ? networkConfigurations : {}), [networkConfigurations]);
39
45
  const walletConnectorOptions = useMemo(() => {
40
46
  if (!projectSettings || !isWalletBookLoaded || !networkConfigurations)
41
47
  return [];
@@ -44,14 +50,16 @@ const useCreateWalletConnectorOptions = (_a) => {
44
50
  redirectUrl, settings: projectSettings, skipMemo: true, walletBook, walletConnectorsProp: walletConnectorsProp !== null && walletConnectorsProp !== void 0 ? walletConnectorsProp : [] }, props),
45
51
  walletConnectorExtensions,
46
52
  });
47
- // Cannot include walletUiUtils in the dependency array because it will cause an infinite loop
53
+ // walletUiUtils is intentionally excluded (its unstable identity would cause an
54
+ // infinite loop); networkConfigurations is depended on via its content signature
55
+ // (networkConfigurationsKey) so an identity-only churn doesn't rebuild the list.
48
56
  // eslint-disable-next-line react-hooks/exhaustive-deps
49
57
  }, [
50
58
  projectSettings,
51
59
  redirectUrl,
52
60
  walletConnectorsKey,
53
61
  isWalletBookLoaded,
54
- networkConfigurations,
62
+ networkConfigurationsKey,
55
63
  ]);
56
64
  useEffect(() => {
57
65
  if (!projectSettings || walletConnectorOptions.length === 0)