@tevm/voltaire / index / BrandedBytes
BrandedBytes
Classes
InvalidBytesFormatError
Defined in: src/primitives/Bytes/errors.js:13Extends
Error
Constructors
Constructor
new InvalidBytesFormatError(Defined in: src/primitives/Bytes/errors.js:18message,details?):InvalidBytesFormatError
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:1Extends
Error
Constructors
Constructor
new InvalidBytesLengthError(Defined in: src/primitives/Bytes/errors.js:6message,details?):InvalidBytesLengthError
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:25Extends
Error
Constructors
Constructor
new InvalidValueError(Defined in: src/primitives/Bytes/errors.js:30message,details?):InvalidValueError
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
Defined in: src/primitives/Bytes/Bytes.index.ts:59constBytesType:object
Type Declaration
assert()
assert: (Assert that value is valid Bytes, throw if notvalue) =>BytesType
Parameters
value
unknown
Value to check
Returns
BytesType
The validated bytes
Throws
If value is not valid BytesExample
clone()
clone: (Clone Bytesbytes) =>BytesType
Parameters
bytes
BytesType
Bytes to clone
Returns
BytesType
Cloned Bytes
Example
compare()
compare: (Compare two Bytes (lexicographic)a,b) =>number
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: (…Concatenate multiple Bytesarrays) =>BytesType
Parameters
arrays
…BytesType[]
Bytes to concatenate
Returns
BytesType
Concatenated Bytes
Example
equals()
equals: (Check if two Bytes are equala,b) =>boolean
Parameters
a
BytesType
First Bytes
b
BytesType
Second Bytes
Returns
boolean
True if equal
Example
from()
from: (Create Bytes from various input types (universal constructor)value) =>BytesType
Parameters
value
Uint8Array, hex string, UTF-8 string, or number arraystring | Uint8Array<ArrayBufferLike> | number[]
Returns
BytesType
Bytes
Throws
If value type is unsupported or invalidExample
fromBigInt()
fromBigInt: (Convert bigint to Bytesvalue,size?) =>BytesType
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 sizeExample
fromHex()
fromHex: (Create Bytes from hex stringhex) =>BytesType
Parameters
hex
string
Hex string with 0x prefix
Returns
BytesType
Bytes
Throws
If hex string is invalidExample
fromNumber()
fromNumber: (Convert number to Bytesvalue,size?) =>BytesType
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_INTEGERExample
fromString()
fromString: (Create Bytes from UTF-8 stringstr) =>BytesType
Parameters
str
string
UTF-8 string
Returns
BytesType
Bytes
Example
isBytes()
isBytes: (Check if value is a valid Bytes (Uint8Array)value) =>value is BytesType
Parameters
value
unknown
Value to check
Returns
value is BytesType
True if value is Uint8Array
Example
isEmpty()
isEmpty: (Check if Bytes is emptybytes) =>boolean
Parameters
bytes
BytesType
Bytes to check
Returns
boolean
True if empty
Example
padLeft()
padLeft: (Pad Bytes on the left (start) with zeros to target sizebytes,targetSize) =>BytesType
Parameters
bytes
BytesType
Bytes to pad
targetSize
number
Target size in bytes
Returns
BytesType
Padded bytes
Throws
If bytes exceeds target sizeExample
padRight()
padRight: (Pad Bytes on the right (end) with zeros to target sizebytes,targetSize) =>BytesType
Parameters
bytes
BytesType
Bytes to pad
targetSize
number
Target size in bytes
Returns
BytesType
Padded bytes
Throws
If bytes exceeds target sizeExample
random()
random: (Generate random Bytes of specified sizesize) =>BytesType
Parameters
size
number
Number of random bytes to generate
Returns
BytesType
Random bytes
Example
size()
size: (Get size of Bytesbytes) =>number
Parameters
bytes
BytesType
Bytes
Returns
number
Size in bytes
Example
slice()
slice: (Slice Bytesbytes,start,end?) =>BytesType
Parameters
bytes
BytesType
Bytes to slice
start
number
Start index
end?
number
End index (optional)
Returns
BytesType
Sliced Bytes
Example
toBigInt()
toBigInt: (Convert Bytes to bigintbytes) =>bigint
Parameters
bytes
BytesType
Bytes to convert
Returns
bigint
BigInt value
Example
toHex()
toHex: (Convert Bytes to hex stringbytes) =>HexType
Parameters
bytes
BytesType
Bytes to convert
Returns
HexType
Hex string with 0x prefix
Example
toNumber()
toNumber: (Convert Bytes to numberbytes) =>number
Parameters
bytes
BytesType
Bytes to convert
Returns
number
Number value
Throws
If value exceeds MAX_SAFE_INTEGERExample
toString()
toString: (Convert Bytes to UTF-8 stringbytes) =>string
Parameters
bytes
BytesType
Bytes to convert
Returns
string
UTF-8 string
Example
trimLeft()
trimLeft: (Trim leading zeros from Bytesbytes) =>BytesType
Parameters
bytes
BytesType
Bytes to trim
Returns
BytesType
Trimmed bytes
Example
trimRight()
trimRight: (Trim trailing zeros from Bytesbytes) =>BytesType
Parameters
bytes
BytesType
Bytes to trim
Returns
BytesType
Trimmed bytes
Example
zero()
zero: (Create zero Bytes of specified sizesize) =>BytesType
Parameters
size
number
Size in bytes
Returns
BytesType
Zero Bytes
Example
Functions
assert()
assert(Defined in: src/primitives/Bytes/assert.js:17 Assert that value is valid Bytes, throw if notvalue):BytesType
Parameters
value
unknown
Value to check
Returns
BytesType
The validated bytes
Throws
If value is not valid BytesExample
clone()
clone(Defined in: src/primitives/Bytes/clone.js:12 Clone Bytesbytes):BytesType
Parameters
bytes
BytesType
Bytes to clone
Returns
BytesType
Cloned Bytes
Example
compare()
compare(Defined in: src/primitives/Bytes/compare.js:13 Compare two Bytes (lexicographic)a,b):number
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(…Defined in: src/primitives/Bytes/concat.js:12 Concatenate multiple Bytesarrays):BytesType
Parameters
arrays
…BytesType[]
Bytes to concatenate
Returns
BytesType
Concatenated Bytes
Example
equals()
equals(Defined in: src/primitives/Bytes/equals.js:13 Check if two Bytes are equala,b):boolean
Parameters
a
BytesType
First Bytes
b
BytesType
Second Bytes
Returns
boolean
True if equal
Example
from()
from(Defined in: src/primitives/Bytes/from.js:20 Create Bytes from various input types (universal constructor)value):BytesType
Parameters
value
Uint8Array, hex string, UTF-8 string, or number arraystring | Uint8Array<ArrayBufferLike> | number[]
Returns
BytesType
Bytes
Throws
If value type is unsupported or invalidExample
fromBigInt()
fromBigInt(Defined in: src/primitives/Bytes/fromBigInt.js:17 Convert bigint to Bytesvalue,size?):BytesType
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 sizeExample
fromHex()
fromHex(Defined in: src/primitives/Bytes/fromHex.js:16 Create Bytes from hex stringhex):BytesType
Parameters
hex
string
Hex string with 0x prefix
Returns
BytesType
Bytes
Throws
If hex string is invalidExample
fromNumber()
fromNumber(Defined in: src/primitives/Bytes/fromNumber.js:17 Convert number to Bytesvalue,size?):BytesType
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_INTEGERExample
fromString()
fromString(Defined in: src/primitives/Bytes/fromString.js:13 Create Bytes from UTF-8 stringstr):BytesType
Parameters
str
string
UTF-8 string
Returns
BytesType
Bytes
Example
isBytes()
isBytes(Defined in: src/primitives/Bytes/isBytes.js:15 Check if value is a valid Bytes (Uint8Array)value):value is BytesType
Parameters
value
unknown
Value to check
Returns
value is BytesType
True if value is Uint8Array
Example
isEmpty()
isEmpty(Defined in: src/primitives/Bytes/isEmpty.js:12 Check if Bytes is emptybytes):boolean
Parameters
bytes
BytesType
Bytes to check
Returns
boolean
True if empty
Example
padLeft()
padLeft(Defined in: src/primitives/Bytes/padLeft.js:15 Pad Bytes on the left (start) with zeros to target sizebytes,targetSize):BytesType
Parameters
bytes
BytesType
Bytes to pad
targetSize
number
Target size in bytes
Returns
BytesType
Padded bytes
Throws
If bytes exceeds target sizeExample
padRight()
padRight(Defined in: src/primitives/Bytes/padRight.js:15 Pad Bytes on the right (end) with zeros to target sizebytes,targetSize):BytesType
Parameters
bytes
BytesType
Bytes to pad
targetSize
number
Target size in bytes
Returns
BytesType
Padded bytes
Throws
If bytes exceeds target sizeExample
random()
random(Defined in: src/primitives/Bytes/random.js:14 Generate random Bytes of specified sizesize):BytesType
Parameters
size
number
Number of random bytes to generate
Returns
BytesType
Random bytes
Example
size()
size(Defined in: src/primitives/Bytes/size.js:12 Get size of Bytesbytes):number
Parameters
bytes
BytesType
Bytes
Returns
number
Size in bytes
Example
slice()
slice(Defined in: src/primitives/Bytes/slice.js:14 Slice Bytesbytes,start,end?):BytesType
Parameters
bytes
BytesType
Bytes to slice
start
number
Start index
end?
number
End index (optional)
Returns
BytesType
Sliced Bytes
Example
toBigInt()
toBigInt(Defined in: src/primitives/Bytes/toBigInt.js:14 Convert Bytes to bigintbytes):bigint
Parameters
bytes
BytesType
Bytes to convert
Returns
bigint
BigInt value
Example
toHex()
toHex(Defined in: src/primitives/Bytes/toHex.js:13 Convert Bytes to hex stringbytes):HexType
Parameters
bytes
BytesType
Bytes to convert
Returns
HexType
Hex string with 0x prefix
Example
toNumber()
toNumber(Defined in: src/primitives/Bytes/toNumber.js:15 Convert Bytes to numberbytes):number
Parameters
bytes
BytesType
Bytes to convert
Returns
number
Number value
Throws
If value exceeds MAX_SAFE_INTEGERExample
toString()
toString(Defined in: src/primitives/Bytes/toString.js:14 Convert Bytes to UTF-8 stringbytes):string
Parameters
bytes
BytesType
Bytes to convert
Returns
string
UTF-8 string
Example
trimLeft()
trimLeft(Defined in: src/primitives/Bytes/trimLeft.js:14 Trim leading zeros from Bytesbytes):BytesType
Parameters
bytes
BytesType
Bytes to trim
Returns
BytesType
Trimmed bytes
Example
trimRight()
trimRight(Defined in: src/primitives/Bytes/trimRight.js:14 Trim trailing zeros from Bytesbytes):BytesType
Parameters
bytes
BytesType
Bytes to trim
Returns
BytesType
Trimmed bytes
Example
zero()
zero(Defined in: src/primitives/Bytes/zero.js:12 Create zero Bytes of specified sizesize):BytesType
Parameters
size
number
Size in bytes
Returns
BytesType
Zero Bytes

