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

primitives/Bytes32

Bytes32 - Fixed-size 32-byte array type Generic 32-byte data structure used throughout Ethereum for various purposes including storage values, contract data, and numeric representations.

Classes

InvalidBytes32HexError

Defined in: src/primitives/Bytes32/errors.js:10 Error thrown when Bytes32 hex format is invalid

Extends

Constructors

Constructor
new InvalidBytes32HexError(message?, options?): InvalidBytes32HexError
Defined in: src/primitives/Bytes32/errors.js:21
Parameters
message?
string Error message
options?
Error options
cause?
Error Root cause error
code?
string Error code
context?
Record<string, unknown> Additional context
docsPath?
string Documentation path
expected?
string Expected format
value?
unknown Invalid value
Returns
InvalidBytes32HexError
Overrides
InvalidFormatError.constructor

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
InvalidFormatError.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
Inherited from
InvalidFormatError.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
Inherited from
InvalidFormatError.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
Inherited from
InvalidFormatError.docsPath
expected
expected: string
Defined in: src/primitives/errors/ValidationError.ts:19
Inherited from
InvalidFormatError.expected
name
name: string
Defined in: src/primitives/Bytes32/errors.js:30
Inherited from
InvalidFormatError.name
value
value: unknown
Defined in: src/primitives/errors/ValidationError.ts:18
Inherited from
InvalidFormatError.value

Methods

getErrorChain()
getErrorChain(): string
Defined in: src/primitives/errors/AbstractError.ts:94 Get full error chain as string for logging
Returns
string
Inherited from
InvalidFormatError.getErrorChain
toJSON()
toJSON(): Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetry
Returns
Record<string, unknown>
Inherited from
InvalidFormatError.toJSON

InvalidBytes32LengthError

Defined in: src/primitives/Bytes32/errors.js:37 Error thrown when Bytes32 has invalid length

Extends

Constructors

Constructor
new InvalidBytes32LengthError(message?, options?): InvalidBytes32LengthError
Defined in: src/primitives/Bytes32/errors.js:48
Parameters
message?
string Error message
options?
Error options
cause?
Error Root cause error
code?
string Error code
context?
Record<string, unknown> Additional context
docsPath?
string Documentation path
expected?
string Expected length
value?
unknown Invalid value
Returns
InvalidBytes32LengthError
Overrides
InvalidLengthError.constructor

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
InvalidLengthError.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
Inherited from
InvalidLengthError.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
Inherited from
InvalidLengthError.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
Inherited from
InvalidLengthError.docsPath
expected
expected: string
Defined in: src/primitives/errors/ValidationError.ts:19
Inherited from
InvalidLengthError.expected
name
name: string
Defined in: src/primitives/Bytes32/errors.js:57
Inherited from
InvalidLengthError.name
value
value: unknown
Defined in: src/primitives/errors/ValidationError.ts:18
Inherited from
InvalidLengthError.value

Methods

getErrorChain()
getErrorChain(): string
Defined in: src/primitives/errors/AbstractError.ts:94 Get full error chain as string for logging
Returns
string
Inherited from
InvalidLengthError.getErrorChain
toJSON()
toJSON(): Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetry
Returns
Record<string, unknown>
Inherited from
InvalidLengthError.toJSON

InvalidBytes32ValueError

Defined in: src/primitives/Bytes32/errors.js:64 Error thrown when value is invalid for Bytes32

Extends

Constructors

Constructor
new InvalidBytes32ValueError(message, options?): InvalidBytes32ValueError
Defined in: src/primitives/Bytes32/errors.js:75
Parameters
message
string Error message
options?
Error options
cause?
Error Root cause error
code?
string Error code
context?
Record<string, unknown> Additional context
docsPath?
string Documentation path
expected?
string Expected value
value?
unknown Invalid value
Returns
InvalidBytes32ValueError
Overrides
ValidationError.constructor

Properties

