1#![doc = include_str!("../README.md")]
2#![doc(
3 html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg",
4 html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico"
5)]
6#![warn(
7 missing_copy_implementations,
8 missing_debug_implementations,
9 missing_docs,
10 unreachable_pub,
11 clippy::missing_const_for_fn,
12 rustdoc::all
13)]
14#![cfg_attr(not(test), warn(unused_crate_dependencies))]
15#![deny(unused_must_use, rust_2018_idioms)]
16#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
17#![cfg_attr(not(feature = "std"), no_std)]
18
19#[macro_use]
20#[allow(unused_imports)]
21extern crate alloc;
22
23pub mod nodes;
24pub use nodes::BranchNodeCompact;
25
26pub mod hash_builder;
27pub use hash_builder::HashBuilder;
28
29pub mod proof;
30
31#[cfg(feature = "ethereum")]
32mod account;
33#[cfg(feature = "ethereum")]
34pub use account::TrieAccount;
35
36mod mask;
37pub use mask::TrieMask;
38
39#[allow(missing_docs)]
40pub mod root;
41
42#[doc(hidden)]
43pub use alloy_primitives::map::HashMap;
44
45#[doc(no_inline)]
46pub use nybbles::{self, Nibbles};
47
48use alloy_primitives::{b256, B256};
49
50pub const EMPTY_ROOT_HASH: B256 =
52 b256!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421");
53
54pub const KECCAK_EMPTY: B256 =
56 b256!("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
57
58#[cfg(test)]
59pub(crate) fn triehash_trie_root<I, K, V>(iter: I) -> B256
60where
61 I: IntoIterator<Item = (K, V)>,
62 K: AsRef<[u8]> + Ord,
63 V: AsRef<[u8]>,
64{
65 struct Keccak256Hasher;
66 impl hash_db::Hasher for Keccak256Hasher {
67 type Out = B256;
68 type StdHasher = plain_hasher::PlainHasher;
69
70 const LENGTH: usize = 32;
71
72 fn hash(x: &[u8]) -> Self::Out {
73 alloy_primitives::keccak256(x)
74 }
75 }
76
77 triehash::trie_root::<Keccak256Hasher, _, _, _>(iter)
82}