The offline verification reference describes the token and the checks. This page is the Figma version: a verifier that needs nothing from the browser, bundled into the plugin’s main file, and tied to the Figma user. The call that fetches the token is in license key validation in a Figma plugin.
npm install @noble/ed25519 @noble/hashes
The verifier
@noble/ed25519 verifies synchronously once it has a SHA-512 function. @noble/hashes provides one in plain JavaScript, so nothing depends on crypto.subtle. The same package gives SHA-256 for the fingerprint:
// src/token.js: bundled into code.js. No WebCrypto, no Node.
import * as ed from '@noble/ed25519';
import { sha256, sha512 } from '@noble/hashes/sha2.js';
import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js';
ed.hashes.sha512 = sha512; // the synchronous verify needs a SHA-512 function
const ALPHABET = /^[A-Za-z0-9_-]+$/;
const bytes = (s) =>
ALPHABET.test(s) ? Uint8Array.from(atob(s.replaceAll('-', '+').replaceAll('_', '/')), (c) => c.charCodeAt(0)) : null;
export const sha256Hex = (text) => bytesToHex(sha256(utf8ToBytes(text)));
export function claims(token, publicKey) {
const parts = typeof token === 'string' ? token.split('.') : [];
if (parts.length !== 3 || parts[0] !== 'sgt1') return 'malformed';
const signature = bytes(parts[2]), payload = bytes(parts[1]), key = bytes(publicKey.trim());
if (!signature || signature.length !== 64 || !payload || !key || key.length !== 32) return 'malformed'; // noble throws on wrong lengths
if (!ed.verify(signature, utf8ToBytes(`${parts[0]}.${parts[1]}`), key)) return 'bad-signature';
try {
const c = JSON.parse(new TextDecoder().decode(payload));
return c && typeof c === 'object' ? c : 'malformed';
} catch {
return 'malformed';
}
}
/** 'ok' or the reason. highestIat is the largest iat verified before. now is in seconds. */
export function check(token, { publicKey, productId, fingerprint, highestIat = 0, now = Date.now() / 1000 }) {
const c = claims(token, publicKey);
if (typeof c === 'string') return c;
if (c.v !== 1) return 'malformed';
if (c.pid !== productId) return 'wrong-product';
if (c.valid !== true) return 'not-valid';
if (c.fp !== undefined && c.fp !== fingerprint) return 'other-user';
if (c.exp !== undefined && c.exp <= now) return 'expired';
if (now < highestIat) return 'clock-set-back';
if (!(c.refresh_by > now)) return 'stale';
return 'ok';
}
Only 'ok' should turn the paid features on. 'stale' means validate online once, which the plugin can do the next time it runs. TextDecoder and atob are used here, so check that your plugin API version provides them. If it does not, replace them with the small decoders from @noble/hashes/utils.js and a hand-written base64url table.
Bundle into one file
Figma loads the file named by main in manifest.json. Build one file that holds your code and both libraries:
esbuild src/code.js --bundle --target=es2020 --outfile=code.js
Load the built plugin in Figma, run it once, and verify a token in the real sandbox before you publish. That step covers anything a Node test cannot.
Test results
Tokens signed with a throwaway key in the documented sgt1 format, with a verifier holding its public half. Output from Node:
good=ok withExp=ok expiredExp=expired stale=stale notValid=not-valid wrongProduct=wrong-product wrongVersion=malformed signedByOtherKey=bad-signature tampered=bad-signature twoParts=malformed garbage=malformed realDemoSignedByClavem=bad-signature
tampered is a good token whose payload was edited to extend exp, with the old signature. realDemoSignedByClavem is the live demo token. It decodes, but Clavem signed it with its own key, so a verifier with any other public key has to refuse it. The extra rows, fourParts, wrongPrefix, a clock set back and 15 days later, behaved as in the other guides.
Tie the token to the user
At activation, the plugin sent a fingerprint: a salted SHA-256 of figma.currentUser.id. Clavem put it in the token as fp. The check above compares it with the same hash computed now. A token that was saved while user A was logged in fails for user B on the same computer, even though its signature is valid:
const fingerprint = sha256Hex(`${SALT}:${figma.currentUser.id}`);
const result = check(saved.token, { publicKey: PUBLIC_KEY, productId: PRODUCT_ID, fingerprint, highestIat });
This needs the currentuser permission in the manifest. For a user who is not logged in, figma.currentUser.id can be null, and the plugin falls back to a random id kept in clientStorage, as on the validation page. If you did not send a fingerprint at activation, fp is absent and this comparison is skipped.
The clock guard and storage
Keep the highest iat you have verified in figma.clientStorage, and pass it as highestIat. Raise it only after a check returned 'ok':
const highest = (await figma.clientStorage.getAsync('highestIat')) ?? 0;
const result = check(saved.token, { publicKey: PUBLIC_KEY, productId: PRODUCT_ID, fingerprint, highestIat: highest });
if (result === 'ok') {
const { iat } = claims(saved.token, PUBLIC_KEY);
if (iat > highest) await figma.clientStorage.setAsync('highestIat', iat);
}
Figma documents clientStorage as local to the user’s machine and says to expect that clearing browser data may clear it. A user who does that starts over, and nothing offline can prevent it. The guard stops the casual date change. The token is signed, not secret, and it holds the buyer’s email in readable form. Keep it in clientStorage, and never in setPluginData, which writes it into the document for every collaborator.
Traps in Figma plugins
- The check is client code. Anyone can unpack a plugin and edit it. The signature stops forged tokens and
refresh_bystops old ones. It does not stop a patched plugin. - Do not pull the libraries from a URL. Bundle them. The manifest limits network access to the domains you list, and loading code at run time is a risk you do not need.
- Pin the noble versions. A major release can rename functions.
- Do not verify in the UI thread unless you must. Keep the key and the verdict in
code.js, and send the UI a state string.
Doing this with Clavem
Each product has its own key pair. The public half is on the product page and in GET /v1/admin/products, and every activate and validate response carries a token signed with the private half. See the API reference for the endpoints.
Questions
Why not use crypto.subtle in a Figma plugin?
The plugin main thread is a restricted sandbox, and relying on a browser API there is a risk you can avoid. noble-ed25519 with a SHA-512 from noble-hashes is plain JavaScript, so it needs no browser crypto.
How do I get the plugin into one file?
Figma loads the file named in main. Bundle your sources and the noble libraries with esbuild into that one file, and keep the manifest pointing at it.
Why compare the fp claim with the Figma user?
The fingerprint sent at activation is a hash of the Figma user id, and the token carries it as fp. A token saved for one user then fails for another user on the same computer, even though its signature is valid.