From 97b2875dd24521541552654624577eb30203249b Mon Sep 17 00:00:00 2001 From: Shreenija Reddy Daggavolu Date: Mon, 10 Jun 2024 12:34:57 -0500 Subject: [PATCH] removed admin-util --- src/services/admin/admin-router.ts | 2 +- src/services/admin/admin-utils.ts | 31 ----------------------- src/services/attendees/attendees-utils.ts | 13 ++++++++++ 3 files changed, 14 insertions(+), 32 deletions(-) delete mode 100644 src/services/admin/admin-utils.ts diff --git a/src/services/admin/admin-router.ts b/src/services/admin/admin-router.ts index 7e3360d..1e0a06c 100644 --- a/src/services/admin/admin-router.ts +++ b/src/services/admin/admin-router.ts @@ -4,7 +4,7 @@ import { Database } from "../../database"; import RoleChecker from "../../middleware/role-checker"; import { Role } from "../auth/auth-models"; import dotenv from "dotenv"; -import { validateQrHash } from "./admin-utils"; +import { validateQrHash } from "../attendees/attendees-utils"; const adminRouter = Router(); diff --git a/src/services/admin/admin-utils.ts b/src/services/admin/admin-utils.ts deleted file mode 100644 index 6af110b..0000000 --- a/src/services/admin/admin-utils.ts +++ /dev/null @@ -1,31 +0,0 @@ -import crypto from "crypto"; -import { Config } from "../../config"; - -export function generateQrHash(userId: string, expTime: number) { - let hashStr = userId + "#" + expTime; - const hashIterations = Config.QR_HASH_ITERATIONS; - const hashSecret = Config.QR_HASH_SECRET; - - const hmac = crypto.createHmac("sha256", hashSecret); - hashStr = hmac.update(hashStr).digest("hex"); - - for (let i = 0; i < hashIterations; i++) { - const hash = crypto.createHash("sha256"); - hashStr = hash.update(hashSecret + "#" + hashStr).digest("hex"); - } - - return `${hashStr}#${expTime}#${userId}`; -} - -export function validateQrHash(qrCode: string) { - const parts = qrCode.split("#"); - const userId = parts[2]; - const expTime = parseInt(parts[1]); - const generatedHash = generateQrHash(userId, expTime); - - if (generatedHash.split("#")[0] !== parts[0]) { - throw new Error("Invalid QR code"); - } - - return { userId, expTime }; -} diff --git a/src/services/attendees/attendees-utils.ts b/src/services/attendees/attendees-utils.ts index 06a4a5a..44169ad 100644 --- a/src/services/attendees/attendees-utils.ts +++ b/src/services/attendees/attendees-utils.ts @@ -16,3 +16,16 @@ export function generateQrHash(userId: string, expTime: number) { return `${hashStr}#${expTime}#${userId}`; } + +export function validateQrHash(qrCode: string) { + const parts = qrCode.split("#"); + const userId = parts[2]; + const expTime = parseInt(parts[1]); + const generatedHash = generateQrHash(userId, expTime); + + if (generatedHash.split("#")[0] !== parts[0]) { + throw new Error("Invalid QR code"); + } + + return { userId, expTime }; +} \ No newline at end of file