From 96ceead110347e3fce7c0d912c2b29454de29e9f Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Fri, 8 Nov 2024 14:25:50 +0530 Subject: [PATCH] Inline --- .../src/components/DeleteAccountModal.tsx | 22 +++++++++++++++++- web/apps/photos/src/utils/crypto/index.ts | 23 ------------------- 2 files changed, 21 insertions(+), 24 deletions(-) delete mode 100644 web/apps/photos/src/utils/crypto/index.ts diff --git a/web/apps/photos/src/components/DeleteAccountModal.tsx b/web/apps/photos/src/components/DeleteAccountModal.tsx index 31a6b753f8..63dcd4d6a3 100644 --- a/web/apps/photos/src/components/DeleteAccountModal.tsx +++ b/web/apps/photos/src/components/DeleteAccountModal.tsx @@ -1,8 +1,11 @@ import { TitledMiniDialog } from "@/base/components/MiniDialog"; import { FocusVisibleButton } from "@/base/components/mui/FocusVisibleButton"; import { LoadingButton } from "@/base/components/mui/LoadingButton"; +import { sharedCryptoWorker } from "@/base/crypto"; import { AppContext } from "@/new/photos/types/context"; import { initiateEmail } from "@/new/photos/utils/web"; +import { getData, LS_KEYS } from "@ente/shared/storage/localStorage"; +import { getActualKey } from "@ente/shared/user"; import { Checkbox, FormControlLabel, @@ -19,7 +22,6 @@ import { GalleryContext } from "pages/gallery"; import { useContext, useRef, useState } from "react"; import { Trans } from "react-i18next"; import { deleteAccount, getAccountDeleteChallenge } from "services/userService"; -import { decryptDeleteAccountChallenge } from "utils/crypto"; import * as Yup from "yup"; import DropdownInput, { DropdownOption } from "./DropdownInput"; @@ -312,3 +314,21 @@ function CheckboxInput({ ); } + +async function decryptDeleteAccountChallenge(encryptedChallenge: string) { + const cryptoWorker = await sharedCryptoWorker(); + const masterKey = await getActualKey(); + const keyAttributes = getData(LS_KEYS.KEY_ATTRIBUTES); + const secretKey = await cryptoWorker.decryptB64( + keyAttributes.encryptedSecretKey, + keyAttributes.secretKeyDecryptionNonce, + masterKey, + ); + const b64DecryptedChallenge = await cryptoWorker.boxSealOpen( + encryptedChallenge, + keyAttributes.publicKey, + secretKey, + ); + const utf8DecryptedChallenge = atob(b64DecryptedChallenge); + return utf8DecryptedChallenge; +} diff --git a/web/apps/photos/src/utils/crypto/index.ts b/web/apps/photos/src/utils/crypto/index.ts deleted file mode 100644 index 52ed93f36d..0000000000 --- a/web/apps/photos/src/utils/crypto/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { sharedCryptoWorker } from "@/base/crypto"; -import { getData, LS_KEYS } from "@ente/shared/storage/localStorage"; -import { getActualKey } from "@ente/shared/user"; - -export async function decryptDeleteAccountChallenge( - encryptedChallenge: string, -) { - const cryptoWorker = await sharedCryptoWorker(); - const masterKey = await getActualKey(); - const keyAttributes = getData(LS_KEYS.KEY_ATTRIBUTES); - const secretKey = await cryptoWorker.decryptB64( - keyAttributes.encryptedSecretKey, - keyAttributes.secretKeyDecryptionNonce, - masterKey, - ); - const b64DecryptedChallenge = await cryptoWorker.boxSealOpen( - encryptedChallenge, - keyAttributes.publicKey, - secretKey, - ); - const utf8DecryptedChallenge = atob(b64DecryptedChallenge); - return utf8DecryptedChallenge; -}