mithril-client

Crates.iomithril-client
lib.rsmithril-client
version0.10.1
sourcesrc
created_at2023-11-27 09:38:30.082226
updated_at2024-11-07 13:51:45.841204
descriptionMithril client library
homepagehttps://mithril.network
repositoryhttps://github.com/input-output-hk/mithril/
max_upload_size
id1050282
size189,281
mithril (github:input-output-hk:mithril)

documentation

README

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.

Commit count: 8466

cargo fmt