lib

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

lib.rs (2129B)


      1 #![cfg_attr(coverage_nightly, feature(coverage_attribute))]
      2 #![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
      3 #![forbid(unsafe_code)]
      4 #![deny(rustdoc::broken_intra_doc_links)]
      5 
      6 //! Canonical Radroots event-domain models.
      7 //!
      8 //! Public behavior is grouped under the approved singular domain modules.
      9 //! The crate root intentionally exposes only its curated native event types.
     10 
     11 #[cfg(not(feature = "std"))]
     12 extern crate alloc;
     13 
     14 /// Applies one fail-closed invariant without duplicating control-flow branches
     15 /// across the event domain's typed validation boundaries.
     16 pub(crate) fn require_invariant<E>(condition: bool, error: &dyn Fn() -> E) -> Result<(), E> {
     17     condition.then_some(()).ok_or_else(error)
     18 }
     19 
     20 #[cfg(test)]
     21 /// Returns deterministic 64-character fixtures that are also valid secp256k1
     22 /// x-only public keys; labels without a curve point are remapped.
     23 pub(crate) fn test_valid_hex_64(character: char) -> String {
     24     if matches!(character, 'b' | 'B') {
     25         let value = "2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4";
     26         return if character.is_ascii_uppercase() {
     27             value.to_ascii_uppercase()
     28         } else {
     29             value.to_owned()
     30         };
     31     }
     32     let character = match character {
     33         '0' => '7',
     34         '1' => '8',
     35         '5' => 'd',
     36         '6' => 'e',
     37         '9' => 'a',
     38         'c' | 'C' => '3',
     39         'f' | 'F' => '4',
     40         other => other,
     41     };
     42     core::iter::repeat_n(character, 64).collect()
     43 }
     44 
     45 pub mod admission;
     46 pub mod calendar;
     47 pub mod contract;
     48 pub mod draft;
     49 #[cfg(all(test, feature = "std", feature = "knowledge"))]
     50 mod dto;
     51 pub mod envelope;
     52 pub mod farm;
     53 pub mod food;
     54 pub mod generic_draft;
     55 pub mod id;
     56 #[cfg(feature = "knowledge")]
     57 pub mod knowledge;
     58 pub mod listing;
     59 pub mod media;
     60 pub mod post;
     61 pub mod profile;
     62 pub mod social;
     63 pub mod tag;
     64 pub mod trade;
     65 mod verification;
     66 pub mod wire;
     67 
     68 pub use draft::SignedEvent;
     69 pub use envelope::{EventEnvelope as Event, EventKind, EventTag};
     70 pub use generic_draft::GenericEventDraft;
     71 pub use id::EventId;
     72 pub use verification::{Error, SignatureVerifiedEvent as VerifiedEvent};