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
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const sized = Hex.assertSize(hex, 2); // Sized<2>
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
import * as Hex from './primitives/Hex/index.js';
const hex1 = Hex.from("0x1234");
const hex2 = Hex.clone(hex1);
console.log(Hex.equals(hex1, hex2)); // true
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
import * as Hex from './primitives/Hex/index.js';
Hex.concat('0x12', '0x34', '0x56'); // '0x123456'
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
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
Hex.equals(hex, Hex.from('0x1234')); // true
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
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const hex2 = Hex.from(new Uint8Array([0x12, 0x34]));
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
import * as Hex from './primitives/Hex/index.js';
Hex.fromBigInt(255n);      // '0xff'
Hex.fromBigInt(255n, 32);  // '0x00...00ff' (32 bytes)
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
import * as Hex from './primitives/Hex/index.js';
Hex.fromBoolean(true);  // '0x01'
Hex.fromBoolean(false); // '0x00'
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
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.fromBytes(new Uint8Array([0x12, 0x34])); // '0x1234'
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
import * as Hex from './primitives/Hex/index.js';
Hex.fromNumber(255);     // '0xff'
Hex.fromNumber(255, 2);  // '0x00ff'
Hex.fromNumber(0x1234);  // '0x1234'
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
import * as Hex from './primitives/Hex/index.js';
Hex.fromString('hello'); // '0x68656c6c6f'
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
import * as Hex from './primitives/Hex/index.js';
Hex.isHex('0x1234'); // true
Hex.isHex('1234');   // false
Hex.isHex('0xZZZZ'); // false
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
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
Hex.isSized(hex, 2); // true
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
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const padded = Hex.pad(hex, 4); // '0x00001234'
Hex.pad('0x1234', 1); // throws Error (2 bytes > 1 byte target)
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
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const padded = Hex.padRight(hex, 4); // '0x12340000'
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
import * as Hex from './primitives/Hex/index.js';
const random = Hex.random(32); // random 32-byte hex
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
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
Hex.size(hex); // 2
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
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x123456');
const sliced = Hex.slice(hex, 1); // '0x3456'
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
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0xff');
const big = Hex.toBigInt(hex); // 255n
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
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x01');
const bool = Hex.toBoolean(hex); // true
Hex.toBoolean('0x00'); // false
Hex.toBoolean('0x02'); // throws Error
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
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const bytes = Hex.toBytes(hex); // Uint8Array([0x12, 0x34])
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
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0xff');
const num = Hex.toNumber(hex); // 255
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
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x68656c6c6f');
const str = Hex.toString(hex); // 'hello'
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
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x00001234');
const trimmed = Hex.trim(hex); // '0x1234'
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
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.validate('0x1234'); // HexType
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
import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x12');
const result = Hex.xor(hex, Hex.from('0x34')); // '0x26'
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
import * as Hex from './primitives/Hex/index.js';
Hex.zero(4); // '0x00000000'

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

import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const sized = Hex.assertSize(hex, 2); // Sized<2>

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

import * as Hex from './primitives/Hex/index.js';
const hex1 = Hex.from("0x1234");
const hex2 = Hex.clone(hex1);
console.log(Hex.equals(hex1, hex2)); // true

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

import * as Hex from './primitives/Hex/index.js';
Hex.concat('0x12', '0x34', '0x56'); // '0x123456'

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

import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
Hex.equals(hex, Hex.from('0x1234')); // true

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

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

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

import * as Hex from './primitives/Hex/index.js';
Hex.fromBigInt(255n);      // '0xff'
Hex.fromBigInt(255n, 32);  // '0x00...00ff' (32 bytes)

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

import * as Hex from './primitives/Hex/index.js';
Hex.fromBoolean(true);  // '0x01'
Hex.fromBoolean(false); // '0x00'

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

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

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

import * as Hex from './primitives/Hex/index.js';
Hex.fromNumber(255);     // '0xff'
Hex.fromNumber(255, 2);  // '0x00ff'
Hex.fromNumber(0x1234);  // '0x1234'

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

import * as Hex from './primitives/Hex/index.js';
Hex.fromString('hello'); // '0x68656c6c6f'

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

import * as Hex from './primitives/Hex/index.js';
Hex.isHex('0x1234'); // true
Hex.isHex('1234');   // false
Hex.isHex('0xZZZZ'); // false

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

import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
Hex.isSized(hex, 2); // true

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

import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const padded = Hex.pad(hex, 4); // '0x00001234'
Hex.pad('0x1234', 1); // throws Error (2 bytes > 1 byte target)

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

import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
const padded = Hex.padRight(hex, 4); // '0x12340000'

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

import * as Hex from './primitives/Hex/index.js';
const random = Hex.random(32); // random 32-byte hex

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

import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x1234');
Hex.size(hex); // 2

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

import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x123456');
const sliced = Hex.slice(hex, 1); // '0x3456'

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

import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0xff');
const big = Hex.toBigInt(hex); // 255n

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

import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x01');
const bool = Hex.toBoolean(hex); // true
Hex.toBoolean('0x00'); // false
Hex.toBoolean('0x02'); // throws Error

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

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

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

import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0xff');
const num = Hex.toNumber(hex); // 255

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

import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x68656c6c6f');
const str = Hex.toString(hex); // 'hello'

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

import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x00001234');
const trimmed = Hex.trim(hex); // '0x1234'

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

import * as Hex from './primitives/Hex/index.js';
const hex = Hex.validate('0x1234'); // HexType

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

import * as Hex from './primitives/Hex/index.js';
const hex = Hex.from('0x12');
const result = Hex.xor(hex, Hex.from('0x34')); // '0x26'

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

import * as Hex from './primitives/Hex/index.js';
Hex.zero(4); // '0x00000000'

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