lib

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

exact_recovery.rs (5232B)


      1 //! Exact-intent recovery data. Refusal of a recovery call proves nothing about
      2 //! the original invocation and can never authorize a stock release.
      3 use super::{
      4     IntentBinding, OutcomeKind, RejectedArtifact, SignedArtifact, SigningIntent, SigningOutcome,
      5 };
      6 use crate::provider::{ProviderCall, ProviderError};
      7 
      8 /// Support actually implemented by a provider, requiring independent adapter
      9 /// qualification. A declaration alone is never permission to request an intent.
     10 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
     11 #[non_exhaustive]
     12 pub enum ExactRecoveryCapability {
     13     /// No qualified original-intent recovery method is available.
     14     Unavailable,
     15     /// A local custody owner can recompute only the complete original preimage
     16     /// while its original first-issuance window is still open.
     17     LocalExactReplay,
     18 }
     19 
     20 /// Original immutable intent and a distinct bounded recovery-call budget.
     21 /// Construction renews no original first-issuance deadline or business consent.
     22 pub struct ExactRecoveryRequest {
     23     original: SigningIntent,
     24     call: ProviderCall,
     25 }
     26 impl ExactRecoveryRequest {
     27     /// Checks identity and representation only. The executor must authenticate
     28     /// current original-operation recovery access and the adapter's support.
     29     pub fn new(original: SigningIntent, call: ProviderCall) -> Result<Self, ProviderError> {
     30         if original.author() != call.identity() {
     31             return Err(ProviderError::IdentityChanged);
     32         }
     33         if call.deadline_unix_ms().get() > super::MAX_OBSERVATION_UNIX_MS {
     34             return Err(ProviderError::InvalidInput);
     35         }
     36         Ok(Self { original, call })
     37     }
     38     /// Borrows the exact original fields, event ID, deadline and intent binding.
     39     pub const fn original(&self) -> &SigningIntent {
     40         &self.original
     41     }
     42     /// Borrows only this recovery invocation's identity/deadline/cancellation.
     43     pub const fn call(&self) -> &ProviderCall {
     44         &self.call
     45     }
     46     /// Returns the immutable original intent binding, never a new request ID.
     47     pub const fn binding(&self) -> IntentBinding {
     48         self.original.binding()
     49     }
     50 }
     51 impl core::fmt::Debug for ExactRecoveryRequest {
     52     fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
     53         f.write_str("ExactRecoveryRequest(<redacted>)")
     54     }
     55 }
     56 
     57 /// Recovery observations do not include a proven-unissued variant.
     58 #[derive(Debug)]
     59 #[non_exhaustive]
     60 pub enum ExactRecoveryKind {
     61     /// Exact authenticated original-intent bytes are now obtained.
     62     Obtained(SignedArtifact),
     63     /// The original issuance remains unresolved, including unsupported methods,
     64     /// current refusal, cancellation and failure of this recovery invocation.
     65     Indeterminate(ProviderError),
     66     /// Untrusted output is neither success nor proof of original nonissuance.
     67     Rejected(RejectedArtifact),
     68 }
     69 
     70 /// A bound recovery observation, distinct from durable capture or business state.
     71 #[derive(Debug)]
     72 pub struct ExactRecoveryOutcome {
     73     binding: IntentBinding,
     74     kind: ExactRecoveryKind,
     75 }
     76 impl ExactRecoveryOutcome {
     77     /// Retains uncertainty about the original intent without dispatching work.
     78     pub const fn indeterminate(binding: IntentBinding, reason: ProviderError) -> Self {
     79         Self {
     80             binding,
     81             kind: ExactRecoveryKind::Indeterminate(reason),
     82         }
     83     }
     84     /// Converts actual exact-field verification output. A pre-dispatch refusal
     85     /// for a recovery invocation cannot prove the original was unissued.
     86     pub fn from_recovery_verification(outcome: SigningOutcome) -> Self {
     87         let (binding, kind) = outcome.into_parts();
     88         let kind = match kind {
     89             OutcomeKind::Obtained(value) => ExactRecoveryKind::Obtained(value),
     90             OutcomeKind::Rejected(value) => ExactRecoveryKind::Rejected(value),
     91             OutcomeKind::Unknown(reason) | OutcomeKind::NotDispatched(reason) => {
     92                 ExactRecoveryKind::Indeterminate(reason)
     93             }
     94         };
     95         Self { binding, kind }
     96     }
     97     /// Enforces the original callback identity using the issuance verifier's
     98     /// bounded forensic policy. A foreign result grants no success or release.
     99     pub fn enforce_binding(self, expected: IntentBinding) -> Self {
    100         let kind = match self.kind {
    101             ExactRecoveryKind::Obtained(value) => OutcomeKind::Obtained(value),
    102             ExactRecoveryKind::Rejected(value) => OutcomeKind::Rejected(value),
    103             ExactRecoveryKind::Indeterminate(reason) => OutcomeKind::Unknown(reason),
    104         };
    105         Self::from_recovery_verification(
    106             SigningOutcome {
    107                 binding: self.binding,
    108                 kind,
    109             }
    110             .enforce_binding(expected),
    111         )
    112     }
    113     /// Returns the original operation/intent binding.
    114     pub const fn binding(&self) -> IntentBinding {
    115         self.binding
    116     }
    117     /// Borrows the actual observation, never permission to release or reissue.
    118     pub const fn kind(&self) -> &ExactRecoveryKind {
    119         &self.kind
    120     }
    121     /// Transfers obtained original bytes to their durable evidence owner.
    122     pub fn into_parts(self) -> (IntentBinding, ExactRecoveryKind) {
    123         (self.binding, self.kind)
    124     }
    125 }