settled-sdk (Rust)
Rust SDK for Settled, a tamper-evident audit log built on RFC 6962 Merkle trees.
Requires Rust 1.70+ and a Tokio async runtime.
Installation
[dependencies]
settled-sdk = "0.1"
tokio = { version = "1", features = ["full"] }
Usage
Connecting to a Settled server
use settled_sdk::SettledClient;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let mut client = SettledClient::connect("http://localhost:50051").await?;
let result = client.append(b"user:42".to_vec(), data).await?;
println!("Assigned seq: {}", result.seq);
let entry = client.get(result.seq).await?;
let recent = client.get_latest(10).await?;
let sth = client.get_sth(0).await?;
let proof = client.inclusion_proof(result.seq, 0).await?;
let cp = client.consistency_proof(10, 0).await?;
Ok(())
}
Verifying proofs locally
use settled_sdk::verifier;
fn to32(v: &[u8]) -> [u8; 32] { v.try_into().expect("hash must be 32 bytes") }
fn to_proof(vecs: &[Vec<u8>]) -> Vec<[u8; 32]> { vecs.iter().map(|v| to32(v)).collect() }
let ok = verifier::verify_inclusion(
to32(&result.leaf_hash),
proof.leaf_index,
proof.tree_size,
&to_proof(&proof.proof),
to32(&proof.sth.root_hash),
);
let ok = verifier::verify_consistency(
cp.old_size,
cp.new_size,
&to_proof(&cp.proof),
to32(&cp.old_sth.root_hash),
to32(&cp.new_sth.root_hash),
);
let ok = verifier::verify_tree_head(
sth.tree_size,
to32(&sth.root_hash),
sth.timestamp_ns,
&sth.signature,
&sth.public_key,
);
Further reading
License
Elastic License 2.0