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
'INVALID_FORMAT', 'INVALID_LENGTH'
Inherited from
InvalidFormatError.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
{ value: '0x123', expected: '20 bytes' }
Inherited from
InvalidFormatError.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
'/primitives/address/from-hex#error-handling'
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
'INVALID_FORMAT', 'INVALID_LENGTH'
Inherited from
InvalidLengthError.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
{ value: '0x123', expected: '20 bytes' }
Inherited from
InvalidLengthError.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
'/primitives/address/from-hex#error-handling'
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
'INVALID_FORMAT', 'INVALID_LENGTH'
Inherited from
ValidationError.code
context?
optional context: Record<string, unknown>
Defined in: src/primitives/errors/AbstractError.ts:45 Additional context metadata for debugging
Example
{ value: '0x123', expected: '20 bytes' }
Inherited from
ValidationError.context
docsPath?
optional docsPath: string
Defined in: src/primitives/errors/AbstractError.ts:51 Path to documentation for this error
Example
'/primitives/address/from-hex#error-handling'
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
const result = Bytes32.bitwiseAnd(a, b);
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
const result = Bytes32.bitwiseOr(a, b);
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
const result = Bytes32.bitwiseXor(a, b);
clone()
clone: (bytes32) => Bytes32Type
Create an independent copy of Bytes32
Parameters
bytes32
Bytes32Type Bytes32 to clone
Returns
Bytes32Type New Bytes32 with same values
Example
const copy = Bytes32.clone(original);
// Modifying copy won't affect original
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
const sorted = bytes32Array.sort(Bytes32.compare);
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
if (Bytes32.equals(a, b)) {
  console.log("Values match");
}
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
const b1 = Bytes32.from(42);                    // from number
const b2 = Bytes32.from(42n);                   // from bigint
const b3 = Bytes32.from('0x' + 'ab'.repeat(32)); // from hex
const b4 = Bytes32.from(new Uint8Array(32));    // from bytes
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
const b32 = Bytes32.fromBigint(0x123456789abcdef0n);
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
const bytes = new Uint8Array(32);
bytes[0] = 1;
const b32 = Bytes32.fromBytes(bytes);
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
const b32 = Bytes32.fromHex('0x' + 'ab'.repeat(32));
const b32Alt = Bytes32.fromHex('ab'.repeat(32));
fromNumber()
fromNumber: (value) => Bytes32Type
Create Bytes32 from number (big-endian, zero-padded)
Parameters
value
number Number to convert
Returns
Bytes32Type Bytes32
Example
const b32 = Bytes32.fromNumber(42);
// Last byte is 42, rest are zeros
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
if (Bytes32.isZero(b32)) {
  console.log("Empty slot");
}
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
const larger = Bytes32.max(a, b);
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
const smaller = Bytes32.min(a, b);
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
const value = Bytes32.toBigint(b32);
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
const hex = Bytes32.toHex(b32);
// "0x000000000000000000000000000000000000000000000000000000000000002a"
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
const value = Bytes32.toNumber(b32);
zero()
zero: () => Bytes32Type
Create a zero-filled Bytes32
Returns
Bytes32Type New Bytes32 with all zeros
Example
const empty = Bytes32.zero();
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

const result = Bytes32.bitwiseAnd(a, b);

_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

const result = Bytes32.bitwiseOr(a, b);

_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

const result = Bytes32.bitwiseXor(a, b);

_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

const copy = Bytes32.clone(original);
// Modifying copy won't affect original

_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

const sorted = bytes32Array.sort(Bytes32.compare);

_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

if (Bytes32.equals(a, b)) {
  console.log("Values match");
}

_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

const b1 = Bytes32.from(42);                    // from number
const b2 = Bytes32.from(42n);                   // from bigint
const b3 = Bytes32.from('0x' + 'ab'.repeat(32)); // from hex
const b4 = Bytes32.from(new Uint8Array(32));    // from bytes

_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

const b32 = Bytes32.fromBigint(0x123456789abcdef0n);

_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

const bytes = new Uint8Array(32);
bytes[0] = 1;
const b32 = Bytes32.fromBytes(bytes);

_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

const b32 = Bytes32.fromHex('0x' + 'ab'.repeat(32));
const b32Alt = Bytes32.fromHex('ab'.repeat(32));

_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

const b32 = Bytes32.fromNumber(42);
// Last byte is 42, rest are zeros

_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

if (Bytes32.isZero(b32)) {
  console.log("Empty slot");
}

_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

const larger = Bytes32.max(a, b);

_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

const smaller = Bytes32.min(a, b);

_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

const value = Bytes32.toBigint(b32);

_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

const hex = Bytes32.toHex(b32);
// "0x000000000000000000000000000000000000000000000000000000000000002a"

_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

const value = Bytes32.toNumber(b32);

_zero()

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

Returns

Bytes32Type New Bytes32 with all zeros

Example

const empty = Bytes32.zero();

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

const result = Bytes32.bitwiseAnd(a, b);

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

const result = Bytes32.bitwiseOr(a, b);

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

const result = Bytes32.bitwiseXor(a, b);

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

const copy = Bytes32.clone(original);
// Modifying copy won't affect original

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

const sorted = bytes32Array.sort(Bytes32.compare);

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

if (Bytes32.equals(a, b)) {
  console.log("Values match");
}

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

const b1 = Bytes32.from(42);                    // from number
const b2 = Bytes32.from(42n);                   // from bigint
const b3 = Bytes32.from('0x' + 'ab'.repeat(32)); // from hex
const b4 = Bytes32.from(new Uint8Array(32));    // from bytes

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

const b32 = Bytes32.fromBigint(0x123456789abcdef0n);

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

const bytes = new Uint8Array(32);
bytes[0] = 1;
const b32 = Bytes32.fromBytes(bytes);

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

const b32 = Bytes32.fromHex('0x' + 'ab'.repeat(32));
const b32Alt = Bytes32.fromHex('ab'.repeat(32));

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

const b32 = Bytes32.fromNumber(42);
// Last byte is 42, rest are zeros

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

if (Bytes32.isZero(b32)) {
  console.log("Empty slot");
}

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

const larger = Bytes32.max(a, b);

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

const smaller = Bytes32.min(a, b);

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

const value = Bytes32.toBigint(b32);

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

const hex = Bytes32.toHex(b32);
// "0x000000000000000000000000000000000000000000000000000000000000002a"

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

const value = Bytes32.toNumber(b32);

zero()

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

Returns

Bytes32Type New Bytes32 with all zeros

Example

const empty = Bytes32.zero();

References

default

Renames and re-exports Bytes32