@tevm/voltaire / primitives/Hash
primitives/Hash
Variables
concat()
Defined in: src/primitives/Hash/index.ts:34constconcat: (…hashes) =>HashType
Parameters
hashes
…HashType[]
Returns
HashType
keccak256()
Defined in: src/primitives/Hash/index.ts:23constkeccak256: (data) =>HashType
Parameters
data
Uint8Array
Returns
HashType
keccak256Hex()
Defined in: src/primitives/Hash/index.ts:26constkeccak256Hex: (hex) =>HashType
Parameters
hex
string
Returns
HashType
keccak256String()
Defined in: src/primitives/Hash/index.ts:29constkeccak256String: (str) =>HashType
Parameters
str
string
Returns
HashType
merkleRoot()
Defined in: src/primitives/Hash/index.ts:31constmerkleRoot: (leaves) =>HashType
Parameters
leaves
HashType[]
Returns
HashType
SIZE
Defined in: src/primitives/Hash/constants.js:4 Hash size in bytes (32 bytes = 256 bits)constSIZE:32=32
ZERO
Defined in: src/primitives/Hash/constants.js:10 Zero hash constant (32 zero bytes)constZERO:HashType
Functions
_ConcatFactory()
_ConcatFactory(Defined in: src/primitives/Hash/concat.js:9 Factory: Concatenate multiple hashes and hash the resultdeps): (…hashes) =>HashType
Parameters
deps
Crypto dependencieskeccak256
(data) => Uint8Array
Keccak256 hash function
Returns
Function that concatenates and hashes(…hashes):HashType
Parameters
hashes
…HashType[]
Returns
HashType
_Keccak256Factory()
_Keccak256Factory(Defined in: src/primitives/Hash/keccak256.js:7 Factory: Hash data with Keccak-256deps): (data) =>HashType
Parameters
deps
Crypto dependencieskeccak256
(data) => Uint8Array
Keccak256 hash function
Returns
Function that hashes data(data):HashType
Parameters
data
Uint8Array
Returns
HashType
_Keccak256HexFactory()
_Keccak256HexFactory(Defined in: src/primitives/Hash/keccak256Hex.js:10 Factory: Hash hex string with Keccak-256deps): (hex) =>HashType
Parameters
deps
Crypto dependencieskeccak256
(data) => Uint8Array
Keccak256 hash function
Returns
Function that hashes hex strings(hex):HashType
Parameters
hex
string
Returns
HashType
_Keccak256StringFactory()
_Keccak256StringFactory(Defined in: src/primitives/Hash/keccak256String.js:9 Factory: Hash string with Keccak-256deps): (str) =>HashType
Parameters
deps
Crypto dependencieskeccak256
(data) => Uint8Array
Keccak256 hash function
Returns
Function that hashes strings(str):HashType
Parameters
str
string
Returns
HashType
_MerkleRootFactory()
_MerkleRootFactory(Defined in: src/primitives/Hash/merkleRoot.js:10 Factory: Calculate Merkle root of hash arraydeps): (hashes) =>HashType
Parameters
deps
Crypto dependencieskeccak256
(data) => Uint8Array
Keccak256 hash function
Returns
Function that calculates Merkle root(hashes):HashType
Parameters
hashes
HashType[]
Returns
HashType
assert()
assert(Defined in: src/primitives/Hash/assert.js:19 Assert value is a Hash, throws if notvalue,message?):asserts value is HashType
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 documentationSince
0.0.0Throws
If value is not a HashExample
clone()
clone(Defined in: src/primitives/Hash/clone.js:16 Clone hashhash):HashType
Parameters
hash
HashType
Hash to clone
Returns
HashType
New hash with same value
See
https://voltaire.tevm.sh/primitives/hash for Hash documentationSince
0.0.0Throws
Example
equals()
equals(Defined in: src/primitives/Hash/equals.js:20 Compare two hashes for equality Uses constant-time comparison to prevent timing attacks.hash,other):boolean
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 documentationSince
0.0.0Throws
Example
format()
format(Defined in: src/primitives/Hash/format.js:18 Format hash for display (truncated)hash,prefixLength?,suffixLength?):string
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 documentationSince
0.0.0Throws
Example
from()
from(Defined in: src/primitives/Hash/from.js:19 Create Hash from string or bytesvalue):HashType
Parameters
value
Hex string with optional 0x prefix or Uint8Arraystring | Uint8Array<ArrayBufferLike>
Returns
HashType
Hash bytes
See
https://voltaire.tevm.sh/primitives/hash for Hash documentationSince
0.0.0Throws
If input is invalid or wrong lengthExample
fromBytes()
fromBytes(Defined in: src/primitives/Hash/fromBytes.js:18 Create Hash from raw bytesbytes):HashType
Parameters
bytes
Uint8Array<ArrayBufferLike>
Raw bytes (must be 32 bytes)
Returns
HashType
Hash bytes
See
https://voltaire.tevm.sh/primitives/hash for Hash documentationSince
0.0.0Throws
If bytes is wrong lengthExample
fromHex()
fromHex(Defined in: src/primitives/Hash/fromHex.js:20 Create Hash from hex stringhex):HashType
Parameters
hex
string
Hex string with optional 0x prefix
Returns
HashType
Hash bytes
See
https://voltaire.tevm.sh/primitives/hash for Hash documentationSince
0.0.0Throws
If hex is wrong lengthThrows
If hex contains invalid charactersExample
isHash()
isHash(Defined in: src/primitives/Hash/isHash.js:19 Check if value is a valid Hashvalue):value is HashType
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 documentationSince
0.0.0Throws
Example
isValidHex()
isValidHex(Defined in: src/primitives/Hash/isValidHex.js:19 Validate hex string is valid hash formathex):boolean
Parameters
hex
string
Hex string to validate
Returns
boolean
True if valid hash hex format
See
https://voltaire.tevm.sh/primitives/hash for Hash documentationSince
0.0.0Throws
Example
isZero()
isZero(Defined in: src/primitives/Hash/isZero.js:18 Check if hash is zero hashhash):boolean
Parameters
hash
HashType
Hash to check
Returns
boolean
True if hash is all zeros
See
https://voltaire.tevm.sh/primitives/hash for Hash documentationSince
0.0.0Throws
Example
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 documentationSince
0.0.0Throws
If crypto.getRandomValues not availableExample
slice()
slice(Defined in: src/primitives/Hash/slice.js:18 Get slice of hashhash,start?,end?):Uint8Array<ArrayBufferLike>
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 documentationSince
0.0.0Throws
Example
toBytes()
toBytes(Defined in: src/primitives/Hash/toBytes.js:16 Convert Hash to raw byteshash):Uint8Array<ArrayBufferLike>
Parameters
hash
HashType
Hash to convert
Returns
Uint8Array<ArrayBufferLike>
Copy of hash bytes
See
https://voltaire.tevm.sh/primitives/hash for Hash documentationSince
0.0.0Throws
Example
toHex()
toHex(Defined in: src/primitives/Hash/toHex.js:16 Convert Hash to hex stringhash):string
Parameters
hash
HashType
Hash to convert
Returns
string
Hex string with 0x prefix
See
https://voltaire.tevm.sh/primitives/hash for Hash documentationSince
0.0.0Throws
Example
toString()
toString(Defined in: src/primitives/Hash/toString.js:17 Convert Hash to string (alias for toHex)hash):string
Parameters
hash
HashType
Hash to convert
Returns
string
Hex string with 0x prefix

