Skip to main content

vex_chora/
lib.rs

1//! vex-chora: The Native Bridge to Neutral Authority.
2//!
3//! This crate provides the adapter logic required for AI agents to communicate
4//! with the external CHORA witness network. It handles JCS serialization,
5//! signature verification, and authority handshakes.
6
7pub mod bridge;
8pub mod client;
9
10pub use bridge::AuthorityBridge;
11
12#[cfg(test)]
13mod tests {
14    use super::*;
15    use crate::client::MockChoraClient;
16    #[tokio::test]
17    async fn test_bridge_handshake() {
18        let bridge = AuthorityBridge::new(std::sync::Arc::new(MockChoraClient));
19        let intent = vex_core::segment::IntentData::Transparent {
20            request_sha256: "8ee6010d905547c377c67e63559e989b8073b168f11a1ffefd092c7ca962076e"
21                .to_string(),
22            confidence: 0.95,
23            capabilities: vec![],
24            magpie_source: None,
25            continuation_token: None,
26            metadata: vex_core::segment::SchemaValue(serde_json::Value::Null),
27        };
28
29        let capsule = bridge.perform_handshake(intent, "42").await.unwrap();
30
31        // Verify segments are present
32        if let vex_core::segment::IntentData::Transparent { confidence, .. } = &capsule.intent {
33            assert_eq!(*confidence, 0.95);
34        } else {
35            panic!("Expected Transparent intent");
36        }
37        assert_eq!(capsule.authority.nonce, "42");
38        assert_eq!(capsule.identity.aid, "mock-aid-01");
39
40        // Verify signature is present (base64)
41        assert!(!capsule.crypto.signature_b64.is_empty());
42
43        // Verify composite hash generation
44        let root = capsule.to_composite_hash().unwrap();
45        assert!(!root.to_hex().is_empty());
46    }
47}