lib

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

installation.rs (16457B)


      1 //! Structural T2 reports. Only an actual qualified transaction establishes
      2 //! installation; constructing these values never grants authority or delivery.
      3 use super::{BoundSigningPlan, CommitAttempt, EvidenceReceipt, OperationError};
      4 use crate::workspace::WorkspaceBinding;
      5 use core::fmt;
      6 use radroots_domain::listing::ListingId;
      7 use radroots_domain::{
      8     CommandDigest, EnvelopeEventId, MessageId, OperationId, PublicKey, TransactionId, UnixSeconds,
      9     WorkspaceId,
     10 };
     11 use radroots_protocol::plan::SigningTarget;
     12 use std::boxed::Box;
     13 
     14 /// Original-operation selectors for native installation. The concrete owner
     15 /// independently loads and authenticates the complete retained graph.
     16 pub struct InstallationRequest {
     17     binding: WorkspaceBinding,
     18     operation: OperationId,
     19     command: CommandDigest,
     20     plan: [u8; 32],
     21 }
     22 impl InstallationRequest {
     23     /// Captures exact selectors, without authorizing installation.
     24     pub const fn new(
     25         binding: WorkspaceBinding,
     26         operation: OperationId,
     27         command: CommandDigest,
     28         plan: [u8; 32],
     29     ) -> Self {
     30         Self {
     31             binding,
     32             operation,
     33             command,
     34             plan,
     35         }
     36     }
     37     /// Original selected workspace scope.
     38     pub const fn binding(&self) -> &WorkspaceBinding {
     39         &self.binding
     40     }
     41     /// Original full operation identity.
     42     pub const fn operation_id(&self) -> OperationId {
     43         self.operation
     44     }
     45     /// Original semantic command commitment.
     46     pub const fn command_digest(&self) -> CommandDigest {
     47         self.command
     48     }
     49     /// Exact retained complete signing plan commitment.
     50     pub const fn plan_digest(&self) -> &[u8; 32] {
     51         &self.plan
     52     }
     53     /// Stable original anchor for an unknown transaction result.
     54     pub fn identity(&self) -> CommitAttempt {
     55         CommitAttempt::new(
     56             self.binding.input().workspace_id(),
     57             self.operation,
     58             self.command,
     59             None,
     60         )
     61     }
     62 }
     63 impl fmt::Debug for InstallationRequest {
     64     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
     65         f.write_str("InstallationRequest(<redacted>)")
     66     }
     67 }
     68 
     69 /// Original confirmed logical installation and its actual obtained basis.
     70 /// The body remains in the protected original command; no ciphertext or text is
     71 /// copied into this fixed reference. This data is not backend qualification.
     72 #[derive(Clone, Copy, Eq, PartialEq)]
     73 pub struct ChatInstallation {
     74     plan: [u8; 32],
     75     message: MessageId,
     76     preparation_transaction: TransactionId,
     77     plan_transaction: TransactionId,
     78     transaction: TransactionId,
     79     installed_at: UnixSeconds,
     80     basis: EvidenceReceipt,
     81 }
     82 impl ChatInstallation {
     83     /// Checks a structural store report against the original complete plan.
     84     /// The backend must also authenticate the referenced actual obtained bytes
     85     /// and compare every retained fact in the installation transaction.
     86     pub fn from_committed_store(
     87         bound: &BoundSigningPlan,
     88         basis: EvidenceReceipt,
     89         transaction: TransactionId,
     90         installed_at: UnixSeconds,
     91     ) -> Result<Self, OperationError> {
     92         check_evidence(bound, basis)?;
     93         if installed_at < bound.bound_at() {
     94             return Err(OperationError::RecoveryRequired);
     95         }
     96         Ok(Self {
     97             plan: *bound.plan().digest(),
     98             message: bound.chat_plan()?.message_id(),
     99             preparation_transaction: bound.prepared().transaction_id(),
    100             plan_transaction: bound.transaction_id(),
    101             transaction,
    102             installed_at,
    103             basis,
    104         })
    105     }
    106     /// Original workspace.
    107     pub const fn workspace_id(&self) -> WorkspaceId {
    108         self.basis.workspace_id()
    109     }
    110     /// Original operation.
    111     pub const fn operation_id(&self) -> OperationId {
    112         self.basis.operation_id()
    113     }
    114     /// Original semantic command commitment.
    115     pub const fn command_digest(&self) -> CommandDigest {
    116         self.basis.command_digest()
    117     }
    118     /// Exact retained plan commitment.
    119     pub const fn plan_digest(&self) -> &[u8; 32] {
    120         &self.plan
    121     }
    122     /// Original logical message, distinct from seal/envelope IDs.
    123     pub const fn message_id(&self) -> MessageId {
    124         self.message
    125     }
    126     /// Original T0 transaction.
    127     pub const fn preparation_transaction_id(&self) -> TransactionId {
    128         self.preparation_transaction
    129     }
    130     /// Original T1 transaction.
    131     pub const fn plan_transaction_id(&self) -> TransactionId {
    132         self.plan_transaction
    133     }
    134     /// Original exactly-once logical installation transaction.
    135     pub const fn transaction_id(&self) -> TransactionId {
    136         self.transaction
    137     }
    138     /// Actual installation clock observation, not the original message time.
    139     pub const fn installed_at(&self) -> UnixSeconds {
    140         self.installed_at
    141     }
    142     /// Exact original capture that established the installation basis.
    143     pub const fn basis(&self) -> EvidenceReceipt {
    144         self.basis
    145     }
    146 }
    147 impl fmt::Debug for ChatInstallation {
    148     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    149         f.write_str("ChatInstallation(<redacted>)")
    150     }
    151 }
    152 
    153 /// Per-recipient pending wrapping/publication work, referencing an actual
    154 /// retained exact seal and the original plan's selected routes. This is neither
    155 /// a signed outer envelope nor a transport acknowledgement.
    156 #[derive(Clone, Copy, Eq, PartialEq)]
    157 pub struct PublicationWork {
    158     recipient: radroots_domain::PublicKey,
    159     installation: TransactionId,
    160     plan: [u8; 32],
    161     evidence: EvidenceReceipt,
    162     transaction: TransactionId,
    163     queued_at: UnixSeconds,
    164 }
    165 impl PublicationWork {
    166     /// Checks scoped data only. An actual adapter must authenticate this work
    167     /// and its evidence and atomically link it to the retained installation.
    168     pub fn from_committed_store(
    169         bound: &BoundSigningPlan,
    170         installation: ChatInstallation,
    171         evidence: EvidenceReceipt,
    172         transaction: TransactionId,
    173         queued_at: UnixSeconds,
    174     ) -> Result<Self, OperationError> {
    175         check_evidence(bound, evidence)?;
    176         if installation.workspace_id() != evidence.workspace_id()
    177             || installation.operation_id() != evidence.operation_id()
    178             || installation.command_digest() != evidence.command_digest()
    179             || installation.plan_digest() != bound.plan().digest()
    180             || installation.message_id() != bound.chat_plan()?.message_id()
    181             || installation.preparation_transaction_id() != bound.prepared().transaction_id()
    182             || installation.plan_transaction_id() != bound.transaction_id()
    183             || queued_at < installation.installed_at()
    184         {
    185             return Err(OperationError::RecoveryRequired);
    186         }
    187         Ok(Self {
    188             recipient: evidence.recipient()?,
    189             installation: installation.transaction_id(),
    190             plan: *bound.plan().digest(),
    191             evidence,
    192             transaction,
    193             queued_at,
    194         })
    195     }
    196     /// Original installation this work extends without replacing it.
    197     pub const fn installation_transaction_id(&self) -> TransactionId {
    198         self.installation
    199     }
    200     /// Original immutable plan holding the exact selected routes.
    201     pub const fn plan_digest(&self) -> &[u8; 32] {
    202         &self.plan
    203     }
    204     /// Actual private participant validated against the retained plan.
    205     pub const fn recipient(&self) -> radroots_domain::PublicKey {
    206         self.recipient
    207     }
    208     /// Exact recipient, seal and protected capture reference.
    209     pub const fn evidence(&self) -> EvidenceReceipt {
    210         self.evidence
    211     }
    212     /// Confirmed transaction that first retained this recipient's work.
    213     pub const fn transaction_id(&self) -> TransactionId {
    214         self.transaction
    215     }
    216     /// Actual original work-retention observation.
    217     pub const fn queued_at(&self) -> UnixSeconds {
    218         self.queued_at
    219     }
    220 }
    221 impl fmt::Debug for PublicationWork {
    222     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    223         f.write_str("PublicationWork(<redacted>)")
    224     }
    225 }
    226 
    227 /// Actual T2 completion or an original retained uncertainty anchor. Applications
    228 /// must reconcile unknown completion before any further effects.
    229 pub enum InstallationOutcome {
    230     /// The logical installation and eligible publication links are confirmed.
    231     Committed(Box<ChatInstallation>),
    232     /// Original public listing revision and direct-publication work, confirmed
    233     /// together by the actual authoritative transaction. No delivery is implied.
    234     ListingCommitted(Box<ListingInstallation>),
    235     /// Completion is unknown; retained claims/evidence are never discarded.
    236     Unknown(CommitAttempt),
    237 }
    238 impl fmt::Debug for InstallationOutcome {
    239     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    240         f.write_str(match self {
    241             Self::Committed(_) => "InstallationOutcome::Committed(<redacted>)",
    242             Self::ListingCommitted(_) => "InstallationOutcome::ListingCommitted(<redacted>)",
    243             Self::Unknown(_) => "InstallationOutcome::Unknown(<retained>)",
    244         })
    245     }
    246 }
    247 
    248 fn check_evidence(
    249     bound: &BoundSigningPlan,
    250     evidence: EvidenceReceipt,
    251 ) -> Result<(), OperationError> {
    252     let identity = bound.prepared().identity();
    253     let seal = bound
    254         .chat_plan()?
    255         .seals()
    256         .iter()
    257         .find(|seal| Some(seal.recipient()) == evidence.target().recipient())
    258         .ok_or(OperationError::RecoveryRequired)?;
    259     if evidence.workspace_id() != identity.workspace_id()
    260         || evidence.operation_id() != identity.operation_id()
    261         || evidence.command_digest() != identity.command_digest()
    262         || evidence.event_id() != EnvelopeEventId::from_bytes(seal.event_id())
    263     {
    264         return Err(OperationError::RecoveryRequired);
    265     }
    266     Ok(())
    267 }
    268 
    269 /// Original confirmed public listing revision, without a private message or
    270 /// participant placeholder. Data construction does not qualify a transaction.
    271 #[derive(Clone, Copy, Eq, PartialEq)]
    272 pub struct ListingInstallation {
    273     plan: [u8; 32],
    274     author: PublicKey,
    275     listing: ListingId,
    276     preparation_transaction: TransactionId,
    277     plan_transaction: TransactionId,
    278     transaction: TransactionId,
    279     installed_at: UnixSeconds,
    280     basis: EvidenceReceipt,
    281 }
    282 impl ListingInstallation {
    283     /// Checks exact original scope and public artifact identity. The backend
    284     /// must also authenticate its actual evidence, creation fence and rows.
    285     pub fn from_committed_store(
    286         bound: &BoundSigningPlan,
    287         basis: EvidenceReceipt,
    288         transaction: TransactionId,
    289         installed_at: UnixSeconds,
    290     ) -> Result<Self, OperationError> {
    291         check_public_evidence(bound, basis)?;
    292         if installed_at < bound.bound_at() {
    293             return Err(OperationError::RecoveryRequired);
    294         }
    295         let command = bound
    296             .prepared()
    297             .request()
    298             .command()
    299             .listing()
    300             .ok_or(OperationError::UnsupportedOperation)?;
    301         let event = bound
    302             .plan()
    303             .listing()
    304             .ok_or(OperationError::UnsupportedOperation)?
    305             .event();
    306         Ok(Self {
    307             plan: *bound.plan().digest(),
    308             author: event.fields().author,
    309             listing: command.input().id(),
    310             preparation_transaction: bound.prepared().transaction_id(),
    311             plan_transaction: bound.transaction_id(),
    312             transaction,
    313             installed_at,
    314             basis,
    315         })
    316     }
    317     /// Original workspace.
    318     pub const fn workspace_id(&self) -> WorkspaceId {
    319         self.basis.workspace_id()
    320     }
    321     /// Original operation.
    322     pub const fn operation_id(&self) -> OperationId {
    323         self.basis.operation_id()
    324     }
    325     /// Original complete command commitment.
    326     pub const fn command_digest(&self) -> CommandDigest {
    327         self.basis.command_digest()
    328     }
    329     /// Exact retained complete plan commitment.
    330     pub const fn plan_digest(&self) -> &[u8; 32] {
    331         &self.plan
    332     }
    333     /// Actual author of this fixed listing coordinate.
    334     pub const fn author(&self) -> PublicKey {
    335         self.author
    336     }
    337     /// Stable128-bit discriminator; parsing never proves novelty.
    338     pub const fn listing_id(&self) -> ListingId {
    339         self.listing
    340     }
    341     /// Original actual signed event ID for this immutable revision.
    342     pub const fn revision(&self) -> EnvelopeEventId {
    343         self.basis.event_id()
    344     }
    345     /// Original T0 transaction.
    346     pub const fn preparation_transaction_id(&self) -> TransactionId {
    347         self.preparation_transaction
    348     }
    349     /// Original T1 transaction.
    350     pub const fn plan_transaction_id(&self) -> TransactionId {
    351         self.plan_transaction
    352     }
    353     /// Actual original installation transaction.
    354     pub const fn transaction_id(&self) -> TransactionId {
    355         self.transaction
    356     }
    357     /// Original installation observation; it never renews an issuance window.
    358     pub const fn installed_at(&self) -> UnixSeconds {
    359         self.installed_at
    360     }
    361     /// Exact original retained evidence reference.
    362     pub const fn basis(&self) -> EvidenceReceipt {
    363         self.basis
    364     }
    365 }
    366 impl fmt::Debug for ListingInstallation {
    367     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    368         f.write_str("ListingInstallation(<redacted>)")
    369     }
    370 }
    371 /// Pending direct public work, referencing retained original signed bytes. It
    372 /// carries no private recipient, wrapping key, new signature or relay outcome.
    373 #[derive(Clone, Copy, Eq, PartialEq)]
    374 pub struct PublicPublicationWork {
    375     installation: TransactionId,
    376     plan: [u8; 32],
    377     evidence: EvidenceReceipt,
    378     transaction: TransactionId,
    379     queued_at: UnixSeconds,
    380 }
    381 impl PublicPublicationWork {
    382     /// Checks structural scope only. Concrete hosts must authenticate actual
    383     /// original evidence and link this work atomically with the installation.
    384     pub fn from_committed_store(
    385         bound: &BoundSigningPlan,
    386         installation: ListingInstallation,
    387         evidence: EvidenceReceipt,
    388         transaction: TransactionId,
    389         queued_at: UnixSeconds,
    390     ) -> Result<Self, OperationError> {
    391         check_public_evidence(bound, evidence)?;
    392         let checked = ListingInstallation::from_committed_store(
    393             bound,
    394             installation.basis(),
    395             installation.transaction_id(),
    396             installation.installed_at(),
    397         )?;
    398         if checked != installation
    399             || installation.basis() != evidence
    400             || queued_at < installation.installed_at()
    401         {
    402             return Err(OperationError::RecoveryRequired);
    403         }
    404         Ok(Self {
    405             installation: installation.transaction_id(),
    406             plan: *bound.plan().digest(),
    407             evidence,
    408             transaction,
    409             queued_at,
    410         })
    411     }
    412     /// Original installation transaction.
    413     pub const fn installation_transaction_id(&self) -> TransactionId {
    414         self.installation
    415     }
    416     /// Original complete plan with its captured target descriptors.
    417     pub const fn plan_digest(&self) -> &[u8; 32] {
    418         &self.plan
    419     }
    420     /// Original exact public signed artifact reference.
    421     pub const fn evidence(&self) -> EvidenceReceipt {
    422         self.evidence
    423     }
    424     /// Actual first work-retention transaction.
    425     pub const fn transaction_id(&self) -> TransactionId {
    426         self.transaction
    427     }
    428     /// Original work observation, not an issuance or delivery deadline.
    429     pub const fn queued_at(&self) -> UnixSeconds {
    430         self.queued_at
    431     }
    432 }
    433 impl fmt::Debug for PublicPublicationWork {
    434     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    435         f.write_str("PublicPublicationWork(<redacted>)")
    436     }
    437 }
    438 fn check_public_evidence(
    439     bound: &BoundSigningPlan,
    440     evidence: EvidenceReceipt,
    441 ) -> Result<(), OperationError> {
    442     let identity = bound.prepared().identity();
    443     let public = bound
    444         .plan()
    445         .listing()
    446         .ok_or(OperationError::UnsupportedOperation)?;
    447     if evidence.target() != SigningTarget::PublicEvent
    448         || evidence.workspace_id() != identity.workspace_id()
    449         || evidence.operation_id() != identity.operation_id()
    450         || evidence.command_digest() != identity.command_digest()
    451         || evidence.event_id().as_bytes() != public.event().event_id()
    452     {
    453         return Err(OperationError::RecoveryRequired);
    454     }
    455     Ok(())
    456 }