Skip to main content

moreinlaw_kernel/
params.rs

1//! The fixed values that decide which network a copy of MoreInLaw is on: event numbers, labels,
2//! web addresses and size limits. Changing one cuts a copy off from every organization that did
3//! not make the same change.
4//!
5//! These are frozen. A new value means a new schema version, never an edit; the test at the
6//! bottom fails on any edit so that the break is a decision and not an accident.
7
8/// Host-signed verified-lawyer badge.
9pub const BADGE_KIND: u16 = 30777;
10/// Maintainer-signed directory entry for an organization.
11pub const ORG_DIRECTORY_KIND: u16 = 30778;
12/// Host-signed registration: an organization's own claim to exist at an address.
13pub const REGISTRATION_KIND: u16 = 30779;
14/// NIP-51 set, used for the public organization set and the private verified list.
15pub const LIST_KIND: u64 = 30003;
16/// NIP-51 follow set, used for the host-group roster.
17pub const ROSTER_KIND: u16 = 30000;
18/// NIP-98 HTTP auth, how one instance proves itself to another.
19pub const NIP98_KIND: u64 = 27235;
20/// Lawyer-verification manifest signed in the phone app.
21pub const MANIFEST_KIND: u64 = 4777;
22
23pub const SCHEMA_VERSION: &str = "1";
24/// Hashtag every registration and org set carries so relays can be queried for MoreInLaw only.
25pub const DISCOVERY_TAG: &str = "moreinlaw";
26
27pub const ORGS_SET_D: &str = "moreinlaw-organizations";
28pub const VERIFIED_SET_D: &str = "moreinlaw-verified-orgs";
29pub const ROSTER_D: &str = "host-group";
30pub const NIP58_DEFINITION_SLUG: &str = "certified-moreinlawyer";
31
32pub const MAX_NAME_CHARS: usize = 120;
33pub const MAX_RELAYS: usize = 10;
34/// The relays MoreInLaw reads and publishes to by default; unlike the values above, editing this list breaks nothing.
35pub const DEFAULT_RELAYS: &[&str] = &[
36    "wss://relay.damus.io",
37    "wss://relay.snort.social",
38    "wss://relay.primal.net",
39    "wss://nos.lol",
40    "wss://relay.nostr.band",
41];
42pub const MAX_URL_CHARS: usize = 200;
43pub const MAX_LIST_COORDS: usize = 2000;
44pub const NIP98_WINDOW_SECS: u64 = 60;
45
46/// Paths under an organization's API base that other instances call. A copy that renames one
47/// fails every peer's address proof.
48pub mod routes {
49    pub const HOST_IDENTITY: &str = "/api/host_identity";
50    pub const HOST_BRANDING_LOGO: &str = "/api/host_branding/logo";
51    pub const FEDERATION_SUMMARY: &str = "/api/federation/summary";
52    pub const FEDERATION_HELLO: &str = "/api/federation/hello";
53    pub const FEDERATION_VERIFICATIONS: &str = "/api/federation/verifications";
54    /// Where the API sits when a registration names no `api`: the portal plus this.
55    pub const DEFAULT_API_SUFFIX: &str = "/backend";
56}
57
58#[cfg(test)]
59mod tests {
60    use super::*;
61
62    #[test]
63    fn wire_values_are_frozen() {
64        assert_eq!(
65            (
66                BADGE_KIND,
67                ORG_DIRECTORY_KIND,
68                REGISTRATION_KIND,
69                ROSTER_KIND
70            ),
71            (30777, 30778, 30779, 30000)
72        );
73        assert_eq!((LIST_KIND, NIP98_KIND, MANIFEST_KIND), (30003, 27235, 4777));
74        assert_eq!((SCHEMA_VERSION, DISCOVERY_TAG), ("1", "moreinlaw"));
75        assert_eq!(ORGS_SET_D, "moreinlaw-organizations");
76        assert_eq!(VERIFIED_SET_D, "moreinlaw-verified-orgs");
77        assert_eq!(ROSTER_D, "host-group");
78        assert_eq!(NIP58_DEFINITION_SLUG, "certified-moreinlawyer");
79        assert_eq!(
80            (MAX_NAME_CHARS, MAX_RELAYS, MAX_URL_CHARS, MAX_LIST_COORDS),
81            (120, 10, 200, 2000)
82        );
83        assert_eq!(NIP98_WINDOW_SECS, 60);
84        assert_eq!(routes::HOST_IDENTITY, "/api/host_identity");
85        assert_eq!(routes::HOST_BRANDING_LOGO, "/api/host_branding/logo");
86        assert_eq!(routes::FEDERATION_SUMMARY, "/api/federation/summary");
87        assert_eq!(routes::FEDERATION_HELLO, "/api/federation/hello");
88        assert_eq!(
89            routes::FEDERATION_VERIFICATIONS,
90            "/api/federation/verifications"
91        );
92        assert_eq!(routes::DEFAULT_API_SUFFIX, "/backend");
93    }
94
95    #[test]
96    fn default_relays_are_valid() {
97        for relay in DEFAULT_RELAYS {
98            crate::registration::check_relay(relay).unwrap();
99        }
100        let unique: std::collections::HashSet<_> = DEFAULT_RELAYS.iter().collect();
101        assert_eq!(unique.len(), DEFAULT_RELAYS.len());
102        assert!(DEFAULT_RELAYS.len() <= MAX_RELAYS);
103    }
104}