ethers.js/docs/v5/api/utils/hashing/index.html

159 lines
25 KiB
HTML
Raw Permalink Normal View History

2020-06-09 23:56:58 -04:00
<!DOCTYPE html>
<html class="paged">
<head>
<title>Hashing Algorithms</title>
<link rel="stylesheet" type="text/css" href="/v5/static/style.css">
</head>
<body>
<div class="sidebar">
<div class="header">
<div class="logo"><a href="/v5/"><div class="image"></div><div class="name">ethers</div><div class="version">v5.0-beta</div></a></div>
</div>
<div class="toc"><div>
2020-06-12 03:38:55 -04:00
<div class="link title"><a href="/v5/">Documentation</a></div><div class="base show link depth-1"><a href="/v5/getting-started/">Getting Started</a></div><div class="base show link depth-1"><a href="/v5/concepts/">Ethereum Basics</a></div><div class="hide link depth-2"><a href="/v5/concepts/events/">Events</a></div><div class="hide link depth-2"><a href="/v5/concepts/gas/">Gas</a></div><div class="hide link depth-2"><a href="/v5/concepts/security/">Security</a></div><div class="base ancestor show link depth-1"><a href="/v5/api/">Application Programming Interface</a></div><div class="show link depth-2"><a href="/v5/api/contract/">Contract Interaction</a></div><div class="hide link depth-3"><a href="/v5/api/contract/contract/">Contract</a></div><div class="hide link depth-3"><a href="/v5/api/contract/contract-factory/">ContractFactory</a></div><div class="hide link depth-3"><a href="/v5/api/contract/example/">Example: ERC-20 Contract</a></div><div class="show link depth-2"><a href="/v5/api/signer/">Signers</a></div><div class="show link depth-2"><a href="/v5/api/providers/">Providers</a></div><div class="hide link depth-3"><a href="/v5/api/providers/provider/">Provider</a></div><div class="hide link depth-3"><a href="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></div><div class="hide link depth-3"><a href="/v5/api/providers/api-providers/">API Providers</a></div><div class="hide link depth-3"><a href="/v5/api/providers/other/">Other Providers</a></div><div class="hide link depth-3"><a href="/v5/api/providers/types/">Types</a></div><div class="ancestor show link depth-2"><a href="/v5/api/utils/">Utilities</a></div><div class="show link depth-3"><a href="/v5/api/utils/abi/">Application Binary Interface</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/coder/">AbiCoder</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/formats/">ABI Formats</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/fragments/">Fragments</a></div><div class="hide link depth-4"><a href="/v5/api/utils/abi/interface/">Interface</a></div><div class="show link depth-3"><a href="/v5/api/utils/address/">Addresses</a></div><div class="show link depth-3"><a href="/v5/api/utils/bignumber/">BigNumber</a></div><div class="show link depth-3"><a href="/v5/api/utils/bytes/">Byte Manipulation</a></div><div class="show link depth-3"><a href="/v5/api/utils/constants/">Constants</a></div><div class="show link depth-3"><a href="/v5/api/utils/display-logic/">Display Logic and Input</a></div><div class="show link depth-3"><a href="/v5/api/utils/encoding/">Encoding Utilities</a></div><div class="show link depth-3"><a href="/v5/api/utils/fixednumber/">FixedNumber</a></div><div class="myself ancestor ancestor show link depth-3"><a href="/v5/api/utils/hashing/">Hashing Algorithms</a></div><div class="show link depth-3"><a href="/v5/api/utils/hdnode/">HD Wallet</a></div><div class="show link depth-3"><a href="/v5/api/utils/logger/">Logging</a></div><div class="show link depth-3"><a href="/v5/api/utils/properties/">Property Utilities</a></div><div class="show link depth-3"><a href="/v5/api/utils/signing-key/">Signing Key</a></div><div class="show link depth-3"><a href="/v5/api/utils/strings/">Strings</a></div><div class="show link depth-3"><a href="/v5/api/utils/transactions/">Transactions</a></div><div class="show link depth-3"><a href="/v5/api/utils/web/">Web Utilities</a></div><div class="show link depth-3"><a href="/v5/api/utils/wordlists/">Wordlists</a></div><div class="show link depth-2"><a href="/v5/api/other/">Other Libraries</a></div><div class="hide link depth-3"><a href="/v5/api/other/assembly/">Assembly</a></div><div class="hide link depth-4"><a href="/v5/api/other/assembly/dialect/">Ethers ASM Dialect</a></div><div class="hide link depth-4"><a href="/v5/api/other/assembly/api/">Utilities</a></div><div class="hide link depth-4"><a href="/v5/api/other/assembly/ast/">Abstract Syntax Tree</a></div><div class="hide link depth-3"><a href="/v5/api/other/hardware/">Hardware Wallets</a></div><div class="sho
2020-06-09 23:56:58 -04:00
</div></div>
</div>
<div class="content">
<div class="breadcrumbs"><a href="/v5/">Documentation</a>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<a href="/v5/api/">API</a>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<a href="/v5/api/utils/">Utilities</a>&nbsp;&nbsp;&raquo;&nbsp;&nbsp;<span class="current">Hashing Algorithms</span></div>
<a name="hashing-algorithms"></a><a name="hashing-algorithms"></a><h1 class="show-anchors"><div>Hashing Algorithms<div class="anchors"><a class="self" href="/v5/api/utils/hashing/#hashing-algorithms"></a></div></div></h1><p>Explain what hash functions are?</p>
<a name="cryptographic-hash-functions"></a><a name="hashing-algorithms--cryptographic-hash-functions"></a><h2 class="show-anchors"><div>Cryptographic Hash Functions<div class="anchors"><a class="self" href="/v5/api/utils/hashing/#cryptographic-hash-functions"></a></div></div></h2><p>The <a href="https://en.wikipedia.org/wiki/Cryptographic_hash_function">Cryptographic Hash Functions</a> are a specific family of hash functions.</p>
<a name="utils-id"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="method">id</span><span class="symbol">(</span> <span class="param">text</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>&lt; 32 &gt; &gt;</span><div class="anchors"><a class="self" href="/v5/api/utils/hashing/#utils-id"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/hash/src.ts/index.ts#L47">source</a></div></div><div class="body"><p>The Ethereum Identity function computs the <a href="https://en.wikipedia.org/wiki/SHA-3">KECCAK256</a> hash of the <i>text</i> bytes.</p>
</div></div><a name="utils-keccak256"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="method">keccak256</span><span class="symbol">(</span> <span class="param">aBytesLike</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>&lt; 32 &gt; &gt;</span><div class="anchors"><a class="self" href="/v5/api/utils/hashing/#utils-keccak256"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/keccak256/src.ts/index.ts#L7">source</a></div></div><div class="body"><p>Returns the <a href="https://en.wikipedia.org/wiki/SHA-3">KECCAK256</a> digest <i>aBytesLike</i>.</p>
</div></div><a name="utils-ripemd160"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="method">ripemd160</span><span class="symbol">(</span> <span class="param">aBytesLike</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>&lt; 20 &gt; &gt;</span><div class="anchors"><a class="self" href="/v5/api/utils/hashing/#utils-ripemd160"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/sha2/src.ts/index.ts#L14">source</a></div></div><div class="body"><p>Returns the <a href="https://en.m.wikipedia.org/wiki/RIPEMD">RIPEMD-160</a> digest of <i>aBytesLike</i>.</p>
</div></div><a name="utils-sha256"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="method">sha256</span><span class="symbol">(</span> <span class="param">aBytesLike</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>&lt; 32 &gt; &gt;</span><div class="anchors"><a class="self" href="/v5/api/utils/hashing/#utils-sha256"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/sha2/src.ts/index.ts#L18">source</a></div></div><div class="body"><p>Returns the <a href="https://en.wikipedia.org/wiki/SHA-2">SHA2-256</a> digest of <i>aBytesLike</i>.</p>
</div></div><a name="utils-sha512"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="method">sha512</span><span class="symbol">(</span> <span class="param">aBytesLike</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>&lt; 64 &gt; &gt;</span><div class="anchors"><a class="self" href="/v5/api/utils/hashing/#utils-sha512"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/sha2/src.ts/index.ts#L22">source</a></div></div><div class="body"><p>Returns the <a href="https://en.wikipedia.org/wiki/SHA-2">SHA2-512</a> digest of <i>aBytesLike</i>.</p>
</div></div><div class="code-title"><div>KECCAK256</div></div><div class="code">utils.keccak256([ 0x12, 0x34 ])
2020-06-12 19:21:37 -04:00
<span class="result ok">// '0x56570de287d73cd1cb6092bb8fdee6173974955fdef345ae579ee9f475ea7432'
</span>
2020-06-09 23:56:58 -04:00
utils.keccak256("0x")
2020-06-12 19:21:37 -04:00
<span class="result ok">// '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
</span>
2020-06-09 23:56:58 -04:00
utils.keccak256("0x1234")
2020-06-12 19:21:37 -04:00
<span class="result ok">// '0x56570de287d73cd1cb6092bb8fdee6173974955fdef345ae579ee9f475ea7432'
</span>
<span class="comment">// The value MUST be data, such as:
</span><span class="comment">// - an Array of numbers
</span><span class="comment">// - a data hex string (e.g. "0x1234")
</span><span class="comment">// - a Uint8Array
</span>
<span class="comment">// Do NOT use UTF-8 strings that are not a DataHexstring
</span>utils.keccak256("hello world")
<span class="result error">// Error: invalid arrayify value (argument="value", value="hello world", code=INVALID_ARGUMENT, version=bytes/5.0.0-beta.138)
</span>
<span class="comment">// If needed, convert strings to bytes first:
</span>utils.keccak256(utils.toUtf8Bytes("hello world"))
<span class="result ok">// '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad'
</span>
<span class="comment">// Or equivalently use the identity function:
</span>utils.id("hello world")
<span class="result ok">// '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad'
</span>
<span class="comment">// Keep in mind that the string "0x1234" represents TWO
</span><span class="comment">// bytes (i.e. [ 0x12, 0x34 ]. If you wish to compute the
</span><span class="comment">// hash of the 6 characters "0x1234", convert it to UTF-8
</span><span class="comment">// bytes first using utils.toUtf8Bytes.
</span>
<span class="comment">// Consider the following examples:
</span>
<span class="comment">// Hash of TWO (2) bytes:
</span>utils.keccak256("0x1234")
<span class="result ok">// '0x56570de287d73cd1cb6092bb8fdee6173974955fdef345ae579ee9f475ea7432'
</span>
<span class="comment">// Hash of TWO (2) bytes: (same result)
</span>utils.keccak256([ 0x12, 0x34 ])
<span class="result ok">// '0x56570de287d73cd1cb6092bb8fdee6173974955fdef345ae579ee9f475ea7432'
</span>
2020-06-09 23:56:58 -04:00
const bytes = utils.toUtf8Bytes("0x1234");
2020-06-12 19:21:37 -04:00
<span class="result ok">// Uint8Array [ 48, 120, 49, 50, 51, 52 ]
</span>
<span class="comment">// Hash of SIX (6) characters (different than above)
</span>utils.keccak256(bytes)
<span class="result ok">// '0x1ac7d1b81b7ba1025b36ccb86723da6ee5a87259f1c2fd5abe69d3200b512ec8'
</span>
<span class="comment">// Hash of SIX (6) characters (same result)
</span>utils.id("0x1234")
<span class="result ok">// '0x1ac7d1b81b7ba1025b36ccb86723da6ee5a87259f1c2fd5abe69d3200b512ec8'
</span></div><div class="code-title"><div>RIPEMD160</div></div><div class="code">utils.ripemd160("0x")
<span class="result ok">// '0x9c1185a5c5e9fc54612808977ee8f548b2258d31'
</span>
2020-06-09 23:56:58 -04:00
utils.ripemd160("0x1234")
2020-06-12 19:21:37 -04:00
<span class="result ok">// '0xc39867e393cb061b837240862d9ad318c176a96d'
</span></div><div class="code-title"><div>SHA-2</div></div><div class="code">utils.sha256("0x")
<span class="result ok">// '0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
</span>
2020-06-09 23:56:58 -04:00
utils.sha256("0x1234")
2020-06-12 19:21:37 -04:00
<span class="result ok">// '0x3a103a4e5729ad68c02a678ae39accfbc0ae208096437401b7ceab63cca0622f'
</span>
2020-06-09 23:56:58 -04:00
utils.sha512("0x")
2020-06-12 19:21:37 -04:00
<span class="result ok">// '0xcf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e'
</span>
2020-06-09 23:56:58 -04:00
utils.sha512("0x1234")
2020-06-12 19:21:37 -04:00
<span class="result ok">// '0x4c54886c9821195522d88ff4705c3e0c686b921054421e6ea598739c29c26e1ee75419aaceec94dd2e3c0dbb82ecf895c9f61215f375de6d800d9b99d3d4b816'
</span></div><a name="utils--hmac"></a><a name="hashing-algorithms--utils--hmac"></a><h2 class="show-anchors"><div>HMAC<div class="anchors"><a class="self" href="/v5/api/utils/hashing/#utils--hmac"></a></div></div></h2>
2020-06-09 23:56:58 -04:00
<a name="utils-computeHmac"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="method">computeHmac</span><span class="symbol">(</span> <span class="param">algorithm</span> <span class="symbol">,</span> <span class="param">key</span> <span class="symbol">,</span> <span class="param">data</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a> &gt;</span><div class="anchors"><a class="self" href="/v5/api/utils/hashing/#utils-computeHmac"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/sha2/src.ts/index.ts#L27">source</a></div></div><div class="body"><p>Returns the <a href="https://en.wikipedia.org/wiki/HMAC">HMAC</a> of <i>data</i> with <i>key</i> using the <a href="/v5/api/utils/hashing/#utils--hmac-supported-algorithm">Algorithm</a> <i>algorithm</i>.</p>
</div></div><a name="utils--hmac-supported-algorithm"></a><a name="hashing-algorithms--utils--hmac--utils--hmac-supported-algorithm"></a><h3 class="show-anchors"><div><b>HMAC Supported Algorithms</b><div class="anchors"><a class="self" href="/v5/api/utils/hashing/#utils--hmac-supported-algorithm"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/sha2/src.ts/index.ts#L11">source</a></div></div></h3>
<div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="path">SupportedAlgorithm</span><span class="symbol">.</span><span class="method">sha256</span> <span class="arrow">&rArr;</span> <span class="returns">string</span><div class="anchors"></div></div><div class="body"><p>Use the <a href="https://en.wikipedia.org/wiki/SHA-2">SHA2-256</a> hash algorithm.</p>
</div></div><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="path">SupportedAlgorithm</span><span class="symbol">.</span><span class="method">sha512</span> <span class="arrow">&rArr;</span> <span class="returns">string</span><div class="anchors"></div></div><div class="body"><p>Use the <a href="https://en.wikipedia.org/wiki/SHA-2">SHA2-512</a> hash algorithm.</p>
</div></div><div class="code-title"><div>HMAC</div></div><div class="code">const key = "0x0102";
const data = "0x1234";
utils.computeHmac("sha256", key, data)
2020-06-12 19:21:37 -04:00
<span class="result ok">// '0x7553df81c628815cf569696cad13a37c606c5058df13d9dff4fee2cf5e9b5779'
</span></div><a name="utils--hashing-helpers"></a><a name="hashing-algorithms--utils--hashing-helpers"></a><h2 class="show-anchors"><div>Hashing Helpers<div class="anchors"><a class="self" href="/v5/api/utils/hashing/#utils--hashing-helpers"></a></div></div></h2>
2020-06-09 23:56:58 -04:00
<a name="utils-hashMessage"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="method">hashMessage</span><span class="symbol">(</span> <span class="param">message</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>&lt; 32 &gt; &gt;</span><div class="anchors"><a class="self" href="/v5/api/utils/hashing/#utils-hashMessage"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/hash/src.ts/index.ts#L53">source</a></div></div><div class="body"><p>Computes the <a href="https://eips.ethereum.org/EIPS/eip-191">EIP-191</a> personal message digest of <i>message</i>. Personal messages are converted to UTF-8 bytes and prefixed with <code class="inline">\x19Ethereum Signed Message:</code> and the length of <i>message</i>.</p>
</div></div><a name="utils-namehash"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="method">namehash</span><span class="symbol">(</span> <span class="param">name</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>&lt; 32 &gt; &gt;</span><div class="anchors"><a class="self" href="/v5/api/utils/hashing/#utils-namehash"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/hash/src.ts/index.ts#L29">source</a></div></div><div class="body"><p>Returns the <a href="https://docs.ens.domains/contract-api-reference/name-processing#hashing-names">ENS Namehash</a> of <i>name</i>.</p>
2020-06-12 19:21:37 -04:00
</div></div><div class="code-title"><div>Hashing Messages</div></div><div class="code"><span class="comment">// @TODO: include examples of hashMessage; it can be complex. :)
</span></div><div class="code-title"><div>Namehash</div></div><div class="code">utils.namehash("")
<span class="result ok">// '0x0000000000000000000000000000000000000000000000000000000000000000'
</span>
2020-06-09 23:56:58 -04:00
utils.namehash("eth")
2020-06-12 19:21:37 -04:00
<span class="result ok">// '0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae'
</span>
2020-06-09 23:56:58 -04:00
utils.namehash("ricmoo.firefly.eth")
2020-06-12 19:21:37 -04:00
<span class="result ok">// '0x0bcad17ecf260d6506c6b97768bdc2acfb6694445d27ffd3f9c1cfbee4a9bd6d'
</span>
2020-06-09 23:56:58 -04:00
utils.namehash("ricmoo.xyz")
2020-06-12 19:21:37 -04:00
<span class="result ok">// '0x7d56aa46358ba2f8b77d8e05bcabdd2358370dcf34e87810f8cea77ecb3fc57d'
</span></div><a name="utils--solidity-hashing"></a><a name="hashing-algorithms--utils--solidity-hashing"></a><h2 class="show-anchors"><div>Solidity Hashing Algorithms<div class="anchors"><a class="self" href="/v5/api/utils/hashing/#utils--solidity-hashing"></a></div></div></h2><p>When using the Solidity <code class="inline">abi.packEncoded(...)</code> function, a non-standard <i>tightly packed</i> version of encoding is used. These functions implement the tightly packing algorithm.</p>
2020-06-09 23:56:58 -04:00
<a name="utils-solidityPack"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="method">solidityPack</span><span class="symbol">(</span> <span class="param">types</span> <span class="symbol">,</span> <span class="param">values</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a> &gt;</span><div class="anchors"><a class="self" href="/v5/api/utils/hashing/#utils-solidityPack"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/solidity/src.ts/index.ts#L73">source</a></div></div><div class="body"><p>Returns the non-standard encoded <i>values</i> packed according to their respecive type in <i>types</i>.</p>
</div></div><a name="utils-solidityKeccak256"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="method">solidityKeccak256</span><span class="symbol">(</span> <span class="param">types</span> <span class="symbol">,</span> <span class="param">values</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>&lt; 32 &gt; &gt;</span><div class="anchors"><a class="self" href="/v5/api/utils/hashing/#utils-solidityKeccak256"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/solidity/src.ts/index.ts#L82">source</a></div></div><div class="body"><p>Returns the <a href="https://en.wikipedia.org/wiki/SHA-3">KECCAK256</a> of the non-standard encoded <i>values</i> packed according to their respective type in <i>types</i>.</p>
</div></div><a name="utils-soliditySha256"></a><div class="property show-anchors"><div class="signature"><span class="path">ethers</span><span class="symbol">.</span><span class="path">utils</span><span class="symbol">.</span><span class="method">soliditySha256</span><span class="symbol">(</span> <span class="param">types</span> <span class="symbol">,</span> <span class="param">values</span> <span class="symbol">)</span> <span class="arrow">&rArr;</span> <span class="returns">string&lt; <a href="/v5/api/utils/bytes/#DataHexString">DataHexString</a>&lt; 32 &gt; &gt;</span><div class="anchors"><a class="self" href="/v5/api/utils/hashing/#utils-soliditySha256"></a><a class="source" href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/solidity/src.ts/index.ts#L86">source</a></div></div><div class="body"><p>Returns the <a href="https://en.wikipedia.org/wiki/SHA-2">SHA2-256</a> of the non-standard encoded <i>values</i> packed according to their respective type in <i>types</i>.</p>
</div></div><div class="code-title"><div>Solidity Hashing</div></div><div class="code">utils.solidityPack([ "int16", "uint48" ], [ -1, 12 ])
2020-06-12 19:21:37 -04:00
<span class="result ok">// '0xffff00000000000c'
</span>
2020-06-09 23:56:58 -04:00
utils.solidityPack([ "string", "uint8" ], [ "Hello", 3 ])
2020-06-12 19:21:37 -04:00
<span class="result ok">// '0x48656c6c6f03'
</span>
2020-06-09 23:56:58 -04:00
utils.solidityKeccak256([ "int16", "uint48" ], [ -1, 12 ])
2020-06-12 19:21:37 -04:00
<span class="result ok">// '0x81da7abb5c9c7515f57dab2fc946f01217ab52f3bd8958bc36bd55894451a93c'
</span>
2020-06-09 23:56:58 -04:00
utils.soliditySha256([ "int16", "uint48" ], [ -1, 12 ])
2020-06-12 19:21:37 -04:00
<span class="result ok">// '0xa5580fb602f6e2ba9c588011dc4e6c2335e0f5d970dc45869db8f217efc6911a'
</span></div>
2020-06-09 23:56:58 -04:00
<div class="footer">
<div class="nav previous"><a href="/v5/api/utils/fixednumber/"><span class="arrow">&larr;</span>FixedNumber</a></div>
<div class="nav next"><a href="/v5/api/utils/hdnode/">HD Wallet<span class="arrow">&rarr;</span></a></div>
</div>
2020-06-12 19:21:37 -04:00
<div class="copyright">The content of this site is licensed under the <a href="https://choosealicense.com/licenses/cc-by-4.0/">Creative Commons License</a>. Last modified on June 12, 2020, 7:17pm.</div>
2020-06-09 23:56:58 -04:00
</div>
<script src="/v5/static/script.js" type="text/javascript"></script>
</body>
</html>