<html><head><title>Byte Manipulation</title><linkrel="stylesheet"type="text/css"href="/static/style.css"></head><body><divclass="sidebar"><divclass="header"><divclass="logo"><ahref="/"><divclass="image"></div><divclass="name">ethers</div><divclass="version">v5.0-beta</div></a></div></div><divclass="toc"><div><divclass="link title"><ahref="/">Documentation</a></div><divclass="base show link depth-1"><ahref="/getting-started/">Getting Started</a></div><divclass="hide link depth-2"><ahref="/getting-started/#installing">Installing</a></div><divclass="hide link depth-2"><ahref="/getting-started/#importing">Importing</a></div><divclass="base show link depth-1"><ahref="/concepts/">Concepts</a></div><divclass="hide link depth-2"><ahref="/concepts/events/">Events</a></div><divclass="hide link depth-2"><ahref="/concepts/gas/">Gas</a></div><divclass="hide link depth-3"><ahref="/concepts/gas/#gas-price">Gas Price</a></div><divclass="hide link depth-3"><ahref="/concepts/gas/#gas-limit">Gas Limit</a></div><divclass="base ancestor show link depth-1"><ahref="/api/">Application Programming Interface</a></div><divclass="show link depth-2"><ahref="/api/contract/">Contracts</a></div><divclass="hide link depth-3"><ahref="/api/contract/#buckets">Buckets</a></div><divclass="show link depth-2"><ahref="/api/signer/">Signers</a></div><divclass="hide link depth-3"><ahref="/api/signer/#signer">Signer</a></div><divclass="hide link depth-3"><ahref="/api/signer/#wallet-inherits-signer">Wallet inherits Signer</a></div><divclass="show link depth-2"><ahref="/api/providers/">Providers</a></div><divclass="hide link depth-3"><ahref="/api/providers/provider/">Provider</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#accounts-methods">Accounts Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#blocks-methods">Blocks Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#ethereum-naming-service-(ens)-methods">Ethereum Naming Service (ENS) Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#logs-methods">Logs Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#network-status-methods">Network Status Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#transactions-methods">Transactions Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#event-emitter-methods">Event Emitter Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#inspection-methods">Inspection Methods</a></div><divclass="hide link depth-3"><ahref="/api/providers/jsonrpc-provider/">JSON-RPC Provider</a></div><divclass="hide link depth-4"><ahref="/api/providers/jsonrpc-provider/#jsonrpcprovider">JsonRpcProvider</a></div><divclass="hide link depth-4"><ahref="/api/providers/jsonrpc-provider/#jsonrpcsigner">JsonRpcSigner</a></div><divclass="hide link depth-4"><ahref="/api/providers/jsonrpc-provider/#jsonrpcuncheckedsigner">JsonRpcUncheckedSigner</a></div><divclass="hide link depth-3"><ahref="/api/providers/api-providers/">API Providers</a></div><divclass="hide link depth-4"><ahref="/api/providers/api-providers/#etherscanprovider">EtherscanProvider</a></div><divclass="hide link depth-4"><ahref="/api/providers/api-providers/#infuraprovider">InfuraProvider</a></div><divclass="hide link depth-4"><ahref="/api/providers/api-providers/#nodesmithprovider">NodesmithProvider</a></div><divclass="hide link depth-4"><ahref="/api/providers/api-providers/#alchemyprovider">AlchemyProvider</a></div><divclass="hide link depth-3"><ahref="/api/providers/other/">Other Providers</a></div><divclass="hide link depth-4"><ahref="/api/providers/other/#fallbackprovider">FallbackProvider</a></div><divclass="hide link depth-4"><ahref="/api/providers/other/#ipcprovider">IpcProvider</a></div><divclass="hide link depth-3"><ahref="/api/providers/types/">Types</a></div><divclass="hide link depth-4"><ahref="/api/providers/types/#blocks">Bloc
<p>A Bytes object is any object which is an <ahref="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a> or <ahref="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray">TypedArray</a> with each value in the valid byte range (i.e. between 0 and 255 inclusive), or is an Object with a <codeclass="inline">length</code> property where each indexed property is in the valid byte range.</p>
<ul><li><b>r</b> and <b>s</b>— The x co-ordinate of <b>r</b> and the <b>s</b> value of the signature</li><li><b>v</b>— The parity of the y co-ordinate of <b>r</b></li><li><b>_vs</b>— The <ahref="https://link_here">compact representation</a> of the <b>(r, s)</b> and <b>v</b></li><li><b>recoveryParam</b>— The normalized (i.e. 0 or 1) value of <b>v</b></li></ul>
<p>A <b>SignatureLike</b> is similar to a <ahref="/api/utils/bytes/#signature">Signature</a>, except redundant properties may be omitted.</p><p>For example, if *_vs* is specified, <b>(r, s)</b> and <b>v</b> can be omitted. Likewise, if <b>recoverParam</b> is provided, <b>v</b> can be omitted (as it can be computed).</p>
<aname="inspection"></a><h2>Inspection</h2>
<divclass="property"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">isBytes</span> ( <spanclass="param">object</span> ) <spanclass="arrow">⇒</span><spanclass="returns">boolean</span></div><divclass="body"><p>Returns true if and only if <i>object</i> is a valid <ahref="/api/utils/bytes/#bytes">Bytes</a>.</p></div></div>
<divclass="property"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">isBytesLike</span> ( <spanclass="param">object</span> ) <spanclass="arrow">⇒</span><spanclass="returns">boolean</span></div><divclass="body"><p>Returns true if and only if <i>object</i> is a <ahref="/api/utils/bytes/#bytes">Bytes</a> or an Array or TypedArray where each value is a valid byte (i.e. between 0 and 255 inclusive).</p></div></div>
<divclass="property"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">isHexString</span> ( <spanclass="param">object</span> , [ <spanclass="param">length</span> ] ) <spanclass="arrow">⇒</span><spanclass="returns">boolean</span></div><divclass="body"><p>Returns true if and only if <i>object</i> is a valid hex string; if <i>length</i> is specified the length (in bytes) is also verified.</p></div></div>
<aname="converting-between-arrays-and-hexstrings"></a><h2>Converting between Arrays and Hexstrings</h2>
<divclass="property"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">arrayify</span> ( <spanclass="param">hexstringOrArrayish</span> [ , <spanclass="param">options</span> ] ) <spanclass="arrow">⇒</span><spanclass="returns">Uint8Array</span></div><divclass="body"><p>Converts <i>hexstringOrArrayish</i> to a Uint8Array. If a <ahref="/api/utils/bytes/#hexstring">Hexstring</a> is passed in, the length must be even.</p></div></div>
<divclass="property"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">hexlify</span> ( <spanclass="param">hexstringOrArrayish</span> ) <spanclass="arrow">⇒</span><spanclass="returns">string</span></div><divclass="body"><p>Converts <i>hexstringOrArrayish</i> to a <ahref="/api/utils/bytes/#hexstring">Hexstring</a>. The result will always be zero-padded to even length.</p></div></div>
<divclass="property"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">hexValue</span> ( <spanclass="param">aBigNumberish</span> ) <spanclass="arrow">⇒</span><spanclass="returns">string</span></div><divclass="body"><p>Converts <i>aBigNumberish</i> to a <ahref="/api/utils/bytes/#hexstring">Hexstring</a>, with no unecessary leading zeros. The result of this function can be of odd-length.</p></div></div>
<divclass="code"><br><spanclass="comment">// Convert a hexstring to a Uint8Array</span><br>arrayify("0x1234")<br><spanclass="result ok">// [ 18, 52 ]</span><br><br><spanclass="comment">// Convert an Array to a hexstring</span><br>hexlify([1, 2, 3, 4])<br><spanclass="result ok">// 0x01020304</span><br><br><spanclass="comment">// Convert an Object to a hexstring</span><br>hexlify({ length: 2, "0": 1, "1": 2 })<br><spanclass="result ok">// 0x0102</span><br><br><spanclass="comment">// Convert an Array to a hexstring</span><br>hexlify([ 1 ])<br><spanclass="result ok">// 0x01</span><br><br><spanclass="comment">// Convert a number to a stripped hex value</span><br>hexValue(1)<br><spanclass="result ok">// 0x1</span><br><br><spanclass="comment">// Convert an Array to a stripped hex value</span><br>hexValue([ 1, 2 ])<br><spanclass="result ok">// 0x102</span><br></div>
<divclass="property"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">concat</span> ( <spanclass="param">arrayOfBytesLike</span> ) <spanclass="arrow">⇒</span><spanclass="returns">Uint8Array</span></div><divclass="body"><p>Concatenates all the <ahref="/api/utils/bytes/#byteslike">BytesLike</a> in <i>arrayOfBytesLike</i> into a single Uint8Array.</p></div></div>
<divclass="property"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">stripZeros</span> ( <spanclass="param">aBytesLike</span> ) <spanclass="arrow">⇒</span><spanclass="returns">Uint8Array</span></div><divclass="body"><p>Concatenates all the <ahref="/api/utils/bytes/#byteslike">BytesLike</a> in <i>arrayOfBytesLike</i></p></div></div>
<divclass="property"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">zeroPad</span> ( <spanclass="param">aBytesLike</span> , <spanclass="param">length</span> ) <spanclass="arrow">⇒</span><spanclass="returns">Uint8Array</span></div><divclass="body"><p>Concatenates all the <ahref="/api/utils/bytes/#byteslike">BytesLike</a> in <i>arrayOfBytesLike</i></p></div></div>
<divclass="property"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">hexConcat</span> ( <spanclass="param">arrayOfBytesLike</span> ) <spanclass="arrow">⇒</span><spanclass="returns">string</span></div><divclass="body"><p>Concatenates all the <ahref="/api/utils/bytes/#byteslike">BytesLike</a> in <i>arrayOfBytesLike</i> into a single <ahref="/api/utils/bytes/#hexstring">Hexstring</a></p></div></div>
<divclass="property"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">hexDataLength</span> ( <spanclass="param">aBytesLike</span> ) <spanclass="arrow">⇒</span><spanclass="returns">number</span></div><divclass="body"><p>Returns the length (in bytes) of <i>aBytesLike</i>.</p><p>This will <b>throw and error</b> if <i>aBytesLike</i> is a <ahref="/api/utils/bytes/#hexstring">Hexstring</a> but is of odd-length.</p></div></div>
<divclass="property"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">hexDataSlice</span> ( <spanclass="param">aBytesLike</span> , <spanclass="param">offset</span> [ , <spanclass="param">endOffset</span> ] ) <spanclass="arrow">⇒</span><spanclass="returns">string</span></div><divclass="body"><p>Returns the length (in bytes) of <i>aBytesLike</i>.</p></div></div>
<divclass="property"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">joinSignature</span> ( <spanclass="param">aSignatureLike</span> ) <spanclass="arrow">⇒</span><spanclass="returns">string</span></div><divclass="body"><p>Return the flat-format of a <ahref="/api/utils/bytes/#signaturelike">SignatureLike</a>, which is 65 bytes (130 nibbles) long, concatenating the <b>r</b>, <b>s</b> and <b>v</b> of a Signature.</p></div></div>
<divclass="property"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">splitSignature</span> ( <spanclass="param">aSignatureLikeOrBytesLike</span> ) <spanclass="arrow">⇒</span><spanclass="returns">Signature</span></div><divclass="body"><p>Return the full expanded-format of a <ahref="/api/utils/bytes/#signaturelike">SignatureLike</a> or a flat-format <ahref="/api/utils/bytes/#hexstring">Hexstring</a>. Any missing properties will be computed.</p></div></div><divclass="footer"><divclass="nav previous"><ahref="/api/utils/bignumber/"><spanclass="arrow">←</span>BigNumber</a></div><divclass="nav next"><ahref="/api/utils/constants/">Constants<spanclass="arrow">→</span></a></div></div><divclass="copyright">The content of this site is licensed under the <ahref="https://choosealicense.com/licenses/cc-by-4.0/">Creative Commons Attribution 4.0 International License</a>.</div></div><scriptsrc="/script.js"type="text/javascript"></script></body></html><!-- ContentHash:07938d148295667a14f2c5a06dddf2fc179b3b8a326bd000f82efa641da15d53 -->