reply.rs (1639B)
1 //! Sealed authoring for strict marked NIP-10 Reply events. 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::reply::AuthoredNip10Reply; 12 use radroots_event_codec::authoring::AuthoredEventBody; 13 14 /// A sealed builder for a validated strict marked NIP-10 Reply. 15 /// 16 /// The wrapper exposes no raw builder conversion or tag/content mutation. 17 /// 18 /// ```compile_fail 19 /// use radroots_nostr::event::Nip10ReplyBuilder; 20 /// 21 /// fn expose_raw_builder(builder: Nip10ReplyBuilder) { 22 /// let _: nostr::EventBuilder = builder.into(); 23 /// } 24 /// ``` 25 #[must_use = "NIP-10 Reply builders must be signed or published"] 26 pub struct Nip10ReplyBuilder { 27 inner: SealedBuilderCore, 28 } 29 30 impl Nip10ReplyBuilder { 31 pub fn custom_created_at(mut self, created_at: RadrootsNostrTimestamp) -> Self { 32 self.inner = self.inner.custom_created_at(created_at); 33 self 34 } 35 36 pub fn sign_with_keys(self, keys: &RadrootsNostrKeys) -> Result<RadrootsNostrEvent, Error> { 37 self.inner.sign_with_keys(keys) 38 } 39 40 pub fn into_external_signing_request( 41 self, 42 public_key: RadrootsNostrPublicKey, 43 ) -> Result<ExternalSigningRequest, Error> { 44 self.inner.into_external_signing_request(public_key) 45 } 46 } 47 48 pub fn build_nip10_reply_event(reply: &AuthoredNip10Reply) -> Result<Nip10ReplyBuilder, Error> { 49 Ok(Nip10ReplyBuilder { 50 inner: SealedBuilderCore::new(AuthoredEventBody::from_nip10_reply(reply)?), 51 }) 52 }