2022-08-29 03:20:54 +00:00
|
|
|
import { v4, v5 } from 'uuid';
|
2020-08-21 02:38:20 +00:00
|
|
|
import { startOfMonth } from 'date-fns';
|
2022-08-29 03:20:54 +00:00
|
|
|
import { hash } from 'next-basics';
|
2020-07-23 03:45:09 +00:00
|
|
|
|
|
|
|
|
export function secret() {
|
2022-04-26 02:11:54 +00:00
|
|
|
return hash(process.env.HASH_SALT || process.env.DATABASE_URL);
|
2020-07-23 03:45:09 +00:00
|
|
|
}
|
2020-07-22 22:46:05 +00:00
|
|
|
|
2020-08-21 02:38:20 +00:00
|
|
|
export function salt() {
|
2022-08-29 03:20:54 +00:00
|
|
|
const ROTATING_SALT = hash(startOfMonth(new Date()).toUTCString());
|
|
|
|
|
|
2022-10-31 18:02:37 +00:00
|
|
|
return hash(secret(), ROTATING_SALT);
|
2020-08-21 02:38:20 +00:00
|
|
|
}
|
|
|
|
|
|
2020-07-23 03:45:09 +00:00
|
|
|
export function uuid(...args) {
|
2020-08-08 00:19:42 +00:00
|
|
|
if (!args.length) return v4();
|
|
|
|
|
|
2022-10-31 18:02:37 +00:00
|
|
|
return v5(hash(...args, salt()), v5.DNS);
|
2020-07-22 22:46:05 +00:00
|
|
|
}
|