(purpose: string | Buffer)
| 1 | import { createHmac } from 'crypto' |
| 2 | |
| 3 | export function deriveFromSecret(purpose: string | Buffer): Buffer { |
| 4 | if (!process.env.SECRET) { |
| 5 | throw new Error('SECRET environment variable not set') |
| 6 | } |
| 7 | |
| 8 | return hmacSha256(process.env.SECRET, purpose) |
| 9 | } |
| 10 | |
| 11 | export function hmacSha256(secret: string | Buffer, data: string | Buffer): Buffer { |
| 12 | return createHmac('sha256', secret).update(data).digest() |