Skip to main content

qualia_client_core/
introduction.rs

1//! Invitation import for the first two-host Internet test.
2//!
3//! Production encoding is length-delimited (`QINV1`). `qcx1_` remains a
4//! trusted-private bootstrap import only.
5
6pub use qualia_core_db::net::peer::connectivity::{
7    phrase_must_not_mint_wg_keys, sign_invitation, verify_invitation, Invitation,
8};
9
10use crate::connection_identifier::ConnectionIdentifier;
11
12/// `qcx1_` is accepted only as a private bootstrap hint, not a public DHT record.
13pub fn qcx1_is_private_bootstrap_only() -> bool {
14    true
15}
16
17/// Decode a pasted `qcx1_` string without treating it as a production invitation.
18pub fn import_qcx1_private(s: &str) -> Result<ConnectionIdentifier, String> {
19    ConnectionIdentifier::decode(s)
20}
21
22#[cfg(test)]
23mod tests {
24    use super::*;
25    use ed25519_dalek::SigningKey;
26
27    #[test]
28    fn qinv1_and_qcx1_roles() {
29        assert!(phrase_must_not_mint_wg_keys());
30        assert!(qcx1_is_private_bootstrap_only());
31        let inv = Invitation {
32            peer: [1u8; 32],
33            proto: 1,
34            relay: 0,
35            expiry_unix: 2_000_000_000,
36            nonce: [2u8; 16],
37            policy: 0,
38        };
39        let mut body = [0u8; 256];
40        let n = inv.encode(&mut body).unwrap();
41        let sk = SigningKey::from_bytes(&[4u8; 32]);
42        let mut signed = [0u8; 320];
43        let sn = sign_invitation(&body[..n], &sk, &mut signed).unwrap();
44        let back = verify_invitation(&signed[..sn], &sk.verifying_key(), 1_700_000_000).unwrap();
45        assert_eq!(back.peer, inv.peer);
46    }
47}