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

BrandedHex

Variables

BrandedHex

const BrandedHex: object
Defined in: src/primitives/Hex/internal-index.ts:63

Type Declaration

assertSize()
assertSize: <TSize>(hex, targetSize) => Sized<TSize>
Assert hex has specific size
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 documentation
Since
0.0.0
Throws
If size doesn’t match
Example
clone()
clone: (hex) => HexType
Create a copy of a Hex string
Parameters
hex
HexType Hex string to clone
Returns
HexType Copy of the hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentation
Since
0.0.0
Throws
Example
concat()
concat: (…hexes) => HexType
Concatenate multiple hex strings
Parameters
hexes
HexType[] Hex strings to concatenate
Returns
HexType Concatenated hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentation
Since
0.0.0
Throws
If missing 0x prefix or contains invalid hex characters
Throws
If hex has odd number of digits
Example
equals()
equals: (hex, other) => boolean
Check if two hex strings are equal
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 documentation
Since
0.0.0
Throws
Example
from()
from: (value) => HexType
Create Hex from string or bytes
Parameters
value
Hex string or bytes string | Uint8Array<ArrayBufferLike>
Returns
HexType Hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentation
Since
0.0.0
Throws
Example
fromBigInt()
fromBigInt: (value, size?) => HexType
Convert bigint to hex
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 documentation
Since
0.0.0
Throws
Example
fromBoolean()
fromBoolean: (value) => Sized<1>
Convert boolean to hex
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 documentation
Since
0.0.0
Throws
Example
fromBytes()
fromBytes: (bytes) => HexType
Convert bytes to hex
Parameters
bytes
Uint8Array Byte array to convert
Returns
HexType Hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentation
Since
0.0.0
Throws
Example
fromNumber()
fromNumber: (value, size?) => HexType
Convert number to hex
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 documentation
Since
0.0.0
Throws
If value exceeds Number.MAX_SAFE_INTEGER or is negative
Example
fromString()
fromString: (str) => HexType
Convert string to hex
Parameters
str
string String to convert
Returns
HexType Hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentation
Since
0.0.0
Throws
Example
isHex()
isHex: (value) => value is HexType
Check if string is valid hex
Parameters
value
string String to validate
Returns
value is HexType True if valid hex format
See
https://voltaire.tevm.sh/primitives/hex for Hex documentation
Since
0.0.0
Throws
Example
isSized()
isSized: <TSize>(hex, targetSize) => hex is Sized<TSize>
Check if hex has specific byte size
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 documentation
Since
0.0.0
Throws
Example
pad()
pad: (hex, targetSize) => string
Pad hex to target size (left-padded with zeros)
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 documentation
Since
0.0.0
Throws
If hex exceeds target size
Example
padRight()
padRight: (hex, targetSize) => string
Pad hex to right (suffix with zeros)
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 documentation
Since
0.0.0
Throws
Example
random()
random: (size) => HexType
Generate random hex of specific size
Parameters
size
number Size in bytes
Returns
HexType Random hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentation
Since
0.0.0
Throws
Example
size()
size: (hex) => number
Get byte size of hex
Parameters
hex
string Hex string
Returns
number Size in bytes
See
https://voltaire.tevm.sh/primitives/hex for Hex documentation
Since
0.0.0
Throws
Example
slice()
slice: (hex, start, end?) => HexType
Slice hex string
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 documentation
Since
0.0.0
Throws
If missing 0x prefix or contains invalid hex characters
Throws
If hex has odd number of digits
Example
toBigInt()
toBigInt: (hex) => bigint
Convert hex to bigint
Parameters
hex
HexType Hex string to convert
Returns
bigint BigInt value
See
https://voltaire.tevm.sh/primitives/hex for Hex documentation
Since
0.0.0
Throws
Example
toBoolean()
toBoolean: (hex) => boolean
Convert hex to boolean (strict: only 0x0/0x00 or 0x1/0x01 are valid)
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 documentation
Since
0.0.0
Throws
If hex is not a valid boolean value (only 0 or 1 allowed)
Example
toBytes()
toBytes: (hex) => Uint8Array
Convert hex to bytes
Parameters
hex
Hex string to convert string | HexType
Returns
Uint8Array Byte array
See
https://voltaire.tevm.sh/primitives/hex for Hex documentation
Since
0.0.0
Throws
If missing 0x prefix or contains invalid hex characters
Throws
If hex has odd number of digits
Example
toNumber()
toNumber: (hex) => number
Convert hex to number
Parameters
hex
HexType Hex string to convert
Returns
number Number value
See
https://voltaire.tevm.sh/primitives/hex for Hex documentation
Since
0.0.0
Throws
If hex represents value larger than MAX_SAFE_INTEGER
Example
toString()
toString: (hex) => string
Convert hex to string
Parameters
hex
HexType Hex string to convert
Returns
string Decoded string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentation
Since
0.0.0
Throws
If missing 0x prefix or contains invalid hex characters
Throws
If hex has odd number of digits
Example
trim()
trim: (hex) => HexType
Trim leading zeros from hex
Parameters
hex
HexType Hex string to trim
Returns
HexType Trimmed hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentation
Since
0.0.0
Throws
If missing 0x prefix or contains invalid hex characters
Throws
If hex has odd number of digits
Example
validate()
validate: (value) => HexType
Validate hex string
Parameters
value
string String to validate as hex
Returns
HexType Validated hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentation
Since
0.0.0
Throws
If missing 0x prefix or contains invalid hex characters
Example
xor()
xor: (hex, other) => HexType
XOR with another hex string of same length
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 documentation
Since
0.0.0
Throws
If missing 0x prefix or contains invalid hex characters
Throws
If hex has odd number of digits or lengths don’t match
Example
zero()
zero: (size) => HexType
Create zero-filled hex of specific size
Parameters
size
number Size in bytes
Returns
HexType Zero-filled hex string
See
https://voltaire.tevm.sh/primitives/hex for Hex documentation
Since
0.0.0
Throws
Example

