- addHexPrefix
- baToJSON
- bufferToHex
- bufferToInt
- fromSigned
- setLengthLeft
- setLengthRight
- toBuffer
- toUnsigned
- unpadArray
- unpadBuffer
- unpadHexString
- zeros
▸ addHexPrefix(str: string): string
Defined in bytes.ts:176
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:189
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:152
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:144
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:161
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:20
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:32
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: any): Buffer
Defined in bytes.ts:111
Attempts to turn a value into a Buffer. As input it supports Buffer, String, Number, null/undefined, BN and other objects with a toArray() method.
Parameters:
| Name | Type | Description |
|---|---|---|
v |
any | the value |
Returns: Buffer
▸ toUnsigned(num: BN): Buffer
Defined in bytes.ts:169
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:77
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:67
Trims leading zeros from a Buffer.
Parameters:
| Name | Type | Description |
|---|---|---|
a |
Buffer | (Buffer) |
Returns: Buffer
(Buffer)
▸ unpadHexString(a: string): string
Defined in bytes.ts:87
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:9
Returns a buffer filled with 0s.
Parameters:
| Name | Type | Description |
|---|---|---|
bytes |
number | the number of bytes the buffer should be |
Returns: Buffer