cause?
optional cause: Error
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)
Inherited from
ValidationError.cause
code
code: string
Defined in: src/primitives/errors/AbstractError.ts:39 Machine-readable error code for programmatic handling
Example
Inherited from
ValidationError.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
Inherited from
ValidationError.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
Inherited from
ValidationError.docsPath
expected
expected: string
Defined in: src/primitives/errors/ValidationError.ts:19
Inherited from
ValidationError.expected
name
name: string
Defined in: src/primitives/Bytes32/errors.js:84
Inherited from
ValidationError.name
value
value: unknown
Defined in: src/primitives/errors/ValidationError.ts:18
Inherited from
ValidationError.value

Methods

getErrorChain()
getErrorChain(): string
Defined in: src/primitives/errors/AbstractError.ts:94 Get full error chain as string for logging
Returns
string
Inherited from
ValidationError.getErrorChain
toJSON()
toJSON(): Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetry
Returns
Record<string, unknown>
Inherited from
ValidationError.toJSON

Type Aliases

Bytes32Like

Bytes32Like = Bytes32Type | string | Uint8Array | bigint | number
Defined in: src/primitives/Bytes32/Bytes32Type.ts:18 Inputs that can be converted to Bytes32

Bytes32Type

Bytes32Type = Uint8Array & object
Defined in: src/primitives/Bytes32/Bytes32Type.ts:11 Bytes32 - Fixed-size 32-byte array type Generic 32-byte data structure used throughout Ethereum for various purposes including storage values, contract data, and numeric representations. While Hash is specifically for cryptographic hashes, Bytes32 is the general-purpose 32-byte type that can represent any 32-byte data.

Type Declaration

[brand]
readonly [brand]: "Bytes32"

Variables

Bytes32

const Bytes32: object
Defined in: src/primitives/Bytes32/index.ts:87

Type Declaration

bitwiseAnd()
bitwiseAnd: (a, b) => Bytes32Type
Perform bitwise AND on two Bytes32 values
Parameters
a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32
Returns
Bytes32Type Result of a & b
Example
bitwiseOr()
bitwiseOr: (a, b) => Bytes32Type
Perform bitwise OR on two Bytes32 values
Parameters
a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32
Returns
Bytes32Type Result of a | b
Example
bitwiseXor()
bitwiseXor: (a, b) => Bytes32Type
Perform bitwise XOR on two Bytes32 values
Parameters
a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32
Returns
Bytes32Type Result of a ^ b
Example
clone()
clone: (bytes32) => Bytes32Type
Create an independent copy of Bytes32
Parameters
bytes32
Bytes32Type Bytes32 to clone
Returns
Bytes32Type New Bytes32 with same values
Example
compare()
compare: (a, b) => number
Compare two Bytes32 values lexicographically
Parameters
a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32
Returns
number -1 if a < b, 0 if equal, 1 if a > b
Example
equals()
equals: (a, b) => boolean
Check if two Bytes32 values are equal
Parameters
a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32
Returns
boolean True if equal
Example
from()
from: (value) => Bytes32Type
Create Bytes32 from various input types (universal constructor)
Parameters
value
Number, bigint, hex string, or Uint8Array string | number | bigint | Uint8Array<ArrayBufferLike>
Returns
Bytes32Type Bytes32
Throws
If value type is unsupported or invalid
Example
fromBigint()
fromBigint: (value) => Bytes32Type
Create Bytes32 from bigint (big-endian)
Parameters
value
bigint Bigint to convert (must fit in 256 bits)
Returns
Bytes32Type Bytes32
Throws
If value is negative or exceeds 256 bits
Example
fromBytes()
fromBytes: (bytes) => Bytes32Type
Create Bytes32 from bytes. Input must be exactly 32 bytes.
Parameters
bytes
Uint8Array<ArrayBufferLike> Input bytes (must be 32 bytes)
Returns
Bytes32Type Bytes32
Throws
If bytes length is not 32
Example
fromHex()
fromHex: (hex) => Bytes32Type
Create Bytes32 from hex string (with or without 0x prefix)
Parameters
hex
string Hex string (64 chars, with or without 0x prefix)
Returns
Bytes32Type Bytes32
Throws
If hex length is not 64 characters
Throws
If hex contains invalid characters
Example
fromNumber()
fromNumber: (value) => Bytes32Type
Create Bytes32 from number (big-endian, zero-padded)
Parameters
value
number Number to convert
Returns
Bytes32Type Bytes32
Example
isZero()
isZero: (bytes32) => boolean
Check if Bytes32 is all zeros
Parameters
bytes32
Bytes32Type Bytes32 to check
Returns
boolean True if all bytes are zero
Example
max()
max: (a, b) => Bytes32Type
Return the maximum of two Bytes32 values (lexicographically)
Parameters
a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32
Returns
Bytes32Type The larger value
Example
min()
min: (a, b) => Bytes32Type
Return the minimum of two Bytes32 values (lexicographically)
Parameters
a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32
Returns
Bytes32Type The smaller value
Example
SIZE
SIZE: number
Size of Bytes32 in bytes
toBigint()
toBigint: (bytes32) => bigint
Convert Bytes32 to bigint (big-endian)
Parameters
bytes32
Bytes32Type Bytes32 to convert
Returns
bigint Big-endian bigint representation
Example
toHex()
toHex: (bytes32) => string
Convert Bytes32 to hex string with 0x prefix
Parameters
bytes32
Bytes32Type Bytes32 to convert
Returns
string Lowercase hex string with 0x prefix (66 chars total)
Example
toNumber()
toNumber: (bytes32) => number
Convert Bytes32 to number (big-endian)
Parameters
bytes32
Bytes32Type Bytes32 to convert
Returns
number Number representation
Throws
If value exceeds Number.MAX_SAFE_INTEGER
Example
zero()
zero: () => Bytes32Type
Create a zero-filled Bytes32
Returns
Bytes32Type New Bytes32 with all zeros
Example
ZERO
ZERO: Bytes32Type
Zero constant - 32 bytes of zeros

