summaryrefslogtreecommitdiffstats
path: root/examples/proofer_blake3.rs
blob: 8db399993ecae5cac00742fb4e7163f3ba1718b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use mt_rs::{
    fs,
    hasher::Blake3Hasher,
    node::Node,
    proof::{DefaultProofer, Proofer},
};

fn main() {
    let root_hash = match std::env::args().nth(1) {
        Some(hash) => hash,
        None => {
            eprintln!(
                "Usage: cargo run --example proofer_blake3 -- <root_hash> <file1> <file2> ..."
            );
            std::process::exit(1);
        }
    };

    let filenames: Vec<String> = std::env::args().skip(2).collect();
    if filenames.is_empty() {
        eprintln!("Usage: cargo run --example proofer_blake3 -- <root_hash> <file1> <file2> ...");
        std::process::exit(1);
    }

    let hasher = Blake3Hasher::new();

    let nodes: Vec<Node> = fs::hash_dir(hasher.clone(), filenames.clone());
    let first_node = nodes[0].clone();

    let proofer = DefaultProofer::new(hasher, nodes);
    let proof = proofer.generate(0).expect("Couldn't generate proof");

    println!(
        "{}",
        proofer.verify_hash(&proof, first_node.hash().to_string(), &root_hash[..])
    );
}