lib

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

commit 14f1a9e64e4f8173004f8c95605ffeffe89a5cf7
parent a7d49cd79561188b138a0353abdd317802ae6135
Author: triesap <tyson@radroots.org>
Date:   Mon, 26 Oct 2026 05:56:01 +0000

storage: expose original stock evidence capture through shared ports

- Own bounded protected evidence inputs and append reports in Storage.
- Verify exact original claims through the existing native worker.
- Preserve late capture, original bytes and uncertain commit semantics.
- Qualify actual shared capture, refusal, recovery, portability and APIs.

Diffstat:
Mcontracts/api_baselines/radroots_storage.txt | 27+++++++++++++++++++++++++++
Mcontracts/api_baselines/radroots_storage_sqlite.txt | 20++++++--------------
Mcontracts/architecture/decisions/shared_sdk_refactor.v1.json | 5+++++
Mcrates/storage/README.md | 11+++++++++++
Mcrates/storage/src/inventory.rs | 12++++++++++++
Acrates/storage/src/inventory/evidence.rs | 152+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcrates/storage/tests/workspace.rs | 3+++
Acrates/storage/tests/workspace/inventory_evidence.rs | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcrates/storage_sqlite/README.md | 11+++++++++++
Mcrates/storage_sqlite/src/workspace/mod.rs | 16++++++++--------
Mcrates/storage_sqlite/src/workspace/stock.rs | 23++++++++++++++++++++---
Mcrates/storage_sqlite/src/workspace/stock/issuance.rs | 9++++-----
Mcrates/storage_sqlite/src/workspace/stock/issuance/evidence.rs | 157++++++++++++++++++++++++++++++++-----------------------------------------------
Mcrates/storage_sqlite/src/workspace/stock/issuance/evidence/codec.rs | 22+++++++++++-----------
Mcrates/storage_sqlite/src/workspace/stock/public_source/evidence_tests.rs | 97++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mcrates/storage_sqlite/src/workspace/stock/public_source/exact_recovery_tests.rs | 22+++++++++++++++++++++-
Mcrates/storage_sqlite/src/workspace/worker.rs | 4++--
Mtools/xtask/src/architecture/decision_package.rs | 23+++++++++++++++++++++++
18 files changed, 565 insertions(+), 139 deletions(-)

