Skip to main content
@tevm/voltaire
@tevm/voltaire / primitives/Hex

primitives/Hex

Classes

InvalidCharacterError

Defined in: src/primitives/Hex/errors.ts:15

Extends

  • Error

Constructors

Constructor
new InvalidCharacterError(message): InvalidCharacterError
Defined in: src/primitives/Hex/errors.ts:16
Parameters
message
string = "Invalid hex character"
Returns
InvalidCharacterError
Overrides
Error.constructor

InvalidFormatError

Defined in: src/primitives/Hex/errors.ts:1

Extends

  • Error

Constructors

Constructor
new InvalidFormatError(message): InvalidFormatError
Defined in: src/primitives/Hex/errors.ts:2
Parameters
message
string = "Invalid hex format: missing 0x prefix"
Returns
InvalidFormatError
Overrides
Error.constructor

InvalidLengthError

Defined in: src/primitives/Hex/errors.ts:8

Extends

  • Error

Constructors

Constructor
new InvalidLengthError(message): InvalidLengthError
Defined in: src/primitives/Hex/errors.ts:9
Parameters
message
string = "Invalid hex length"
Returns
InvalidLengthError
Overrides
Error.constructor

OddLengthError

Defined in: src/primitives/Hex/errors.ts:22

Extends

  • Error

Constructors

Constructor
new OddLengthError(message): OddLengthError
Defined in: src/primitives/Hex/errors.ts:23
Parameters
message
string = "Odd length hex string"
Returns
OddLengthError
Overrides
Error.constructor

Type Aliases

Bytes

Bytes<N> = Sized<N>
Defined in: src/primitives/Hex/HexType.ts:25 Hex string of exactly N bytes

Type Parameters

N
N extends number

HexBrand

HexBrand = HexType
Defined in: src/primitives/Hex/HexType.ts:11 Alias for HexType

HexType

HexType = `0x${string}` & object
Defined in: src/primitives/Hex/HexType.ts:6 Branded Hex type (unsized)

Type Declaration

[brand]
readonly [brand]: "Hex"

Sized

Sized<TSize> = `0x${string}` & object
Defined in: src/primitives/Hex/HexType.ts:17 Sized Hex type with specific byte size

Type Declaration

[brand]
readonly [brand]: "Hex"
size
readonly size: TSize

Type Parameters

TSize
TSize extends number = number

Example

HexType.Sized<4> = '0x12345678' (4 bytes = 8 hex chars)

Variables

fromBytes()

const fromBytes: (bytes) => HexType = HexFuncs.fromBytes
Defined in: src/primitives/Hex/Hex.ts:8 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

import * as Hex from './primitives/Hex/index.js';
const hex = Hex.fromBytes(new Uint8Array([0x12, 0x34])); // '0x1234'

InvalidHexCharacterError

const InvalidHexCharacterError: typeof InvalidCharacterError = InvalidCharacterError
Defined in: src/primitives/Hex/errors.ts:31

InvalidHexFormatError

const InvalidHexFormatError: typeof InvalidFormatError = InvalidFormatError
Defined in: src/primitives/Hex/errors.ts:30

InvalidHexLengthError

const InvalidHexLengthError: typeof InvalidLengthError = InvalidLengthError
Defined in: src/primitives/Hex/errors.ts:33

OddLengthHexError

const OddLengthHexError: typeof OddLengthError = OddLengthError
Defined in: src/primitives/Hex/errors.ts:32

toBytes()

const toBytes: (hex) => Uint8Array = HexFuncs.toBytes
Defined in: src/primitives/Hex/Hex.ts:9 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

import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const bytes = Hex.toBytes(hex); // Uint8Array([0x12, 0x34])

References

default

Renames and re-exports Hex

Hex

Re-exports Hex