import { hexFromBytes, utf8Bytes } from "@/worker/auth/bytes"; async function importHkdfMaterial(secret: string): Promise { return await crypto.subtle.importKey("raw", utf8Bytes(secret), "HKDF", false, ["deriveBits", "deriveKey"]); } export async function deriveHmacKeyBytes(secret: string, salt: string, info: string): Promise { const material = await importHkdfMaterial(secret); const bits = await crypto.subtle.deriveBits( { name: "HKDF", hash: "SHA-256", salt: utf8Bytes(salt), info: utf8Bytes(info), }, material, 256, ); return new Uint8Array(bits); } export async function sha256Hex(value: string): Promise { const digest = await crypto.subtle.digest("SHA-256", utf8Bytes(value)); return hexFromBytes(new Uint8Array(digest)); }