offline_license_validator/lib.rs
1//! # Offline License Validator
2//!
3//! A simple, secure offline license validation library using Ed25519 signatures.
4//!
5//! ## Features
6//!
7//! - **Ed25519 Cryptography**: Industry-standard signature verification
8//! - **HWID Binding**: Licenses are bound to specific hardware
9//! - **Expiration Checking**: Automatic expiration validation
10//! - **Persistent Storage**: Saves validated licenses to `~/.offline-license/`
11//! - **Easy Integration**: Simple API - just provide public key
12//!
13//! ## Quick Start
14//!
15//! ```rust,no_run
16//! use offline_license_validator::{LicenseValidator, storage};
17//!
18//! // Initialize validator with your public key
19//! let validator = LicenseValidator::new(
20//! "913d5e19269699e51bcdb5c5a7106c278ef0e0fe92d31b76b6daf5bb00594fcf"
21//! ).expect("Invalid public key");
22//!
23//! // Validate license
24//! match validator.validate("license_string_here", "hardware_id_here") {
25//! Ok(info) => {
26//! println!("✓ Valid license!");
27//! println!("Type: {}", info.license_type);
28//! println!("Expires: {}", info.expires_at);
29//!
30//! // Save to disk for offline use
31//! storage::save_license(&info, "license_string_here").ok();
32//! }
33//! Err(e) => eprintln!("✗ Invalid license: {}", e),
34//! }
35//! ```
36//!
37//! ## Storage
38//!
39//! Validated licenses are automatically saved to:
40//! - **Unix/macOS**: `~/.offline-license/license.json`
41//! - **Windows**: `%USERPROFILE%\.offline-license\license.json`
42//!
43//! ## Security
44//!
45//! - Public key is hardcoded in your application
46//! - Ed25519 signatures prevent tampering
47//! - HWID binding prevents license sharing
48//! - No network required for validation
49//!
50//! ## Integration with Tauri
51//!
52//! ```rust,ignore
53//! #[tauri::command]
54//! fn verify_license(license: String, hwid: String) -> Result<String, String> {
55//! let validator = LicenseValidator::new(PUBLIC_KEY)
56//! .map_err(|e| e.to_string())?;
57//!
58//! let info = validator.validate(&license, &hwid)
59//! .map_err(|e| e.to_string())?;
60//!
61//! storage::save_license(&info, &license).ok();
62//!
63//! Ok(format!("Valid until: {}", info.expires_at))
64//! }
65//! ```
66//!
67//! ## Credits
68//!
69//! Developed by [Krakiun](https://krakiun.com) - Expert Software Development & Security Solutions
70//!
71//! **Need custom licensing solutions?** Visit [krakiun.com](https://krakiun.com)
72
73pub mod storage;
74pub mod types;
75pub mod validator;
76
77// Re-export main types for convenience
78pub use types::{LicensePayload, ValidLicenseInfo};
79pub use validator::{LicenseError, LicenseValidator};
80
81#[cfg(test)]
82mod tests {
83 use super::*;
84
85 #[test]
86 fn test_library_basic_usage() {
87 // This test verifies that the public API works
88 let result = LicenseValidator::new("invalid");
89 assert!(result.is_err());
90 }
91}