Skip to main content

SqliteReceiptStore

Struct SqliteReceiptStore 

Source
pub struct SqliteReceiptStore { /* private fields */ }

Implementations§

Source§

impl SqliteReceiptStore

Source

pub fn record_capability_snapshot( &self, token: &CapabilityToken, parent_capability_id: Option<&str>, ) -> Result<(), CapabilityLineageError>

Record a capability snapshot at issuance time.

Uses INSERT OR IGNORE for idempotency – duplicate inserts are silently dropped, preserving the first-writer-wins record.

The parent_capability_id argument must refer to a capability already present in the lineage table. If it is Some but the parent is missing, the depth defaults to 1 (the minimum delegation depth).

Source

pub fn upsert_capability_snapshot( &mut self, snapshot: &CapabilitySnapshot, ) -> Result<(), CapabilityLineageError>

Upsert an already-materialized capability snapshot.

This is used by cluster replication so followers can converge on the leader’s lineage table without reconstructing full signed tokens.

Source

pub fn get_lineage( &self, capability_id: &str, ) -> Result<Option<CapabilitySnapshot>, CapabilityLineageError>

Retrieve a single capability snapshot by its ID.

Returns None if no snapshot exists for the given capability_id.

Source

pub fn get_delegation_chain( &self, capability_id: &str, ) -> Result<Vec<CapabilitySnapshot>, CapabilityLineageError>

Walk the delegation chain for a capability, returning root-first ordering.

Uses a WITH RECURSIVE CTE that walks from the given capability up through its parent chain, tracking depth level. The ORDER BY level DESC produces root-first ordering because the root has the highest level value.

A max-depth guard (level < 20) prevents infinite recursion caused by accidental cycles in the parent chain.

Source

pub fn list_capabilities_for_subject( &self, subject_key: &str, ) -> Result<Vec<CapabilitySnapshot>, CapabilityLineageError>

List all capability snapshots for a given subject key.

Returns snapshots ordered newest-first by issued_at.

Source

pub fn list_capability_snapshots( &self, subject_key: Option<&str>, issuer_key: Option<&str>, ) -> Result<Vec<CapabilitySnapshot>, CapabilityLineageError>

List capability snapshots filtered by subject and/or issuer.

If both filters are present they are combined with AND semantics. Results are ordered deterministically oldest-first to keep reputation corpus construction stable across runs.

Source

pub fn list_capability_snapshots_after_seq( &self, after_seq: u64, limit: usize, ) -> Result<Vec<StoredCapabilitySnapshot>, CapabilityLineageError>

Return capability lineage snapshots added after a given local sequence.

The sequence is the SQLite rowid, which is monotonic for this append-only table and therefore suitable as a replication cursor.

Source§

impl SqliteReceiptStore

Source

pub fn build_evidence_export_bundle( &self, query: &EvidenceExportQuery, ) -> Result<EvidenceExportBundle, EvidenceExportError>

Build a local-only evidence export bundle from the current SQLite store.

This method never fabricates joins that the runtime does not persist. Tool receipts can be scoped by capability or agent subject. Child receipts do not currently have the same attribution fields, so they are either included by query window or omitted with an explicit scope flag.

Source

pub fn build_evidence_export_transparency_summary( &self, checkpoints: &[KernelCheckpoint], ) -> Result<CheckpointTransparencySummary, EvidenceExportError>

Source§

impl SqliteReceiptStore

Source

pub fn query_receipts( &self, query: &ReceiptQuery, ) -> Result<ReceiptQueryResult, ReceiptStoreError>

Query tool receipts with multi-filter support and cursor-based pagination.

Filters are applied with AND semantics. The cursor parameter enables forward-only pagination using the seq column as a stable cursor.

The limit is capped at MAX_QUERY_LIMIT. total_count reflects the full filtered set (no cursor applied), regardless of the page limit.

Source§

impl SqliteReceiptStore

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self, ReceiptStoreError>

Source

pub fn tool_receipt_count(&self) -> Result<u64, ReceiptStoreError>

Source

pub fn child_receipt_count(&self) -> Result<u64, ReceiptStoreError>

Source

pub fn list_tool_receipts( &self, limit: usize, capability_id: Option<&str>, tool_server: Option<&str>, tool_name: Option<&str>, decision_kind: Option<&str>, ) -> Result<Vec<ChioReceipt>, ReceiptStoreError>

Source

