Skip to main content

igc_net/
topic.rs

1//! Well-known gossip topic IDs for the igc-net protocol.
2//!
3//! Topic IDs are fixed protocol constants.
4//!
5//! The values are precomputed from the canonical derivation strings and embedded
6//! directly so the implementation matches the spec's interoperability rules.
7
8/// Derivation string for the primary announcement topic.
9/// All compliant igc-net nodes MUST join this topic on startup.
10pub const ANNOUNCE_TOPIC_STR: &str = "igc-net/announce/v1";
11
12/// Derivation string for the analytics announcement topic.
13/// Nodes that publish or consume IGC_META_DOC analytics SHOULD join this topic.
14pub const ANALYTICS_TOPIC_STR: &str = "igc-net/analytics/v1";
15
16/// Derivation string for the normative governance topic.
17/// All governance records defined by `55-governance-sync.md` propagate here.
18pub const GOVERNANCE_TOPIC_STR: &str = "igc-net/governance/v1";
19
20/// Derivation string for pilot-auth-did governance propagation.
21///
22/// Nodes that participate in identity governance catch-up SHOULD join this topic.
23pub const PILOT_AUTH_DID_GOVERNANCE_TOPIC_STR: &str = "igc-net/governance/pilot-auth-did/v1";
24
25/// `BLAKE3("igc-net/announce/v1")` as a 32-byte array.
26pub const ANNOUNCE_TOPIC_ID: [u8; 32] = [
27    0x2f, 0x06, 0x56, 0x7e, 0x5d, 0x71, 0x48, 0xb5, 0x63, 0x49, 0xa7, 0x53, 0xf8, 0xb4, 0x07, 0xfb,
28    0xc3, 0x5b, 0x2f, 0x0d, 0x90, 0xff, 0x36, 0x6f, 0xf2, 0x67, 0x3d, 0x06, 0x02, 0x45, 0xdd, 0xa9,
29];
30
31/// `BLAKE3("igc-net/analytics/v1")` as a 32-byte array.
32pub const ANALYTICS_TOPIC_ID: [u8; 32] = [
33    0x4f, 0x29, 0x34, 0x5b, 0x69, 0x86, 0x88, 0x63, 0x51, 0xdb, 0xff, 0x97, 0xb4, 0x23, 0x1b, 0x7d,
34    0x9a, 0x60, 0x1a, 0x50, 0x98, 0xf1, 0x84, 0x80, 0xc2, 0xcb, 0x4d, 0x28, 0xfb, 0xe3, 0x09, 0x50,
35];
36
37/// `BLAKE3("igc-net/governance/v1")` as a 32-byte array.
38pub const GOVERNANCE_TOPIC_ID: [u8; 32] = [
39    0xb5, 0x66, 0x7d, 0x06, 0x81, 0x7e, 0xb4, 0x90, 0xa5, 0x82, 0x0b, 0x5a, 0x77, 0x50, 0xa4, 0x60,
40    0xea, 0x00, 0x32, 0x42, 0x66, 0x34, 0x00, 0x27, 0xcd, 0x4c, 0xf3, 0x09, 0xd2, 0x74, 0x45, 0x81,
41];
42
43/// `BLAKE3("igc-net/governance/pilot-auth-did/v1")` as a 32-byte array.
44pub const PILOT_AUTH_DID_GOVERNANCE_TOPIC_ID: [u8; 32] = [
45    0xd5, 0xe1, 0x5e, 0xf3, 0x48, 0x40, 0x2d, 0x96, 0xdb, 0x04, 0x71, 0x12, 0xdd, 0x99, 0xb9, 0x7e,
46    0xdf, 0x13, 0x09, 0xe5, 0xa0, 0x56, 0xa5, 0xc7, 0xfa, 0xfe, 0xa9, 0xf4, 0x1a, 0x40, 0x34, 0x57,
47];
48
49/// `BLAKE3("igc-net/announce/v1")` as a 32-byte array.
50///
51/// This is the well-known gossip topic for flight announcements.
52/// The canonical hex value is defined in specs/specs_igc.md §2.
53pub fn announce_topic_id() -> [u8; 32] {
54    ANNOUNCE_TOPIC_ID
55}
56
57/// `BLAKE3("igc-net/analytics/v1")` as a 32-byte array.
58///
59/// Single well-known gossip topic for IGC_META_DOC analytics announcements.
60/// Defined in specs/specs_meta.md §11.1.
61pub fn analytics_topic_id() -> [u8; 32] {
62    ANALYTICS_TOPIC_ID
63}
64
65/// `BLAKE3("igc-net/governance/v1")` as a 32-byte array.
66pub fn governance_topic_id() -> [u8; 32] {
67    GOVERNANCE_TOPIC_ID
68}
69
70/// `BLAKE3("igc-net/governance/pilot-auth-did/v1")` as a 32-byte array.
71pub fn pilot_auth_did_governance_topic_id() -> [u8; 32] {
72    PILOT_AUTH_DID_GOVERNANCE_TOPIC_ID
73}
74
75#[cfg(test)]
76mod tests {
77    use super::*;
78
79    #[test]
80    fn announce_topic_id_is_32_bytes() {
81        assert_eq!(announce_topic_id().len(), 32);
82    }
83
84    #[test]
85    fn analytics_topic_id_is_32_bytes() {
86        assert_eq!(analytics_topic_id().len(), 32);
87    }
88
89    #[test]
90    fn topic_ids_are_distinct() {
91        assert_ne!(announce_topic_id(), analytics_topic_id());
92        assert_ne!(announce_topic_id(), governance_topic_id());
93        assert_ne!(announce_topic_id(), pilot_auth_did_governance_topic_id());
94        assert_ne!(analytics_topic_id(), governance_topic_id());
95        assert_ne!(analytics_topic_id(), pilot_auth_did_governance_topic_id());
96        assert_ne!(governance_topic_id(), pilot_auth_did_governance_topic_id());
97    }
98
99    #[test]
100    fn announce_topic_id_matches_derivation() {
101        // Verify the runtime value matches a directly-computed BLAKE3.
102        let expected = *blake3::hash(ANNOUNCE_TOPIC_STR.as_bytes()).as_bytes();
103        assert_eq!(announce_topic_id(), expected);
104    }
105
106    #[test]
107    fn analytics_topic_id_matches_derivation() {
108        let expected = *blake3::hash(ANALYTICS_TOPIC_STR.as_bytes()).as_bytes();
109        assert_eq!(analytics_topic_id(), expected);
110    }
111
112    #[test]
113    fn governance_topic_id_matches_derivation() {
114        let expected = *blake3::hash(GOVERNANCE_TOPIC_STR.as_bytes()).as_bytes();
115        assert_eq!(governance_topic_id(), expected);
116    }
117
118    #[test]
119    fn pilot_auth_did_governance_topic_id_matches_derivation() {
120        let expected = *blake3::hash(PILOT_AUTH_DID_GOVERNANCE_TOPIC_STR.as_bytes()).as_bytes();
121        assert_eq!(pilot_auth_did_governance_topic_id(), expected);
122    }
123
124    /// Snapshot test — verifies the announce topic ID against the value published
125    /// in specs/specs_igc.md §2.  If this fails, the spec and implementation have
126    /// diverged; update one of them.
127    #[test]
128    fn announce_topic_id_matches_spec_constant() {
129        let hex = hex::encode(announce_topic_id());
130        // Pre-computed: BLAKE3("igc-net/announce/v1")
131        assert_eq!(
132            hex,
133            "2f06567e5d7148b56349a753f8b407fbc35b2f0d90ff366ff2673d060245dda9"
134        );
135    }
136
137    #[test]
138    fn analytics_topic_id_matches_spec_constant() {
139        let hex = hex::encode(analytics_topic_id());
140        // Pre-computed: BLAKE3("igc-net/analytics/v1")
141        assert_eq!(
142            hex,
143            "4f29345b6986886351dbff97b4231b7d9a601a5098f18480c2cb4d28fbe30950"
144        );
145    }
146
147    #[test]
148    fn governance_topic_id_matches_spec_constant() {
149        let hex = hex::encode(governance_topic_id());
150        // Pre-computed: BLAKE3("igc-net/governance/v1")
151        assert_eq!(
152            hex,
153            "b5667d06817eb490a5820b5a7750a460ea00324266340027cd4cf309d2744581"
154        );
155    }
156
157    #[test]
158    fn pilot_auth_did_governance_topic_id_matches_spec_constant() {
159        let hex = hex::encode(pilot_auth_did_governance_topic_id());
160        // Pre-computed: BLAKE3("igc-net/governance/pilot-auth-did/v1")
161        assert_eq!(
162            hex,
163            "d5e15ef348402d96db047112dd99b97edf1309e5a056a5c7fafea9f41a403457"
164        );
165    }
166}