lib

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

authored.rs (1979B)


      1 #[cfg(not(feature = "std"))]
      2 use alloc::{
      3     string::{String, ToString},
      4     vec,
      5     vec::Vec,
      6 };
      7 
      8 use radroots_event::{
      9     envelope::kind::KIND_POST,
     10     post::{
     11         AuthoredAsk, AuthoredPhotoUpdate, AuthoredPostImage, AuthoredUpdate,
     12         RADROOTS_ASK_MARKER_TAG_KEY, RADROOTS_ASK_MARKER_TAG_VALUE,
     13     },
     14     wire::Nip01EventWireParts,
     15 };
     16 
     17 /// Builds deterministic unsigned kind-1 wire parts for a strict Update.
     18 pub fn authored_update_to_wire_parts(update: &AuthoredUpdate) -> Nip01EventWireParts {
     19     Nip01EventWireParts {
     20         kind: KIND_POST,
     21         content: update.content().to_string(),
     22         tags: Vec::new(),
     23     }
     24 }
     25 
     26 /// Builds deterministic unsigned kind-1 wire parts for a strict PhotoUpdate.
     27 ///
     28 /// The caller must separately establish successful BUD-02 upload completion
     29 /// for every image before passing these parts to a signing boundary.
     30 pub fn authored_photo_update_to_wire_parts(photo: &AuthoredPhotoUpdate) -> Nip01EventWireParts {
     31     Nip01EventWireParts {
     32         kind: KIND_POST,
     33         content: photo.content().to_string(),
     34         tags: image_tags(photo.images()),
     35     }
     36 }
     37 
     38 /// Builds deterministic unsigned kind-1 wire parts for a strict Ask.
     39 ///
     40 /// The exact Ask marker is emitted first. Optional media uses the same strict
     41 /// NIP-92 profile as PhotoUpdate. Upload completion remains a separate runtime
     42 /// precondition before signing.
     43 pub fn authored_ask_to_wire_parts(ask: &AuthoredAsk) -> Nip01EventWireParts {
     44     let mut tags = Vec::with_capacity(1 + ask.images().len());
     45     tags.push(vec![
     46         RADROOTS_ASK_MARKER_TAG_KEY.to_string(),
     47         RADROOTS_ASK_MARKER_TAG_VALUE.to_string(),
     48     ]);
     49     tags.extend(image_tags(ask.images()));
     50     Nip01EventWireParts {
     51         kind: KIND_POST,
     52         content: ask.content().to_string(),
     53         tags,
     54     }
     55 }
     56 
     57 fn image_tags(images: &[AuthoredPostImage]) -> Vec<Vec<String>> {
     58     images
     59         .iter()
     60         .map(|image| image.imeta_tag().to_vec())
     61         .collect()
     62 }