pub fn list_tool_receipts_for_subject( &self, subject_key: &str, ) -> Result<Vec<ChioReceipt>, ReceiptStoreError>

List all tool receipts attributed to a given subject public key.

Uses the persisted subject_key column when present and falls back to the capability lineage join for older rows.

Source

pub fn list_tool_receipts_after_seq( &self, after_seq: u64, limit: usize, ) -> Result<Vec<StoredToolReceipt>, ReceiptStoreError>

Source

pub fn list_child_receipts( &self, limit: usize, session_id: Option<&str>, parent_request_id: Option<&str>, request_id: Option<&str>, operation_kind: Option<&str>, terminal_state: Option<&str>, ) -> Result<Vec<ChildRequestReceipt>, ReceiptStoreError>

Source

pub fn list_child_receipts_after_seq( &self, after_seq: u64, limit: usize, ) -> Result<Vec<StoredChildReceipt>, ReceiptStoreError>

Source

pub fn import_federated_evidence_share( &mut self, import: &FederatedEvidenceShareImport, ) -> Result<FederatedEvidenceShareSummary, ReceiptStoreError>

Source

pub fn get_federated_share_for_capability( &self, capability_id: &str, ) -> Result<Option<(FederatedEvidenceShareSummary, CapabilitySnapshot)>, ReceiptStoreError>

Source

pub fn list_federated_share_subject_corpora( &self, subject_key: &str, since: Option<u64>, until: Option<u64>, ) -> Result<Vec<(FederatedEvidenceShareSummary, Vec<StoredToolReceipt>, Vec<CapabilitySnapshot>)>, ReceiptStoreError>

Source

pub fn record_federated_lineage_bridge( &mut self, local_capability_id: &str, parent_capability_id: &str, share_id: Option<&str>, ) -> Result<(), ReceiptStoreError>

Source

pub fn get_combined_lineage( &self, capability_id: &str, ) -> Result<Option<CapabilitySnapshot>, ReceiptStoreError>

Source

pub fn get_combined_delegation_chain( &self, capability_id: &str, ) -> Result<Vec<CapabilitySnapshot>, ReceiptStoreError>

Source§

impl SqliteReceiptStore

Source

pub fn append_chio_receipt_returning_seq( &self, receipt: &ChioReceipt, ) -> Result<u64, ReceiptStoreError>

Source

pub fn store_checkpoint( &self, checkpoint: &KernelCheckpoint, ) -> Result<(), ReceiptStoreError>

Store a signed KernelCheckpoint in the kernel_checkpoints table.

Source

pub fn load_checkpoint_by_seq( &self, checkpoint_seq: u64, ) -> Result<Option<KernelCheckpoint>, ReceiptStoreError>

Load a KernelCheckpoint by its checkpoint_seq.

Source

pub fn receipts_canonical_bytes_range( &self, start_seq: u64, end_seq: u64, ) -> Result<Vec<(u64, Vec<u8>)>, ReceiptStoreError>

Return canonical JSON bytes for receipts with seq in [start_seq, end_seq], ordered by seq.

Uses RFC 8785 canonical JSON for deterministic Merkle leaf hashing.

Source

pub fn db_size_bytes(&self) -> Result<u64, ReceiptStoreError>

Return the current on-disk size of the database in bytes.

Uses PRAGMA page_count and PRAGMA page_size to compute the size without requiring a filesystem stat, which is consistent in WAL mode.

Source

pub fn oldest_receipt_timestamp(&self) -> Result<Option<u64>, ReceiptStoreError>

Return the Unix timestamp (seconds) of the oldest receipt in the live database, or None if there are no receipts.

Source

pub fn oldest_receipt_timestamp_for_tenant( &self, tenant_id: &str, ) -> Result<Option<u64>, ReceiptStoreError>

Return the oldest live receipt timestamp for a tenant.

Source

pub fn archive_receipts_before( &mut self, cutoff_unix_secs: u64, archive_path: &str, ) -> Result<u64, ReceiptStoreError>

Archive all receipts with timestamp < cutoff_unix_secs to an external SQLite file, then delete them from the live database.

Checkpoint rows whose entire batch (batch_end_seq) falls within the archived receipt range are also copied to the archive. Partial batches are never archived to avoid breaking inclusion proofs.

Returns the number of receipt rows deleted from the live database.

Source

pub fn archive_receipts_before_for_tenant( &mut self, cutoff_unix_secs: u64, archive_path: &str, tenant_id: &str, ) -> Result<u64, ReceiptStoreError>

