import { createHmac } from 'node:crypto' /** * Compute HMAC-SHA256 and return Base64-encoded signature. * * @param key - HMAC key (Buffer) * @param data - Data to sign (UTF-8 string) * @returns Base64-encoded HMAC-SHA256 signature */ export const hmacSha256Base64 = (key: Buffer, data: string): string => { return createHmac('sha256', key).update(data, 'utf-8').digest('base64') } /** * Compute HMAC-SHA256 and return raw Buffer. * * @param key - HMAC key (Buffer) * @param data - Data to sign (UTF-8 string) * @returns HMAC-SHA256 digest as Buffer */ export const hmacSha256 = (key: Buffer, data: string): Buffer => { return createHmac('sha256', key).update(data, 'utf-8').digest() }