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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//! # Storage Module
//!
//! UHRP (Universal Hash Resolution Protocol) file storage for BSV.
//!
//! ## Overview
//!
//! This module provides decentralized file storage using content-addressed UHRP URLs.
//! Files are identified by their SHA-256 hash and stored on overlay network hosts.
//!
//! ## Components
//!
//! - **UHRP URL utilities**: Generate and parse content-addressed URLs
//! - **StorageDownloader**: Download files from UHRP URLs via overlay lookup
//! - **StorageUploader**: Upload files to storage services
//!
//! ## UHRP URL Format
//!
//! UHRP URLs encode a SHA-256 file hash using Base58Check:
//!
//! ```text
//! uhrp://<base58check_encoded_hash>
//! ```
//!
//! The encoding uses:
//! - Prefix: `0xce00` (2 bytes)
//! - Payload: SHA-256 hash (32 bytes)
//! - Checksum: First 4 bytes of SHA256(SHA256(prefix || payload))
//!
//! ## Example
//!
//! ```rust
//! use bsv_rs::storage::{get_url_for_file, get_hash_from_url, is_valid_url};
//!
//! // Generate a UHRP URL for file content
//! let content = b"Hello, World!";
//! let url = get_url_for_file(content).unwrap();
//! assert!(url.starts_with("uhrp://"));
//!
//! // Validate and parse the URL
//! assert!(is_valid_url(&url));
//! let hash = get_hash_from_url(&url).unwrap();
//! assert_eq!(hash.len(), 32);
//! ```
//!
//! ## Downloading Files
//!
//! ```rust,ignore
//! use bsv_rs::storage::{StorageDownloader, StorageDownloaderConfig};
//!
//! let downloader = StorageDownloader::new(StorageDownloaderConfig::default());
//!
//! // Resolve hosts for a UHRP URL
//! let hosts = downloader.resolve("uhrp://...").await?;
//!
//! // Download the file (requires 'http' feature)
//! let result = downloader.download("uhrp://...").await?;
//! println!("Downloaded {} bytes of {}", result.data.len(), result.mime_type);
//! ```
//!
//! ## Uploading Files
//!
//! ```rust,ignore
//! use bsv_rs::storage::{StorageUploader, StorageUploaderConfig, UploadableFile};
//!
//! let config = StorageUploaderConfig::new("https://storage.example.com");
//! let uploader = StorageUploader::new(config);
//!
//! let file = UploadableFile::new(b"Hello".to_vec(), "text/plain");
//! let result = uploader.publish_file(&file, None).await?;
//! println!("Uploaded to: {}", result.uhrp_url);
//! ```
//!
//! ## Feature Requirements
//!
//! - `storage` - Enables the storage module
//! - `http` - Required for actual file download/upload operations
// Re-export types
pub use ;
// Re-export downloader
pub use ;
// Re-export uploader
pub use ;
// Re-export utilities
pub use ;