@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/dist/index.js ADDED
@@ -0,0 +1,600 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LicenseKit = exports.Seal = exports.LicenseError = exports.SDK_VERSION = exports.readMachineId = exports.MachineIdUnavailableError = void 0;
4
+ const node_fs_1 = require("node:fs");
5
+ const promises_1 = require("node:fs/promises");
6
+ const node_module_1 = require("node:module");
7
+ const node_os_1 = require("node:os");
8
+ const node_path_1 = require("node:path");
9
+ const node_vm_1 = require("node:vm");
10
+ const seal_core_1 = require("@carchalabs/seal-core");
11
+ const fingerprint_1 = require("./fingerprint");
12
+ Object.defineProperty(exports, "MachineIdUnavailableError", { enumerable: true, get: function () { return fingerprint_1.MachineIdUnavailableError; } });
13
+ Object.defineProperty(exports, "readMachineId", { enumerable: true, get: function () { return fingerprint_1.readMachineId; } });
14
+ /** This SDK's version, sent to the server so vendors can see (and require) which SDK each device runs. */
15
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
16
+ exports.SDK_VERSION = require('../package.json').version;
17
+ /** File formats of offline activation, shared with the license server. */
18
+ const OFFLINE_REQUEST_FORMAT = 'licensekit-offline-request';
19
+ const OFFLINE_LICENSE_FORMAT = 'licensekit-offline-license';
20
+ const OFFLINE_DEACTIVATION_FORMAT = 'licensekit-offline-deactivation';
21
+ const DEFINITIVE = new Set(['invalid_key', 'not_activated', 'license_suspended', 'license_revoked', 'license_expired', 'sdk_update_required', 'app_update_required', 'vm_not_allowed']);
22
+ /** The native hardware module. A non-literal require: bundlers leave it to Node, which must load the .node file from disk. */
23
+ const HWID_PACKAGE = '@carchalabs/seal-hwid';
24
+ /** Loads the native module once per process; null when it is not installed or has no build for this platform. */
25
+ let hwidModule;
26
+ function loadHwid() {
27
+ if (hwidModule === undefined) {
28
+ try {
29
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
30
+ hwidModule = require(HWID_PACKAGE);
31
+ }
32
+ catch {
33
+ hwidModule = null;
34
+ }
35
+ }
36
+ return hwidModule;
37
+ }
38
+ /** The server accepts at most this many components. */
39
+ const MAX_COMPONENTS = 32;
40
+ /** The license itself is gone: forget the key too. The other refusals can be undone on the server (resume, renew,
41
+ * re-activate), so the key is kept and the next successful online check restores the license on its own. */
42
+ const FORGET_KEY = new Set(['invalid_key', 'license_revoked']);
43
+ const CLOCK_TOLERANCE_SECONDS = 24 * 3600;
44
+ /**
45
+ * A check-in answered 2xx whose lease fails for one of these reasons did not come from this app's license server for
46
+ * this device (a TLS-inspecting proxy's or captive portal's page, say): it is treated as no answer, and the saved lease
47
+ * is kept. A lease that fails only on time (not_yet_valid, expired, revalidation_required) is the server's, and is used.
48
+ */
49
+ const NOT_A_LEASE_FOR_THIS_DEVICE = new Set(['malformed', 'unsupported_algorithm', 'wrong_type', 'unknown_key', 'bad_signature', 'wrong_issuer', 'wrong_product', 'wrong_device']);
50
+ const DEFAULT_GRACE_DAYS = 7;
51
+ const CLOCK_MESSAGE = 'The date and time on this computer look wrong. Correct them, then connect to the internet.';
52
+ class LicenseError extends Error {
53
+ code;
54
+ status;
55
+ constructor(code, message, status) {
56
+ super(message);
57
+ this.code = code;
58
+ this.status = status;
59
+ this.name = 'LicenseError';
60
+ }
61
+ }
62
+ exports.LicenseError = LicenseError;
63
+ /**
64
+ * Refuses a server address that would send requests in plain text (OWASP ASVS 4.1.2, 12.2.1): every request
65
+ * carries the license key and the device's fingerprint. http:// is accepted for this computer only, where a server
66
+ * under development runs; `localhost` and the loopback addresses do not leave the machine.
67
+ */
68
+ function checkServerUrl(serverUrl) {
69
+ let url;
70
+ try {
71
+ url = new URL(serverUrl);
72
+ }
73
+ catch {
74
+ throw new LicenseError('invalid_server_url', 'serverUrl is not a valid URL.');
75
+ }
76
+ if (url.protocol === 'https:')
77
+ return;
78
+ const loopback = url.hostname === 'localhost' || url.hostname === '[::1]' || /^127(\.\d{1,3}){3}$/.test(url.hostname);
79
+ if (url.protocol === 'http:' && loopback)
80
+ return;
81
+ throw new LicenseError('insecure_server_url', 'serverUrl must start with https:// (http:// only for localhost).');
82
+ }
83
+ const REASON_TEXT = {
84
+ malformed: 'The saved license is damaged. Please activate again.',
85
+ bad_signature: 'The saved license was modified. Please activate again.',
86
+ unsupported_algorithm: 'Please update the app.',
87
+ wrong_type: 'Please update the app.',
88
+ unknown_key: 'Please update the app.',
89
+ wrong_issuer: 'This license was issued by a different license server.',
90
+ not_yet_valid: CLOCK_MESSAGE,
91
+ wrong_product: 'This license is for a different product.',
92
+ wrong_device: 'This license is activated on another device.',
93
+ expired: 'Your license has expired.',
94
+ revalidation_required: 'Connect to the internet to confirm your license.',
95
+ };
96
+ const toIso = (seconds) => new Date(seconds * 1000).toISOString();
97
+ /** A saved record of the shape save() writes, keeping only its known fields; null for anything else. */
98
+ function parseStored(value) {
99
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
100
+ return null;
101
+ const v = value;
102
+ if (typeof v.licenseKey !== 'string')
103
+ return null;
104
+ const stored = { licenseKey: v.licenseKey };
105
+ if (typeof v.token === 'string')
106
+ stored.token = v.token;
107
+ if (typeof v.lastSeen === 'number' && Number.isFinite(v.lastSeen))
108
+ stored.lastSeen = v.lastSeen;
109
+ const r = v.refused;
110
+ if (r && typeof r.code === 'string' && typeof r.message === 'string' && typeof r.at === 'number')
111
+ stored.refused = { code: r.code, message: r.message, at: r.at };
112
+ if (Array.isArray(v.notices))
113
+ stored.notices = v.notices.filter((n) => !!n && typeof n.code === 'string');
114
+ if (v.offline === true)
115
+ stored.offline = true;
116
+ return stored;
117
+ }
118
+ function noticesFrom(response) {
119
+ const list = Array.isArray(response?.notices) ? response.notices.filter((n) => n && typeof n.code === 'string') : [];
120
+ return list.length ? { notices: list } : {};
121
+ }
122
+ class Seal {
123
+ opts;
124
+ file;
125
+ keys;
126
+ fingerprintCache;
127
+ hardwareCache;
128
+ /** The native lease verifier, when it trusts every key this app was given (undefined = not looked up yet). */
129
+ nativeLease;
130
+ deviceKeyCache;
131
+ constructor(opts) {
132
+ this.opts = opts;
133
+ checkServerUrl(opts.serverUrl);
134
+ this.file = (0, node_path_1.join)(opts.storageDir, 'license.dat');
135
+ this.keys = (0, seal_core_1.keySet)(Array.isArray(opts.publicKey) ? opts.publicKey : [opts.publicKey]);
136
+ }
137
+ get fetch() {
138
+ return this.opts.fetchImpl ?? fetch;
139
+ }
140
+ nowSec() {
141
+ return Math.floor((this.opts.now?.() ?? Date.now()) / 1000);
142
+ }
143
+ get storageProtected() {
144
+ const store = this.opts.secureStore;
145
+ return store !== undefined && (store.isProtected?.() ?? true);
146
+ }
147
+ async fingerprint() {
148
+ if (!this.fingerprintCache) {
149
+ let raw;
150
+ try {
151
+ raw = await (this.opts.machineId ?? (() => (0, fingerprint_1.readMachineId)({ allowFallback: this.opts.allowFallbackFingerprint })))();
152
+ }
153
+ catch (e) {
154
+ if (e instanceof fingerprint_1.MachineIdUnavailableError)
155
+ throw new LicenseError(e.code, e.message);
156
+ throw e;
157
+ }
158
+ this.fingerprintCache = (0, seal_core_1.hashFingerprint)(raw, this.opts.product);
159
+ }
160
+ return this.fingerprintCache;
161
+ }
162
+ /** Read once per instance: hardware does not change while the app runs. Never throws. */
163
+ hardware() {
164
+ this.hardwareCache ??= (async () => {
165
+ const source = this.opts.hardware;
166
+ if (source === false)
167
+ return null;
168
+ try {
169
+ if (source)
170
+ return await source();
171
+ const hwid = loadHwid();
172
+ if (!hwid)
173
+ return null;
174
+ const { components, vm } = hwid.collect(`licensekit:${this.opts.product}`);
175
+ return { components, vm };
176
+ }
177
+ catch {
178
+ return null; // not installed, or no module for this platform: send nothing, as before
179
+ }
180
+ })();
181
+ return this.hardwareCache.then((report) => report && report.components.length ? { components: report.components.slice(0, MAX_COMPONENTS), vm: report.vm === true } : {});
182
+ }
183
+ /** The saved record; null when there is none, or it cannot be read or is not a record (as no license). */
184
+ async load() {
185
+ try {
186
+ const buf = await (0, promises_1.readFile)(this.file);
187
+ const text = this.opts.secureStore ? await this.opts.secureStore.decrypt(buf) : buf.toString('utf8');
188
+ return parseStored(JSON.parse(text));
189
+ }
190
+ catch {
191
+ return null;
192
+ }
193
+ }
194
+ /** Replaces license.dat whole: written to license.dat.tmp, then renamed over it, so a crash or full disk mid-write
195
+ * leaves the previous record. */
196
+ async save(stored) {
197
+ await (0, promises_1.mkdir)(this.opts.storageDir, { recursive: true });
198
+ const text = JSON.stringify(stored);
199
+ const temp = this.file + '.tmp';
200
+ try {
201
+ await (0, promises_1.writeFile)(temp, this.opts.secureStore ? await this.opts.secureStore.encrypt(text) : text, { mode: 0o600, flush: true });
202
+ await (0, promises_1.rename)(temp, this.file);
203
+ }
204
+ catch (e) {
205
+ await (0, promises_1.rm)(temp, { force: true }).catch(() => { });
206
+ throw e;
207
+ }
208
+ }
209
+ async clear() {
210
+ await (0, promises_1.rm)(this.file, { force: true });
211
+ }
212
+ async post(path, body) {
213
+ let res;
214
+ try {
215
+ res = await this.fetch(this.opts.serverUrl.replace(/\/+$/, '') + path, {
216
+ method: 'POST',
217
+ headers: { 'Content-Type': 'application/json' },
218
+ body: JSON.stringify(body),
219
+ // A redirect is refused, not followed: it could take the request, license key included, to another
220
+ // address or to http:// (ASVS 4.1.2). The server answers its API at the configured address.
221
+ redirect: 'error',
222
+ signal: AbortSignal.timeout(this.opts.requestTimeoutMs ?? 8000),
223
+ });
224
+ }
225
+ catch {
226
+ throw new LicenseError('network', 'Could not reach the license server.');
227
+ }
228
+ const json = await res.json().catch(() => ({}));
229
+ if (!res.ok)
230
+ throw new LicenseError(json.error ?? 'server_error', json.message ?? `License server error (${res.status})`, res.status);
231
+ return json;
232
+ }
233
+ emptyState(status, offline, extra = {}) {
234
+ return { status, offline, storageProtected: this.storageProtected, features: [], expiresAt: null, ...extra };
235
+ }
236
+ /**
237
+ * The device's public key, sent with activation and check-ins so the server wraps feature keys for
238
+ * this machine only. Only when the native module verifies for this app (it then also decrypts, with
239
+ * the matching secret it derives itself) and hardware is not turned off. Never throws.
240
+ */
241
+ deviceKey() {
242
+ if (this.deviceKeyCache === undefined) {
243
+ let key = null;
244
+ try {
245
+ const native = this.opts.hardware === false ? null : this.native();
246
+ if (native && typeof native.devicePublicKey === 'function' && typeof native.decryptFeature === 'function') {
247
+ key = native.devicePublicKey(`licensekit:${this.opts.product}`);
248
+ }
249
+ }
250
+ catch {
251
+ key = null;
252
+ }
253
+ this.deviceKeyCache = key;
254
+ }
255
+ return this.deviceKeyCache ? { devicePublicKey: this.deviceKeyCache } : {};
256
+ }
257
+ /**
258
+ * The native verifier, used only when its compiled-in keys include every key this app was given:
259
+ * an app that trusts other keys (a self-hosted server) is checked by the JavaScript verifier alone.
260
+ */
261
+ native() {
262
+ if (this.nativeLease === undefined) {
263
+ const hwid = loadHwid();
264
+ let native = null;
265
+ if (hwid && typeof hwid.verifyLease === 'function' && typeof hwid.leaseKeyIds === 'function') {
266
+ const trusted = new Set(hwid.leaseKeyIds());
267
+ if ([...this.keys.keys()].every((kid) => trusted.has(kid)))
268
+ native = hwid;
269
+ }
270
+ this.nativeLease = native;
271
+ }
272
+ return this.nativeLease;
273
+ }
274
+ /**
275
+ * Verifies a lease twice, in JavaScript and in the native module, when the native verifier applies.
276
+ * Both follow the same rules, so a different answer means one of them was tampered with: the lease
277
+ * is then treated as modified.
278
+ */
279
+ verify(token, options) {
280
+ const result = (0, seal_core_1.verifyLease)(token, options);
281
+ const native = this.native();
282
+ if (!native)
283
+ return result;
284
+ const check = native.verifyLease(token, {
285
+ product: options.product,
286
+ fingerprintHash: options.fingerprintHash,
287
+ now: options.now ?? Math.floor(Date.now() / 1000),
288
+ ...(options.graceSeconds !== undefined ? { graceSeconds: options.graceSeconds } : {}),
289
+ });
290
+ const agree = check.ok === result.ok && (result.ok || check.reason === result.reason);
291
+ return agree ? result : { ok: false, reason: 'bad_signature' };
292
+ }
293
+ stateFromLease(stored, offline) {
294
+ const fingerprintHash = this.fingerprintCache;
295
+ const now = this.nowSec();
296
+ const keyHint = `${stored.licenseKey.slice(0, 7)}…${stored.licenseKey.slice(-4)}`;
297
+ if (offline && stored.lastSeen !== undefined && now < stored.lastSeen - CLOCK_TOLERANCE_SECONDS) {
298
+ return this.emptyState('clock_suspect', offline, { reason: 'clock_rollback', message: CLOCK_MESSAGE, keyHint });
299
+ }
300
+ const verifyOptions = { keys: this.keys, product: this.opts.product, fingerprintHash, now };
301
+ const strict = this.verify(stored.token, verifyOptions);
302
+ const fromClaims = (claims) => ({
303
+ customer: claims.cus,
304
+ features: claims.feat,
305
+ expiresAt: claims.exp === undefined ? null : toIso(claims.exp),
306
+ maintenanceUntil: claims.mnt === undefined ? null : toIso(claims.mnt),
307
+ storageProtected: this.storageProtected,
308
+ keyHint,
309
+ ...(stored.notices ? { notices: stored.notices } : {}),
310
+ ...(stored.offline ? { offlineActivated: true } : {}),
311
+ });
312
+ if (strict.ok) {
313
+ return { status: 'valid', offline, ...fromClaims(strict.claims), revalidateBy: toIso(strict.claims.rev) };
314
+ }
315
+ if (strict.reason === 'not_yet_valid') {
316
+ return this.emptyState('clock_suspect', offline, { reason: 'lease_from_future', message: CLOCK_MESSAGE, keyHint });
317
+ }
318
+ if (strict.reason === 'revalidation_required' && strict.claims) {
319
+ const grace = strict.claims.grc ?? (this.opts.graceDays ?? DEFAULT_GRACE_DAYS) * 86400;
320
+ const lenient = this.verify(stored.token, { ...verifyOptions, graceSeconds: grace });
321
+ if (lenient.ok) {
322
+ return {
323
+ status: 'grace',
324
+ offline,
325
+ reason: 'offline_grace',
326
+ message: stored.offline
327
+ ? 'This offline license is past its renewal date. Load a new offline license file soon to keep using the app.'
328
+ : 'Working offline. Connect to the internet soon to keep using the app.',
329
+ ...fromClaims(lenient.claims),
330
+ revalidateBy: toIso(Math.min(lenient.claims.rev + grace, lenient.claims.exp ?? Infinity)),
331
+ };
332
+ }
333
+ }
334
+ return this.emptyState('invalid', offline, { reason: strict.reason, message: REASON_TEXT[strict.reason], keyHint });
335
+ }
336
+ /** 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). */
337
+ async activate(licenseKey, machineName) {
338
+ const fingerprint = await this.fingerprint();
339
+ const key = licenseKey.trim().toUpperCase();
340
+ const response = await this.post('/v1/activate', {
341
+ licenseKey: key,
342
+ product: this.opts.product,
343
+ fingerprint,
344
+ machineName: machineName?.slice(0, 80),
345
+ platform: (0, node_os_1.platform)(),
346
+ appVersion: this.opts.appVersion,
347
+ sdkVersion: exports.SDK_VERSION,
348
+ ...(await this.hardware()),
349
+ ...this.deviceKey(),
350
+ });
351
+ const stored = { licenseKey: key, token: response.token, lastSeen: this.nowSec(), ...noticesFrom(response) };
352
+ const state = this.stateFromLease(stored, false);
353
+ if (state.status !== 'valid')
354
+ throw new LicenseError(state.status === 'clock_suspect' ? 'clock_suspect' : state.reason ?? 'invalid', state.message ?? 'Server returned an unusable license');
355
+ await this.save(stored);
356
+ return state;
357
+ }
358
+ async check() {
359
+ try {
360
+ await this.fingerprint();
361
+ }
362
+ catch (e) {
363
+ // Nothing is changed on disk: the next check tries to read the id again.
364
+ if (e instanceof LicenseError && e.code === 'machine_id_unavailable')
365
+ return this.emptyState('invalid', false, { reason: e.code, message: e.message });
366
+ throw e;
367
+ }
368
+ const stored = await this.load();
369
+ if (!stored)
370
+ return this.emptyState('unlicensed', false);
371
+ if (stored.offline && stored.token) {
372
+ // Activated from an offline license file: the machine is not expected to reach the server.
373
+ const state = this.stateFromLease({ ...stored, token: stored.token }, true);
374
+ if (state.status === 'valid' || state.status === 'grace') {
375
+ await this.save({ ...stored, lastSeen: Math.max(stored.lastSeen ?? 0, this.nowSec()) });
376
+ }
377
+ return state;
378
+ }
379
+ let response;
380
+ try {
381
+ response = await this.post('/v1/validate', {
382
+ licenseKey: stored.licenseKey,
383
+ product: this.opts.product,
384
+ fingerprint: this.fingerprintCache,
385
+ appVersion: this.opts.appVersion,
386
+ sdkVersion: exports.SDK_VERSION,
387
+ ...(await this.hardware()),
388
+ ...this.deviceKey(),
389
+ });
390
+ }
391
+ catch (e) {
392
+ if (e instanceof LicenseError && DEFINITIVE.has(e.code)) {
393
+ // Persist the refusal: drop the signed lease so going offline cannot bring the license back.
394
+ if (FORGET_KEY.has(e.code))
395
+ await this.clear();
396
+ else
397
+ await this.save({ licenseKey: stored.licenseKey, lastSeen: stored.lastSeen, refused: { code: e.code, message: e.message, at: this.nowSec() } });
398
+ const keyHint = `${stored.licenseKey.slice(0, 7)}…${stored.licenseKey.slice(-4)}`;
399
+ return this.emptyState('invalid', false, { reason: e.code, message: e.message, keyHint });
400
+ }
401
+ return this.offlineCheck(stored);
402
+ }
403
+ if (typeof response?.token === 'string') {
404
+ const fresh = { licenseKey: stored.licenseKey, token: response.token, lastSeen: this.nowSec(), ...noticesFrom(response) };
405
+ const state = this.stateFromLease(fresh, false);
406
+ if (!(state.status === 'invalid' && NOT_A_LEASE_FOR_THIS_DEVICE.has(state.reason ?? ''))) {
407
+ await this.save(fresh);
408
+ return state;
409
+ }
410
+ }
411
+ // A 2xx without a lease from this server for this device: as no answer.
412
+ return this.offlineCheck(stored);
413
+ }
414
+ /** The state from the saved record when the server gave no usable answer; a usable lease moves lastSeen forward. */
415
+ async offlineCheck(stored) {
416
+ if (!stored.token) {
417
+ const keyHint = `${stored.licenseKey.slice(0, 7)}…${stored.licenseKey.slice(-4)}`;
418
+ const refused = stored.refused ?? { code: 'not_activated', message: 'This device is not activated for this license' };
419
+ return this.emptyState('invalid', true, { reason: refused.code, message: refused.message, keyHint });
420
+ }
421
+ const state = this.stateFromLease({ ...stored, token: stored.token }, true);
422
+ if (state.status === 'valid' || state.status === 'grace') {
423
+ await this.save({ ...stored, lastSeen: Math.max(stored.lastSeen ?? 0, this.nowSec()) });
424
+ }
425
+ return state;
426
+ }
427
+ /**
428
+ * Decrypts data you encrypted for a feature (encryptForFeature in @carchalabs/seal-core, with the
429
+ * feature's content key from the console). Works offline: it uses the saved lease, which must be valid
430
+ * (or in its offline grace period), grant the feature and carry its key, and the saved license key.
431
+ * The native module does the work when it trusts this app's keys, so the content key never reaches
432
+ * JavaScript; without it the JavaScript implementation is used. Throws a LicenseError:
433
+ * `unlicensed`, a lease failure reason, `clock_suspect`, `feature_not_licensed` or `decrypt_failed`.
434
+ */
435
+ async decrypt(feature, data) {
436
+ return (await this.opener(feature))(data);
437
+ }
438
+ /**
439
+ * Envelope: loads a CommonJS module you encrypted for a feature (seal-encrypt, one file or a
440
+ * folder) and returns its exports, like require(). The code is decrypted with the lease's feature key
441
+ * (see decrypt) and compiled from memory; it never exists as a plain file. Relative requires inside
442
+ * it load encrypted neighbours (`./x` finds `x.lke`, `x.js.lke` or `x/index.js.lke`), anything else
443
+ * goes to Node as usual. Loaded once per process, like require(). Throws the same LicenseErrors as
444
+ * decrypt. A licensed user can still read the code from memory: this keeps an app with the license
445
+ * check removed from having the feature, it does not hide the code from its licensed users.
446
+ */
447
+ async requireEncrypted(feature, file) {
448
+ const open = await this.opener(feature);
449
+ return this.loadEncrypted((0, node_path_1.resolve)(file), feature, open);
450
+ }
451
+ encryptedModules = new Map();
452
+ loadEncrypted(file, feature, open) {
453
+ const cacheKey = `${feature}\0${file}`;
454
+ const cached = this.encryptedModules.get(cacheKey);
455
+ if (cached)
456
+ return cached.exports;
457
+ const source = open((0, node_fs_1.readFileSync)(file)).toString('utf8');
458
+ const filename = file.replace(/\.lke$/, '');
459
+ const mod = { exports: {}, filename, id: filename, loaded: false };
460
+ // Registered before it runs, so a require cycle gets the partial exports, as in Node.
461
+ this.encryptedModules.set(cacheKey, mod);
462
+ const nodeRequire = (0, node_module_1.createRequire)(filename);
463
+ const localRequire = ((request) => {
464
+ if (request.startsWith('./') || request.startsWith('../')) {
465
+ const base = (0, node_path_1.resolve)((0, node_path_1.dirname)(filename), request);
466
+ const encrypted = [`${base}.lke`, `${base}.js.lke`, (0, node_path_1.join)(base, 'index.js.lke')].find((candidate) => (0, node_fs_1.existsSync)(candidate));
467
+ if (encrypted)
468
+ return this.loadEncrypted(encrypted, feature, open);
469
+ }
470
+ return nodeRequire(request);
471
+ });
472
+ Object.assign(localRequire, { resolve: nodeRequire.resolve, cache: nodeRequire.cache, main: nodeRequire.main, extensions: nodeRequire.extensions });
473
+ try {
474
+ const run = (0, node_vm_1.compileFunction)(source, ['exports', 'require', 'module', '__filename', '__dirname'], { filename });
475
+ run.call(mod.exports, mod.exports, localRequire, mod, filename, (0, node_path_1.dirname)(filename));
476
+ }
477
+ catch (e) {
478
+ this.encryptedModules.delete(cacheKey);
479
+ throw e;
480
+ }
481
+ mod.loaded = true;
482
+ return mod.exports;
483
+ }
484
+ /**
485
+ * Checks the saved lease once for a feature and returns a synchronous decrypter bound to it: decrypt
486
+ * uses it once, requireEncrypted for a module and the encrypted modules it requires.
487
+ */
488
+ async opener(feature) {
489
+ const fingerprintHash = await this.fingerprint();
490
+ const stored = await this.load();
491
+ if (!stored?.token)
492
+ throw new LicenseError('unlicensed', 'This device has no license.');
493
+ const leased = { ...stored, token: stored.token };
494
+ const state = this.stateFromLease(leased, true);
495
+ if (state.status !== 'valid' && state.status !== 'grace') {
496
+ throw new LicenseError(state.status === 'clock_suspect' ? 'clock_suspect' : (state.reason ?? 'invalid'), state.message ?? 'The license is not valid.');
497
+ }
498
+ const claims = (0, seal_core_1.decodeLease)(leased.token)?.claims;
499
+ const graceSeconds = state.status === 'grace' ? (claims?.grc ?? (this.opts.graceDays ?? DEFAULT_GRACE_DAYS) * 86400) : 0;
500
+ const check = { product: this.opts.product, fingerprintHash, now: this.nowSec(), ...(graceSeconds ? { graceSeconds } : {}) };
501
+ const native = this.native();
502
+ return (data) => {
503
+ const result = native && typeof native.decryptFeature === 'function'
504
+ ? native.decryptFeature(leased.token, check, leased.licenseKey, feature, Buffer.from(data))
505
+ : (0, seal_core_1.decryptFeature)(leased.token, { keys: this.keys, ...check }, leased.licenseKey, feature, Buffer.from(data));
506
+ if (result.ok && result.data)
507
+ return Buffer.from(result.data);
508
+ if (result.reason === 'not_licensed')
509
+ throw new LicenseError('feature_not_licensed', `This license does not include "${feature}".`);
510
+ if (result.reason === 'decrypt_failed')
511
+ throw new LicenseError('decrypt_failed', 'The data could not be decrypted with this license.');
512
+ throw new LicenseError(result.reason ?? 'invalid', REASON_TEXT[result.reason] ?? 'The license is not valid.');
513
+ };
514
+ }
515
+ /**
516
+ * Offline activation, step 1 on a machine that cannot reach the server: the request file (JSON text)
517
+ * the user takes to a connected device. The license server turns it into a license file at
518
+ * POST /v1/offline/activate (or its offline activation page). It holds what activate() would send:
519
+ * the license key, this device's fingerprint and hashed hardware parts, never raw serial numbers.
520
+ */
521
+ async offlineRequest(licenseKey, machineName) {
522
+ const fingerprint = await this.fingerprint();
523
+ const activation = {
524
+ licenseKey: licenseKey.trim().toUpperCase(),
525
+ product: this.opts.product,
526
+ fingerprint,
527
+ machineName: machineName?.slice(0, 80),
528
+ platform: (0, node_os_1.platform)(),
529
+ appVersion: this.opts.appVersion,
530
+ sdkVersion: exports.SDK_VERSION,
531
+ ...(await this.hardware()),
532
+ ...this.deviceKey(),
533
+ };
534
+ return JSON.stringify({ format: OFFLINE_REQUEST_FORMAT, version: 1, activation }, null, 2);
535
+ }
536
+ /**
537
+ * Offline activation, step 2: loads the license file the server issued for this machine's request.
538
+ * It is verified like an online lease (signature, product, this device) and then saved; from then on
539
+ * check() works without the server until the lease's renewal date plus the offline grace. Throws a
540
+ * LicenseError: `invalid_file`, `wrong_product`, or a lease failure reason such as `wrong_device`.
541
+ */
542
+ async activateOffline(licenseFile) {
543
+ await this.fingerprint();
544
+ let file;
545
+ try {
546
+ file = JSON.parse(licenseFile);
547
+ }
548
+ catch {
549
+ throw new LicenseError('invalid_file', 'This is not a Carcha Seal offline license file.');
550
+ }
551
+ if (!file || file.format !== OFFLINE_LICENSE_FORMAT || file.version !== 1 || typeof file.token !== 'string' || typeof file.licenseKey !== 'string') {
552
+ throw new LicenseError('invalid_file', 'This is not a Carcha Seal offline license file.');
553
+ }
554
+ if (file.product !== this.opts.product)
555
+ throw new LicenseError('wrong_product', 'This offline license file is for another product.');
556
+ const stored = { licenseKey: file.licenseKey.trim().toUpperCase(), token: file.token, lastSeen: this.nowSec(), offline: true };
557
+ const state = this.stateFromLease(stored, true);
558
+ if (state.status !== 'valid') {
559
+ throw new LicenseError(state.status === 'clock_suspect' ? 'clock_suspect' : state.reason ?? 'invalid', state.message ?? 'This offline license file cannot be used on this computer.');
560
+ }
561
+ await this.save(stored);
562
+ return state;
563
+ }
564
+ /**
565
+ * Gives an offline machine's seat back: removes the license from this device and returns the
566
+ * deactivation file (JSON text) for the vendor, who frees the seat by uploading it in the console.
567
+ * Throws `unlicensed` when there is no license to remove.
568
+ */
569
+ async deactivateOffline() {
570
+ const stored = await this.load();
571
+ if (!stored?.token)
572
+ throw new LicenseError('unlicensed', 'This device has no license.');
573
+ await this.clear();
574
+ return JSON.stringify({ format: OFFLINE_DEACTIVATION_FORMAT, version: 1, product: this.opts.product, token: stored.token }, null, 2);
575
+ }
576
+ async deactivate() {
577
+ const stored = await this.load();
578
+ if (!stored)
579
+ return;
580
+ try {
581
+ await this.post('/v1/deactivate', {
582
+ licenseKey: stored.licenseKey,
583
+ product: this.opts.product,
584
+ fingerprint: await this.fingerprint(),
585
+ ...(await this.hardware()),
586
+ });
587
+ }
588
+ catch (e) {
589
+ if (!(e instanceof LicenseError && (e.code === 'not_activated' || e.code === 'invalid_key')))
590
+ throw e;
591
+ }
592
+ await this.clear();
593
+ }
594
+ static hasFeature(state, feature) {
595
+ return (state.status === 'valid' || state.status === 'grace') && state.features.includes(feature);
596
+ }
597
+ }
598
+ exports.Seal = Seal;
599
+ exports.LicenseKit = Seal;
600
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,qCAAmD;AACnD,+CAA0E;AAC1E,6CAA4C;AAC5C,qCAAmC;AACnC,yCAAmD;AACnD,qCAA0C;AAC1C,qDAA4K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