use invoance::models::{AnchorDocumentParams, AnchorFileParams, FileSource, VerifyDocumentParams};
use invoance::InvoanceClient;
use sha2::{Digest, Sha256};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = InvoanceClient::new()?;
let bytes = b"...your document bytes...";
let mut hasher = Sha256::new();
hasher.update(bytes);
let document_hash = hex::encode(hasher.finalize());
let doc = client
.documents()
.anchor(AnchorDocumentParams {
document_hash: document_hash.clone(),
document_ref: Some("Invoice #1042".into()),
..Default::default()
})
.await?;
println!("anchored {}", doc.event_id);
let anchored = client
.documents()
.anchor_file(AnchorFileParams {
file: FileSource::Bytes(bytes.to_vec()),
document_ref: Some("Invoice #1042".into()),
event_type: Some("invoice".into()),
metadata: None,
idempotency_key: None,
skip_original: false,
trace_id: None,
})
.await?;
println!("anchored via file helper {}", anchored.event_id);
let verify = client
.documents()
.verify(&doc.event_id, VerifyDocumentParams { document_hash })
.await?;
println!("match_result = {}", verify.match_result);
Ok(())
}