pub trait MemoryProvenanceStore: Send + Sync {
// Required methods
fn append(
&self,
input: MemoryProvenanceAppend,
) -> Result<MemoryProvenanceEntry, MemoryProvenanceError>;
fn get_entry(
&self,
entry_id: &str,
) -> Result<Option<MemoryProvenanceEntry>, MemoryProvenanceError>;
fn latest_for_key(
&self,
store: &str,
key: &str,
) -> Result<Option<MemoryProvenanceEntry>, MemoryProvenanceError>;
fn verify_entry(
&self,
entry_id: &str,
) -> Result<ProvenanceVerification, MemoryProvenanceError>;
fn chain_digest(&self) -> Result<String, MemoryProvenanceError>;
}Expand description
Contract for the append-only, hash-chained memory provenance log.
Implementations MUST:
- Compute
prev_hashby reading the tail entry inside the same transactional scope as the append, so concurrent appenders cannot both read the same tail and produce a forked chain. - Populate
hashwithrecompute_entry_hash(or equivalent) so every consumer can independently verify the entry. - Keep the chain insertion order total:
appendfollowed bylatest_for_key/chain_digestmust observe the freshly written entry.
Required Methods§
Sourcefn append(
&self,
input: MemoryProvenanceAppend,
) -> Result<MemoryProvenanceEntry, MemoryProvenanceError>
fn append( &self, input: MemoryProvenanceAppend, ) -> Result<MemoryProvenanceEntry, MemoryProvenanceError>
Append a new entry, computing the chain linkage atomically.
Sourcefn get_entry(
&self,
entry_id: &str,
) -> Result<Option<MemoryProvenanceEntry>, MemoryProvenanceError>
fn get_entry( &self, entry_id: &str, ) -> Result<Option<MemoryProvenanceEntry>, MemoryProvenanceError>
Fetch an entry by its unique id. Returns Ok(None) when the id
is absent; consumers should treat that as
UnverifiedReason::NoProvenance when it happens during a read.
Sourcefn latest_for_key(
&self,
store: &str,
key: &str,
) -> Result<Option<MemoryProvenanceEntry>, MemoryProvenanceError>
fn latest_for_key( &self, store: &str, key: &str, ) -> Result<Option<MemoryProvenanceEntry>, MemoryProvenanceError>
Fetch the most-recent entry for a (store, key) pair, or
Ok(None) when no entry has ever been appended for that key.
Sourcefn verify_entry(
&self,
entry_id: &str,
) -> Result<ProvenanceVerification, MemoryProvenanceError>
fn verify_entry( &self, entry_id: &str, ) -> Result<ProvenanceVerification, MemoryProvenanceError>
Verify a specific entry: recompute its hash, confirm its
prev_hash matches the entry that sits immediately before it
(or the genesis marker for entry #1), and return
ProvenanceVerification::Verified when everything checks out.
Sourcefn chain_digest(&self) -> Result<String, MemoryProvenanceError>
fn chain_digest(&self) -> Result<String, MemoryProvenanceError>
Aggregate digest of the chain – the hash of the tail entry,
or MEMORY_PROVENANCE_GENESIS_PREV_HASH when the chain is
empty. Useful for embedding into receipts as a snapshot marker.