confium_transparency/ots/proof.rs
1//! OTS proof types.
2
3use serde::{Deserialize, Serialize};
4
5/// An OpenTimestamps proof (compact form).
6///
7/// In real OTS format, this is a sequence of attestation operations.
8/// Here we model it semantically; serialization to .ots file format
9/// is a separate concern.
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct OtsProof {
12 /// Original hash that was stamped.
13 pub hash: [u8; 32],
14 /// Bitcoin block height where the attestation anchor was mined.
15 pub bitcoin_height: u32,
16 /// Merkle branch from the hash to the block's Merkle root (if direct anchor).
17 pub merkle_branch: Vec<[u8; 32]>,
18 /// The Bitcoin block's Merkle root.
19 pub merkle_root: [u8; 32],
20 /// Calendar server that facilitated the stamping (if applicable).
21 #[serde(default)]
22 pub calendar_server: Option<String>,
23}
24
25impl OtsProof {
26 /// Construct a new proof.
27 pub fn new(hash: [u8; 32], bitcoin_height: u32) -> Self {
28 Self {
29 hash,
30 bitcoin_height,
31 merkle_branch: Vec::new(),
32 merkle_root: [0u8; 32],
33 calendar_server: None,
34 }
35 }
36}
37
38/// Verification result.
39#[derive(Debug, Clone)]
40pub struct OtsVerification {
41 /// Whether the proof is valid.
42 pub valid: bool,
43 /// Bitcoin block height anchoring the proof.
44 pub bitcoin_height: u32,
45 /// Approximate timestamp (from Bitcoin block header).
46 pub block_timestamp: Option<u64>,
47}
48
49/// Errors during OTS operations.
50#[derive(Debug, thiserror::Error)]
51pub enum OtsError {
52 /// Calendar server unreachable.
53 #[error("calendar server unreachable: {0}")]
54 CalendarUnreachable(String),
55 /// Proof invalid.
56 #[error("proof invalid: {0}")]
57 InvalidProof(String),
58 /// Bitcoin backend unavailable.
59 #[error("Bitcoin backend unavailable: {0}")]
60 BitcoinBackend(String),
61}