SIZE

const SIZE: 32 = 32
Defined in: src/primitives/Bytes32/constants.js:7 Size of Bytes32 in bytes

ZERO

const ZERO: Bytes32Type
Defined in: src/primitives/Bytes32/constants.js:10 Zero constant - 32 bytes of zeros

Functions

_bitwiseAnd()

_bitwiseAnd(a, b): Bytes32Type
Defined in: src/primitives/Bytes32/bitwiseAnd.js:15 Perform bitwise AND on two Bytes32 values

Parameters

a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32

Returns

Bytes32Type Result of a & b

Example


_bitwiseOr()

_bitwiseOr(a, b): Bytes32Type
Defined in: src/primitives/Bytes32/bitwiseOr.js:15 Perform bitwise OR on two Bytes32 values

Parameters

a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32

Returns

Bytes32Type Result of a | b

Example


_bitwiseXor()

_bitwiseXor(a, b): Bytes32Type
Defined in: src/primitives/Bytes32/bitwiseXor.js:15 Perform bitwise XOR on two Bytes32 values

Parameters

a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32

Returns

Bytes32Type Result of a ^ b

Example


_clone()

_clone(bytes32): Bytes32Type
Defined in: src/primitives/Bytes32/clone.js:15 Create an independent copy of Bytes32

Parameters

bytes32
Bytes32Type Bytes32 to clone

Returns

Bytes32Type New Bytes32 with same values

Example


_compare()

_compare(a, b): number
Defined in: src/primitives/Bytes32/compare.js:15 Compare two Bytes32 values lexicographically

Parameters

a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32

Returns

number -1 if a < b, 0 if equal, 1 if a > b

Example


_equals()

_equals(a, b): boolean
Defined in: src/primitives/Bytes32/equals.js:17 Check if two Bytes32 values are equal

Parameters

a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32

Returns

boolean True if equal

Example


_from()

_from(value): Bytes32Type
Defined in: src/primitives/Bytes32/from.js:22 Create Bytes32 from various input types (universal constructor)

Parameters

value
Number, bigint, hex string, or Uint8Array string | number | bigint | Uint8Array<ArrayBufferLike>

Returns

Bytes32Type Bytes32

Throws

If value type is unsupported or invalid

Example


_fromBigint()

_fromBigint(value): Bytes32Type
Defined in: src/primitives/Bytes32/fromBigint.js:21 Create Bytes32 from bigint (big-endian)

Parameters

value
bigint Bigint to convert (must fit in 256 bits)

Returns

