ethers.js/lib.esm/crypto/hmac.js

22 lines
749 B
JavaScript
Raw Normal View History

2022-11-09 10:57:02 +03:00
import { createHmac } from "./crypto.js";
2022-09-16 05:58:45 +03:00
import { getBytes, hexlify } from "../utils/index.js";
2022-09-05 23:57:11 +03:00
let locked = false;
const _computeHmac = function (algorithm, key, data) {
2022-10-20 12:03:32 +03:00
return createHmac(algorithm, key).update(data).digest();
2022-09-05 23:57:11 +03:00
};
let __computeHmac = _computeHmac;
export function computeHmac(algorithm, _key, _data) {
2022-09-16 05:58:45 +03:00
const key = getBytes(_key, "key");
const data = getBytes(_data, "data");
2022-09-05 23:57:11 +03:00
return hexlify(__computeHmac(algorithm, key, data));
}
computeHmac._ = _computeHmac;
computeHmac.lock = function () { locked = true; };
computeHmac.register = function (func) {
if (locked) {
throw new Error("computeHmac is locked");
}
__computeHmac = func;
};
Object.freeze(computeHmac);
//# sourceMappingURL=hmac.js.map