Functions

assertSize()

assertSize<TSize>(hex, targetSize): Sized<TSize>
Defined in: src/primitives/Hex/assertSize.ts:20 Assert hex has specific size

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 documentation

Since

0.0.0

Throws

If size doesn’t match

Example


clone()

clone(hex): HexType
Defined in: src/primitives/Hex/clone.js:17 Create a copy of a Hex string

Parameters

hex
HexType Hex string to clone

Returns

HexType Copy of the hex string

See

https://voltaire.tevm.sh/primitives/hex for Hex documentation

Since

0.0.0

Throws

Example


concat()

concat(…hexes): HexType
Defined in: src/primitives/Hex/concat.ts:21 Concatenate multiple hex strings

Parameters

hexes
HexType[] Hex strings to concatenate

Returns

HexType Concatenated hex string

See

https://voltaire.tevm.sh/primitives/hex for Hex documentation

Since

0.0.0

Throws

If missing 0x prefix or contains invalid hex characters

Throws

If hex has odd number of digits

Example


equals()

equals(hex, other): boolean
Defined in: src/primitives/Hex/equals.ts:19 Check if two hex strings are equal

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 documentation

Since

0.0.0

Throws

Example


from()

from(value): HexType
Defined in: src/primitives/Hex/from.ts:19 Create Hex from string or bytes

Parameters

value
Hex string or bytes string | Uint8Array<ArrayBufferLike>

Returns

HexType Hex string

See

https://voltaire.tevm.sh/primitives/hex for Hex documentation

Since

0.0.0

Throws

Example


fromBigInt()

fromBigInt(value, size?): HexType
Defined in: src/primitives/Hex/fromBigInt.ts:19 Convert bigint to hex

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 documentation

Since

0.0.0

Throws

Example


fromBoolean()

fromBoolean(value): Sized<1>
Defined in: src/primitives/Hex/fromBoolean.js:16 Convert boolean to hex

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 documentation

Since

0.0.0

Throws

Example


fromBytes()

fromBytes(bytes): HexType
Defined in: src/primitives/Hex/fromBytes.ts:17 Convert bytes to hex

Parameters

bytes
Uint8Array Byte array to convert

Returns

HexType Hex string

See

https://voltaire.tevm.sh/primitives/hex for Hex documentation

Since

0.0.0

Throws

Example


fromNumber()

fromNumber(value, size?): HexType
Defined in: src/primitives/Hex/fromNumber.js:18 Convert number to hex

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 documentation

Since

0.0.0

Throws

If value exceeds Number.MAX_SAFE_INTEGER or is negative

Example


fromString()

fromString(str): HexType
Defined in: src/primitives/Hex/fromString.ts:18 Convert string to hex

Parameters

str
string String to convert

Returns

HexType Hex string

See

https://voltaire.tevm.sh/primitives/hex for Hex documentation

Since

0.0.0

Throws

Example


isHex()

isHex(value): value is HexType
Defined in: src/primitives/Hex/isHex.ts:20 Check if string is valid hex

Parameters

value
string String to validate

Returns

value is HexType True if valid hex format

See

https://voltaire.tevm.sh/primitives/hex for Hex documentation

Since

0.0.0

Throws

Example


isSized()

isSized<TSize>(hex, targetSize): hex is Sized<TSize>
Defined in: src/primitives/Hex/isSized.ts:19 Check if hex has specific byte size

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 documentation

Since

0.0.0

Throws

Example


pad()

pad(hex, targetSize): string
Defined in: src/primitives/Hex/pad.js:21 Pad hex to target size (left-padded with zeros)

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 documentation

Since

0.0.0

Throws

If hex exceeds target size

Example


