Client Library Reference

A minimal C library for offline license verification. Drop it into your application to validate license files locally — no network calls required.

Setup Types lfg_license_verify Accessors Error Codes Example

Setup

Copy these four files into your project:

Download Client Library (.tar)

lfg-license.h      /* Client library header */
lfg-license.c      /* Client library implementation */
monocypher.h       /* Monocypher crypto header */
monocypher.c       /* Monocypher crypto implementation */

Then include the header where needed:

#include "lfg-license.h"

Optionally, download lfg-license-defs.h from your project's settings page. This generated header provides named constants for your products and features:

#include "lfg-license.h"
#include "lfg-license-defs.h"  /* Generated: product & feature enums */
The library is self-contained C99 with no external dependencies beyond Monocypher. It compiles on any platform with a standard C compiler.

Keys

Each product has a unique Ed25519 signing keypair. You will need the public key for your product, available in the organization panel under Products.

lfg_license_keys_t keys;

/* Copy your product's 32-byte public key */
memcpy(keys.public_key, my_public_key, 32);
The public key is displayed as a hex string in the admin panel. You will need to decode it to raw bytes before use.

Types

lfg_license_keys_t

Public key needed for license verification.

FieldTypeDescription
public_keyuint8_t[32]Ed25519 public signing key for your product

lfg_license_t

Decoded license data, populated by lfg_license_verify().

FieldTypeDescription
product_iduint8_tProduct identifier
license_typeuint8_tLFG_LICENSE_TYPE_COMPUTER (1) or LFG_LICENSE_TYPE_NAMED_USER (2)
expiryuint32_tUnix timestamp, or 0 for perpetual
keychar[20]License key string (XXXX-XXXX-XXXX-XXXX)
computer_countuint8_tNumber of activated computers
computers[]arrayEach entry has .len and .uin (the computer's unique identifier)
feature_countuint8_tNumber of features
features[]arrayEach entry has .id and .state (LFG_FEATURE_ENABLED or LFG_FEATURE_DISABLED)

Constants

NameValueDescription
LFG_LICENSE_TYPE_COMPUTER1Computer-locked license
LFG_LICENSE_TYPE_NAMED_USER2Named user license
LFG_FEATURE_ENABLED2Feature is enabled
LFG_FEATURE_DISABLED1Feature is disabled

Core Function

lfg_license_verify

lfg_license_error_t lfg_license_verify(const lfg_license_keys_t *keys, const char *base64_blob, lfg_license_t *out)

Verifies the Ed25519 signature on a base64-encoded license blob. On success, populates out with the decoded license data.

ParameterDescription
keysProduct public key
base64_blobBase64-encoded license file contents (from the /api/activate response)
outPointer to lfg_license_t to receive decoded license data

Returns: LFG_OK (0) on success, or an error code.

Convenience Accessors

Helper functions for common license checks. All take a const lfg_license_t * pointer.

lfg_license_is_perpetual

bool lfg_license_is_perpetual(const lfg_license_t *l)

Returns true if the license never expires (expiry is 0).

lfg_license_is_expired

bool lfg_license_is_expired(const lfg_license_t *l)

Returns true if the license has passed its expiry date. Always returns false for perpetual licenses.

lfg_license_days_to_expiry

int lfg_license_days_to_expiry(const lfg_license_t *l)

Returns the number of days until expiry. Returns -1 for perpetual licenses, 0 if already expired.

lfg_license_has_feature

bool lfg_license_has_feature(const lfg_license_t *l, uint8_t feature_id)

Returns true if the license contains the given feature (regardless of state).

lfg_license_feature_enabled

bool lfg_license_feature_enabled(const lfg_license_t *l, uint8_t feature_id)

Returns true if the feature exists and is enabled. Returns false if the feature is missing or disabled.

lfg_license_has_computer

bool lfg_license_has_computer(const lfg_license_t *l, const char *uin)

Returns true if the given computer UIN is present in the license’s activation list.

Error Codes

Returned by lfg_license_verify():

CodeValueDescription
LFG_OK0Success
LFG_ERR_DECODE1Base64 decoding failed
LFG_ERR_TOO_SHORT2Decoded blob is too short to be valid
LFG_ERR_SIGNATURE3Ed25519 signature verification failed (wrong key or tampered data)
LFG_ERR_PARSE4Binary payload is malformed

Example

Typical usage in an application startup routine:

#include "lfg-license.h"
#include <stdio.h>

/* Your product's keys (decoded from hex) */
static const lfg_license_keys_t my_keys = {
    .public_key = { /* 32 bytes */ },
};

int
check_license(const char *license_blob, const char *my_computer_uin)
{
    lfg_license_t lic;
    lfg_license_error_t err = lfg_license_verify(&my_keys, license_blob, &lic);

    if (err != LFG_OK)
    {
        fprintf(stderr, "License verification failed (error %d)\n", err);
        return -1;
    }

    /* Check this computer is authorized */
    if (!lfg_license_has_computer(&lic, my_computer_uin))
    {
        fprintf(stderr, "License not activated for this computer\n");
        return -1;
    }

    /* Check expiry */
    if (lfg_license_is_expired(&lic))
    {
        fprintf(stderr, "License has expired\n");
        return -1;
    }

    if (!lfg_license_is_perpetual(&lic))
    {
        printf("License expires in %d days\n",
               lfg_license_days_to_expiry(&lic));
    }

    /* Check features (using constants from lfg-license-defs.h) */
    if (lfg_license_feature_enabled(&lic, LFG_FEATURE_MYAPP_PRO))
    {
        printf("Pro feature unlocked\n");
    }

    return 0; /* License is valid */
}

API Reference · Home