Rust SDK
License activation for Rust apps with the moonbase crate: CLI tools, egui, iced or Slint apps, or anything else written in Rust.
The crate is open-source under the MIT license, published on crates.io as moonbase, and developed at Moonbase-sh/moonbase-rs. It is the Rust counterpart of the C++ SDK, with the same behaviour, the same error model and the same cross-SDK device ID, so a license activated through any Moonbase SDK validates in your Rust app.
It supports:
- Browser-based activations with polling, and offline activations by machine file
- Local RS256 JWT validation against an embedded public key, with online re-validation and a configurable grace period
- Cross-SDK device identity implementing the Moonbase device fingerprint spec
- Trials, seats, expiry, add-ons and custom properties on the validated license
- Licenses that cover some versions, judged against the running version of your app
- Update checks with release notes and a download link
- Server-side deactivation, so users can free up an activation seat
- Overridable license storage, device ID resolvers and HTTP transports
- No system libraries: crypto is
ring, and HTTP isureqwithrustls
Building a Tauri app? The Tauri plugin is built on this crate and adds a finished, themeable activation UI, so you don't have to build your own.
Requirements
- Rust 1.89 or newer (edition 2024)
- Windows, macOS or Linux
Installation
Add the crate from crates.io:
[dependencies]
moonbase = "0.1"
The bundled HTTP transport sits behind the default ureq-transport feature. Set default-features = false to drop ureq and rustls and supply your own transport.
Configuration
Configure the SDK with your account endpoint, product ID and RS256 public key. You will find all three in the Implementation guide for your product in the Moonbase app.
use moonbase::{FileLicenseStore, Licensing, LicensingOptions};
const PUBLIC_KEY_PEM: &str = include_str!("../moonbase-public-key.pem");
let options = LicensingOptions::new("https://your-account.moonbase.sh", "your-product", PUBLIC_KEY_PEM)
.account_id("your-account-id") // optional issuer check
.application_version("1.4.0"); // reported to Moonbase and compared with your releases
let licensing = Licensing::builder(options)
.store(FileLicenseStore::new(data_dir.join("license.mb")))
.build()?;
The default license store is in-memory. Pass a FileLicenseStore, or your own LicenseStore, to keep the license across launches.
The API is blocking, like the C++ SDK. Licensing is Send + Sync, so share one instance behind an Arc, and in an async app run its calls on a blocking pool such as tokio::task::spawn_blocking.
Browser activation
Request an activation, send the user to its browser URL, and poll until it is fulfilled:
use std::time::Duration;
use moonbase::ActivationMethod;
let request = licensing.request_activation(ActivationMethod::Online)?;
println!("Open: {}", request.browser_url);
let license = loop {
std::thread::sleep(Duration::from_secs(2));
match licensing.complete_activation(&request) {
Ok(Some(license)) => break license, // fulfilled, and stored
Ok(None) => continue, // still pending
Err(moonbase::Error::Api(_)) => continue, // offline or busy, retry
Err(error) => return Err(error.into()), // ended or refused, start over
}
};
Poll every 2 to 3 seconds. Pass ActivationMethod::Offline instead to have the same browser flow issue an offline license, for a machine that has network now but won't later.
Startup validation
On every launch, load and validate the stored license:
match licensing.load_and_validate()? {
Some(license) => unlock(license),
None => offer_activation(),
}
load_and_validate checks the license locally (signature, audience, issuer, device and expiry), re-validates it against the Moonbase API when that is due, and stores the refreshed license. Two LicensingOptions settings control the API cadence and offline tolerance:
online_validation_min_interval(default 5 minutes): when the license was validated more recently than this, the API is skipped, so it's cheap to call on every window or document open.online_validation_grace_period(default 7 days): the longest a license may go without a successful online check. Within it, a network failure falls back to the local result.
A definitive rejection, such as a revoked license or one bound to another device, always propagates. Offline licenses are validated locally and never contact the API.
Revoking activations
Wire revoke_activation to a Deactivate or Sign out button so users can free up the activation seat for the current device:
licensing.revoke_activation(&license.token)?; // frees the seat and clears the store
Only online-activated paid licenses can be revoked. Offline and trial licenses fail with Error::OperationNotSupported without contacting the API.
Errors
Everything fails with moonbase::Error. The variants an app usually acts on:
| Variant | Meaning | What to do |
|---|---|---|
Api | No definitive answer: Moonbase is unreachable, rate limiting or failing | Retry later |
LicenseInvalid, DeviceMismatch | Refused for good, or bound to another device | Lock, and offer to activate again |
ReleaseNotCovered | Valid, but doesn't cover this version of the app | Lock, keep the license, and offer the upgrade |
LicenseExpired | A trial ended, or a subscription lapsed | Lock, and offer to buy |
error.is_license_invalid() is true for LicenseInvalid, DeviceMismatch and ReleaseNotCovered. The core SDK guide lists every variant.
Add-ons
An add-on with Include in the main product's license turned on travels in the main license. When a device activates or validates the main product, it takes a seat of each such add-on the customer owns, so one validation answers for both:
if license.has_sub_product("drum-kit") {
// unlock the drum kit add-on
}
activate_sub_product takes a seat on demand, request_sub_product_trial starts an add-on's trial from the main license, and list_sub_products lists the product's add-ons with their prices, ownership and trial status, for an in-app store or upgrade screen.
Offline activation
For a machine with no network at all, exchange a machine file for a license file:
// Write the machine file for the customer to upload
std::fs::write("device-token.dt", licensing.generate_device_token()?)?;
// Read back the license file they got in return, validate it locally, and store it
let license = licensing.import_offline_license(&std::fs::read_to_string("license.mb")?)?;
Offline licenses are permanent and validated locally, and can't be revoked. See Offline activations for the customer-facing side of the flow.
Tauri plugin
tauri-plugin-moonbase is built on this crate, and brings the whole flow to a Tauri 2 app with a finished activation UI: in its own window, or as an overlay that locks the app until it is licensed. See the Tauri plugin page.
Licenses that cover some versions
Licenses that cover only some releases are in beta, and are switched on account by account. Reach out to support if you'd like to sell them.
A license bought outright can cover only some versions of your app, such as 12 months of updates or every version up to 2.x. Set application_version to the running version, and a license that doesn't cover it fails with Error::ReleaseNotCovered.
Don't delete the stored license when this happens, since it still covers the versions it did. Tell the customer what their license covers, and offer the upgrade:
use moonbase::Error;
match licensing.load_and_validate() {
Ok(Some(license)) => unlock(license),
Ok(None) => offer_activation(),
Err(Error::ReleaseNotCovered(refusal)) => {
// Keep the license, and offer the upgrade
offer_upgrade(refusal.release_access(), refusal.upgrade_url());
}
Err(error) if error.is_license_invalid() => {
licensing.store().delete_local_license()?; // revoked, or not for this device
}
Err(error) => return Err(error),
}
To check another version, such as an update before offering it for download, use license.covers_version(version), which applies the same rule as Moonbase.
In-app updates
A validated license names the product's current release. Compare it with the running version, and fetch the release notes and a download link only when it is newer:
use moonbase::{Platform, can_download, version::update_available};
if let Some(latest) = &license.licensed_product.current_release_version {
if update_available(APP_VERSION, latest) {
let inventory = licensing.inventory();
let release = inventory.get_release(latest, &license.token)?;
if release.has_downloads && can_download(&license, &release) {
let target = inventory.get_download_url(Platform::current().as_str(), &license.token)?;
// target.url is a short-lived download link
}
}
}
Device identity
The default resolver implements the cross-SDK Moonbase device fingerprint spec (version 2, IDs stamped mbd2_): a SHA-256 of stable hardware identifiers, read from IOPlatformUUID on macOS, SMBIOS on Windows, and machine-id plus world-readable DMI fields on Linux. Every Moonbase SDK computes the same ID, so a license activated in a web or Electron app built on @moonbase.sh/licensing, or in a C++ or JUCE app, validates in your Rust app, and the other way round.
Nothing is shelled out to and no root-only file is read, so the same ID comes back whether or not the process is elevated or sandboxed. A machine with no usable hardware identity, such as a cloned VM image or a minimal container, fails with Error::InsufficientDeviceIdentity rather than binding something weak. Supply your own resolver to the builder's device_id_resolver when you need an application-specific device ID.
Sample app
The repository has two examples. activation activates from a terminal against the public Moonbase demo account, so it works out of the box, and device_id prints this machine's device ID:
git clone https://github.com/Moonbase-sh/moonbase-rs.git
cd moonbase-rs
cargo run -p moonbase --example activation
cargo run -p moonbase --example device_id
For a full app, see Aurora on the Tauri plugin page.
Releases and source
The moonbase crate and the Tauri plugin share one version, follow semantic versioning, and are published to crates.io with a GitHub Release for every version. They stay at 0.x while the API settles, so a breaking change bumps the minor version (0.1 to 0.2), which Cargo already treats as incompatible.
The API reference is on docs.rs at moonbase, and the full guides live alongside the source: the core SDK, device identity and security.
The moonbase licensing crate for Rust, and the tauri-plugin-moonbase activation UI built on it.