Bytes32Type Bytes32

Throws

If value is negative or exceeds 256 bits

Example


_fromBytes()

_fromBytes(bytes): Bytes32Type
Defined in: src/primitives/Bytes32/fromBytes.js:18 Create Bytes32 from bytes. Input must be exactly 32 bytes.

Parameters

bytes
Uint8Array<ArrayBufferLike> Input bytes (must be 32 bytes)

Returns

Bytes32Type Bytes32

Throws

If bytes length is not 32

Example


_fromHex()

_fromHex(hex): Bytes32Type
Defined in: src/primitives/Bytes32/fromHex.js:18 Create Bytes32 from hex string (with or without 0x prefix)

Parameters

hex
string Hex string (64 chars, with or without 0x prefix)

Returns

Bytes32Type Bytes32

Throws

If hex length is not 64 characters

Throws

If hex contains invalid characters

Example


_fromNumber()

_fromNumber(value): Bytes32Type
Defined in: src/primitives/Bytes32/fromNumber.js:15 Create Bytes32 from number (big-endian, zero-padded)

Parameters

value
number Number to convert

Returns

Bytes32Type Bytes32

Example


_isZero()

_isZero(bytes32): boolean
Defined in: src/primitives/Bytes32/isZero.js:16 Check if Bytes32 is all zeros

Parameters

bytes32
Bytes32Type Bytes32 to check

Returns

boolean True if all bytes are zero

Example


_max()

_max(a, b): Bytes32Type
Defined in: src/primitives/Bytes32/max.js:15 Return the maximum of two Bytes32 values (lexicographically)

Parameters

a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32

Returns

Bytes32Type The larger value

Example


_min()

_min(a, b): Bytes32Type
Defined in: src/primitives/Bytes32/min.js:15 Return the minimum of two Bytes32 values (lexicographically)

Parameters

a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32

Returns

Bytes32Type The smaller value

Example


_toBigint()

_toBigint(bytes32): bigint
Defined in: src/primitives/Bytes32/toBigint.js:12 Convert Bytes32 to bigint (big-endian)

Parameters

bytes32
Bytes32Type Bytes32 to convert

Returns

bigint Big-endian bigint representation

Example


_toHex()

_toHex(bytes32): string
Defined in: src/primitives/Bytes32/toHex.js:13 Convert Bytes32 to hex string with 0x prefix

Parameters

bytes32
Bytes32Type Bytes32 to convert

Returns

string Lowercase hex string with 0x prefix (66 chars total)

Example


_toNumber()

_toNumber(bytes32): number
Defined in: src/primitives/Bytes32/toNumber.js:21 Convert Bytes32 to number (big-endian)

Parameters

bytes32
Bytes32Type Bytes32 to convert

Returns

number Number representation

Throws

If value exceeds Number.MAX_SAFE_INTEGER

Example


_zero()

_zero(): Bytes32Type
Defined in: src/primitives/Bytes32/zero.js:13 Create a zero-filled Bytes32

Returns

Bytes32Type New Bytes32 with all zeros

Example


bitwiseAnd()

bitwiseAnd(a, b): Bytes32Type
Defined in: src/primitives/Bytes32/bitwiseAnd.js:15 Perform bitwise AND on two Bytes32 values

Parameters

a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32

Returns

Bytes32Type Result of a & b

Example


bitwiseOr()

bitwiseOr(a, b): Bytes32Type
Defined in: src/primitives/Bytes32/bitwiseOr.js:15 Perform bitwise OR on two Bytes32 values

Parameters

a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32

Returns

Bytes32Type Result of a | b

Example


bitwiseXor()

bitwiseXor(a, b): Bytes32Type
Defined in: src/primitives/Bytes32/bitwiseXor.js:15 Perform bitwise XOR on two Bytes32 values

Parameters

a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32

Returns

Bytes32Type Result of a ^ b

Example


clone()

clone(bytes32): Bytes32Type
Defined in: src/primitives/Bytes32/clone.js:15 Create an independent copy of Bytes32

Parameters

bytes32
Bytes32Type Bytes32 to clone

Returns

Bytes32Type New Bytes32 with same values

Example


compare()

