mirror of
https://github.com/danbulant/jose
synced 2026-05-22 13:58:47 +00:00
11 lines
372 B
TypeScript
11 lines
372 B
TypeScript
import crypto from './webcrypto.js'
|
|
import type { DigestFunction } from '../interfaces.d'
|
|
|
|
const digest: DigestFunction = async (
|
|
algorithm: 'sha256' | 'sha384' | 'sha512',
|
|
data: Uint8Array,
|
|
): Promise<Uint8Array> => {
|
|
const subtleDigest = `SHA-${algorithm.substr(-3)}`
|
|
return new Uint8Array(await crypto.subtle.digest(subtleDigest, data))
|
|
}
|
|
export default digest
|