Skip to content

Commit

Permalink
refactor: terser key gen with random bytes func
Browse files Browse the repository at this point in the history
  • Loading branch information
williams-jack committed Aug 2, 2024
1 parent b311d39 commit 3aa0d2f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion orchestrator/packages/db/src/api-key-operations/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { randomBytes } from 'crypto';
import prismaInstance from '../prisma-instance';

const KEY_LENGTH = 64;
Expand All @@ -17,4 +18,4 @@ export const createAPIKey = async (hostname: string): Promise<string> =>
export const validAPIKey = async (hostname: string, value: string) =>
Boolean(await prismaInstance.apiKey.count({ where: { hostname, value } }))

const generateKey = (): string => [...Array(KEY_LENGTH)].map((_) => Math.floor(Math.random() * 16).toString(16)).join('');
const generateKey = (): string => randomBytes(KEY_LENGTH).toString('hex');

0 comments on commit 3aa0d2f

Please sign in to comment.