π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Update the embedding layer
Manav Rathi5536f7ac039d
diff --git a/web/packages/base/crypto/ente.ts b/web/packages/base/crypto/ente.tsindex 335330fde8..121532e9d3 100644--- a/web/packages/base/crypto/ente.ts+++ b/web/packages/base/crypto/ente.ts@@ -36,15 +36,16 @@ import * as libsodium from "@ente/shared/crypto/internal/libsodium";export const encryptFileAssociatedData = libsodium.encryptChaChaOneShot;/**- * A variant of {@link encryptFileAssociatedData} that returns the Base64- * encoded encrypted data instead of its raw bytes.+ * Encrypted the embedding associated with a file using the file's key.*- * This is the sibling of {@link decryptFileAssociatedDataFromB64}.+ * This as a variant of {@link encryptFileAssociatedData} tailored for+ * encrypting the embeddings (a.k.a. derived data) associated with a file. In+ * particular, it returns the encrypted data in the result as a Base64 string+ * instead of its bytes.*- * It is useful in cases where the (encrypted) associated data needs to- * transferred as the HTTP POST body.+ * Use {@link decryptFileEmbedding} to decrypt the result.*/-export const encryptFileAssociatedDataToB64 = async (+export const encryptFileEmbedding = async (data: Uint8Array,keyB64: string,) => {@@ -102,9 +103,9 @@ export const encryptFileMetadata = async (export const decryptFileAssociatedData = libsodium.decryptChaChaOneShot2;/**- * Decrypt arbitrary data associated with a file using the file's key.+ * Decrypt the embedding associated with a file using the file's key.*- * This is the sibling of {@link encryptFileAssociatedDataToB64}.+ * This is the sibling of {@link encryptFileEmbedding}.** @param encryptedDataB64 Base64 encoded string containing the encrypted data.*@@ -117,13 +118,13 @@ export const decryptFileAssociatedData = libsodium.decryptChaChaOneShot2;** @returns The decrypted metadata bytes.*/-export const decryptFileAssociatedDataFromB64 = async (+export const decryptFileEmbedding = async (encryptedDataB64: string,decryptionHeaderB64: string,keyB64: string,) =>- libsodium.decryptChaChaOneShot(+ decryptFileAssociatedData(await libsodium.fromB64(encryptedDataB64),- await libsodium.fromB64(decryptionHeaderB64),+ decryptionHeaderB64,keyB64,);diff --git a/web/packages/new/photos/services/ml/embedding.ts b/web/packages/new/photos/services/ml/embedding.tsindex d405327513..2c96f43152 100644--- a/web/packages/new/photos/services/ml/embedding.ts+++ b/web/packages/new/photos/services/ml/embedding.ts@@ -1,7 +1,4 @@-import {- decryptFileAssociatedDataFromB64,- encryptFileAssociatedDataToB64,-} from "@/base/crypto/ente";+import { decryptFileEmbedding, encryptFileEmbedding } from "@/base/crypto/ente";import { authenticatedRequestHeaders, ensureOk } from "@/base/http";import log from "@/base/log";import { apiURL } from "@/base/origins";@@ -198,7 +195,7 @@ export const fetchDerivedData = async (}try {- const decryptedBytes = await decryptFileAssociatedDataFromB64(+ const decryptedBytes = await decryptFileEmbedding(remoteEmbedding.encryptedEmbedding,remoteEmbedding.decryptionHeader,file.key,@@ -297,7 +294,7 @@ const putEmbedding = async (embedding: Uint8Array,) => {const { encryptedDataB64, decryptionHeaderB64 } =- await encryptFileAssociatedDataToB64(embedding, enteFile.key);+ await encryptFileEmbedding(embedding, enteFile.key);const res = await fetch(await apiURL("/embeddings"), {method: "PUT",