2019-08-22 08:52:17 +03:00
-----
Documentation: [html ](https://docs-beta.ethers.io/ )
-----
2019-08-21 08:53:47 +03:00
Byte Manipulation
=================
Tra la la...
Types
-----
### Bytes
2019-12-14 06:05:10 +03:00
A **Bytes** is any object which is an
2020-02-18 01:56:50 +03:00
[Array ](../../../Users/ricmoo/Development/ethers/ethers.js-v5/https:/developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array ) or [TypedArray ](../../../Users/ricmoo/Development/ethers/ethers.js-v5/https:/developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray ) with
2019-08-21 08:53:47 +03:00
each value in the valid byte range (i.e. between 0 and 255 inclusive),
or is an Object with a `length` property where each indexed property
is in the valid byte range.
### BytesLike
2019-12-14 06:05:10 +03:00
A **BytesLike** can be either a [Bytes ](./ ) or a [DataHexstring ](./ ).
### DataHexstring
A **DataHexstring** is identical to a [Hexstring ](./ ) except that it has
an even number of nibbles, and therefore is a valid representation of
binary data as a string.
2019-08-21 08:53:47 +03:00
### Hexstring
2020-02-02 08:53:22 +03:00
A **Hexstring** is a string which has a `0x` prefix followed by any
2019-12-14 06:05:10 +03:00
number of nibbles (i.e. case-insensitive hexidecumal characters, `0-9` and `a-f` ).
2019-08-21 08:53:47 +03:00
### Signature
* **r** and **s** --- The x co-ordinate of **r** and the **s** value of the signature
* **v** --- The parity of the y co-ordinate of **r**
2020-02-18 01:56:50 +03:00
* **_vs** --- The [compact representation ](../../../Users/ricmoo/Development/ethers/ethers.js-v5/https:/eips.ethereum.org/EIPS/eip-2098 ) of the **s** and **v**
2019-08-21 08:53:47 +03:00
* **recoveryParam** --- The normalized (i.e. 0 or 1) value of **v**
2020-02-02 08:53:22 +03:00
### Flat-Format Signature
A **Flat-Format Signature** is a common Signature format where
the r, s and v are concanenated into a 65 byte (130 nibble)
[DataHexstring ](./ ).
2019-08-21 08:53:47 +03:00
### SignatureLike
A **SignatureLike** is similar to a [Signature ](./ ), except redundant properties
2020-02-02 08:53:22 +03:00
may be omitted or it may be a [Flat-Format Signature ](./ ).
2019-08-21 08:53:47 +03:00
2019-12-14 06:05:10 +03:00
For example, if **_vs** is specified, **s** and **v** may be omitted. Likewise,
if **recoveryParam** is provided, **v** may be omitted (as in these cases the
missing values can be computed).
2019-08-21 08:53:47 +03:00
Inspection
----------
#### *utils* . **isBytes** ( object ) **=>** *boolean*
Returns true if and only if *object* is a valid [Bytes ](./ ).
#### *utils* . **isBytesLike** ( object ) **=>** *boolean*
2019-12-14 06:05:10 +03:00
Returns true if and only if *object* is a [Bytes ](./ ) or [DataHexstring ](./ ).
2019-08-21 08:53:47 +03:00
#### *utils* . **isHexString** ( object , [ length ] ) **=>** *boolean*
2019-12-14 06:05:10 +03:00
Returns true if and only if *object* is a valid hex string.
If *length* is specified and *object* is not a valid [DataHexstring ](./ ) of
*length* bytes, an InvalidArgument error is thrown.
2019-08-21 08:53:47 +03:00
Converting between Arrays and Hexstrings
----------------------------------------
2019-12-14 06:05:10 +03:00
#### *utils* . **arrayify** ( datahexstringOrArrayish [ , options ] ) **=>** *Uint8Array*
2019-08-21 08:53:47 +03:00
2019-12-14 06:05:10 +03:00
Converts *datahexstringOrArrayish* to a Uint8Array.
2019-08-21 08:53:47 +03:00
2020-02-02 08:53:22 +03:00
#### *utils* . **hexlify** ( hexstringOrArrayish ) **=>** *string< [DataHexstring](./) >*
2019-08-21 08:53:47 +03:00
2019-12-14 06:05:10 +03:00
Converts *hexstringOrArrayish* to a [DataHexstring ](./ ).
2019-08-21 08:53:47 +03:00
2020-02-02 08:53:22 +03:00
#### *utils* . **hexValue** ( aBigNumberish ) **=>** *string< [Hexstring](./) >*
2019-08-21 08:53:47 +03:00
2019-12-14 06:05:10 +03:00
Converts *aBigNumberish* to a [Hexstring ](./ ), with no *unnecessary* leading
zeros.
2019-08-21 08:53:47 +03:00
### Examples
```javascript
2020-02-18 01:56:50 +03:00
Skipping JavaScript Evaluation.
2019-08-21 08:53:47 +03:00
```
Array Manipulation
------------------
#### *utils* . **concat** ( arrayOfBytesLike ) **=>** *Uint8Array*
2019-12-14 06:05:10 +03:00
Concatenates all the [BytesLike ](./ ) in *arrayOfBytesLike* into a single Uint8Array.
2019-08-21 08:53:47 +03:00
#### *utils* . **stripZeros** ( aBytesLike ) **=>** *Uint8Array*
2019-12-14 06:05:10 +03:00
Returns a Uint8Array with all leading `0` bytes of *aBtyesLike* removed.
2019-08-21 08:53:47 +03:00
#### *utils* . **zeroPad** ( aBytesLike , length ) **=>** *Uint8Array*
2019-12-14 06:05:10 +03:00
Retutns a Uint8Array of the data in *aBytesLike* with `0` bytes prepended to
*length* bytes long.
If *aBytesLike* is already longer than *length* bytes long, an InvalidArgument
error will be thrown.
2019-08-21 08:53:47 +03:00
Hexstring Manipulation
----------------------
2020-02-02 08:53:22 +03:00
#### *utils* . **hexConcat** ( arrayOfBytesLike ) **=>** *string< [DataHexstring](./) >*
2019-08-21 08:53:47 +03:00
2019-12-14 06:05:10 +03:00
Concatenates all the [BytesLike ](./ ) in *arrayOfBytesLike* into a single [DataHexstring ](./ )
2019-08-21 08:53:47 +03:00
2020-02-02 08:53:22 +03:00
#### *utils* . **hexDataLength** ( aBytesLike ) **=>** *string< [DataHexstring](./) >*
2019-08-21 08:53:47 +03:00
Returns the length (in bytes) of *aBytesLike* .
2020-02-02 08:53:22 +03:00
#### *utils* . **hexDataSlice** ( aBytesLike , offset [ , endOffset ] ) **=>** *string< [DataHexstring](./) >*
2019-08-21 08:53:47 +03:00
2019-12-14 06:05:10 +03:00
Returns a [DataHexstring ](./ ) representation of a slice of *aBytesLike* , from
*offset* (in bytes) to *endOffset* (in bytes). If *endOffset* is
omitted, the length of *aBytesLike* is used.
2019-08-21 08:53:47 +03:00
2020-02-02 08:53:22 +03:00
#### *utils* . **hexStripZeros** ( aBytesLike ) **=>** *string< [Hexstring](./) >*
2019-08-21 08:53:47 +03:00
2019-12-14 06:05:10 +03:00
Returns a [Hexstring ](./ ) representation of *aBytesLike* with all
leading zeros removed.
2019-08-21 08:53:47 +03:00
2020-02-02 08:53:22 +03:00
#### *utils* . **hexZeroPad** ( aBytesLike , length ) **=>** *string< [DataHexstring](./) >*
2019-08-21 08:53:47 +03:00
2019-12-14 06:05:10 +03:00
Returns a [DataHexstring ](./ ) representation of *aBytesLike* padded to *length* bytes.
2019-08-21 08:53:47 +03:00
2019-12-14 06:05:10 +03:00
If *aBytesLike* is already longer than *length* bytes long, an InvalidArgument
error will be thrown.
2019-08-21 08:53:47 +03:00
Signature Conversion
--------------------
2020-02-02 08:53:22 +03:00
#### *utils* . **joinSignature** ( aSignatureLike ) **=>** *string< [FlatSignature](./) >*
2019-08-21 08:53:47 +03:00
2019-12-14 06:05:10 +03:00
Return the flat-format of *aSignaturelike* , which is 65 bytes (130 nibbles)
long, concatenating the **r** , **s** and (normalized) **v** of a Signature.
2019-08-21 08:53:47 +03:00
2019-12-14 06:05:10 +03:00
#### *utils* . **splitSignature** ( aSignatureLikeOrBytesLike ) **=>** *[Signature](./)*
2019-08-21 08:53:47 +03:00
2019-12-14 06:05:10 +03:00
Return the full expanded-format of *aSignaturelike* or a flat-format [DataHexstring ](./ ).
Any missing properties will be computed.
2019-08-21 08:53:47 +03:00
2020-02-18 01:56:50 +03:00
Random Bytes
------------
#### *ethers* . *utils* . **randomBytes** ( length ) **=>** *Uint8Array*
Return a new Uint8Array of *length* random bytes.
2019-08-21 08:53:47 +03:00
-----
2020-02-18 01:56:50 +03:00
**Content Hash:** 36831e9bb9c02d184b22e8b4b8700572a545c366ced4d9811a92c560dafaf035