generate_conformance_seal

Function generate_conformance_seal 

Source
pub fn generate_conformance_seal(
    judgments: &[&NeutrosophicJudgment],
    weights: &[f64],
    operator_id: &str,
) -> Result<String>
Expand description

Generates a Conformance Seal for a fusion operation

This function implements the deterministic algorithm that creates a cryptographic fingerprint proving the fusion operation was performed according to OTP specification.

§Arguments

  • judgments - Slice of input Neutrosophic Judgments
  • weights - Corresponding weights for each judgment
  • operator_id - The fusion operator identifier (e.g., “otp-cawa-v1.1”)

§Returns

A SHA-256 hash as a hexadecimal string representing the Conformance Seal

§Errors

Returns ConformanceError if inputs are invalid or serialization fails

§Algorithm

  1. Validate input lengths match
  2. Create judgment-weight pairs
  3. Sort canonically by source_id from last provenance entry
  4. Serialize to canonical JSON (no spaces, sorted keys)
  5. Concatenate with operator ID using separator
  6. Calculate SHA-256 hash

§Example

use opentrustprotocol::{NeutrosophicJudgment, generate_conformance_seal};
 
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let judgment1 = NeutrosophicJudgment::new(0.8, 0.2, 0.0, vec![
        ("sensor1".to_string(), "2023-01-01T00:00:00Z".to_string())
    ])?;
 
    let judgment2 = NeutrosophicJudgment::new(0.6, 0.3, 0.1, vec![
        ("sensor2".to_string(), "2023-01-01T00:00:00Z".to_string())
    ])?;
 
    let seal = generate_conformance_seal(
        &[&judgment1, &judgment2],
        &[0.6, 0.4],
        "otp-cawa-v1.1"
    )?;
 
    println!("Conformance Seal: {}", seal);
    Ok(())
}