@carchalabs/seal-electron 0.0.0-stage → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +109 -0
- package/README.md +35 -2
- package/dist/fingerprint.d.ts +33 -0
- package/dist/fingerprint.js +97 -0
- package/dist/fingerprint.js.map +1 -0
- package/dist/index.d.ts +173 -0
- package/dist/index.js +600 -0
- package/dist/index.js.map +1 -0
- package/package.json +24 -4
- package/src/fingerprint.ts +103 -0
- package/src/index.ts +692 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
Carcha Seal SDK License
|
|
2
|
+
Version 1.0, 7 November 2026
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2026 Bugra Omer Aydemir (Carcha Labs) ("we", "us").
|
|
5
|
+
All rights not expressly granted below are reserved.
|
|
6
|
+
|
|
7
|
+
This license covers the software in the carcha-seal-sdk repository and the packages
|
|
8
|
+
built from it (the "SDK"). The source code is published so that you can review it;
|
|
9
|
+
publishing it does not make it open source. Versions of the SDK published before
|
|
10
|
+
7 November 2026 were released under the MIT License, which still applies to those
|
|
11
|
+
versions.
|
|
12
|
+
|
|
13
|
+
1. Definitions
|
|
14
|
+
|
|
15
|
+
"Carcha Seal Service" means a license server operated by us, or a license server you
|
|
16
|
+
run under a written agreement with us.
|
|
17
|
+
|
|
18
|
+
"Your Application" means software that you develop and provide to your own customers,
|
|
19
|
+
that uses the SDK to obtain and check licenses from the Carcha Seal Service, and whose
|
|
20
|
+
main purpose is not licensing, license management, copy protection or software
|
|
21
|
+
protection.
|
|
22
|
+
|
|
23
|
+
"End Users" means the people and organizations that receive Your Application from you.
|
|
24
|
+
|
|
25
|
+
2. What you may do
|
|
26
|
+
|
|
27
|
+
As long as you comply with this license, we grant you a non-exclusive, worldwide,
|
|
28
|
+
royalty-free, non-transferable license, which you may not sublicense except as
|
|
29
|
+
section 2(c) allows, to:
|
|
30
|
+
|
|
31
|
+
(a) use, copy and modify the SDK to integrate Your Application with the Carcha Seal
|
|
32
|
+
Service;
|
|
33
|
+
|
|
34
|
+
(b) read and study the SDK's source code, for example to evaluate the SDK or to review
|
|
35
|
+
its security; and
|
|
36
|
+
|
|
37
|
+
(c) distribute the SDK, unmodified or modified under (a), only as part of Your
|
|
38
|
+
Application, in object code or source code form, and let your End Users use it
|
|
39
|
+
only as part of Your Application.
|
|
40
|
+
|
|
41
|
+
3. What you may not do
|
|
42
|
+
|
|
43
|
+
You may not, and may not allow anyone else to:
|
|
44
|
+
|
|
45
|
+
(a) sell, license, rent, lend or otherwise distribute the SDK, or any part or modified
|
|
46
|
+
version of it, on its own or as part of a software development kit, library,
|
|
47
|
+
framework or other product for developers;
|
|
48
|
+
|
|
49
|
+
(b) use the SDK, or any part or modified version of it, with a license server or
|
|
50
|
+
service other than the Carcha Seal Service, except a test server you run only to
|
|
51
|
+
test Your Application;
|
|
52
|
+
|
|
53
|
+
(c) use the SDK, or any part, modified version or translation of it, in a product or
|
|
54
|
+
service that substitutes for the Carcha Seal Service or the SDK, or that offers the
|
|
55
|
+
same or substantially similar functionality;
|
|
56
|
+
|
|
57
|
+
(d) reverse engineer, decompile or disassemble the compiled parts of the SDK (such as
|
|
58
|
+
its native libraries), or otherwise try to derive source code we have not
|
|
59
|
+
published, except to the extent applicable law permits it despite this
|
|
60
|
+
restriction;
|
|
61
|
+
|
|
62
|
+
(e) disable, bypass or tamper with the SDK's license checks, signature verification,
|
|
63
|
+
encryption or device binding, or help anyone else do so, in any application that
|
|
64
|
+
uses the Carcha Seal Service, except in Your Application while you test it;
|
|
65
|
+
|
|
66
|
+
(f) remove or change this license or any copyright or other notice in the SDK; or
|
|
67
|
+
|
|
68
|
+
(g) use our names, logos or trademarks, including "Carcha Seal" and "Carcha Labs",
|
|
69
|
+
except to state truthfully that Your Application uses Carcha Seal.
|
|
70
|
+
|
|
71
|
+
4. Your End Users
|
|
72
|
+
|
|
73
|
+
Your terms for Your Application must not give your End Users more rights in the SDK
|
|
74
|
+
than to use it as part of Your Application. You are responsible for your End Users'
|
|
75
|
+
use of the SDK as part of Your Application.
|
|
76
|
+
|
|
77
|
+
5. Contributions
|
|
78
|
+
|
|
79
|
+
If you send us changes or suggestions for the SDK, you grant us a perpetual,
|
|
80
|
+
irrevocable, worldwide, royalty-free license to use, modify and distribute them for
|
|
81
|
+
any purpose.
|
|
82
|
+
|
|
83
|
+
6. Termination
|
|
84
|
+
|
|
85
|
+
Your rights under this license end automatically if you breach it. If you end the
|
|
86
|
+
breach within 30 days after we notify you of it, your rights are restored, unless you
|
|
87
|
+
have breached this license before. When your rights end, you must stop using and
|
|
88
|
+
distributing the SDK; your End Users may keep using copies of Your Application they
|
|
89
|
+
received before then. Sections 3, 5, 7 and 8 continue to apply after termination.
|
|
90
|
+
|
|
91
|
+
7. No warranty
|
|
92
|
+
|
|
93
|
+
To the extent the law allows, the SDK is provided "as is", without warranty of any
|
|
94
|
+
kind, express or implied, including warranties of merchantability, fitness for a
|
|
95
|
+
particular purpose and non-infringement. If you have a separate written agreement with
|
|
96
|
+
us for the Carcha Seal Service, its terms on warranty and liability apply to the SDK
|
|
97
|
+
instead of sections 7 and 8.
|
|
98
|
+
|
|
99
|
+
8. Limitation of liability
|
|
100
|
+
|
|
101
|
+
To the extent the law allows, we are not liable for any damages arising from the SDK
|
|
102
|
+
or this license. Nothing in this license limits or excludes liability that cannot be
|
|
103
|
+
limited or excluded under applicable law, including liability for intent or gross
|
|
104
|
+
negligence, for death or personal injury, or under product liability law.
|
|
105
|
+
|
|
106
|
+
9. New versions of this license
|
|
107
|
+
|
|
108
|
+
We may publish new versions of this license. Each version of the SDK stays under the
|
|
109
|
+
license it was published with.
|
package/README.md
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @carchalabs/seal-electron
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The [Carcha Seal](https://seal.carchalabs.com) (formerly LicenseKit) SDK. It runs in the Electron main process or in plain Node. It activates a license key on this device, saves the signed lease, and verifies it offline with your public keys.
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
const { Seal } = require('@carchalabs/seal-electron');
|
|
7
|
+
|
|
8
|
+
const kit = new Seal({
|
|
9
|
+
serverUrl: 'https://licenses.example.com',
|
|
10
|
+
product: 'example-studio',
|
|
11
|
+
publicKey: [currentKeyPem, nextKeyPem],
|
|
12
|
+
storageDir: app.getPath('userData'),
|
|
13
|
+
secureStore: {
|
|
14
|
+
encrypt: (s) => safeStorage.encryptString(s),
|
|
15
|
+
decrypt: (b) => safeStorage.decryptString(b),
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const state = await kit.check();
|
|
20
|
+
if (state.status === 'unlicensed') await kit.activate(userEnteredKey);
|
|
21
|
+
if (Seal.hasFeature(state, 'export-pdf')) exportPdf();
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
`check()` returns one of `valid`, `grace`, `invalid`, `unlicensed` or `clock_suspect`, with `offline` and `storageProtected` flags. A refusal from the server (suspended, expired, device removed, update required) is kept while offline and cleared by the next successful check-in. `notices` carries what the server asks your app to act on, such as `sdk_update_recommended` or `app_update_recommended` with a `minimum` version and a `requiredFrom` date; the SDK shows nothing itself. `activate(key, machineName)` sends the device name you pass, and none when you pass nothing (a computer's host name often holds its user's name). `deactivate()` releases the seat.
|
|
25
|
+
|
|
26
|
+
Code can be protected the same way (Envelope): encrypt a CommonJS module or a folder of them with `seal-encrypt --feature pro dist/premium dist/premium`, and load it with `await kit.requireEncrypted('pro', path.join(__dirname, 'premium/index.js.lke'))`. Without the feature in the license the code cannot be read; a licensed user can still read it from memory.
|
|
27
|
+
|
|
28
|
+
Computers that never reach the server use offline activation: `offlineRequest(key)` returns a request file, the license server turns it into a license file (its `/offline` page, `POST /v1/offline/activate` or the console), and `activateOffline(file)` loads it; it works only on that computer, for the policy's offline days. `deactivateOffline()` removes the license and returns a deactivation file the vendor uploads to free the seat. See the [documentation](https://seal.carchalabs.com/docs/#concepts).
|
|
29
|
+
|
|
30
|
+
The SDK sends the license key, a per-product SHA-256 hash of the operating system's machine ID, the device name, the platform, your app version and its own version. The raw machine ID does not leave the computer.
|
|
31
|
+
|
|
32
|
+
**Feature data.** `await kit.decrypt('pro', data)` returns data you encrypted for a feature (`encryptForFeature` in `@carchalabs/seal-core`, with the feature's content key from the console). It works offline from the stored lease and only on a device whose license includes the feature; without a license the data stays encrypted, so removing a license check from your app does not unlock it. With `@carchalabs/seal-hwid` 0.2 the native module does the decryption and the key never reaches JavaScript.
|
|
33
|
+
|
|
34
|
+
**Hardware components.** When `@carchalabs/seal-hwid` is installed, the SDK also sends one keyed hash per hardware part (motherboard, disk, network card, OS install, CPU and graphics models) and whether the computer is a virtual machine. The license server then recognises the computer after a new disk, network card or operating system install, and refuses a copied disk or system image on other hardware. Raw serial numbers never leave the computer. Without the package, or on a platform it has no module for, nothing extra is sent. `hardware: false` turns it off. Bundlers must leave the package to Node (mark it external); electron-builder unpacks its native module from the asar archive.
|
|
35
|
+
|
|
36
|
+
Integration guide (activate once, check at start, put feature code behind `decrypt`, ship the native module, harden the app): [seal.carchalabs.com/docs/#integration](https://seal.carchalabs.com/docs/#integration). Full reference: [seal.carchalabs.com/docs](https://seal.carchalabs.com/docs/#sdk). Requires Node 22.13 or later. [Carcha Seal SDK License](LICENSE): for apps that use Carcha Seal; versions before 7 November 2026 are MIT.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The OS tools are run by absolute path, never looked up through PATH: an app started from a terminal inherits the
|
|
3
|
+
* user's PATH, and a fake `ioreg` or `reg` placed first in it could report another computer's id.
|
|
4
|
+
*/
|
|
5
|
+
export declare const IOREG = "/usr/sbin/ioreg";
|
|
6
|
+
export declare const REG_EXE: string[];
|
|
7
|
+
export declare const LINUX_ID_FILES: string[];
|
|
8
|
+
export interface MachineIdDeps {
|
|
9
|
+
platform?: NodeJS.Platform;
|
|
10
|
+
/** Attempts to read the OS id before giving up (default 3). */
|
|
11
|
+
attempts?: number;
|
|
12
|
+
/** Pause between attempts (default 250 ms, doubled each time). */
|
|
13
|
+
delayMs?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Use hostname + CPU + MAC when the OS id cannot be read. Off by default: that value differs from the OS id, so the
|
|
16
|
+
* same computer would look like a new device and take another seat.
|
|
17
|
+
*/
|
|
18
|
+
allowFallback?: boolean;
|
|
19
|
+
run?: (file: string, args: string[], options: {
|
|
20
|
+
timeout: number;
|
|
21
|
+
windowsHide: boolean;
|
|
22
|
+
}) => Promise<{
|
|
23
|
+
stdout: string;
|
|
24
|
+
}>;
|
|
25
|
+
readText?: (file: string) => Promise<string>;
|
|
26
|
+
}
|
|
27
|
+
/** The OS id could not be read; licensing on this computer cannot continue until it can. */
|
|
28
|
+
export declare class MachineIdUnavailableError extends Error {
|
|
29
|
+
readonly code = "machine_id_unavailable";
|
|
30
|
+
constructor();
|
|
31
|
+
}
|
|
32
|
+
/** Reads a stable, OS-provided machine id, retrying a few times. Throws MachineIdUnavailableError unless allowFallback. */
|
|
33
|
+
export declare function readMachineId(deps?: MachineIdDeps): Promise<string>;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MachineIdUnavailableError = exports.LINUX_ID_FILES = exports.REG_EXE = exports.IOREG = void 0;
|
|
4
|
+
exports.readMachineId = readMachineId;
|
|
5
|
+
const node_child_process_1 = require("node:child_process");
|
|
6
|
+
const promises_1 = require("node:fs/promises");
|
|
7
|
+
const node_os_1 = require("node:os");
|
|
8
|
+
const node_path_1 = require("node:path");
|
|
9
|
+
const node_util_1 = require("node:util");
|
|
10
|
+
const execFileAsync = (0, node_util_1.promisify)(node_child_process_1.execFile);
|
|
11
|
+
/**
|
|
12
|
+
* The OS tools are run by absolute path, never looked up through PATH: an app started from a terminal inherits the
|
|
13
|
+
* user's PATH, and a fake `ioreg` or `reg` placed first in it could report another computer's id.
|
|
14
|
+
*/
|
|
15
|
+
exports.IOREG = '/usr/sbin/ioreg';
|
|
16
|
+
exports.REG_EXE = [
|
|
17
|
+
'C:\\Windows\\System32\\reg.exe',
|
|
18
|
+
node_path_1.win32.join(process.env.SystemRoot || 'C:\\Windows', 'System32', 'reg.exe'),
|
|
19
|
+
].filter((file, index, all) => all.indexOf(file) === index);
|
|
20
|
+
exports.LINUX_ID_FILES = ['/etc/machine-id', '/var/lib/dbus/machine-id'];
|
|
21
|
+
/** The OS id could not be read; licensing on this computer cannot continue until it can. */
|
|
22
|
+
class MachineIdUnavailableError extends Error {
|
|
23
|
+
code = 'machine_id_unavailable';
|
|
24
|
+
constructor() {
|
|
25
|
+
super('This computer\'s id could not be read. Try again; if it keeps failing, contact the app\'s support.');
|
|
26
|
+
this.name = 'MachineIdUnavailableError';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.MachineIdUnavailableError = MachineIdUnavailableError;
|
|
30
|
+
/** Reads a stable, OS-provided machine id, retrying a few times. Throws MachineIdUnavailableError unless allowFallback. */
|
|
31
|
+
async function readMachineId(deps = {}) {
|
|
32
|
+
const attempts = Math.max(1, deps.attempts ?? 3);
|
|
33
|
+
let delay = deps.delayMs ?? 250;
|
|
34
|
+
for (let attempt = 1; attempt <= attempts; attempt++) {
|
|
35
|
+
const id = await readOsMachineId(deps);
|
|
36
|
+
if (id)
|
|
37
|
+
return id;
|
|
38
|
+
if (attempt < attempts) {
|
|
39
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
40
|
+
delay *= 2;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (deps.allowFallback)
|
|
44
|
+
return `fallback:${fallbackTraits()}`;
|
|
45
|
+
throw new MachineIdUnavailableError();
|
|
46
|
+
}
|
|
47
|
+
/** One attempt; null when the OS id is not available. */
|
|
48
|
+
async function readOsMachineId(deps) {
|
|
49
|
+
const os = deps.platform ?? (0, node_os_1.platform)();
|
|
50
|
+
const run = deps.run ?? ((file, args, options) => execFileAsync(file, args, options));
|
|
51
|
+
const readText = deps.readText ?? ((file) => (0, promises_1.readFile)(file, 'utf8'));
|
|
52
|
+
try {
|
|
53
|
+
if (os === 'darwin') {
|
|
54
|
+
const { stdout } = await run(exports.IOREG, ['-rd1', '-c', 'IOPlatformExpertDevice'], { timeout: 3000, windowsHide: true });
|
|
55
|
+
const m = stdout.match(/"IOPlatformUUID"\s*=\s*"([^"]+)"/);
|
|
56
|
+
if (m)
|
|
57
|
+
return `mac:${m[1]}`;
|
|
58
|
+
}
|
|
59
|
+
else if (os === 'win32') {
|
|
60
|
+
for (const reg of exports.REG_EXE) {
|
|
61
|
+
try {
|
|
62
|
+
// /reg:64 reads the 64-bit registry view, so a 32-bit build sees the same MachineGuid.
|
|
63
|
+
const { stdout } = await run(reg, ['query', 'HKLM\\SOFTWARE\\Microsoft\\Cryptography', '/v', 'MachineGuid', '/reg:64'], {
|
|
64
|
+
timeout: 3000,
|
|
65
|
+
windowsHide: true,
|
|
66
|
+
});
|
|
67
|
+
const m = stdout.match(/MachineGuid\s+REG_SZ\s+([\w-]+)/i);
|
|
68
|
+
if (m)
|
|
69
|
+
return `win:${m[1]}`;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
/* try the next location */
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
for (const f of exports.LINUX_ID_FILES) {
|
|
78
|
+
const id = (await readText(f).catch(() => '')).trim();
|
|
79
|
+
if (id)
|
|
80
|
+
return `linux:${id}`;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
/* fall through */
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
function fallbackTraits() {
|
|
90
|
+
const macs = Object.values((0, node_os_1.networkInterfaces)())
|
|
91
|
+
.flat()
|
|
92
|
+
.filter((i) => i && !i.internal && i.mac && i.mac !== '00:00:00:00:00:00')
|
|
93
|
+
.map((i) => i.mac)
|
|
94
|
+
.sort();
|
|
95
|
+
return [(0, node_os_1.hostname)(), (0, node_os_1.cpus)()[0]?.model ?? '', macs[0] ?? ''].join('|');
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=fingerprint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fingerprint.js","sourceRoot":"","sources":["../src/fingerprint.ts"],"names":[],"mappings":";;;AA4CA,sCAaC;AAzDD,2DAA8C;AAC9C,+CAA4C;AAC5C,qCAAsE;AACtE,yCAAkC;AAClC,yCAAsC;AAEtC,MAAM,aAAa,GAAG,IAAA,qBAAS,EAAC,6BAAQ,CAAC,CAAC;AAE1C;;;GAGG;AACU,QAAA,KAAK,GAAG,iBAAiB,CAAC;AAC1B,QAAA,OAAO,GAAG;IACrB,gCAAgC;IAChC,iBAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,aAAa,EAAE,UAAU,EAAE,SAAS,CAAC;CAC3E,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,CAAC;AAC/C,QAAA,cAAc,GAAG,CAAC,iBAAiB,EAAE,0BAA0B,CAAC,CAAC;AAiB9E,4FAA4F;AAC5F,MAAa,yBAA0B,SAAQ,KAAK;IACzC,IAAI,GAAG,wBAAwB,CAAC;IACzC;QACE,KAAK,CAAC,oGAAoG,CAAC,CAAC;QAC5G,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF;AAND,8DAMC;AAED,2HAA2H;AACpH,KAAK,UAAU,aAAa,CAAC,OAAsB,EAAE;IAC1D,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC;IAC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ACN,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,IAAI,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,KAAK,mBAAmB,CAAC;SACzE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAE,CAAC,GAAG,CAAC;SAClB,IAAI,EAAE,CAAC;IACV,OAAO,CAAC,IAAA,kBAAQ,GAAE,EAAE,IAAA,cAAI,GAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACvE,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { MachineIdUnavailableError, readMachineId } from './fingerprint';
|
|
2
|
+
export { MachineIdUnavailableError, readMachineId };
|
|
3
|
+
/** This SDK's version, sent to the server so vendors can see (and require) which SDK each device runs. */
|
|
4
|
+
export declare const SDK_VERSION: string;
|
|
5
|
+
export type LicenseStatus = 'valid' | 'grace' | 'invalid' | 'unlicensed' | 'clock_suspect';
|
|
6
|
+
/**
|
|
7
|
+
* Something the server asks the app to act on: sdk_update_recommended (update the Carcha Seal SDK in the app) or
|
|
8
|
+
* app_update_recommended (the vendor's minimum app version), each with minimum and requiredFrom.
|
|
9
|
+
*/
|
|
10
|
+
export interface LicenseNotice {
|
|
11
|
+
code: string;
|
|
12
|
+
minimum?: string;
|
|
13
|
+
/** ISO date from which an older SDK is refused; null when the update is only recommended. */
|
|
14
|
+
requiredFrom?: string | null;
|
|
15
|
+
}
|
|
16
|
+
export interface LicenseState {
|
|
17
|
+
status: LicenseStatus;
|
|
18
|
+
offline: boolean;
|
|
19
|
+
storageProtected: boolean;
|
|
20
|
+
reason?: string;
|
|
21
|
+
message?: string;
|
|
22
|
+
customer?: string;
|
|
23
|
+
features: string[];
|
|
24
|
+
expiresAt: string | null;
|
|
25
|
+
maintenanceUntil?: string | null;
|
|
26
|
+
revalidateBy?: string;
|
|
27
|
+
keyHint?: string;
|
|
28
|
+
/** From the last successful check-in; kept while offline. The app decides how to show them. */
|
|
29
|
+
notices?: LicenseNotice[];
|
|
30
|
+
/** True when the license came from an offline license file (activateOffline); renew it with a new file. */
|
|
31
|
+
offlineActivated?: boolean;
|
|
32
|
+
}
|
|
33
|
+
/** Hashed hardware components (see @carchalabs/seal-hwid); the server matches a device by them. */
|
|
34
|
+
export interface HardwareReport {
|
|
35
|
+
components: {
|
|
36
|
+
kind: string;
|
|
37
|
+
hash: string;
|
|
38
|
+
}[];
|
|
39
|
+
/** True when the device runs as a virtual machine. */
|
|
40
|
+
vm: boolean;
|
|
41
|
+
}
|
|
42
|
+
export interface SecureStore {
|
|
43
|
+
encrypt(plain: string): Buffer | Promise<Buffer>;
|
|
44
|
+
decrypt(cipher: Buffer): string | Promise<string>;
|
|
45
|
+
isProtected?(): boolean;
|
|
46
|
+
}
|
|
47
|
+
export interface SealOptions {
|
|
48
|
+
/** The license server: https://, or http:// on this computer only (localhost, 127.x.x.x, [::1]). */
|
|
49
|
+
serverUrl: string;
|
|
50
|
+
product: string;
|
|
51
|
+
publicKey: string | string[];
|
|
52
|
+
storageDir: string;
|
|
53
|
+
appVersion?: string;
|
|
54
|
+
graceDays?: number;
|
|
55
|
+
secureStore?: SecureStore;
|
|
56
|
+
requestTimeoutMs?: number;
|
|
57
|
+
fetchImpl?: typeof fetch;
|
|
58
|
+
machineId?: () => Promise<string>;
|
|
59
|
+
/** Use hostname + CPU + MAC when the OS machine id cannot be read (default false; see readMachineId). */
|
|
60
|
+
allowFallbackFingerprint?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Hardware components sent with each request, so the device keeps its seat after a new disk, network
|
|
63
|
+
* card or OS install. Default: read with @carchalabs/seal-hwid when it is installed; nothing is
|
|
64
|
+
* sent when it is not (or cannot load on this platform). false: never send them. A function: your own.
|
|
65
|
+
*/
|
|
66
|
+
hardware?: false | (() => HardwareReport | null | Promise<HardwareReport | null>);
|
|
67
|
+
now?: () => number;
|
|
68
|
+
}
|
|
69
|
+
export declare class LicenseError extends Error {
|
|
70
|
+
readonly code: string;
|
|
71
|
+
readonly status?: number | undefined;
|
|
72
|
+
constructor(code: string, message: string, status?: number | undefined);
|
|
73
|
+
}
|
|
74
|
+
export declare class Seal {
|
|
75
|
+
private readonly opts;
|
|
76
|
+
private readonly file;
|
|
77
|
+
private readonly keys;
|
|
78
|
+
private fingerprintCache?;
|
|
79
|
+
private hardwareCache?;
|
|
80
|
+
/** The native lease verifier, when it trusts every key this app was given (undefined = not looked up yet). */
|
|
81
|
+
private nativeLease?;
|
|
82
|
+
private deviceKeyCache?;
|
|
83
|
+
constructor(opts: SealOptions);
|
|
84
|
+
private get fetch();
|
|
85
|
+
private nowSec;
|
|
86
|
+
private get storageProtected();
|
|
87
|
+
fingerprint(): Promise<string>;
|
|
88
|
+
/** Read once per instance: hardware does not change while the app runs. Never throws. */
|
|
89
|
+
private hardware;
|
|
90
|
+
/** The saved record; null when there is none, or it cannot be read or is not a record (as no license). */
|
|
91
|
+
private load;
|
|
92
|
+
/** Replaces license.dat whole: written to license.dat.tmp, then renamed over it, so a crash or full disk mid-write
|
|
93
|
+
* leaves the previous record. */
|
|
94
|
+
private save;
|
|
95
|
+
private clear;
|
|
96
|
+
private post;
|
|
97
|
+
private emptyState;
|
|
98
|
+
/**
|
|
99
|
+
* The device's public key, sent with activation and check-ins so the server wraps feature keys for
|
|
100
|
+
* this machine only. Only when the native module verifies for this app (it then also decrypts, with
|
|
101
|
+
* the matching secret it derives itself) and hardware is not turned off. Never throws.
|
|
102
|
+
*/
|
|
103
|
+
private deviceKey;
|
|
104
|
+
/**
|
|
105
|
+
* The native verifier, used only when its compiled-in keys include every key this app was given:
|
|
106
|
+
* an app that trusts other keys (a self-hosted server) is checked by the JavaScript verifier alone.
|
|
107
|
+
*/
|
|
108
|
+
private native;
|
|
109
|
+
/**
|
|
110
|
+
* Verifies a lease twice, in JavaScript and in the native module, when the native verifier applies.
|
|
111
|
+
* Both follow the same rules, so a different answer means one of them was tampered with: the lease
|
|
112
|
+
* is then treated as modified.
|
|
113
|
+
*/
|
|
114
|
+
private verify;
|
|
115
|
+
private stateFromLease;
|
|
116
|
+
/** machineName: the name to show the vendor for this device. Nothing is sent when the app gives none (host names often hold a person's name). */
|
|
117
|
+
activate(licenseKey: string, machineName?: string): Promise<LicenseState>;
|
|
118
|
+
check(): Promise<LicenseState>;
|
|
119
|
+
/** The state from the saved record when the server gave no usable answer; a usable lease moves lastSeen forward. */
|
|
120
|
+
private offlineCheck;
|
|
121
|
+
/**
|
|
122
|
+
* Decrypts data you encrypted for a feature (encryptForFeature in @carchalabs/seal-core, with the
|
|
123
|
+
* feature's content key from the console). Works offline: it uses the saved lease, which must be valid
|
|
124
|
+
* (or in its offline grace period), grant the feature and carry its key, and the saved license key.
|
|
125
|
+
* The native module does the work when it trusts this app's keys, so the content key never reaches
|
|
126
|
+
* JavaScript; without it the JavaScript implementation is used. Throws a LicenseError:
|
|
127
|
+
* `unlicensed`, a lease failure reason, `clock_suspect`, `feature_not_licensed` or `decrypt_failed`.
|
|
128
|
+
*/
|
|
129
|
+
decrypt(feature: string, data: Uint8Array): Promise<Buffer>;
|
|
130
|
+
/**
|
|
131
|
+
* Envelope: loads a CommonJS module you encrypted for a feature (seal-encrypt, one file or a
|
|
132
|
+
* folder) and returns its exports, like require(). The code is decrypted with the lease's feature key
|
|
133
|
+
* (see decrypt) and compiled from memory; it never exists as a plain file. Relative requires inside
|
|
134
|
+
* it load encrypted neighbours (`./x` finds `x.lke`, `x.js.lke` or `x/index.js.lke`), anything else
|
|
135
|
+
* goes to Node as usual. Loaded once per process, like require(). Throws the same LicenseErrors as
|
|
136
|
+
* decrypt. A licensed user can still read the code from memory: this keeps an app with the license
|
|
137
|
+
* check removed from having the feature, it does not hide the code from its licensed users.
|
|
138
|
+
*/
|
|
139
|
+
requireEncrypted(feature: string, file: string): Promise<any>;
|
|
140
|
+
private readonly encryptedModules;
|
|
141
|
+
private loadEncrypted;
|
|
142
|
+
/**
|
|
143
|
+
* Checks the saved lease once for a feature and returns a synchronous decrypter bound to it: decrypt
|
|
144
|
+
* uses it once, requireEncrypted for a module and the encrypted modules it requires.
|
|
145
|
+
*/
|
|
146
|
+
private opener;
|
|
147
|
+
/**
|
|
148
|
+
* Offline activation, step 1 on a machine that cannot reach the server: the request file (JSON text)
|
|
149
|
+
* the user takes to a connected device. The license server turns it into a license file at
|
|
150
|
+
* POST /v1/offline/activate (or its offline activation page). It holds what activate() would send:
|
|
151
|
+
* the license key, this device's fingerprint and hashed hardware parts, never raw serial numbers.
|
|
152
|
+
*/
|
|
153
|
+
offlineRequest(licenseKey: string, machineName?: string): Promise<string>;
|
|
154
|
+
/**
|
|
155
|
+
* Offline activation, step 2: loads the license file the server issued for this machine's request.
|
|
156
|
+
* It is verified like an online lease (signature, product, this device) and then saved; from then on
|
|
157
|
+
* check() works without the server until the lease's renewal date plus the offline grace. Throws a
|
|
158
|
+
* LicenseError: `invalid_file`, `wrong_product`, or a lease failure reason such as `wrong_device`.
|
|
159
|
+
*/
|
|
160
|
+
activateOffline(licenseFile: string): Promise<LicenseState>;
|
|
161
|
+
/**
|
|
162
|
+
* Gives an offline machine's seat back: removes the license from this device and returns the
|
|
163
|
+
* deactivation file (JSON text) for the vendor, who frees the seat by uploading it in the console.
|
|
164
|
+
* Throws `unlicensed` when there is no license to remove.
|
|
165
|
+
*/
|
|
166
|
+
deactivateOffline(): Promise<string>;
|
|
167
|
+
deactivate(): Promise<void>;
|
|
168
|
+
static hasFeature(state: LicenseState, feature: string): boolean;
|
|
169
|
+
}
|
|
170
|
+
/** The SDK class under its earlier name (LicenseKit). Same class; use Seal in new code. */
|
|
171
|
+
export { Seal as LicenseKit };
|
|
172
|
+
/** @deprecated The options under the class's earlier name; use SealOptions. */
|
|
173
|
+
export type LicenseKitOptions = SealOptions;
|