| 1 | import { toHex } from "./bytes.js"; |
| 2 | |
| 3 | /** SHA-1 using WebCrypto (available in Workers and Node 20+). */ |
| 4 | export async function sha1(data: Uint8Array): Promise<Uint8Array> { |
| 5 | const digest = await crypto.subtle.digest("SHA-1", data as BufferSource); |
| 6 | return new Uint8Array(digest); |
| 7 | } |
| 8 | |
| 9 | export async function sha1Hex(data: Uint8Array): Promise<string> { |
| 10 | return toHex(await sha1(data)); |
| 11 | } |
| 12 | |
| 13 | export async function sha256Hex(data: Uint8Array): Promise<string> { |
| 14 | return toHex(new Uint8Array(await crypto.subtle.digest("SHA-256", data as BufferSource))); |
| 15 | } |