commerce.rs (11471B)
1 //! Shared acceptance orchestration and typed host transaction boundaries. 2 //! Host reports are a qualification boundary, never caller-created authority. 3 use super::{HostBound, HostFuture}; 4 use alloc::boxed::Box; 5 use core::fmt; 6 use radroots_domain::{CommandDigest, OperationId, OrderId, PublicKey, RecordId, SigningAttemptId}; 7 use radroots_protocol::commerce::CommerceSigningPlan; 8 use radroots_signing::{ 9 commerce::VerifiedCommerceSigningPlan, 10 issuance::{ExactRecoveryRequest, IntentBinding}, 11 provider::ProviderCall, 12 request::CancellationSignal, 13 }; 14 use radroots_storage::{ 15 command::{CommitAttempt, OperationError}, 16 inventory::{ 17 InventoryCheckpointRef, StockAcceptanceReceipt, StockDeliverySummary, StockEvidenceReceipt, 18 StockEvidenceSource, 19 }, 20 workspace::{AttachmentProof, WorkspaceBinding}, 21 }; 22 23 #[path = "commerce_run.rs"] 24 mod run; 25 pub(crate) use run::observe; 26 pub(in crate::session) use run::rewrap_status; 27 28 /// Original operation selectors and independently retained minimum; no authority. 29 #[derive(Clone)] 30 pub struct AcceptanceSelection { 31 /// Exact selected authenticated attachment descriptor. 32 pub binding: WorkspaceBinding, 33 /// Independently retained protected inventory minimum. 34 pub minimum: InventoryCheckpointRef, 35 /// Original full-width operation identity. 36 pub operation: OperationId, 37 /// Original captured command commitment. 38 pub digest: CommandDigest, 39 } 40 41 /// Original durable claim metadata, without a first-dispatch or replay permit. 42 #[derive(Clone, Copy, Eq, PartialEq)] 43 pub struct AcceptanceClaim { 44 /// Protected store claim identity. 45 pub id: SigningAttemptId, 46 /// Exact original event, recipient, command and deadline commitment. 47 pub binding: IntentBinding, 48 } 49 impl fmt::Debug for AcceptanceClaim { 50 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 51 f.write_str("AcceptanceClaim(<redacted>)") 52 } 53 } 54 55 /// One recipient's independent actual retained signing observations. 56 #[derive(Clone, Copy, Eq, PartialEq)] 57 pub struct AcceptanceRecipient { 58 /// Exact original participant. 59 pub recipient: PublicKey, 60 /// Original claim, if durably observed; never permission to sign again. 61 pub claim: Option<AcceptanceClaim>, 62 /// First authenticated original encoding, if durably observed. 63 pub evidence: Option<StockEvidenceReceipt>, 64 /// Authenticated fact about the original invocation, independent of later S. 65 pub original_unissued: Option<AcceptanceUnissuedReceipt>, 66 } 67 68 /// Actual initial agreement installation, independent of self-copy and delivery. 69 #[derive(Clone, Copy, Eq, PartialEq)] 70 pub struct InstalledAcceptance { 71 /// Original confirmed installation transaction. 72 pub attempt: CommitAttempt, 73 /// Installed order identity. 74 pub order: OrderId, 75 /// Installed original commitment record. 76 pub record: RecordId, 77 /// Confirmed protected checkpoint. 78 pub checkpoint: InventoryCheckpointRef, 79 } 80 impl fmt::Debug for InstalledAcceptance { 81 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 82 f.write_str("InstalledAcceptance(<redacted>)") 83 } 84 } 85 86 /// Read-only authenticated native/browser snapshot retained by its target host. 87 /// Implementations expose original facts, not fresh allocation or signing policy. 88 pub trait AcceptanceSnapshot: HostBound { 89 /// Actual original T0 and its unchanged rumor/window. 90 fn preparation(&self) -> &StockAcceptanceReceipt; 91 /// Complete original T1, if present. 92 fn plan(&self) -> Option<&CommerceSigningPlan>; 93 /// Current authenticated protected checkpoint. 94 fn checkpoint(&self) -> InventoryCheckpointRef; 95 /// Complete original bilateral set, in canonical participant order. 96 fn recipients(&self) -> [AcceptanceRecipient; 2]; 97 /// Actual matching installation, if present. 98 fn installation(&self) -> Option<InstalledAcceptance>; 99 /// Whether an actual original proven-unissued abort was observed. 100 fn aborted(&self) -> bool; 101 /// Coherent bounded original per-recipient delivery progress, in the same 102 /// canonical order as recipients. None means unsupported by this catalog. 103 fn delivery(&self) -> Option<&[StockDeliverySummary; 2]>; 104 } 105 106 #[path = "commerce_dispatch.rs"] 107 mod dispatch; 108 pub use self::dispatch::{ 109 AcceptanceDispatch, AcceptanceDispatchOutcome, AcceptanceUnissued, AcceptanceUnissuedOutcome, 110 AcceptanceUnissuedReceipt, 111 }; 112 113 /// Actual host completion of T1; an unknown commit must be queried, not repeated 114 /// as a new preparation or signature. 115 pub enum AcceptancePlanOutcome { 116 /// The exact original complete plan is durably bound. 117 Bound(CommitAttempt), 118 /// Original transaction completion remains uncertain. 119 Unknown(CommitAttempt), 120 } 121 /// Per-recipient host claim results, without optimistic existing-claim replay. 122 pub enum AcceptanceClaimOutcome { 123 /// Fresh confirmed single-use first-dispatch permit. 124 Fresh(Box<dyn AcceptanceDispatch>), 125 /// Original claim exists and provides no fresh permit. 126 Existing(AcceptanceClaim), 127 /// Original claim transaction completion remains uncertain. 128 Unknown(CommitAttempt), 129 } 130 /// Actual initial T2 result; a report never claims wrapping or relay delivery. 131 pub enum AcceptanceInstallationOutcome { 132 /// Original matching agreement and recipient work are installed. 133 Installed(Box<InstalledAcceptance>), 134 /// Original installation transaction completion remains uncertain. 135 Unknown(CommitAttempt), 136 } 137 138 /// Mechanical target transactions for the shared concrete acceptance algorithm. 139 /// Implementations enforce protected identity, CAS, consent and exact transaction 140 /// completion. They do not choose business inputs, invoke signers or run a 141 /// replacement application workflow. The ordinary facade selects the same owner 142 /// as its InventoryStore; custom hosts require their own executed qualification. 143 pub trait AcceptanceStore: HostBound { 144 /// Reads the exact retained signed seal under current recovery access. 145 /// This cannot create signing material or confer dispatch permission. 146 fn signing_evidence<'a>( 147 &'a self, 148 _selection: AcceptanceSelection, 149 _receipt: StockEvidenceReceipt, 150 _proof: &'a AttachmentProof, 151 ) -> HostFuture<'a, Result<Option<StockEvidenceSource>, OperationError>> { 152 Box::pin(async { Err(OperationError::UnsupportedOperation) }) 153 } 154 /// Reads original T0/T1, independent recipient S and initial T2 coherently. 155 fn snapshot<'a>( 156 &'a self, 157 selection: AcceptanceSelection, 158 proof: &'a AttachmentProof, 159 ) -> HostFuture<'a, Result<Box<dyn AcceptanceSnapshot>, OperationError>>; 160 /// Binds a shared cryptographically qualified exact plan to original T0. 161 fn bind<'a>( 162 &'a self, 163 selection: AcceptanceSelection, 164 plan: VerifiedCommerceSigningPlan, 165 proof: &'a AttachmentProof, 166 ) -> HostFuture<'a, Result<AcceptancePlanOutcome, OperationError>>; 167 /// Commits and observes the exact original recipient's first claim. 168 fn claim<'a>( 169 &'a self, 170 selection: AcceptanceSelection, 171 recipient: PublicKey, 172 proof: &'a AttachmentProof, 173 ) -> HostFuture<'a, Result<AcceptanceClaimOutcome, OperationError>>; 174 /// Explicit original exact replay authorization; unsupported hosts refuse. 175 /// Refusal proves nothing about the original invocation's issuance. 176 fn exact_replay<'a>( 177 &'a self, 178 _selection: AcceptanceSelection, 179 _recipient: PublicKey, 180 _call: ProviderCall, 181 _proof: &'a AttachmentProof, 182 ) -> HostFuture<'a, Result<(ExactRecoveryRequest, AcceptanceClaim), OperationError>> { 183 Box::pin(async { Err(OperationError::UnsupportedOperation) }) 184 } 185 /// Installs only the original agreement backed by actually retained peer S. 186 fn install<'a>( 187 &'a self, 188 selection: AcceptanceSelection, 189 proof: &'a AttachmentProof, 190 ) -> HostFuture<'a, Result<AcceptanceInstallationOutcome, OperationError>>; 191 } 192 193 /// Owned original operation facts. No wait, signature or relay outcome is 194 /// collapsed into business success; this report cannot dispatch or release stock. 195 pub struct AcceptanceStatus { 196 pub(crate) attempt: CommitAttempt, 197 pub(crate) record: RecordId, 198 pub(crate) checkpoint: InventoryCheckpointRef, 199 pub(crate) recipients: [AcceptanceRecipient; 2], 200 pub(crate) plan_bound: bool, 201 pub(crate) installation: Option<InstalledAcceptance>, 202 pub(crate) aborted: bool, 203 pub(crate) delivery: Option<Box<[StockDeliverySummary; 2]>>, 204 } 205 impl AcceptanceStatus { 206 /// Original per-recipient delivery progress, independently of installation 207 /// or buyer receipt. Absence means this catalog does not support stock D. 208 pub fn delivery(&self) -> Option<&[StockDeliverySummary; 2]> { 209 self.delivery.as_deref() 210 } 211 /// Original confirmed T0 anchor. 212 pub const fn attempt(&self) -> CommitAttempt { 213 self.attempt 214 } 215 /// Original immutable commitment record. 216 pub const fn record_id(&self) -> RecordId { 217 self.record 218 } 219 /// Current authenticated observation checkpoint. 220 pub const fn checkpoint(&self) -> InventoryCheckpointRef { 221 self.checkpoint 222 } 223 /// Independent peer/self original signing observations. 224 pub const fn recipients(&self) -> &[AcceptanceRecipient; 2] { 225 &self.recipients 226 } 227 /// Whether complete original T1 was actually observed. 228 pub const fn plan_bound(&self) -> bool { 229 self.plan_bound 230 } 231 /// Actual original T2, independently of self-copy or relay delivery. 232 pub const fn installation(&self) -> Option<InstalledAcceptance> { 233 self.installation 234 } 235 /// Actual original abort observation, never inferred from absent evidence. 236 pub const fn aborted(&self) -> bool { 237 self.aborted 238 } 239 } 240 impl fmt::Debug for AcceptanceStatus { 241 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 242 f.write_str("AcceptanceStatus(<redacted>)") 243 } 244 } 245 246 /// Separate current-access observations of one explicitly requested rewrap. 247 /// A missing outer is an unknown wrapping outcome, never proof of nonissuance 248 /// or permission to regenerate. Delivery carries its own authenticated read 249 /// checkpoint; this report does not claim an atomic combined absence snapshot. 250 #[derive(Clone)] 251 pub struct AcceptanceRewrapStatus { 252 id: OperationId, 253 recipient: PublicKey, 254 state: Option<radroots_storage::inventory::StockRewrapState>, 255 delivery: Option<StockDeliverySummary>, 256 } 257 impl AcceptanceRewrapStatus { 258 /// Explicit request identity, distinct from the original business command. 259 pub const fn rewrap_id(&self) -> OperationId { 260 self.id 261 } 262 /// Recipient whose original evidence and additional outer were selected. 263 pub const fn recipient(&self) -> PublicKey { 264 self.recipient 265 } 266 /// Observed admission and optional captured outer; absence grants no work. 267 pub const fn state(&self) -> Option<radroots_storage::inventory::StockRewrapState> { 268 self.state 269 } 270 /// Independent current delivery observation for the exact captured outer. 271 pub const fn delivery(&self) -> Option<&StockDeliverySummary> { 272 self.delivery.as_ref() 273 } 274 } 275 impl fmt::Debug for AcceptanceRewrapStatus { 276 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { 277 f.write_str("AcceptanceRewrapStatus(<redacted>)") 278 } 279 }