API Reference

StickCode v6.0.15 runtime — buffer, stream, and license APIs.

const stickcode = require('stickcode');

License & device

async initFromFile(path?)

Loads a *.lic file from disk, verifies the RSA signature, activates the device on first run, and derives the AES key. Returns the resolved license path.

const licensePath = await stickcode.initFromFile();
// or: await stickcode.initFromFile('/etc/stickcode/license.lic');

async init(licenseJson)

Same as initFromFile but accepts a parsed license object ({ payload, signature }) instead of a file path.

getMachineId()

Returns the SHA-256 hardware fingerprint (hostname + platform + arch) used for device binding.

getLicenseFeatures()

Returns feature flags from the license payload after successful init().

resetDevices()

Deletes the local .device_registry cache in node_modules/stickcode/. Forces re-activation on next init(). Does not free a server-side device slot.

stickcode.resetDevices();

Buffer API

encrypt(input, options?)

Preprocess → Brotli → AES-256-GCM. Requires init() first in licensed builds. Returns a Buffer in wire format [version:1][iv:12][tag:16][ciphertext…] where version is 0x05.

Options:
  • quality (number, default 6) — Brotli level 0–11
  • preprocessFlags (number, default 0) — bitmask: FLAGS.CLEAN, FLAGS.LOWERCASE, FLAGS.TRANSPOSE
  • tokenize (boolean, default false)
const packed = stickcode.encrypt(inputBuffer, { quality: 6, preprocessFlags: 0 });

decrypt(input)

Reverses encrypt(). Verifies the GCM auth tag before decompression. No quality parameter needed.

const restored = stickcode.decrypt(packed);

compressOnly(input, options?)

Brotli only — no AES. Wire format version 0x00.

const blob = stickcode.compressOnly(input, { quality: 6 });

Streaming API

async pipeEncrypt(source, dest, options?)

Stream encrypt from a readable to a writable. Wire format: [version:1][iv:12][ciphertext…][tag:16]. Use for large files and binary assets.

await stickcode.pipeEncrypt(
  fs.createReadStream('video.mp4'),
  fs.createWriteStream('video.mp4.scnp'),
  { quality: 6 }
);

async pipeDecrypt(source, dest)

Stream decrypt a .scnp file back to plain output. Auto-detects buffer vs stream layout.

createEncryptStream(options?) / createDecryptStream()

Low-level stream pair for custom pipelines. Returns { input, output } (decrypt: { input: decIn, output: decOut }).

const { input, output } = stickcode.createEncryptStream({ quality: 6 });
const { input: decIn, output: decOut } = stickcode.createDecryptStream();

Pipeline helpers

encodePipeline(input, options?) / decodePipeline(input)

Compress / decompress without the AES wrapper or version byte.

CLI

Binary name: stick (via npx stick or node node_modules/stickcode/stick.js).

Command Description
stick enc <file>Encrypt + compress → .scnp
stick dec <file.scnp>Decrypt + decompress

Common flags: --license <path>, --quality <0-11>, --stream / --buffer, -o <output>. Production requires --license or STICKCODE_LICENSE_FILE.

Wire format summary
  • Buffer: [version:1][iv:12][tag:16][ciphertext…] — from encrypt()
  • Stream: [version:1][iv:12][ciphertext…][tag:16] — from pipeEncrypt()
  • Version byte (auto-read on decrypt): 0x05 = encrypted · 0x00 = compress-only
  • Encrypt always writes: 0x05 (latest format) — no option for older wire versions
  • Brotli quality: write-only on encrypt(); embedded in bitstream — not passed to decrypt()
  • Output files: .scnp extension convention

Full compatibility matrix, decrypt pipeline, and legacy 0x04 notes: Versioning & backward compatibility →