|
1
|
import crypto from "node:crypto" |
|
2
|
|
|
3
|
export const generateVerificationToken = (): string => { |
|
4
|
return crypto.randomBytes(32).toString("base64url") |
|
5
|
} |
|
6
|
|
|
7
|
export const hashVerificationToken = (token: string): string => { |
|
8
|
return crypto.createHash("sha256").update(token).digest("hex") |
|
9
|
} |
|
10
|
|
|
11
|
export const getVerificationTokenTtlMs = ( |
|
12
|
ttlSeconds = 900 |
|
13
|
): number => { |
|
14
|
if (!Number.isInteger(ttlSeconds) || ttlSeconds < 1) { |
|
15
|
throw new Error("Verification token TTL must be a positive integer") |
|
16
|
} |
|
17
|
|
|
18
|
return ttlSeconds * 1000 |
|
19
|
} |