2019-08-25 02:39:20 -04:00
|
|
|
"use strict";
|
2020-11-16 23:07:24 -05:00
|
|
|
import hash from "hash.js";
|
|
|
|
//const _ripemd160 = _hash.ripemd160;
|
2019-08-25 02:39:20 -04:00
|
|
|
import { arrayify } from "@ethersproject/bytes";
|
2020-11-16 23:07:24 -05:00
|
|
|
import { SupportedAlgorithm } from "./types";
|
2019-08-25 02:39:20 -04:00
|
|
|
import { Logger } from "@ethersproject/logger";
|
|
|
|
import { version } from "./_version";
|
|
|
|
const logger = new Logger(version);
|
|
|
|
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-20 19:43:50 -05:00
|
|
|
if (!SupportedAlgorithm[algorithm]) {
|
2019-08-25 02:39:20 -04:00
|
|
|
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-11-16 23:07:24 -05:00
|
|
|
//# sourceMappingURL=sha2.js.map
|