lib

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

calendar.rs (2131B)


      1 //! Sealed authoring for strict NIP-52 Event profiles.
      2 
      3 use crate::{
      4     error::Error,
      5     events::sealed::SealedBuilderCore,
      6     types::{
      7         ExternalSigningRequest, RadrootsNostrEvent, RadrootsNostrKeys, RadrootsNostrPublicKey,
      8         RadrootsNostrTimestamp,
      9     },
     10 };
     11 use radroots_event::calendar::{AuthoredCalendarDateEvent, AuthoredCalendarTimeEvent};
     12 use radroots_event_codec::authoring::AuthoredEventBody;
     13 
     14 /// A sealed builder for one validated NIP-52 date or time Event.
     15 ///
     16 /// Callers cannot change the event kind, coordinate, content, or tags after
     17 /// the typed calendar model has been converted into the authored body.
     18 #[must_use = "calendar event builders must be signed or published"]
     19 pub struct CalendarEventBuilder {
     20     inner: SealedBuilderCore,
     21 }
     22 
     23 impl CalendarEventBuilder {
     24     /// Sets the event timestamp without changing the validated NIP-52 profile.
     25     pub fn custom_created_at(mut self, created_at: RadrootsNostrTimestamp) -> Self {
     26         self.inner = self.inner.custom_created_at(created_at);
     27         self
     28     }
     29 
     30     /// Signs the exact authored Event directly with local keys.
     31     pub fn sign_with_keys(self, keys: &RadrootsNostrKeys) -> Result<RadrootsNostrEvent, Error> {
     32         self.inner.sign_with_keys(keys)
     33     }
     34 
     35     /// Finalizes the exact authored plan for an opaque host signer.
     36     pub fn into_external_signing_request(
     37         self,
     38         public_key: RadrootsNostrPublicKey,
     39     ) -> Result<ExternalSigningRequest, Error> {
     40         self.inner.into_external_signing_request(public_key)
     41     }
     42 }
     43 
     44 /// Builds a sealed kind-31922 all-day Event.
     45 pub fn build_calendar_date_event(
     46     event: &AuthoredCalendarDateEvent,
     47 ) -> Result<CalendarEventBuilder, Error> {
     48     Ok(CalendarEventBuilder {
     49         inner: SealedBuilderCore::new(AuthoredEventBody::from_calendar_date_event(event)?),
     50     })
     51 }
     52 
     53 /// Builds a sealed kind-31923 timed Event.
     54 pub fn build_calendar_time_event(
     55     event: &AuthoredCalendarTimeEvent,
     56 ) -> Result<CalendarEventBuilder, Error> {
     57     Ok(CalendarEventBuilder {
     58         inner: SealedBuilderCore::new(AuthoredEventBody::from_calendar_time_event(event)?),
     59     })
     60 }