ethereumjs-util / bytes
- addHexPrefix
- baToJSON
- bufferToHex
- bufferToInt
- fromSigned
- setLengthLeft
- setLengthRight
- toBuffer
- toUnsigned
- unpadArray
- unpadBuffer
- unpadHexString
- zeros
Ƭ ToBufferInputTypes: PrefixedHexString | number
| BN | Buffer
| Uint8Array
| number
[] | TransformableToArray | TransformableToBuffer | null
| undefined
packages/util/src/bytes.ts:108
▸ Const
addHexPrefix(str
): string
Adds "0x" to a given String
if it does not already start with "0x".
Name | Type |
---|---|
str |
string |
string
packages/util/src/bytes.ts:205
▸ Const
baToJSON(ba
): any
Converts a Buffer
or Array
to JSON.
Name | Type | Description |
---|---|---|
ba |
any |
(Buffer|Array) |
any
(Array|String|null)
packages/util/src/bytes.ts:218
▸ Const
bufferToHex(buf
): string
Converts a Buffer
into a 0x
-prefixed hex String
.
Name | Type | Description |
---|---|---|
buf |
Buffer |
Buffer object to convert |
string
packages/util/src/bytes.ts:181
▸ Const
bufferToInt(buf
): number
Converts a Buffer
to a Number
.
throws
If the input number exceeds 53 bits.
Name | Type | Description |
---|---|---|
buf |
Buffer |
Buffer object to convert |
number
packages/util/src/bytes.ts:173
▸ Const
fromSigned(num
): BN
Interprets a Buffer
as a signed integer and returns a BN
. Assumes 256-bit numbers.
Name | Type | Description |
---|---|---|
num |
Buffer |
Signed integer value |
packages/util/src/bytes.ts:190
▸ Const
setLengthLeft(msg
, length
): Buffer
Left Pads a Buffer
with leading zeros till it has length
bytes.
Or it truncates the beginning if it exceeds.
Name | Type | Description |
---|---|---|
msg |
Buffer |
the value to pad (Buffer) |
length |
number |
the number of bytes the output should be |
Buffer
(Buffer)
▸ Const
setLengthRight(msg
, length
): Buffer
Right Pads a Buffer
with trailing zeros till it has length
bytes.
it truncates the end if it exceeds.
Name | Type | Description |
---|---|---|
msg |
Buffer |
the value to pad (Buffer) |
length |
number |
the number of bytes the output should be |
Buffer
(Buffer)
▸ Const
toBuffer(v
): Buffer
Attempts to turn a value into a Buffer
.
Inputs supported: Buffer
, String
(hex-prefixed), Number
, null/undefined, BN
and other objects
with a toArray()
or toBuffer()
method.
Name | Type | Description |
---|---|---|
v |
ToBufferInputTypes | the value |
Buffer
packages/util/src/bytes.ts:126
▸ Const
toUnsigned(num
): Buffer
Converts a BN
to an unsigned integer and returns it as a Buffer
. Assumes 256-bit numbers.
Name | Type |
---|---|
num |
BN |
Buffer
packages/util/src/bytes.ts:198
▸ Const
unpadArray(a
): number
[]
Trims leading zeros from an Array
(of numbers).
Name | Type | Description |
---|---|---|
a |
number [] |
(number[]) |
number
[]
(number[])
▸ Const
unpadBuffer(a
): Buffer
Trims leading zeros from a Buffer
.
Name | Type | Description |
---|---|---|
a |
Buffer |
(Buffer) |
Buffer
(Buffer)
▸ Const
unpadHexString(a
): string
Trims leading zeros from a hex-prefixed String
.
Name | Type | Description |
---|---|---|
a |
string |
(String) |
string
(String)
packages/util/src/bytes.ts:102
▸ Const
zeros(bytes
): Buffer
Returns a buffer filled with 0s.
Name | Type | Description |
---|---|---|
bytes |
number |
the number of bytes the buffer should be |
Buffer