Archive receipts for a single tenant without deleting other tenants’ evidence that may have a longer retention window.

Source

pub fn rotate_if_needed( &mut self, config: &RetentionConfig, ) -> Result<u64, ReceiptStoreError>

Check time and size thresholds and archive receipts if either is exceeded.

  • Time threshold: receipts older than config.retention_days days are archived.
  • Size threshold: if db_size_bytes() exceeds config.max_size_bytes, receipts older than the median timestamp are archived (removes roughly half the receipts).

Returns the number of receipt rows archived (0 if no threshold was exceeded).

Source§

impl SqliteReceiptStore

Source§

impl SqliteReceiptStore

Source§

impl SqliteReceiptStore

Source

pub fn query_receipt_analytics( &self, query: &ReceiptAnalyticsQuery, ) -> Result<ReceiptAnalyticsResponse, ReceiptStoreError>

Source

pub fn query_cost_attribution_report( &self, query: &CostAttributionQuery, ) -> Result<CostAttributionReport, ReceiptStoreError>

Source

pub fn query_shared_evidence_report( &self, query: &SharedEvidenceQuery, ) -> Result<SharedEvidenceReferenceReport, ReceiptStoreError>

Source

pub fn query_compliance_report( &self, query: &OperatorReportQuery, ) -> Result<ComplianceReport, ReceiptStoreError>

Source

pub fn upsert_settlement_reconciliation( &self, receipt_id: &str, reconciliation_state: SettlementReconciliationState, note: Option<&str>, ) -> Result<i64, ReceiptStoreError>

Source

pub fn upsert_metered_billing_reconciliation( &self, receipt_id: &str, evidence: &MeteredBillingEvidenceRecord, reconciliation_state: MeteredBillingReconciliationState, note: Option<&str>, ) -> Result<i64, ReceiptStoreError>

Source

pub fn query_metered_billing_reconciliation_report( &self, query: &OperatorReportQuery, ) -> Result<MeteredBillingReconciliationReport, ReceiptStoreError>

Source

pub fn query_economic_receipt_projection_report( &self, query: &OperatorReportQuery, ) -> Result<EconomicReceiptProjectionReport, ReceiptStoreError>

Source

pub fn query_economic_completion_flow_report( &self, query: &ExposureLedgerQuery, ) -> Result<EconomicCompletionFlowReport, ReceiptStoreError>

Source

pub fn query_settlement_reconciliation_report( &self, query: &OperatorReportQuery, ) -> Result<SettlementReconciliationReport, ReceiptStoreError>

Source

pub fn query_authorization_context_report( &self, query: &OperatorReportQuery, ) -> Result<AuthorizationContextReport, ReceiptStoreError>

Source

pub fn authorization_profile_metadata_report( &self, ) -> ChioOAuthAuthorizationMetadataReport

Source

pub fn query_authorization_review_pack( &self, query: &OperatorReportQuery, ) -> Result<ChioOAuthAuthorizationReviewPack, ReceiptStoreError>

Source

pub fn query_behavioral_feed_receipts( &self, query: &BehavioralFeedQuery, ) -> Result<(BehavioralFeedSettlementSummary, BehavioralFeedGovernedActionSummary, BehavioralFeedMeteredBillingSummary, BehavioralFeedReceiptSelection), ReceiptStoreError>

Source

pub fn query_recent_credit_loss_receipts( &self, query: &BehavioralFeedQuery, limit: usize, ) -> Result<(u64, Vec<BehavioralFeedReceiptRow>), ReceiptStoreError>

Source§

impl SqliteReceiptStore

Source

pub fn record_session_anchor_record( &self, session_id: &str, anchor_id: &str, auth_context_fingerprint: &str, issued_at: u64, supersedes_anchor_id: Option<&str>, anchor_json: &Value, ) -> Result<(), ReceiptStoreError>

Source

pub fn record_request_lineage_record( &self, session_id: &str, request_id: &str, parent_request_id: Option<&str>, session_anchor_id: Option<&str>, recorded_at: u64, request_fingerprint: Option<&str>, lineage_json: &Value, ) -> Result<(), ReceiptStoreError>

Source

pub fn record_receipt_lineage_statement_record( &self, child_receipt_id: &str, request_id: Option<&str>, session_id: Option<&str>, session_anchor_id: Option<&str>, parent_request_id: Option<&str>, parent_receipt_id: Option<&str>, chain_id: Option<&str>, recorded_at: u64, statement_json: &Value, ) -> Result<(), ReceiptStoreError>

