feat: change field password to hashedPassword

This commit is contained in:
=
2024-06-12 23:04:10 +05:30
parent e95109c446
commit 21bd468307
6 changed files with 10 additions and 10 deletions
@@ -3,7 +3,7 @@ import { Knex } from "knex";
import { TableName } from "../schemas"; import { TableName } from "../schemas";
export async function up(knex: Knex): Promise<void> { export async function up(knex: Knex): Promise<void> {
const doesPasswordFieldExist = await knex.schema.hasColumn(TableName.UserEncryptionKey, "password"); const doesPasswordFieldExist = await knex.schema.hasColumn(TableName.UserEncryptionKey, "hashedPassword");
const doesPrivateKeyFieldExist = await knex.schema.hasColumn( const doesPrivateKeyFieldExist = await knex.schema.hasColumn(
TableName.UserEncryptionKey, TableName.UserEncryptionKey,
"serverEncryptedPrivateKey" "serverEncryptedPrivateKey"
@@ -22,7 +22,7 @@ export async function up(knex: Knex): Promise<void> {
); );
if (await knex.schema.hasTable(TableName.UserEncryptionKey)) { if (await knex.schema.hasTable(TableName.UserEncryptionKey)) {
await knex.schema.alterTable(TableName.UserEncryptionKey, (t) => { await knex.schema.alterTable(TableName.UserEncryptionKey, (t) => {
if (!doesPasswordFieldExist) t.string("password"); if (!doesPasswordFieldExist) t.string("hashedPassword");
if (!doesPrivateKeyFieldExist) t.text("serverEncryptedPrivateKey"); if (!doesPrivateKeyFieldExist) t.text("serverEncryptedPrivateKey");
if (!doesPrivateKeyIVFieldExist) t.text("serverEncryptedPrivateKeyIV"); if (!doesPrivateKeyIVFieldExist) t.text("serverEncryptedPrivateKeyIV");
if (!doesPrivateKeyTagFieldExist) t.text("serverEncryptedPrivateKeyTag"); if (!doesPrivateKeyTagFieldExist) t.text("serverEncryptedPrivateKeyTag");
@@ -32,7 +32,7 @@ export async function up(knex: Knex): Promise<void> {
} }
export async function down(knex: Knex): Promise<void> { export async function down(knex: Knex): Promise<void> {
const doesPasswordFieldExist = await knex.schema.hasColumn(TableName.UserEncryptionKey, "password"); const doesPasswordFieldExist = await knex.schema.hasColumn(TableName.UserEncryptionKey, "hashedPassword");
const doesPrivateKeyFieldExist = await knex.schema.hasColumn( const doesPrivateKeyFieldExist = await knex.schema.hasColumn(
TableName.UserEncryptionKey, TableName.UserEncryptionKey,
"serverEncryptedPrivateKey" "serverEncryptedPrivateKey"
@@ -51,7 +51,7 @@ export async function down(knex: Knex): Promise<void> {
); );
if (await knex.schema.hasTable(TableName.UserEncryptionKey)) { if (await knex.schema.hasTable(TableName.UserEncryptionKey)) {
await knex.schema.alterTable(TableName.UserEncryptionKey, (t) => { await knex.schema.alterTable(TableName.UserEncryptionKey, (t) => {
if (doesPasswordFieldExist) t.dropColumn("password"); if (doesPasswordFieldExist) t.dropColumn("hashedPassword");
if (doesPrivateKeyFieldExist) t.dropColumn("serverEncryptedPrivateKey"); if (doesPrivateKeyFieldExist) t.dropColumn("serverEncryptedPrivateKey");
if (doesPrivateKeyIVFieldExist) t.dropColumn("serverEncryptedPrivateKeyIV"); if (doesPrivateKeyIVFieldExist) t.dropColumn("serverEncryptedPrivateKeyIV");
if (doesPrivateKeyTagFieldExist) t.dropColumn("serverEncryptedPrivateKeyTag"); if (doesPrivateKeyTagFieldExist) t.dropColumn("serverEncryptedPrivateKeyTag");
@@ -22,7 +22,7 @@ export const UserEncryptionKeysSchema = z.object({
salt: z.string(), salt: z.string(),
verifier: z.string(), verifier: z.string(),
userId: z.string().uuid(), userId: z.string().uuid(),
password: z.string().nullable().optional(), hashedPassword: z.string().nullable().optional(),
serverEncryptedPrivateKey: z.string().nullable().optional(), serverEncryptedPrivateKey: z.string().nullable().optional(),
serverEncryptedPrivateKeyIV: z.string().nullable().optional(), serverEncryptedPrivateKeyIV: z.string().nullable().optional(),
serverEncryptedPrivateKeyTag: z.string().nullable().optional(), serverEncryptedPrivateKeyTag: z.string().nullable().optional(),
@@ -264,7 +264,7 @@ export const authLoginServiceFactory = ({
await userDAL.updateUserEncryptionByUserId(userEnc.userId, { await userDAL.updateUserEncryptionByUserId(userEnc.userId, {
serverPrivateKey: null, serverPrivateKey: null,
clientPublicKey: null, clientPublicKey: null,
password: hashedPassword, hashedPassword,
serverEncryptedPrivateKey: ciphertext, serverEncryptedPrivateKey: ciphertext,
serverEncryptedPrivateKeyIV: iv, serverEncryptedPrivateKeyIV: iv,
serverEncryptedPrivateKeyTag: tag, serverEncryptedPrivateKeyTag: tag,
@@ -92,7 +92,7 @@ export const authPaswordServiceFactory = ({
verifier, verifier,
serverPrivateKey: null, serverPrivateKey: null,
clientPublicKey: null, clientPublicKey: null,
password: hashedPassword hashedPassword
}); });
if (tokenVersionId) { if (tokenVersionId) {
@@ -183,7 +183,7 @@ export const authSignupServiceFactory = ({
encryptedPrivateKey, encryptedPrivateKey,
iv: encryptedPrivateKeyIV, iv: encryptedPrivateKeyIV,
tag: encryptedPrivateKeyTag, tag: encryptedPrivateKeyTag,
password: hashedPassword, hashedPassword,
serverEncryptedPrivateKeyEncoding: encoding, serverEncryptedPrivateKeyEncoding: encoding,
serverEncryptedPrivateKeyTag: tag, serverEncryptedPrivateKeyTag: tag,
serverEncryptedPrivateKeyIV: iv, serverEncryptedPrivateKeyIV: iv,
@@ -344,7 +344,7 @@ export const authSignupServiceFactory = ({
encryptedPrivateKey, encryptedPrivateKey,
iv: encryptedPrivateKeyIV, iv: encryptedPrivateKeyIV,
tag: encryptedPrivateKeyTag, tag: encryptedPrivateKeyTag,
password: hashedPassword, hashedPassword,
serverEncryptedPrivateKeyEncoding: encoding, serverEncryptedPrivateKeyEncoding: encoding,
serverEncryptedPrivateKeyTag: tag, serverEncryptedPrivateKeyTag: tag,
serverEncryptedPrivateKeyIV: iv, serverEncryptedPrivateKeyIV: iv,
@@ -136,7 +136,7 @@ export const superAdminServiceFactory = ({
tag: encryptedPrivateKeyTag, tag: encryptedPrivateKeyTag,
verifier, verifier,
userId: newUser.id, userId: newUser.id,
password: hashedPassword, hashedPassword,
serverEncryptedPrivateKey: ciphertext, serverEncryptedPrivateKey: ciphertext,
serverEncryptedPrivateKeyIV: iv, serverEncryptedPrivateKeyIV: iv,
serverEncryptedPrivateKeyTag: tag, serverEncryptedPrivateKeyTag: tag,