- addHexPrefix
- baToJSON
- bufferToHex
- bufferToInt
- fromSigned
- setLengthLeft
- setLengthRight
- toBuffer
- toUnsigned
- unpadArray
- unpadBuffer
- unpadHexString
- zeros
▸ addHexPrefix(str
: string): string
Defined in bytes.ts:204
Adds "0x" to a given String
if it does not already start with "0x".
Parameters:
Name | Type |
---|---|
str |
string |
Returns: string
▸ baToJSON(ba
: any): any
Defined in bytes.ts:217
Converts a Buffer
or Array
to JSON.
Parameters:
Name | Type | Description |
---|---|---|
ba |
any | (Buffer |
Returns: any
(Array|String|null)
▸ bufferToHex(buf
: Buffer): string
Defined in bytes.ts:180
Converts a Buffer
into a 0x
-prefixed hex String
.
Parameters:
Name | Type | Description |
---|---|---|
buf |
Buffer | Buffer object to convert |
Returns: string
▸ bufferToInt(buf
: Buffer): number
Defined in bytes.ts:172
Converts a Buffer
to a Number
.
Parameters:
Name | Type | Description |
---|---|---|
buf |
Buffer | Buffer object to convert |
Returns: number
▸ fromSigned(num
: Buffer): BN
Defined in bytes.ts:189
Interprets a Buffer
as a signed integer and returns a BN
. Assumes 256-bit numbers.
Parameters:
Name | Type | Description |
---|---|---|
num |
Buffer | Signed integer value |
Returns: BN
▸ setLengthLeft(msg
: Buffer, length
: number): Buffer‹›
Defined in bytes.ts:21
Left Pads a Buffer
with leading zeros till it has length
bytes.
Or it truncates the beginning if it exceeds.
Parameters:
Name | Type | Description |
---|---|---|
msg |
Buffer | the value to pad (Buffer) |
length |
number | the number of bytes the output should be |
Returns: Buffer‹›
(Buffer)
▸ setLengthRight(msg
: Buffer, length
: number): Buffer‹›
Defined in bytes.ts:33
Right Pads a Buffer
with trailing zeros till it has length
bytes.
it truncates the end if it exceeds.
Parameters:
Name | Type | Description |
---|---|---|
msg |
Buffer | the value to pad (Buffer) |
length |
number | the number of bytes the output should be |
Returns: Buffer‹›
(Buffer)
▸ toBuffer(v
: string | number | BN | Buffer | Uint8Array | number[] | TransformableToArray | TransformableToBuffer | null | undefined): Buffer
Defined in bytes.ts:113
Attempts to turn a value into a Buffer
.
Inputs supported: Buffer
, String
, Number
, null/undefined, BN
and other objects with a toArray()
or toBuffer()
method.
Parameters:
Name | Type | Description |
---|---|---|
v |
string | number | BN | Buffer | Uint8Array | number[] | TransformableToArray | TransformableToBuffer | null | undefined | the value |
Returns: Buffer
▸ toUnsigned(num
: BN): Buffer
Defined in bytes.ts:197
Converts a BN
to an unsigned integer and returns it as a Buffer
. Assumes 256-bit numbers.
Parameters:
Name | Type | Description |
---|---|---|
num |
BN |
Returns: Buffer
▸ unpadArray(a
: number[]): number[]
Defined in bytes.ts:78
Trims leading zeros from an Array
(of numbers).
Parameters:
Name | Type | Description |
---|---|---|
a |
number[] | (number[]) |
Returns: number[]
(number[])
▸ unpadBuffer(a
: Buffer): Buffer
Defined in bytes.ts:68
Trims leading zeros from a Buffer
.
Parameters:
Name | Type | Description |
---|---|---|
a |
Buffer | (Buffer) |
Returns: Buffer
(Buffer)
▸ unpadHexString(a
: string): string
Defined in bytes.ts:88
Trims leading zeros from a hex-prefixed String
.
Parameters:
Name | Type | Description |
---|---|---|
a |
string | (String) |
Returns: string
(String)
▸ zeros(bytes
: number): Buffer
Defined in bytes.ts:10
Returns a buffer filled with 0s.
Parameters:
Name | Type | Description |
---|---|---|
bytes |
number | the number of bytes the buffer should be |
Returns: Buffer