π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Move
Manav Rathiaec3ec718bf7
diff --git a/web/packages/accounts/components/LoginContents.tsx b/web/packages/accounts/components/LoginContents.tsxindex eae1479346..7217573145 100644--- a/web/packages/accounts/components/LoginContents.tsx+++ b/web/packages/accounts/components/LoginContents.tsx@@ -1,9 +1,7 @@import { Input, Stack, TextField, Typography } from "@mui/material";import { AccountsPageFooter } from "ente-accounts/components/layouts/centered-paper";-import {- getSRPAttributes,- saveSRPAttributes,-} from "ente-accounts/services/srp";+import { saveSRPAttributes } from "ente-accounts/services/accounts-db";+import { getSRPAttributes } from "ente-accounts/services/srp";import { savePartialLocalUser, sendOTT } from "ente-accounts/services/user";import { LinkButton } from "ente-base/components/LinkButton";import { LoadingButton } from "ente-base/components/mui/LoadingButton";diff --git a/web/packages/accounts/pages/credentials.tsx b/web/packages/accounts/pages/credentials.tsxindex bbeb2136a0..7c2a30c03b 100644--- a/web/packages/accounts/pages/credentials.tsx+++ b/web/packages/accounts/pages/credentials.tsx@@ -19,6 +19,8 @@ import {getToken,savedIsFirstLogin,saveIsFirstLogin,+ saveKeyAttributes,+ saveSRPAttributes,setData,setLSUser,} from "ente-accounts/services/accounts-db";@@ -105,8 +107,8 @@ const Page: React.FC = () => {case "valid":break;case "validButPasswordChanged":- setData("keyAttributes", session.updatedKeyAttributes);- setData("srpAttributes", session.updatedSRPAttributes);+ saveKeyAttributes(session.updatedKeyAttributes);+ saveSRPAttributes(session.updatedSRPAttributes);// Set a flag that causes new interactive key attributes to// be generated.saveIsFirstLogin();diff --git a/web/packages/accounts/pages/passkeys/finish.tsx b/web/packages/accounts/pages/passkeys/finish.tsxindex b9dadaf7ce..66c5f0df36 100644--- a/web/packages/accounts/pages/passkeys/finish.tsx+++ b/web/packages/accounts/pages/passkeys/finish.tsx@@ -28,8 +28,8 @@ const Page: React.FC = () => {const response = searchParams.get("response");if (!passkeySessionID || !response) return;- void saveCredentialsAndNavigateTo(passkeySessionID, response).then(- (slug: string) => router.push(slug),+ void saveQueryCredentialsAndNavigateTo(passkeySessionID, response).then(+ (slug) => router.push(slug),);}, [router]);@@ -51,10 +51,13 @@ export default Page;** @returns the slug that we should navigate to now.*/-const saveCredentialsAndNavigateTo = async (+const saveQueryCredentialsAndNavigateTo = async (passkeySessionID: string,response: string,) => {+ // This function's implementation is on the same lines as that of the+ // `saveCredentialsAndNavigateTo` function in passkey utilities.+const inflightPasskeySessionID = nullToUndefined(sessionStorage.getItem("inflightPasskeySessionID"),);diff --git a/web/packages/accounts/services/accounts-db.ts b/web/packages/accounts/services/accounts-db.tsindex acc4ac5aa2..8582d619ec 100644--- a/web/packages/accounts/services/accounts-db.ts+++ b/web/packages/accounts/services/accounts-db.ts@@ -3,6 +3,7 @@ import log from "ente-base/log";import { nullToUndefined } from "ente-utils/transform";import { z } from "zod/v4";import { RemoteKeyAttributes, type KeyAttributes } from "./user";+import { RemoteSRPAttributes, type SRPAttributes } from "./srp";export type LocalStorageKey =| "user"@@ -179,6 +180,27 @@ export const saveOriginalKeyAttributes = (keyAttributes: KeyAttributes) =>JSON.stringify(keyAttributes),);+/**+ * Return the user's {@link SRPAttributes} if they are present in local storage.+ *+ * Like key attributes, SRP attributes are also stored in the browser's local+ * storage so will not be accessible to web workers.+ */+export const savedSRPAttributes = (): SRPAttributes | undefined => {+ const jsonString = localStorage.getItem("srpAttributes");+ if (!jsonString) return undefined;+ return RemoteSRPAttributes.parse(JSON.parse(jsonString));+};++/**+ * Save the user's {@link SRPAttributes} in local storage.+ *+ * Use {@link savedSRPAttributes} to retrieve them.+ */+export const saveSRPAttributes = (srpAttributes: SRPAttributes) =>+ localStorage.setItem("srpAttributes", JSON.stringify(srpAttributes));++export const getToken = (): string => {const token = getData("user")?.token;return token;diff --git a/web/packages/accounts/services/passkey.ts b/web/packages/accounts/services/passkey.tsindex 9b7bbd0515..47ed81dfac 100644--- a/web/packages/accounts/services/passkey.ts+++ b/web/packages/accounts/services/passkey.ts@@ -1,6 +1,6 @@import {getData,- setData,+ saveKeyAttributes,setLSUser,} from "ente-accounts/services/accounts-db";import { TwoFactorAuthorizationResponse } from "ente-accounts/services/user";@@ -243,12 +243,13 @@ export const checkPasskeyVerificationStatus = async (export const saveCredentialsAndNavigateTo = async (response: TwoFactorAuthorizationResponse,) => {- // This method somewhat duplicates `saveCredentialsAndNavigateTo` in the- // /passkeys/finish page.+ // The implementation is similar to the `saveQueryCredentialsAndNavigateTo`+ // function on the "/passkeys/finish" page.+const { id, encryptedToken, keyAttributes } = response;await setLSUser({ ...getData("user"), encryptedToken, id });- setData("keyAttributes", keyAttributes);+ saveKeyAttributes(keyAttributes);return unstashRedirect() ?? "/credentials";};diff --git a/web/packages/accounts/services/srp.ts b/web/packages/accounts/services/srp.tsindex 8618957f89..3fded86f0c 100644--- a/web/packages/accounts/services/srp.ts+++ b/web/packages/accounts/services/srp.ts@@ -190,7 +190,7 @@ export interface SRPAttributes {* it to local storage, so the same schema describes both the remote type and* the local storage type.*/-const RemoteSRPAttributes = z.object({+export const RemoteSRPAttributes = z.object({srpUserID: z.string(),srpSalt: z.string(),memLimit: z.number(),@@ -221,26 +221,6 @@ export const getSRPAttributes = async (.attributes;};-/**- * Return the user's {@link SRPAttributes} if they are present in local storage.- *- * Like key attributes, SRP attributes are also stored in the browser's local- * storage so will not be accessible to web workers.- */-export const savedSRPAttributes = (): SRPAttributes | undefined => {- const jsonString = localStorage.getItem("srpAttributes");- if (!jsonString) return undefined;- return RemoteSRPAttributes.parse(JSON.parse(jsonString));-};--/**- * Save the user's {@link SRPAttributes} in local storage.- *- * Use {@link savedSRPAttributes} to retrieve them.- */-export const saveSRPAttributes = (srpAttributes: SRPAttributes) =>- localStorage.setItem("srpAttributes", JSON.stringify(srpAttributes));-/*** A local-only structure holding information required for SRP setup.*diff --git a/web/packages/accounts/services/user.ts b/web/packages/accounts/services/user.tsindex c34a178d07..eb54e1b94c 100644--- a/web/packages/accounts/services/user.ts+++ b/web/packages/accounts/services/user.ts@@ -2,12 +2,12 @@ import {getData,savedKeyAttributes,saveKeyAttributes,+ saveSRPAttributes,setLSUser,} from "ente-accounts/services/accounts-db";import {generateSRPSetupAttributes,getSRPAttributes,- saveSRPAttributes,updateSRPAndKeyAttributes,type UpdatedKeyAttr,} from "ente-accounts/services/srp";