@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 invalidExtends
Constructors
Constructor
new InvalidBytes32HexError(Defined in: src/primitives/Bytes32/errors.js:21message?,options?):InvalidBytes32HexError
Parameters
message?
string
Error message
options?
Error optionscause?
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?
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)optionalcause:Error
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?
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debuggingoptionalcontext:Record<string,unknown>
Example
Inherited from
InvalidFormatError.context
docsPath?
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this erroroptionaldocsPath:string
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():Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetryRecord<string,unknown>
Returns
Record<string, unknown>
Inherited from
InvalidFormatError.toJSON
InvalidBytes32LengthError
Defined in: src/primitives/Bytes32/errors.js:37 Error thrown when Bytes32 has invalid lengthExtends
Constructors
Constructor
new InvalidBytes32LengthError(Defined in: src/primitives/Bytes32/errors.js:48message?,options?):InvalidBytes32LengthError
Parameters
message?
string
Error message
options?
Error optionscause?
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?
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)optionalcause:Error
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?
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debuggingoptionalcontext:Record<string,unknown>
Example
Inherited from
InvalidLengthError.context
docsPath?
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this erroroptionaldocsPath:string
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():Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetryRecord<string,unknown>
Returns
Record<string, unknown>
Inherited from
InvalidLengthError.toJSON
InvalidBytes32ValueError
Defined in: src/primitives/Bytes32/errors.js:64 Error thrown when value is invalid for Bytes32Extends
Constructors
Constructor
new InvalidBytes32ValueError(Defined in: src/primitives/Bytes32/errors.js:75message,options?):InvalidBytes32ValueError
Parameters
message
string
Error message
options?
Error optionscause?
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?
Defined in: src/primitives/errors/AbstractError.ts:56 Root cause of this error (for error chaining)optionalcause:Error
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?
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debuggingoptionalcontext:Record<string,unknown>
Example
Inherited from
ValidationError.context
docsPath?
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this erroroptionaldocsPath:string
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():Defined in: src/primitives/errors/AbstractError.ts:110 Serialize error to JSON for logging/telemetryRecord<string,unknown>
Returns
Record<string, unknown>
Inherited from
ValidationError.toJSON
Type Aliases
Bytes32Like
Bytes32Like =Defined in: src/primitives/Bytes32/Bytes32Type.ts:18 Inputs that can be converted to Bytes32Bytes32Type|string|Uint8Array|bigint|number
Bytes32Type
Bytes32Type =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.Uint8Array&object
Type Declaration
[brand]
readonly[brand]:"Bytes32"
Variables
Bytes32
Defined in: src/primitives/Bytes32/index.ts:87constBytes32:object
Type Declaration
bitwiseAnd()
bitwiseAnd: (Perform bitwise AND on two Bytes32 valuesa,b) =>Bytes32Type
Parameters
a
Bytes32Type
First Bytes32
b
Bytes32Type
Second Bytes32
Returns
Bytes32Type
Result of a & b
Example
bitwiseOr()
bitwiseOr: (Perform bitwise OR on two Bytes32 valuesa,b) =>Bytes32Type
Parameters
a
Bytes32Type
First Bytes32
b
Bytes32Type
Second Bytes32
Returns
Bytes32Type
Result of a | b
Example
bitwiseXor()
bitwiseXor: (Perform bitwise XOR on two Bytes32 valuesa,b) =>Bytes32Type
Parameters
a
Bytes32Type
First Bytes32
b
Bytes32Type
Second Bytes32
Returns
Bytes32Type
Result of a ^ b
Example
clone()
clone: (Create an independent copy of Bytes32bytes32) =>Bytes32Type
Parameters
bytes32
Bytes32Type
Bytes32 to clone
Returns
Bytes32Type
New Bytes32 with same values
Example
compare()
compare: (Compare two Bytes32 values lexicographicallya,b) =>number
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: (Check if two Bytes32 values are equala,b) =>boolean
Parameters
a
Bytes32Type
First Bytes32
b
Bytes32Type
Second Bytes32
Returns
boolean
True if equal
Example
from()
from: (Create Bytes32 from various input types (universal constructor)value) =>Bytes32Type
Parameters
value
Number, bigint, hex string, or Uint8Arraystring | number | bigint | Uint8Array<ArrayBufferLike>
Returns
Bytes32Type
Bytes32
Throws
If value type is unsupported or invalidExample
fromBigint()
fromBigint: (Create Bytes32 from bigint (big-endian)value) =>Bytes32Type
Parameters
value
bigint
Bigint to convert (must fit in 256 bits)
Returns
Bytes32Type
Bytes32
Throws
If value is negative or exceeds 256 bitsExample
fromBytes()
fromBytes: (Create Bytes32 from bytes. Input must be exactly 32 bytes.bytes) =>Bytes32Type
Parameters
bytes
Uint8Array<ArrayBufferLike>
Input bytes (must be 32 bytes)
Returns
Bytes32Type
Bytes32
Throws
If bytes length is not 32Example
fromHex()
fromHex: (Create Bytes32 from hex string (with or without 0x prefix)hex) =>Bytes32Type
Parameters
hex
string
Hex string (64 chars, with or without 0x prefix)
Returns
Bytes32Type
Bytes32
Throws
If hex length is not 64 charactersThrows
If hex contains invalid charactersExample
fromNumber()
fromNumber: (Create Bytes32 from number (big-endian, zero-padded)value) =>Bytes32Type
Parameters
value
number
Number to convert
Returns
Bytes32Type
Bytes32
Example
isZero()
isZero: (Check if Bytes32 is all zerosbytes32) =>boolean
Parameters
bytes32
Bytes32Type
Bytes32 to check
Returns
boolean
True if all bytes are zero
Example
max()
max: (Return the maximum of two Bytes32 values (lexicographically)a,b) =>Bytes32Type
Parameters
a
Bytes32Type
First Bytes32
b
Bytes32Type
Second Bytes32
Returns
Bytes32Type
The larger value
Example
min()
min: (Return the minimum of two Bytes32 values (lexicographically)a,b) =>Bytes32Type
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: (Convert Bytes32 to bigint (big-endian)bytes32) =>bigint
Parameters
bytes32
Bytes32Type
Bytes32 to convert
Returns
bigint
Big-endian bigint representation
Example
toHex()
toHex: (Convert Bytes32 to hex string with 0x prefixbytes32) =>string
Parameters
bytes32
Bytes32Type
Bytes32 to convert
Returns
string
Lowercase hex string with 0x prefix (66 chars total)
Example
toNumber()
toNumber: (Convert Bytes32 to number (big-endian)bytes32) =>number
Parameters
bytes32
Bytes32Type
Bytes32 to convert
Returns
number
Number representation
Throws
If value exceeds Number.MAX_SAFE_INTEGERExample
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
Defined in: src/primitives/Bytes32/constants.js:7 Size of Bytes32 in bytesconstSIZE:32=32
ZERO
Defined in: src/primitives/Bytes32/constants.js:10 Zero constant - 32 bytes of zerosconstZERO:Bytes32Type
Functions
_bitwiseAnd()
_bitwiseAnd(Defined in: src/primitives/Bytes32/bitwiseAnd.js:15 Perform bitwise AND on two Bytes32 valuesa,b):Bytes32Type
Parameters
a
Bytes32Type
First Bytes32
b
Bytes32Type
Second Bytes32
Returns
Bytes32Type
Result of a & b
Example
_bitwiseOr()
_bitwiseOr(Defined in: src/primitives/Bytes32/bitwiseOr.js:15 Perform bitwise OR on two Bytes32 valuesa,b):Bytes32Type
Parameters
a
Bytes32Type
First Bytes32
b
Bytes32Type
Second Bytes32
Returns
Bytes32Type
Result of a | b
Example
_bitwiseXor()
_bitwiseXor(Defined in: src/primitives/Bytes32/bitwiseXor.js:15 Perform bitwise XOR on two Bytes32 valuesa,b):Bytes32Type
Parameters
a
Bytes32Type
First Bytes32
b
Bytes32Type
Second Bytes32
Returns
Bytes32Type
Result of a ^ b
Example
_clone()
_clone(Defined in: src/primitives/Bytes32/clone.js:15 Create an independent copy of Bytes32bytes32):Bytes32Type
Parameters
bytes32
Bytes32Type
Bytes32 to clone
Returns
Bytes32Type
New Bytes32 with same values
Example
_compare()
_compare(Defined in: src/primitives/Bytes32/compare.js:15 Compare two Bytes32 values lexicographicallya,b):number
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(Defined in: src/primitives/Bytes32/equals.js:17 Check if two Bytes32 values are equala,b):boolean
Parameters
a
Bytes32Type
First Bytes32
b
Bytes32Type
Second Bytes32
Returns
boolean
True if equal
Example
_from()
_from(Defined in: src/primitives/Bytes32/from.js:22 Create Bytes32 from various input types (universal constructor)value):Bytes32Type
Parameters
value
Number, bigint, hex string, or Uint8Arraystring | number | bigint | Uint8Array<ArrayBufferLike>
Returns
Bytes32Type
Bytes32
Throws
If value type is unsupported or invalidExample
_fromBigint()
_fromBigint(Defined in: src/primitives/Bytes32/fromBigint.js:21 Create Bytes32 from bigint (big-endian)value):Bytes32Type
Parameters
value
bigint
Bigint to convert (must fit in 256 bits)
Returns
Bytes32Type
Bytes32
Throws
If value is negative or exceeds 256 bitsExample
_fromBytes()
_fromBytes(Defined in: src/primitives/Bytes32/fromBytes.js:18 Create Bytes32 from bytes. Input must be exactly 32 bytes.bytes):Bytes32Type
Parameters
bytes
Uint8Array<ArrayBufferLike>
Input bytes (must be 32 bytes)
Returns
Bytes32Type
Bytes32
Throws
If bytes length is not 32Example
_fromHex()
_fromHex(Defined in: src/primitives/Bytes32/fromHex.js:18 Create Bytes32 from hex string (with or without 0x prefix)hex):Bytes32Type
Parameters
hex
string
Hex string (64 chars, with or without 0x prefix)
Returns
Bytes32Type
Bytes32
Throws
If hex length is not 64 charactersThrows
If hex contains invalid charactersExample
_fromNumber()
_fromNumber(Defined in: src/primitives/Bytes32/fromNumber.js:15 Create Bytes32 from number (big-endian, zero-padded)value):Bytes32Type
Parameters
value
number
Number to convert
Returns
Bytes32Type
Bytes32
Example
_isZero()
_isZero(Defined in: src/primitives/Bytes32/isZero.js:16 Check if Bytes32 is all zerosbytes32):boolean
Parameters
bytes32
Bytes32Type
Bytes32 to check
Returns
boolean
True if all bytes are zero
Example
_max()
_max(Defined in: src/primitives/Bytes32/max.js:15 Return the maximum of two Bytes32 values (lexicographically)a,b):Bytes32Type
Parameters
a
Bytes32Type
First Bytes32
b
Bytes32Type
Second Bytes32
Returns
Bytes32Type
The larger value
Example
_min()
_min(Defined in: src/primitives/Bytes32/min.js:15 Return the minimum of two Bytes32 values (lexicographically)a,b):Bytes32Type
Parameters
a
Bytes32Type
First Bytes32
b
Bytes32Type
Second Bytes32
Returns
Bytes32Type
The smaller value
Example
_toBigint()
_toBigint(Defined in: src/primitives/Bytes32/toBigint.js:12 Convert Bytes32 to bigint (big-endian)bytes32):bigint
Parameters
bytes32
Bytes32Type
Bytes32 to convert
Returns
bigint
Big-endian bigint representation
Example
_toHex()
_toHex(Defined in: src/primitives/Bytes32/toHex.js:13 Convert Bytes32 to hex string with 0x prefixbytes32):string
Parameters
bytes32
Bytes32Type
Bytes32 to convert
Returns
string
Lowercase hex string with 0x prefix (66 chars total)
Example
_toNumber()
_toNumber(Defined in: src/primitives/Bytes32/toNumber.js:21 Convert Bytes32 to number (big-endian)bytes32):number
Parameters
bytes32
Bytes32Type
Bytes32 to convert
Returns
number
Number representation
Throws
If value exceeds Number.MAX_SAFE_INTEGERExample
_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(Defined in: src/primitives/Bytes32/bitwiseAnd.js:15 Perform bitwise AND on two Bytes32 valuesa,b):Bytes32Type
Parameters
a
Bytes32Type
First Bytes32
b
Bytes32Type
Second Bytes32
Returns
Bytes32Type
Result of a & b
Example
bitwiseOr()
bitwiseOr(Defined in: src/primitives/Bytes32/bitwiseOr.js:15 Perform bitwise OR on two Bytes32 valuesa,b):Bytes32Type
Parameters
a
Bytes32Type
First Bytes32
b
Bytes32Type
Second Bytes32
Returns
Bytes32Type
Result of a | b
Example
bitwiseXor()
bitwiseXor(Defined in: src/primitives/Bytes32/bitwiseXor.js:15 Perform bitwise XOR on two Bytes32 valuesa,b):Bytes32Type
Parameters
a
Bytes32Type
First Bytes32
b
Bytes32Type
Second Bytes32
Returns
Bytes32Type
Result of a ^ b
Example
clone()
clone(Defined in: src/primitives/Bytes32/clone.js:15 Create an independent copy of Bytes32bytes32):Bytes32Type
Parameters
bytes32
Bytes32Type
Bytes32 to clone
Returns
Bytes32Type
New Bytes32 with same values
Example
compare()
compare(Defined in: src/primitives/Bytes32/compare.js:15 Compare two Bytes32 values lexicographicallya,b):number
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(Defined in: src/primitives/Bytes32/equals.js:17 Check if two Bytes32 values are equala,b):boolean
Parameters
a
Bytes32Type
First Bytes32
b
Bytes32Type
Second Bytes32
Returns
boolean
True if equal
Example
from()
from(Defined in: src/primitives/Bytes32/from.js:22 Create Bytes32 from various input types (universal constructor)value):Bytes32Type
Parameters
value
Number, bigint, hex string, or Uint8Arraystring | number | bigint | Uint8Array<ArrayBufferLike>
Returns
Bytes32Type
Bytes32
Throws
If value type is unsupported or invalidExample
fromBigint()
fromBigint(Defined in: src/primitives/Bytes32/fromBigint.js:21 Create Bytes32 from bigint (big-endian)value):Bytes32Type
Parameters
value
bigint
Bigint to convert (must fit in 256 bits)
Returns
Bytes32Type
Bytes32
Throws
If value is negative or exceeds 256 bitsExample
fromBytes()
fromBytes(Defined in: src/primitives/Bytes32/fromBytes.js:18 Create Bytes32 from bytes. Input must be exactly 32 bytes.bytes):Bytes32Type
Parameters
bytes
Uint8Array<ArrayBufferLike>
Input bytes (must be 32 bytes)
Returns
Bytes32Type
Bytes32
Throws
If bytes length is not 32Example
fromHex()
fromHex(Defined in: src/primitives/Bytes32/fromHex.js:18 Create Bytes32 from hex string (with or without 0x prefix)hex):Bytes32Type
Parameters
hex
string
Hex string (64 chars, with or without 0x prefix)
Returns
Bytes32Type
Bytes32
Throws
If hex length is not 64 charactersThrows
If hex contains invalid charactersExample
fromNumber()
fromNumber(Defined in: src/primitives/Bytes32/fromNumber.js:15 Create Bytes32 from number (big-endian, zero-padded)value):Bytes32Type
Parameters
value
number
Number to convert
Returns
Bytes32Type
Bytes32
Example
isZero()
isZero(Defined in: src/primitives/Bytes32/isZero.js:16 Check if Bytes32 is all zerosbytes32):boolean
Parameters
bytes32
Bytes32Type
Bytes32 to check
Returns
boolean
True if all bytes are zero
Example
max()
max(Defined in: src/primitives/Bytes32/max.js:15 Return the maximum of two Bytes32 values (lexicographically)a,b):Bytes32Type
Parameters
a
Bytes32Type
First Bytes32
b
Bytes32Type
Second Bytes32
Returns
Bytes32Type
The larger value
Example
min()
min(Defined in: src/primitives/Bytes32/min.js:15 Return the minimum of two Bytes32 values (lexicographically)a,b):Bytes32Type
Parameters
a
Bytes32Type
First Bytes32
b
Bytes32Type
Second Bytes32
Returns
Bytes32Type
The smaller value
Example
toBigint()
toBigint(Defined in: src/primitives/Bytes32/toBigint.js:12 Convert Bytes32 to bigint (big-endian)bytes32):bigint
Parameters
bytes32
Bytes32Type
Bytes32 to convert
Returns
bigint
Big-endian bigint representation
Example
toHex()
toHex(Defined in: src/primitives/Bytes32/toHex.js:13 Convert Bytes32 to hex string with 0x prefixbytes32):string
Parameters
bytes32
Bytes32Type
Bytes32 to convert
Returns
string
Lowercase hex string with 0x prefix (66 chars total)
Example
toNumber()
toNumber(Defined in: src/primitives/Bytes32/toNumber.js:21 Convert Bytes32 to number (big-endian)bytes32):number
Parameters
bytes32
Bytes32Type
Bytes32 to convert
Returns
number
Number representation
Throws
If value exceeds Number.MAX_SAFE_INTEGERExample
zero()
zero(): Bytes32Type
Defined in: src/primitives/Bytes32/zero.js:13
Create a zero-filled Bytes32
Returns
Bytes32Type
New Bytes32 with all zeros

