Skip to main content
@tevm/voltaire
@tevm/voltaire / index / BrandedBytes

BrandedBytes

Classes

InvalidBytesFormatError

Defined in: src/primitives/Bytes/errors.js:13

Extends

  • Error

Constructors

Constructor
new InvalidBytesFormatError(message, details?): InvalidBytesFormatError
Defined in: src/primitives/Bytes/errors.js:18
Parameters
message
string
details?
any
Returns
InvalidBytesFormatError
Overrides
Error.constructor

Properties

details
details: any
Defined in: src/primitives/Bytes/errors.js:21
name
name: string
Defined in: src/primitives/Bytes/errors.js:20
Inherited from
Error.name

InvalidBytesLengthError

Defined in: src/primitives/Bytes/errors.js:1

Extends

  • Error

Constructors

Constructor
new InvalidBytesLengthError(message, details?): InvalidBytesLengthError
Defined in: src/primitives/Bytes/errors.js:6
Parameters
message
string
details?
any
Returns
InvalidBytesLengthError
Overrides
Error.constructor

Properties

details
details: any
Defined in: src/primitives/Bytes/errors.js:9
name
name: string
Defined in: src/primitives/Bytes/errors.js:8
Inherited from
Error.name

InvalidValueError

Defined in: src/primitives/Bytes/errors.js:25

Extends

  • Error

Constructors

Constructor
new InvalidValueError(message, details?): InvalidValueError
Defined in: src/primitives/Bytes/errors.js:30
Parameters
message
string
details?
any
Returns
InvalidValueError
Overrides
Error.constructor

Properties

details
details: any
Defined in: src/primitives/Bytes/errors.js:33
name
name: string
Defined in: src/primitives/Bytes/errors.js:32
Inherited from
Error.name

Variables

BytesType

const BytesType: object
Defined in: src/primitives/Bytes/Bytes.index.ts:59

Type Declaration

assert()
assert: (value) => BytesType
Assert that value is valid Bytes, throw if not
Parameters
value
unknown Value to check
Returns
BytesType The validated bytes
Throws
If value is not valid Bytes
Example
clone()
clone: (bytes) => BytesType
Clone Bytes
Parameters
bytes
BytesType Bytes to clone
Returns
BytesType Cloned Bytes
Example
compare()
compare: (a, b) => number
Compare two Bytes (lexicographic)
Parameters
a
BytesType First Bytes
b
BytesType Second Bytes
Returns
number -1 if a < b, 0 if equal, 1 if a > b
Example
concat()
concat: (…arrays) => BytesType
Concatenate multiple Bytes
Parameters
arrays
BytesType[] Bytes to concatenate
Returns
BytesType Concatenated Bytes
Example
equals()
equals: (a, b) => boolean
Check if two Bytes are equal
Parameters
a
BytesType First Bytes
b
BytesType Second Bytes
Returns
boolean True if equal
Example
from()
from: (value) => BytesType
Create Bytes from various input types (universal constructor)
Parameters
value
Uint8Array, hex string, UTF-8 string, or number array string | Uint8Array<ArrayBufferLike> | number[]
Returns
BytesType Bytes
Throws
If value type is unsupported or invalid
Example
fromBigInt()
fromBigInt: (value, size?) => BytesType
Convert bigint to Bytes
Parameters
value
bigint BigInt to convert (must be non-negative)
size?
number Optional byte size (pads or throws if too small)
Returns
BytesType Bytes
Throws
If value is negative or doesn’t fit in size
Example
fromHex()
fromHex: (hex) => BytesType
Create Bytes from hex string
Parameters
hex
string Hex string with 0x prefix
Returns
BytesType Bytes
Throws
If hex string is invalid
Example
fromNumber()
fromNumber: (value, size?) => BytesType
Convert number to Bytes
Parameters
value
number Number to convert (must be safe integer, non-negative)
size?
number Optional byte size (pads or throws if too small)
Returns
BytesType Bytes
Throws
If value is negative, not an integer, or exceeds MAX_SAFE_INTEGER
Example
fromString()
fromString: (str) => BytesType
Create Bytes from UTF-8 string
Parameters
str
string UTF-8 string
Returns
BytesType Bytes
Example
isBytes()
isBytes: (value) => value is BytesType
Check if value is a valid Bytes (Uint8Array)
Parameters
value
unknown Value to check
Returns
value is BytesType True if value is Uint8Array
Example
isEmpty()
isEmpty: (bytes) => boolean
Check if Bytes is empty
Parameters
bytes
BytesType Bytes to check
Returns
boolean True if empty
Example
padLeft()
padLeft: (bytes, targetSize) => BytesType
Pad Bytes on the left (start) with zeros to target size
Parameters
bytes
BytesType Bytes to pad
targetSize
number Target size in bytes
Returns
BytesType Padded bytes
Throws
If bytes exceeds target size
Example
padRight()
padRight: (bytes, targetSize) => BytesType
Pad Bytes on the right (end) with zeros to target size
Parameters
bytes
BytesType Bytes to pad
targetSize
number Target size in bytes
Returns
BytesType Padded bytes
Throws
If bytes exceeds target size
Example
random()
random: (size) => BytesType
Generate random Bytes of specified size
Parameters
size
number Number of random bytes to generate
Returns
BytesType Random bytes
Example
size()
size: (bytes) => number
Get size of Bytes
Parameters
bytes
BytesType Bytes
Returns
number Size in bytes
Example
slice()
slice: (bytes, start, end?) => BytesType
Slice Bytes
Parameters
bytes
BytesType Bytes to slice
start
number Start index
end?
number End index (optional)
Returns
BytesType Sliced Bytes
Example
toBigInt()
toBigInt: (bytes) => bigint
Convert Bytes to bigint
Parameters
bytes
BytesType Bytes to convert
Returns
bigint BigInt value
Example
toHex()
toHex: (bytes) => HexType
Convert Bytes to hex string
Parameters
bytes
BytesType Bytes to convert
Returns
HexType Hex string with 0x prefix
Example
toNumber()
toNumber: (bytes) => number
Convert Bytes to number
Parameters
bytes
BytesType Bytes to convert
Returns
number Number value
Throws
If value exceeds MAX_SAFE_INTEGER
Example
toString()
toString: (bytes) => string
Convert Bytes to UTF-8 string
Parameters
bytes
BytesType Bytes to convert
Returns
string UTF-8 string
Example
trimLeft()
trimLeft: (bytes) => BytesType
Trim leading zeros from Bytes
Parameters
bytes
BytesType Bytes to trim
Returns
BytesType Trimmed bytes
Example
trimRight()
trimRight: (bytes) => BytesType
Trim trailing zeros from Bytes
Parameters
bytes
BytesType Bytes to trim
Returns
BytesType Trimmed bytes
Example
zero()
zero: (size) => BytesType
Create zero Bytes of specified size
Parameters
size
number Size in bytes
Returns
BytesType Zero Bytes
Example

