// SPDX-License-Identifier: BUSL-1.1 // Copyright (c) 2026 StellaOps // Sprint: SPRINT_20260118_028_LIB_scoring_manifest_jcs_integration // Task: TASK-028-003 - ICanonicalizable interface namespace StellaOps.Canonical.Json; /// /// Interface for types that support canonical JSON serialization. /// Enables deterministic serialization and content-addressed hashing. /// public interface ICanonicalizable { /// /// Gets the canonical JSON representation of this object. /// Output is deterministic: same input produces identical bytes. /// /// Canonical JSON string. string GetCanonicalJson(); /// /// Computes the SHA-256 digest of the canonical JSON representation. /// /// 64-character lowercase hex string. string ComputeDigest(); } /// /// Extension methods for canonical JSON operations. /// public static class CanonJsonExtensions { /// /// Computes the canonical digest if the object implements ICanonicalizable, /// otherwise falls back to CanonJson.Hash(). /// public static string GetDigest(T obj) where T : notnull { if (obj is ICanonicalizable canonicalizable) { return canonicalizable.ComputeDigest(); } return CanonJson.Hash(obj); } /// /// Computes the prefixed canonical digest (sha256:...). /// public static string GetPrefixedDigest(T obj) where T : notnull { return "sha256:" + GetDigest(obj); } }