ethers.js/lib.esm/crypto/hmac.js
2022-10-20 05:03:32 -04:00

22 lines
757 B
JavaScript

import { createHmac } from "./crypto-browser.js";
import { getBytes, hexlify } from "../utils/index.js";
let locked = false;
const _computeHmac = function (algorithm, key, data) {
return createHmac(algorithm, key).update(data).digest();
};
let __computeHmac = _computeHmac;
export function computeHmac(algorithm, _key, _data) {
const key = getBytes(_key, "key");
const data = getBytes(_data, "data");
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