compare(a, b): number
Defined in: src/primitives/Bytes32/compare.js:15 Compare two Bytes32 values lexicographically

Parameters

a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32

Returns

number -1 if a < b, 0 if equal, 1 if a > b

Example


equals()

equals(a, b): boolean
Defined in: src/primitives/Bytes32/equals.js:17 Check if two Bytes32 values are equal

Parameters

a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32

Returns

boolean True if equal

Example


from()

from(value): Bytes32Type
Defined in: src/primitives/Bytes32/from.js:22 Create Bytes32 from various input types (universal constructor)

Parameters

value
Number, bigint, hex string, or Uint8Array string | number | bigint | Uint8Array<ArrayBufferLike>

Returns

Bytes32Type Bytes32

Throws

If value type is unsupported or invalid

Example


fromBigint()

fromBigint(value): Bytes32Type
Defined in: src/primitives/Bytes32/fromBigint.js:21 Create Bytes32 from bigint (big-endian)

Parameters

value
bigint Bigint to convert (must fit in 256 bits)

Returns

Bytes32Type Bytes32

Throws

If value is negative or exceeds 256 bits

Example


fromBytes()

fromBytes(bytes): Bytes32Type
Defined in: src/primitives/Bytes32/fromBytes.js:18 Create Bytes32 from bytes. Input must be exactly 32 bytes.

Parameters

bytes
Uint8Array<ArrayBufferLike> Input bytes (must be 32 bytes)

Returns

Bytes32Type Bytes32

Throws

If bytes length is not 32

Example


fromHex()

fromHex(hex): Bytes32Type
Defined in: src/primitives/Bytes32/fromHex.js:18 Create Bytes32 from hex string (with or without 0x prefix)

Parameters

hex
string Hex string (64 chars, with or without 0x prefix)

Returns

Bytes32Type Bytes32

Throws

If hex length is not 64 characters

Throws

If hex contains invalid characters

Example


fromNumber()

fromNumber(value): Bytes32Type
Defined in: src/primitives/Bytes32/fromNumber.js:15 Create Bytes32 from number (big-endian, zero-padded)

Parameters

value
number Number to convert

Returns

Bytes32Type Bytes32

Example


isZero()

isZero(bytes32): boolean
Defined in: src/primitives/Bytes32/isZero.js:16 Check if Bytes32 is all zeros

Parameters

bytes32
Bytes32Type Bytes32 to check

Returns

boolean True if all bytes are zero

Example


max()

max(a, b): Bytes32Type
Defined in: src/primitives/Bytes32/max.js:15 Return the maximum of two Bytes32 values (lexicographically)

Parameters

a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32

Returns

Bytes32Type The larger value

Example


min()

min(a, b): Bytes32Type
Defined in: src/primitives/Bytes32/min.js:15 Return the minimum of two Bytes32 values (lexicographically)

Parameters

a
Bytes32Type First Bytes32
b
Bytes32Type Second Bytes32

Returns

Bytes32Type The smaller value

Example


toBigint()

toBigint(bytes32): bigint
Defined in: src/primitives/Bytes32/toBigint.js:12 Convert Bytes32 to bigint (big-endian)

Parameters

bytes32
Bytes32Type Bytes32 to convert

Returns

bigint Big-endian bigint representation

Example


toHex()

toHex(bytes32): string
Defined in: src/primitives/Bytes32/toHex.js:13 Convert Bytes32 to hex string with 0x prefix

Parameters

bytes32
Bytes32Type Bytes32 to convert

Returns

string Lowercase hex string with 0x prefix (66 chars total)

Example


toNumber()

toNumber(bytes32): number
Defined in: src/primitives/Bytes32/toNumber.js:21 Convert Bytes32 to number (big-endian)

Parameters

bytes32
Bytes32Type Bytes32 to convert

Returns

number Number representation

Throws

If value exceeds Number.MAX_SAFE_INTEGER

Example


zero()

zero(): Bytes32Type
Defined in: src/primitives/Bytes32/zero.js:13 Create a zero-filled Bytes32

Returns

Bytes32Type New Bytes32 with all zeros

Example

References

default

Renames and re-exports Bytes32