pub struct ProofLedger { /* private fields */ }Expand description
The ProofLedger - manages immutable citations
Implementations§
Source§impl ProofLedger
impl ProofLedger
Sourcepub fn in_memory() -> Result<Self>
pub fn in_memory() -> Result<Self>
Create an in-memory ProofLedger (for testing)
§Examples
use reasonkit::verification::ProofLedger;
let ledger = ProofLedger::in_memory()?;Sourcepub fn anchor(
&self,
content: &str,
url: &str,
metadata: Option<String>,
) -> Result<String>
pub fn anchor( &self, content: &str, url: &str, metadata: Option<String>, ) -> Result<String>
Anchor content to the ledger
Creates an immutable anchor for the given content and URL. Returns the hash ID which can be used for citations.
§Arguments
content- The full content to anchorurl- Source URLmetadata- Optional JSON metadata
§Examples
use reasonkit::verification::ProofLedger;
let ledger = ProofLedger::in_memory()?;
let hash = ledger.anchor(
"The global AI market size was valued at USD 196.63 billion in 2023.",
"https://example.com/ai-market",
None,
)?;
println!("Citation hash: {}", hash);Sourcepub fn get_anchor(&self, hash: &str) -> Result<Anchor>
pub fn get_anchor(&self, hash: &str) -> Result<Anchor>
Retrieve an anchor by hash
§Arguments
hash- The SHA-256 hash to look up
§Examples
use reasonkit::verification::ProofLedger;
let ledger = ProofLedger::in_memory()?;
let hash = ledger.anchor("test content", "https://example.com", None)?;
let anchor = ledger.get_anchor(&hash)?;
assert_eq!(anchor.url, "https://example.com");Sourcepub fn verify(
&self,
hash: &str,
current_content: &str,
) -> Result<VerificationResult>
pub fn verify( &self, hash: &str, current_content: &str, ) -> Result<VerificationResult>
Verify current content against anchored hash
Detects if the content has drifted from the original anchored version.
§Arguments
hash- The original hash from the citationcurrent_content- The current content to verify
§Examples
use reasonkit::verification::ProofLedger;
let ledger = ProofLedger::in_memory()?;
let original = "Original content";
let hash = ledger.anchor(original, "https://example.com", None)?;
// Verify with same content
let result = ledger.verify(&hash, original)?;
assert!(result.verified);
// Verify with different content (drift)
let result = ledger.verify(&hash, "Modified content")?;
assert!(!result.verified);Sourcepub fn check_drift(
&self,
hash: &str,
refetched_content: &str,
) -> Result<VerificationResult>
pub fn check_drift( &self, hash: &str, refetched_content: &str, ) -> Result<VerificationResult>
Check for content drift by re-fetching and verifying
This is a higher-level function that would typically:
- Re-fetch content from the URL
- Verify against the anchor
- Return drift status
Note: This function requires external fetch capability. For now, it just verifies the provided content.
§Arguments
hash- The original hashrefetched_content- Content re-fetched from the source
Sourcepub fn list_by_url(&self, url: &str) -> Result<Vec<Anchor>>
pub fn list_by_url(&self, url: &str) -> Result<Vec<Anchor>>
List all anchors for a given URL
Useful for finding all citations from a particular source.
§Arguments
url- The URL to search for
Sourcepub fn ledger_path(&self) -> &Path
pub fn ledger_path(&self) -> &Path
Get the ledger database path
Auto Trait Implementations§
impl !Freeze for ProofLedger
impl !RefUnwindSafe for ProofLedger
impl Send for ProofLedger
impl !Sync for ProofLedger
impl Unpin for ProofLedger
impl !UnwindSafe for ProofLedger
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more