Skip to main content
@tevm/voltaire
@tevm/voltaire / crypto/Keccak256

crypto/Keccak256

Variables

DIGEST_SIZE

const DIGEST_SIZE: number = 32
Defined in: src/crypto/Keccak256/constants.js:13 Digest size in bytes (32 bytes = 256 bits)

Since

0.0.0

Keccak256

const Keccak256: (input) => Keccak256Hash & object = Keccak256Hash
Defined in: src/crypto/Keccak256/Keccak256.js:82

Type Declaration

contractAddress()
contractAddress: (sender, nonce) => Uint8Array<ArrayBufferLike>
Compute contract address from deployer and nonce Uses CREATE formula: keccak256(rlp([sender, nonce]))[12:]
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 documentation
Since
0.0.0
Throws
If sender is not 20 bytes
Example
create2Address()
create2Address: (sender, salt, initCodeHash) => Uint8Array<ArrayBufferLike>
Compute CREATE2 address Uses CREATE2 formula: keccak256(0xff ++ sender ++ salt ++ keccak256(init_code))[12:]
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 documentation
Since
0.0.0
Throws
If sender is not 20 bytes
Throws
If salt is not 32 bytes
Throws
If initCodeHash is not 32 bytes
Example
DIGEST_SIZE
DIGEST_SIZE: number
Digest size in bytes (32 bytes = 256 bits)
Since
0.0.0
from()
from: (input) => Keccak256Hash
Hash input with Keccak-256 (constructor pattern) Auto-detects input type and hashes accordingly:
  • Uint8Array: hash directly
  • string starting with 0x: parse as hex
  • string: UTF-8 encode then hash
Parameters
input
Data to hash string | Uint8Array<ArrayBufferLike>
Returns
Keccak256Hash 32-byte hash
See
https://voltaire.tevm.sh/crypto/keccak256 for crypto documentation
Since
0.0.0
Throws
If hex string is invalid
Example
fromHex()
fromHex: (hex) => Keccak256Hash = hashHex
Hash hex string with Keccak-256
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 documentation
Since
0.0.0
Throws
If hex string is invalid or has odd length
Example
fromString()
fromString: (str) => Keccak256Hash = hashString
Hash string with Keccak-256 String is UTF-8 encoded before hashing.
Parameters
str
string String to hash
Returns
Keccak256Hash 32-byte hash
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example
fromTopic()
fromTopic: (signature) => Keccak256Hash = topic
Compute event topic (32-byte Keccak-256 hash) Used for Ethereum event signatures.
Parameters
signature
string Event signature string
Returns
Keccak256Hash 32-byte topic
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example
hash()
hash: (data) => Keccak256Hash
Hash data with Keccak-256
Parameters
data
Uint8Array<ArrayBufferLike> Data to hash
Returns
Keccak256Hash 32-byte hash
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example
hashHex()
hashHex: (hex) => Keccak256Hash
Hash hex string with Keccak-256
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 documentation
Since
0.0.0
Throws
If hex string is invalid or has odd length
Example
hashMultiple()
hashMultiple: (chunks) => Keccak256Hash
Hash multiple data chunks in sequence Equivalent to hashing the concatenation of all chunks.
Parameters
chunks
readonly Uint8Array<ArrayBufferLike>[] Array of data chunks to hash
Returns
Keccak256Hash 32-byte hash
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example
hashString()
hashString: (str) => Keccak256Hash
Hash string with Keccak-256 String is UTF-8 encoded before hashing.
Parameters
str
string String to hash
Returns
Keccak256Hash 32-byte hash
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example
RATE
RATE: number
Rate in bytes for Keccak256 (136 bytes = 1088 bits)
Since
0.0.0
selector()
selector: (signature) => Uint8Array<ArrayBufferLike>
Compute function selector (first 4 bytes of Keccak-256 hash) Used for Ethereum function signatures.
Parameters
signature
string Function signature string
Returns
Uint8Array<ArrayBufferLike> 4-byte selector
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example
STATE_SIZE
STATE_SIZE: number
State size (25 u64 words = 1600 bits)
Since
0.0.0
topic()
topic: (signature) => Keccak256Hash
Compute event topic (32-byte Keccak-256 hash) Used for Ethereum event signatures.
Parameters
signature
string Event signature string
Returns
Keccak256Hash 32-byte topic
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
Example

