ethers.js/lib.esm/crypto/keccak.js
2022-12-02 21:27:06 -05:00

31 lines
828 B
JavaScript

/**
* Cryptographic hashing functions
*
* @_subsection: api/crypto:Hash Functions [about-crypto-hashing]
*/
import { keccak_256 } from "@noble/hashes/sha3";
import { getBytes, hexlify } from "../utils/index.js";
let locked = false;
const _keccak256 = function (data) {
return keccak_256(data);
};
let __keccak256 = _keccak256;
/**
* Compute the cryptographic KECCAK256 hash of %%data%%.
*
* @returns DataHexstring
*/
export function keccak256(_data) {
const data = getBytes(_data, "data");
return hexlify(__keccak256(data));
}
keccak256._ = _keccak256;
keccak256.lock = function () { locked = true; };
keccak256.register = function (func) {
if (locked) {
throw new TypeError("keccak256 is locked");
}
__keccak256 = func;
};
Object.freeze(keccak256);
//# sourceMappingURL=keccak.js.map