More gohst user

This commit is contained in:
Daniel Hougaard
2024-02-22 05:00:35 +01:00
parent c33741d588
commit e445970f36
5 changed files with 49 additions and 178 deletions
+21
View File
@@ -1,3 +1,5 @@
import crypto from "crypto";
import { ProjectMembershipRole, TProjectKeys } from "@app/db/schemas";
import { decryptAsymmetric, encryptAsymmetric } from "../crypto";
@@ -37,3 +39,22 @@ export const createWsMembers = ({ members, decryptKey, userPrivateKey }: AddUser
return newWsMembers;
};
type TCreateWorkspaceKeyDTO = {
publicKey: string;
privateKey: string;
};
export const createWorkspaceKey = ({ publicKey, privateKey }: TCreateWorkspaceKeyDTO) => {
// 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 };
};