LicenseChain Rust SDK
Official Rust SDK for LicenseChain - Secure license management for Rust applications.
๐ Features
- ๐ 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
๐ฆ Installation
Method 1: Cargo (Recommended)
Add to your Cargo.toml:
[]
= "1.0.0"
Method 2: Git Repository
[]
= { = "https://github.com/LicenseChain/LicenseChain-Rust-SDK.git" }
Method 3: Local Path
[]
= { = "path/to/licensechain-sdk" }
๐ Quick Start
Basic Setup
use ;
async
User Authentication
// Register a new user
match client.register.await
// Login existing user
match client.login.await
License Management
// Validate a license
match client.validate_license.await
// Get user's licenses
match client.get_user_licenses.await
Hardware ID Validation
// Get hardware ID (automatically generated)
let hardware_id = client.get_hardware_id;
println!;
// Validate hardware ID with license
match client.validate_hardware_id.await
Webhook Integration
// Set up webhook handler
client.set_webhook_handler;
// Start webhook listener
client.start_webhook_listener.await?;
๐ API Endpoints
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.
Base URL
https://api.licensechain.app/v1
Available Endpoints
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.
๐ API Reference
LicenseChainClient
Constructor
let config = new
.api_key
.app_name
.version
.base_url; // Optional
let mut client = new;
Methods
Connection Management
// Connect to LicenseChain
client.connect.await?;
// Disconnect from LicenseChain
client.disconnect.await?;
// Check connection status
let is_connected = client.is_connected;
User Authentication
// Register a new user
let user = client.register.await?;
// Login existing user
let user = client.login.await?;
// Logout current user
client.logout.await?;
// Get current user info
let user = client.get_current_user.await?;
License Management
// Validate a license
let license = client.validate_license.await?;
// Get user's licenses
let licenses = client.get_user_licenses.await?;
// Create a new license
let license = client.create_license.await?;
// Update a license
let license = client.update_license.await?;
// Revoke a license
client.revoke_license.await?;
// Extend a license
let license = client.extend_license.await?;
Hardware ID Management
// Get hardware ID
let hardware_id = client.get_hardware_id;
// Validate hardware ID
let is_valid = client.validate_hardware_id.await?;
// Bind hardware ID to license
client.bind_hardware_id.await?;
Webhook Management
// Set webhook handler
client.set_webhook_handler;
// Start webhook listener
client.start_webhook_listener.await?;
// Stop webhook listener
client.stop_webhook_listener.await?;
Analytics
// Track event
let mut properties = new;
properties.insert;
properties.insert;
client.track_event.await?;
// Get analytics data
let analytics = client.get_analytics.await?;
๐ง Configuration
Environment Variables
Set these in your environment or through your build process:
# Required
# Optional
Advanced Configuration
let config = new
.api_key
.app_name
.version
.base_url
.timeout // Request timeout
.retries // Number of retry attempts
.debug // Enable debug logging
.user_agent; // Custom user agent
๐ก๏ธ Security Features
Hardware ID Protection
The SDK automatically generates and manages hardware IDs to prevent license sharing:
// Hardware ID is automatically generated and stored
let hardware_id = client.get_hardware_id;
// Validate against license
let is_valid = client.validate_hardware_id.await?;
Secure Communication
- All API requests use HTTPS
- API keys are securely stored and transmitted
- Session tokens are automatically managed
- Webhook signatures are verified
License Validation
- Real-time license validation
- Hardware ID binding
- Expiration checking
- Feature-based access control
๐ Analytics and Monitoring
Event Tracking
// Track custom events
let mut properties = new;
properties.insert;
properties.insert;
client.track_event.await?;
// Track license events
let mut license_properties = new;
license_properties.insert;
license_properties.insert;
client.track_event.await?;
Performance Monitoring
// Get performance metrics
let metrics = client.get_performance_metrics.await?;
println!;
println!;
println!;
๐ Error Handling
Custom Error Types
match client.validate_license.await
Retry Logic
// Automatic retry for network errors
let config = new
.api_key
.app_name
.version
.retries // Retry up to 3 times
.timeout; // Wait 30 seconds for each request
๐งช Testing
Unit Tests
# Run tests
# Run tests with output
# Run specific test
Integration Tests
# Test with real API
๐ Examples
See 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)
๐ค Contributing
We welcome contributions! Please see our Contributing Guide for details.
Development Setup
- Clone the repository
- Install Rust 1.70 or later
- Build:
cargo build - Test:
cargo test
๐ License
This project is licensed under the Elastic License 2.0 (ELv2) โ see the LICENSE file for details.
๐ Support
- Documentation: https://docs.licensechain.app/rust
- Issues: GitHub Issues
- Discord: LicenseChain Discord
- Email: support@licensechain.app
๐ Related Projects
Made with โค๏ธ for the Rust community
LicenseChain API (v1)
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