Crate mithril_client

Source
Expand description

Define all the tooling necessary to manipulate Mithril certified types from a Mithril Aggregator.

It handles the different types that can be queried to a Mithril aggregator:

The Client aggregates the queries of all of those types.

NOTE: Snapshot download and Certificate chain validation can take quite some time even with a fast computer and network. For those a feedback mechanism is available, more details on it in the feedback submodule.

§Example

Below is an example describing the usage of most of the library’s functions together:

Note: Snapshot download and the compute snapshot message functions are available using crate feature fs.

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

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 the binary must have read/write access to it.
let target_directory = Path::new("/home/user/download/");
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));

§Optional Features

The following are a list of Cargo features that can be enabled or disabled:

  • fs: Enables file system related functionalities.
  • unstable: Enables experimental or in-development mithril-client features that may change.
  • rug-backend (enabled by default): Enables usage of rug numerical backend in mithril-stm (dependency of mithril-common).
  • num-integer-backend: Enables usage of num-integer numerical backend in mithril-stm (dependency of mithril-common).

To allow fine tuning of the http queries, the following Reqwest features are re-exported:

  • native-tls (enabled by default): Enables TLS functionality provided by native-tls.
  • native-tls-vendored: Enables the vendored feature of native-tls.
  • native-tls-alpn: Enables the alpn feature of native-tls.
  • rustls-tls: Enables TLS functionality provided by rustls. Equivalent to rustls-tls-webpki-roots.
  • rustls-tls-manual-roots: Enables TLS functionality provided by rustls, without setting any root certificates. Roots have to be specified manually.
  • rustls-tls-webpki-roots: Enables TLS functionality provided by rustls, while using root certificates from the webpki-roots crate.
  • rustls-tls-native-roots: Enables TLS functionality provided by rustls, while using root certificates from the rustls-native-certs crate.
  • enable-http-compression (enabled by default): Enables compressed traffic with reqwest.

Modules§

Structs§

Enums§

Type Aliases§