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

primitives/Hash

Variables

concat()

const concat: (…hashes) => HashType
Defined in: src/primitives/Hash/index.ts:34

Parameters

hashes
HashType[]

Returns

HashType

keccak256()

const keccak256: (data) => HashType
Defined in: src/primitives/Hash/index.ts:23

Parameters

data
Uint8Array

Returns

HashType

keccak256Hex()

const keccak256Hex: (hex) => HashType
Defined in: src/primitives/Hash/index.ts:26

Parameters

hex
string

Returns

HashType

keccak256String()

const keccak256String: (str) => HashType
Defined in: src/primitives/Hash/index.ts:29

Parameters

str
string

Returns

HashType

merkleRoot()

const merkleRoot: (leaves) => HashType
Defined in: src/primitives/Hash/index.ts:31

Parameters

leaves
HashType[]

Returns

HashType

SIZE

const SIZE: 32 = 32
Defined in: src/primitives/Hash/constants.js:4 Hash size in bytes (32 bytes = 256 bits)

ZERO

const ZERO: HashType
Defined in: src/primitives/Hash/constants.js:10 Zero hash constant (32 zero bytes)

Functions

_ConcatFactory()

_ConcatFactory(deps): (…hashes) => HashType
Defined in: src/primitives/Hash/concat.js:9 Factory: Concatenate multiple hashes and hash the result

Parameters

deps
Crypto dependencies
keccak256
(data) => Uint8Array Keccak256 hash function

Returns

Function that concatenates and hashes
(…hashes): HashType
Parameters
hashes
HashType[]
Returns
HashType

_Keccak256Factory()

_Keccak256Factory(deps): (data) => HashType
Defined in: src/primitives/Hash/keccak256.js:7 Factory: Hash data with Keccak-256

Parameters

deps
Crypto dependencies
keccak256
(data) => Uint8Array Keccak256 hash function

Returns

Function that hashes data
(data): HashType
Parameters
data
Uint8Array
Returns
HashType

_Keccak256HexFactory()

_Keccak256HexFactory(deps): (hex) => HashType
Defined in: src/primitives/Hash/keccak256Hex.js:10 Factory: Hash hex string with Keccak-256

Parameters

deps
Crypto dependencies
keccak256
(data) => Uint8Array Keccak256 hash function

Returns

Function that hashes hex strings
(hex): HashType
Parameters
hex
string
Returns
HashType

_Keccak256StringFactory()

_Keccak256StringFactory(deps): (str) => HashType
Defined in: src/primitives/Hash/keccak256String.js:9 Factory: Hash string with Keccak-256

Parameters

deps
Crypto dependencies
keccak256
(data) => Uint8Array Keccak256 hash function

Returns

Function that hashes strings
(str): HashType
Parameters
str
string
Returns
HashType

_MerkleRootFactory()

_MerkleRootFactory(deps): (hashes) => HashType
Defined in: src/primitives/Hash/merkleRoot.js:10 Factory: Calculate Merkle root of hash array

Parameters

deps
Crypto dependencies
keccak256
(data) => Uint8Array Keccak256 hash function

Returns

Function that calculates Merkle root
(hashes): HashType
Parameters
hashes
HashType[]
Returns
HashType

assert()

assert(value, message?): asserts value is HashType
Defined in: src/primitives/Hash/assert.js:19 Assert value is a Hash, throws if not

Parameters

value
unknown Value to assert
message?
string Optional error message

Returns

asserts value is HashType

See

https://voltaire.tevm.sh/primitives/hash for Hash documentation

Since

0.0.0

Throws

If value is not a Hash

Example

import * as Hash from './primitives/Hash/index.js';
Hash.assert(value); // throws if not Hash

clone()

clone(hash): HashType
Defined in: src/primitives/Hash/clone.js:16 Clone hash

Parameters

hash
HashType Hash to clone

Returns

HashType New hash with same value

See

https://voltaire.tevm.sh/primitives/hash for Hash documentation

Since

0.0.0

Throws

Example

import * as Hash from './primitives/Hash/index.js';
const hash = Hash.from('0x1234...');
const copy = Hash.clone(hash);

equals()

equals(hash, other): boolean
Defined in: src/primitives/Hash/equals.js:20 Compare two hashes for equality Uses constant-time comparison to prevent timing attacks.

Parameters

hash
HashType First hash
other
HashType Hash to compare with

Returns

boolean True if hashes are equal

See

https://voltaire.tevm.sh/primitives/hash for Hash documentation

Since

0.0.0

Throws

Example

import * as Hash from './primitives/Hash/index.js';
const hash1 = Hash.from('0x1234...');
const hash2 = Hash.from('0x1234...');
const same = Hash.equals(hash1, hash2); // true

format()

format(hash, prefixLength?, suffixLength?): string
Defined in: src/primitives/Hash/format.js:18 Format hash for display (truncated)

Parameters

hash
HashType Hash to format
prefixLength?
number = 6 Number of chars to show at start
suffixLength?
number = 4 Number of chars to show at end

Returns

string Formatted string like “0x1234…5678”

See

https://voltaire.tevm.sh/primitives/hash for Hash documentation

Since

0.0.0

Throws

Example

import * as Hash from './primitives/Hash/index.js';
const hash = Hash.from('0x1234...');
const display = Hash.format(hash); // "0x1234...5678"

from()

from(value): HashType
Defined in: src/primitives/Hash/from.js:19 Create Hash from string or bytes

Parameters

