_section: Hashing Algorithms @ Explain what hash functions are? _subsection: Cryptographic Hash Functions @ The [Cryptographic Hash Functions](link-wiki-cryptographichash) are a specific family of hash functions. _property: ethers.utils.id(text) => string<[[DataHexString]]<32>> @ @SRC The Ethereum Identity function computes the [KECCAK256](link-wiki-sha3) hash of the //text// bytes. _property: ethers.utils.keccak256(aBytesLike) => string<[[DataHexString]]<32>> @ @SRC Returns the [KECCAK256](link-wiki-sha3) digest //aBytesLike//. _property: ethers.utils.ripemd160(aBytesLike) => string<[[DataHexString]]<20>> @ @SRC Returns the [RIPEMD-160](link-wiki-ripemd) digest of //aBytesLike//. _property: ethers.utils.sha256(aBytesLike) => string<[[DataHexString]]<32>> @ @SRC Returns the [SHA2-256](link-wiki-sha2) digest of //aBytesLike//. _property: ethers.utils.sha512(aBytesLike) => string<[[DataHexString]]<64>> @ @SRC Returns the [SHA2-512](link-wiki-sha2) digest of //aBytesLike//. _code: KECCAK256 @lang utils.keccak256([ 0x12, 0x34 ]) //! utils.keccak256("0x") //! utils.keccak256("0x1234") //! // The value MUST be data, such as: // - an Array of numbers // - a data hex string (e.g. "0x1234") // - a Uint8Array // Do NOT use UTF-8 strings that are not a DataHexstring utils.keccak256("hello world") //! error // If needed, convert strings to bytes first: utils.keccak256(utils.toUtf8Bytes("hello world")) //! // Or equivalently use the identity function: utils.id("hello world") //! // Keep in mind that the string "0x1234" represents TWO // bytes (i.e. [ 0x12, 0x34 ]. If you wish to compute the // hash of the 6 characters "0x1234", convert it to UTF-8 // bytes first using utils.toUtf8Bytes. // Consider the following examples: // Hash of TWO (2) bytes: utils.keccak256("0x1234") //! // Hash of TWO (2) bytes: (same result) utils.keccak256([ 0x12, 0x34 ]) //! const bytes = utils.toUtf8Bytes("0x1234"); // bytes // //! // Hash of SIX (6) characters (different than above) utils.keccak256(bytes) //! // Hash of SIX (6) characters (same result) utils.id("0x1234") //! _code: RIPEMD160 @lang utils.ripemd160("0x") //! utils.ripemd160("0x1234") //! _code: SHA-2 @lang utils.sha256("0x") //! utils.sha256("0x1234") //! utils.sha512("0x") //! utils.sha512("0x1234") //! _subsection: HMAC @ _property: ethers.utils.computeHmac(algorithm, key, data) => string<[[DataHexString]]> @ @SRC Returns the [HMAC](link-wiki-hmac) of //data// with //key// using the [Algorithm](utils--hmac-supported-algorithm) //algorithm//. _heading: **HMAC Supported Algorithms** @ @SRC _property: ethers.utils.SupportedAlgorithm.sha256 => string Use the [SHA2-256](link-wiki-sha2) hash algorithm. _property: ethers.utils.SupportedAlgorithm.sha512 => string Use the [SHA2-512](link-wiki-sha2) hash algorithm. _code: HMAC @lang const key = "0x0102"; const data = "0x1234"; utils.computeHmac("sha256", key, data) //! _subsection: Hashing Helpers @ _property: ethers.utils.hashMessage(message) => string<[[DataHexString]]<32>> @ @SRC Computes the [[link-eip-191]] personal message digest of //message//. Personal messages are converted to UTF-8 bytes and prefixed with ``\\x19Ethereum Signed Message:`` and the length of //message//. _property: ethers.utils.namehash(name) => string<[[DataHexString]]<32>> @ @SRC Returns the [ENS Namehash](link-namehash) of //name//. _code: Hashing Messages @lang // @TODO: include examples of hashMessage; it can be complex. :) _code: Namehash @lang utils.namehash("") //! utils.namehash("eth") //! utils.namehash("ricmoo.firefly.eth") //! utils.namehash("ricmoo.xyz") //! _subsection: Solidity Hashing Algorithms @ When using the Solidity ``abi.packEncoded(...)`` function, a non-standard //tightly packed// version of encoding is used. These functions implement the tightly packing algorithm. _property: ethers.utils.solidityPack(types, values) => string<[[DataHexString]]> @ @SRC Returns the non-standard encoded //values// packed according to their respecive type in //types//. _property: ethers.utils.solidityKeccak256(types, values) => string<[[DataHexString]]<32>> @ @SRC Returns the [KECCAK256](link-wiki-sha3) of the non-standard encoded //values// packed according to their respective type in //types//. _property: ethers.utils.soliditySha256(types, values) => string<[[DataHexString]]<32>> @ @SRC Returns the [SHA2-256](link-wiki-sha2) of the non-standard encoded //values// packed according to their respective type in //types//. _code: Solidity Hashing @lang utils.solidityPack([ "int16", "uint48" ], [ -1, 12 ]) //! utils.solidityPack([ "string", "uint8" ], [ "Hello", 3 ]) //! utils.solidityKeccak256([ "int16", "uint48" ], [ -1, 12 ]) //! utils.soliditySha256([ "int16", "uint48" ], [ -1, 12 ]) //!