Clavem

Verify an Ed25519 license token offline in a Blender add-on

Blender's Python has no Ed25519 module, so either bundle a wheel such as PyNaCl in blender_manifest.toml or add a short pure-Python verifier. Verification uses only public data, so the pure-Python version needs no constant-time care and takes a few milliseconds.

Two ways to get Ed25519 into an add-on

The token format and claims are in the offline verification reference. Your add-on must verify an Ed25519 signature, and the Blender manual says an extension has to bring its own dependencies.

Option How Trade-off
Bundled wheels List PyNaCl or cryptography wheels under wheels in blender_manifest.toml audited code, but binary wheels need one file per platform and Python version, and the manifest needs matching platforms
Pure-Python module Add ed25519.py to the add-on no binaries, runs on every platform and in legacy add-ons, but it is code you maintain

For a verifier, the second is reasonable. Verification never touches a secret: the public key, the message and the signature are all public, so timing side channels do not matter. A signing implementation would not get that pass. This one cannot sign.

The verifier

This is RFC 8032 section 5.1.7 in about sixty lines. It needs Python 3.8 or later, because of pow(x, -1, p). It rejects a signature whose S is not below the group order, and points that are not on the curve.

"""Ed25519 signature verification in pure Python (RFC 8032). Verify only: no signing, no secrets."""
import hashlib

