Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

refactor

Manav Rathi2163a5fbeae8
diff --git a/web/packages/new/photos/services/user-entity/index.ts b/web/packages/new/photos/services/user-entity/index.ts
index d32b8eaf1c..0186c326fb 100644
--- a/web/packages/new/photos/services/user-entity/index.ts
+++ b/web/packages/new/photos/services/user-entity/index.ts
@@ -173,13 +173,7 @@ export const addOrUpdateUserEntity = async (
id: string | undefined,
masterKey: Uint8Array,
) => {
- const entityKeyB64 = await getOrCreateEntityKeyB64(type, masterKey);
-
- const json = JSON.stringify(data);
- const bytes = isGzipped(type)
- ? await gzip(json)
- : new TextEncoder().encode(json);
- const encryptedBlob = await encryptBlobB64(bytes, entityKeyB64);
+ const encryptedBlob = await encryptedUserEntityData(type, data, masterKey);
await (id
? putUserEntity(id, type, encryptedBlob)
@@ -189,6 +183,20 @@ export const addOrUpdateUserEntity = async (
return pullUserEntities(type, masterKey);
};
+export const encryptedUserEntityData = async (
+ type: EntityType,
+ data: unknown,
+ masterKey: Uint8Array,
+) => {
+ const entityKeyB64 = await getOrCreateEntityKeyB64(type, masterKey);
+
+ const json = JSON.stringify(data);
+ const bytes = isGzipped(type)
+ ? await gzip(json)
+ : new TextEncoder().encode(json);
+ return encryptBlobB64(bytes, entityKeyB64);
+};
+
/**
* Return the entity key that can be used to decrypt the encrypted contents of
* user entities of the given {@link type}.