chore: reexport sha3 from primitives (#109)

* chore: reexport sha3 from primitives

* feat: add keccak256

* replace sha3 with tinykeccak
This commit is contained in:
Matthias Seitz
2022-10-20 16:43:29 +02:00
committed by GitHub
parent 4536e09c99
commit e9945b565a
3 changed files with 35 additions and 8 deletions

11
Cargo.lock generated
View File

@ -895,7 +895,7 @@ dependencies = [
"impl-rlp", "impl-rlp",
"impl-serde", "impl-serde",
"scale-info", "scale-info",
"tiny-keccak", "tiny-keccak 2.0.2",
] ]
[[package]] [[package]]
@ -936,7 +936,7 @@ dependencies = [
"serde_json", "serde_json",
"strum", "strum",
"thiserror", "thiserror",
"tiny-keccak", "tiny-keccak 2.0.2",
"unicode-xid", "unicode-xid",
] ]
@ -2536,6 +2536,7 @@ dependencies = [
"serde", "serde",
"serde_json", "serde_json",
"thiserror", "thiserror",
"tiny-keccak 0.3.0",
] ]
[[package]] [[package]]
@ -3366,6 +3367,12 @@ dependencies = [
"syn", "syn",
] ]
[[package]]
name = "tiny-keccak"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81cd8183d45872feda10001dfacfebf7e163e159922582cd919bed08732447c4"
[[package]] [[package]]
name = "tiny-keccak" name = "tiny-keccak"
version = "2.0.2" version = "2.0.2"

View File

@ -8,19 +8,24 @@ readme = "README.md"
description = "Commonly used types in reth." description = "Commonly used types in reth."
[dependencies] [dependencies]
ethers-core = { git = "https://github.com/gakonst/ethers-rs", default-features = false } # reth
bytes = "1.2"
serde = "1.0"
thiserror = "1"
reth-rlp = { path = "../common/rlp", features = ["std", "derive", "ethereum-types"]} reth-rlp = { path = "../common/rlp", features = ["std", "derive", "ethereum-types"]}
parity-scale-codec = { version = "3.2.1", features = ["derive", "bytes"] }
reth-codecs = { version = "0.1.0", path = "../codecs" } reth-codecs = { version = "0.1.0", path = "../codecs" }
# ethereum
ethers-core = { git = "https://github.com/gakonst/ethers-rs", default-features = false }
parity-scale-codec = { version = "3.2.1", features = ["derive", "bytes"] }
tiny-keccak = "0.3"
#used for forkid #used for forkid
crc = "1" crc = "1"
maplit = "1" maplit = "1"
# misc
bytes = "1.2"
serde = "1.0"
thiserror = "1"
[dev-dependencies] [dev-dependencies]
serde_json = "1.0" serde_json = "1.0"
hex-literal = "0.3" hex-literal = "0.3"

View File

@ -49,3 +49,18 @@ pub use ethers_core::{
types as rpc, types as rpc,
types::{Bloom, Bytes, H128, H160, H256, H512, H64, U128, U256, U64}, types::{Bloom, Bytes, H128, H160, H256, H512, H64, U128, U256, U64},
}; };
#[doc(hidden)]
mod __reexport {
pub use tiny_keccak;
}
// Useful reexports
pub use __reexport::*;
/// Returns the keccak256 hash for the given data.
pub fn keccak256(data: impl AsRef<[u8]>) -> H256 {
let mut res: [u8; 32] = [0; 32];
tiny_keccak::keccak_256(data.as_ref(), &mut res);
res.into()
}