> ## Documentation Index
> Fetch the complete documentation index at: https://voltaire.tevm.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# primitives/Hash

> Auto-generated API documentation

[**@tevm/voltaire**](../index.mdx)

***

[@tevm/voltaire](../index.mdx) / primitives/Hash

# primitives/Hash

## Variables

### concat()

> `const` **concat**: (...`hashes`) => [`HashType`](../index/namespaces/HashType.mdx#hashtype)

Defined in: [src/primitives/Hash/index.ts:34](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/index.ts#L34)

#### Parameters

##### hashes

...[`HashType`](../index/namespaces/HashType.mdx#hashtype)\[]

#### Returns

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

***

### keccak256()

> `const` **keccak256**: (`data`) => [`HashType`](../index/namespaces/HashType.mdx#hashtype)

Defined in: [src/primitives/Hash/index.ts:23](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/index.ts#L23)

#### Parameters

##### data

`Uint8Array`

#### Returns

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

***

### keccak256Hex()

> `const` **keccak256Hex**: (`hex`) => [`HashType`](../index/namespaces/HashType.mdx#hashtype)

Defined in: [src/primitives/Hash/index.ts:26](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/index.ts#L26)

#### Parameters

##### hex

`string`

#### Returns

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

***

### keccak256String()

> `const` **keccak256String**: (`str`) => [`HashType`](../index/namespaces/HashType.mdx#hashtype)

Defined in: [src/primitives/Hash/index.ts:29](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/index.ts#L29)

#### Parameters

##### str

`string`

#### Returns

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

***

### merkleRoot()

> `const` **merkleRoot**: (`leaves`) => [`HashType`](../index/namespaces/HashType.mdx#hashtype)

Defined in: [src/primitives/Hash/index.ts:31](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/index.ts#L31)

#### Parameters

##### leaves

[`HashType`](../index/namespaces/HashType.mdx#hashtype)\[]

#### Returns

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

***

### SIZE

> `const` **SIZE**: `32` = `32`

Defined in: [src/primitives/Hash/constants.js:4](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/constants.js#L4)

Hash size in bytes (32 bytes = 256 bits)

***

### ZERO

> `const` **ZERO**: [`HashType`](../index/namespaces/HashType.mdx#hashtype)

Defined in: [src/primitives/Hash/constants.js:10](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/constants.js#L10)

Zero hash constant (32 zero bytes)

## Functions

### \_ConcatFactory()

> **\_ConcatFactory**(`deps`): (...`hashes`) => [`HashType`](../index/namespaces/HashType.mdx#hashtype)

Defined in: [src/primitives/Hash/concat.js:9](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/concat.js#L9)

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`](../index/namespaces/HashType.mdx#hashtype)

##### Parameters

###### hashes

...[`HashType`](../index/namespaces/HashType.mdx#hashtype)\[]

##### Returns

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

***

### \_Keccak256Factory()

> **\_Keccak256Factory**(`deps`): (`data`) => [`HashType`](../index/namespaces/HashType.mdx#hashtype)

Defined in: [src/primitives/Hash/keccak256.js:7](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/keccak256.js#L7)

Factory: Hash data with Keccak-256

#### Parameters

##### deps

Crypto dependencies

###### keccak256

(`data`) => `Uint8Array`

Keccak256 hash function

#### Returns

Function that hashes data

> (`data`): [`HashType`](../index/namespaces/HashType.mdx#hashtype)

##### Parameters

###### data

`Uint8Array`

##### Returns

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

***

### \_Keccak256HexFactory()

> **\_Keccak256HexFactory**(`deps`): (`hex`) => [`HashType`](../index/namespaces/HashType.mdx#hashtype)

Defined in: [src/primitives/Hash/keccak256Hex.js:10](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/keccak256Hex.js#L10)

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`](../index/namespaces/HashType.mdx#hashtype)

##### Parameters

###### hex

`string`

##### Returns

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

***

### \_Keccak256StringFactory()

> **\_Keccak256StringFactory**(`deps`): (`str`) => [`HashType`](../index/namespaces/HashType.mdx#hashtype)

Defined in: [src/primitives/Hash/keccak256String.js:9](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/keccak256String.js#L9)

Factory: Hash string with Keccak-256

#### Parameters

##### deps

Crypto dependencies

###### keccak256

(`data`) => `Uint8Array`

Keccak256 hash function

#### Returns

Function that hashes strings

> (`str`): [`HashType`](../index/namespaces/HashType.mdx#hashtype)

##### Parameters

###### str

`string`

##### Returns

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

***

### \_MerkleRootFactory()

> **\_MerkleRootFactory**(`deps`): (`hashes`) => [`HashType`](../index/namespaces/HashType.mdx#hashtype)

Defined in: [src/primitives/Hash/merkleRoot.js:10](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/merkleRoot.js#L10)

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`](../index/namespaces/HashType.mdx#hashtype)

##### Parameters

###### hashes

[`HashType`](../index/namespaces/HashType.mdx#hashtype)\[]

##### Returns

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

***

### assert()

> **assert**(`value`, `message?`): `asserts value is HashType`

Defined in: [src/primitives/Hash/assert.js:19](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/assert.js#L19)

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](https://voltaire.tevm.sh/primitives/hash) for Hash documentation

#### Since

0.0.0

#### Throws

If value is not a Hash

#### Example

```javascript theme={null}
import * as Hash from './primitives/Hash/index.js';
Hash.assert(value); // throws if not Hash
```

***

### clone()

> **clone**(`hash`): [`HashType`](../index/namespaces/HashType.mdx#hashtype)

Defined in: [src/primitives/Hash/clone.js:16](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/clone.js#L16)

Clone hash

#### Parameters

##### hash

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

Hash to clone

#### Returns

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

New hash with same value

#### See

[https://voltaire.tevm.sh/primitives/hash](https://voltaire.tevm.sh/primitives/hash) for Hash documentation

#### Since

0.0.0

#### Throws

#### Example

```javascript theme={null}
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](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/equals.js#L20)

Compare two hashes for equality

Uses constant-time comparison to prevent timing attacks.

#### Parameters

##### hash

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

First hash

##### other

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

Hash to compare with

#### Returns

`boolean`

True if hashes are equal

#### See

[https://voltaire.tevm.sh/primitives/hash](https://voltaire.tevm.sh/primitives/hash) for Hash documentation

#### Since

0.0.0

#### Throws

#### Example

```javascript theme={null}
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](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/format.js#L18)

Format hash for display (truncated)

#### Parameters

##### hash

[`HashType`](../index/namespaces/HashType.mdx#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](https://voltaire.tevm.sh/primitives/hash) for Hash documentation

#### Since

0.0.0

#### Throws

#### Example

```javascript theme={null}
import * as Hash from './primitives/Hash/index.js';
const hash = Hash.from('0x1234...');
const display = Hash.format(hash); // "0x1234...5678"
```

***

### from()

> **from**(`value`): [`HashType`](../index/namespaces/HashType.mdx#hashtype)

Defined in: [src/primitives/Hash/from.js:19](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/from.js#L19)

Create Hash from string or bytes

#### Parameters

##### value

Hex string with optional 0x prefix or Uint8Array

`string` | `Uint8Array`\<`ArrayBufferLike`>

#### Returns

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

Hash bytes

#### See

[https://voltaire.tevm.sh/primitives/hash](https://voltaire.tevm.sh/primitives/hash) for Hash documentation

#### Since

0.0.0

#### Throws

If input is invalid or wrong length

#### Example

```javascript theme={null}
import * as Hash from './primitives/Hash/index.js';
const hash = Hash.from('0x1234...');
const hash2 = Hash.from(new Uint8Array(32));
```

***

### fromBytes()

> **fromBytes**(`bytes`): [`HashType`](../index/namespaces/HashType.mdx#hashtype)

Defined in: [src/primitives/Hash/fromBytes.js:18](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/fromBytes.js#L18)

Create Hash from raw bytes

#### Parameters

##### bytes

`Uint8Array`\<`ArrayBufferLike`>

Raw bytes (must be 32 bytes)

#### Returns

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

Hash bytes

#### See

[https://voltaire.tevm.sh/primitives/hash](https://voltaire.tevm.sh/primitives/hash) for Hash documentation

#### Since

0.0.0

#### Throws

If bytes is wrong length

#### Example

```javascript theme={null}
import * as Hash from './primitives/Hash/index.js';
const hash = Hash.fromBytes(new Uint8Array(32));
```

***

### fromHex()

> **fromHex**(`hex`): [`HashType`](../index/namespaces/HashType.mdx#hashtype)

Defined in: [src/primitives/Hash/fromHex.js:20](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/fromHex.js#L20)

Create Hash from hex string

#### Parameters

##### hex

`string`

Hex string with optional 0x prefix

#### Returns

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

Hash bytes

#### See

[https://voltaire.tevm.sh/primitives/hash](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

```javascript theme={null}
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](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/isHash.js#L19)

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](https://voltaire.tevm.sh/primitives/hash) for Hash documentation

#### Since

0.0.0

#### Throws

#### Example

```javascript theme={null}
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](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/isValidHex.js#L19)

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](https://voltaire.tevm.sh/primitives/hash) for Hash documentation

#### Since

0.0.0

#### Throws

#### Example

```javascript theme={null}
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](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/isZero.js#L18)

Check if hash is zero hash

#### Parameters

##### hash

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

Hash to check

#### Returns

`boolean`

True if hash is all zeros

#### See

[https://voltaire.tevm.sh/primitives/hash](https://voltaire.tevm.sh/primitives/hash) for Hash documentation

#### Since

0.0.0

#### Throws

#### Example

```javascript theme={null}
import * as Hash from './primitives/Hash/index.js';
const hash = Hash.from('0x00...');
const zero = Hash.isZero(hash); // true
```

***

### random()

> **random**(): [`HashType`](../index/namespaces/HashType.mdx#hashtype)

Defined in: [src/primitives/Hash/random.js:17](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/random.js#L17)

Generate random hash

#### Returns

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

Random 32-byte hash

#### See

[https://voltaire.tevm.sh/primitives/hash](https://voltaire.tevm.sh/primitives/hash) for Hash documentation

#### Since

0.0.0

#### Throws

If crypto.getRandomValues not available

#### Example

```javascript theme={null}
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](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/slice.js#L18)

Get slice of hash

#### Parameters

##### hash

[`HashType`](../index/namespaces/HashType.mdx#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](https://voltaire.tevm.sh/primitives/hash) for Hash documentation

#### Since

0.0.0

#### Throws

#### Example

```javascript theme={null}
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](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/toBytes.js#L16)

Convert Hash to raw bytes

#### Parameters

##### hash

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

Hash to convert

#### Returns

`Uint8Array`\<`ArrayBufferLike`>

Copy of hash bytes

#### See

[https://voltaire.tevm.sh/primitives/hash](https://voltaire.tevm.sh/primitives/hash) for Hash documentation

#### Since

0.0.0

#### Throws

#### Example

```javascript theme={null}
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](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/toHex.js#L16)

Convert Hash to hex string

#### Parameters

##### hash

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

Hash to convert

#### Returns

`string`

Hex string with 0x prefix

#### See

[https://voltaire.tevm.sh/primitives/hash](https://voltaire.tevm.sh/primitives/hash) for Hash documentation

#### Since

0.0.0

#### Throws

#### Example

```javascript theme={null}
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](https://github.com/evmts/voltaire/blob/bd6ec34405c15ad8cd51d11579d495dc53813482/src/primitives/Hash/toString.js#L17)

Convert Hash to string (alias for toHex)

#### Parameters

##### hash

[`HashType`](../index/namespaces/HashType.mdx#hashtype)

Hash to convert

#### Returns

`string`

Hex string with 0x prefix

#### See

[https://voltaire.tevm.sh/primitives/hash](https://voltaire.tevm.sh/primitives/hash) for Hash documentation

#### Since

0.0.0

#### Throws

#### Example

```javascript theme={null}
import * as Hash from './primitives/Hash/index.js';
const hash = Hash.from('0x1234...');
const str = Hash.toString(hash);
```

## References

### Hash

Re-exports [Hash](../index/index.mdx#hash)

***

### HashLike

Re-exports [HashLike](../index/namespaces/HashType.mdx#hashlike)

***

### HashType

Re-exports [HashType](../index/namespaces/HashType.mdx#hashtype)

***

### HashTypeInterface

Renames and re-exports [HashType](../index/namespaces/HashType.mdx#hashtype)
