mempill_types/
validity.rs1use crate::claim::Confidence;
4use crate::identity::{AgentId, ClaimRef};
5use crate::provenance::ProvenanceLabel;
6use crate::time::TransactionTime;
7
8#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
10pub struct ValidityAssertion {
11 pub assertion_ref: uuid::Uuid,
13 pub agent_id: AgentId,
15 pub target_claim: ClaimRef,
17 pub kind: AssertionKind,
19 pub provenance: ProvenanceLabel,
21 pub confidence: Confidence,
23 pub asserted_at: TransactionTime,
25}
26
27#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
29#[non_exhaustive]
30pub enum AssertionKind {
31 Bound {
33 bound_at: chrono::DateTime<chrono::Utc>,
35 },
36 Reopen {
38 reopen_at: chrono::DateTime<chrono::Utc>,
40 },
41}
42
43#[cfg(test)]
44mod tests {
45 use super::*;
46 use crate::identity::AgentId;
47 use crate::claim::Confidence;
48 use crate::provenance::{ExternalKind, ProvenanceLabel};
49 use crate::time::TransactionTime;
50 use chrono::Utc;
51
52 #[test]
53 fn validity_assertion_round_trip_serde() {
54 let now = Utc::now();
55 let va = ValidityAssertion {
56 assertion_ref: uuid::Uuid::new_v4(),
57 agent_id: AgentId("agent-1".into()),
58 target_claim: ClaimRef::new_random(),
59 kind: AssertionKind::Bound { bound_at: now },
60 provenance: ProvenanceLabel::External(ExternalKind::UserAsserted),
61 confidence: Confidence { value_confidence: 1.0, valid_time_confidence: 1.0 },
62 asserted_at: TransactionTime(now),
63 };
64 let json = serde_json::to_string(&va).unwrap();
65 let back: ValidityAssertion = serde_json::from_str(&json).unwrap();
66 assert_eq!(va.assertion_ref, back.assertion_ref);
67 assert_eq!(va.kind, back.kind);
68 }
69
70 #[test]
71 fn assertion_kind_bound_and_reopen_are_distinct() {
72 let now = Utc::now();
73 let bound = AssertionKind::Bound { bound_at: now };
74 let reopen = AssertionKind::Reopen { reopen_at: now };
75 assert_ne!(bound, reopen);
76 }
77}