Skip to content

armgit / ente

Public Imported from GitHub
0

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

Rearrange

Manav Rathi85020a490eb3
diff --git a/web/packages/base/crypto/ente.ts b/web/packages/base/crypto/ente.ts
index e28583137f..7b09d3c02f 100644
--- a/web/packages/base/crypto/ente.ts
+++ b/web/packages/base/crypto/ente.ts
@@ -3,25 +3,25 @@
*
* [Note: Crypto code hierarchy]
*
- * 1. ente.ts or crypto.worker.ts (high level, Ente specific).
- * 2. internal/libsodium.ts (wrappers over libsodium)
- * 3. libsodium (JS bindings).
+ * 1. crypto/ente.ts (Ente specific higher level functions)
+ * 2. crypto/libsodium.ts (More primitive wrappers over libsodium)
+ * 3. libsodium-wrappers (JavaScript bindings to libsodium)
*
* Our cryptography primitives are provided by libsodium, specifically, its
* JavaScript bindings ("libsodium-wrappers"). This is the lowest layer.
*
- * Direct usage of "libsodium-wrappers" is restricted to
- * `crypto/internal/libsodium.ts`. This is the next higher layer, and the first
- * one that our code should directly use. Usually the functions in this file are
- * thin wrappers over the raw libsodium APIs, with a bit of massaging or
- * book-keeping. They also ensure that sodium.ready has been called before
- * accessing libsodium's APIs, thus all the functions it exposes are async.
+ * Direct usage of "libsodium-wrappers" is restricted to `crypto/libsodium.ts`.
+ * This is the next higher layer, and the first one that our code should
+ * directly use. Usually the functions in this file are thin wrappers over the
+ * raw libsodium APIs, with a bit of massaging. They also ensure that
+ * sodium.ready has been called before accessing libsodium's APIs, thus all the
+ * functions it exposes are async.
*
* The final layer is this file, `crypto/ente.ts`. These are usually thin
- * wrappers themselves over functions exposed by `internal/libsodium.ts`, but
- * the difference is that the functions in ente.ts don't talk in terms of the
- * crypto algorithms, but rather in terms the higher-level Ente specific goal we
- * are trying to accomplish.
+ * wrappers themselves over functions exposed by `crypto/libsodium.ts`, but the
+ * difference is that the functions in ente.ts don't talk in terms of the crypto
+ * algorithms, but rather in terms the higher-level Ente specific goal we are
+ * trying to accomplish.
*
* There is an additional actor in the play. Cryptographic operations are CPU
* intensive and would cause the UI to stutter if used directly on the main
@@ -42,9 +42,9 @@
* recommendation though (in circumstances where we create more crypto workers
* instead of using the shared one).
*/
-import ComlinkCryptoWorker from "@ente/shared/crypto";
-import * as libsodium from "@ente/shared/crypto/internal/libsodium";
import { inWorker } from "../env";
+import * as libsodium from "./libsodium";
+import ComlinkCryptoWorker from "./worker";
const cryptoWorker = () => ComlinkCryptoWorker.getInstance();
diff --git a/web/packages/shared/crypto/internal/libsodium.ts b/web/packages/base/crypto/libsodium.ts
similarity index 98%
rename from web/packages/shared/crypto/internal/libsodium.ts
rename to web/packages/base/crypto/libsodium.ts
index 7a3e720319..cf30256a86 100644
--- a/web/packages/shared/crypto/internal/libsodium.ts
+++ b/web/packages/base/crypto/libsodium.ts
@@ -311,6 +311,8 @@ export const decryptChaCha = async (
pullState,
buffer,
);
+ // TODO:
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!pullResult.message) {
throw new Error(CustomError.PROCESSING_FAILED);
}
@@ -343,6 +345,8 @@ export async function decryptFileChunk(
pullState,
data,
);
+ // TODO:
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (!pullResult.message) {
throw new Error(CustomError.PROCESSING_FAILED);
}
diff --git a/web/packages/shared/crypto/index.ts b/web/packages/base/crypto/worker/index.ts
similarity index 80%
rename from web/packages/shared/crypto/index.ts
rename to web/packages/base/crypto/worker/index.ts
index ed3d47e155..8d4f50e4bf 100644
--- a/web/packages/shared/crypto/index.ts
+++ b/web/packages/base/crypto/worker/index.ts
@@ -1,6 +1,6 @@
import { ComlinkWorker } from "@/base/worker/comlink-worker";
import type { Remote } from "comlink";
-import { type DedicatedCryptoWorker } from "./internal/crypto.worker";
+import { type DedicatedCryptoWorker } from "./worker";
class ComlinkCryptoWorker {
private comlinkWorkerInstance:
@@ -18,8 +18,8 @@ class ComlinkCryptoWorker {
export const getDedicatedCryptoWorker = () => {
const cryptoComlinkWorker = new ComlinkWorker<typeof DedicatedCryptoWorker>(
- "ente-crypto-worker",
- new Worker(new URL("internal/crypto.worker.ts", import.meta.url)),
+ "Crypto",
+ new Worker(new URL("./worker.ts", import.meta.url)),
);
return cryptoComlinkWorker;
};
diff --git a/web/packages/shared/crypto/internal/crypto.worker.ts b/web/packages/base/crypto/worker/worker.ts
similarity index 97%
rename from web/packages/shared/crypto/internal/crypto.worker.ts
rename to web/packages/base/crypto/worker/worker.ts
index 319d75c57d..9fff54f61f 100644
--- a/web/packages/shared/crypto/internal/crypto.worker.ts
+++ b/web/packages/base/crypto/worker/worker.ts
@@ -1,7 +1,7 @@
-import * as ente from "@/base/crypto/ente";
-import * as libsodium from "@ente/shared/crypto/internal/libsodium";
import { expose } from "comlink";
import type { StateAddress } from "libsodium-wrappers";
+import * as ente from "../ente";
+import * as libsodium from "../libsodium";
/**
* A web worker that exposes some of the functions defined in either the Ente