Byte Manipulation
Tra la la...
Types
Bytes
A Bytes object is any object which is an Array or TypedArray with 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
A BytesLike can be either a Bytes or a Hexstring.
Hexstring
A hexstring is a string which has a 0x
prefix followed by
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
- _vs — The compact representation of the (r, s) and v
- recoveryParam — The normalized (i.e. 0 or 1) value of v
SignatureLike
A SignatureLike is similar to a Signature, except redundant properties may be omitted.
For example, if *_vs* is specified, (r, s) and v can be omitted. Likewise, if recoverParam is provided, v can be omitted (as it can be computed).
Inspection
Returns true if and only if object is a valid Bytes.
Returns true if and only if object is a Bytes or an Array or TypedArray where each value is a valid byte (i.e. between 0 and 255 inclusive).
Returns true if and only if object is a valid hex string; if length is specified the length (in bytes) is also verified.
Converting between Arrays and Hexstrings
Converts hexstringOrArrayish to a Uint8Array. If a Hexstring is passed in, the length must be even.
Converts hexstringOrArrayish to a Hexstring. The result will always be zero-padded to even length.
Converts aBigNumberish to a Hexstring, with no unecessary leading zeros. The result of this function can be of odd-length.
Examples
// Convert a hexstring to a Uint8Array
arrayify("0x1234")
// [ 18, 52 ]
// Convert an Array to a hexstring
hexlify([1, 2, 3, 4])
// 0x01020304
// Convert an Object to a hexstring
hexlify({ length: 2, "0": 1, "1": 2 })
// 0x0102
// Convert an Array to a hexstring
hexlify([ 1 ])
// 0x01
// Convert a number to a stripped hex value
hexValue(1)
// 0x1
// Convert an Array to a stripped hex value
hexValue([ 1, 2 ])
// 0x102
Array Manipulation
Concatenates all the BytesLike in arrayOfBytesLike into a single Uint8Array.
Concatenates all the BytesLike in arrayOfBytesLike
Concatenates all the BytesLike in arrayOfBytesLike
Hexstring Manipulation
Returns the length (in bytes) of aBytesLike.
This will throw and error if aBytesLike is a Hexstring but is of odd-length.
Returns the length (in bytes) of aBytesLike.
@TODO
@TODO
Signature Conversion
Return the flat-format of a SignatureLike, which is 65 bytes (130 nibbles) long, concatenating the r, s and v of a Signature.
Return the full expanded-format of a SignatureLike or a flat-format Hexstring. Any missing properties will be computed.