Skip to main content

Crate moonbase

Crate moonbase 

Source
Expand description

§Moonbase licensing for Rust

License activation for desktop apps and audio plugins, against Moonbase: browser and offline activation, local RS256 validation with an offline grace period, revocation, add-ons, licenses that cover only some versions, pluggable storage and HTTP, and the cross-SDK device fingerprint, so a license activated by any Moonbase SDK validates here too.

The Rust port of moonbase-cpp.

use std::{thread, time::Duration};
use moonbase::{ActivationMethod, FileLicenseStore, Licensing, LicensingOptions};

let options = LicensingOptions::new(
    "https://your-tenant.moonbase.sh",
    "your-product",
    "-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----",
);
let licensing = Licensing::builder(options)
    .store(FileLicenseStore::new("license.mb"))
    .build()?;

// On startup: validate what is stored, re-checking online when it is due.
if let Some(license) = licensing.load_and_validate()? {
    println!("Licensed to {}", license.issued_to.email);
    return Ok(());
}

// Otherwise activate through the browser; the license is stored once it lands.
let request = licensing.request_activation(ActivationMethod::Online)?;
println!("Open {}", request.browser_url);
let license = loop {
    thread::sleep(Duration::from_secs(2));
    if let Some(license) = licensing.complete_activation(&request)? {
        break license;
    }
};
println!("Activated for {}", license.issued_to.email);

§What the SDK guarantees, and what it leaves to you

It answers one question soundly: is this license valid, for this product, on this machine, right now? Tokens are RS256 JWTs verified against the public key you embed with the algorithm pinned, bound to your product by audience, and to this machine by a device id recomputed from hardware on every validation. It ships no anti-debugging, obfuscation or tamper detection: hardening only works when it is specific to your binary. See docs/security.md.

Modules§

fingerprint_spec
The Moonbase device fingerprint specification, version 2.
serde_iso8601
Serde adapters for a SystemTime as the license file writes one: YYYY-MM-DDTHH:MM:SSZ, in UTC. For types of your own that carry a license’s times, as #[serde(with = "moonbase::serde_iso8601")], or moonbase::serde_iso8601::option for an Option<SystemTime>.
version
Just enough Semantic Versioning to decide whether the license’s released version (p:rel) is newer than the running app.

Structs§

ActivationRequest
A browser activation in progress. Send the user to browser_url, then poll with Licensing::get_requested_activation.
ApiError
A request that got no definitive answer.
DeviceIdDescription
A device id plus the provenance needed to reason about it: safe to log, show in an about box, or attach to a support ticket.
DeviceIdentity
What a single read of the machine produced.
DownloadTarget
A ready-to-fetch installer URL. The link is presigned and short-lived (the backend expires it after about 15 minutes).
FileLicenseStore
Persists the validated license as JSON in a file, in the same format as the C++ SDK’s file_license_store.
HttpRequest
HttpResponse
InventoryClient
Client for the inventory endpoints.
License
A validated license.
LicenseClient
The raw client API. Most apps use Licensing, which wraps this with storage, throttling and the offline grace period.
LicenseValidator
Validates license tokens locally: signature, audience, issuer, claims, expiry and device binding.
Licensing
The SDK’s entry point: activation, validation, offline licenses, revocation, add-ons and storage, for one product.
LicensingBuilder
Builds a Licensing with a custom store, device id resolver or transport.
LicensingOptions
Connection and validation settings.
MemoryLicenseStore
Keeps the license in memory for the life of the process. The default, so nothing is persisted unless you choose a store.
MigratingDeviceIdResolver
Binds the current fingerprint while still recognising ids this device was bound to before: the migration path off an older algorithm without a flag day.
MoonbaseDeviceIdResolver
The cross-SDK device id: what every Moonbase SDK computes on this machine.
MoonbaseDeviceIdResolverOptions
Product
The licensed product, from the token’s p:* claims.
ReleaseAccess
Which versions of the app a license covers, when it doesn’t cover every one.
ReleaseInfo
A release’s plain-text notes, plus enough to know an installer exists and who may download it.
ReleaseNotCovered
A license that is valid, but doesn’t cover the version of the app that runs: it covers only the releases published while its updates lasted, or versions up to some major. Carried by Error::ReleaseNotCovered.
StaticDeviceIdResolver
A fixed identity. Useful in tests, and for apps that source the device id from somewhere else entirely.
StorageError
Reading or writing the stored license failed, or its lock: a LicenseStore’s own trouble, which says nothing about the license. The I/O failure behind it, when there was one, is its source, and io_error hands it over for a look at its kind.
StoreLockGuard
Exclusive access to a store for as long as it is held, across processes when the store is backed by something shared, such as a file. Returned by LicenseStore::lock_for_update.
SubProduct
One of the product’s add-ons that the merchant includes in its license, as the license reports it for this device. To decide whether to unlock it, use License::has_sub_product, which also checks expires_at.
SubProductCatalog
The product’s add-ons that the customer can do something with: those they own or subscribe to, those on sale, and those whose trial can be started or is running on this device.
SubProductCatalogEntry
One of the product’s add-ons as Licensing::list_sub_products reports it for this device.
SubProductCatalogProduct
The add-on, with its prices when it is for sale, and whether the customer has it.
SubProductPricing
One way an add-on is sold.
SubProductRecurrence
How a price recurs: "OneOff", or "Recurring" with how often it renews ("Daily", "Weekly", "Monthly", "Quarterly" or "Yearly").
SubProductSeats
Seats across all of the customer’s licenses for an add-on.
SubProductTrialOffer
An add-on’s trial on this device, or whether one can be started.
UreqTransport
The bundled blocking transport: ureq with rustls, honouring the system proxy environment variables.
User
The customer the license was issued to, from the token’s u:* claims.

Enums§

ActivationMethod
How a license was activated.
DeviceIdFallback
What to do when no hardware identity is readable.
Error
Everything the SDK can fail with.
ErrorType
What kind of failure an Error is, as a plain value that can be persisted, logged or compared.
Method
Platform
The platform reported to Moonbase with each request, for analytics and platform-specific downloads.
SubProductTrialStatus
Where an add-on’s trial stands on this device.

Constants§

VERSION
This SDK’s version, as sent in the User-Agent.

Traits§

DeviceIdResolver
Identifies this machine to Moonbase.
HttpTransport
Performs one HTTP exchange.
LicenseStore
Persists the validated license.

Functions§

can_download
May license download the installer for a release with these access flags?

Type Aliases§

DeviceIdentityReader
Overrides how the resolver reads the machine. Primarily for testing.
Result
The SDK’s result type.