π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Inline and move
Manav Rathid857648af998
diff --git a/web/packages/accounts/components/two-factor/TwoFactorSetup.tsx b/web/packages/accounts/components/two-factor/TwoFactorSetup.tsxnew file mode 100644index 0000000000..8f6a081a61--- /dev/null+++ b/web/packages/accounts/components/two-factor/TwoFactorSetup.tsx@@ -0,0 +1,101 @@+import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";+import CodeBlock from "@ente/shared/components/CodeBlock";+import { VerticallyCentered } from "@ente/shared/components/Container";+import LinkButton from "@ente/shared/components/LinkButton";+import { styled, Typography } from "@mui/material";+import { t } from "i18next";+import { useState } from "react";+import { type SetupMode } from "../../pages/two-factor/setup";+import type { TwoFactorSecret } from "../../services/user";++interface TwoFactorSetupProps {+ twoFactorSecret?: TwoFactorSecret;+}++export function TwoFactorSetup({ twoFactorSecret }: TwoFactorSetupProps) {+ const [setupMode, setSetupMode] = useState<SetupMode>("qrCode");++ const changeToManualMode = () => setSetupMode("manualCode");++ const changeToQRMode = () => setSetupMode("qrCode");++ return (+ <VerticallyCentered sx={{ mb: 3 }}>+ {setupMode == "qrCode" ? (+ <SetupQRMode+ twoFactorSecret={twoFactorSecret}+ changeToManualMode={changeToManualMode}+ />+ ) : (+ <SetupManualMode+ twoFactorSecret={twoFactorSecret}+ changeToQRMode={changeToQRMode}+ />+ )}+ </VerticallyCentered>+ );+}++interface SetupManualModeProps {+ twoFactorSecret?: TwoFactorSecret;+ changeToQRMode: () => void;+}+function SetupManualMode({+ twoFactorSecret,+ changeToQRMode,+}: SetupManualModeProps) {+ return (+ <>+ <Typography>{t("TWO_FACTOR_MANUAL_CODE_INSTRUCTION")}</Typography>+ <CodeBlock code={twoFactorSecret?.secretCode ?? ""} my={2} />+ <LinkButton onClick={changeToQRMode}>+ {t("SCAN_QR_CODE")}+ </LinkButton>+ </>+ );+}++interface SetupQRModeProps {+ twoFactorSecret?: TwoFactorSecret;+ changeToManualMode: () => void;+}++function SetupQRMode({+ twoFactorSecret,+ changeToManualMode,+}: SetupQRModeProps) {+ return (+ <>+ <Typography>{t("TWO_FACTOR_QR_INSTRUCTION")}</Typography>+ {!twoFactorSecret ? (+ <LoadingQRCode>+ <ActivityIndicator />+ </LoadingQRCode>+ ) : (+ <QRCode+ src={`data:image/png;base64,${twoFactorSecret?.qrCode}`}+ />+ )}+ <LinkButton onClick={changeToManualMode}>+ {t("ENTER_CODE_MANUALLY")}+ </LinkButton>+ </>+ );+}++const QRCode = styled("img")(+ ({ theme }) => `+ height: 200px;+ width: 200px;+ margin: ${theme.spacing(2)};+`,+);++const LoadingQRCode = styled(VerticallyCentered)(+ ({ theme }) => `+ width:200px;+ aspect-ratio:1;+ border: 1px solid ${theme.palette.grey.A200};+ margin: ${theme.spacing(2)};+ `,+);diff --git a/web/packages/accounts/components/two-factor/setup/ManualMode.tsx b/web/packages/accounts/components/two-factor/setup/ManualMode.tsxdeleted file mode 100644index f30faae76f..0000000000--- a/web/packages/accounts/components/two-factor/setup/ManualMode.tsx+++ /dev/null@@ -1,25 +0,0 @@-import type { TwoFactorSecret } from "@/accounts/types/user";-import CodeBlock from "@ente/shared/components/CodeBlock";-import { Typography } from "@mui/material";-import { t } from "i18next";--import LinkButton from "@ente/shared/components/LinkButton";--interface Iprops {- twoFactorSecret?: TwoFactorSecret;- changeToQRMode: () => void;-}-export default function SetupManualMode({- twoFactorSecret,- changeToQRMode,-}: Iprops) {- return (- <>- <Typography>{t("TWO_FACTOR_MANUAL_CODE_INSTRUCTION")}</Typography>- <CodeBlock code={twoFactorSecret?.secretCode ?? ""} my={2} />- <LinkButton onClick={changeToQRMode}>- {t("SCAN_QR_CODE")}- </LinkButton>- </>- );-}diff --git a/web/packages/accounts/components/two-factor/setup/QRMode.tsx b/web/packages/accounts/components/two-factor/setup/QRMode.tsxdeleted file mode 100644index 53b11048b4..0000000000--- a/web/packages/accounts/components/two-factor/setup/QRMode.tsx+++ /dev/null@@ -1,34 +0,0 @@-import type { TwoFactorSecret } from "@/accounts/types/user";-import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";-import LinkButton from "@ente/shared/components/LinkButton";-import { Typography } from "@mui/material";-import { t } from "i18next";-import { LoadingQRCode, QRCode } from "../styledComponents";--interface Iprops {- twoFactorSecret?: TwoFactorSecret;- changeToManualMode: () => void;-}--export default function SetupQRMode({- twoFactorSecret,- changeToManualMode,-}: Iprops) {- return (- <>- <Typography>{t("TWO_FACTOR_QR_INSTRUCTION")}</Typography>- {!twoFactorSecret ? (- <LoadingQRCode>- <ActivityIndicator />- </LoadingQRCode>- ) : (- <QRCode- src={`data:image/png;base64,${twoFactorSecret?.qrCode}`}- />- )}- <LinkButton onClick={changeToManualMode}>- {t("ENTER_CODE_MANUALLY")}- </LinkButton>- </>- );-}diff --git a/web/packages/accounts/components/two-factor/setup/index.tsx b/web/packages/accounts/components/two-factor/setup/index.tsxdeleted file mode 100644index 87e3ce404b..0000000000--- a/web/packages/accounts/components/two-factor/setup/index.tsx+++ /dev/null@@ -1,33 +0,0 @@-import SetupManualMode from "@/accounts/components/two-factor/setup/ManualMode";-import SetupQRMode from "@/accounts/components/two-factor/setup/QRMode";-import { type SetupMode } from "@/accounts/pages/two-factor/setup";-import type { TwoFactorSecret } from "@/accounts/types/user";-import { VerticallyCentered } from "@ente/shared/components/Container";-import { useState } from "react";--interface Iprops {- twoFactorSecret?: TwoFactorSecret;-}-export function TwoFactorSetup({ twoFactorSecret }: Iprops) {- const [setupMode, setSetupMode] = useState<SetupMode>("qrCode");-- const changeToManualMode = () => setSetupMode("manualCode");-- const changeToQRMode = () => setSetupMode("qrCode");-- return (- <VerticallyCentered sx={{ mb: 3 }}>- {setupMode == "qrCode" ? (- <SetupQRMode- twoFactorSecret={twoFactorSecret}- changeToManualMode={changeToManualMode}- />- ) : (- <SetupManualMode- twoFactorSecret={twoFactorSecret}- changeToQRMode={changeToQRMode}- />- )}- </VerticallyCentered>- );-}diff --git a/web/packages/accounts/components/two-factor/styledComponents.ts b/web/packages/accounts/components/two-factor/styledComponents.tsdeleted file mode 100644index 7a9e7fe1c2..0000000000--- a/web/packages/accounts/components/two-factor/styledComponents.ts+++ /dev/null@@ -1,18 +0,0 @@-import { VerticallyCentered } from "@ente/shared/components/Container";-import { styled } from "@mui/material";-export const QRCode = styled("img")(- ({ theme }) => `- height: 200px;- width: 200px;- margin: ${theme.spacing(2)};-`,-);--export const LoadingQRCode = styled(VerticallyCentered)(- ({ theme }) => `- width:200px;- aspect-ratio:1;- border: 1px solid ${theme.palette.grey.A200};- margin: ${theme.spacing(2)};- `,-);diff --git a/web/packages/accounts/pages/change-password.tsx b/web/packages/accounts/pages/change-password.tsxindex 3031cd5c95..b3e0adf7bb 100644--- a/web/packages/accounts/pages/change-password.tsx+++ b/web/packages/accounts/pages/change-password.tsx@@ -34,8 +34,8 @@ import SetPasswordForm, {} from "../components/SetPasswordForm";import { PAGES } from "../constants/pages";import { appHomeRoute, stashRedirect } from "../services/redirect";+import type { UpdatedKey } from "../services/user";import type { PageProps } from "../types/page";-import type { UpdatedKey } from "../types/user";const Page: React.FC<PageProps> = () => {const [token, setToken] = useState<string>();diff --git a/web/packages/accounts/pages/two-factor/setup.tsx b/web/packages/accounts/pages/two-factor/setup.tsxindex d3414c20c6..0e6fbce450 100644--- a/web/packages/accounts/pages/two-factor/setup.tsx+++ b/web/packages/accounts/pages/two-factor/setup.tsx@@ -1,9 +1,3 @@-import VerifyTwoFactor, {- type VerifyTwoFactorCallback,-} from "@/accounts/components/two-factor/VerifyForm";-import { TwoFactorSetup } from "@/accounts/components/two-factor/setup";-import { enableTwoFactor, setupTwoFactor } from "@/accounts/services/user";-import type { TwoFactorSecret } from "@/accounts/types/user";import log from "@/base/log";import { VerticallyCentered } from "@ente/shared/components/Container";import LinkButton from "@ente/shared/components/LinkButton";@@ -14,7 +8,13 @@ import Card from "@mui/material/Card";import { t } from "i18next";import { useRouter } from "next/router";import { useEffect, useState } from "react";+import { TwoFactorSetup } from "../../components/two-factor/TwoFactorSetup";+import VerifyTwoFactor, {+ type VerifyTwoFactorCallback,+} from "../../components/two-factor/VerifyForm";import { appHomeRoute } from "../../services/redirect";+import type { TwoFactorSecret } from "../../services/user";+import { enableTwoFactor, setupTwoFactor } from "../../services/user";import type { PageProps } from "../../types/page";export type SetupMode = "qrCode" | "manualCode";diff --git a/web/packages/accounts/pages/verify.tsx b/web/packages/accounts/pages/verify.tsxindex d0c61721ec..9e5ebe3fd4 100644--- a/web/packages/accounts/pages/verify.tsx+++ b/web/packages/accounts/pages/verify.tsx@@ -1,4 +1,3 @@-import type { UserVerificationResponse } from "@/accounts/types/user";import { FormPaper, FormPaperTitle } from "@/base/components/FormPaper";import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";import log from "@/base/log";@@ -40,6 +39,7 @@ import { stashedRedirect, unstashRedirect } from "../services/redirect";import { configureSRP } from "../services/srp";import type { SRPAttributes, SRPSetupAttributes } from "../services/srp-remote";import { getSRPAttributes } from "../services/srp-remote";+import type { UserVerificationResponse } from "../services/user";import { putAttributes, sendOtt, verifyOtt } from "../services/user";import type { PageProps } from "../types/page";diff --git a/web/packages/accounts/services/srp-remote.ts b/web/packages/accounts/services/srp-remote.tsindex cec06e837b..1aad4ddb2a 100644--- a/web/packages/accounts/services/srp-remote.ts+++ b/web/packages/accounts/services/srp-remote.ts@@ -3,7 +3,7 @@ import { apiURL } from "@/base/origins";import { ApiError, CustomError } from "@ente/shared/error";import HTTPService from "@ente/shared/network/HTTPService";import { HttpStatusCode } from "axios";-import type { UpdatedKey, UserVerificationResponse } from "../types/user";+import type { UpdatedKey, UserVerificationResponse } from "./user";export interface SRPAttributes {srpUserID: string;diff --git a/web/packages/accounts/services/srp.ts b/web/packages/accounts/services/srp.tsindex 5d2242e484..357a2a9aae 100644--- a/web/packages/accounts/services/srp.ts+++ b/web/packages/accounts/services/srp.ts@@ -1,4 +1,3 @@-import type { UserVerificationResponse } from "@/accounts/types/user";import { sharedCryptoWorker } from "@/base/crypto";import log from "@/base/log";import { generateLoginSubKey } from "@ente/shared/crypto/helpers";@@ -6,13 +5,15 @@ import { getToken } from "@ente/shared/storage/localStorage/helpers";import type { KeyAttributes } from "@ente/shared/user/types";import { SRP, SrpClient } from "fast-srp-hap";import { v4 as uuidv4 } from "uuid";-import type { SRPAttributes, SRPSetupAttributes } from "./srp-remote";import {completeSRPSetup,createSRPSession,startSRPSetup,verifySRPSession,+ type SRPAttributes,+ type SRPSetupAttributes,} from "./srp-remote";+import type { UserVerificationResponse } from "./user";const SRP_PARAMS = SRP.params["4096"];diff --git a/web/packages/accounts/services/user.ts b/web/packages/accounts/services/user.tsindex 02148bf41a..e328338850 100644--- a/web/packages/accounts/services/user.ts+++ b/web/packages/accounts/services/user.ts@@ -1,10 +1,3 @@-import type {- RecoveryKey,- TwoFactorRecoveryResponse,- TwoFactorSecret,- TwoFactorVerificationResponse,- UserVerificationResponse,-} from "@/accounts/types/user";import { appName } from "@/base/app";import type { B64EncryptionResult } from "@/base/crypto/libsodium";import { apiURL } from "@/base/origins";@@ -14,6 +7,48 @@ import { getToken } from "@ente/shared/storage/localStorage/helpers";import type { KeyAttributes } from "@ente/shared/user/types";import { HttpStatusCode } from "axios";+export interface UserVerificationResponse {+ id: number;+ keyAttributes?: KeyAttributes;+ encryptedToken?: string;+ token?: string;+ twoFactorSessionID: string;+ passkeySessionID: string;+ srpM2?: string;+}++export interface TwoFactorVerificationResponse {+ id: number;+ keyAttributes: KeyAttributes;+ encryptedToken?: string;+ token?: string;+}++export interface TwoFactorSecret {+ secretCode: string;+ qrCode: string;+}++export interface TwoFactorRecoveryResponse {+ encryptedSecret: string;+ secretDecryptionNonce: string;+}++export interface UpdatedKey {+ kekSalt: string;+ encryptedKey: string;+ keyDecryptionNonce: string;+ memLimit: number;+ opsLimit: number;+}++export interface RecoveryKey {+ masterKeyEncryptedWithRecoveryKey: string;+ masterKeyDecryptionNonce: string;+ recoveryKeyEncryptedWithMasterKey: string;+ recoveryKeyDecryptionNonce: string;+}+export const sendOtt = async (email: string) => {return HTTPService.post(await apiURL("/users/ott"), {email,diff --git a/web/packages/accounts/types/user.ts b/web/packages/accounts/types/user.tsdeleted file mode 100644index 569b6c6116..0000000000--- a/web/packages/accounts/types/user.ts+++ /dev/null@@ -1,43 +0,0 @@-import type { KeyAttributes } from "@ente/shared/user/types";--export interface UserVerificationResponse {- id: number;- keyAttributes?: KeyAttributes;- encryptedToken?: string;- token?: string;- twoFactorSessionID: string;- passkeySessionID: string;- srpM2?: string;-}--export interface TwoFactorVerificationResponse {- id: number;- keyAttributes: KeyAttributes;- encryptedToken?: string;- token?: string;-}--export interface TwoFactorSecret {- secretCode: string;- qrCode: string;-}--export interface TwoFactorRecoveryResponse {- encryptedSecret: string;- secretDecryptionNonce: string;-}--export interface UpdatedKey {- kekSalt: string;- encryptedKey: string;- keyDecryptionNonce: string;- memLimit: number;- opsLimit: number;-}--export interface RecoveryKey {- masterKeyEncryptedWithRecoveryKey: string;- masterKeyDecryptionNonce: string;- recoveryKeyEncryptedWithMasterKey: string;- recoveryKeyDecryptionNonce: string;-}