Source

pub fn receipt_lineage_verification( &self, receipt_id: &str, ) -> Result<Option<ReceiptLineageVerification>, ReceiptStoreError>

Source

pub fn append_child_receipt_record( &self, receipt: &ChildRequestReceipt, ) -> Result<(), ReceiptStoreError>

Source§

impl SqliteReceiptStore

Source§

impl SqliteReceiptStore

Source§

impl SqliteReceiptStore

Source

pub fn with_strict_tenant_isolation(&self, strict: bool)

Phase 1.5 multi-tenant receipt isolation: toggle strict-isolation mode on tenant-scoped queries.

When strict = true, a tenant_filter = Some(id) query returns ONLY rows whose tenant_id = id. Legacy pre-1.5 receipts with tenant_id IS NULL are excluded.

When strict = false, the same query also includes rows where tenant_id IS NULL – the pre-multitenant “public” fallback set – so legacy receipts remain visible during an explicit compatibility window.

A tenant_filter = None admin / compat query always returns every row regardless of this setting.

Source

pub fn strict_tenant_isolation_enabled(&self) -> bool

Read the current strict-tenant-isolation setting.

Trait Implementations§

Source§

impl ReceiptStore for SqliteReceiptStore

Source§

fn append_chio_receipt( &mut self, receipt: &ChioReceipt, ) -> Result<(), ReceiptStoreError>

Source§

fn append_chio_receipt_returning_seq( &mut self, receipt: &ChioReceipt, ) -> Result<Option<u64>, ReceiptStoreError>

Source§

fn receipts_canonical_bytes_range( &self, start_seq: u64, end_seq: u64, ) -> Result<Vec<(u64, Vec<u8>)>, ReceiptStoreError>

Source§

fn store_checkpoint( &mut self, checkpoint: &KernelCheckpoint, ) -> Result<(), ReceiptStoreError>

Source§

fn load_checkpoint_by_seq( &self, checkpoint_seq: u64, ) -> Result<Option<KernelCheckpoint>, ReceiptStoreError>

Source§

fn supports_kernel_signed_checkpoints(&self) -> bool

Source§

fn record_capability_snapshot( &mut self, token: &CapabilityToken, parent_capability_id: Option<&str>, ) -> Result<(), ReceiptStoreError>

Source§

fn get_capability_snapshot( &self, capability_id: &str, ) -> Result<Option<CapabilitySnapshot>, ReceiptStoreError>

Source§

fn get_capability_delegation_chain( &self, capability_id: &str, ) -> Result<Vec<CapabilitySnapshot>, ReceiptStoreError>

Source§

fn record_session_anchor( &mut self, session_id: &str, anchor_id: &str, auth_context_fingerprint: &str, issued_at: u64, supersedes_anchor_id: Option<&str>, anchor_json: &Value, ) -> Result<(), ReceiptStoreError>

Persist a serialized SessionAnchor while the concrete P1-A type remains in flight.
Source§

fn record_request_lineage( &mut self, session_id: &str, request_id: &str, parent_request_id: Option<&str>, session_anchor_id: Option<&str>, recorded_at: u64, request_fingerprint: Option<&str>, lineage_json: &Value, ) -> Result<(), ReceiptStoreError>

Persist a serialized RequestLineageRecord while the concrete P1-A type remains in flight.
Source§

fn record_receipt_lineage_statement( &mut self, child_receipt_id: &str, request_id: Option<&str>, session_id: Option<&str>, session_anchor_id: Option<&str>, parent_request_id: Option<&str>, parent_receipt_id: Option<&str>, chain_id: Option<&str>, recorded_at: u64, statement_json: &Value, ) -> Result<(), ReceiptStoreError>

Persist a serialized ReceiptLineageStatement while the concrete P1-A type remains in flight.
Source§

fn get_receipt_lineage_verification( &self, receipt_id: &str, ) -> Result<Option<ReceiptLineageVerification>, ReceiptStoreError>

Source§

fn as_any_mut(&mut self) -> Option<&mut dyn Any>

Source§

fn resolve_credit_bond( &self, bond_id: &str, ) -> Result<Option<CreditBondRow>, ReceiptStoreError>

Source§

fn append_child_receipt( &mut self, receipt: &ChildRequestReceipt, ) -> Result<(), ReceiptStoreError>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more