<div align="center">
# 🎲 drandite
**An idiomatic Rust implementation for drand**
[](https://crates.io/crates/drandite)
[](https://docs.rs/drandite)
</div>
`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.
```rust
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](https://docs.rs/drandite) 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
- Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or <https://www.apache.org/licenses/LICENSE-2.0>)
- MIT license
([LICENSE-MIT](LICENSE-MIT) or <https://opensource.org/licenses/MIT>)
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.
[`drand`]: https://www.drand.love/
[`libcrux`]: https://github.com/celabshq/libcrux
[`blst`]: https://github.com/supranational/blst
[`kyber`]: https://github.com/drand/kyber