11 releases (4 breaking)

new 0.10.1 Nov 7, 2024
0.8.18 Sep 23, 2024
0.8.10 Jul 30, 2024
0.6.9 Mar 26, 2024
0.5.7 Nov 27, 2023

#438 in Magic Beans

Download history 6/week @ 2024-07-20 128/week @ 2024-07-27 4/week @ 2024-08-03 16/week @ 2024-08-24 1/week @ 2024-08-31 2/week @ 2024-09-07 23/week @ 2024-09-14 169/week @ 2024-09-21 29/week @ 2024-09-28 38/week @ 2024-10-05 22/week @ 2024-10-12 142/week @ 2024-10-19 18/week @ 2024-10-26 105/week @ 2024-11-02

291 downloads per month

Apache-2.0 and maybe LGPL-3.0+

425KB
9K SLoC

Mithril-client crates.io License Discord

This is a work in progress 🛠

  • mithril-client defines all the tooling necessary to manipulate Mithril certified types available from a Mithril aggregator.

  • The different types of available data certified by Mithril are:

    • Snapshot: list, get, download tarball and record statistics.
    • Mithril stake distribution: list and get.
    • Cardano transactions: list & get snapshot, get proofs.
    • Cardano stake distribution: list, get and get by epoch.
    • Certificate: list, get, and chain validation.

Example

Below is a basic example of how to use most of the functions exposed by the Mithril client library:

use mithril_client::{ClientBuilder, MessageBuilder};
use std::path::Path;

#[tokio::main]
async fn main() -> mithril_client::MithrilResult<()> {
    let client = ClientBuilder::aggregator("YOUR_AGGREGATOR_ENDPOINT", "YOUR_GENESIS_VERIFICATION_KEY").build()?;

    let snapshots = client.snapshot().list().await?;

    let last_digest = snapshots.first().unwrap().digest.as_ref();
    let snapshot = client.snapshot().get(last_digest).await?.unwrap();

    let certificate = client
        .certificate()
        .verify_chain(&snapshot.certificate_hash)
        .await?;

    // Note: the directory must already exist, and the user running this code must have read/write access to it.
    let target_directory = Path::new("YOUR_TARGET_DIRECTORY");
    client
        .snapshot()
        .download_unpack(&snapshot, target_directory)
        .await?;

    if let Err(e) = client.snapshot().add_statistics(&snapshot).await {
        println!("Could not increment snapshot download statistics: {:?}", e);
    }

    let message = MessageBuilder::new()
        .compute_snapshot_message(&certificate, target_directory)
        .await?;
    assert!(certificate.match_message(&message));

    Ok(())
}

Different arithmetic libraries

Under the hood mithril client could use different arithmetic libraries:

You can switch beetwen them by using rug-backend and num-integer-backend respectively. For Windows and WASM target platforms only num-integer-backend is available, for others rug-backend is a default option.

Getting Help

First, check our Developer documentation.

If you need more information, feel free to join IOG's Technical Community discord server.

Contributing

Thanks for considering contributing and help us on creating the Mithril protocol!

The best way to contribute right now is to try things out and provide feedback, but we also accept contributions to the documentation and obviously to the code itself.

When contributing to this project and interacting with others, please follow our Code of Conduct and our Contributing Guidelines.

Dependencies

~8–28MB
~458K SLoC