# ProofMode Python Bindings (UniFFI)
Python bindings for ProofMode using UniFFI for consistent cross-language support.
## Installation
```bash
# Install dependencies
pip install maturin
# Build and install the Python package
maturin develop --features uniffi,python
# Or install from wheel
pip install .
```
## Usage
### Basic Usage
```python
import proofmode
# Create ProofMode instance
pm = proofmode.create_proofmode(
storage_path="./proofs",
email="user@example.com",
passphrase="secure_passphrase"
)
# Generate proof from file
proof_hash = pm.generate_proof_from_file("photo.jpg", {"description": "Test photo"})
print(f"Proof generated: {proof_hash}")
# Check files
result = pm.check_files(["photo.jpg"])
print(f"Verification result: {result}")
```
### With Progress Callbacks
```python
import proofmode
class MyProgressCallback(proofmode.ProgressCallback):
def report_progress(self, message):
print(f"Progress: {message}")
# Create ProofMode instance
pm = proofmode.create_proofmode("./proofs", "user@example.com", "pass")
# Generate proof with progress reporting
progress = MyProgressCallback()
result = pm.check_files(["photo.jpg"], progress)
```
### Platform-Specific Callbacks (for mobile-like usage)
```python
import proofmode
class MyPlatformCallbacks(proofmode.PlatformCallbacks):
def get_location(self):
return proofmode.LocationInfo(
latitude=37.7749,
longitude=-122.4194,
altitude=None,
accuracy=10.0,
provider="python_gps"
)
def get_device_info(self):
return proofmode.DeviceInfo(
manufacturer="Python",
model="VM",
os_version="3.11",
device_id="python_device",
imei=None
)
def get_network_info(self):
return proofmode.NetworkInfo(
network_type="wifi",
carrier=None,
cell_tower_id=None,
wifi_ssid="MyNetwork"
)
def save_data(self, hash_val, filename, data):
with open(f"./proofs/{hash_val}/{filename}", "wb") as f:
f.write(data)
return True
def save_text(self, hash_val, filename, text):
with open(f"./proofs/{hash_val}/{filename}", "w") as f:
f.write(text)
return True
def sign_data(self, data):
# Return mock signature
return b"mock_signature_" + data[:10]
# Use with callbacks
pm = proofmode.create_proofmode("./proofs", "user@example.com", "pass")
callbacks = MyPlatformCallbacks()
progress = MyProgressCallback()
with open("photo.jpg", "rb") as f:
media_data = f.read()
proof_hash = pm.generate_proof_with_callbacks(
media_data,
{"description": "Photo with platform data"},
callbacks,
progress
)
```
## API Reference
### Core Functions
- `create_proofmode(storage_path, email, passphrase)` - Create ProofMode instance
- `generate_proof_simple(file_path, storage_path, email, passphrase, metadata?)` - Simple proof generation
- `check_files_simple(files)` - Simple file checking
- `get_proofmode_version()` - Get version string
### ProofMode Class
#### Methods
- `generate_proof_from_file(file_path, metadata?)` - Generate proof from file path
- `generate_proof_from_data(media_data, metadata?)` - Generate proof from bytes
- `generate_proof_with_callbacks(media_data, metadata?, callbacks, progress?)` - Generate with platform callbacks
- `check_files(files, progress?)` - Check files with optional progress
- `check_urls(urls, progress?)` - Check URLs with optional progress
- `check_cids(cids, progress?)` - Check IPFS CIDs with optional progress
- `get_file_hash(data)` - Get SHA-256 hash of data
- `get_version()` - Get version string
### Callback Interfaces
#### ProgressCallback
- `report_progress(message)` - Called during operations
#### PlatformCallbacks
- `get_location()` - Return LocationInfo or None
- `get_device_info()` - Return DeviceInfo or None
- `get_network_info()` - Return NetworkInfo or None
- `save_data(hash, filename, data)` - Save binary data, return bool
- `save_text(hash, filename, text)` - Save text data, return bool
- `sign_data(data)` - Sign data, return signature bytes or None
### Data Structures
#### LocationInfo
- `latitude: float`
- `longitude: float`
- `altitude: Optional[float]`
- `accuracy: Optional[float]`
- `provider: Optional[str]`
#### DeviceInfo
- `manufacturer: str`
- `model: str`
- `os_version: str`
- `device_id: str`
- `imei: Optional[str]`
#### NetworkInfo
- `network_type: str`
- `carrier: Optional[str]`
- `cell_tower_id: Optional[str]`
- `wifi_ssid: Optional[str]`
## Error Handling
All operations can raise `ProofModeError` with variants:
- `Io` - I/O errors
- `PgpError` - PGP/cryptographic errors
- `StorageError` - Storage backend errors
- `SerializationError` - JSON/data serialization errors
- `Configuration` - Configuration errors
- `InvalidInput` - Invalid input parameters
- `NotFound` - Resource not found
- `CheckError` - Verification errors
```python
try:
proof_hash = pm.generate_proof_from_file("photo.jpg")
print(f"Success: {proof_hash}")
except proofmode.ProofModeError.Io as e:
print(f"I/O Error: {e}")
except proofmode.ProofModeError.PgpError as e:
print(f"Crypto Error: {e}")
```