@tevm/voltaire / index / BrandedHex
BrandedHex
Variables
BrandedHex
Defined in: src/primitives/Hex/internal-index.ts:63constBrandedHex:object
Type Declaration
assertSize()
assertSize: <Assert hex has specific sizeTSize>(hex,targetSize) =>Sized<TSize>
Type Parameters
TSize
TSize extends number
Parameters
hex
HexType
Hex string to check
targetSize
TSize
Expected byte size
Returns
Sized<TSize>
Sized hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If size doesn’t matchExample
clone()
clone: (Create a copy of a Hex stringhex) =>HexType
Parameters
hex
HexType
Hex string to clone
Returns
HexType
Copy of the hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
concat()
concat: (…Concatenate multiple hex stringshexes) =>HexType
Parameters
hexes
…HexType[]
Hex strings to concatenate
Returns
HexType
Concatenated hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If missing 0x prefix or contains invalid hex charactersThrows
If hex has odd number of digitsExample
equals()
equals: (Check if two hex strings are equalhex,other) =>boolean
Parameters
hex
HexType
First hex string
other
HexType
Hex string to compare with
Returns
boolean
True if equal
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
from()
from: (Create Hex from string or bytesvalue) =>HexType
Parameters
value
Hex string or bytesstring | Uint8Array<ArrayBufferLike>
Returns
HexType
Hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
fromBigInt()
fromBigInt: (Convert bigint to hexvalue,size?) =>HexType
Parameters
value
bigint
BigInt to convert
size?
number
Optional byte size for padding
Returns
HexType
Hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
fromBoolean()
fromBoolean: (Convert boolean to hexvalue) =>Sized<1>
Parameters
value
boolean
Boolean to convert
Returns
Sized<1>
Hex string (‘0x01’ for true, ‘0x00’ for false)
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
fromBytes()
fromBytes: (Convert bytes to hexbytes) =>HexType
Parameters
bytes
Uint8Array
Byte array to convert
Returns
HexType
Hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
fromNumber()
fromNumber: (Convert number to hexvalue,size?) =>HexType
Parameters
value
number
Number to convert (must be safe integer)
size?
number
Optional byte size for padding
Returns
HexType
Hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If value exceeds Number.MAX_SAFE_INTEGER or is negativeExample
fromString()
fromString: (Convert string to hexstr) =>HexType
Parameters
str
string
String to convert
Returns
HexType
Hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
isHex()
isHex: (Check if string is valid hexvalue) =>value is HexType
Parameters
value
string
String to validate
Returns
value is HexType
True if valid hex format
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
isSized()
isSized: <Check if hex has specific byte sizeTSize>(hex,targetSize) =>hex is Sized<TSize>
Type Parameters
TSize
TSize extends number
Parameters
hex
HexType
Hex string to check
targetSize
TSize
Expected size in bytes
Returns
hex is Sized<TSize>
True if size matches
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
pad()
pad: (Pad hex to target size (left-padded with zeros)hex,targetSize) =>string
Parameters
hex
string
Hex string to pad
targetSize
number
Target size in bytes
Returns
string
Padded hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If hex exceeds target sizeExample
padRight()
padRight: (Pad hex to right (suffix with zeros)hex,targetSize) =>string
Parameters
hex
string
Hex string to pad
targetSize
number
Target size in bytes
Returns
string
Right-padded hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
random()
random: (Generate random hex of specific sizesize) =>HexType
Parameters
size
number
Size in bytes
Returns
HexType
Random hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
size()
size: (Get byte size of hexhex) =>number
Parameters
hex
string
Hex string
Returns
number
Size in bytes
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
slice()
slice: (Slice hex stringhex,start,end?) =>HexType
Parameters
hex
HexType
Hex string to slice
start
number
Start byte index
end?
number
End byte index (optional)
Returns
HexType
Sliced hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If missing 0x prefix or contains invalid hex charactersThrows
If hex has odd number of digitsExample
toBigInt()
toBigInt: (Convert hex to biginthex) =>bigint
Parameters
hex
HexType
Hex string to convert
Returns
bigint
BigInt value
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
toBoolean()
toBoolean: (Convert hex to boolean (strict: only 0x0/0x00 or 0x1/0x01 are valid)hex) =>boolean
Parameters
hex
HexType
Hex string to convert
Returns
boolean
Boolean value (true for 0x1/0x01, false for 0x0/0x00)
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If hex is not a valid boolean value (only 0 or 1 allowed)Example
toBytes()
toBytes: (Convert hex to byteshex) =>Uint8Array
Parameters
hex
Hex string to convertstring | HexType
Returns
Uint8Array
Byte array
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If missing 0x prefix or contains invalid hex charactersThrows
If hex has odd number of digitsExample
toNumber()
toNumber: (Convert hex to numberhex) =>number
Parameters
hex
HexType
Hex string to convert
Returns
number
Number value
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If hex represents value larger than MAX_SAFE_INTEGERExample
toString()
toString: (Convert hex to stringhex) =>string
Parameters
hex
HexType
Hex string to convert
Returns
string
Decoded string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If missing 0x prefix or contains invalid hex charactersThrows
If hex has odd number of digitsExample
trim()
trim: (Trim leading zeros from hexhex) =>HexType
Parameters
hex
HexType
Hex string to trim
Returns
HexType
Trimmed hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If missing 0x prefix or contains invalid hex charactersThrows
If hex has odd number of digitsExample
validate()
validate: (Validate hex stringvalue) =>HexType
Parameters
value
string
String to validate as hex
Returns
HexType
Validated hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If missing 0x prefix or contains invalid hex charactersExample
xor()
xor: (XOR with another hex string of same lengthhex,other) =>HexType
Parameters
hex
HexType
First hex string
other
HexType
Hex string to XOR with
Returns
HexType
XOR result
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If missing 0x prefix or contains invalid hex charactersThrows
If hex has odd number of digits or lengths don’t matchExample
zero()
zero: (Create zero-filled hex of specific sizesize) =>HexType
Parameters
size
number
Size in bytes
Returns
HexType
Zero-filled hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
Functions
assertSize()
assertSize<Defined in: src/primitives/Hex/assertSize.ts:20 Assert hex has specific sizeTSize>(hex,targetSize):Sized<TSize>
Type Parameters
TSize
TSize extends number
Parameters
hex
HexType
Hex string to check
targetSize
TSize
Expected byte size
Returns
Sized<TSize>
Sized hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If size doesn’t matchExample
clone()
clone(Defined in: src/primitives/Hex/clone.js:17 Create a copy of a Hex stringhex):HexType
Parameters
hex
HexType
Hex string to clone
Returns
HexType
Copy of the hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
concat()
concat(…Defined in: src/primitives/Hex/concat.ts:21 Concatenate multiple hex stringshexes):HexType
Parameters
hexes
…HexType[]
Hex strings to concatenate
Returns
HexType
Concatenated hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If missing 0x prefix or contains invalid hex charactersThrows
If hex has odd number of digitsExample
equals()
equals(Defined in: src/primitives/Hex/equals.ts:19 Check if two hex strings are equalhex,other):boolean
Parameters
hex
HexType
First hex string
other
HexType
Hex string to compare with
Returns
boolean
True if equal
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
from()
from(Defined in: src/primitives/Hex/from.ts:19 Create Hex from string or bytesvalue):HexType
Parameters
value
Hex string or bytesstring | Uint8Array<ArrayBufferLike>
Returns
HexType
Hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
fromBigInt()
fromBigInt(Defined in: src/primitives/Hex/fromBigInt.ts:19 Convert bigint to hexvalue,size?):HexType
Parameters
value
bigint
BigInt to convert
size?
number
Optional byte size for padding
Returns
HexType
Hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
fromBoolean()
fromBoolean(Defined in: src/primitives/Hex/fromBoolean.js:16 Convert boolean to hexvalue):Sized<1>
Parameters
value
boolean
Boolean to convert
Returns
Sized<1>
Hex string (‘0x01’ for true, ‘0x00’ for false)
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
fromBytes()
fromBytes(Defined in: src/primitives/Hex/fromBytes.ts:17 Convert bytes to hexbytes):HexType
Parameters
bytes
Uint8Array
Byte array to convert
Returns
HexType
Hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
fromNumber()
fromNumber(Defined in: src/primitives/Hex/fromNumber.js:18 Convert number to hexvalue,size?):HexType
Parameters
value
number
Number to convert (must be safe integer)
size?
number
Optional byte size for padding
Returns
HexType
Hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If value exceeds Number.MAX_SAFE_INTEGER or is negativeExample
fromString()
fromString(Defined in: src/primitives/Hex/fromString.ts:18 Convert string to hexstr):HexType
Parameters
str
string
String to convert
Returns
HexType
Hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
isHex()
isHex(Defined in: src/primitives/Hex/isHex.ts:20 Check if string is valid hexvalue):value is HexType
Parameters
value
string
String to validate
Returns
value is HexType
True if valid hex format
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
isSized()
isSized<Defined in: src/primitives/Hex/isSized.ts:19 Check if hex has specific byte sizeTSize>(hex,targetSize):hex is Sized<TSize>
Type Parameters
TSize
TSize extends number
Parameters
hex
HexType
Hex string to check
targetSize
TSize
Expected size in bytes
Returns
hex is Sized<TSize>
True if size matches
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
pad()
pad(Defined in: src/primitives/Hex/pad.js:21 Pad hex to target size (left-padded with zeros)hex,targetSize):string
Parameters
hex
string
Hex string to pad
targetSize
number
Target size in bytes
Returns
string
Padded hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If hex exceeds target sizeExample
padRight()
padRight(Defined in: src/primitives/Hex/padRight.js:20 Pad hex to right (suffix with zeros)hex,targetSize):string
Parameters
hex
string
Hex string to pad
targetSize
number
Target size in bytes
Returns
string
Right-padded hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
random()
random(Defined in: src/primitives/Hex/random.ts:18 Generate random hex of specific sizesize):HexType
Parameters
size
number
Size in bytes
Returns
HexType
Random hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
size()
size(Defined in: src/primitives/Hex/size.js:16 Get byte size of hexhex):number
Parameters
hex
string
Hex string
Returns
number
Size in bytes
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
slice()
slice(Defined in: src/primitives/Hex/slice.ts:24 Slice hex stringhex,start,end?):HexType
Parameters
hex
HexType
Hex string to slice
start
number
Start byte index
end?
number
End byte index (optional)
Returns
HexType
Sliced hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If missing 0x prefix or contains invalid hex charactersThrows
If hex has odd number of digitsExample
toBigInt()
toBigInt(Defined in: src/primitives/Hex/toBigInt.ts:18 Convert hex to biginthex):bigint
Parameters
hex
HexType
Hex string to convert
Returns
bigint
BigInt value
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
Example
toBoolean()
toBoolean(Defined in: src/primitives/Hex/toBoolean.js:20 Convert hex to boolean (strict: only 0x0/0x00 or 0x1/0x01 are valid)hex):boolean
Parameters
hex
HexType
Hex string to convert
Returns
boolean
Boolean value (true for 0x1/0x01, false for 0x0/0x00)
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If hex is not a valid boolean value (only 0 or 1 allowed)Example
toBytes()
toBytes(Defined in: src/primitives/Hex/toBytes.ts:21 Convert hex to byteshex):Uint8Array
Parameters
hex
Hex string to convertstring | HexType
Returns
Uint8Array
Byte array
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If missing 0x prefix or contains invalid hex charactersThrows
If hex has odd number of digitsExample
toNumber()
toNumber(Defined in: src/primitives/Hex/toNumber.js:18 Convert hex to numberhex):number
Parameters
hex
HexType
Hex string to convert
Returns
number
Number value
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If hex represents value larger than MAX_SAFE_INTEGERExample
toString()
toString(Defined in: src/primitives/Hex/toString.ts:22 Convert hex to stringhex):string
Parameters
hex
HexType
Hex string to convert
Returns
string
Decoded string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If missing 0x prefix or contains invalid hex charactersThrows
If hex has odd number of digitsExample
trim()
trim(Defined in: src/primitives/Hex/trim.ts:22 Trim leading zeros from hexhex):HexType
Parameters
hex
HexType
Hex string to trim
Returns
HexType
Trimmed hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If missing 0x prefix or contains invalid hex charactersThrows
If hex has odd number of digitsExample
validate()
validate(Defined in: src/primitives/Hex/validate.ts:19 Validate hex stringvalue):HexType
Parameters
value
string
String to validate as hex
Returns
HexType
Validated hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If missing 0x prefix or contains invalid hex charactersExample
xor()
xor(Defined in: src/primitives/Hex/xor.ts:24 XOR with another hex string of same lengthhex,other):HexType
Parameters
hex
HexType
First hex string
other
HexType
Hex string to XOR with
Returns
HexType
XOR result
See
https://voltaire.tevm.sh/primitives/hex for Hex documentationSince
0.0.0Throws
If missing 0x prefix or contains invalid hex charactersThrows
If hex has odd number of digits or lengths don’t matchExample
zero()
zero(Defined in: src/primitives/Hex/zero.ts:18 Create zero-filled hex of specific sizesize):HexType
Parameters
size
number
Size in bytes
Returns
HexType
Zero-filled hex string

