> ## 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/licence-verify

> Leverine Licensing — licence keys, activation, and verification for Leverine products, signed with ML-DSA.

# @leverine/licence-verify

The reference validation library for Leverine Licensing (docs/PLAN.md, Part 2). Apps import it to verify licence tokens **offline** and derive licence state — there is no stored “licensed” flag anywhere; state is a function of the token’s ML-DSA-65 signature, its claims, and the clock.

```ts theme={null}
import { verifyLicence } from "@leverine/licence-verify";

const result = verifyLicence(token, {
  keys,                 // from GET /v1/keys (cache it; pin a fallback set)
  product: "pvez-v2",   // the product this app is
  lastSeenAt,           // the value the previous call returned (persist it)
});
persist(result.lastSeenAt);
switch (result.state) {
  case "licensed":  /* full function */ break;
  case "grace":     /* full function, warn: renewal overdue */ break;
  case "read-only": /* data stays readable/exportable, writes off */ break;
  case "unlicensed":/* no valid token (see result.failure) */ break;
}
```

State machine (decided 2026-12-03): a token is `licensed` until its `exp`, then `grace` for 7 days, then `read-only` — never dead. Structural failures (bad signature, wrong product, unknown `kid`, wrong `alg`, malformed) are `unlicensed` with a `failure` reason.

The clock-rollback guard: pass back the `lastSeenAt` each result returns. Effective time never goes backwards, so winding the system clock cannot extend a licence.

Conformance: the vectors in the repo’s `test/conformance.test.ts` exercise this library against the issuer — valid, grace, read-only, forged, tampered, wrong-product, unknown-kid, wrong-alg, and clock-rollback cases all pinned.

## Lifecycle responses (0.2.0)

When the app can reach the issuer, two more helpers consume the lifecycle API (docs/PLAN.md, L3):

* `applyRefreshResponse(resp, opts)` folds a `POST /v1/refresh` body into a state. It merges CONSERVATIVELY — the effective state is the more restrictive of the state derived from the returned token and the state the server reported — because each side knows something the other doesn’t: the token knows the term, the server knows revocations and Paddle payment state. A `revoked` response derives `unlicensed` with failure `revoked`, even if the token in hand is unexpired. A response claiming `active` with no token derives `unlicensed` / `malformed`: a claim without a token proves nothing.
* `parseActivateResponse(status, body)` classifies a `POST /v1/activate` outcome. `device_cap_reached` is a first-class `cap_reached` result carrying the cap and the live count, so the app can explain the hard refusal and offer deactivation — never a silent displacement.

***

*Source: Leverine/Leverine-Licensing\@7ac3cc9 — `packages/licence-verify/README.md`.*


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