@tevm/voltaire / crypto/Keccak256
crypto/Keccak256
Variables
DIGEST_SIZE
Defined in: src/crypto/Keccak256/constants.js:13 Digest size in bytes (32 bytes = 256 bits)constDIGEST_SIZE:number=32
Since
0.0.0Keccak256
Defined in: src/crypto/Keccak256/Keccak256.js:82constKeccak256: (input) =>Keccak256Hash&object=Keccak256Hash
Type Declaration
contractAddress()
contractAddress: (Compute contract address from deployer and nonce Uses CREATE formula: keccak256(rlp([sender, nonce]))[12:]sender,nonce) =>Uint8Array<ArrayBufferLike>
Parameters
sender
Uint8Array<ArrayBufferLike>
Deployer address (20 bytes)
nonce
bigint
Transaction nonce
Returns
Uint8Array<ArrayBufferLike>
Contract address (20 bytes)
See
https://voltaire.tevm.sh/crypto for crypto documentationSince
0.0.0Throws
If sender is not 20 bytesExample
create2Address()
create2Address: (Compute CREATE2 address Uses CREATE2 formula: keccak256(0xff ++ sender ++ salt ++ keccak256(init_code))[12:]sender,salt,initCodeHash) =>Uint8Array<ArrayBufferLike>
Parameters
sender
Uint8Array<ArrayBufferLike>
Deployer address (20 bytes)
salt
Uint8Array<ArrayBufferLike>
32-byte salt
initCodeHash
Uint8Array<ArrayBufferLike>
Hash of initialization code
Returns
Uint8Array<ArrayBufferLike>
Contract address (20 bytes)
See
https://voltaire.tevm.sh/crypto for crypto documentationSince
0.0.0Throws
If sender is not 20 bytesThrows
If salt is not 32 bytesThrows
If initCodeHash is not 32 bytesExample
DIGEST_SIZE
DIGEST_SIZE: number
Digest size in bytes (32 bytes = 256 bits)
Since
0.0.0from()
from: (Hash input with Keccak-256 (constructor pattern) Auto-detects input type and hashes accordingly:input) =>Keccak256Hash
- Uint8Array: hash directly
- string starting with 0x: parse as hex
- string: UTF-8 encode then hash
Parameters
input
Data to hashstring | Uint8Array<ArrayBufferLike>
Returns
Keccak256Hash
32-byte hash
See
https://voltaire.tevm.sh/crypto/keccak256 for crypto documentationSince
0.0.0Throws
If hex string is invalidExample
fromHex()
fromHex: (Hash hex string with Keccak-256hex) =>Keccak256Hash=hashHex
Parameters
hex
string
Hex string to hash (with or without 0x prefix)
Returns
Keccak256Hash
32-byte hash
See
https://voltaire.tevm.sh/crypto for crypto documentationSince
0.0.0Throws
If hex string is invalid or has odd lengthExample
fromString()
fromString: (Hash string with Keccak-256 String is UTF-8 encoded before hashing.str) =>Keccak256Hash=hashString
Parameters
str
string
String to hash
Returns
Keccak256Hash
32-byte hash
See
https://voltaire.tevm.sh/crypto for crypto documentationSince
0.0.0Throws
Example
fromTopic()
fromTopic: (Compute event topic (32-byte Keccak-256 hash) Used for Ethereum event signatures.signature) =>Keccak256Hash=topic
Parameters
signature
string
Event signature string
Returns
Keccak256Hash
32-byte topic
See
https://voltaire.tevm.sh/crypto for crypto documentationSince
0.0.0Throws
Example
hash()
hash: (Hash data with Keccak-256data) =>Keccak256Hash
Parameters
data
Uint8Array<ArrayBufferLike>
Data to hash
Returns
Keccak256Hash
32-byte hash
See
https://voltaire.tevm.sh/crypto for crypto documentationSince
0.0.0Throws
Example
hashHex()
hashHex: (Hash hex string with Keccak-256hex) =>Keccak256Hash
Parameters
hex
string
Hex string to hash (with or without 0x prefix)
Returns
Keccak256Hash
32-byte hash
See
https://voltaire.tevm.sh/crypto for crypto documentationSince
0.0.0Throws
If hex string is invalid or has odd lengthExample
hashMultiple()
hashMultiple: (Hash multiple data chunks in sequence Equivalent to hashing the concatenation of all chunks.chunks) =>Keccak256Hash
Parameters
chunks
readonlyUint8Array<ArrayBufferLike>[]
Array of data chunks to hash
Returns
Keccak256Hash
32-byte hash
See
https://voltaire.tevm.sh/crypto for crypto documentationSince
0.0.0Throws
Example
hashString()
hashString: (Hash string with Keccak-256 String is UTF-8 encoded before hashing.str) =>Keccak256Hash
Parameters
str
string
String to hash
Returns
Keccak256Hash
32-byte hash
See
https://voltaire.tevm.sh/crypto for crypto documentationSince
0.0.0Throws
Example
RATE
RATE: number
Rate in bytes for Keccak256 (136 bytes = 1088 bits)
Since
0.0.0selector()
selector: (Compute function selector (first 4 bytes of Keccak-256 hash) Used for Ethereum function signatures.signature) =>Uint8Array<ArrayBufferLike>
Parameters
signature
string
Function signature string
Returns
Uint8Array<ArrayBufferLike>
4-byte selector
See
https://voltaire.tevm.sh/crypto for crypto documentationSince
0.0.0Throws
Example
STATE_SIZE
STATE_SIZE: number
State size (25 u64 words = 1600 bits)
Since
0.0.0topic()
topic: (Compute event topic (32-byte Keccak-256 hash) Used for Ethereum event signatures.signature) =>Keccak256Hash
Parameters
signature
string
Event signature string
Returns
Keccak256Hash
32-byte topic
See
https://voltaire.tevm.sh/crypto for crypto documentationSince
0.0.0Throws
Example
Deprecated
Use Keccak256Hash instead Keccak256 alias maintained for backward compatibilityRATE
Defined in: src/crypto/Keccak256/constants.js:20 Rate in bytes for Keccak256 (136 bytes = 1088 bits)constRATE:number=136
Since
0.0.0STATE_SIZE
Defined in: src/crypto/Keccak256/constants.js:27 State size (25 u64 words = 1600 bits)constSTATE_SIZE:number=25
Since
0.0.0Functions
contractAddress()
contractAddress(Defined in: src/crypto/Keccak256/contractAddress.js:40 Compute contract address from deployer and nonce Uses CREATE formula: keccak256(rlp([sender, nonce]))[12:]sender,nonce):Uint8Array<ArrayBufferLike>
Parameters
sender
Uint8Array<ArrayBufferLike>
Deployer address (20 bytes)
nonce
bigint
Transaction nonce
Returns
Uint8Array<ArrayBufferLike>
Contract address (20 bytes)
See
https://voltaire.tevm.sh/crypto for crypto documentationSince
0.0.0Throws
If sender is not 20 bytesExample
create2Address()
create2Address(Defined in: src/crypto/Keccak256/create2Address.js:27 Compute CREATE2 address Uses CREATE2 formula: keccak256(0xff ++ sender ++ salt ++ keccak256(init_code))[12:]sender,salt,initCodeHash):Uint8Array<ArrayBufferLike>
Parameters
sender
Uint8Array<ArrayBufferLike>
Deployer address (20 bytes)
salt
Uint8Array<ArrayBufferLike>
32-byte salt
initCodeHash
Uint8Array<ArrayBufferLike>
Hash of initialization code
Returns
Uint8Array<ArrayBufferLike>
Contract address (20 bytes)
See
https://voltaire.tevm.sh/crypto for crypto documentationSince
0.0.0Throws
If sender is not 20 bytesThrows
If salt is not 32 bytesThrows
If initCodeHash is not 32 bytesExample
from()
from(Defined in: src/crypto/Keccak256/from.js:27 Hash input with Keccak-256 (constructor pattern) Auto-detects input type and hashes accordingly:input):Keccak256Hash
- Uint8Array: hash directly
- string starting with 0x: parse as hex
- string: UTF-8 encode then hash
Parameters
input
Data to hashstring | Uint8Array<ArrayBufferLike>
Returns
Keccak256Hash
32-byte hash
See
https://voltaire.tevm.sh/crypto/keccak256 for crypto documentationSince
0.0.0Throws
If hex string is invalidExample
hash()
hash(Defined in: src/crypto/Keccak256/hash.js:17 Hash data with Keccak-256data):Keccak256Hash
Parameters
data
Uint8Array<ArrayBufferLike>
Data to hash
Returns
Keccak256Hash
32-byte hash
See
https://voltaire.tevm.sh/crypto for crypto documentationSince
0.0.0Throws
Example
hashHex()
hashHex(Defined in: src/crypto/Keccak256/hashHex.js:18 Hash hex string with Keccak-256hex):Keccak256Hash
Parameters
hex
string
Hex string to hash (with or without 0x prefix)
Returns
Keccak256Hash
32-byte hash
See
https://voltaire.tevm.sh/crypto for crypto documentationSince
0.0.0Throws
If hex string is invalid or has odd lengthExample
hashMultiple()
hashMultiple(Defined in: src/crypto/Keccak256/hashMultiple.js:19 Hash multiple data chunks in sequence Equivalent to hashing the concatenation of all chunks.chunks):Keccak256Hash
Parameters
chunks
readonlyUint8Array<ArrayBufferLike>[]
Array of data chunks to hash
Returns
Keccak256Hash
32-byte hash
See
https://voltaire.tevm.sh/crypto for crypto documentationSince
0.0.0Throws
Example
hashString()
hashString(Defined in: src/crypto/Keccak256/hashString.js:19 Hash string with Keccak-256 String is UTF-8 encoded before hashing.str):Keccak256Hash
Parameters
str
string
String to hash
Returns
Keccak256Hash
32-byte hash
See
https://voltaire.tevm.sh/crypto for crypto documentationSince
0.0.0Throws
Example
selector()
selector(Defined in: src/crypto/Keccak256/selector.js:20 Compute function selector (first 4 bytes of Keccak-256 hash) Used for Ethereum function signatures.signature):Uint8Array<ArrayBufferLike>
Parameters
signature
string
Function signature string
Returns
Uint8Array<ArrayBufferLike>
4-byte selector
See
https://voltaire.tevm.sh/crypto for crypto documentationSince
0.0.0Throws
Example
topic()
topic(Defined in: src/crypto/Keccak256/topic.js:19 Compute event topic (32-byte Keccak-256 hash) Used for Ethereum event signatures.signature):Keccak256Hash
Parameters
signature
string
Event signature string
Returns
Keccak256Hash
32-byte topic

