Core Hashing Methods
Basic Keccak256 hashing operations that returnKeccak256Hash type (branded 32-byte Uint8Array).
hash(data)
Hash raw bytes with Keccak-256. Signature:data(Uint8Array) - Input bytes to hash
Keccak256Hash (32-byte hash)
Throws: Never throws for valid input
- Basic Usage
- Transaction Data
- Multiple Chunks
- Constant-time implementation for security
- Processes arbitrary-length input (0 to 2^64-1 bytes)
- Output always exactly 32 bytes
- Deterministic - same input always produces same output
hashString(str)
Hash UTF-8 encoded string with Keccak-256. Signature:str(string) - String to hash (UTF-8 encoded before hashing)
Keccak256Hash (32-byte hash)
Throws: Never throws for valid input
- Basic Usage
- Function Signatures
- Event Signatures
- Unicode Handling
- Uses
TextEncoderfor UTF-8 conversion - Handles all Unicode code points correctly
- No normalization applied - different encodings produce different hashes
- Empty string produces:
0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
hashHex(hex)
Hash hex-encoded string with Keccak-256. Signature:hex(string) - Hex string to hash (with or without “0x” prefix)
Keccak256Hash (32-byte hash)
Throws: Never throws for valid hex string
- Basic Usage
- Hashing Addresses
- Hashing Calldata
- Public Key Hashing
- Hex string decoded to bytes before hashing
- Accepts both uppercase and lowercase hex
- “0x” prefix optional and stripped automatically
- Odd-length hex padded with leading zero:
"abc"→"0abc"
hashMultiple(chunks)
Hash multiple byte chunks in sequence. Signature:chunks(readonly Uint8Array[]) - Array of byte chunks to hash
Keccak256Hash (32-byte hash)
Throws: Never throws for valid input
- Basic Usage
- Efficient Concatenation
- Streaming Data
- Merkle Tree Nodes
- Equivalent to hashing concatenation of all chunks
- More efficient than manual concatenation for large data
- Preserves order -
[A, B]≠[B, A] - Empty chunks array produces empty input hash
Return Type: Keccak256Hash
All hash methods returnKeccak256Hash, a branded Uint8Array type:
- Always exactly 32 bytes (256 bits)
- Behaves like
Uint8Arrayat runtime - Type-safe at compile time
- Zero runtime overhead
Test Vectors
Verify implementation correctness:Related
- Ethereum Methods - Selector, topic, contract address methods
- Usage Patterns - Common patterns and best practices
- Implementations - Implementation comparison and selection
- Keccak256Hash - 32-byte hash type

