> ## Documentation Index
> Fetch the complete documentation index at: https://docs.leverine.com/llms.txt
> Use this file to discover all available pages before exploring further.

# leverine-licensing-client

> The reusable Kotlin licensing client library: licence activation, ML-DSA verification, and encrypted on-device storage for Leverine Android apps.

# 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

| Module | What it is |
| - | - |
| `licensing-core` | Pure Kotlin/JVM, **zero Android imports**. Token envelope parsing, ML-DSA-65 verification behind the `SignatureVerifier` interface (BouncyCastle reference implementation), entitlement derivation (state / feats / expiry / grace), the LVN key format, and the issuer lifecycle client behind the `HttpTransport` interface. Its tests run on any JVM — that is the portability proof. |
| `licensing-android` | The thin Android layer: Keystore AES-GCM licence storage, an HttpURLConnection transport, and `LicenceManager`, the facade a host app talks to. |
| `licensing-ui-compose` | Optional Compose activation UI (`LicenceActivationSection`) rendering the core’s `LicencePresentation` model. Apps with their own UI toolkit skip it and render the same model themselves (BunnyBridge does — its UI is Views). |

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:

   ```kotlin theme={null}
   // settings.gradle.kts
   includeBuild("../leverine-licensing-client") {
       dependencySubstitution {
           substitute(module("com.leverine:licensing-core"))
               .using(project(":licensing-core"))
           substitute(module("com.leverine:licensing-android"))
               .using(project(":licensing-android"))
           substitute(module("com.leverine:licensing-ui-compose"))
               .using(project(":licensing-ui-compose"))
       }
   }
   ```

   ```kotlin theme={null}
   // app build.gradle.kts
   dependencies {
       implementation("com.leverine:licensing-android")
       // and, for Compose apps:
       implementation("com.leverine:licensing-ui-compose")
   }
   ```

   (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:

   ```kotlin theme={null}
   val licences = LicenceManagerFactory.create(
       context,
       LicenceConfig(
           issuerBaseUrl = "https://licence.leverine.com",
           product = "your-product",
           fallbackKeys = listOf(/* pinned from GET /v1/keys */),
       ),
   )
   ```

4. **Gate features** on the entitlement, with your own feat constants:

   ```kotlin theme={null}
   val state = licences.entitlement()          // offline, instant
   if (state.entitled("unlock")) { /* full function */ }
   ```

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`.*


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.