File size: 1,558 Bytes
2c41dce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
Proof data model representing a cryptographic proof of existence.
"""

from dataclasses import dataclass, asdict
from typing import Optional
from datetime import datetime
import json


@dataclass
class Proof:
    """
    Immutable proof object containing hash, metadata, and validation info.
    """
    proof_id: str
    content_hash: str
    hash_algorithm: str
    content_type: str
    content_size: int
    timestamp: str
    validation_status: str
    metadata: dict
    extracted_text: Optional[str] = None  # OCR output (if applicable)
    ocr_engine: Optional[str] = None  # Fixed: "tesseract"
    ocr_status: Optional[str] = None  # "success" | "skipped" | "failed"
    
    def to_dict(self) -> dict:
        """Convert proof to dictionary."""
        return asdict(self)
    
    def to_json(self) -> str:
        """Serialize proof to JSON string."""
        return json.dumps(self.to_dict(), indent=2)
    
    @classmethod
    def from_dict(cls, data: dict) -> 'Proof':
        """Create proof from dictionary."""
        return cls(**data)
    
    @classmethod
    def from_json(cls, json_str: str) -> 'Proof':
        """Deserialize proof from JSON string."""
        return cls.from_dict(json.loads(json_str))


@dataclass
class VerificationResult:
    """
    Result of proof verification operation.
    """
    proof_id: str
    is_valid: bool
    original_hash: str
    computed_hash: str
    timestamp: str
    message: str
    
    def to_dict(self) -> dict:
        """Convert result to dictionary."""
        return asdict(self)