From fe7524fca19639c0b4e5431a878b1b211548f503 Mon Sep 17 00:00:00 2001 From: Daniel Hougaard <62331820+DanielHougaard@users.noreply.github.com> Date: Sat, 17 Feb 2024 01:02:52 +0100 Subject: [PATCH] Requested changes --- backend/src/lib/crypto/srp.ts | 4 --- backend/src/lib/project/index.ts | 60 -------------------------------- 2 files changed, 64 deletions(-) delete mode 100644 backend/src/lib/project/index.ts diff --git a/backend/src/lib/crypto/srp.ts b/backend/src/lib/crypto/srp.ts index d0d290be1..6f4588e3f 100644 --- a/backend/src/lib/crypto/srp.ts +++ b/backend/src/lib/crypto/srp.ts @@ -8,10 +8,6 @@ import { TUserEncryptionKeys } from "@app/db/schemas"; import { decryptSymmetric, encryptAsymmetric, encryptSymmetric } from "./encryption"; -// Importing the argon2 constants from the argon2 module fails due to an issue with importing commonjs modules. -// Read more: https://stackoverflow.com/questions/70605320/named-export-types-not-found-the-requested-module-mongoose-is-a-commonjs-mo -const ARGON_2_ID = 2; - export const generateSrpServerKey = async (salt: string, verifier: string) => { // eslint-disable-next-line new-cap const server = new jsrp.server(); diff --git a/backend/src/lib/project/index.ts b/backend/src/lib/project/index.ts deleted file mode 100644 index e0ed0d70b..000000000 --- a/backend/src/lib/project/index.ts +++ /dev/null @@ -1,60 +0,0 @@ -import crypto from "crypto"; - -import { ProjectMembershipRole, TProjectKeys } from "@app/db/schemas"; - -import { decryptAsymmetric, encryptAsymmetric } from "../crypto"; - -type AddUserToWsDTO = { - decryptKey: TProjectKeys & { sender: { publicKey: string } }; - userPrivateKey: string; - members: { - orgMembershipId: string; - projectMembershipRole: ProjectMembershipRole; - userPublicKey: string; - }[]; -}; - -export const createWsMembers = ({ members, decryptKey, userPrivateKey }: AddUserToWsDTO) => { - const key = decryptAsymmetric({ - ciphertext: decryptKey.encryptedKey, - nonce: decryptKey.nonce, - publicKey: decryptKey.sender.publicKey, - privateKey: userPrivateKey - }); - - const newWsMembers = members.map(({ orgMembershipId, userPublicKey, projectMembershipRole }) => { - const { ciphertext: inviteeCipherText, nonce: inviteeNonce } = encryptAsymmetric( - key, - userPublicKey, - userPrivateKey - ); - - return { - orgMembershipId, - projectRole: projectMembershipRole, - workspaceEncryptedKey: inviteeCipherText, - workspaceEncryptedNonce: inviteeNonce - }; - }); - - return newWsMembers; -}; - -type TCreateProjectKeyDTO = { - publicKey: string; - privateKey: string; -}; - -export const createProjectKey = ({ publicKey, privateKey }: TCreateProjectKeyDTO) => { - // 3. Create a random key that we'll use as the project key. - const randomBytes = crypto.randomBytes(16).toString("hex"); - - // 4. Encrypt the project key with the users key pair. - const { ciphertext: encryptedProjectKey, nonce: encryptedProjectKeyIv } = encryptAsymmetric( - randomBytes, - publicKey, - privateKey - ); - - return { key: encryptedProjectKey, iv: encryptedProjectKeyIv }; -};