configure salt rotation period using env vars. Closed #3427

This commit is contained in:
Francis Cao committed 2026-02-05 08:56:12 -08:00
1 parent 5267222a67
commit e21c1c83bb
2 files changed
+13 -3

No files matched your search

+9
View File
@@ -1,4 +1,5 @@
import crypto from 'node:crypto';
import { startOfDay, startOfMonth, startOfWeek } from 'date-fns';
import { v4, v5, v7 } from 'uuid';
const ALGORITHM = 'aes-256-gcm';
@@ -67,3 +68,11 @@ export function uuid(...args: any) {
export function createAuthKey() {
return crypto.randomBytes(16).toString('hex');
}
export function getSalt(saltRotation: string, createdAt: Date): string {
return hash(
(saltRotation === 'day' ? startOfDay : saltRotation === 'week' ? startOfWeek : startOfMonth)(
createdAt,
).toUTCString(),
);
}