diff --git a/web/packages/base/crypto/ente-impl.ts b/web/packages/base/crypto/ente-impl.ts index 831dab029c..a5c5b93c0e 100644 --- a/web/packages/base/crypto/ente-impl.ts +++ b/web/packages/base/crypto/ente-impl.ts @@ -20,13 +20,13 @@ export const _encryptAssociatedData = libsodium.encryptChaChaOneShot; export const _encryptThumbnail = _encryptAssociatedData; -export const _encryptMetadataBytes = (r: EncryptBytes) => +export const _encryptAssociatedB64Data = (r: EncryptBytes) => _encryptAssociatedData(r).then(EncryptedBytesToB64); -export const _encryptFileEmbedding = _encryptMetadataBytes; +export const _encryptFileEmbedding = _encryptAssociatedB64Data; export const _encryptMetadataJSON = ({ jsonValue, keyB64 }: EncryptJSON) => - _encryptMetadataBytes({ + _encryptAssociatedB64Data({ data: new TextEncoder().encode(JSON.stringify(jsonValue)), keyB64, }); @@ -35,7 +35,7 @@ export const _decryptAssociatedData = libsodium.decryptChaChaOneShot; export const _decryptThumbnail = _decryptAssociatedData; -export const _decryptMetadataBytes = async ({ +export const _decryptAssociatedB64Data = async ({ encryptedDataB64, decryptionHeaderB64, keyB64, @@ -46,9 +46,9 @@ export const _decryptMetadataBytes = async ({ keyB64, }); -export const _decryptFileEmbedding = _decryptMetadataBytes; +export const _decryptFileEmbedding = _decryptAssociatedB64Data; export const _decryptMetadataJSON = async (r: DecryptB64) => JSON.parse( - new TextDecoder().decode(await _decryptMetadataBytes(r)), + new TextDecoder().decode(await _decryptAssociatedB64Data(r)), ) as unknown; diff --git a/web/packages/base/crypto/ente.ts b/web/packages/base/crypto/ente.ts index eaa8482eab..0a2b394f94 100644 --- a/web/packages/base/crypto/ente.ts +++ b/web/packages/base/crypto/ente.ts @@ -93,18 +93,18 @@ export const encryptThumbnail = (r: EncryptBytes) => assertInWorker(ei._encryptThumbnail(r)); /** - * A variant of {@link encryptAssociatedData} that returns the encrypted data in - * the result as a base64 string instead of its bytes. + * A variant of {@link encryptAssociatedData} that returns the encrypted data as + * a base64 string instead of returning its bytes. * - * Use {@link decryptMetadataBytes} to decrypt the result. + * Use {@link decryptAssociatedB64Data} to decrypt the result. */ -export const encryptMetadataBytes = (r: EncryptBytes) => - assertInWorker(ei._encryptMetadataBytes(r)); +export const encryptAssociatedB64Data = (r: EncryptBytes) => + assertInWorker(ei._encryptAssociatedB64Data(r)); /** * Encrypted the embedding associated with a file using the file's key. * - * This is just an alias for {@link encryptMetadataBytes}. + * This is just an alias for {@link encryptAssociatedB64Data}. * * Use {@link decryptFileEmbedding} to decrypt the result. */ @@ -151,14 +151,15 @@ export const decryptThumbnail = (r: DecryptBytes) => assertInWorker(ei._decryptThumbnail(r)); /** - * Decrypt metadata associated with an Ente object. + * A variant of {@link decryptAssociatedData} that expects the encrypted data as + * a base64 encoded string. * - * This is the sibling of {@link decryptMetadataBytes}. + * This is the sibling of {@link decryptAssociatedB64Data}. */ -export const decryptMetadataBytes = (r: DecryptB64) => +export const decryptAssociatedB64Data = (r: DecryptB64) => inWorker() - ? ei._decryptMetadataBytes(r) - : sharedCryptoWorker().then((w) => w.decryptMetadataBytes(r)); + ? ei._decryptAssociatedB64Data(r) + : sharedCryptoWorker().then((w) => w.decryptAssociatedB64Data(r)); /** * Decrypt the embedding associated with a file using the file's key. diff --git a/web/packages/base/crypto/worker.ts b/web/packages/base/crypto/worker.ts index 32b62b327a..c4a1dc1b62 100644 --- a/web/packages/base/crypto/worker.ts +++ b/web/packages/base/crypto/worker.ts @@ -15,7 +15,7 @@ export class CryptoWorker { encryptThumbnail = ei._encryptThumbnail; encryptMetadataJSON = ei._encryptMetadataJSON; decryptThumbnail = ei._decryptThumbnail; - decryptMetadataBytes = ei._decryptMetadataBytes; + decryptAssociatedB64Data = ei._decryptAssociatedB64Data; decryptMetadataJSON = ei._decryptMetadataJSON; // TODO: -- AUDIT BELOW -- diff --git a/web/packages/new/photos/services/user-entity.ts b/web/packages/new/photos/services/user-entity.ts index 3383ed42de..6be7c699be 100644 --- a/web/packages/new/photos/services/user-entity.ts +++ b/web/packages/new/photos/services/user-entity.ts @@ -1,4 +1,4 @@ -import { decryptMetadataBytes } from "@/base/crypto/ente"; +import { decryptAssociatedB64Data } from "@/base/crypto/ente"; import { authenticatedRequestHeaders, ensureOk } from "@/base/http"; import { apiURL } from "@/base/origins"; import { z } from "zod"; @@ -92,7 +92,7 @@ export const userEntityDiff = async ( entityKeyB64: string, ): Promise => { const decrypt = (encryptedDataB64: string, decryptionHeaderB64: string) => - decryptMetadataBytes({ + decryptAssociatedB64Data({ encryptedDataB64, decryptionHeaderB64, keyB64: entityKeyB64,