drandite 0.1.0

Drand beacon verification, relay clients, and timelock encryption
Documentation

🎲 drandite

An idiomatic Rust implementation for drand

Crates.io Docs

drandite is an idiomatic Rust implementation of the drand stack, covering cryptographic primitives, beacon verification, the wire protocol, an HTTP client, and time-lock encryption.

Based on the original Go implementation, it differs by leveraging Rust's strong typing guarantees, aiming to make invalid states unrepresentable.

Cryptographic operations use formally verified libraries, libcrux and blst.

Usage

The following example fetches chain information for a pinned chain hash, retrieves the latest beacon, and verifies it before accessing its randomness.

use drandite::{
    reqwest, scheme::BlsUnchainedG1Rfc9380, ChainHash, Client, V2, Verifier,
};
use hex_literal::hex;
use std::time::Duration;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let adapter = reqwest::blocking::Client::builder()
        .timeout(Duration::from_secs(10))
        .build()?;

    let client = Client::<V2, _>::new("https://api.drand.sh", adapter)?;

    let pinned = ChainHash::new(hex!(
        "52db9ba70e0cc0f6eaf7803dd07447a1f5477735fd3f661792ba94600c84e971"
    ));
    let chain = client.chain::<BlsUnchainedG1Rfc9380>(pinned);

    let info = chain.info()?;
    let verified = Verifier::new(&info).verify(chain.latest()?)?;

    println!("{:?}", verified.randomness());

    Ok(())
}

See the API documentation for more information and other uses.

AI Usage

AI tools were used to assist with documentation and tests. Approximately 90% of the implementation was written by hand, with good part of it being ported directly from the original Go implementation (including the kyber library) into idiomatic Rust.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual-licensed as above, without any additional terms or conditions.