lib

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

deletion.rs (2101B)


      1 //! Sealed authoring for validated NIP-09 deletion requests.
      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::post::deletion::AuthoredNip09DeletionRequest;
     12 use radroots_event_codec::authoring::AuthoredEventBody;
     13 
     14 /// A sealed builder for a validated NIP-09 deletion request.
     15 ///
     16 /// The wrapper exposes no raw builder conversion or tag/content mutation.
     17 /// Signing or publication establishes no target-deletion authorization or
     18 /// effect.
     19 ///
     20 /// ```compile_fail
     21 /// use radroots_nostr::event::Nip09DeletionRequestBuilder;
     22 ///
     23 /// fn expose_raw_builder(builder: Nip09DeletionRequestBuilder) {
     24 ///     let _: nostr::EventBuilder = builder.into();
     25 /// }
     26 /// ```
     27 ///
     28 /// ```compile_fail
     29 /// use radroots_nostr::{event::Nip09DeletionRequestBuilder, tag::Tag};
     30 ///
     31 /// fn mutate_validated_tags(
     32 ///     builder: Nip09DeletionRequestBuilder,
     33 ///     tag: Tag,
     34 /// ) {
     35 ///     let _ = builder.tag(tag);
     36 /// }
     37 /// ```
     38 #[must_use = "NIP-09 deletion request builders must be signed or published"]
     39 pub struct Nip09DeletionRequestBuilder {
     40     inner: SealedBuilderCore,
     41 }
     42 
     43 impl Nip09DeletionRequestBuilder {
     44     pub fn custom_created_at(mut self, created_at: RadrootsNostrTimestamp) -> Self {
     45         self.inner = self.inner.custom_created_at(created_at);
     46         self
     47     }
     48 
     49     pub fn sign_with_keys(self, keys: &RadrootsNostrKeys) -> Result<RadrootsNostrEvent, Error> {
     50         self.inner.sign_with_keys(keys)
     51     }
     52 
     53     pub fn into_external_signing_request(
     54         self,
     55         public_key: RadrootsNostrPublicKey,
     56     ) -> Result<ExternalSigningRequest, Error> {
     57         self.inner.into_external_signing_request(public_key)
     58     }
     59 }
     60 
     61 pub fn build_nip09_deletion_request_event(
     62     request: &AuthoredNip09DeletionRequest,
     63 ) -> Result<Nip09DeletionRequestBuilder, Error> {
     64     Ok(Nip09DeletionRequestBuilder {
     65         inner: SealedBuilderCore::new(AuthoredEventBody::from_nip09_deletion_request(request)?),
     66     })
     67 }