Functions

assert()

assert(value): BytesType
Defined in: src/primitives/Bytes/assert.js:17 Assert that value is valid Bytes, throw if not

Parameters

value
unknown Value to check

Returns

BytesType The validated bytes

Throws

If value is not valid Bytes

Example


clone()

clone(bytes): BytesType
Defined in: src/primitives/Bytes/clone.js:12 Clone Bytes

Parameters

bytes
BytesType Bytes to clone

Returns

BytesType Cloned Bytes

Example


compare()

compare(a, b): number
Defined in: src/primitives/Bytes/compare.js:13 Compare two Bytes (lexicographic)

Parameters

a
BytesType First Bytes
b
BytesType Second Bytes

Returns

number -1 if a < b, 0 if equal, 1 if a > b

Example


concat()

concat(…arrays): BytesType
Defined in: src/primitives/Bytes/concat.js:12 Concatenate multiple Bytes

Parameters

arrays
BytesType[] Bytes to concatenate

Returns

BytesType Concatenated Bytes

Example


equals()

equals(a, b): boolean
Defined in: src/primitives/Bytes/equals.js:13 Check if two Bytes are equal

Parameters

a
BytesType First Bytes
b
BytesType Second Bytes

Returns

boolean True if equal

Example


from()

from(value): BytesType
Defined in: src/primitives/Bytes/from.js:20 Create Bytes from various input types (universal constructor)

Parameters

value
Uint8Array, hex string, UTF-8 string, or number array string | Uint8Array<ArrayBufferLike> | number[]

Returns

BytesType Bytes

Throws

If value type is unsupported or invalid

Example


fromBigInt()

fromBigInt(value, size?): BytesType
Defined in: src/primitives/Bytes/fromBigInt.js:17 Convert bigint to Bytes

Parameters

value
bigint BigInt to convert (must be non-negative)
size?
number Optional byte size (pads or throws if too small)

Returns

BytesType Bytes

Throws

If value is negative or doesn’t fit in size

