lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README

relay_auth.rs (1137B)


      1 #![forbid(unsafe_code)]
      2 
      3 use crate::envelope::kind::KIND_RELAY_AUTH as KIND_RELAY_AUTH_EVENT;
      4 
      5 #[cfg(not(feature = "std"))]
      6 use alloc::string::String;
      7 
      8 pub const KIND_RELAY_AUTH: u32 = KIND_RELAY_AUTH_EVENT;
      9 
     10 #[cfg_attr(
     11     any(feature = "serde", test),
     12     derive(serde::Serialize, serde::Deserialize)
     13 )]
     14 #[derive(Clone, Debug, PartialEq, Eq)]
     15 pub struct RelayAuth {
     16     pub relay: String,
     17     pub challenge: String,
     18 }
     19 
     20 #[cfg(all(test, feature = "serde"))]
     21 #[cfg_attr(coverage_nightly, coverage(off))]
     22 mod tests {
     23     use super::*;
     24 
     25     #[test]
     26     fn relay_auth_kind_matches_nip42() {
     27         assert_eq!(KIND_RELAY_AUTH, 22242);
     28     }
     29 
     30     #[test]
     31     fn relay_auth_serializes_nip42_tags() {
     32         let value = serde_json::to_value(RelayAuth {
     33             relay: "wss://relay.example.invalid/farm/ABCDEFGHIJKLMNOPQRSTUV".to_string(),
     34             challenge: "relay-provided-challenge".to_string(),
     35         })
     36         .unwrap();
     37 
     38         assert_eq!(
     39             value["relay"],
     40             "wss://relay.example.invalid/farm/ABCDEFGHIJKLMNOPQRSTUV"
     41         );
     42         assert_eq!(value["challenge"], "relay-provided-challenge");
     43     }
     44 }