UNPKG

hardhat

Version:

Hardhat is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.

26 lines • 1.13 kB
import { HardhatError } from "@nomicfoundation/hardhat-errors"; import { utf8StringToBytes } from "@nomicfoundation/hardhat-utils/bytes"; import { keccak256 } from "@nomicfoundation/hardhat-utils/crypto"; import { bytesToHexString, getUnprefixedHexString, hexStringToBytes, isHexString, isPrefixedHexString, } from "@nomicfoundation/hardhat-utils/hex"; const keccakAction = async ({ value, }) => { let bytes; if (isPrefixedHexString(value)) { if (!isHexString(value)) { throw new HardhatError(HardhatError.ERRORS.CORE.GENERAL.INVALID_HEX_STRING, { value }); } if (getUnprefixedHexString(value).length % 2 !== 0) { throw new HardhatError(HardhatError.ERRORS.CORE.ARGUMENTS.INVALID_VALUE, { value, name: "value", reason: "it must have an even number of hex digits", }); } bytes = hexStringToBytes(value); } else { bytes = utf8StringToBytes(value); } console.log(bytesToHexString(await keccak256(bytes))); }; export default keccakAction; //# sourceMappingURL=keccak.js.map