LicenseSeat Rust SDK
Official Rust SDK for LicenseSeat — simple, secure software licensing for desktop apps, games, CLI tools, and plugins.
Table of Contents
- Installation
- Quick Start
- License Lifecycle
- Entitlements
- Offline Validation
- Heartbeat & Seat Tracking
- Event System
- Configuration
- Error Handling
- Telemetry & Privacy
- Examples
- Feature Flags
- API Reference
Installation
Add to your Cargo.toml:
Or manually:
[]
= "0.1"
With Offline Validation
For Ed25519 cryptographic offline validation:
With Native TLS
To use your system's TLS instead of rustls:
Quick Start
use ;
async
License Lifecycle
Activation
Activation binds a license key to this device and consumes a seat:
use ;
let sdk = new;
// Simple activation
let license = sdk.activate.await?;
println!;
println!;
// Activation with options
let license = sdk.activate_with_options.await?;
When to activate:
- First app launch with a new license key
- When the user enters a different license key
- After a deactivation (switching devices)
Validation
Validation checks the license status without consuming a new seat:
let result = sdk.validate.await?;
if result.valid else
// Check for warnings (e.g., expiring soon)
if let Some = &result.warnings
When to validate:
- On app launch (after initial activation)
- Periodically in the background (SDK does this automatically)
- Before performing license-gated operations
Deactivation
Deactivation releases the seat, allowing activation on another device:
// Deactivate current device
sdk.deactivate.await?;
println!;
When to deactivate:
- User clicks "Deactivate" in settings
- During app uninstall (if you have an uninstaller)
- When switching to a different license key
Entitlements
Entitlements provide fine-grained feature gating beyond simple license validity.
Quick Check
// Simple boolean check
if sdk.has_entitlement
if sdk.has_entitlement
Detailed Status
use EntitlementReason;
let status = sdk.check_entitlement;
println!;
println!;
match status.reason
List All Entitlements
for entitlement in sdk.entitlements
Offline Validation
For environments with unreliable network or air-gapped systems, enable offline validation:
use ;
use Duration;
let config = Config ;
let sdk = new;
Fallback Modes
| Mode | Behavior |
|---|---|
NetworkOnly |
Always require network. Fail if offline. (Default) |
AllowOffline |
Try network first, fall back to cached token if unavailable |
OfflineFirst |
Use cached token first, sync with server when online |
How It Works
- On successful validation, the server returns a signed offline token
- The token is cryptographically signed with Ed25519
- The SDK caches the token locally
- When offline, the SDK verifies the signature and checks expiration
- After
max_offline_days, the token expires and network is required
Clock Tampering Protection
The SDK includes safeguards against clock manipulation:
- Tokens include
nbf(not before) andexp(expiration) timestamps - Significant clock jumps are detected and flagged
- Backward clock movement invalidates offline tokens
Heartbeat & Seat Tracking
Heartbeats enable real-time seat tracking for concurrent user limits:
use Duration;
let config = Config ;
let sdk = new;
// Manual heartbeat
let response = sdk.heartbeat.await?;
println!;
Seat Release
If heartbeats stop (app crash, network loss, user closes app), the seat is released after the grace period configured in your LicenseSeat dashboard.
Continuous Heartbeat Loop
use interval;
let sdk = new;
let sdk_clone = sdk.clone;
spawn;
Event System
Subscribe to SDK events for reactive UI updates:
use ;
let sdk = new;
// Get event receiver
let mut events = sdk.subscribe;
// Spawn event handler
spawn;
Event Types
| Event | Description |
|---|---|
ActivationSuccess |
License successfully activated |
ActivationError |
Activation failed (invalid key, limit exceeded, etc.) |
ValidationSuccess |
License validated successfully |
ValidationFailed |
Validation failed (expired, suspended, etc.) |
DeactivationSuccess |
License deactivated, seat released |
DeactivationError |
Deactivation failed |
HeartbeatSuccess |
Server acknowledged heartbeat |
HeartbeatError |
Heartbeat failed (network error, etc.) |
Configuration
Full Configuration Example
use ;
use Duration;
let config = Config ;
let sdk = new;
Configuration Reference
| Option | Type | Default | Description |
|---|---|---|---|
api_key |
String |
— | Your LicenseSeat API key (required) |
product_slug |
String |
— | Your product slug (required) |
api_base_url |
String |
https://licenseseat.com/api/v1 |
API base URL |
auto_validate_interval |
Duration |
1 hour | Background validation interval |
heartbeat_interval |
Duration |
5 minutes | Heartbeat interval |
offline_fallback_mode |
OfflineFallbackMode |
NetworkOnly |
Offline validation behavior |
max_offline_days |
u32 |
0 |
Grace period for offline mode (days) |
telemetry_enabled |
bool |
true |
Send device telemetry |
app_version |
Option<String> |
None |
Your app version (for analytics) |
debug |
bool |
false |
Enable debug logging |
Error Handling
The SDK uses a unified Error type:
use ;
async
Error Types
| Error | Description |
|---|---|
InvalidLicenseKey |
The license key is invalid or doesn't exist |
LicenseExpired |
The license has expired |
LicenseSuspended |
The license has been suspended |
DeviceLimitExceeded |
Maximum device limit reached |
NotActivated |
Tried to validate/deactivate without activation |
NetworkError |
Network request failed |
OfflineValidationFailed |
Offline token invalid or expired |
InvalidSignature |
Ed25519 signature verification failed |
Telemetry & Privacy
The SDK collects minimal telemetry to help you understand your user base:
Collected automatically:
- Device ID (hardware-based, stable identifier)
- OS name and version
- Platform (e.g., "macos-arm64")
- SDK version
You can add:
- App version via
config.app_version
Not collected:
- Personal information
- File system data
- Network information beyond API calls
- User behavior or analytics
Disabling Telemetry
let config = Config ;
Examples
DevHeartbeat
Simple demo showing the full license lifecycle:
LICENSESEAT_API_KEY=your_key \
LICENSESEAT_PRODUCT_SLUG=your_product \
LICENSESEAT_LICENSE_KEY=your_license \
Stress Test
Comprehensive test covering 12 scenarios:
Scenarios tested:
- Activation with valid key
- Validation after activation
- Heartbeat functionality
- Telemetry collection
- Entitlement checking
- Non-existent entitlement handling
- Offline configuration
- Event subscription
- Multiple subscriptions
- Concurrent operations
- Full lifecycle
- SDK cloning
Feature Flags
| Feature | Description | Dependencies Added |
|---|---|---|
default |
Uses rustls for TLS | reqwest/rustls-tls |
native-tls |
Use system TLS instead | reqwest/native-tls |
offline |
Ed25519 offline validation | ed25519-dalek, sha2, base64 |
API Reference
Full API documentation is available at docs.rs/licenseseat.
Key Types
// Main SDK instance
// Configuration
// License data
// Entitlements
// Events
// Responses
// Errors
pub type Result<T> = Result;
License
MIT License. See LICENSE for details.