@dynamic-labs/sdk-react-core 1.1.0-alpha.4 → 1.1.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +10 -10
- package/src/index.cjs +14 -0
- package/src/index.d.ts +1 -1
- package/src/index.js +7 -0
- package/src/lib/components/index.d.ts +1 -0
- package/src/lib/context/ViewContext/ViewContext.d.ts +1 -1
- package/src/lib/data/api.cjs +15 -0
- package/src/lib/data/api.d.ts +7 -1
- package/src/lib/data/api.js +15 -1
- package/src/lib/events/dynamicEvents.d.ts +2 -0
- package/src/lib/layout/DynamicUserProfileLayout/DynamicUserProfileLayout.cjs +1 -0
- package/src/lib/layout/DynamicUserProfileLayout/DynamicUserProfileLayout.js +2 -1
- package/src/lib/locale/en/translation.cjs +71 -1
- package/src/lib/locale/en/translation.d.ts +70 -0
- package/src/lib/locale/en/translation.js +71 -1
- package/src/lib/shared/assets/alt-embedded-wallet.cjs +54 -0
- package/src/lib/shared/assets/alt-embedded-wallet.js +30 -0
- package/src/lib/shared/assets/export-embedded-hero.cjs +90 -0
- package/src/lib/shared/assets/export-embedded-hero.js +66 -0
- package/src/lib/shared/assets/eye-off-icon.cjs +53 -0
- package/src/lib/shared/assets/eye-off-icon.js +29 -0
- package/src/lib/shared/assets/face-id.cjs +53 -0
- package/src/lib/shared/assets/face-id.js +29 -0
- package/src/lib/shared/assets/index.d.ts +6 -0
- package/src/lib/shared/assets/lock.cjs +54 -0
- package/src/lib/shared/assets/lock.js +30 -0
- package/src/lib/shared/assets/wallet-v2.cjs +53 -0
- package/src/lib/shared/assets/wallet-v2.js +29 -0
- package/src/lib/styles/index.shadow.cjs +1 -1
- package/src/lib/styles/index.shadow.js +1 -1
- package/src/lib/utils/hooks/authenticationHooks/useEmailVerificationRequest/useEmailVerificationRequest.cjs +28 -1
- package/src/lib/utils/hooks/authenticationHooks/useEmailVerificationRequest/useEmailVerificationRequest.js +28 -1
- package/src/lib/utils/hooks/index.d.ts +1 -0
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.cjs +2 -1
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js +2 -1
- package/src/lib/utils/hooks/useEmbeddedReveal/index.d.ts +1 -0
- package/src/lib/utils/hooks/useEmbeddedReveal/useEmbeddedReveal.cjs +60 -0
- package/src/lib/utils/hooks/useEmbeddedReveal/useEmbeddedReveal.d.ts +4 -0
- package/src/lib/utils/hooks/useEmbeddedReveal/useEmbeddedReveal.js +56 -0
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.cjs +3 -0
- package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.js +3 -0
- package/src/lib/utils/hooks/useIsLoggedIn/useIsLoggedIn.cjs +2 -27
- package/src/lib/utils/hooks/useIsLoggedIn/useIsLoggedIn.js +2 -27
- package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.cjs +20 -14
- package/src/lib/utils/hooks/useSocialAuth/useSocialAuth.js +20 -14
- package/src/lib/utils/hooks/useUserUpdateRequest/useUpdateUser/useUpdateUser.cjs +26 -4
- package/src/lib/utils/hooks/useUserUpdateRequest/useUpdateUser/useUpdateUser.js +26 -4
- package/src/lib/views/EmailVerification/EmailVerification.cjs +34 -23
- package/src/lib/views/EmailVerification/EmailVerification.js +34 -23
- package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.cjs +158 -0
- package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.d.ts +2 -0
- package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/EmbeddedRevealView.js +154 -0
- package/src/lib/views/EmbeddedReveal/EmbeddedRevealView/index.d.ts +1 -0
- package/src/lib/views/EmbeddedReveal/constants.cjs +9 -0
- package/src/lib/views/EmbeddedReveal/constants.d.ts +2 -0
- package/src/lib/views/EmbeddedReveal/constants.js +4 -0
- package/src/lib/views/EmbeddedReveal/index.d.ts +1 -0
- package/src/lib/views/EmbeddedReveal/utils/turnkeyExport/index.d.ts +1 -0
- package/src/lib/views/EmbeddedReveal/utils/turnkeyExport/turnkeyExport.cjs +114 -0
- package/src/lib/views/EmbeddedReveal/utils/turnkeyExport/turnkeyExport.d.ts +15 -0
- package/src/lib/views/EmbeddedReveal/utils/turnkeyExport/turnkeyExport.js +108 -0
- package/src/lib/views/Passkey/PasskeyRecovery/InitRecovery/PasskeyInitRecovery.cjs +2 -2
- package/src/lib/views/Passkey/PasskeyRecovery/InitRecovery/PasskeyInitRecovery.js +2 -2
- package/src/lib/views/Passkey/utils/passkeyRecovery/passkeyRecovery.cjs +2 -2
- package/src/lib/views/Passkey/utils/passkeyRecovery/passkeyRecovery.d.ts +2 -2
- package/src/lib/views/Passkey/utils/passkeyRecovery/passkeyRecovery.js +2 -2
- package/src/lib/views/viewToComponentMap.cjs +2 -0
- package/src/lib/views/viewToComponentMap.js +2 -0
- package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletInformation.cjs +2 -2
- package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletInformation.js +2 -2
- package/src/lib/widgets/DynamicWidget/components/DynamicWidgetViews/DynamicWidgetViews.cjs +2 -0
- package/src/lib/widgets/DynamicWidget/components/DynamicWidgetViews/DynamicWidgetViews.js +2 -0
- package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.types.cjs +2 -0
- package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.types.d.ts +3 -1
- package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.types.js +2 -1
- package/src/lib/widgets/DynamicWidget/views/ManagePasskeysWidgetView/ManagePasskeysWidgetView.cjs +4 -4
- package/src/lib/widgets/DynamicWidget/views/ManagePasskeysWidgetView/ManagePasskeysWidgetView.js +4 -4
- package/src/lib/widgets/DynamicWidget/views/WalletSettingsView/WalletSettingsView.cjs +93 -0
- package/src/lib/widgets/DynamicWidget/views/WalletSettingsView/WalletSettingsView.d.ts +2 -0
- package/src/lib/widgets/DynamicWidget/views/WalletSettingsView/WalletSettingsView.js +89 -0
- package/src/lib/widgets/DynamicWidget/views/WalletSettingsView/index.d.ts +1 -0
- package/src/lib/widgets/DynamicWidget/views/index.d.ts +1 -0
|
@@ -24,6 +24,8 @@ import { useEffectOnce } from '../../shared/utils/hooks/useEffectOnce/useEffectO
|
|
|
24
24
|
import '../../shared/consts/index.js';
|
|
25
25
|
import '@dynamic-labs/multi-wallet';
|
|
26
26
|
import '@dynamic-labs/sdk-api';
|
|
27
|
+
import { isTurnkeyEnabled } from '../../utils/functions/isTurnkeyEnabled/isTurnkeyEnabled.js';
|
|
28
|
+
import { storeAuthToken } from '../../utils/functions/storeAuthToken/index.js';
|
|
27
29
|
import '../../context/AccessDeniedContext/AccessDeniedContext.js';
|
|
28
30
|
import { useAccountExistsContext } from '../../context/AccountExistsContext/AccountExistsContext.js';
|
|
29
31
|
import { signInWithEmailVerification, retryEmailVerification } from '../../data/api.js';
|
|
@@ -97,6 +99,7 @@ const EmailVerification = () => {
|
|
|
97
99
|
const { loading, setLoading } = useLoadingContext();
|
|
98
100
|
const { t } = useTranslation();
|
|
99
101
|
const { createEmbeddedWallet } = useEmbeddedWallet();
|
|
102
|
+
const isTurnkeyProviderEnabled = isTurnkeyEnabled(projectSettings);
|
|
100
103
|
const { remainingSeconds, startCountdown } = useCountdown({
|
|
101
104
|
callback: () => setRetried(false),
|
|
102
105
|
seconds: SECONDS_TO_RETRY,
|
|
@@ -126,7 +129,7 @@ const EmailVerification = () => {
|
|
|
126
129
|
return;
|
|
127
130
|
}
|
|
128
131
|
try {
|
|
129
|
-
const { nextView } = yield verifyEmail(verificationToken, verificationUUID);
|
|
132
|
+
const { nextView, jwt } = yield verifyEmail(verificationToken, verificationUUID);
|
|
130
133
|
if (onboardingOnlyJwt) {
|
|
131
134
|
setOnboardingOnlyJwt(undefined);
|
|
132
135
|
setCallback('authSuccess');
|
|
@@ -135,18 +138,20 @@ const EmailVerification = () => {
|
|
|
135
138
|
if (nextView === 'verified-and-transferred') {
|
|
136
139
|
setShowTransferMessage(true);
|
|
137
140
|
}
|
|
138
|
-
if (
|
|
139
|
-
|
|
141
|
+
if (isTurnkeyProviderEnabled &&
|
|
142
|
+
((_c = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _c === void 0 ? void 0 : _c.automaticEmbeddedWalletCreation)) {
|
|
143
|
+
try {
|
|
144
|
+
storeAuthToken(jwt);
|
|
145
|
+
// this function will check turnkey wallet enabled and create wallet if needed
|
|
146
|
+
// if not enabled, it will throw an error.
|
|
147
|
+
yield createEmbeddedWallet();
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
setShowAuthFlow(false);
|
|
151
|
+
}
|
|
140
152
|
return;
|
|
141
153
|
}
|
|
142
|
-
|
|
143
|
-
// this function will check turnkey wallet enabled and create wallet if needed
|
|
144
|
-
// if not enabled, it will throw an error.
|
|
145
|
-
yield createEmbeddedWallet();
|
|
146
|
-
}
|
|
147
|
-
catch (e) {
|
|
148
|
-
setShowAuthFlow(false);
|
|
149
|
-
}
|
|
154
|
+
setShowAuthFlow(false);
|
|
150
155
|
}
|
|
151
156
|
catch (error) {
|
|
152
157
|
logger.debug(error);
|
|
@@ -174,8 +179,8 @@ const EmailVerification = () => {
|
|
|
174
179
|
(_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _a === void 0 ? void 0 : _a.automaticEmbeddedWalletCreation,
|
|
175
180
|
createEmbeddedWallet,
|
|
176
181
|
setShowAuthFlow,
|
|
177
|
-
setErrorMessage,
|
|
178
182
|
setView,
|
|
183
|
+
isTurnkeyProviderEnabled,
|
|
179
184
|
]);
|
|
180
185
|
const handleEmailLogin = useCallback((verificationToken) => __awaiter(void 0, void 0, void 0, function* () {
|
|
181
186
|
var _d;
|
|
@@ -208,19 +213,24 @@ const EmailVerification = () => {
|
|
|
208
213
|
setCallback('authSuccess');
|
|
209
214
|
// this timeout is set to make sure that the user will see success message
|
|
210
215
|
yield sleepToShowSuccessMessage();
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
216
|
+
if (isTurnkeyProviderEnabled &&
|
|
217
|
+
((_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _d === void 0 ? void 0 : _d.automaticEmbeddedWalletCreation)) {
|
|
218
|
+
try {
|
|
219
|
+
// Store the auth token in local storage so it can be used during embedded wallet creation
|
|
220
|
+
storeAuthToken(jwt);
|
|
221
|
+
// this function will check turnkey wallet enabled and create wallet if needed
|
|
222
|
+
// if not enabled, it will throw an error.
|
|
223
|
+
yield createEmbeddedWallet();
|
|
224
|
+
}
|
|
225
|
+
catch (e) {
|
|
226
|
+
yield createUserProfileByJWT(jwt);
|
|
227
|
+
setShowAuthFlow(false);
|
|
228
|
+
}
|
|
214
229
|
return;
|
|
215
230
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
yield createEmbeddedWallet();
|
|
220
|
-
}
|
|
221
|
-
catch (e) {
|
|
222
|
-
setShowAuthFlow(false);
|
|
223
|
-
}
|
|
231
|
+
// If not creating embedded wallet automatically, create user profile
|
|
232
|
+
yield createUserProfileByJWT(jwt);
|
|
233
|
+
setShowAuthFlow(false);
|
|
224
234
|
}
|
|
225
235
|
catch (error) {
|
|
226
236
|
if (error instanceof NoAccessError) {
|
|
@@ -252,6 +262,7 @@ const EmailVerification = () => {
|
|
|
252
262
|
setShowAuthFlow,
|
|
253
263
|
setErrorMessage,
|
|
254
264
|
setExistentAccountData,
|
|
265
|
+
isTurnkeyProviderEnabled,
|
|
255
266
|
]);
|
|
256
267
|
const handleRetry = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
257
268
|
try {
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('../../../../../_virtual/_tslib.cjs');
|
|
6
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var reactI18next = require('react-i18next');
|
|
9
|
+
var utils = require('@dynamic-labs/utils');
|
|
10
|
+
var getProperErrorMessage = require('../../../modals/SignMessageConfirmationModal/getProperErrorMessage.cjs');
|
|
11
|
+
var dynamicEvents = require('../../../events/dynamicEvents.cjs');
|
|
12
|
+
var useInternalDynamicContext = require('../../../context/DynamicContext/useInternalDynamicContext.cjs');
|
|
13
|
+
require('@dynamic-labs/wallet-connector-core');
|
|
14
|
+
require('../../../context/CaptchaContext/CaptchaContext.cjs');
|
|
15
|
+
require('../../../context/ErrorContext/ErrorContext.cjs');
|
|
16
|
+
require('../../../context/ViewContext/ViewContext.cjs');
|
|
17
|
+
var decodeJwt = require('../../../shared/utils/functions/decodeJwt/decodeJwt.cjs');
|
|
18
|
+
require('@dynamic-labs/iconic');
|
|
19
|
+
var close = require('../../../shared/assets/close.cjs');
|
|
20
|
+
var eyeOffIcon = require('../../../shared/assets/eye-off-icon.cjs');
|
|
21
|
+
var exportEmbeddedHero = require('../../../shared/assets/export-embedded-hero.cjs');
|
|
22
|
+
var walletV2 = require('../../../shared/assets/wallet-v2.cjs');
|
|
23
|
+
var logger = require('../../../shared/logger.cjs');
|
|
24
|
+
require('@dynamic-labs/wallet-book');
|
|
25
|
+
require('../../../utils/constants/colors.cjs');
|
|
26
|
+
require('../../../shared/utils/classes/storage/localStorage.cjs');
|
|
27
|
+
require('viem');
|
|
28
|
+
require('../../../shared/consts/index.cjs');
|
|
29
|
+
require('@dynamic-labs/multi-wallet');
|
|
30
|
+
require('@dynamic-labs/sdk-api');
|
|
31
|
+
require('../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
|
|
32
|
+
require('../../../context/AccountExistsContext/AccountExistsContext.cjs');
|
|
33
|
+
require('../../../config/ApiEndpoint.cjs');
|
|
34
|
+
require('../../../context/EmailVerificationContext/EmailVerificationContext.cjs');
|
|
35
|
+
require('react-dom');
|
|
36
|
+
require('../../../context/ThemeContext/ThemeContext.cjs');
|
|
37
|
+
var useMutation = require('../../../utils/hooks/useMutation/useMutation.cjs');
|
|
38
|
+
require('@dynamic-labs/types');
|
|
39
|
+
require('yup');
|
|
40
|
+
require('../../../context/MockContext/MockContext.cjs');
|
|
41
|
+
require('../../../utils/hooks/useUserUpdateRequest/useUpdateUser/useUpdateUser.cjs');
|
|
42
|
+
require('../../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
|
|
43
|
+
require('@dynamic-labs/rpc-providers');
|
|
44
|
+
require('../../../context/UserWalletsContext/UserWalletsContext.cjs');
|
|
45
|
+
require('../../../components/Transition/ZoomTransition/ZoomTransition.cjs');
|
|
46
|
+
require('../../../components/Transition/SlideInUpTransition/SlideInUpTransition.cjs');
|
|
47
|
+
require('../../../components/Transition/OpacityTransition/OpacityTransition.cjs');
|
|
48
|
+
require('../../../components/ShadowDOM/ShadowDOM.cjs');
|
|
49
|
+
require('../../../components/OverlayCard/OverlayCard.context.cjs');
|
|
50
|
+
require('../../../context/FooterAnimationContext/index.cjs');
|
|
51
|
+
require('../../../context/QrCodeContext/QrCodeContext.cjs');
|
|
52
|
+
var Typography = require('../../../components/Typography/Typography.cjs');
|
|
53
|
+
var Badge = require('../../../components/Badge/Badge.cjs');
|
|
54
|
+
require('../../../context/WalletGroupContext/WalletGroupContext.cjs');
|
|
55
|
+
require('../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
|
|
56
|
+
require('qrcode');
|
|
57
|
+
require('../../../context/LoadingContext/LoadingContext.cjs');
|
|
58
|
+
require('i18next');
|
|
59
|
+
require('../../../widgets/DynamicWidget/context/DynamicWidgetContext.cjs');
|
|
60
|
+
var ErrorContainer = require('../../../components/ErrorContainer/ErrorContainer.cjs');
|
|
61
|
+
require('../../../components/UserProfile/parts/UserProfileField/components/VerifiedEmailIcon/VerifiedEmailIcon.cjs');
|
|
62
|
+
require('formik');
|
|
63
|
+
var Button = require('../../../components/Button/Button.cjs');
|
|
64
|
+
var ModalHeader = require('../../../components/ModalHeader/ModalHeader.cjs');
|
|
65
|
+
var IconButton = require('../../../components/IconButton/IconButton.cjs');
|
|
66
|
+
require('../../../components/Alert/Alert.cjs');
|
|
67
|
+
require('@dynamic-labs/viem-utils');
|
|
68
|
+
require('../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.cjs');
|
|
69
|
+
var Checkbox = require('../../../components/Checkbox/Checkbox.cjs');
|
|
70
|
+
require('../../../components/InlineWidget/InlineWidget.cjs');
|
|
71
|
+
require('../../../components/MenuList/Dropdown/Dropdown.cjs');
|
|
72
|
+
require('../../../components/Popper/Popper/Popper.cjs');
|
|
73
|
+
require('../../../components/Popper/PopperContext/PopperContext.cjs');
|
|
74
|
+
require('react-focus-lock');
|
|
75
|
+
var turnkeyExport = require('../utils/turnkeyExport/turnkeyExport.cjs');
|
|
76
|
+
var constants = require('../constants.cjs');
|
|
77
|
+
|
|
78
|
+
const EmbeddedRevealView = () => {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
const { authToken, primaryWallet, user, setShowAuthFlow, environmentId } = useInternalDynamicContext.useInternalDynamicContext();
|
|
81
|
+
const [acknowledgement1, setAcknowledgement1] = React.useState(false);
|
|
82
|
+
const iframeContainerRef = React.useRef(null);
|
|
83
|
+
const decodedJwt = decodeJwt.decodeJwt(authToken);
|
|
84
|
+
const walletProperties = (_b = (_a = decodedJwt === null || decodedJwt === void 0 ? void 0 : decodedJwt.verifiedCredentials) === null || _a === void 0 ? void 0 : _a.find(({ walletName }) => walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey'))) === null || _b === void 0 ? void 0 : _b.walletProperties;
|
|
85
|
+
const isTurnkeyHDWallet = walletProperties === null || walletProperties === void 0 ? void 0 : walletProperties.turnkeyHDWalletId;
|
|
86
|
+
React.useEffect(() => {
|
|
87
|
+
const iframeContainerElement = iframeContainerRef.current;
|
|
88
|
+
if (!iframeContainerElement) {
|
|
89
|
+
throw new utils.DynamicError('Missing iframe container');
|
|
90
|
+
}
|
|
91
|
+
if (iframeContainerElement.children.length > 0) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
turnkeyExport.initExport({
|
|
95
|
+
iframeContainer: iframeContainerElement,
|
|
96
|
+
iframeElementId: constants.iframeElementId,
|
|
97
|
+
wallet: primaryWallet,
|
|
98
|
+
});
|
|
99
|
+
return () => {
|
|
100
|
+
turnkeyExport.cleanupExport({
|
|
101
|
+
wallet: primaryWallet,
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
// only run once on mount
|
|
105
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
106
|
+
}, []);
|
|
107
|
+
const { mutate: handleExportWallet, isLoading, error, data, } = useMutation.useMutation(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
108
|
+
const iframeContainerElement = iframeContainerRef.current;
|
|
109
|
+
if (!iframeContainerElement) {
|
|
110
|
+
throw new utils.DynamicError('Missing iframe container');
|
|
111
|
+
}
|
|
112
|
+
return turnkeyExport.exportCredential({
|
|
113
|
+
authToken,
|
|
114
|
+
environmentId,
|
|
115
|
+
userEmail: user === null || user === void 0 ? void 0 : user.email,
|
|
116
|
+
wallet: primaryWallet,
|
|
117
|
+
});
|
|
118
|
+
}), {
|
|
119
|
+
onFailure: (err) => {
|
|
120
|
+
logger.logger.error('Failed to export', err);
|
|
121
|
+
dynamicEvents.dynamicEvents.emit('embeddedWalletRevealFailed', err);
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
const errorText = React.useMemo(() => {
|
|
125
|
+
if (!error) {
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
if (error instanceof utils.DynamicError) {
|
|
129
|
+
return error.message;
|
|
130
|
+
}
|
|
131
|
+
return getProperErrorMessage.getProperErrorMessage(error);
|
|
132
|
+
}, [error]);
|
|
133
|
+
const { t } = reactI18next.useTranslation();
|
|
134
|
+
const contentHeader = (jsxRuntime.jsx("div", { className: 'embedded-reveal-view__body__description', children: !isLoading && data && !error ? (jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', color: 'secondary', weight: 'regular', children: t('dyn_embedded_reveal.reveal_description') })) : (jsxRuntime.jsx("div", { className: 'embedded-reveal-view__header', children: jsxRuntime.jsx(exportEmbeddedHero.ReactComponent, {}) })) }));
|
|
135
|
+
React.useEffect(() => {
|
|
136
|
+
var _a;
|
|
137
|
+
if (((_a = iframeContainerRef === null || iframeContainerRef === void 0 ? void 0 : iframeContainerRef.current) === null || _a === void 0 ? void 0 : _a.children) && data) {
|
|
138
|
+
// eslint-disable-next-line prefer-destructuring
|
|
139
|
+
const iframeElement = iframeContainerRef.current.children[0];
|
|
140
|
+
iframeElement === null || iframeElement === void 0 ? void 0 : iframeElement.setAttribute('style', isTurnkeyHDWallet ? 'height: 100px' : 'height: 60px');
|
|
141
|
+
}
|
|
142
|
+
}, [iframeContainerRef, data, isTurnkeyHDWallet]);
|
|
143
|
+
const closeButton = (jsxRuntime.jsx(IconButton.IconButton, { onClick: () => setShowAuthFlow(false), type: 'button', children: jsxRuntime.jsx(close.ReactComponent, {}) }));
|
|
144
|
+
const hasInjectedCredential = !isLoading && data && !error;
|
|
145
|
+
const credentialTitle = isTurnkeyHDWallet
|
|
146
|
+
? t('dyn_embedded_reveal.recovery_phrase_title')
|
|
147
|
+
: t('dyn_embedded_reveal.private_key_title');
|
|
148
|
+
const title = hasInjectedCredential
|
|
149
|
+
? credentialTitle
|
|
150
|
+
: t('dyn_embedded_reveal.agreement_title');
|
|
151
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(ModalHeader.ModalHeader, { trailing: closeButton, children: jsxRuntime.jsx(Typography.Typography, { as: 'h1', variant: 'title', color: 'primary', "data-testid": 'dynamic-auth-modal-heading', className: 'header__typography', children: title }) }), jsxRuntime.jsx("div", { className: 'embedded-reveal-view', children: jsxRuntime.jsxs("div", { className: 'embedded-reveal-view__body', children: [contentHeader, jsxRuntime.jsx("div", { id: constants.iframeContainerId, style: { display: data ? 'block' : 'none' }, ref: iframeContainerRef }), hasInjectedCredential ? (jsxRuntime.jsx(Button.Button, { buttonPadding: 'large', buttonVariant: 'brand-primary', onClick: () => setShowAuthFlow(false), loading: isLoading, typographyProps: {
|
|
152
|
+
color: 'inherit',
|
|
153
|
+
}, children: t('dyn_embedded_reveal.done_button_label') })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", { className: 'embedded-reveal-view__body__description', children: jsxRuntime.jsx(Badge.Badge, { text: t('dyn_embedded_reveal.badge_label'), className: 'embedded-reveal-view__body__badge' }) }), errorText && jsxRuntime.jsx(ErrorContainer.ErrorContainer, { children: errorText }), jsxRuntime.jsxs("div", { className: 'embedded-reveal-view__body__card', children: [jsxRuntime.jsxs("div", { className: 'embedded-reveal-view__body__card__statement', children: [jsxRuntime.jsx("div", { className: 'embedded-reveal-view__body__card__icon', children: jsxRuntime.jsx(walletV2.ReactComponent, {}) }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', color: 'primary', style: { letterSpacing: '-0.15px' }, children: t('dyn_embedded_reveal.statement_1.title') }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', color: 'secondary', weight: 'regular', children: t('dyn_embedded_reveal.statement_1.description') })] })] }), jsxRuntime.jsxs("div", { className: 'embedded-reveal-view__body__card__statement', children: [jsxRuntime.jsx("div", { className: 'embedded-reveal-view__body__card__icon', children: jsxRuntime.jsx(eyeOffIcon.ReactComponent, {}) }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', color: 'primary', style: { letterSpacing: '-0.15px' }, children: t('dyn_embedded_reveal.statement_2.title') }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', color: 'secondary', weight: 'regular', children: t('dyn_embedded_reveal.statement_2.description') })] })] })] }), jsxRuntime.jsxs("div", { className: 'embedded-reveal-view__body__confirm_card', children: [jsxRuntime.jsxs("button", { className: 'embedded-reveal-view__body__card__acknowledgement', onClick: () => setAcknowledgement1(!acknowledgement1), children: [jsxRuntime.jsx("div", { children: jsxRuntime.jsx(Checkbox.Checkbox, { checked: acknowledgement1, onChange: () => setAcknowledgement1(!acknowledgement1), className: 'embedded-reveal-view__body__card__statement__checkbox', id: 'embedded-reveal-checkbox-1' }) }), jsxRuntime.jsx("div", { children: jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', color: 'primary', style: { letterSpacing: '-0.15px' }, children: t('dyn_embedded_reveal.checkbox_label') }) })] }), jsxRuntime.jsx(Button.Button, { buttonPadding: 'large', buttonVariant: 'brand-primary', typographyProps: {
|
|
154
|
+
color: 'inherit',
|
|
155
|
+
}, onClick: () => handleExportWallet(), disabled: !acknowledgement1, loading: isLoading, dataTestId: 'embedded-reveal-button', children: t('dyn_embedded_reveal.reveal_button_label') })] })] }))] }) })] }));
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
exports.EmbeddedRevealView = EmbeddedRevealView;
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
2
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
|
+
import { useState, useRef, useEffect, useMemo } from 'react';
|
|
4
|
+
import { useTranslation } from 'react-i18next';
|
|
5
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
6
|
+
import { getProperErrorMessage } from '../../../modals/SignMessageConfirmationModal/getProperErrorMessage.js';
|
|
7
|
+
import { dynamicEvents } from '../../../events/dynamicEvents.js';
|
|
8
|
+
import { useInternalDynamicContext } from '../../../context/DynamicContext/useInternalDynamicContext.js';
|
|
9
|
+
import '@dynamic-labs/wallet-connector-core';
|
|
10
|
+
import '../../../context/CaptchaContext/CaptchaContext.js';
|
|
11
|
+
import '../../../context/ErrorContext/ErrorContext.js';
|
|
12
|
+
import '../../../context/ViewContext/ViewContext.js';
|
|
13
|
+
import { decodeJwt } from '../../../shared/utils/functions/decodeJwt/decodeJwt.js';
|
|
14
|
+
import '@dynamic-labs/iconic';
|
|
15
|
+
import { ReactComponent as SvgClose } from '../../../shared/assets/close.js';
|
|
16
|
+
import { ReactComponent as SvgEyeOffIcon } from '../../../shared/assets/eye-off-icon.js';
|
|
17
|
+
import { ReactComponent as SvgExportEmbeddedHero } from '../../../shared/assets/export-embedded-hero.js';
|
|
18
|
+
import { ReactComponent as SvgWalletV2 } from '../../../shared/assets/wallet-v2.js';
|
|
19
|
+
import { logger } from '../../../shared/logger.js';
|
|
20
|
+
import '@dynamic-labs/wallet-book';
|
|
21
|
+
import '../../../utils/constants/colors.js';
|
|
22
|
+
import '../../../shared/utils/classes/storage/localStorage.js';
|
|
23
|
+
import 'viem';
|
|
24
|
+
import '../../../shared/consts/index.js';
|
|
25
|
+
import '@dynamic-labs/multi-wallet';
|
|
26
|
+
import '@dynamic-labs/sdk-api';
|
|
27
|
+
import '../../../context/AccessDeniedContext/AccessDeniedContext.js';
|
|
28
|
+
import '../../../context/AccountExistsContext/AccountExistsContext.js';
|
|
29
|
+
import '../../../config/ApiEndpoint.js';
|
|
30
|
+
import '../../../context/EmailVerificationContext/EmailVerificationContext.js';
|
|
31
|
+
import 'react-dom';
|
|
32
|
+
import '../../../context/ThemeContext/ThemeContext.js';
|
|
33
|
+
import { useMutation } from '../../../utils/hooks/useMutation/useMutation.js';
|
|
34
|
+
import '@dynamic-labs/types';
|
|
35
|
+
import 'yup';
|
|
36
|
+
import '../../../context/MockContext/MockContext.js';
|
|
37
|
+
import '../../../utils/hooks/useUserUpdateRequest/useUpdateUser/useUpdateUser.js';
|
|
38
|
+
import '../../../context/UserFieldEditorContext/UserFieldEditorContext.js';
|
|
39
|
+
import '@dynamic-labs/rpc-providers';
|
|
40
|
+
import '../../../context/UserWalletsContext/UserWalletsContext.js';
|
|
41
|
+
import '../../../components/Transition/ZoomTransition/ZoomTransition.js';
|
|
42
|
+
import '../../../components/Transition/SlideInUpTransition/SlideInUpTransition.js';
|
|
43
|
+
import '../../../components/Transition/OpacityTransition/OpacityTransition.js';
|
|
44
|
+
import '../../../components/ShadowDOM/ShadowDOM.js';
|
|
45
|
+
import '../../../components/OverlayCard/OverlayCard.context.js';
|
|
46
|
+
import '../../../context/FooterAnimationContext/index.js';
|
|
47
|
+
import '../../../context/QrCodeContext/QrCodeContext.js';
|
|
48
|
+
import { Typography } from '../../../components/Typography/Typography.js';
|
|
49
|
+
import { Badge } from '../../../components/Badge/Badge.js';
|
|
50
|
+
import '../../../context/WalletGroupContext/WalletGroupContext.js';
|
|
51
|
+
import '../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.js';
|
|
52
|
+
import 'qrcode';
|
|
53
|
+
import '../../../context/LoadingContext/LoadingContext.js';
|
|
54
|
+
import 'i18next';
|
|
55
|
+
import '../../../widgets/DynamicWidget/context/DynamicWidgetContext.js';
|
|
56
|
+
import { ErrorContainer } from '../../../components/ErrorContainer/ErrorContainer.js';
|
|
57
|
+
import '../../../components/UserProfile/parts/UserProfileField/components/VerifiedEmailIcon/VerifiedEmailIcon.js';
|
|
58
|
+
import 'formik';
|
|
59
|
+
import { Button } from '../../../components/Button/Button.js';
|
|
60
|
+
import { ModalHeader } from '../../../components/ModalHeader/ModalHeader.js';
|
|
61
|
+
import { IconButton } from '../../../components/IconButton/IconButton.js';
|
|
62
|
+
import '../../../components/Alert/Alert.js';
|
|
63
|
+
import '@dynamic-labs/viem-utils';
|
|
64
|
+
import '../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js';
|
|
65
|
+
import { Checkbox } from '../../../components/Checkbox/Checkbox.js';
|
|
66
|
+
import '../../../components/InlineWidget/InlineWidget.js';
|
|
67
|
+
import '../../../components/MenuList/Dropdown/Dropdown.js';
|
|
68
|
+
import '../../../components/Popper/Popper/Popper.js';
|
|
69
|
+
import '../../../components/Popper/PopperContext/PopperContext.js';
|
|
70
|
+
import 'react-focus-lock';
|
|
71
|
+
import { initExport, cleanupExport, exportCredential } from '../utils/turnkeyExport/turnkeyExport.js';
|
|
72
|
+
import { iframeContainerId, iframeElementId } from '../constants.js';
|
|
73
|
+
|
|
74
|
+
const EmbeddedRevealView = () => {
|
|
75
|
+
var _a, _b;
|
|
76
|
+
const { authToken, primaryWallet, user, setShowAuthFlow, environmentId } = useInternalDynamicContext();
|
|
77
|
+
const [acknowledgement1, setAcknowledgement1] = useState(false);
|
|
78
|
+
const iframeContainerRef = useRef(null);
|
|
79
|
+
const decodedJwt = decodeJwt(authToken);
|
|
80
|
+
const walletProperties = (_b = (_a = decodedJwt === null || decodedJwt === void 0 ? void 0 : decodedJwt.verifiedCredentials) === null || _a === void 0 ? void 0 : _a.find(({ walletName }) => walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey'))) === null || _b === void 0 ? void 0 : _b.walletProperties;
|
|
81
|
+
const isTurnkeyHDWallet = walletProperties === null || walletProperties === void 0 ? void 0 : walletProperties.turnkeyHDWalletId;
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
const iframeContainerElement = iframeContainerRef.current;
|
|
84
|
+
if (!iframeContainerElement) {
|
|
85
|
+
throw new DynamicError('Missing iframe container');
|
|
86
|
+
}
|
|
87
|
+
if (iframeContainerElement.children.length > 0) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
initExport({
|
|
91
|
+
iframeContainer: iframeContainerElement,
|
|
92
|
+
iframeElementId,
|
|
93
|
+
wallet: primaryWallet,
|
|
94
|
+
});
|
|
95
|
+
return () => {
|
|
96
|
+
cleanupExport({
|
|
97
|
+
wallet: primaryWallet,
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
// only run once on mount
|
|
101
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
102
|
+
}, []);
|
|
103
|
+
const { mutate: handleExportWallet, isLoading, error, data, } = useMutation(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
104
|
+
const iframeContainerElement = iframeContainerRef.current;
|
|
105
|
+
if (!iframeContainerElement) {
|
|
106
|
+
throw new DynamicError('Missing iframe container');
|
|
107
|
+
}
|
|
108
|
+
return exportCredential({
|
|
109
|
+
authToken,
|
|
110
|
+
environmentId,
|
|
111
|
+
userEmail: user === null || user === void 0 ? void 0 : user.email,
|
|
112
|
+
wallet: primaryWallet,
|
|
113
|
+
});
|
|
114
|
+
}), {
|
|
115
|
+
onFailure: (err) => {
|
|
116
|
+
logger.error('Failed to export', err);
|
|
117
|
+
dynamicEvents.emit('embeddedWalletRevealFailed', err);
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
const errorText = useMemo(() => {
|
|
121
|
+
if (!error) {
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
|
124
|
+
if (error instanceof DynamicError) {
|
|
125
|
+
return error.message;
|
|
126
|
+
}
|
|
127
|
+
return getProperErrorMessage(error);
|
|
128
|
+
}, [error]);
|
|
129
|
+
const { t } = useTranslation();
|
|
130
|
+
const contentHeader = (jsx("div", { className: 'embedded-reveal-view__body__description', children: !isLoading && data && !error ? (jsx(Typography, { variant: 'body_normal', color: 'secondary', weight: 'regular', children: t('dyn_embedded_reveal.reveal_description') })) : (jsx("div", { className: 'embedded-reveal-view__header', children: jsx(SvgExportEmbeddedHero, {}) })) }));
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
var _a;
|
|
133
|
+
if (((_a = iframeContainerRef === null || iframeContainerRef === void 0 ? void 0 : iframeContainerRef.current) === null || _a === void 0 ? void 0 : _a.children) && data) {
|
|
134
|
+
// eslint-disable-next-line prefer-destructuring
|
|
135
|
+
const iframeElement = iframeContainerRef.current.children[0];
|
|
136
|
+
iframeElement === null || iframeElement === void 0 ? void 0 : iframeElement.setAttribute('style', isTurnkeyHDWallet ? 'height: 100px' : 'height: 60px');
|
|
137
|
+
}
|
|
138
|
+
}, [iframeContainerRef, data, isTurnkeyHDWallet]);
|
|
139
|
+
const closeButton = (jsx(IconButton, { onClick: () => setShowAuthFlow(false), type: 'button', children: jsx(SvgClose, {}) }));
|
|
140
|
+
const hasInjectedCredential = !isLoading && data && !error;
|
|
141
|
+
const credentialTitle = isTurnkeyHDWallet
|
|
142
|
+
? t('dyn_embedded_reveal.recovery_phrase_title')
|
|
143
|
+
: t('dyn_embedded_reveal.private_key_title');
|
|
144
|
+
const title = hasInjectedCredential
|
|
145
|
+
? credentialTitle
|
|
146
|
+
: t('dyn_embedded_reveal.agreement_title');
|
|
147
|
+
return (jsxs(Fragment, { children: [jsx(ModalHeader, { trailing: closeButton, children: jsx(Typography, { as: 'h1', variant: 'title', color: 'primary', "data-testid": 'dynamic-auth-modal-heading', className: 'header__typography', children: title }) }), jsx("div", { className: 'embedded-reveal-view', children: jsxs("div", { className: 'embedded-reveal-view__body', children: [contentHeader, jsx("div", { id: iframeContainerId, style: { display: data ? 'block' : 'none' }, ref: iframeContainerRef }), hasInjectedCredential ? (jsx(Button, { buttonPadding: 'large', buttonVariant: 'brand-primary', onClick: () => setShowAuthFlow(false), loading: isLoading, typographyProps: {
|
|
148
|
+
color: 'inherit',
|
|
149
|
+
}, children: t('dyn_embedded_reveal.done_button_label') })) : (jsxs(Fragment, { children: [jsx("div", { className: 'embedded-reveal-view__body__description', children: jsx(Badge, { text: t('dyn_embedded_reveal.badge_label'), className: 'embedded-reveal-view__body__badge' }) }), errorText && jsx(ErrorContainer, { children: errorText }), jsxs("div", { className: 'embedded-reveal-view__body__card', children: [jsxs("div", { className: 'embedded-reveal-view__body__card__statement', children: [jsx("div", { className: 'embedded-reveal-view__body__card__icon', children: jsx(SvgWalletV2, {}) }), jsxs("div", { children: [jsx(Typography, { variant: 'body_normal', color: 'primary', style: { letterSpacing: '-0.15px' }, children: t('dyn_embedded_reveal.statement_1.title') }), jsx(Typography, { variant: 'body_small', color: 'secondary', weight: 'regular', children: t('dyn_embedded_reveal.statement_1.description') })] })] }), jsxs("div", { className: 'embedded-reveal-view__body__card__statement', children: [jsx("div", { className: 'embedded-reveal-view__body__card__icon', children: jsx(SvgEyeOffIcon, {}) }), jsxs("div", { children: [jsx(Typography, { variant: 'body_normal', color: 'primary', style: { letterSpacing: '-0.15px' }, children: t('dyn_embedded_reveal.statement_2.title') }), jsx(Typography, { variant: 'body_small', color: 'secondary', weight: 'regular', children: t('dyn_embedded_reveal.statement_2.description') })] })] })] }), jsxs("div", { className: 'embedded-reveal-view__body__confirm_card', children: [jsxs("button", { className: 'embedded-reveal-view__body__card__acknowledgement', onClick: () => setAcknowledgement1(!acknowledgement1), children: [jsx("div", { children: jsx(Checkbox, { checked: acknowledgement1, onChange: () => setAcknowledgement1(!acknowledgement1), className: 'embedded-reveal-view__body__card__statement__checkbox', id: 'embedded-reveal-checkbox-1' }) }), jsx("div", { children: jsx(Typography, { variant: 'body_normal', color: 'primary', style: { letterSpacing: '-0.15px' }, children: t('dyn_embedded_reveal.checkbox_label') }) })] }), jsx(Button, { buttonPadding: 'large', buttonVariant: 'brand-primary', typographyProps: {
|
|
150
|
+
color: 'inherit',
|
|
151
|
+
}, onClick: () => handleExportWallet(), disabled: !acknowledgement1, loading: isLoading, dataTestId: 'embedded-reveal-button', children: t('dyn_embedded_reveal.reveal_button_label') })] })] }))] }) })] }));
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export { EmbeddedRevealView };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { EmbeddedRevealView } from './EmbeddedRevealView';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const iframeContainerId = 'dyn-turnkey-export-container-id';
|
|
6
|
+
const iframeElementId = 'dyn-turnkey-export-element-id';
|
|
7
|
+
|
|
8
|
+
exports.iframeContainerId = iframeContainerId;
|
|
9
|
+
exports.iframeElementId = iframeElementId;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './EmbeddedRevealView';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './turnkeyExport';
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _tslib = require('../../../../../../_virtual/_tslib.cjs');
|
|
6
|
+
var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
7
|
+
var utils = require('@dynamic-labs/utils');
|
|
8
|
+
var decodeJwt = require('../../../../shared/utils/functions/decodeJwt/decodeJwt.cjs');
|
|
9
|
+
require('@dynamic-labs/iconic');
|
|
10
|
+
require('react/jsx-runtime');
|
|
11
|
+
require('../../../../context/ViewContext/ViewContext.cjs');
|
|
12
|
+
require('react');
|
|
13
|
+
require('../../../../shared/logger.cjs');
|
|
14
|
+
require('@dynamic-labs/wallet-book');
|
|
15
|
+
require('../../../../utils/constants/colors.cjs');
|
|
16
|
+
require('../../../../shared/utils/classes/storage/localStorage.cjs');
|
|
17
|
+
require('viem');
|
|
18
|
+
require('../../../../shared/consts/index.cjs');
|
|
19
|
+
var api = require('../../../../data/api.cjs');
|
|
20
|
+
|
|
21
|
+
const initExport = ({ iframeContainer, iframeElementId, wallet, }) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
+
var _a;
|
|
23
|
+
if (!(wallet === null || wallet === void 0 ? void 0 : wallet.connector) ||
|
|
24
|
+
!(wallet === null || wallet === void 0 ? void 0 : wallet.id) ||
|
|
25
|
+
!walletConnectorCore.isPasskeyWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector)) {
|
|
26
|
+
throw new utils.DynamicError('PasskeyWalletConnector not found');
|
|
27
|
+
}
|
|
28
|
+
const turnkeyExportHandler = (_a = wallet.connector) === null || _a === void 0 ? void 0 : _a.getExportHandler();
|
|
29
|
+
const publicKey = yield turnkeyExportHandler.initExport(iframeContainer, iframeElementId);
|
|
30
|
+
if (!publicKey) {
|
|
31
|
+
throw new utils.DynamicError('Something went wrong');
|
|
32
|
+
}
|
|
33
|
+
return turnkeyExportHandler;
|
|
34
|
+
});
|
|
35
|
+
const exportCredential = ({ authToken, userEmail, wallet, environmentId, }) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
var _b, _c;
|
|
37
|
+
if (!authToken) {
|
|
38
|
+
throw new utils.DynamicError('User must be logged in');
|
|
39
|
+
}
|
|
40
|
+
const decodedJwt = decodeJwt.decodeJwt(authToken);
|
|
41
|
+
if (!decodedJwt) {
|
|
42
|
+
throw new utils.DynamicError('User must be logged in with a valid token');
|
|
43
|
+
}
|
|
44
|
+
if (!(wallet === null || wallet === void 0 ? void 0 : wallet.connector) ||
|
|
45
|
+
!(wallet === null || wallet === void 0 ? void 0 : wallet.id) ||
|
|
46
|
+
!walletConnectorCore.isPasskeyWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector)) {
|
|
47
|
+
throw new utils.DynamicError('PasskeyWalletConnector not found');
|
|
48
|
+
}
|
|
49
|
+
const connector = wallet.connector;
|
|
50
|
+
connector.setEmail(userEmail);
|
|
51
|
+
const walletProperties = (_c = (_b = decodedJwt.verifiedCredentials) === null || _b === void 0 ? void 0 : _b.find(({ walletName }) => walletName === null || walletName === void 0 ? void 0 : walletName.startsWith('turnkey'))) === null || _c === void 0 ? void 0 : _c.walletProperties;
|
|
52
|
+
const turnkeyHDWalletId = walletProperties === null || walletProperties === void 0 ? void 0 : walletProperties.turnkeyHDWalletId;
|
|
53
|
+
const privateKeyId = walletProperties === null || walletProperties === void 0 ? void 0 : walletProperties.turnkeyPrivateKeyId;
|
|
54
|
+
const organizationId = walletProperties === null || walletProperties === void 0 ? void 0 : walletProperties.turnkeySubOrganizationId;
|
|
55
|
+
if (!organizationId ||
|
|
56
|
+
(turnkeyHDWalletId === undefined && privateKeyId === undefined)) {
|
|
57
|
+
throw new utils.DynamicError('Invalid token!');
|
|
58
|
+
}
|
|
59
|
+
const turnkeyExportHandler = connector.getExportHandler();
|
|
60
|
+
const targetPublicKey = turnkeyExportHandler.publicKey;
|
|
61
|
+
if (!targetPublicKey) {
|
|
62
|
+
throw new utils.DynamicError('Must initialize export first');
|
|
63
|
+
}
|
|
64
|
+
// calls turnkey export api
|
|
65
|
+
if (turnkeyHDWalletId) {
|
|
66
|
+
const newActivity = yield turnkeyExportHandler.exportWallet({
|
|
67
|
+
organizationId,
|
|
68
|
+
walletId: turnkeyHDWalletId,
|
|
69
|
+
});
|
|
70
|
+
const activityId = newActivity.id;
|
|
71
|
+
const res = yield api.exportEmbeddedWallet({
|
|
72
|
+
activityId,
|
|
73
|
+
environmentId,
|
|
74
|
+
userJwt: authToken,
|
|
75
|
+
walletId: wallet.id,
|
|
76
|
+
});
|
|
77
|
+
const exportBundle = res === null || res === void 0 ? void 0 : res.exportBundle;
|
|
78
|
+
if (!exportBundle) {
|
|
79
|
+
throw new utils.DynamicError('Invalid export response');
|
|
80
|
+
}
|
|
81
|
+
const injected = yield turnkeyExportHandler.verifyExportWallet(exportBundle);
|
|
82
|
+
return injected;
|
|
83
|
+
}
|
|
84
|
+
else if (privateKeyId) {
|
|
85
|
+
const newActivity = yield turnkeyExportHandler.exportPrivateKey({
|
|
86
|
+
organizationId,
|
|
87
|
+
privateKeyId,
|
|
88
|
+
});
|
|
89
|
+
const activityId = newActivity.id;
|
|
90
|
+
const res = yield api.exportEmbeddedWallet({
|
|
91
|
+
activityId,
|
|
92
|
+
environmentId,
|
|
93
|
+
userJwt: authToken,
|
|
94
|
+
walletId: wallet.id,
|
|
95
|
+
});
|
|
96
|
+
const exportBundle = res === null || res === void 0 ? void 0 : res.exportBundle;
|
|
97
|
+
if (!exportBundle) {
|
|
98
|
+
throw new utils.DynamicError('Invalid export response');
|
|
99
|
+
}
|
|
100
|
+
const injected = yield turnkeyExportHandler.verifyExportPrivateKey(exportBundle);
|
|
101
|
+
return injected;
|
|
102
|
+
}
|
|
103
|
+
throw new utils.DynamicError('Invalid token!');
|
|
104
|
+
});
|
|
105
|
+
const cleanupExport = ({ wallet }) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
106
|
+
var _d;
|
|
107
|
+
const connector = wallet === null || wallet === void 0 ? void 0 : wallet.connector;
|
|
108
|
+
// clear iframeStamper and its reference
|
|
109
|
+
(_d = connector === null || connector === void 0 ? void 0 : connector.getExportHandler()) === null || _d === void 0 ? void 0 : _d.clear();
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
exports.cleanupExport = cleanupExport;
|
|
113
|
+
exports.exportCredential = exportCredential;
|
|
114
|
+
exports.initExport = initExport;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Wallet } from '../../../../shared';
|
|
2
|
+
export declare const initExport: ({ iframeContainer, iframeElementId, wallet, }: {
|
|
3
|
+
iframeContainer: HTMLElement;
|
|
4
|
+
iframeElementId: string;
|
|
5
|
+
wallet: Wallet | null;
|
|
6
|
+
}) => Promise<import("@dynamic-labs/wallet-connector-core").ExportHandler>;
|
|
7
|
+
export declare const exportCredential: ({ authToken, userEmail, wallet, environmentId, }: {
|
|
8
|
+
authToken: string | undefined;
|
|
9
|
+
userEmail: string | undefined;
|
|
10
|
+
wallet: Wallet | null;
|
|
11
|
+
environmentId: string;
|
|
12
|
+
}) => Promise<unknown>;
|
|
13
|
+
export declare const cleanupExport: ({ wallet }: {
|
|
14
|
+
wallet: Wallet | null;
|
|
15
|
+
}) => Promise<void>;
|