darkfi_sdk/monotree/
mod.rs

1/* This file is part of DarkFi (https://dark.fi)
2 *
3 * Copyright (C) 2020-2025 Dyne.org foundation
4 * Copyright (C) 2021 MONOLOG (Taeho Francis Lim and Jongwhan Lee) MIT License
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18 */
19
20/// Size of fixed length byte-array from a `Hasher`.
21/// Equivalent to `key` length of the tree.
22pub const HASH_LEN: usize = 32;
23
24/// A type representing length of `Bits`
25pub type BitsLen = u16;
26
27/// Type indicating fixed length byte-array.
28pub type Hash = [u8; HASH_LEN];
29
30/// Type representing a Merkle proof
31pub type Proof = Vec<(bool, Vec<u8>)>;
32
33/// The key to be used to restore the latest `root`
34pub const ROOT_KEY: &Hash = b"_______monotree::headroot_______";
35
36use std::sync::LazyLock;
37pub static EMPTY_HASH: LazyLock<Hash> = LazyLock::new(|| *blake3::hash(&[]).as_bytes());
38
39pub mod bits;
40
41pub mod node;
42
43pub mod tree;
44pub use tree::Monotree;
45
46pub mod utils;
47
48#[cfg(test)]
49mod tests;