Skip to main content

leverine-licensing-client

The reusable client library for the Leverine licensing system (issuer: Leverine/Leverine-Licensing, live at licence.leverine.com). BunnyBridge is its first consumer (v0.5.0); it is not the owner — every Leverine app that needs licence unlocking uses this library instead of re-implementing token verification. There are no user accounts in this system. The licence key is the handle; the issuer returns a signed token (ML-DSA-65, FIPS 204); the client verifies it offline and refreshes it when online.

Modules

The core’s only runtime dependency is BouncyCastle (bcprov-jdk18on) — the JVM/Android platform has no ML-DSA verifier for raw external keys, and the issuer signs with ML-DSA-65. Interop with the issuer’s @noble/post-quantum signatures is pinned by golden-vector tests in licensing-core (tokens minted by the issuer’s own TypeScript code).

Semantics (identical to the issuer’s reference client)

  • Token states: licensed → grace (7 days past expiry, full function, refresh overdue) → read-only (evidence of a lapsed licence, grants nothing). Anything else is unlicensed with a failure: malformed / wrong_alg / unknown_kid / bad_signature / wrong_product / revoked.
  • Expiry is judged against max(now, lastSeenAt): rolling the device clock back cannot extend a licence. Persist the lastSeenAt the verifier returns (LicenceManager does this for you).
  • Refresh merges conservatively: the more restrictive of (verified token state, server state) wins; a server revoked wins over everything, including a still-valid token.
  • Activation is hard-refuse at the device cap: CapReached is a first-class outcome, never a silent displacement of another device.

Adding the library to an app

  1. Declare your product in the Licensing repo’s catalogue (docs/catalogue-<product>.md there): product id, tiers, feat strings, device cap. Feat names are yours — the library treats them as opaque strings.
  2. Consume the build. During development, as a composite build:
    (Published coordinates com.leverine:licensing-* are the plan once a Leverine maven repo exists; the composite build is the supported route today.)
  3. Create the manager once, at app start:
  4. Gate features on the entitlement, with your own feat constants:
  5. Render activation. Compose apps drop in LicenceActivationSection(state, onActivate, onDeactivate). Other UIs render LicencePresentation.describe(state, markerFeat) — headline, detail, which actions make sense — or build their own model on EntitlementState.
  6. Wire the lifecycle off the main thread: licences.activate(key, label, appVersion), licences.refresh() (on launch / on reconnect), licences.deactivate(). All outcomes are sealed types; the cap refusal and revocation are values, not exceptions.

Rules for consumers

  • Never log or persist a licence key anywhere but the library’s own encrypted store.
  • The DIRECT_CHANNEL question is the host app’s own build decision; the library knows nothing about channels.
  • If you change verification semantics, you change them here, for every app, with the golden vectors still green.

Source: Leverine/leverine-licensing-client@e078fc4 — README.md.