value
Hex string with optional 0x prefix or Uint8Array string | Uint8Array<ArrayBufferLike>

Returns

HashType Hash bytes

See

https://voltaire.tevm.sh/primitives/hash for Hash documentation

Since

0.0.0

Throws

If input is invalid or wrong length

Example

import * as Hash from './primitives/Hash/index.js';
const hash = Hash.from('0x1234...');
const hash2 = Hash.from(new Uint8Array(32));

fromBytes()

fromBytes(bytes): HashType
Defined in: src/primitives/Hash/fromBytes.js:18 Create Hash from raw bytes

Parameters

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

Returns

HashType Hash bytes

See

https://voltaire.tevm.sh/primitives/hash for Hash documentation

Since

0.0.0

Throws

If bytes is wrong length

Example

import * as Hash from './primitives/Hash/index.js';
const hash = Hash.fromBytes(new Uint8Array(32));

fromHex()

fromHex(hex): HashType
Defined in: src/primitives/Hash/fromHex.js:20 Create Hash from hex string

Parameters

hex
string Hex string with optional 0x prefix

Returns

HashType Hash bytes

See

https://voltaire.tevm.sh/primitives/hash for Hash documentation

Since

0.0.0

Throws

If hex is wrong length

Throws

If hex contains invalid characters

Example

import * as Hash from './primitives/Hash/index.js';
const hash = Hash.fromHex('0x1234...');
const hash2 = Hash.fromHex('1234...'); // 0x prefix optional

isHash()

isHash(value): value is HashType
Defined in: src/primitives/Hash/isHash.js:19 Check if value is a valid Hash

Parameters

value
unknown Value to check

Returns

value is HashType True if value is Hash type

See

https://voltaire.tevm.sh/primitives/hash for Hash documentation

Since

0.0.0

Throws

Example

import * as Hash from './primitives/Hash/index.js';
if (Hash.isHash(value)) {
  // value is Hash
}

isValidHex()

isValidHex(hex): boolean
Defined in: src/primitives/Hash/isValidHex.js:19 Validate hex string is valid hash format

Parameters

hex
string Hex string to validate

Returns

boolean True if valid hash hex format

See

https://voltaire.tevm.sh/primitives/hash for Hash documentation

Since

0.0.0

Throws

Example

import * as Hash from './primitives/Hash/index.js';
if (Hash.isValidHex('0x1234...')) {
  const hash = Hash.fromHex('0x1234...');
}

isZero()

isZero(hash): boolean
Defined in: src/primitives/Hash/isZero.js:18 Check if hash is zero hash

Parameters

hash
HashType Hash to check

Returns

boolean True if hash is all zeros

See

https://voltaire.tevm.sh/primitives/hash for Hash documentation

Since

0.0.0

Throws

Example

import * as Hash from './primitives/Hash/index.js';
const hash = Hash.from('0x00...');
const zero = Hash.isZero(hash); // true

random()

random(): HashType
Defined in: src/primitives/Hash/random.js:17 Generate random hash

Returns

HashType Random 32-byte hash

See

https://voltaire.tevm.sh/primitives/hash for Hash documentation

Since

0.0.0

Throws

If crypto.getRandomValues not available

Example

import * as Hash from './primitives/Hash/index.js';
const hash = Hash.random();

slice()

slice(hash, start?, end?): Uint8Array<ArrayBufferLike>
Defined in: src/primitives/Hash/slice.js:18 Get slice of hash

Parameters

hash
HashType Hash to slice
start?
number Start index (inclusive)
end?
number End index (exclusive)

Returns

Uint8Array<ArrayBufferLike> Slice of hash bytes

See

https://voltaire.tevm.sh/primitives/hash for Hash documentation

Since

0.0.0

Throws

Example

import * as Hash from './primitives/Hash/index.js';
const hash = Hash.from('0x1234...');
const selector = Hash.slice(hash, 0, 4);

toBytes()

toBytes(hash): Uint8Array<ArrayBufferLike>
Defined in: src/primitives/Hash/toBytes.js:16 Convert Hash to raw bytes

Parameters

hash
HashType Hash to convert

Returns

Uint8Array<ArrayBufferLike> Copy of hash bytes

See

https://voltaire.tevm.sh/primitives/hash for Hash documentation

Since

0.0.0

Throws

Example

import * as Hash from './primitives/Hash/index.js';
const hash = Hash.from('0x1234...');
const bytes = Hash.toBytes(hash);

toHex()

toHex(hash): string
Defined in: src/primitives/Hash/toHex.js:16 Convert Hash to hex string

Parameters

hash
HashType Hash to convert

Returns

string Hex string with 0x prefix

See

https://voltaire.tevm.sh/primitives/hash for Hash documentation

Since

0.0.0

Throws

Example

import * as Hash from './primitives/Hash/index.js';
const hash = Hash.from('0x1234...');
const hex = Hash.toHex(hash); // "0x1234..."

toString()

toString(hash): string
Defined in: src/primitives/Hash/toString.js:17 Convert Hash to string (alias for toHex)

Parameters

hash
HashType Hash to convert

Returns

string Hex string with 0x prefix

See

https://voltaire.tevm.sh/primitives/hash for Hash documentation

Since

0.0.0

Throws

Example

import * as Hash from './primitives/Hash/index.js';
const hash = Hash.from('0x1234...');
const str = Hash.toString(hash);

References

Hash

Re-exports Hash

HashLike

Re-exports HashLike

HashType

Re-exports HashType

HashTypeInterface

Renames and re-exports HashType