Deprecated

Use Keccak256Hash instead Keccak256 alias maintained for backward compatibility

RATE

const RATE: number = 136
Defined in: src/crypto/Keccak256/constants.js:20 Rate in bytes for Keccak256 (136 bytes = 1088 bits)

Since

0.0.0

STATE_SIZE

const STATE_SIZE: number = 25
Defined in: src/crypto/Keccak256/constants.js:27 State size (25 u64 words = 1600 bits)

Since

0.0.0

Functions

contractAddress()

contractAddress(sender, nonce): Uint8Array<ArrayBufferLike>
Defined in: src/crypto/Keccak256/contractAddress.js:40 Compute contract address from deployer and nonce Uses CREATE formula: keccak256(rlp([sender, nonce]))[12:]

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 documentation

Since

0.0.0

Throws

If sender is not 20 bytes

Example


create2Address()

create2Address(sender, salt, initCodeHash): Uint8Array<ArrayBufferLike>
Defined in: src/crypto/Keccak256/create2Address.js:27 Compute CREATE2 address Uses CREATE2 formula: keccak256(0xff ++ sender ++ salt ++ keccak256(init_code))[12:]

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 documentation

Since

0.0.0

Throws

If sender is not 20 bytes

Throws

If salt is not 32 bytes

Throws

If initCodeHash is not 32 bytes

Example


from()

from(input): Keccak256Hash
Defined in: src/crypto/Keccak256/from.js:27 Hash input with Keccak-256 (constructor pattern) Auto-detects input type and hashes accordingly:
  • Uint8Array: hash directly
  • string starting with 0x: parse as hex
  • string: UTF-8 encode then hash

Parameters

input
Data to hash string | Uint8Array<ArrayBufferLike>

Returns

Keccak256Hash 32-byte hash

See

https://voltaire.tevm.sh/crypto/keccak256 for crypto documentation

Since

0.0.0

Throws

If hex string is invalid

Example


hash()

hash(data): Keccak256Hash
Defined in: src/crypto/Keccak256/hash.js:17 Hash data with Keccak-256

Parameters

data
Uint8Array<ArrayBufferLike> Data to hash

Returns

Keccak256Hash 32-byte hash

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

Example


hashHex()

hashHex(hex): Keccak256Hash
Defined in: src/crypto/Keccak256/hashHex.js:18 Hash hex string with Keccak-256

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 documentation

Since

0.0.0

Throws

If hex string is invalid or has odd length

Example


hashMultiple()

hashMultiple(chunks): Keccak256Hash
Defined in: src/crypto/Keccak256/hashMultiple.js:19 Hash multiple data chunks in sequence Equivalent to hashing the concatenation of all chunks.

Parameters

chunks
readonly Uint8Array<ArrayBufferLike>[] Array of data chunks to hash

Returns

Keccak256Hash 32-byte hash

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

Example


hashString()

hashString(str): Keccak256Hash
Defined in: src/crypto/Keccak256/hashString.js:19 Hash string with Keccak-256 String is UTF-8 encoded before hashing.

Parameters

str
string String to hash

Returns

Keccak256Hash 32-byte hash

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

Example


selector()

selector(signature): Uint8Array<ArrayBufferLike>
Defined in: src/crypto/Keccak256/selector.js:20 Compute function selector (first 4 bytes of Keccak-256 hash) Used for Ethereum function signatures.

Parameters

signature
string Function signature string

Returns

Uint8Array<ArrayBufferLike> 4-byte selector

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

Example


topic()

topic(signature): Keccak256Hash
Defined in: src/crypto/Keccak256/topic.js:19 Compute event topic (32-byte Keccak-256 hash) Used for Ethereum event signatures.

Parameters

signature
string Event signature string

Returns

Keccak256Hash 32-byte topic

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

Example

References

Keccak256Hash

Re-exports Keccak256Hash