feat: use hash as pw & move to symmetric encrpytion

This commit is contained in:
ShubhamPalriwala
2024-05-29 14:10:47 +05:30
parent b5b778e241
commit 286426b240
10 changed files with 89 additions and 119 deletions
@@ -16,13 +16,16 @@ export const secretSharingServiceFactory = ({
secretSharingDAL
}: TSecretSharingServiceFactoryDep) => {
const createSharedSecret = async (createSharedSecretInput: TCreateSharedSecretDTO) => {
const { actor, actorId, orgId, actorAuthMethod, actorOrgId, name, signedValue, expiresAt } =
const { actor, actorId, orgId, actorAuthMethod, actorOrgId, name, encryptedValue, iv, tag, hashedHex, expiresAt } =
createSharedSecretInput;
const { permission } = await permissionService.getOrgPermission(actor, actorId, orgId, actorAuthMethod, actorOrgId);
if (!permission) throw new UnauthorizedError({ name: "User not in org" });
const newSharedSecret = await secretSharingDAL.create({
name,
signedValue,
encryptedValue,
iv,
tag,
hashedHex,
expiresAt,
userId: actorId,
orgId
@@ -38,8 +41,8 @@ export const secretSharingServiceFactory = ({
return userSharedSecrets;
};
const getActiveSharedSecretById = async (sharedSecretId: string) => {
const sharedSecret = await secretSharingDAL.findById(sharedSecretId);
const getActiveSharedSecretByIdAndHashedHex = async (sharedSecretId: string, hashedHex: string) => {
const sharedSecret = await secretSharingDAL.findOne({ id: sharedSecretId, hashedHex });
if (sharedSecret && sharedSecret.expiresAt < new Date()) {
return;
}
@@ -58,6 +61,6 @@ export const secretSharingServiceFactory = ({
createSharedSecret,
getSharedSecrets,
deleteSharedSecretById,
getActiveSharedSecretById
getActiveSharedSecretByIdAndHashedHex
};
};
@@ -10,7 +10,10 @@ export type TSharedSecretPermission = {
export type TCreateSharedSecretDTO = {
name: string;
signedValue: string;
encryptedValue: string;
iv: string;
tag: string;
hashedHex: string;
expiresAt: Date;
} & TSharedSecretPermission;