Clavem

Verify an Ed25519 license token offline in Godot

Godot 4 has no Ed25519 verifier. Its Crypto class signs and verifies with RSA keys, and HashingContext stops at SHA-256. In practice you verify the sgt1 token in a small C# autoload with BouncyCastle and check the claims in GDScript.

Your options

Clavem tokens are Ed25519 signatures over the text sgt1.<payload>. Godot’s Crypto.verify takes a CryptoKey, which is RSA, so it cannot check them.

Option Cost Verdict
C# autoload with BouncyCastle Needs the .NET build of Godot. Pure managed code, no native binaries. Use this if you can.
GDExtension around libsodium A native library per export platform, and a build step for each. Reasonable for a studio with that pipeline. I did not test one.
Pure GDScript SHA-512 and 255-bit arithmetic to write yourself, on 64-bit ints. Not recommended.
Saved timestamp, no signature Trivial. Forgeable by editing a file. Honest outage grace only.

The C# half

Add the package to your .csproj. Godot’s C# guide says it downloads new NuGet references on the next build.

<ItemGroup>
  <PackageReference Include="BouncyCastle.Cryptography" Version="2.7.0" />
</ItemGroup>

Save this as LicenseToken.cs and add it as an autoload named LicenseToken. It does one job, the signature, and returns the payload text:

using Godot;
using System;
using System.Text;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Crypto.Signers;

public partial class LicenseToken : Node
{
    static byte[] B64Url(string s)
    {
        s = s.Replace('-', '+').Replace('_', '/');
        s = s.PadRight(s.Length + (4 - s.Length % 4) % 4, '='); // the token has no padding
        return Convert.FromBase64String(s);
    }

    /// The payload JSON when the Ed25519 signature is good, otherwise an empty string.
    public string VerifySignature(string token, string publicKey)
    {
        try
        {
            var parts = token.Split('.');
            if (parts.Length != 3 || parts[0] != "sgt1") return "";
            byte[] key = B64Url(publicKey), sig = B64Url(parts[2]), body = B64Url(parts[1]);
            if (key.Length != 32 || sig.Length != 64) return "";

            var signer = new Ed25519Signer();
            signer.Init(false, new Ed25519PublicKeyParameters(key, 0));
            byte[] signed = Encoding.ASCII.GetBytes(parts[0] + "." + parts[1]); // the text as received
            signer.BlockUpdate(signed, 0, signed.Length);
            return signer.VerifySignature(sig) ? Encoding.UTF8.GetString(body) : "";
        }
        catch (Exception) { return ""; } // bad base64, bad key
    }
}

The GDScript half

GDScript calls C# methods directly, by their C# names, and the engine marshals the arguments. Keeping the claim checks in GDScript means they run without .NET and are easy to test.

class_name LicenseOffline

const PUBLIC_KEY := "YOUR_PUBLIC_KEY"  # from your product page: 32 raw bytes, base64url
const PRODUCT_ID := 75                  # from your product page
const CLOCK_SLACK := 600                # seconds of clock error to forgive

## Changes saved["high_iat"]. The caller saves the dictionary.
static func is_fresh(saved: Dictionary) -> bool:
	var claims := claims_if_signed(saved.get("token", ""))
	if claims.is_empty():
		return false
	var now := int(Time.get_unix_time_from_system())
	var seen := int(saved.get("high_iat", 0))
	if now + CLOCK_SLACK < seen:
		return false  # the clock is behind a time the server already stamped
	saved["high_iat"] = maxi(seen, int(claims.get("iat", 0)))
	return is_licensed(claims, now)

static func claims_if_signed(token: String) -> Dictionary:
	var payload: String = LicenseToken.VerifySignature(token, PUBLIC_KEY)  # the C# autoload
	if payload == "":
		return {}
	var parsed = JSON.parse_string(payload)
	return parsed if parsed is Dictionary else {}

static func is_licensed(c: Dictionary, now: int) -> bool:
	if c.is_empty():
		return false
	return c.get("v") == 1 and c.get("pid") == PRODUCT_ID and c.get("valid") == true \
		and (not c.has("exp") or c["exp"] > now) and c.get("refresh_by", 0) > now

These are the five checks from the reference. JSON.parse_string reads numbers with to_float(), so pid is 75.0. GDScript compares that equal to 75, so the checks hold as written.

Without C#

If your project cannot use the .NET build, nothing in GDScript replaces the signature. What you can do is keep the last successful validation time and allow a window after it:

# Not verification. A player can edit this file. It only keeps honest customers running through an outage.
static func within_grace(saved: Dictionary, days := 14) -> bool:
	return Time.get_unix_time_from_system() - float(saved.get("last_ok", 0)) < days * 86400.0

Write last_ok when validate answers 200. Say so plainly in your own threat model: this stops no one who edits a file.

Test tokens

Godot cannot mint Ed25519 tokens, so make test tokens with Node, sign them with a throwaway key, and pass its public key to LicenseToken.VerifySignature in a test scene. This script prints a good token, a stale one, one for another product and an expired one:

// mint.mjs
import { generateKeyPairSync, sign } from 'node:crypto';
const { publicKey, privateKey } = generateKeyPairSync('ed25519');
const enc = (b) => Buffer.from(b).toString('base64url');
const now = Math.floor(Date.now() / 1000);
const mint = (claims) => {
  const head = 'sgt1.' + enc(JSON.stringify(claims)); // the signed text is this string, as is
  return head + '.' + enc(sign(null, Buffer.from(head), privateKey));
};
const base = { v: 1, lid: 1, pid: 75, kh: '0'.repeat(16), status: 'active', valid: true, iat: now, refresh_by: now + 14 * 86400 };
console.log(JSON.stringify({
  publicKey: publicKey.export({ format: 'jwk' }).x,
  good: mint(base),
  stale: mint({ ...base, refresh_by: now - 86400 }),
  other_product: mint({ ...base, pid: 99 }),
  expired: mint({ ...base, status: 'expired', valid: false }),
}, null, 2));

I ran this script and checked its output with Node’s own Ed25519 verification: good verifies and is licensed, while stale, other_product and expired verify but are not licensed.

Godot-specific notes

  • The public key is a constant in a script inside the PCK. Anyone can read it, which is fine, and anyone can patch it in a modified build, which no client check prevents.
  • Where the token lives is the same file as the key, from the validation page.
  • Clock. Time.get_unix_time_from_system() is the player’s clock. The high_iat guard catches a clock moved behind a time the server stamped. It does not catch someone who deletes the file.
  • Exports. C# projects export with the .NET runtime, and not every platform in the Godot export list supports C# builds. Check your targets before you commit to this route.

Doing this with Clavem

Each product has its own key pair. Copy the public key from the product page. The token comes back on every activate and validate call, so there is no extra request. The reference in offline verification lists every claim.

Questions

Can I verify an Ed25519 signature in pure GDScript?

In theory, in practice no. Ed25519 needs SHA-512, which HashingContext does not offer, and 255-bit integer arithmetic, while GDScript's int is 64 bits. You would write both from scratch, and it would be slow.

Is a saved timestamp good enough instead?

It covers honest outages, and nothing else. A player can edit a file in user:// to any date. Without a signature check the offline path is not verification, and you should treat it as a goodwill window.

Sources

  1. Godot docs, Crypto class (checked November 2026)
  2. Godot docs, HashingContext, hash types (checked November 2026)
  3. Godot docs, int is a signed 64-bit integer (checked November 2026)
  4. Godot docs, C# basics, using NuGet packages (checked November 2026)
  5. Godot docs, cross-language scripting (checked November 2026)