@dynamic-labs/sdk-react-core 1.1.0-alpha.3 → 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 +17 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +10 -10
- package/src/index.cjs +16 -0
- package/src/index.d.ts +2 -1
- package/src/index.js +8 -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 +16 -2
- 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/functions/index.d.ts +1 -0
- package/src/lib/utils/functions/isEmailValid/index.d.ts +1 -0
- package/src/lib/utils/functions/isEmailValid/isEmailValid.cjs +8 -0
- package/src/lib/utils/functions/isEmailValid/isEmailValid.d.ts +1 -0
- package/src/lib/utils/functions/isEmailValid/isEmailValid.js +4 -0
- package/src/lib/utils/functions/isProviderEnabled/isProviderEnabled.cjs +9 -1
- package/src/lib/utils/functions/isProviderEnabled/isProviderEnabled.js +9 -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 +4 -1
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.d.ts +1 -0
- package/src/lib/utils/hooks/useAuthLayoutChecks/useAuthLayoutChecks.js +4 -1
- package/src/lib/utils/hooks/useConnectWithEmailOtp/index.d.ts +1 -0
- package/src/lib/utils/hooks/useConnectWithEmailOtp/useConnectWithEmailOtp.cjs +150 -0
- package/src/lib/utils/hooks/useConnectWithEmailOtp/useConnectWithEmailOtp.d.ts +32 -0
- package/src/lib/utils/hooks/useConnectWithEmailOtp/useConnectWithEmailOtp.js +146 -0
- package/src/lib/utils/hooks/useEmailProvider/useEmailProvider.cjs +3 -3
- package/src/lib/utils/hooks/useEmailProvider/useEmailProvider.js +3 -3
- 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/LoginView/sections/EmailSignInSection/LoginEmailForm.cjs +2 -3
- package/src/lib/views/LoginView/sections/EmailSignInSection/LoginEmailForm.d.ts +0 -1
- package/src/lib/views/LoginView/sections/EmailSignInSection/LoginEmailForm.js +3 -3
- 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/WalletList/WalletList.cjs +5 -8
- package/src/lib/views/WalletList/WalletList.js +5 -8
- 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
|
@@ -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>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { __awaiter } from '../../../../../../_virtual/_tslib.js';
|
|
2
|
+
import { isPasskeyWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
4
|
+
import { decodeJwt } from '../../../../shared/utils/functions/decodeJwt/decodeJwt.js';
|
|
5
|
+
import '@dynamic-labs/iconic';
|
|
6
|
+
import 'react/jsx-runtime';
|
|
7
|
+
import '../../../../context/ViewContext/ViewContext.js';
|
|
8
|
+
import 'react';
|
|
9
|
+
import '../../../../shared/logger.js';
|
|
10
|
+
import '@dynamic-labs/wallet-book';
|
|
11
|
+
import '../../../../utils/constants/colors.js';
|
|
12
|
+
import '../../../../shared/utils/classes/storage/localStorage.js';
|
|
13
|
+
import 'viem';
|
|
14
|
+
import '../../../../shared/consts/index.js';
|
|
15
|
+
import { exportEmbeddedWallet } from '../../../../data/api.js';
|
|
16
|
+
|
|
17
|
+
const initExport = ({ iframeContainer, iframeElementId, wallet, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
+
var _a;
|
|
19
|
+
if (!(wallet === null || wallet === void 0 ? void 0 : wallet.connector) ||
|
|
20
|
+
!(wallet === null || wallet === void 0 ? void 0 : wallet.id) ||
|
|
21
|
+
!isPasskeyWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector)) {
|
|
22
|
+
throw new DynamicError('PasskeyWalletConnector not found');
|
|
23
|
+
}
|
|
24
|
+
const turnkeyExportHandler = (_a = wallet.connector) === null || _a === void 0 ? void 0 : _a.getExportHandler();
|
|
25
|
+
const publicKey = yield turnkeyExportHandler.initExport(iframeContainer, iframeElementId);
|
|
26
|
+
if (!publicKey) {
|
|
27
|
+
throw new DynamicError('Something went wrong');
|
|
28
|
+
}
|
|
29
|
+
return turnkeyExportHandler;
|
|
30
|
+
});
|
|
31
|
+
const exportCredential = ({ authToken, userEmail, wallet, environmentId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
var _b, _c;
|
|
33
|
+
if (!authToken) {
|
|
34
|
+
throw new DynamicError('User must be logged in');
|
|
35
|
+
}
|
|
36
|
+
const decodedJwt = decodeJwt(authToken);
|
|
37
|
+
if (!decodedJwt) {
|
|
38
|
+
throw new DynamicError('User must be logged in with a valid token');
|
|
39
|
+
}
|
|
40
|
+
if (!(wallet === null || wallet === void 0 ? void 0 : wallet.connector) ||
|
|
41
|
+
!(wallet === null || wallet === void 0 ? void 0 : wallet.id) ||
|
|
42
|
+
!isPasskeyWalletConnector(wallet === null || wallet === void 0 ? void 0 : wallet.connector)) {
|
|
43
|
+
throw new DynamicError('PasskeyWalletConnector not found');
|
|
44
|
+
}
|
|
45
|
+
const connector = wallet.connector;
|
|
46
|
+
connector.setEmail(userEmail);
|
|
47
|
+
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;
|
|
48
|
+
const turnkeyHDWalletId = walletProperties === null || walletProperties === void 0 ? void 0 : walletProperties.turnkeyHDWalletId;
|
|
49
|
+
const privateKeyId = walletProperties === null || walletProperties === void 0 ? void 0 : walletProperties.turnkeyPrivateKeyId;
|
|
50
|
+
const organizationId = walletProperties === null || walletProperties === void 0 ? void 0 : walletProperties.turnkeySubOrganizationId;
|
|
51
|
+
if (!organizationId ||
|
|
52
|
+
(turnkeyHDWalletId === undefined && privateKeyId === undefined)) {
|
|
53
|
+
throw new DynamicError('Invalid token!');
|
|
54
|
+
}
|
|
55
|
+
const turnkeyExportHandler = connector.getExportHandler();
|
|
56
|
+
const targetPublicKey = turnkeyExportHandler.publicKey;
|
|
57
|
+
if (!targetPublicKey) {
|
|
58
|
+
throw new DynamicError('Must initialize export first');
|
|
59
|
+
}
|
|
60
|
+
// calls turnkey export api
|
|
61
|
+
if (turnkeyHDWalletId) {
|
|
62
|
+
const newActivity = yield turnkeyExportHandler.exportWallet({
|
|
63
|
+
organizationId,
|
|
64
|
+
walletId: turnkeyHDWalletId,
|
|
65
|
+
});
|
|
66
|
+
const activityId = newActivity.id;
|
|
67
|
+
const res = yield exportEmbeddedWallet({
|
|
68
|
+
activityId,
|
|
69
|
+
environmentId,
|
|
70
|
+
userJwt: authToken,
|
|
71
|
+
walletId: wallet.id,
|
|
72
|
+
});
|
|
73
|
+
const exportBundle = res === null || res === void 0 ? void 0 : res.exportBundle;
|
|
74
|
+
if (!exportBundle) {
|
|
75
|
+
throw new DynamicError('Invalid export response');
|
|
76
|
+
}
|
|
77
|
+
const injected = yield turnkeyExportHandler.verifyExportWallet(exportBundle);
|
|
78
|
+
return injected;
|
|
79
|
+
}
|
|
80
|
+
else if (privateKeyId) {
|
|
81
|
+
const newActivity = yield turnkeyExportHandler.exportPrivateKey({
|
|
82
|
+
organizationId,
|
|
83
|
+
privateKeyId,
|
|
84
|
+
});
|
|
85
|
+
const activityId = newActivity.id;
|
|
86
|
+
const res = yield exportEmbeddedWallet({
|
|
87
|
+
activityId,
|
|
88
|
+
environmentId,
|
|
89
|
+
userJwt: authToken,
|
|
90
|
+
walletId: wallet.id,
|
|
91
|
+
});
|
|
92
|
+
const exportBundle = res === null || res === void 0 ? void 0 : res.exportBundle;
|
|
93
|
+
if (!exportBundle) {
|
|
94
|
+
throw new DynamicError('Invalid export response');
|
|
95
|
+
}
|
|
96
|
+
const injected = yield turnkeyExportHandler.verifyExportPrivateKey(exportBundle);
|
|
97
|
+
return injected;
|
|
98
|
+
}
|
|
99
|
+
throw new DynamicError('Invalid token!');
|
|
100
|
+
});
|
|
101
|
+
const cleanupExport = ({ wallet }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
102
|
+
var _d;
|
|
103
|
+
const connector = wallet === null || wallet === void 0 ? void 0 : wallet.connector;
|
|
104
|
+
// clear iframeStamper and its reference
|
|
105
|
+
(_d = connector === null || connector === void 0 ? void 0 : connector.getExportHandler()) === null || _d === void 0 ? void 0 : _d.clear();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
export { cleanupExport, exportCredential, initExport };
|
|
@@ -25,6 +25,7 @@ require('viem');
|
|
|
25
25
|
require('../../../../shared/consts/index.cjs');
|
|
26
26
|
require('@dynamic-labs/multi-wallet');
|
|
27
27
|
var isEmailProviderEnabled = require('../../../../utils/functions/isEmailProviderEnabled/isEmailProviderEnabled.cjs');
|
|
28
|
+
var isEmailValid = require('../../../../utils/functions/isEmailValid/isEmailValid.cjs');
|
|
28
29
|
require('../../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
|
|
29
30
|
require('../../../../context/AccountExistsContext/AccountExistsContext.cjs');
|
|
30
31
|
require('../../../../config/ApiEndpoint.cjs');
|
|
@@ -66,7 +67,6 @@ require('../../../../components/Popper/PopperContext/PopperContext.cjs');
|
|
|
66
67
|
require('react-focus-lock');
|
|
67
68
|
var useEmailProvider = require('../../../../utils/hooks/useEmailProvider/useEmailProvider.cjs');
|
|
68
69
|
|
|
69
|
-
const EMAIL_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i;
|
|
70
70
|
const LoginEmailForm = ({ isLoading: isExternalLoading, onSubmit, onSubmitError, currentEmail, }) => {
|
|
71
71
|
var _a, _b, _c;
|
|
72
72
|
const { t } = reactI18next.useTranslation();
|
|
@@ -112,7 +112,7 @@ const LoginEmailForm = ({ isLoading: isExternalLoading, onSubmit, onSubmitError,
|
|
|
112
112
|
const handleSubmit = (e) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
113
113
|
var _d;
|
|
114
114
|
e.preventDefault();
|
|
115
|
-
if (!
|
|
115
|
+
if (!isEmailValid.isEmailValid(emailInput)) {
|
|
116
116
|
setInvalidEmail(true);
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
@@ -153,5 +153,4 @@ const LoginEmailForm = ({ isLoading: isExternalLoading, onSubmit, onSubmitError,
|
|
|
153
153
|
}, children: "Continue" }))] }));
|
|
154
154
|
};
|
|
155
155
|
|
|
156
|
-
exports.EMAIL_REGEX = EMAIL_REGEX;
|
|
157
156
|
exports.LoginEmailForm = LoginEmailForm;
|