invoance 0.1.0

Official Rust SDK for the Invoance compliance API
Documentation
//! Documents: anchor a hash, anchor a file, verify.
//!
//! ```bash
//! INVOANCE_API_KEY=inv_live_... cargo run --example documents
//! ```

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()?;

    // Anchor a document you have already hashed yourself.
    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);

    // Or let the SDK hash + upload a file for you.
    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);

    // Verify the hash.
    let verify = client
        .documents()
        .verify(&doc.event_id, VerifyDocumentParams { document_hash })
        .await?;
    println!("match_result = {}", verify.match_result);

    Ok(())
}