UNPKG

ts-mls

Version:

[![CI](https://github.com/LukaJCB/ts-mls/actions/workflows/ci.yml/badge.svg)](https://github.com/LukaJCB/ts-mls/actions/workflows/ci.yml) [![npm version](https://badge.fury.io/js/ts-mls.svg)](https://badge.fury.io/js/ts-mls) [![Coverage Status](https://co

32 lines 1.21 kB
import { utf8ToBytes } from "@noble/ciphers/utils"; import { encodeVarLenData } from "../codec/variableLength"; import { bytesToBuffer } from "../util/byteArray"; export function makeHashImpl(sc, h) { return { async digest(data) { const result = await sc.digest(h, bytesToBuffer(data)); return new Uint8Array(result); }, async mac(key, data) { const result = await sc.sign("HMAC", await importMacKey(key, h), bytesToBuffer(data)); return new Uint8Array(result); }, async verifyMac(key, mac, data) { return sc.verify("HMAC", await importMacKey(key, h), bytesToBuffer(mac), bytesToBuffer(data)); }, }; } function importMacKey(rawKey, h) { return crypto.subtle.importKey("raw", bytesToBuffer(rawKey), { name: "HMAC", hash: { name: h }, }, false, ["sign", "verify"]); } export function refhash(label, value, h) { return h.digest(encodeRefHash(label, value)); } function encodeRefHash(label, value) { const labelBytes = utf8ToBytes(label); return new Uint8Array([...encodeVarLenData(labelBytes), ...encodeVarLenData(value)]); } //# sourceMappingURL=hash.js.map