Skip to content

Verify signatures

Every entry in a lookup answer is signed with your organization’s private key. Your software checks it with the matching public key, so a tampered, copied or invented entry is rejected. The public key is safe to build into your software; the private key never leaves LaaSio.

For each entry:

  1. Remove key from the entry.

  2. Encode the rest as JSON:

    • object keys sorted by byte value at every level, including inside limits;
    • no whitespace;
    • / and non-ASCII characters not escaped;
    • null values kept.

    For example, {"a":{"c":"x/ü","d":null},"b":1}.

  3. Check the base64-decoded key as an Ed25519 detached signature of those UTF-8 bytes, using the public key for the entry’s keyVersion.

Then check that clientId equals the client you looked up.

Your organization ID and public key are in LaaSio → Settings in the console.

These examples are the same ones the console’s Develop tab shows with your values filled in. Each one looks up a client, keeps only entries with a valid signature for that client, and prints the active ones. They are tested against LaaSio.

// Node.js 18+ (built-in fetch and Ed25519), save as licenses.mjs
import { createPublicKey, verify } from "node:crypto";
const LAASIO_URL = "https://laasio.functual.com";
const ORG_ID = "lzo_YOUR_ORG_ID";
// Your organization's public key, wrapped in the standard 12-byte Ed25519 header Node expects
const PUBLIC_KEY = createPublicKey({
key: Buffer.concat([Buffer.from("302a300506032b6570032100", "hex"), Buffer.from("YOUR_PUBLIC_KEY_BASE64", "base64")]),
format: "der",
type: "spki",
});
// Keys sorted at every level; JSON.stringify adds no whitespace and leaves "/" and Unicode as-is
function canonical(value) {
if (Array.isArray(value)) return value.map(canonical);
if (value && typeof value === "object") {
return Object.fromEntries(Object.keys(value).sort().map((k) => [k, canonical(value[k])]));
}
return value;
}
/** Return the client's licenses whose signature is valid. */
export async function getLicenses(clientId) {
const url = `${LAASIO_URL}/api/v1/lookup?${new URLSearchParams({ org: ORG_ID, client: clientId })}`;
const response = await fetch(url, { headers: { Accept: "application/json" } });
if (!response.ok) throw new Error(`LaaSio ${response.status}`);
const { data } = await response.json();
return data.filter(({ key, ...signed }) =>
signed.clientId === clientId &&
verify(null, Buffer.from(JSON.stringify(canonical(signed))), PUBLIC_KEY, Buffer.from(key, "base64")));
}
/** A license is active from its start until its end (end null = never expires). */
export function isActive(license, now = new Date()) {
return new Date(license.start) <= now && (license.end === null || now < new Date(license.end));
}
const licenses = await getLicenses("PC-123");
for (const license of licenses.filter((l) => isActive(l))) {
console.log(license.name, license.type, license.limits);
}
  • Sorting only the top level. Keys inside limits must be sorted too.
  • Escaped characters. Many encoders escape / (PHP) or <, > and & (Go) by default. Turn that off, as the examples do.
  • Empty limits in PHP. json_decode($body, true) turns {} into []. Put back an object before encoding, or the bytes differ.
  • Re-serializing numbers. Keep limit values as the integers you received.
  • Skipping the clientId check. A valid entry for another client is still valid; make sure it’s for yours.