diff --git a/contracts/api_baselines/radroots_storage.txt b/contracts/api_baselines/radroots_storage.txt @@ -1376,6 +1376,9 @@ pub enum radroots_storage::inventory::StockAcceptanceOutcome pub radroots_storage::inventory::StockAcceptanceOutcome::Aborted(alloc::boxed::Box<radroots_storage::inventory::StockAbortReceipt>) pub radroots_storage::inventory::StockAcceptanceOutcome::Prepared(alloc::boxed::Box<radroots_storage::inventory::StockAcceptanceReceipt>) pub radroots_storage::inventory::StockAcceptanceOutcome::Unknown(radroots_storage::command::CommitAttempt) +pub enum radroots_storage::inventory::StockEvidenceOutcome +pub radroots_storage::inventory::StockEvidenceOutcome::Committed(radroots_storage::inventory::StockEvidenceReceipt) +pub radroots_storage::inventory::StockEvidenceOutcome::Unknown(radroots_storage::command::CommitAttempt) pub struct radroots_storage::inventory::InventoryCheckpointRef impl radroots_storage::inventory::InventoryCheckpointRef pub const fn radroots_storage::inventory::InventoryCheckpointRef::authority(self) -> radroots_domain::context::AuthorityRef @@ -1455,8 +1458,32 @@ pub const fn radroots_storage::inventory::StockAcceptanceRequest::minimum_checkp pub const fn radroots_storage::inventory::StockAcceptanceRequest::source_checkpoint(&self) -> radroots_storage::workspace::seller_stock::StockSourceCheckpointRef impl core::fmt::Debug for radroots_storage::inventory::StockAcceptanceRequest pub fn radroots_storage::inventory::StockAcceptanceRequest::fmt(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result +pub struct radroots_storage::inventory::StockEvidenceReceipt +impl radroots_storage::inventory::StockEvidenceReceipt +pub const fn radroots_storage::inventory::StockEvidenceReceipt::attempt(&self) -> radroots_storage::command::CommitAttempt +pub const fn radroots_storage::inventory::StockEvidenceReceipt::digest(&self) -> &[u8; 32] +pub fn radroots_storage::inventory::StockEvidenceReceipt::from_committed_store(radroots_storage::command::CommitAttempt, radroots_domain::identifier::SigningAttemptId, radroots_identity::key::PublicKey, [u8; 32], core::option::Option<core::num::nonzero::NonZeroU64>) -> core::result::Result<Self, radroots_storage::command::OperationError> +pub const fn radroots_storage::inventory::StockEvidenceReceipt::observed_at_unix_ms(&self) -> core::option::Option<core::num::nonzero::NonZeroU64> +pub const fn radroots_storage::inventory::StockEvidenceReceipt::recipient(&self) -> radroots_identity::key::PublicKey +pub const fn radroots_storage::inventory::StockEvidenceReceipt::signing_attempt_id(&self) -> radroots_domain::identifier::SigningAttemptId +pub struct radroots_storage::inventory::StockEvidenceRequest +impl radroots_storage::inventory::StockEvidenceRequest +pub fn radroots_storage::inventory::StockEvidenceRequest::attempt(&self) -> radroots_storage::command::CommitAttempt +pub const fn radroots_storage::inventory::StockEvidenceRequest::binding(&self) -> &radroots_storage::workspace::WorkspaceBinding +pub const fn radroots_storage::inventory::StockEvidenceRequest::command_digest(&self) -> radroots_domain::identifier::CommandDigest +pub fn radroots_storage::inventory::StockEvidenceRequest::from_obtained_wire(radroots_storage::workspace::WorkspaceBinding, radroots_domain::identifier::OperationId, radroots_domain::identifier::CommandDigest, radroots_domain::identifier::SigningAttemptId, radroots_identity::key::PublicKey, [u8; 32], &str, core::option::Option<core::num::nonzero::NonZeroU64>) -> core::result::Result<Self, radroots_storage::command::OperationError> +pub const fn radroots_storage::inventory::StockEvidenceRequest::intent_digest(&self) -> &[u8; 32] +pub const fn radroots_storage::inventory::StockEvidenceRequest::observed_at_unix_ms(&self) -> core::option::Option<core::num::nonzero::NonZeroU64> +pub const fn radroots_storage::inventory::StockEvidenceRequest::operation_id(&self) -> radroots_domain::identifier::OperationId +pub const fn radroots_storage::inventory::StockEvidenceRequest::recipient(&self) -> radroots_identity::key::PublicKey +pub fn radroots_storage::inventory::StockEvidenceRequest::retained_copy(&self) -> Self +pub const fn radroots_storage::inventory::StockEvidenceRequest::signing_attempt_id(&self) -> radroots_domain::identifier::SigningAttemptId +pub fn radroots_storage::inventory::StockEvidenceRequest::with_json<T>(&self, impl core::ops::function::FnOnce(&str) -> T) -> T +impl core::fmt::Debug for radroots_storage::inventory::StockEvidenceRequest +pub fn radroots_storage::inventory::StockEvidenceRequest::fmt(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result pub trait radroots_storage::inventory::InventoryStore: radroots_storage::workspace::WorkspaceStore pub fn radroots_storage::inventory::InventoryStore::abort_proven_unissued(&self, radroots_storage::inventory::StockAbortRequest, radroots_storage::workspace::AttachmentProof) -> radroots_transport::source::BoxFuture<'_, core::result::Result<radroots_storage::inventory::StockAbortOutcome, radroots_storage::command::OperationError>> +pub fn radroots_storage::inventory::InventoryStore::capture_stock_evidence<'a>(&'a self, &'a radroots_storage::inventory::StockEvidenceRequest, &'a radroots_storage::workspace::AttachmentProof) -> radroots_transport::source::BoxFuture<'a, core::result::Result<radroots_storage::inventory::StockEvidenceOutcome, radroots_storage::command::OperationError>> pub fn radroots_storage::inventory::InventoryStore::execute_inventory(&self, radroots_storage::inventory::InventoryRequest, radroots_storage::workspace::AttachmentProof) -> radroots_transport::source::BoxFuture<'_, core::result::Result<radroots_storage::inventory::InventoryOutcome, radroots_storage::command::OperationError>> pub fn radroots_storage::inventory::InventoryStore::inventory_operation(&self, radroots_storage::workspace::WorkspaceBinding, radroots_storage::inventory::InventoryCheckpointRef, radroots_domain::identifier::OperationId, core::option::Option<radroots_domain::identifier::CommandDigest>, radroots_storage::workspace::AttachmentProof) -> radroots_transport::source::BoxFuture<'_, core::result::Result<core::option::Option<radroots_storage::inventory::InventoryReceipt>, radroots_storage::command::OperationError>> pub fn radroots_storage::inventory::InventoryStore::option_mapping(&self, radroots_storage::workspace::WorkspaceBinding, radroots_storage::inventory::InventoryCheckpointRef, radroots_domain::stock::mapping::OptionMappingKey, radroots_storage::workspace::AttachmentProof) -> radroots_transport::source::BoxFuture<'_, core::result::Result<core::option::Option<radroots_domain::stock::mapping::OptionPoolMapping>, radroots_storage::command::OperationError>> diff --git a/contracts/api_baselines/radroots_storage_sqlite.txt b/contracts/api_baselines/radroots_storage_sqlite.txt @@ -382,9 +382,6 @@ pub radroots_storage_sqlite::workspace::StockConsentOutcome::Unknown::command_op pub radroots_storage_sqlite::workspace::StockConsentOutcome::Unknown::control_operation: radroots_domain::identifier::OperationId pub radroots_storage_sqlite::workspace::StockConsentOutcome::Unknown::subject: radroots_domain::identifier::GrantId pub radroots_storage_sqlite::workspace::StockConsentOutcome::Unknown::transaction: radroots_domain::identifier::TransactionId -pub enum radroots_storage_sqlite::workspace::StockEvidenceOutcome -pub radroots_storage_sqlite::workspace::StockEvidenceOutcome::Committed(radroots_storage_sqlite::workspace::StockEvidenceReceipt) -pub radroots_storage_sqlite::workspace::StockEvidenceOutcome::Unknown(radroots_storage::command::CommitAttempt) pub enum radroots_storage_sqlite::workspace::StockGrantOutcome pub radroots_storage_sqlite::workspace::StockGrantOutcome::Committed(radroots_storage_sqlite::workspace::StockGrantReceipt) pub radroots_storage_sqlite::workspace::StockGrantOutcome::Unknown(radroots_domain::identifier::TransactionId) @@ -429,7 +426,7 @@ impl radroots_storage_sqlite::workspace::NativeWorkspace pub async fn radroots_storage_sqlite::workspace::NativeWorkspace::bind_stock_signing_intents(&self, radroots_storage_sqlite::workspace::StockSigningPlanRequest, &radroots_storage::workspace::AttachmentProof) -> core::result::Result<radroots_storage_sqlite::workspace::StockSigningPlanOutcome, radroots_storage::command::OperationError> pub async fn radroots_storage_sqlite::workspace::NativeWorkspace::stock_signing_plan(&self, radroots_storage::workspace::WorkspaceBinding, radroots_storage::inventory::InventoryCheckpointRef, radroots_domain::identifier::OperationId, radroots_domain::identifier::CommandDigest, &radroots_storage::workspace::AttachmentProof) -> core::result::Result<core::option::Option<radroots_storage_sqlite::workspace::StockBoundSigningPlan>, radroots_storage::command::OperationError> impl radroots_storage_sqlite::workspace::NativeWorkspace -pub async fn radroots_storage_sqlite::workspace::NativeWorkspace::capture_stock_signing_evidence(&self, &radroots_storage_sqlite::workspace::StockEvidenceCapture, &radroots_storage::workspace::AttachmentProof) -> core::result::Result<radroots_storage_sqlite::workspace::StockEvidenceOutcome, radroots_storage::command::OperationError> +pub async fn radroots_storage_sqlite::workspace::NativeWorkspace::capture_stock_signing_evidence(&self, &radroots_storage_sqlite::workspace::StockEvidenceCapture, &radroots_storage::workspace::AttachmentProof) -> core::result::Result<radroots_storage::inventory::evidence::StockEvidenceOutcome, radroots_storage::command::OperationError> pub async fn radroots_storage_sqlite::workspace::NativeWorkspace::stock_signing_evidence(&self, radroots_storage_sqlite::workspace::StockClaimRequest, [u8; 32], &radroots_storage::workspace::AttachmentProof) -> core::result::Result<core::option::Option<radroots_storage_sqlite::workspace::StockCapturedEvidence>, radroots_storage::command::OperationError> pub async fn radroots_storage_sqlite::workspace::NativeWorkspace::stock_signing_evidence_page(&self, radroots_storage_sqlite::workspace::StockClaimRequest, core::option::Option<radroots_domain::context::Sequence>, &radroots_storage::workspace::AttachmentProof) -> core::result::Result<radroots_storage_sqlite::workspace::StockEvidencePage, radroots_storage::command::OperationError> impl radroots_storage_sqlite::workspace::NativeWorkspace @@ -481,6 +478,7 @@ pub fn radroots_storage_sqlite::workspace::NativeWorkspace::signing_attempt(&sel pub fn radroots_storage_sqlite::workspace::NativeWorkspace::signing_plan(&self, radroots_storage::workspace::WorkspaceBinding, radroots_domain::identifier::OperationId, radroots_domain::identifier::CommandDigest, radroots_storage::workspace::AttachmentProof) -> radroots_transport::source::BoxFuture<'_, core::result::Result<core::option::Option<radroots_storage::command::BoundSigningPlan>, radroots_storage::command::OperationError>> impl radroots_storage::inventory::InventoryStore for radroots_storage_sqlite::workspace::NativeWorkspace pub fn radroots_storage_sqlite::workspace::NativeWorkspace::abort_proven_unissued(&self, radroots_storage::inventory::abort::StockAbortRequest, radroots_storage::workspace::AttachmentProof) -> radroots_transport::source::BoxFuture<'_, core::result::Result<radroots_storage::inventory::abort::StockAbortOutcome, radroots_storage::command::OperationError>> +pub fn radroots_storage_sqlite::workspace::NativeWorkspace::capture_stock_evidence<'a>(&'a self, &'a radroots_storage::inventory::evidence::StockEvidenceRequest, &'a radroots_storage::workspace::AttachmentProof) -> radroots_transport::source::BoxFuture<'a, core::result::Result<radroots_storage::inventory::evidence::StockEvidenceOutcome, radroots_storage::command::OperationError>> pub fn radroots_storage_sqlite::workspace::NativeWorkspace::execute_inventory(&self, radroots_storage::inventory::InventoryRequest, radroots_storage::workspace::AttachmentProof) -> radroots_transport::source::BoxFuture<'_, core::result::Result<radroots_storage::inventory::InventoryOutcome, radroots_storage::command::OperationError>> pub fn radroots_storage_sqlite::workspace::NativeWorkspace::inventory_operation(&self, radroots_storage::workspace::WorkspaceBinding, radroots_storage::inventory::InventoryCheckpointRef, radroots_domain::identifier::OperationId, core::option::Option<radroots_domain::identifier::CommandDigest>, radroots_storage::workspace::AttachmentProof) -> radroots_transport::source::BoxFuture<'_, core::result::Result<core::option::Option<radroots_storage::inventory::InventoryReceipt>, radroots_storage::command::OperationError>> pub fn radroots_storage_sqlite::workspace::NativeWorkspace::option_mapping(&self, radroots_storage::workspace::WorkspaceBinding, radroots_storage::inventory::InventoryCheckpointRef, radroots_domain::stock::mapping::OptionMappingKey, radroots_storage::workspace::AttachmentProof) -> radroots_transport::source::BoxFuture<'_, core::result::Result<core::option::Option<radroots_domain::stock::mapping::OptionPoolMapping>, radroots_storage::command::OperationError>> @@ -510,7 +508,7 @@ impl core::fmt::Debug for radroots_storage_sqlite::workspace::StockBoundSigningP pub fn radroots_storage_sqlite::workspace::StockBoundSigningPlan::fmt(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result pub struct radroots_storage_sqlite::workspace::StockCapturedEvidence impl radroots_storage_sqlite::workspace::StockCapturedEvidence -pub const fn radroots_storage_sqlite::workspace::StockCapturedEvidence::receipt(&self) -> radroots_storage_sqlite::workspace::StockEvidenceReceipt +pub const fn radroots_storage_sqlite::workspace::StockCapturedEvidence::receipt(&self) -> radroots_storage::inventory::evidence::StockEvidenceReceipt pub fn radroots_storage_sqlite::workspace::StockCapturedEvidence::with_json<T>(&self, impl core::ops::function::FnOnce(&str) -> T) -> T impl core::fmt::Debug for radroots_storage_sqlite::workspace::StockCapturedEvidence pub fn radroots_storage_sqlite::workspace::StockCapturedEvidence::fmt(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result @@ -565,6 +563,7 @@ impl core::fmt::Debug for radroots_storage_sqlite::workspace::StockEnrollment pub fn radroots_storage_sqlite::workspace::StockEnrollment::fmt(&self, &mut core::fmt::Formatter<'_>) -> core::fmt::Result pub struct radroots_storage_sqlite::workspace::StockEvidenceCapture impl radroots_storage_sqlite::workspace::StockEvidenceCapture +pub fn radroots_storage_sqlite::workspace::StockEvidenceCapture::into_request(self) -> radroots_storage::inventory::evidence::StockEvidenceRequest pub const fn radroots_storage_sqlite::workspace::StockEvidenceCapture::observed_at_unix_ms(&self) -> core::option::Option<core::num::nonzero::NonZeroU64> pub fn radroots_storage_sqlite::workspace::StockEvidenceCapture::verify(radroots_storage::workspace::WorkspaceBinding, &radroots_storage_sqlite::workspace::StockSigningAttempt, &str, core::option::Option<core::num::nonzero::NonZeroU64>) -> core::result::Result<Self, radroots_storage::command::OperationError> pub fn radroots_storage_sqlite::workspace::StockEvidenceCapture::with_json<T>(&self, impl core::ops::function::FnOnce(&str) -> T) -> T @@ -573,14 +572,7 @@ pub fn radroots_storage_sqlite::workspace::StockEvidenceCapture::fmt(&self, &mut pub struct radroots_storage_sqlite::workspace::StockEvidencePage impl radroots_storage_sqlite::workspace::StockEvidencePage pub const fn radroots_storage_sqlite::workspace::StockEvidencePage::next(&self) -> core::option::Option<radroots_domain::context::Sequence> -pub fn radroots_storage_sqlite::workspace::StockEvidencePage::receipts(&self) -> &[radroots_storage_sqlite::workspace::StockEvidenceReceipt] -pub struct radroots_storage_sqlite::workspace::StockEvidenceReceipt -impl radroots_storage_sqlite::workspace::StockEvidenceReceipt -pub const fn radroots_storage_sqlite::workspace::StockEvidenceReceipt::attempt(&self) -> radroots_storage::command::CommitAttempt -pub const fn radroots_storage_sqlite::workspace::StockEvidenceReceipt::digest(&self) -> &[u8; 32] -pub const fn radroots_storage_sqlite::workspace::StockEvidenceReceipt::observed_at_unix_ms(&self) -> core::option::Option<core::num::nonzero::NonZeroU64> -pub const fn radroots_storage_sqlite::workspace::StockEvidenceReceipt::recipient(&self) -> radroots_identity::key::PublicKey -pub const fn radroots_storage_sqlite::workspace::StockEvidenceReceipt::signing_attempt_id(&self) -> radroots_domain::identifier::SigningAttemptId +pub fn radroots_storage_sqlite::workspace::StockEvidencePage::receipts(&self) -> &[radroots_storage::inventory::evidence::StockEvidenceReceipt] pub struct radroots_storage_sqlite::workspace::StockExactReplayPermit impl radroots_storage_sqlite::workspace::StockExactReplayPermit pub const fn radroots_storage_sqlite::workspace::StockExactReplayPermit::authorized_at(&self) -> radroots_domain::context::UnixSeconds @@ -674,7 +666,7 @@ impl radroots_storage_sqlite::workspace::StockRecipientSnapshot pub const fn radroots_storage_sqlite::workspace::StockRecipientSnapshot::claim(&self) -> core::option::Option<radroots_storage_sqlite::workspace::StockClaimReference> pub const fn radroots_storage_sqlite::workspace::StockRecipientSnapshot::evidence_count(&self) -> radroots_domain::context::Sequence pub const fn radroots_storage_sqlite::workspace::StockRecipientSnapshot::expected_event_id(&self) -> core::option::Option<[u8; 32]> -pub const fn radroots_storage_sqlite::workspace::StockRecipientSnapshot::first_evidence(&self) -> core::option::Option<radroots_storage_sqlite::workspace::StockEvidenceReceipt> +pub const fn radroots_storage_sqlite::workspace::StockRecipientSnapshot::first_evidence(&self) -> core::option::Option<radroots_storage::inventory::evidence::StockEvidenceReceipt> pub const fn radroots_storage_sqlite::workspace::StockRecipientSnapshot::progress(&self) -> radroots_storage_sqlite::workspace::StockSigningProgress pub const fn radroots_storage_sqlite::workspace::StockRecipientSnapshot::recipient(&self) -> radroots_identity::key::PublicKey pub struct radroots_storage_sqlite::workspace::StockRequestSnapshot diff --git a/contracts/architecture/decisions/shared_sdk_refactor.v1.json b/contracts/architecture/decisions/shared_sdk_refactor.v1.json @@ -255,6 +255,11 @@ "agreement_installed": false }, "signing_issuance": { + "shared_capture_port": "InventoryStore.capture_stock_evidence", + "shared_capture_model_owner": "radroots_storage.inventory", + "shared_capture_descriptors_are_authority": false, + "shared_capture_reauthenticates_original": true, + "native_capture_report_aliases": false, "coherent_operation_snapshot_required": true, "final_evidence_selectors_and_page_rows_required": true, "recovery_view_has_dispatch_or_installation_rights": false, diff --git a/crates/storage/README.md b/crates/storage/README.md @@ -406,3 +406,14 @@ metadata, not consent, authority, actual holds or a commit. Unsupported hosts refuse explicitly; no memory or runtime fallback is constructed. The native adapter uses its selected existing worker. Signing/Nostr remain outside Storage's dependency graph. Complete ordinary commerce ownership remains separate work. + +`InventoryStore::capture_stock_evidence` borrows a bounded zeroizing +`StockEvidenceRequest`; the caller retains original bytes across errors or an +unknown append. The request contains untrusted original selectors and at most +64 KiB of wire bytes. A concrete host authenticates the actual retained claim +and verifies its operation, command digest, recipient, intent and signature. +`StockEvidenceReceipt` and `StockEvidenceOutcome` report append identity only. +Their constructors provide no protected claim, authority, installation or safe +release proof. Capture neither signs nor renews current issuing permission. +Unsupported hosts refuse. An ordinary owner must separately retain admitted +tasks, failed captures and resource leases until durable settlement. diff --git a/crates/storage/src/inventory.rs b/crates/storage/src/inventory.rs @@ -9,8 +9,10 @@ pub use radroots_protocol::command::{CapturedInventoryCommand, InventoryCommandK use radroots_transport::BoxFuture; mod abort; mod acceptance; +mod evidence; pub use abort::{StockAbortOutcome, StockAbortReceipt, StockAbortRequest}; pub use acceptance::{StockAcceptanceOutcome, StockAcceptanceReceipt, StockAcceptanceRequest}; +pub use evidence::{StockEvidenceOutcome, StockEvidenceReceipt, StockEvidenceRequest}; /// Exact captured owner-private inventory command and original authenticated observation. pub struct InventoryRequest { @@ -266,6 +268,16 @@ pub enum InventoryOutcome { /// Native and browser hosts enforce these same atomic rules, never a memory /// success placeholder. No signing or network work occurs in these methods. pub trait InventoryStore: WorkspaceStore { + /// Appends already obtained bytes against the actual protected original + /// claim. This performs no signing or installation and renews no permission. + /// Unsupported hosts refuse. Borrowed original evidence survives errors. + fn capture_stock_evidence<'a>( + &'a self, + _request: &'a StockEvidenceRequest, + _proof: &'a AttachmentProof, + ) -> BoxFuture<'a, Result<StockEvidenceOutcome, OperationError>> { + Box::pin(async { Err(OperationError::UnsupportedOperation) }) + } /// Prepares an original acceptance with complete atomic holds and the order /// fence. Unsupported hosts execute no fallback or simulated stock effect. fn prepare_stock_acceptance( diff --git a/crates/storage/src/inventory/evidence.rs b/crates/storage/src/inventory/evidence.rs @@ -0,0 +1,152 @@ +//! Bounded original evidence input and confirmed append metadata. +use super::*; +use core::num::NonZeroU64; +use radroots_domain::{PublicKey, SigningAttemptId}; +use zeroize::Zeroizing; + +/// Obtained original wire bytes, never proof of a protected claim or authority. +/// The concrete store must authenticate the actual retained claim and verify +/// these bytes against it before append. Construction performs no cryptography. +pub struct StockEvidenceRequest { + binding: WorkspaceBinding, + operation: OperationId, + digest: CommandDigest, + claim: SigningAttemptId, + recipient: PublicKey, + intent: [u8; 32], + raw: Zeroizing<String>, + observed: Option<NonZeroU64>, +} +impl StockEvidenceRequest { + #[allow(clippy::too_many_arguments)] + pub fn from_obtained_wire( + binding: WorkspaceBinding, + operation: OperationId, + digest: CommandDigest, + claim: SigningAttemptId, + recipient: PublicKey, + intent: [u8; 32], + raw: &str, + observed: Option<NonZeroU64>, + ) -> Result<Self, OperationError> { + if binding.scope() != WorkspaceScope::SellerStockOwner { + return Err(OperationError::Unauthorized); + } + if raw.is_empty() || raw.len() > 64 * 1024 { + return Err(OperationError::InvalidEvidence); + } + Ok(Self { + binding, + operation, + digest, + claim, + recipient, + intent, + raw: Zeroizing::new(raw.to_string()), + observed, + }) + } + pub const fn binding(&self) -> &WorkspaceBinding { + &self.binding + } + pub const fn operation_id(&self) -> OperationId { + self.operation + } + pub const fn command_digest(&self) -> CommandDigest { + self.digest + } + pub const fn signing_attempt_id(&self) -> SigningAttemptId { + self.claim + } + pub const fn recipient(&self) -> PublicKey { + self.recipient + } + pub const fn intent_digest(&self) -> &[u8; 32] { + &self.intent + } + pub const fn observed_at_unix_ms(&self) -> Option<NonZeroU64> { + self.observed + } + pub fn with_json<T>(&self, use_json: impl FnOnce(&str) -> T) -> T { + use_json(&self.raw) + } + /// Bounded protected copy for the host's existing owned worker. The caller + /// retains its original bytes across a failed or uncertain append. + pub fn retained_copy(&self) -> Self { + Self { + binding: self.binding.clone(), + operation: self.operation, + digest: self.digest, + claim: self.claim, + recipient: self.recipient, + intent: self.intent, + raw: Zeroizing::new(self.raw.to_string()), + observed: self.observed, + } + } + pub fn attempt(&self) -> CommitAttempt { + CommitAttempt::new( + self.binding.input().workspace_id(), + self.operation, + self.digest, + None, + ) + } +} +impl core::fmt::Debug for StockEvidenceRequest { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + f.write_str("StockEvidenceRequest(<redacted>)") + } +} + +/// Confirmed append identity, independent of installation or delivery. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub struct StockEvidenceReceipt { + attempt: CommitAttempt, + claim: SigningAttemptId, + recipient: PublicKey, + digest: [u8; 32], + observed: Option<NonZeroU64>, +} +impl StockEvidenceReceipt { + /// Validates report shape only. The concrete host confirms the actual + /// authenticated append and original observation; metadata grants nothing. + pub fn from_committed_store( + attempt: CommitAttempt, + claim: SigningAttemptId, + recipient: PublicKey, + digest: [u8; 32], + observed: Option<NonZeroU64>, + ) -> Result<Self, OperationError> { + if attempt.transaction_id().is_none() { + return Err(OperationError::RecoveryRequired); + } + Ok(Self { + attempt, + claim, + recipient, + digest, + observed, + }) + } + pub const fn attempt(&self) -> CommitAttempt { + self.attempt + } + pub const fn signing_attempt_id(&self) -> SigningAttemptId { + self.claim + } + pub const fn recipient(&self) -> PublicKey { + self.recipient + } + pub const fn digest(&self) -> &[u8; 32] { + &self.digest + } + pub const fn observed_at_unix_ms(&self) -> Option<NonZeroU64> { + self.observed + } +} +#[derive(Debug)] +pub enum StockEvidenceOutcome { + Committed(StockEvidenceReceipt), + Unknown(CommitAttempt), +} diff --git a/crates/storage/tests/workspace.rs b/crates/storage/tests/workspace.rs @@ -8,6 +8,9 @@ use radroots_storage::workspace::{ #[cfg(feature = "protected_outbox")] #[path = "workspace/inventory_abort.rs"] mod inventory_abort; +#[cfg(feature = "protected_outbox")] +#[path = "workspace/inventory_evidence.rs"] +mod inventory_evidence; fn key() -> PublicKey { PublicKey::from_hex("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798").unwrap() } diff --git a/crates/storage/tests/workspace/inventory_evidence.rs b/crates/storage/tests/workspace/inventory_evidence.rs @@ -0,0 +1,90 @@ +//! These are bounded descriptors and report-shape checks, not store proofs. +use super::*; +use radroots_domain::{CommandDigest, OperationId, SigningAttemptId, TransactionId}; +use radroots_storage::{ + command::{CommitAttempt, OperationError}, + inventory::{StockEvidenceReceipt, StockEvidenceRequest}, + workspace::WorkspaceScope, +}; +fn binding(scope: WorkspaceScope) -> WorkspaceBinding { + WorkspaceBinding::from_authenticated_host( + input(), + scope, + ActorRef::new(key(), ActorRole::Seller, None, Some(input().grant_id())), + "synthetic", + Sequence::new(1).unwrap(), + UnixSeconds::new(200).unwrap(), + UnixSeconds::new(100).unwrap(), + ) + .unwrap() +} +fn request(scope: WorkspaceScope, raw: &str) -> Result<StockEvidenceRequest, OperationError> { + StockEvidenceRequest::from_obtained_wire( + binding(scope), + OperationId::from_bytes([7; 32]), + CommandDigest::from_bytes([8; 32]), + SigningAttemptId::from_bytes([9; 32]), + key(), + [10; 32], + raw, + None, + ) +} +#[test] +fn input_bounds_original_identity_and_redaction_hold_without_authenticating_a_claim() { + for raw in ["".to_owned(), "x".repeat(65537), "é".repeat(32769)] { + assert!(matches!( + request(WorkspaceScope::SellerStockOwner, &raw), + Err(OperationError::InvalidEvidence) + )); + } + assert!(request(WorkspaceScope::NewSellerOutbox, "x").is_err()); + let raw = "x".repeat(65536); + let evidence = request(WorkspaceScope::SellerStockOwner, &raw).unwrap(); + let retained = evidence.retained_copy(); + drop(evidence); + retained.with_json(|value| assert_eq!(value, raw)); + assert!(!format!("{retained:?}").contains(&raw)); + assert_eq!(retained.attempt().workspace_id(), input().workspace_id()); + assert_eq!(retained.attempt().operation_id(), retained.operation_id()); + assert_eq!( + retained.attempt().command_digest(), + retained.command_digest() + ); + assert!(retained.attempt().transaction_id().is_none()); + assert_eq!( + retained.signing_attempt_id(), + SigningAttemptId::from_bytes([9; 32]) + ); + assert_eq!(retained.recipient(), key()); + assert_eq!(retained.intent_digest(), &[10; 32]); + assert!(retained.observed_at_unix_ms().is_none()); +} +#[test] +fn append_report_requires_commit_identity_and_preserves_nullable_observation() { + let attempt = |transaction| { + CommitAttempt::new( + input().workspace_id(), + OperationId::from_bytes([7; 32]), + CommandDigest::from_bytes([8; 32]), + transaction, + ) + }; + let claim = SigningAttemptId::from_bytes([9; 32]); + assert_eq!( + StockEvidenceReceipt::from_committed_store(attempt(None), claim, key(), [10; 32], None) + .unwrap_err(), + OperationError::RecoveryRequired + ); + for observed in [None, core::num::NonZeroU64::new(150000)] { + let original = attempt(Some(TransactionId::from_bytes([11; 32]))); + let report = + StockEvidenceReceipt::from_committed_store(original, claim, key(), [10; 32], observed) + .unwrap(); + assert_eq!(report.attempt(), original); + assert_eq!(report.signing_attempt_id(), claim); + assert_eq!(report.recipient(), key()); + assert_eq!(report.digest(), &[10; 32]); + assert_eq!(report.observed_at_unix_ms(), observed); + } +} diff --git a/crates/storage_sqlite/README.md b/crates/storage_sqlite/README.md @@ -523,3 +523,14 @@ bounded worker and protected transaction. Native consent, source/allocation, holds, original replay and commit classification remain authoritative. Catalog13, stored bodies and the512KiB worker charge are unchanged. Ordinary outboxes refuse this stock port. Metadata constructors provide no dispatch or installation right. + +Obtained stock evidence uses the shared `InventoryStore::capture_stock_evidence` +port and Storage append reports. The low-level verified `StockEvidenceCapture` +adapter converts into a shared request; the existing native worker verifies that +request again against the actual protected original before append. Both entry +points use the same transaction and256KiB charge. Foreign selectors or invalid +wire cannot become evidence for another claim. Original optional observation, +distinct valid encodings, idempotency, late capture and unknown-commit fencing +retain their existing semantics. Catalog13 and stored encodings/hashes remain +unchanged. Public native receipt/outcome aliases are removed. Borrowed inputs +survive errors; full ordinary task/capture ownership remains separate work. diff --git a/crates/storage_sqlite/src/workspace/mod.rs b/crates/storage_sqlite/src/workspace/mod.rs @@ -26,14 +26,14 @@ pub use stock::{ SellerStockConfig, StockAuthorityReceipt, StockBoundSigningPlan, StockCapturedEvidence, StockClaimOutcome, StockClaimReference, StockClaimRequest, StockConsentCapture, StockConsentMode, StockConsentOutcome, StockConsentReceipt, StockDispatchPermit, - StockEnrollment, StockEvidenceCapture, StockEvidenceOutcome, StockEvidencePage, - StockEvidenceReceipt, StockExactReplayPermit, StockGrantEnrollment, StockGrantOutcome, - StockGrantReceipt, StockHistorySnapshot, StockInstallationOutcome, StockInstallationReceipt, - StockInstallationRequest, StockListingCapture, StockListingOutcome, StockListingReceipt, - StockListingSnapshot, StockOperationSnapshot, StockPublicationWork, StockRecipientSnapshot, - StockRequestSnapshot, StockSigningAttempt, StockSigningPlanOutcome, StockSigningPlanRequest, - StockSigningProgress, StockSnapshotRequest, StockSourceCapture, StockSourceOutcome, - StockSourceProfile, StockSourceReceipt, StockSourceSnapshot, + StockEnrollment, StockEvidenceCapture, StockEvidencePage, StockExactReplayPermit, + StockGrantEnrollment, StockGrantOutcome, StockGrantReceipt, StockHistorySnapshot, + StockInstallationOutcome, StockInstallationReceipt, StockInstallationRequest, + StockListingCapture, StockListingOutcome, StockListingReceipt, StockListingSnapshot, + StockOperationSnapshot, StockPublicationWork, StockRecipientSnapshot, StockRequestSnapshot, + StockSigningAttempt, StockSigningPlanOutcome, StockSigningPlanRequest, StockSigningProgress, + StockSnapshotRequest, StockSourceCapture, StockSourceOutcome, StockSourceProfile, + StockSourceReceipt, StockSourceSnapshot, }; mod worker; diff --git a/crates/storage_sqlite/src/workspace/stock.rs b/crates/storage_sqlite/src/workspace/stock.rs @@ -18,7 +18,8 @@ pub use inventory::installation::{ StockPublicationWork, }; pub(in crate::workspace) use radroots_storage::inventory::{ - StockAbortOutcome, StockAbortReceipt, StockAbortRequest, + StockAbortOutcome, StockAbortReceipt, StockAbortRequest, StockEvidenceOutcome, + StockEvidenceReceipt, StockEvidenceRequest, }; pub(in crate::workspace) use radroots_storage::inventory::{ StockAcceptanceOutcome, StockAcceptanceReceipt, StockAcceptanceRequest, @@ -28,8 +29,7 @@ mod ledger; mod order_state; pub use issuance::{ StockCapturedEvidence, StockClaimOutcome, StockClaimRequest, StockDispatchPermit, - StockEvidenceCapture, StockEvidenceOutcome, StockEvidencePage, StockEvidenceReceipt, - StockExactReplayPermit, StockSigningAttempt, + StockEvidenceCapture, StockEvidencePage, StockExactReplayPermit, StockSigningAttempt, }; pub(in crate::workspace) mod signing_plan; pub(in crate::workspace) mod snapshot; @@ -1101,6 +1101,23 @@ async fn unchanged( } impl radroots_storage::inventory::InventoryStore for NativeWorkspace { + fn capture_stock_evidence<'a>( + &'a self, + request: &'a StockEvidenceRequest, + proof: &'a AttachmentProof, + ) -> radroots_transport::BoxFuture< + 'a, + Result<StockEvidenceOutcome, radroots_storage::command::OperationError>, + > { + Box::pin(async move { + self.worker + .capture_stock_signing_evidence( + request.retained_copy(), + proof.with_secret(|bytes| AttachmentProof::from_protected_input(bytes))?, + ) + .await + }) + } fn prepare_stock_acceptance( &self, request: StockAcceptanceRequest, diff --git a/crates/storage_sqlite/src/workspace/stock/issuance.rs b/crates/storage_sqlite/src/workspace/stock/issuance.rs @@ -3,7 +3,9 @@ use super::*; use radroots_domain::{CommandDigest, OperationId, PublicKey, SigningAttemptId, UnixSeconds}; use radroots_storage::{ command::{CommitAttempt, OperationError}, - inventory::InventoryCheckpointRef, + inventory::{ + InventoryCheckpointRef, StockEvidenceOutcome, StockEvidenceReceipt, StockEvidenceRequest, + }, }; use sha2::{Digest, Sha256}; use sqlx::Row; @@ -13,10 +15,7 @@ mod projection; pub(in crate::workspace) mod recovery; pub(super) use claim::read_entry; pub use claim::{StockClaimOutcome, StockClaimRequest, StockDispatchPermit, StockSigningAttempt}; -pub use evidence::{ - StockCapturedEvidence, StockEvidenceCapture, StockEvidenceOutcome, StockEvidencePage, - StockEvidenceReceipt, -}; +pub use evidence::{StockCapturedEvidence, StockEvidenceCapture, StockEvidencePage}; pub(super) use projection::{Projection, raw_projection}; pub use recovery::StockExactReplayPermit; diff --git a/crates/storage_sqlite/src/workspace/stock/issuance/evidence.rs b/crates/storage_sqlite/src/workspace/stock/issuance/evidence.rs @@ -15,12 +15,7 @@ const MAX_RAW: usize = 64 * 1024; /// Independently checked obtained bytes. A store error leaves the caller's /// original borrowed value intact. This supplies no installation or retry right. pub struct StockEvidenceCapture { - anchor: CommitAttempt, - binding: WorkspaceBinding, - claim: OperationId, - intent: [u8; 32], - raw: Zeroizing<String>, - observed: Option<NonZeroU64>, + request: StockEvidenceRequest, } impl StockEvidenceCapture { pub fn verify( @@ -50,37 +45,28 @@ impl StockEvidenceCapture { return Err(OperationError::InvalidEvidence); }; Ok(Self { - anchor: CommitAttempt::new( - attempt.attempt().workspace_id(), + request: StockEvidenceRequest::from_obtained_wire( + binding, attempt.attempt().operation_id(), attempt.attempt().command_digest(), - None, - ), - binding, - claim: OperationId::from_bytes(*attempt.attempt_id().as_bytes()), - intent: *attempt.binding().digest(), - raw: Zeroizing::new(raw.into()), - observed: signed.observed_at_unix_ms(), + attempt.attempt_id(), + attempt.recipient(), + *attempt.binding().digest(), + raw, + signed.observed_at_unix_ms(), + )?, }) } + /// Transfers bounded original data into the shared port. The host still + /// authenticates its actual retained claim and verifies these bytes again. + pub fn into_request(self) -> StockEvidenceRequest { + self.request + } pub fn with_json<T>(&self, use_json: impl FnOnce(&str) -> T) -> T { - use_json(&self.raw) + self.request.with_json(use_json) } pub const fn observed_at_unix_ms(&self) -> Option<NonZeroU64> { - self.observed - } - pub(in crate::workspace) const fn attempt(&self) -> CommitAttempt { - self.anchor - } - pub(in crate::workspace) fn retained_copy(&self) -> Self { - Self { - anchor: self.anchor, - binding: self.binding.clone(), - claim: self.claim, - intent: self.intent, - raw: Zeroizing::new(self.raw.to_string()), - observed: self.observed, - } + self.request.observed_at_unix_ms() } } impl std::fmt::Debug for StockEvidenceCapture { @@ -89,32 +75,6 @@ impl std::fmt::Debug for StockEvidenceCapture { } } -/// Confirmed append identity, independent of command installation or delivery. -#[derive(Clone, Copy, Debug, Eq, PartialEq)] -pub struct StockEvidenceReceipt { - attempt: CommitAttempt, - claim: SigningAttemptId, - recipient: PublicKey, - digest: [u8; 32], - observed: Option<NonZeroU64>, -} -impl StockEvidenceReceipt { - pub const fn attempt(&self) -> CommitAttempt { - self.attempt - } - pub const fn signing_attempt_id(&self) -> SigningAttemptId { - self.claim - } - pub const fn recipient(&self) -> PublicKey { - self.recipient - } - pub const fn digest(&self) -> &[u8; 32] { - &self.digest - } - pub const fn observed_at_unix_ms(&self) -> Option<NonZeroU64> { - self.observed - } -} pub struct StockCapturedEvidence { receipt: StockEvidenceReceipt, raw: Zeroizing<String>, @@ -132,12 +92,6 @@ impl std::fmt::Debug for StockCapturedEvidence { f.write_str("StockCapturedEvidence(<redacted>)") } } -#[derive(Debug)] -pub enum StockEvidenceOutcome { - Committed(StockEvidenceReceipt), - Unknown(CommitAttempt), -} - /// At most 32 authenticated references in append order. The cursor discovers /// retained bytes after process loss without reconstructing a signer output. #[derive(Debug)] @@ -249,14 +203,14 @@ pub(in crate::workspace) async fn page( pub(in crate::workspace) async fn capture( turn: &mut Turn<'_>, - supplied: StockEvidenceCapture, + supplied: StockEvidenceRequest, proof: AttachmentProof, ) -> Result<StockEvidenceOutcome, OperationError> { if *turn.uncertain { return Err(OperationError::RecoveryRequired); } turn.namespace.validate()?; - let input = supplied.binding.input(); + let input = supplied.binding().input(); if !SellerAuthoritySelection::from_attachment(turn.selected).matches_attachment(input) { return Err(OperationError::Unauthorized); } @@ -266,22 +220,37 @@ pub(in crate::workspace) async fn capture( return Err(OperationError::UnsupportedOperation); } record.authenticate_retained_capture(input, &proof)?; - let original = claim::read_entry(turn.connection, turn.selected, turn.crypto, supplied.claim) - .await? - .ok_or(OperationError::RecoveryRequired)?; - if original.frame.header.actor != supplied.binding.actor() - || original.report.binding().digest() != &supplied.intent + let original = claim::read_entry( + turn.connection, + turn.selected, + turn.crypto, + OperationId::from_bytes(*supplied.signing_attempt_id().as_bytes()), + ) + .await? + .ok_or(OperationError::RecoveryRequired)?; + if original.frame.header.actor != supplied.binding().actor() + || original.report.binding().digest() != supplied.intent_digest() + { + return Err(OperationError::InvalidEvidence); + } + if original.report.attempt().operation_id() != supplied.operation_id() + || original.report.attempt().command_digest() != supplied.command_digest() + || original.report.recipient() != supplied.recipient() { return Err(OperationError::InvalidEvidence); } // Verify again against the actual protected claim, never a caller descriptor. - let checked = StockEvidenceCapture::verify( - supplied.binding.clone(), - &original.report, - &supplied.raw, - supplied.observed, - )?; - let digest: [u8; 32] = Sha256::digest(checked.raw.as_bytes()).into(); + let checked = supplied + .with_json(|raw| { + StockEvidenceCapture::verify( + supplied.binding().clone(), + &original.report, + raw, + supplied.observed_at_unix_ms(), + ) + })? + .into_request(); + let digest: [u8; 32] = checked.with_json(|raw| Sha256::digest(raw.as_bytes()).into()); let before = authority .inventory .ok_or(OperationError::RecoveryRequired)?; @@ -294,7 +263,7 @@ pub(in crate::workspace) async fn capture( turn.connection, turn.selected, turn.crypto, - &supplied.binding, + supplied.binding(), &authority, minimum, ) @@ -309,8 +278,8 @@ pub(in crate::workspace) async fn capture( ) .await?; let (frame, updated_root, receipt) = if let Some(retained) = &existing { - if retained.value.raw.as_str() != checked.raw.as_str() - || retained.value.receipt.claim != original.report.attempt_id() + if checked.with_json(|raw| retained.value.raw.as_str() != raw) + || retained.value.receipt.signing_attempt_id() != original.report.attempt_id() { return Err(OperationError::RecoveryRequired); } @@ -358,18 +327,18 @@ pub(in crate::workspace) async fn capture( .crypto .seal_stock_root(turn.selected, next.catalog, &next.encode()?) .await?; - let receipt = StockEvidenceReceipt { - attempt: CommitAttempt::new( + let receipt = StockEvidenceReceipt::from_committed_store( + CommitAttempt::new( input.workspace_id(), original.report.bound_plan().plan().operation_id(), original.frame.header.digest, Some(transaction), ), - claim: original.report.attempt_id(), - recipient: original.report.recipient(), + original.report.attempt_id(), + original.report.recipient(), digest, - observed: checked.observed, - }; + checked.observed_at_unix_ms(), + )?; (Some(frame), Some(updated), receipt) }; let mut tx = turn @@ -385,7 +354,7 @@ pub(in crate::workspace) async fn capture( if let Some(existing)=&existing {existing.confirm(&mut tx).await?;} if let Some(frame)=&frame { frame.insert_record(&mut tx).await?; - sqlx::query("INSERT INTO stock_signing_evidence(actor,operation_id,recipient,evidence_digest,entry_id) VALUES(?,?,?,?,?)").bind(input.participant().as_bytes().as_slice()).bind(receipt.attempt.operation_id().as_bytes().as_slice()).bind(receipt.recipient.as_bytes().as_slice()).bind(digest.as_slice()).bind(frame.header.operation.as_bytes().as_slice()).execute(&mut *tx).await.map_err(|_|OperationError::StorageFailure)?; + sqlx::query("INSERT INTO stock_signing_evidence(actor,operation_id,recipient,evidence_digest,entry_id) VALUES(?,?,?,?,?)").bind(input.participant().as_bytes().as_slice()).bind(receipt.attempt().operation_id().as_bytes().as_slice()).bind(receipt.recipient().as_bytes().as_slice()).bind(digest.as_slice()).bind(frame.header.operation.as_bytes().as_slice()).execute(&mut *tx).await.map_err(|_|OperationError::StorageFailure)?; let result=sqlx::query("UPDATE stock_authority SET protected=? WHERE singleton=1 AND protected=?").bind(updated_root.as_ref().ok_or(OperationError::RecoveryRequired)?).bind(&root).execute(&mut *tx).await.map_err(|_|OperationError::StorageFailure)?; if result.rows_affected()!=1 {return Err(OperationError::RecoveryRequired);} } @@ -394,7 +363,7 @@ pub(in crate::workspace) async fn capture( if let Err(error) = changed { if tx.rollback().await.is_err() { *turn.uncertain = true; - return Ok(StockEvidenceOutcome::Unknown(receipt.attempt)); + return Ok(StockEvidenceOutcome::Unknown(receipt.attempt())); } return Err(error); } @@ -405,7 +374,7 @@ pub(in crate::workspace) async fn capture( }; if done.is_err() { *turn.uncertain = true; - return Ok(StockEvidenceOutcome::Unknown(receipt.attempt)); + return Ok(StockEvidenceOutcome::Unknown(receipt.attempt())); } Ok(StockEvidenceOutcome::Committed(receipt)) } @@ -542,12 +511,12 @@ impl NativeWorkspace { evidence: &StockEvidenceCapture, proof: &AttachmentProof, ) -> Result<StockEvidenceOutcome, OperationError> { - self.worker - .capture_stock_signing_evidence( - evidence.retained_copy(), - proof.with_secret(|bytes| AttachmentProof::from_protected_input(bytes))?, - ) - .await + radroots_storage::inventory::InventoryStore::capture_stock_evidence( + self, + &evidence.request, + proof, + ) + .await } pub async fn stock_signing_evidence( &self, diff --git a/crates/storage_sqlite/src/workspace/stock/issuance/evidence/codec.rs b/crates/storage_sqlite/src/workspace/stock/issuance/evidence/codec.rs @@ -4,23 +4,23 @@ const PREFIX: usize = 117; const MAGIC: &[u8; 8] = b"RDSTKS1\0"; pub(super) fn encode( original: &claim::codec::Retained, - supplied: &StockEvidenceCapture, + supplied: &StockEvidenceRequest, ) -> Vec<u8> { - let mut out = Vec::with_capacity(PREFIX + supplied.raw.len()); + let mut out = Vec::with_capacity(PREFIX + supplied.with_json(str::len)); out.extend_from_slice(MAGIC); out.extend_from_slice(original.frame.header.operation.as_bytes()); out.extend_from_slice(original.frame.header.transaction.as_bytes()); out.extend_from_slice(original.frame.header.head.as_bytes()); - out.push(u8::from(supplied.observed.is_some())); + out.push(u8::from(supplied.observed_at_unix_ms().is_some())); out.extend_from_slice( &supplied - .observed + .observed_at_unix_ms() .map(NonZeroU64::get) .unwrap_or(0) .to_be_bytes(), ); - out.extend_from_slice(&(supplied.raw.len() as u32).to_be_bytes()); - out.extend_from_slice(supplied.raw.as_bytes()); + out.extend_from_slice(&(supplied.with_json(str::len) as u32).to_be_bytes()); + supplied.with_json(|raw| out.extend_from_slice(raw.as_bytes())); out } pub(super) fn head(header: &ledger::Header, body: &[u8]) -> radroots_domain::CheckpointDigest { @@ -150,18 +150,18 @@ pub(in crate::workspace::stock) async fn read_entry( recipient: original.report.recipient(), evidence: Some(digest), }; - let receipt = StockEvidenceReceipt { - attempt: CommitAttempt::new( + let receipt = StockEvidenceReceipt::from_committed_store( + CommitAttempt::new( input.workspace_id(), projection.operation, header.digest, Some(header.transaction), ), - claim: original.report.attempt_id(), - recipient: projection.recipient, + original.report.attempt_id(), + projection.recipient, digest, observed, - }; + )?; let value = StockCapturedEvidence { receipt, raw: Zeroizing::new(raw.into()), diff --git a/crates/storage_sqlite/src/workspace/stock/public_source/evidence_tests.rs b/crates/storage_sqlite/src/workspace/stock/public_source/evidence_tests.rs @@ -4,7 +4,8 @@ use super::*; mod installations; #[path = "snapshot_tests.rs"] mod snapshots; -use crate::workspace::{StockEvidenceCapture, StockEvidenceOutcome, StockEvidenceReceipt}; +use crate::workspace::StockEvidenceCapture; +use radroots_storage::inventory::{StockEvidenceOutcome, StockEvidenceReceipt}; use sha2::{Digest, Sha256}; async fn obtained( r: &Rig, @@ -33,6 +34,100 @@ fn committed(value: StockEvidenceOutcome) -> StockEvidenceReceipt { value } #[tokio::test] +async fn shared_capture_authenticates_actual_claim_and_rejects_substituted_descriptors_or_wire() { + use radroots_storage::inventory::{InventoryStore, StockEvidenceRequest}; + let mut r = Rig::new().await; + let receipt = ready(&r).await; + let recipient = receipt.rumor().recipients()[0]; + let (report, raw) = obtained(&r, &receipt, recipient).await; + let before = inventory_minimum(&r).await; + let port: &dyn InventoryStore = &r.store; + let tampered = raw.replace("\"sig\":\"", "\"sig\":\"0"); + for mode in 0..7 { + let request = StockEvidenceRequest::from_obtained_wire( + r.binding.clone(), + if mode == 0 { + OperationId::from_bytes([91; 32]) + } else { + report.attempt().operation_id() + }, + if mode == 1 { + radroots_domain::CommandDigest::from_bytes([92; 32]) + } else { + report.attempt().command_digest() + }, + if mode == 2 { + radroots_domain::SigningAttemptId::from_bytes([93; 32]) + } else { + report.attempt_id() + }, + if mode == 3 { + receipt.rumor().recipients()[1] + } else { + report.recipient() + }, + if mode == 4 { + [94; 32] + } else { + *report.binding().digest() + }, + if mode == 5 { + "synthetic invalid original wire" + } else if mode == 6 { + &tampered + } else { + &raw + }, + None, + ) + .unwrap(); + assert!(!format!("{request:?}").contains("synthetic invalid")); + assert!( + port.capture_stock_evidence(&request, r.enrollment.proof()) + .await + .is_err(), + "mode {mode}" + ); + request.with_json(|retained| assert!(!retained.is_empty())); + assert_eq!(inventory_minimum(&r).await, before); + } + let request = StockEvidenceCapture::verify(r.binding.clone(), &report, &raw, None) + .unwrap() + .into_request(); + let retained = request.retained_copy(); + assert_eq!(retained.attempt(), request.attempt()); + retained.with_json(|bytes| assert_eq!(bytes, raw)); + let first = committed( + port.capture_stock_evidence(&request, r.enrollment.proof()) + .await + .unwrap(), + ); + assert_eq!(first.signing_attempt_id(), report.attempt_id()); + assert_eq!( + committed( + port.capture_stock_evidence(&request, r.enrollment.proof()) + .await + .unwrap() + ), + first + ); + reopen_plain(&mut r).await; + let stored = r + .store + .stock_signing_evidence( + selector(&r, &receipt, recipient).await, + *first.digest(), + r.enrollment.proof(), + ) + .await + .unwrap() + .unwrap(); + assert_eq!(stored.receipt(), first); + stored.with_json(|bytes| assert_eq!(bytes, raw)); + r.store.close().await.unwrap(); +} + +#[tokio::test] async fn original_peer_self_bytes_are_captured_once_reopened_and_preserve_first_optional_time() { let mut r = Rig::new().await; let receipt = ready(&r).await; diff --git a/crates/storage_sqlite/src/workspace/stock/public_source/exact_recovery_tests.rs b/crates/storage_sqlite/src/workspace/stock/public_source/exact_recovery_tests.rs @@ -1,10 +1,11 @@ //! Actual original-claim local recovery, current authorization and existing S/T2. use super::*; use crate::workspace::{ - StockEvidenceCapture, StockEvidenceOutcome, StockExactReplayPermit, StockInstallationOutcome, + StockEvidenceCapture, StockExactReplayPermit, StockInstallationOutcome, StockInstallationRequest, }; use radroots_signing::issuance::ExactRecoveryKind; +use radroots_storage::inventory::StockEvidenceOutcome; async fn local_ready(r: &Rig) -> StockAcceptanceReceipt { local_ready_command(r).await.1 @@ -184,6 +185,25 @@ async fn ordinary_outbox_refuses_exact_replay_without_adopting_stock_authority() .unwrap_err(), OperationError::UnsupportedOperation ); + let evidence = radroots_storage::inventory::StockEvidenceRequest::from_obtained_wire( + r.binding.clone(), + receipt.attempt().operation_id(), + receipt.attempt().command_digest(), + radroots_domain::SigningAttemptId::from_bytes([95; 32]), + receipt.rumor().recipients()[0], + [96; 32], + "synthetic unsupported descriptor", + None, + ) + .unwrap(); + assert_eq!( + radroots_storage::inventory::InventoryStore::capture_stock_evidence( + &outbox, &evidence, &proof + ) + .await + .unwrap_err(), + OperationError::UnsupportedOperation, + ); outbox.close().await.unwrap(); r.store.close().await.unwrap(); } diff --git a/crates/storage_sqlite/src/workspace/worker.rs b/crates/storage_sqlite/src/workspace/worker.rs @@ -70,7 +70,7 @@ enum Job { Reply<stock::StockEvidencePage, OperationError>, ), CaptureStockEvidence( - Box<stock::StockEvidenceCapture>, + Box<radroots_storage::inventory::StockEvidenceRequest>, AttachmentProof, Reply<stock::StockEvidenceOutcome, OperationError>, ), @@ -1808,7 +1808,7 @@ impl Handle { } pub(super) async fn capture_stock_signing_evidence( &self, - evidence: stock::StockEvidenceCapture, + evidence: radroots_storage::inventory::StockEvidenceRequest, proof: AttachmentProof, ) -> Result<stock::StockEvidenceOutcome, OperationError> { let unknown = stock::StockEvidenceOutcome::Unknown(evidence.attempt()); diff --git a/tools/xtask/src/architecture/decision_package.rs b/tools/xtask/src/architecture/decision_package.rs @@ -290,6 +290,11 @@ struct InitialAgreementInstallation { #[derive(Deserialize)] #[serde(deny_unknown_fields)] struct SigningIssuance { + shared_capture_port: String, + shared_capture_model_owner: String, + shared_capture_descriptors_are_authority: bool, + shared_capture_reauthenticates_original: bool, + native_capture_report_aliases: bool, coherent_operation_snapshot_required: bool, final_evidence_selectors_and_page_rows_required: bool, recovery_view_has_dispatch_or_installation_rights: bool, @@ -600,6 +605,16 @@ fn validate_bytes(raw: &[u8]) -> Result<(), String> { .signing_issuance .fresh_current_backing_projection_required && stock.signing_issuance.coherent_operation_snapshot_required + && stock.signing_issuance.shared_capture_port + == "InventoryStore.capture_stock_evidence" + && stock.signing_issuance.shared_capture_model_owner == "radroots_storage.inventory" + && !stock + .signing_issuance + .shared_capture_descriptors_are_authority + && stock + .signing_issuance + .shared_capture_reauthenticates_original + && !stock.signing_issuance.native_capture_report_aliases && stock .signing_issuance .final_evidence_selectors_and_page_rows_required @@ -1375,6 +1390,14 @@ mod tests { ("claim_worker_charge_bytes", json!(16384)), ("capture_worker_charge_bytes", json!(16384)), ("capture_raw_max_bytes", json!(65537)), + ("shared_capture_port", json!("arbitrary_transaction")), + ( + "shared_capture_model_owner", + json!("radroots_storage_sqlite"), + ), + ("shared_capture_descriptors_are_authority", json!(true)), + ("shared_capture_reauthenticates_original", json!(false)), + ("native_capture_report_aliases", json!(true)), ("first_dispatch_requires_confirmed_commit", json!(false)), ("existing_claim_returns_dispatch_permit", json!(true)), (