Example


fromHex()

fromHex(hex): BytesType
Defined in: src/primitives/Bytes/fromHex.js:16 Create Bytes from hex string

Parameters

hex
string Hex string with 0x prefix

Returns

BytesType Bytes

Throws

If hex string is invalid

Example


fromNumber()

fromNumber(value, size?): BytesType
Defined in: src/primitives/Bytes/fromNumber.js:17 Convert number to Bytes

Parameters

value
number Number to convert (must be safe integer, non-negative)
size?
number Optional byte size (pads or throws if too small)

Returns

BytesType Bytes

Throws

If value is negative, not an integer, or exceeds MAX_SAFE_INTEGER

Example


fromString()

fromString(str): BytesType
Defined in: src/primitives/Bytes/fromString.js:13 Create Bytes from UTF-8 string

Parameters

str
string UTF-8 string

Returns

BytesType Bytes

Example


isBytes()

isBytes(value): value is BytesType
Defined in: src/primitives/Bytes/isBytes.js:15 Check if value is a valid Bytes (Uint8Array)

Parameters

value
unknown Value to check

Returns

value is BytesType True if value is Uint8Array

Example


isEmpty()

isEmpty(bytes): boolean
Defined in: src/primitives/Bytes/isEmpty.js:12 Check if Bytes is empty

Parameters

bytes
BytesType Bytes to check

Returns

boolean True if empty

Example


padLeft()

padLeft(bytes, targetSize): BytesType
Defined in: src/primitives/Bytes/padLeft.js:15 Pad Bytes on the left (start) with zeros to target size

Parameters

bytes
BytesType Bytes to pad
targetSize
number Target size in bytes

Returns

BytesType Padded bytes

Throws

If bytes exceeds target size

Example


padRight()

padRight(bytes, targetSize): BytesType
Defined in: src/primitives/Bytes/padRight.js:15 Pad Bytes on the right (end) with zeros to target size

Parameters

bytes
BytesType Bytes to pad
targetSize
number Target size in bytes

Returns

BytesType Padded bytes

Throws

If bytes exceeds target size

Example


random()

random(size): BytesType
Defined in: src/primitives/Bytes/random.js:14 Generate random Bytes of specified size

Parameters

size
number Number of random bytes to generate

Returns

BytesType Random bytes

Example


size()

size(bytes): number
Defined in: src/primitives/Bytes/size.js:12 Get size of Bytes

Parameters

bytes
BytesType Bytes

Returns

number Size in bytes

Example


slice()

slice(bytes, start, end?): BytesType
Defined in: src/primitives/Bytes/slice.js:14 Slice Bytes

Parameters

bytes
BytesType Bytes to slice
start
number Start index
end?
number End index (optional)

Returns

BytesType Sliced Bytes

Example


toBigInt()

toBigInt(bytes): bigint
Defined in: src/primitives/Bytes/toBigInt.js:14 Convert Bytes to bigint

Parameters

bytes
BytesType Bytes to convert

Returns

bigint BigInt value

Example


toHex()

toHex(bytes): HexType
Defined in: src/primitives/Bytes/toHex.js:13 Convert Bytes to hex string

Parameters

bytes
BytesType Bytes to convert

Returns

HexType Hex string with 0x prefix

Example


toNumber()

toNumber(bytes): number
Defined in: src/primitives/Bytes/toNumber.js:15 Convert Bytes to number

Parameters

bytes
BytesType Bytes to convert

Returns

number Number value

Throws

If value exceeds MAX_SAFE_INTEGER

Example


toString()

toString(bytes): string
Defined in: src/primitives/Bytes/toString.js:14 Convert Bytes to UTF-8 string

Parameters

bytes
BytesType Bytes to convert

Returns

string UTF-8 string

Example


trimLeft()

trimLeft(bytes): BytesType
Defined in: src/primitives/Bytes/trimLeft.js:14 Trim leading zeros from Bytes

Parameters

bytes
BytesType Bytes to trim

Returns

BytesType Trimmed bytes

Example


trimRight()

trimRight(bytes): BytesType
Defined in: src/primitives/Bytes/trimRight.js:14 Trim trailing zeros from Bytes

Parameters

bytes
BytesType Bytes to trim

Returns

BytesType Trimmed bytes

Example


zero()

zero(size): BytesType
Defined in: src/primitives/Bytes/zero.js:12 Create zero Bytes of specified size

Parameters

size
number Size in bytes

Returns

BytesType Zero Bytes

Example