Skip to main content

Try it Live

Run Keccak256 examples in the interactive playground
Future Plans: This page is planned and under active development. Examples are placeholders and will be replaced with accurate, tested content.

Core Hashing Methods

Basic Keccak256 hashing operations that return Keccak256Hash type (branded 32-byte Uint8Array).

hash(data)

Hash raw bytes with Keccak-256. Signature:
Parameters:
  • data (Uint8Array) - Input bytes to hash
Returns: Keccak256Hash (32-byte hash) Throws: Never throws for valid input
Technical Notes:
  • 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:
Parameters:
  • str (string) - String to hash (UTF-8 encoded before hashing)
Returns: Keccak256Hash (32-byte hash) Throws: Never throws for valid input
Technical Notes:
  • Uses TextEncoder for UTF-8 conversion
  • Handles all Unicode code points correctly
  • No normalization applied - different encodings produce different hashes
  • Empty string produces: 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470
Different string representations hash differently:
  • "hello"" hello""hello " (whitespace matters)
  • "Transfer(address,uint256)""Transfer(address, uint256)" (spaces matter)
  • Normalize function/event signatures before hashing

hashHex(hex)

Hash hex-encoded string with Keccak-256. Signature:
Parameters:
  • hex (string) - Hex string to hash (with or without “0x” prefix)
Returns: Keccak256Hash (32-byte hash) Throws: Never throws for valid hex string
Technical Notes:
  • 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:
Parameters:
  • chunks (readonly Uint8Array[]) - Array of byte chunks to hash
Returns: Keccak256Hash (32-byte hash) Throws: Never throws for valid input
Technical Notes:
  • 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 return Keccak256Hash, a branded Uint8Array type:
Properties:
  • Always exactly 32 bytes (256 bits)
  • Behaves like Uint8Array at runtime
  • Type-safe at compile time
  • Zero runtime overhead
Usage:

Test Vectors

Verify implementation correctness: