moreinlaw-kernel 0.3.0

The MoreInLaw federation protocol: what every instance must agree on to stay on the network.
Documentation
//! The fixed values that decide which network a copy of MoreInLaw is on: event numbers, labels,
//! web addresses and size limits. Changing one cuts a copy off from every organization that did
//! not make the same change.
//!
//! These are frozen. A new value means a new schema version, never an edit; the test at the
//! bottom fails on any edit so that the break is a decision and not an accident.

/// Host-signed verified-lawyer badge.
pub const BADGE_KIND: u16 = 30777;
/// Maintainer-signed directory entry for an organization.
pub const ORG_DIRECTORY_KIND: u16 = 30778;
/// Host-signed registration: an organization's own claim to exist at an address.
pub const REGISTRATION_KIND: u16 = 30779;
/// NIP-51 set, used for the public organization set and the private verified list.
pub const LIST_KIND: u64 = 30003;
/// NIP-51 follow set, used for the host-group roster.
pub const ROSTER_KIND: u16 = 30000;
/// NIP-98 HTTP auth, how one instance proves itself to another.
pub const NIP98_KIND: u64 = 27235;
/// Lawyer-verification manifest signed in the phone app.
pub const MANIFEST_KIND: u64 = 4777;

pub const SCHEMA_VERSION: &str = "1";
/// Hashtag every registration and org set carries so relays can be queried for MoreInLaw only.
pub const DISCOVERY_TAG: &str = "moreinlaw";

pub const ORGS_SET_D: &str = "moreinlaw-organizations";
pub const VERIFIED_SET_D: &str = "moreinlaw-verified-orgs";
pub const ROSTER_D: &str = "host-group";
pub const NIP58_DEFINITION_SLUG: &str = "certified-moreinlawyer";

pub const MAX_NAME_CHARS: usize = 120;
pub const MAX_RELAYS: usize = 10;
pub const MAX_URL_CHARS: usize = 200;
pub const MAX_LIST_COORDS: usize = 2000;
pub const NIP98_WINDOW_SECS: u64 = 60;

/// Paths under an organization's API base that other instances call. A copy that renames one
/// fails every peer's address proof.
pub mod routes {
    pub const HOST_IDENTITY: &str = "/api/host_identity";
    pub const HOST_BRANDING_LOGO: &str = "/api/host_branding/logo";
    pub const FEDERATION_SUMMARY: &str = "/api/federation/summary";
    pub const FEDERATION_HELLO: &str = "/api/federation/hello";
    pub const FEDERATION_VERIFICATIONS: &str = "/api/federation/verifications";
    /// Where the API sits when a registration names no `api`: the portal plus this.
    pub const DEFAULT_API_SUFFIX: &str = "/backend";
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn wire_values_are_frozen() {
        assert_eq!(
            (
                BADGE_KIND,
                ORG_DIRECTORY_KIND,
                REGISTRATION_KIND,
                ROSTER_KIND
            ),
            (30777, 30778, 30779, 30000)
        );
        assert_eq!((LIST_KIND, NIP98_KIND, MANIFEST_KIND), (30003, 27235, 4777));
        assert_eq!((SCHEMA_VERSION, DISCOVERY_TAG), ("1", "moreinlaw"));
        assert_eq!(ORGS_SET_D, "moreinlaw-organizations");
        assert_eq!(VERIFIED_SET_D, "moreinlaw-verified-orgs");
        assert_eq!(ROSTER_D, "host-group");
        assert_eq!(NIP58_DEFINITION_SLUG, "certified-moreinlawyer");
        assert_eq!(
            (MAX_NAME_CHARS, MAX_RELAYS, MAX_URL_CHARS, MAX_LIST_COORDS),
            (120, 10, 200, 2000)
        );
        assert_eq!(NIP98_WINDOW_SECS, 60);
        assert_eq!(routes::HOST_IDENTITY, "/api/host_identity");
        assert_eq!(routes::HOST_BRANDING_LOGO, "/api/host_branding/logo");
        assert_eq!(routes::FEDERATION_SUMMARY, "/api/federation/summary");
        assert_eq!(routes::FEDERATION_HELLO, "/api/federation/hello");
        assert_eq!(
            routes::FEDERATION_VERIFICATIONS,
            "/api/federation/verifications"
        );
        assert_eq!(routes::DEFAULT_API_SUFFIX, "/backend");
    }
}