MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / triage_reference

Function triage_reference

atomic-canonical/src/triage_ref.rs:45–53  ·  view source on GitHub ↗

The `urn:atomic:triage: ` reference for a set of pins. `candidate_changes` is sorted before hashing so a triage over the same set of changes in a different order produces the same reference. The map is already canonical (BTreeMap), and JCS sorts object keys, so the reference is a pure function of the pinned facts.

(pins: &TriagePins)

Source from the content-addressed store, hash-verified

43/// canonical (BTreeMap), and JCS sorts object keys, so the reference is a pure
44/// function of the pinned facts.
45pub fn triage_reference(pins: &TriagePins) -> String {
46 let mut canonical_pins = pins.clone();
47 canonical_pins.candidate_changes.sort();
48 let value =
49 serde_json::to_value(&canonical_pins).expect("TriagePins serialization is infallible");
50 let canonical = jcs::canonicalize(&value);
51 let digest = blake3::hash(canonical.as_bytes());
52 format!("urn:atomic:triage:{}", digest.to_hex())
53}
54
55/// Recompute the reference for `pins` and compare it to `reference`. True iff the
56/// pins hash to exactly this reference (order-insensitive for candidate changes).

Calls 5

canonicalizeFunction · 0.85
sortMethod · 0.80
hashFunction · 0.50
cloneMethod · 0.45
as_bytesMethod · 0.45