Skip to main content
import * as Hash from 'voltaire-effect/primitives/Hash'
import { Effect } from 'effect'

const hash = await Effect.runPromise(
  Hash.fromHex('0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b')
)

Schemas

SchemaInputOutput
Hash.Hexhex stringHashType
Hash.BytesUint8ArrayHashType
import * as S from 'effect/Schema'

const hash = S.decodeSync(Hash.Hex)(
  '0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b'
)

Constructors (Effect)

FunctionInputDescription
from(value)string | Uint8ArrayCreate from hex or bytes
fromHex(hex)stringCreate from 66-char hex string
fromBytes(bytes)Uint8ArrayCreate from 32-byte array
const hash = Effect.runSync(Hash.from('0x' + 'ab'.repeat(32)))
const hash2 = Effect.runSync(Hash.fromBytes(new Uint8Array(32)))

Validation

FunctionDescription
isHash(value)Type guard (pure sync)
isValidHex(hex)Check if hex is valid hash format
isZero(hash)Check if hash is all zeros
assert(hash)Assert value is valid hash
if (Hash.isHash(value)) {
  // value is HashType
}

Operations (Effect)

FunctionDescription
clone(hash)Create independent copy
concat(...hashes)Concatenate and hash
equals(a, b)Compare two hashes
slice(hash, start?, end?)Extract byte range
const copy = Effect.runSync(Hash.clone(hash))
const combined = Effect.runSync(Hash.concat(hash1, hash2))

Conversions

FunctionDescription
toHex(hash)Convert to hex string (pure sync)
toBytes(hash)Convert to Uint8Array (pure sync)
toString(hash)Same as toHex (Effect)
format(hash)Format for display (Effect)
const hex = Hash.toHex(hash)  // "0x..."
const bytes = Hash.toBytes(hash)

Crypto (Effect)

FunctionDescription
keccak256(data)Hash bytes
keccak256Hex(hex)Hash hex string
keccak256String(str)Hash UTF-8 string
merkleRoot(leaves)Compute merkle root
random()Generate random hash
const hash = Effect.runSync(Hash.keccak256String('hello'))

Common Uses

  • Transaction hashes (eth_getTransactionByHash)
  • Block hashes (eth_getBlockByHash)
  • State roots, receipts roots, transactions roots
  • Storage slots

See Also