Leverine · Licensing · Documentation

Integration guide

The end-to-end flow, in the order your app lives it: a purchase issues a licence, the customer activates with their key, the app verifies offline from then on, and refresh keeps the picture current.

01

Purchase issues the licence

Your buyer checks out with Paddle. The transaction.completed webhook reaches your deployment, maps the price to a product and tier, and issues the licence — linked to the Paddle customer and subscription. (Operators can also issue directly via POST /v1/admin/issue.)

02

The customer activates

The buyer receives their LVN- key and pastes it into your app. The app calls POST /v1/activate with a stable per-install instanceId and stores the returned token.

03

The app verifies offline

On every check, the app verifies the stored token’s signature and derives state from the token and the clock — no network, no phone-home. It persists the lastSeenAt the verifier returns, so a rolled-back clock can’t extend anything.

04

Refresh keeps it current

When the app is online, it calls POST /v1/refresh for a fresh token and the server’s current view — revocations, payment grace, cancellation caps — and merges the two views conservatively.

Guide

Step 2 — activate

Choose an instanceId that is stable for the installation (generate one at first run and store it), and a label your customer will recognize in device lists.

curl -X POST https://licence.leverine.com/v1/activate \
  -H 'Content-Type: application/json' \
  -d '{
    "key": "LVN-XXXXX-XXXXX-XXXXX-XXXXX",
    "instanceId": "install-9f27c1",
    "label": "Studio Mac",
    "appVersion": "2.4.1"
  }'

With the reference library, classify the outcome instead of hand-parsing it. device_cap_reached is a first-class result, not an error — your UX should explain it and offer to deactivate another device:

import { parseActivateResponse } from "@leverine/licence-verify";

const res = await fetch(`${issuer}/v1/activate`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ key, instanceId, label, appVersion }),
});
const outcome = parseActivateResponse(res.status, await res.json());

switch (outcome.kind) {
  case "activated":
    storeToken(outcome.token);            // entitlement token, verify offline
    break;
  case "cap_reached":
    // outcome.cap, outcome.activeDeployments — explain, offer deactivation
    break;
  case "error":
    // outcome.error — e.g. "invalid_key", "licence_revoked", "licence_readonly"
    break;
}

Moving a customer to a new machine is the same API from the other side:

curl -X POST https://licence.leverine.com/v1/deactivate \
  -H 'Content-Type: application/json' \
  -d '{ "key": "LVN-XXXXX-XXXXX-XXXXX-XXXXX", "instanceId": "install-old-441" }'

Guide

Step 3 — verify offline

The reference library is @leverine/licence-verify. It verifies ML-DSA-65 tokens against the deployment’s public keys — fetched from GET /v1/keys, cached, with a pinned fallback set in the app build — and derives state on every call:

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;
}

result.failure explains an unlicensed verdict: malformed, wrong_alg, unknown_kid, bad_signature, wrong_product — or revoked, which only a refresh can learn (below). result.claims carries the verified token claims (tier, cap, feats, exp, …) when the signature verified and the product matched.

The clock-rollback guard: pass back the lastSeenAt each result returns. Effective time is max(now, lastSeenAt) — it never goes backwards, so winding the system clock cannot extend a licence. result.clockRollback tells you when a rollback was detected.

The library’s behaviour is pinned by conformance vectors exercised against the issuer — valid, grace, read-only, forged, tampered, wrong-product, unknown-kid, wrong-alg, and clock-rollback cases — so a port to another language has an exact target to match.

Guide

Step 4 — refresh

Tokens live at most 30 days by default, so a purely offline app has a natural horizon: token expiry, then 7 days of grace, then read-only. Refresh whenever the app is online — at launch is a good cadence — to mint a fresh token and learn anything the token can’t know.

import { applyRefreshResponse } from "@leverine/licence-verify";

const res = await fetch(`${issuer}/v1/refresh`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ key, instanceId }),
});
const merged = applyRefreshResponse(await res.json(), {
  keys,
  product: "pvez-v2",
  lastSeenAt,
});
persist(merged.lastSeenAt);
if (merged.token) storeToken(merged.token);

applyRefreshResponse merges conservatively: the effective state is the more restrictive of the state derived from the returned token and the state the server reported — each side knows something the other doesn’t. The token knows the term; the server knows revocations and payment state. Two consequences worth designing around:

  • A revoked response derives unlicensed with failure revoked, even if the token in hand is unexpired. That is the whole point of refreshing.
  • A response claiming active with no token derives unlicensed / malformed — a claim without a token proves nothing.

For support screens, GET /v1/status shows the customer their own licence: state, cap, and every deployment with its label and last-seen time — the data behind a “manage your devices” view.

Putting the states in your UI

StateFunctionSuggested treatment
licensedFullNothing to show.
graceFullA visible renewal warning — payment is overdue, 7-day window running.
read-onlyData readable/exportable; entitled features offExplain the licence lapsed and how to renew; keep the customer’s data open to them.
unlicensedNoneAsk for a key (activation), or explain a revocation if failure is revoked.

Full request/response shapes for every call in this guide are in the API reference; the purchase side of the flow is specified on the webhooks page.