lib

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

seal.rs (2810B)


      1 //! Exact structured-commerce seal data, without permission, crypto or retention.
      2 use super::EncodedCommerceRumor;
      3 use crate::{
      4     nip01::{EventFields, WireError},
      5     nip59::PrivateSeal,
      6 };
      7 use core::fmt;
      8 use radroots_domain::{CommandDigest, OperationId, PublicKey, RecordId, RumorEventId, UnixSeconds};
      9 
     10 /// One recipient's exact kind13 intent for an unchanged structured rumor.
     11 /// Identity fields are data claims. A concrete executor must compare the entire
     12 /// record/rumor and command against its actual retained T0 before binding T1.
     13 pub struct CommerceSeal {
     14     operation: OperationId,
     15     command: CommandDigest,
     16     record: RecordId,
     17     rumor: RumorEventId,
     18     seal: PrivateSeal,
     19 }
     20 impl CommerceSeal {
     21     /// Requires an actual bilateral recipient and the shared complete NIP59
     22     /// structural limits. Encryption/MAC and current execution are separate.
     23     pub fn new(
     24         operation: OperationId,
     25         command: CommandDigest,
     26         rumor: &EncodedCommerceRumor,
     27         recipient: PublicKey,
     28         created_at: UnixSeconds,
     29         ciphertext: &str,
     30     ) -> Result<Self, WireError> {
     31         if !rumor.recipients().contains(&recipient) {
     32             return Err(WireError::InvalidInput);
     33         }
     34         let seal = PrivateSeal::new(
     35             rumor.author(),
     36             recipient,
     37             created_at,
     38             rumor.created_at(),
     39             rumor.protected_wire().len(),
     40             ciphertext,
     41         )?;
     42         Ok(Self {
     43             operation,
     44             command,
     45             record: rumor.record_id(),
     46             rumor: rumor.event_id(),
     47             seal,
     48         })
     49     }
     50     /// Exact declared captured operation identity; no store completion proof.
     51     pub const fn operation_id(&self) -> OperationId {
     52         self.operation
     53     }
     54     /// Exact declared command commitment; no approval proof.
     55     pub const fn command_digest(&self) -> CommandDigest {
     56         self.command
     57     }
     58     /// Original domain-separated structured record identity.
     59     pub const fn record_id(&self) -> RecordId {
     60         self.record
     61     }
     62     /// Exact unchanged inner NIP01 rumor identity.
     63     pub const fn rumor_id(&self) -> RumorEventId {
     64         self.rumor
     65     }
     66     /// Exact private recipient; never a public kind13 tag.
     67     pub const fn recipient(&self) -> PublicKey {
     68         self.seal.recipient()
     69     }
     70     /// Exact expected event identity; this provides no signature evidence.
     71     pub const fn event_id(&self) -> [u8; 32] {
     72         self.seal.event_id()
     73     }
     74     /// Original immutable NIP01 fields for qualified signing and comparison.
     75     pub fn fields(&self) -> EventFields<'_> {
     76         self.seal.fields()
     77     }
     78 }
     79 impl fmt::Debug for CommerceSeal {
     80     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     81         f.write_str("CommerceSeal(<redacted>)")
     82     }
     83 }