Skip to main content

vc_bundle/
hash.rs

1//! Deterministic hashing for VisualBundleCore.
2
3use crate::error::BundleError;
4use crate::VisualBundleCore;
5use vc_shared::canonical::canonical_json;
6use vc_shared::hashing::{sha256, Sha256Digest};
7
8/// Computes the deterministic hash of a VisualBundleCore.
9///
10/// The hash is computed from the canonical JSON representation of the core.
11///
12/// # Contract
13///
14/// Given the same `VisualBundleCore`, every supported platform produces
15/// exactly the same canonical bytes and exactly the same SHA-256 digest.
16///
17/// # Errors
18/// Returns `BundleError` if canonical serialization fails.
19pub fn bundle_hash(core: &VisualBundleCore) -> Result<Sha256Digest, BundleError> {
20    let bytes = canonical_json(core)?;
21    Ok(sha256(&bytes))
22}