ethers.js/packages/sha2/lib.esm/browser.js

31 lines
1.1 KiB
JavaScript
Raw Normal View History

"use strict";
import * as hash from "hash.js";
import { arrayify } from "@ethersproject/bytes";
import { Logger } from "@ethersproject/logger";
import { version } from "./_version";
const logger = new Logger(version);
2020-01-21 03:43:50 +03:00
export var SupportedAlgorithm;
(function (SupportedAlgorithm) {
SupportedAlgorithm["sha256"] = "sha256";
SupportedAlgorithm["sha512"] = "sha512";
})(SupportedAlgorithm || (SupportedAlgorithm = {}));
;
export function ripemd160(data) {
return "0x" + (hash.ripemd160().update(arrayify(data)).digest("hex"));
}
export function sha256(data) {
return "0x" + (hash.sha256().update(arrayify(data)).digest("hex"));
}
export function sha512(data) {
return "0x" + (hash.sha512().update(arrayify(data)).digest("hex"));
}
export function computeHmac(algorithm, key, data) {
2020-01-21 03:43:50 +03:00
if (!SupportedAlgorithm[algorithm]) {
logger.throwError("unsupported algorithm " + algorithm, Logger.errors.UNSUPPORTED_OPERATION, {
operation: "hmac",
algorithm: algorithm
});
}
return "0x" + hash.hmac(hash[algorithm], arrayify(key)).update(arrayify(data)).digest("hex");
}
2020-07-13 15:03:56 +03:00
//# sourceMappingURL=browser.js.map