Module mithril_client::cardano_transaction_client

source ·
Expand description

A client to retrieve from an aggregator cryptographic proofs of membership for a subset of Cardano transactions.

In order to do so it defines a CardanoTransactionClient which exposes the following features:

Important: Verifying a proof only means that its cryptography is valid, in order to certify that a Cardano transactions subset is valid, the associated proof must be tied to a valid Mithril certificate (see the example below).

§Get and verify Cardano transaction proof

To get and verify a Cardano transaction proof using the ClientBuilder.

use mithril_client::{ClientBuilder, MessageBuilder};

let client = ClientBuilder::aggregator("YOUR_AGGREGATOR_ENDPOINT", "YOUR_GENESIS_VERIFICATION_KEY").build()?;

// 1 - Get a proof from the aggregator and verify it
let cardano_transaction_proof = client.cardano_transaction().get_proofs(&["tx-1", "tx-2"]).await?;
println!("Mithril could not certify the following transactions : {:?}", &cardano_transaction_proof.non_certified_transactions);

let verified_transactions = cardano_transaction_proof.verify()?;

// 2 - Verify its associated certificate chain
let certificate = client.certificate().verify_chain(&cardano_transaction_proof.certificate_hash).await?;

// 3 - Ensure that the proof is indeed signed in the associated certificate
let message = MessageBuilder::new().compute_cardano_transactions_proofs_message(&certificate, &verified_transactions);
if certificate.match_message(&message) {
    // All green, Mithril certifies that those transactions are part of the Cardano transactions set.
    println!("Certified transactions : {:?}", verified_transactions.certified_transactions());
}

§Get a Cardano transaction snapshot

To get a Cardano transaction snapshot using the ClientBuilder.

use mithril_client::ClientBuilder;

let client = ClientBuilder::aggregator("YOUR_AGGREGATOR_ENDPOINT", "YOUR_GENESIS_VERIFICATION_KEY").build()?;
let cardano_transaction_snapshot = client.cardano_transaction().get_snapshot("CARDANO_TRANSACTION_SNAPSHOT_HASH").await?.unwrap();

println!("Cardano transaction snapshot hash={}, epoch={}", cardano_transaction_snapshot.hash, cardano_transaction_snapshot.epoch);

§List available Cardano transaction snapshots

To list latest available Cardano transaction snapshots using the ClientBuilder.

use mithril_client::ClientBuilder;

let client = ClientBuilder::aggregator("YOUR_AGGREGATOR_ENDPOINT", "YOUR_GENESIS_VERIFICATION_KEY").build()?;
let cardano_transaction_snapshots = client.cardano_transaction().list_snapshots().await?;

for cardano_transaction_snapshot in cardano_transaction_snapshots {
    println!("Cardano transaction snapshot hash={}, epoch={}", cardano_transaction_snapshot.hash, cardano_transaction_snapshot.epoch);
}

Structs§