1#![cfg_attr(not(feature = "std"), no_std)]
17#![doc = include_str!("../README.md")]
18
19extern crate alloc;
20
21use core::marker::PhantomData;
22use hash_db::Hasher;
23use primitive_types::H256;
24use trie_db::TrieLayout;
25
26mod node_codec;
27mod storage_proof;
28
29#[cfg(test)]
30mod tests;
31
32pub use storage_proof::{MemoryDB, StorageProof};
33
34#[derive(Default, Clone)]
36pub struct EIP1186Layout<H>(PhantomData<H>);
37
38impl<H: Hasher<Out = H256>> TrieLayout for EIP1186Layout<H> {
39 const USE_EXTENSION: bool = true;
40 const ALLOW_EMPTY: bool = false;
41 const MAX_INLINE_VALUE: Option<u32> = None;
42 type Hash = H;
43 type Codec = node_codec::RlpNodeCodec<H>;
44}
45
46#[cfg(feature = "std")]
49pub mod keccak {
50 use super::*;
51 use hash256_std_hasher::Hash256StdHasher;
52 use tiny_keccak::{Hasher, Keccak};
53
54 #[derive(Debug)]
56 pub struct KeccakHasher;
57
58 impl hash_db::Hasher for KeccakHasher {
59 type Out = H256;
60 type StdHasher = Hash256StdHasher;
61 const LENGTH: usize = 32;
62
63 fn hash(x: &[u8]) -> Self::Out {
64 keccak_256(x).into()
65 }
66 }
67
68 pub fn keccak_256(input: &[u8]) -> [u8; 32] {
70 let mut out = [0u8; 32];
71 let mut k = Keccak::v256();
72 k.update(input);
73 k.finalize(&mut out);
74 out
75 }
76}