blob: 90edd4e72945f1d05b1e52fb5f8a8bcba6cd831b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
import { COSEALG } from './cose';
import { isoUint8Array, isoCrypto } from './iso';
/**
* Returns hash digest of the given data, using the given algorithm when provided. Defaults to using
* SHA-256.
*/
export async function toHash(
data: Uint8Array | string,
algorithm: COSEALG = -7,
): Promise<Uint8Array> {
if (typeof data === 'string') {
data = isoUint8Array.fromUTF8String(data);
}
const digest = isoCrypto.digest(data, algorithm);
return digest;
}
|