vc-bundle 0.1.0

Deterministic VisualBundleCore hashing for Visual Compiler
Documentation
//! Deterministic hashing for VisualBundleCore.

use crate::error::BundleError;
use crate::VisualBundleCore;
use vc_shared::canonical::canonical_json;
use vc_shared::hashing::{sha256, Sha256Digest};

/// Computes the deterministic hash of a VisualBundleCore.
///
/// The hash is computed from the canonical JSON representation of the core.
///
/// # Contract
///
/// Given the same `VisualBundleCore`, every supported platform produces
/// exactly the same canonical bytes and exactly the same SHA-256 digest.
///
/// # Errors
/// Returns `BundleError` if canonical serialization fails.
pub fn bundle_hash(core: &VisualBundleCore) -> Result<Sha256Digest, BundleError> {
    let bytes = canonical_json(core)?;
    Ok(sha256(&bytes))
}