ts-mls
Version:
[](https://github.com/LukaJCB/ts-mls/actions/workflows/ci.yml) [](https://badge.fury.io/js/ts-mls) [ {
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