padRight()

padRight(hex, targetSize): string
Defined in: src/primitives/Hex/padRight.js:20 Pad hex to right (suffix with zeros)

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 documentation

Since

0.0.0

Throws

Example


random()

random(size): HexType
Defined in: src/primitives/Hex/random.ts:18 Generate random hex of specific size

Parameters

size
number Size in bytes

Returns

HexType Random hex string

See

https://voltaire.tevm.sh/primitives/hex for Hex documentation

Since

0.0.0

Throws

Example


size()

size(hex): number
Defined in: src/primitives/Hex/size.js:16 Get byte size of hex

Parameters

hex
string Hex string

Returns

number Size in bytes

See

https://voltaire.tevm.sh/primitives/hex for Hex documentation

Since

0.0.0

Throws

Example


slice()

slice(hex, start, end?): HexType
Defined in: src/primitives/Hex/slice.ts:24 Slice hex string

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 documentation

Since

0.0.0

Throws

If missing 0x prefix or contains invalid hex characters

Throws

If hex has odd number of digits

Example


toBigInt()

toBigInt(hex): bigint
Defined in: src/primitives/Hex/toBigInt.ts:18 Convert hex to bigint

Parameters

hex
HexType Hex string to convert

Returns

bigint BigInt value

See

https://voltaire.tevm.sh/primitives/hex for Hex documentation

Since

0.0.0

Throws

Example


toBoolean()

toBoolean(hex): boolean
Defined in: src/primitives/Hex/toBoolean.js:20 Convert hex to boolean (strict: only 0x0/0x00 or 0x1/0x01 are valid)

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 documentation

Since

0.0.0

Throws

If hex is not a valid boolean value (only 0 or 1 allowed)

Example


toBytes()

toBytes(hex): Uint8Array
Defined in: src/primitives/Hex/toBytes.ts:21 Convert hex to bytes

Parameters

hex
Hex string to convert string | HexType

Returns

Uint8Array Byte array

See

https://voltaire.tevm.sh/primitives/hex for Hex documentation

Since

0.0.0

Throws

If missing 0x prefix or contains invalid hex characters

Throws

If hex has odd number of digits

Example


toNumber()

toNumber(hex): number
Defined in: src/primitives/Hex/toNumber.js:18 Convert hex to number

Parameters

hex
HexType Hex string to convert

Returns

number Number value

See

https://voltaire.tevm.sh/primitives/hex for Hex documentation

Since

0.0.0

Throws

If hex represents value larger than MAX_SAFE_INTEGER

Example


toString()

toString(hex): string
Defined in: src/primitives/Hex/toString.ts:22 Convert hex to string

Parameters

hex
HexType Hex string to convert

Returns

string Decoded string

See

https://voltaire.tevm.sh/primitives/hex for Hex documentation

Since

0.0.0

Throws

If missing 0x prefix or contains invalid hex characters

Throws

If hex has odd number of digits

Example


trim()

trim(hex): HexType
Defined in: src/primitives/Hex/trim.ts:22 Trim leading zeros from hex

Parameters

hex
HexType Hex string to trim

Returns

HexType Trimmed hex string

See

https://voltaire.tevm.sh/primitives/hex for Hex documentation

Since

0.0.0

Throws

If missing 0x prefix or contains invalid hex characters

Throws

If hex has odd number of digits

Example


validate()

validate(value): HexType
Defined in: src/primitives/Hex/validate.ts:19 Validate hex string

Parameters

value
string String to validate as hex

Returns

HexType Validated hex string

See

https://voltaire.tevm.sh/primitives/hex for Hex documentation

Since

0.0.0

Throws

If missing 0x prefix or contains invalid hex characters

Example


xor()

xor(hex, other): HexType
Defined in: src/primitives/Hex/xor.ts:24 XOR with another hex string of same length

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 documentation

Since

0.0.0

Throws

If missing 0x prefix or contains invalid hex characters

Throws

If hex has odd number of digits or lengths don’t match

Example


zero()

zero(size): HexType
Defined in: src/primitives/Hex/zero.ts:18 Create zero-filled hex of specific size

Parameters

size
number Size in bytes

Returns

HexType Zero-filled hex string

See

https://voltaire.tevm.sh/primitives/hex for Hex documentation

Since

0.0.0

Throws

Example

References

HexType

Renames and re-exports HexBrand

InvalidCharacterError

Re-exports InvalidCharacterError

InvalidFormatError

Re-exports InvalidFormatError

InvalidHexCharacterError

Re-exports InvalidHexCharacterError

InvalidHexFormatError

Re-exports InvalidHexFormatError

InvalidHexLengthError

Re-exports InvalidHexLengthError

InvalidLengthError

Re-exports InvalidLengthError

OddLengthError

Re-exports OddLengthError

OddLengthHexError

Re-exports OddLengthHexError