Official Rust SDK for LicenseChain - Secure license management for Rust applications.
- 🔐 Secure Authentication - User registration, login, and session management
- 📜 License Management - Create, validate, update, and revoke licenses
- 🛡️ Hardware ID Validation - Prevent license sharing and unauthorized access
- 🔔 Webhook Support - Real-time license events and notifications
- 📊 Analytics Integration - Track license usage and performance metrics
- ⚡ High Performance - Optimized for production workloads
- 🔄 Async Operations - Non-blocking HTTP requests and data processing
- 🛠️ Easy Integration - Simple API with comprehensive documentation
Add to your Cargo.toml:
[dependencies]
licensechain-sdk = "1.0.0"[dependencies]
licensechain-sdk = { git = "https://github.com/LicenseChain/LicenseChain-Rust-SDK.git" }[dependencies]
licensechain-sdk = { path = "path/to/licensechain-sdk" }use licensechain_sdk::{LicenseChainClient,LicenseChainConfig};#[tokio::main]asyncfnmain() -> Result<(),Box<dyn std::error::Error>>{// Initialize the clientlet config = LicenseChainConfig::new().api_key("your-api-key").app_name("your-app-name").version("1.0.0");letmut client = LicenseChainClient::new(config);// Connect to LicenseChain
client.connect().await?;println!("Connected to LicenseChain successfully!");Ok(())}// Register a new usermatch client.register("username","password","email@example.com").await{Ok(user) => {println!("User registered successfully!");println!("User ID: {}", user.id);}Err(e) => eprintln!("Registration failed: {}", e),}// Login existing usermatch client.login("username","password").await{Ok(user) => {println!("User logged in successfully!");println!("Session ID: {}", user.session_id);}Err(e) => eprintln!("Login failed: {}", e),}// Validate a licensematch client.validate_license("LICENSE-KEY-HERE").await{Ok(license) => {println!("License is valid!");println!("License Key: {}", license.key);println!("Status: {}", license.status);println!("Expires: {}", license.expires);println!("Features: {:?}", license.features);println!("User: {}", license.user);}Err(e) => eprintln!("License validation failed: {}", e),}// Get user's licensesmatch client.get_user_licenses().await{Ok(licenses) => {println!("Found {} licenses:", licenses.len());for(i, license)in licenses.iter().enumerate(){println!(" {}. {} - {} (Expires: {})", i + 1, license.key, license.status, license.expires);}}Err(e) => eprintln!("Failed to get licenses: {}", e),}// Get hardware ID (automatically generated)let hardware_id = client.get_hardware_id();println!("Hardware ID: {}", hardware_id);// Validate hardware ID with licensematch client.validate_hardware_id("LICENSE-KEY-HERE",&hardware_id).await{Ok(is_valid) => {if is_valid {println!("Hardware ID is valid for this license!");}else{println!("Hardware ID is not valid for this license.");}}Err(e) => eprintln!("Hardware ID validation failed: {}", e),}// Set up webhook handler
client.set_webhook_handler(|event, data| {println!("Webhook received: {}", event);match event.as_str(){"license.created" => {ifletSome(license_key) = data.get("licenseKey"){println!("New license created: {}", license_key);}}"license.updated" => {ifletSome(license_key) = data.get("licenseKey"){println!("License updated: {}", license_key);}}"license.revoked" => {ifletSome(license_key) = data.get("licenseKey"){println!("License revoked: {}", license_key);}}
_ => {}}});// Start webhook listener
client.start_webhook_listener().await?;Use the canonical LicenseChain API base URL https://api.licensechain.app/v1. The SDK also accepts the root host and normalizes requests to the same API version.
https://api.licensechain.app/v1
All endpoints use the /v1 prefix:
- Health Check:
GET /v1/health - Authentication:
POST /v1/auth/register- Register new userPOST /v1/auth/login- User loginGET /v1/auth/me- Get current userPOST /v1/auth/logout- User logout
- Applications:
GET /v1/apps- List all appsGET /v1/apps/:id- Get app by IDPOST /v1/apps- Create new appPUT /v1/apps/:id- Update appDELETE /v1/apps/:id- Delete app
- Licenses:
GET /v1/licenses- List licensesGET /v1/licenses/:id- Get license by IDPOST /v1/apps/:id/licenses- Create licensePOST /v1/licenses/verify- Verify license keyPATCH /v1/licenses/:id- Update licensePATCH /v1/licenses/:id/revoke- Revoke license
- Webhooks:
GET /v1/webhooks- List webhooksPOST /v1/webhooks- Create webhookGET /v1/webhooks/:id- Get webhook by IDPUT /v1/webhooks/:id- Update webhookDELETE /v1/webhooks/:id- Delete webhook
- Analytics:
GET /v1/analytics/stats- Get analytics data
Note: The SDK accepts either the root host or the canonical
/v1base and normalizes endpoint calls automatically.
let config = LicenseChainConfig::new().api_key("your-api-key").app_name("your-app-name").version("1.0.0").base_url("https://api.licensechain.app/v1");// Optionalletmut client = LicenseChainClient::new(config);// Connect to LicenseChain
client.connect().await?;// Disconnect from LicenseChain
client.disconnect().await?;// Check connection statuslet is_connected = client.is_connected();// Register a new userlet user = client.register(username, password, email).await?;// Login existing userlet user = client.login(username, password).await?;// Logout current user
client.logout().await?;// Get current user infolet user = client.get_current_user().await?;// Validate a licenselet license = client.validate_license(license_key).await?;// Get user's licenseslet licenses = client.get_user_licenses().await?;// Create a new licenselet license = client.create_license(app_id, user_email, metadata).await?;// Update a licenselet license = client.update_license(license_key, updates).await?;// Revoke a license
client.revoke_license(license_key).await?;// Extend a licenselet license = client.extend_license(license_key, days).await?;// Get hardware IDlet hardware_id = client.get_hardware_id();// Validate hardware IDlet is_valid = client.validate_hardware_id(license_key,&hardware_id).await?;// Bind hardware ID to license
client.bind_hardware_id(license_key,&hardware_id).await?;// Set webhook handler
client.set_webhook_handler(handler);// Start webhook listener
client.start_webhook_listener().await?;// Stop webhook listener
client.stop_webhook_listener().await?;// Track eventletmut properties = HashMap::new();
properties.insert("level".to_string(),"1".to_string());
properties.insert("playerCount".to_string(),"10".to_string());
client.track_event("app.started", properties).await?;// Get analytics datalet analytics = client.get_analytics(time_range).await?;Set these in your environment or through your build process:
# Requiredexport LICENSECHAIN_API_KEY=your-api-key
export LICENSECHAIN_APP_NAME=your-app-name
export LICENSECHAIN_APP_VERSION=1.0.0
# Optionalexport LICENSECHAIN_BASE_URL=https://api.licensechain.app/v1
export LICENSECHAIN_DEBUG=truelet config = LicenseChainConfig::new().api_key("your-api-key").app_name("your-app-name").version("1.0.0").base_url("https://api.licensechain.app/v1").timeout(Duration::from_secs(30))// Request timeout.retries(3)// Number of retry attempts.debug(false)// Enable debug logging.user_agent("MyApp/1.0.0");// Custom user agentThe SDK automatically generates and manages hardware IDs to prevent license sharing:
// Hardware ID is automatically generated and storedlet hardware_id = client.get_hardware_id();// Validate against licenselet is_valid = client.validate_hardware_id(license_key,&hardware_id).await?;- All API requests use HTTPS
- API keys are securely stored and transmitted
- Session tokens are automatically managed
- Webhook signatures are verified
- Real-time license validation
- Hardware ID binding
- Expiration checking
- Feature-based access control
// Track custom eventsletmut properties = HashMap::new();
properties.insert("level".to_string(),"1".to_string());
properties.insert("playerCount".to_string(),"10".to_string());
client.track_event("app.started", properties).await?;// Track license eventsletmut license_properties = HashMap::new();
license_properties.insert("licenseKey".to_string(),"LICENSE-KEY".to_string());
license_properties.insert("features".to_string(),"premium,unlimited".to_string());
client.track_event("license.validated", license_properties).await?;// Get performance metricslet metrics = client.get_performance_metrics().await?;println!("API Response Time: {}ms", metrics.average_response_time);println!("Success Rate: {:.2}%", metrics.success_rate *100.0);println!("Error Count: {}", metrics.error_count);match client.validate_license("invalid-key").await{Ok(license) => {// Handle valid license}Err(LicenseChainError::InvalidLicense) => {eprintln!("License key is invalid");}Err(LicenseChainError::ExpiredLicense) => {eprintln!("License has expired");}Err(LicenseChainError::NetworkError(e)) => {eprintln!("Network connection failed: {}", e);}Err(e) => {eprintln!("LicenseChain error: {}", e);}}// Automatic retry for network errorslet config = LicenseChainConfig::new().api_key("your-api-key").app_name("your-app-name").version("1.0.0").retries(3)// Retry up to 3 times.timeout(Duration::from_secs(30));// Wait 30 seconds for each request# Run tests
cargo test# Run tests with output
cargo test -- --nocapture
# Run specific test
cargo test test_validate_license# Test with real API
cargo test --test integration_testsSee the examples/ directory:
basic_usage.rs— Basic SDK usagelicense_assertion_jwks.rs—POST /v1/licenses/verifythen RS256license_tokenvia JWKS (cargo run --example license_assertion_jwks; JWKS athttps://api.licensechain.app/v1/licenses/jwks)jwks_only.rs— token +license_jwks_urionly (cargo run --example jwks_only; JWKS_EXAMPLE_PRIORITY)
We welcome contributions! Please see our Contributing Guide for details.
- Clone the repository
- Install Rust 1.70 or later
- Build:
cargo build - Test:
cargo test
This project is licensed under the Elastic License 2.0 (ELv2) — see the LICENSE file for details.
- Documentation: https://docs.licensechain.app/rust
- Issues: GitHub Issues
- Discord: LicenseChain Discord
- Email: support@licensechain.app
Made with ❤️ for the Rust community
This SDK targets the LicenseChain HTTP API v1 implemented by the LicenseChain API service.
- Production base URL:https://api.licensechain.app/v1
- API reference:docs.licensechain.app
- Baseline REST mapping (documented for integrators):
- GET /health
- POST /auth/register
- POST /licenses/verify
- PATCH /licenses/:id/revoke
- PATCH /licenses/:id/activate
- PATCH /licenses/:id/extend
- GET /analytics/stats