_P = 2**255 - 19
_L = 2**252 + 27742317777372353535851937790883648493
_D = -121665 * pow(121666, -1, _P) % _P
_SQRT_M1 = pow(2, (_P - 1) // 4, _P)


def _recover_x(y, sign):
    x2 = (y * y - 1) * pow(_D * y * y + 1, -1, _P) % _P
    x = pow(x2, (_P + 3) // 8, _P)
    if (x * x - x2) % _P:
        x = x * _SQRT_M1 % _P
    if (x * x - x2) % _P:
        return None  # not a point on the curve
    if x == 0 and sign:
        return None
    return _P - x if (x & 1) != sign else x


def _decode(data):
    y = int.from_bytes(data, "little")
    sign, y = y >> 255, y & ((1 << 255) - 1)
    if y >= _P:
        return None
    x = _recover_x(y, sign)
    return None if x is None else (x, y, 1, x * y % _P)


def _encode(point):
    zinv = pow(point[2], -1, _P)
    x, y = point[0] * zinv % _P, point[1] * zinv % _P
    return (y | ((x & 1) << 255)).to_bytes(32, "little")


def _add(p, q):
    a = (p[1] - p[0]) * (q[1] - q[0]) % _P
    b = (p[1] + p[0]) * (q[1] + q[0]) % _P
    c = 2 * p[3] * q[3] * _D % _P
    d = 2 * p[2] * q[2] % _P
    e, f, g, h = b - a, d - c, d + c, b + a
    return (e * f % _P, g * h % _P, f * g % _P, e * h % _P)


def _mul(scalar, point):
    result = (0, 1, 1, 0)
    while scalar:
        if scalar & 1:
            result = _add(result, point)
        point = _add(point, point)
        scalar >>= 1
    return result


_BASE_Y = 4 * pow(5, -1, _P) % _P
_BASE_X = _recover_x(_BASE_Y, 0)
_BASE = (_BASE_X, _BASE_Y, 1, _BASE_X * _BASE_Y % _P)


def verify(public_key: bytes, message: bytes, signature: bytes) -> bool:
    if len(public_key) != 32 or len(signature) != 64:
        return False
    a = _decode(public_key)
    r = _decode(signature[:32])
    s = int.from_bytes(signature[32:], "little")
    if a is None or r is None or s >= _L:
        return False
    k = int.from_bytes(hashlib.sha512(signature[:32] + public_key + message).digest(), "little") % _L
    return _encode(_mul(s, _BASE)) == _encode(_add(r, _mul(k, a)))

The token checks

import base64, hashlib, json, re, time
from . import ed25519

PUBLIC_KEY = "YOUR_PUBLIC_KEY"  # from your product page: 32 raw bytes, base64url
PRODUCT_ID = 75  # from your product page


def _b64url(value: str) -> bytes:
    return base64.urlsafe_b64decode(value + "=" * (-len(value) % 4))


def verify_token(token: str):
    """Returns the claims when the signature is good, otherwise None."""
    parts = token.split(".")
    if len(parts) != 3 or parts[0] != "sgt1":
        return None
    try:
        # The signed text is the first two parts exactly as received.
        signed = f"{parts[0]}.{parts[1]}".encode("ascii")
        if not ed25519.verify(_b64url(PUBLIC_KEY), signed, _b64url(parts[2])):
            return None
        claims = json.loads(_b64url(parts[1]))
    except ValueError:  # bad base64, bad JSON, non-ASCII text
        return None
    return claims if isinstance(claims, dict) else None


def is_licensed(claims, now=None) -> bool:
    now = time.time() if now is None else now
    return (
        claims is not None
        and claims.get("v") == 1
        and claims.get("pid") == PRODUCT_ID
        and claims.get("valid") is True
        and claims.get("exp", float("inf")) > now
        and claims.get("refresh_by", 0) > now
    )


def clock_went_back(state: dict, claims: dict, now=None) -> bool:
    """Call save(state) afterwards. A clock earlier than an iat already seen means it was set back."""
    now = time.time() if now is None else now
    state["max_iat"] = max(state.get("max_iat", 0), claims["iat"])
    return now + 300 < state["max_iat"]  # five minutes of slack for ordinary drift

What I ran

The verifier passes the first two test vectors in RFC 8032 section 7.1, fails when the message changes by a byte, and rejects a signature whose S is at or above the group order. It also agrees with Node’s Ed25519 on the eight test tokens, signed with a throwaway key pair in Clavem’s format: the valid one is licensed, and the tampered, other-key, stale, valid: false, other-product, v: 2 and past-exp ones are not. One verify_token() call took about 2 ms on my machine under CPython 3.14.

That is not Blender’s interpreter. The code ran under a stub bpy, outside Blender, so time it in the Python your Blender release ships.

Blender traps

  • The manifest. If you choose wheels instead, list one per platform, for example ./wheels/<package>-<version>-cp313-cp313-win_amd64.whl as in the manual, and set platforms to match. The manual’s own example does this for Python 3.13. A platform without a matching wheel has no copy of the dependency.
  • Import path. An extension is loaded as a package, so import its own modules relatively (from . import ed25519), as above, not by an absolute name.
  • Where the token lives. Keep it with the key in the file from the validation guide, under extension_path_user, so an upgrade does not delete it.
  • Readable code. The add-on is Python on the user’s disk. Anyone can edit is_licensed(). Obfuscating it would make support harder and would not stop anyone who wants to bypass it.
  • Offline is normal. Machines on a render farm and laptops on location often have no network. The 14-day window in refresh_by is for them: after it, ask the user to connect once.

Doing this with Clavem

Each product has its own key pair. The public key on the product page is the only value your add-on needs to verify tokens offline. The token decoder shows the claims of any token you paste.

Questions

Why not just pip install PyNaCl inside Blender?

An extension has to be self-contained, so its dependencies ship inside it. The Blender manual says to bundle third-party modules as wheels listed in the manifest, or to vendor pure-Python ones. Binary wheels need one file per platform and Python version.

Can I copy the license to my render nodes?

A token is not bound to a device unless you compare its iid or fp claim with what you stored at activation, so copying the file works mechanically. Whether that is allowed is a matter for your license terms, and nodes will need a fresh token every 14 days.

Sources

  1. Blender manual, Python Wheels (checked November 2026)
  2. Blender manual, add-ons (bundle dependencies, local storage; checked November 2026)
  3. Blender manual, getting started with extensions (manifest wheels and platforms; checked November 2026)