π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Take 1 at remote type
Manav Rathi114ff5dc9bad
diff --git a/web/apps/cast/src/services/render.ts b/web/apps/cast/src/services/render.tsindex 65463014b4..b3f6ad3417 100644--- a/web/apps/cast/src/services/render.ts+++ b/web/apps/cast/src/services/render.ts@@ -233,7 +233,6 @@ const decryptEnteFile = async (key: fileKey,// @ts-expect-error The types need to be updated heremetadata: fileMetadata,- // @ts-expect-error The types need to be updated heremagicMetadata: fileMagicMetadata,pubMagicMetadata: filePubMagicMetadata,});diff --git a/web/packages/media/collection.ts b/web/packages/media/collection.tsindex d60c6a5326..458bfb3fb9 100644--- a/web/packages/media/collection.ts+++ b/web/packages/media/collection.ts@@ -345,7 +345,7 @@ export interface PublicURL {}/**- * Zod schema for the {@link PublicURL2} we use in our interactions with remote.+ * Zod schema for the {@link PublicURL} we use in our interactions with remote.** We also use the same schema when persisting the collection locally.*/diff --git a/web/packages/media/file-metadata.ts b/web/packages/media/file-metadata.tsindex e501ae457a..953239e8bb 100644--- a/web/packages/media/file-metadata.ts+++ b/web/packages/media/file-metadata.ts@@ -385,8 +385,6 @@ const PublicMagicMetadata = z.looseObject({* check/cast shouldn't be needed, and this should become a trivial accessor.*/export const filePrivateMagicMetadata = (file: EnteFile) => {- // TODO: Audit the types.- // eslint-disable-next-line @typescript-eslint/no-unnecessary-conditionif (!file.magicMetadata) return undefined;if (typeof file.magicMetadata.data == "string") {throw new Error(@@ -570,7 +568,6 @@ export const updateRemotePrivateMagicMetadata = async (const updatedMetadata = { ...(existingMetadata ?? {}), ...metadataUpdates };- // eslint-disable-next-line @typescript-eslint/no-unnecessary-conditionconst metadataVersion = file.magicMetadata?.version ?? 1;const updateRequest = await updateMagicMetadataRequest(diff --git a/web/packages/media/file.ts b/web/packages/media/file.tsindex fb10c7fb78..6dbe12ab9a 100644--- a/web/packages/media/file.ts+++ b/web/packages/media/file.ts@@ -1,60 +1,11 @@import { sharedCryptoWorker } from "ente-base/crypto";import { dateFromEpochMicroseconds } from "ente-base/date";import log from "ente-base/log";+import { nullToUndefined } from "ente-utils/transform";+import { z } from "zod/v4";import { type Metadata, ItemVisibility } from "./file-metadata";import { FileType } from "./file-type";--// TODO: Audit this file.--export interface MetadataFileAttributes {- encryptedData: string;- decryptionHeader: string;-}--/**- * Attributes about an object uploaded to S3.- *- * TODO: Split between fields needed during upload, and the fields we get back- * from remote in the /diff response.- */-export interface S3FileAttributes {- /**- * Upload only: This should be present during upload, but is not returned- * back from remote in the /diff response.- */- objectKey: string;- /**- * Upload and diff: This is present both during upload and also returned by- * remote in the /diff response.- */- decryptionHeader: string;- /**- * The size of the file, in bytes.- *- * For both file and thumbnails, the client also sends the size of the- * encrypted file (as per the client) while creating a new object on remote.- * This allows the server to validate that the size of the objects is same- * as what client is reporting.- *- * Upload only: This should be present during upload, but is not returned- * back from remote in the /diff response.- */- size: number;-}--/**- * Static information associated with a file.- */-export interface FileInfo {- /**- * The size of the file (in bytes).- */- fileSize: number;- /**- * The size of the thumbnail associated with the file (in bytes).- */- thumbSize: number;-}+import { RemoteMagicMetadata } from "./magic-metadata";export interface MagicMetadataCore<T> {version: number;@@ -99,14 +50,13 @@ export interface EncryptedEnteFile {/*** Static, remote visible, information associated with a file.*- * This is information about storage used by the file and its metadata (in- * the future if needed). Unlike {@link metadata} which is E2EE, the- * {@link FileInfo} is remote visible for bookkeeping purposes.+ * This is information about storage used by the file and its thumbnail.+ * Unlike {@link metadata} which is E2EE, the {@link FileInfo} is remote+ * visible for bookkeeping purposes.*- * Files uploaded by very old versions of Ente might not have this structure- * present.+ * Files uploaded by very old versions of Ente might not have this field.*/- info: FileInfo | undefined;+ info?: FileInfo;magicMetadata: EncryptedMagicMetadata;pubMagicMetadata: EncryptedMagicMetadata;/**@@ -126,6 +76,11 @@ export interface EncryptedEnteFile {*/keyDecryptionNonce: string;isDeleted: boolean;+ /**+ * The last time the file was updated (epoch microseconds).+ *+ * (e.g. magic metadata updates).+ */updationTime: number;}@@ -172,11 +127,17 @@ export interface EnteFile*/key: string;/**- * Static metadata associated with a file.+ * Public static metadata associated with a file.** This is the immutable metadata that gets associated with a file when it* is uploaded, and there after cannot be changed.*+ * It is visible to all users with whom the file gets shared.+ *+ * > {@link pubMagicMetadata} contains fields that override fields present+ * > in the metadata. Clients overlay those atop the metadata fields, and+ * > thus they can be used to implement edits.+ ** See: [Note: Metadatum].*/metadata: Metadata;@@ -186,7 +147,7 @@ export interface EnteFile** See: [Note: Metadatum]*/- magicMetadata: FileMagicMetadata;+ magicMetadata?: FileMagicMetadata;/*** Public mutable metadata associated with the file that is visible to all* users with whom the file has been shared.@@ -204,12 +165,113 @@ export interface EnteFile*/isTrashed?: boolean;/**- * If this is a file in trash, then {@link deleteBy} contains the epoch+ * If {@link isTrashed} is `true`, then {@link deleteBy} contains the epoch* microseconds when this file will be permanently deleted.*/deleteBy?: number;}+export interface MetadataFileAttributes {+ encryptedData: string;+ decryptionHeader: string;+}++/**+ * Attributes about an object uploaded to S3.+ *+ * TODO: Split between fields needed during upload, and the fields we get back+ * from remote in the /diff response.+ */+export interface S3FileAttributes {+ /**+ * Upload only: This should be present during upload, but is not returned+ * back from remote in the /diff response.+ */+ objectKey: string;+ /**+ * Upload and diff: This is present both during upload and also returned by+ * remote in the /diff response.+ */+ decryptionHeader: string;+ /**+ * The size of the file, in bytes.+ *+ * For both file and thumbnails, the client also sends the size of the+ * encrypted file (as per the client) while creating a new object on remote.+ * This allows the server to validate that the size of the objects is same+ * as what client is reporting.+ *+ * Upload only: This should be present during upload, but is not returned+ * back from remote in the /diff response.+ */+ size: number;+}++/**+ * Static information associated with a file.+ */+export interface FileInfo {+ /**+ * The size of the file (in bytes).+ */+ fileSize: number;+ /**+ * The size of the thumbnail associated with the file (in bytes).+ */+ thumbSize: number;+}++const RemoteFileInfo = z.looseObject({+ fileSize: z.number(),+ thumbSize: z.number(),+});++/**+ * Zod schema for a {@link EnteFile} as represented in our interactions with+ * remote.+ *+ * The contents of the fields are encrypted by the file's key (which itself is+ * encrypted by the key of the collection that contains the file). EnteFile is+ * the decrypted local representation.+ *+ * See: [Note: Use looseObject when parsing JSON that will get persisted]+ */+// TODO(RE): Use me+export const RemoteEnteFile = z.looseObject({+ id: z.number(),+ collectionID: z.number(),+ ownerID: z.number(),+ /**+ * The file's key, encrypted using the key of the collection that contains+ * the file.+ *+ * Base64 encoded.+ */+ encryptedKey: z.string(),+ /**+ * The nonce to use when decrypting {@link encryptedKey}.+ *+ * Base64 encoded.+ */+ keyDecryptionNonce: z.string(),+ file: z.unknown(),+ thumbnail: z.unknown(),+ info: RemoteFileInfo.nullish().transform(nullToUndefined),+ updationTime: z.number(),+ /**+ * Tombstone marker.+ *+ * This is set to true in the diff response to indicate files which+ * have been deleted and should thus be pruned by the client locally.+ */+ isDeleted: z.boolean().nullish().transform(nullToUndefined),+ metadata: z.unknown(),+ magicMetadata: RemoteMagicMetadata.nullish().transform(nullToUndefined),+ pubMagicMetadata: RemoteMagicMetadata.nullish().transform(nullToUndefined),+ isTrashed: z.boolean().nullish().transform(nullToUndefined),+ deleteBy: z.number().nullish().transform(nullToUndefined),+});+export interface FileWithUpdatedMagicMetadata {file: EnteFile;updatedMagicMetadata: FileMagicMetadata;