@softactivate/licensing-core
v5.0.3
Published
SoftActivate Licensing SDK - Core library for Browser and Node.js
Maintainers
Readme
@softactivate/licensing-core
WebAssembly build of the SoftActivate Licensing SDK for Browser and Node.js environments.
Features
- 🚀 Cross-platform - Works in browsers and Node.js
- 📦 Dual-build - ESM and CommonJS support
- 🔒 License Key Generation - Create cryptographically secure license keys
- ✅ License Key Validation - Validate keys without network calls
- 🔑 ECC Signatures - Uses elliptic curve cryptography
- 📄 Template Serialization - Save/load templates as XML or JSON
Installation
npm install @softactivate/licensing-coreQuick Start
Node.js (ESM)
import createLicensing from '@softactivate/licensing-core';
async function main() {
// Initialize the WASM module
const licensing = await createLicensing();
const {
SDK,
LicenseTemplate,
KeyGenerator,
KeyValidator,
FIELD_TYPE_INTEGER,
FIELD_TYPE_STRING
} = licensing;
// =========================================================
// KEY GENERATION (server-side only, requires SDK license)
// =========================================================
// Set SDK license key (required for generating key pairs and license keys)
// ⚠️ NEVER include this in customer-facing software!
SDK.setLicenseKey('YOUR-SDK-LICENSE-KEY');
// Create a license template
const template = new LicenseTemplate();
template.setNumberOfGroups(6);
template.setCharactersPerGroup(5);
template.setSignatureSize(110);
template.setDataSize(40);
// Generate signing key pair
template.generateSigningKeyPair();
// Add data fields
template.addDataField('UserID', FIELD_TYPE_INTEGER, 16, 0);
template.addDataField('Edition', FIELD_TYPE_STRING, 24, 16);
// Save template with private key (keep secure on server)
const privateTemplate = template.saveJson(true);
// Save public certificate (safe to embed in customer software)
const publicCert = template.getPublicKeyCertificate();
// Generate a license key
const generator = new KeyGenerator();
generator.setLicenseTemplate(template);
generator.setIntKeyData('UserID', 12345);
generator.setStringKeyData('Edition', 'PRO');
const licenseKey = generator.generateKey();
console.log('Generated key:', licenseKey);
generator.destroy();
template.destroy();
// =========================================================
// KEY VALIDATION (client-side, no SDK license needed)
// =========================================================
// Create template with public certificate only
const clientTemplate = new LicenseTemplate();
clientTemplate.setPublicKeyCertificate(publicCert);
clientTemplate.setNumberOfGroups(6);
clientTemplate.setCharactersPerGroup(5);
clientTemplate.addDataField('UserID', FIELD_TYPE_INTEGER, 16, 0);
clientTemplate.addDataField('Edition', FIELD_TYPE_STRING, 24, 16);
// Validate the license key
const validator = new KeyValidator();
validator.setLicenseTemplate(clientTemplate);
validator.setKey(licenseKey);
if (validator.isKeyValid()) {
console.log('Valid! UserID:', validator.queryIntKeyData('UserID'));
console.log('Edition:', validator.queryStringKeyData('Edition'));
}
// Cleanup
validator.destroy();
clientTemplate.destroy();
}
main();Node.js (CommonJS)
const createLicensing = require('@softactivate/licensing-core');
async function main() {
const licensing = await createLicensing();
// ... same as above
}
main();Browser
<script type="module">
import createLicensing from '@softactivate/licensing-core';
async function main() {
const licensing = await createLicensing();
// ... same as above
}
main();
</script>Or with a bundler (webpack, rollup, vite, etc.):
import createLicensing from '@softactivate/licensing-core';
// Client-side validation - no SDK license key needed!
async function validateLicenseKey(key, publicCertificate) {
const licensing = await createLicensing();
const template = new licensing.LicenseTemplate();
template.setPublicKeyCertificate(publicCertificate);
// ... configure template
const validator = new licensing.KeyValidator();
validator.setLicenseTemplate(template);
validator.setKey(key);
return validator.isKeyValid();
}API Reference
Initialization
createLicensing()
Initialize the WASM module and return the licensing API. This is an async function that must be awaited.
import createLicensing from '@softactivate/licensing-core';
const licensing = await createLicensing();The returned licensing object contains all classes and constants:
SDK- SDK registrationLicenseTemplate- License key template configurationKeyGenerator- License key generationKeyValidator- License key validationLicensingClient- Online activation clientLicense- License data containerLicenseValidationArgs- Validation argumentsLicenseValidationResult- Validation result- Constants:
FIELD_TYPE_*,ENCODING_*,STATUS_*
SDK
SDK.setLicenseKey(key)
Set the SDK license key. Required only for generating key pairs and license keys (server-side operations).
⚠️ WARNING: Never include the SDK license key in customer-facing software. It is only needed for:
template.generateSigningKeyPair()generator.generateKey()
License key validation only requires the public certificate and does not need the SDK license key.
// Server-side only!
SDK.setLicenseKey('XXXXX-XXXXX-XXXXX-XXXXX-XXXXX');SDK.isRegistered()
Check if the SDK is registered.
const isRegistered = SDK.isRegistered();LicenseTemplate
The LicenseTemplate class defines the structure and format of license keys.
const template = new LicenseTemplate();
// Key format
template.setNumberOfGroups(6); // e.g., XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
template.setCharactersPerGroup(5);
template.setGroupSeparator('-');
template.setEncoding(ENCODING_BASE32X);
// Cryptographic parameters
template.setSignatureSize(110); // Signature bits
template.setDataSize(40); // Data bits
// Generate or set keys
template.generateSigningKeyPair();
// or
template.setPublicKeyCertificate(certBase64);
template.setPrivateKey(keyBase64);
// Define data fields
template.addDataField('FieldName', FIELD_TYPE_INTEGER, bitSize, offset);
// Serialization
const xml = template.saveXml(true); // Include private key
const json = template.saveJson(false); // Public only
// Cleanup
template.destroy();KeyGenerator
Generate license keys from a template.
const generator = new KeyGenerator();
generator.setLicenseTemplate(template);
// Set key data
generator.setIntKeyData('UserID', 12345);
generator.setStringKeyData('Name', 'ABC');
generator.setDateKeyData('Expiry', 2026, 12, 31);
// Generate key
const key = generator.generateKey();
generator.destroy();KeyValidator
Validate license keys and extract embedded data.
const validator = new KeyValidator();
validator.setLicenseTemplate(template);
validator.setKey(licenseKey);
if (validator.isKeyValid()) {
const userId = validator.queryIntKeyData('UserID');
const name = validator.queryStringKeyData('Name');
const { year, month, day } = validator.queryDateKeyData('Expiry');
}
validator.destroy();Constants
Field Types
FIELD_TYPE_RAW(0) - Raw binary dataFIELD_TYPE_INTEGER(1) - Integer valueFIELD_TYPE_STRING(2) - String valueFIELD_TYPE_DATE14(3) - Date (14-bit format)FIELD_TYPE_DATE16(4) - Date (16-bit format)FIELD_TYPE_DATE13(5) - Date (13-bit format)
Encoding Types
ENCODING_BASE32X(5) - Base32 encoding (default)ENCODING_BASE64X(6) - Base64 encoding
Status Codes
STATUS_SUCCESS(0)STATUS_GENERIC_ERROR(1)STATUS_INVALID_LICENSE_KEY(6)- ... and more
Building from Source
Prerequisites
- Emscripten SDK
- CMake 3.15+
- Node.js 14+
Build Steps
Install Emscripten SDK:
git clone https://github.com/emscripten-core/emsdk.git cd emsdk ./emsdk install latest ./emsdk activate latestBuild the WASM module:
cd src/server/licensing-core # Unix/Git Bash EMSDK_PATH=/path/to/emsdk ./scripts/build.shThe output files will be in the project root:
index.js- ESM moduleindex.cjs- CommonJS moduleindex.d.ts- TypeScript definitions
Browser Compatibility
- Chrome 57+
- Firefox 52+
- Safari 11+
- Edge 16+
Node.js Compatibility
- Node.js 14+
License
See LICENSE file.
Support
For support, visit https://www.softactivate.com or contact [email protected].
