@tbsoft-gmbh/signature-sdk 1.0.0 → 1.0.2

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.
@@ -8,9 +8,6 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __esm = (fn, res) => function __init() {
9
9
  return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
10
  };
11
- var __commonJS = (cb, mod) => function __require() {
12
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
- };
14
11
  var __export = (target, all) => {
15
12
  for (var name in all)
16
13
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -33,1703 +30,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
33
30
  ));
34
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
32
 
36
- // node_modules/node-gyp-build/node-gyp-build.js
37
- var require_node_gyp_build = __commonJS({
38
- "node_modules/node-gyp-build/node-gyp-build.js"(exports2, module2) {
39
- "use strict";
40
- var fs3 = require("fs");
41
- var path2 = require("path");
42
- var os = require("os");
43
- var runtimeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
44
- var vars = process.config && process.config.variables || {};
45
- var prebuildsOnly = !!process.env.PREBUILDS_ONLY;
46
- var abi = process.versions.modules;
47
- var runtime = isElectron() ? "electron" : isNwjs() ? "node-webkit" : "node";
48
- var arch = process.env.npm_config_arch || os.arch();
49
- var platform = process.env.npm_config_platform || os.platform();
50
- var libc = process.env.LIBC || (isAlpine(platform) ? "musl" : "glibc");
51
- var armv = process.env.ARM_VERSION || (arch === "arm64" ? "8" : vars.arm_version) || "";
52
- var uv = (process.versions.uv || "").split(".")[0];
53
- module2.exports = load;
54
- function load(dir) {
55
- return runtimeRequire(load.resolve(dir));
56
- }
57
- load.resolve = load.path = function(dir) {
58
- dir = path2.resolve(dir || ".");
59
- try {
60
- var name = runtimeRequire(path2.join(dir, "package.json")).name.toUpperCase().replace(/-/g, "_");
61
- if (process.env[name + "_PREBUILD"]) dir = process.env[name + "_PREBUILD"];
62
- } catch (err) {
63
- }
64
- if (!prebuildsOnly) {
65
- var release = getFirst(path2.join(dir, "build/Release"), matchBuild);
66
- if (release) return release;
67
- var debug = getFirst(path2.join(dir, "build/Debug"), matchBuild);
68
- if (debug) return debug;
69
- }
70
- var prebuild = resolve(dir);
71
- if (prebuild) return prebuild;
72
- var nearby = resolve(path2.dirname(process.execPath));
73
- if (nearby) return nearby;
74
- var target = [
75
- "platform=" + platform,
76
- "arch=" + arch,
77
- "runtime=" + runtime,
78
- "abi=" + abi,
79
- "uv=" + uv,
80
- armv ? "armv=" + armv : "",
81
- "libc=" + libc,
82
- "node=" + process.versions.node,
83
- process.versions.electron ? "electron=" + process.versions.electron : "",
84
- typeof __webpack_require__ === "function" ? "webpack=true" : ""
85
- // eslint-disable-line
86
- ].filter(Boolean).join(" ");
87
- throw new Error("No native build was found for " + target + "\n loaded from: " + dir + "\n");
88
- function resolve(dir2) {
89
- var tuples = readdirSync(path2.join(dir2, "prebuilds")).map(parseTuple);
90
- var tuple = tuples.filter(matchTuple(platform, arch)).sort(compareTuples)[0];
91
- if (!tuple) return;
92
- var prebuilds = path2.join(dir2, "prebuilds", tuple.name);
93
- var parsed = readdirSync(prebuilds).map(parseTags);
94
- var candidates = parsed.filter(matchTags(runtime, abi));
95
- var winner = candidates.sort(compareTags(runtime))[0];
96
- if (winner) return path2.join(prebuilds, winner.file);
97
- }
98
- };
99
- function readdirSync(dir) {
100
- try {
101
- return fs3.readdirSync(dir);
102
- } catch (err) {
103
- return [];
104
- }
105
- }
106
- function getFirst(dir, filter) {
107
- var files = readdirSync(dir).filter(filter);
108
- return files[0] && path2.join(dir, files[0]);
109
- }
110
- function matchBuild(name) {
111
- return /\.node$/.test(name);
112
- }
113
- function parseTuple(name) {
114
- var arr = name.split("-");
115
- if (arr.length !== 2) return;
116
- var platform2 = arr[0];
117
- var architectures = arr[1].split("+");
118
- if (!platform2) return;
119
- if (!architectures.length) return;
120
- if (!architectures.every(Boolean)) return;
121
- return { name, platform: platform2, architectures };
122
- }
123
- function matchTuple(platform2, arch2) {
124
- return function(tuple) {
125
- if (tuple == null) return false;
126
- if (tuple.platform !== platform2) return false;
127
- return tuple.architectures.includes(arch2);
128
- };
129
- }
130
- function compareTuples(a, b) {
131
- return a.architectures.length - b.architectures.length;
132
- }
133
- function parseTags(file) {
134
- var arr = file.split(".");
135
- var extension = arr.pop();
136
- var tags = { file, specificity: 0 };
137
- if (extension !== "node") return;
138
- for (var i = 0; i < arr.length; i++) {
139
- var tag = arr[i];
140
- if (tag === "node" || tag === "electron" || tag === "node-webkit") {
141
- tags.runtime = tag;
142
- } else if (tag === "napi") {
143
- tags.napi = true;
144
- } else if (tag.slice(0, 3) === "abi") {
145
- tags.abi = tag.slice(3);
146
- } else if (tag.slice(0, 2) === "uv") {
147
- tags.uv = tag.slice(2);
148
- } else if (tag.slice(0, 4) === "armv") {
149
- tags.armv = tag.slice(4);
150
- } else if (tag === "glibc" || tag === "musl") {
151
- tags.libc = tag;
152
- } else {
153
- continue;
154
- }
155
- tags.specificity++;
156
- }
157
- return tags;
158
- }
159
- function matchTags(runtime2, abi2) {
160
- return function(tags) {
161
- if (tags == null) return false;
162
- if (tags.runtime && tags.runtime !== runtime2 && !runtimeAgnostic(tags)) return false;
163
- if (tags.abi && tags.abi !== abi2 && !tags.napi) return false;
164
- if (tags.uv && tags.uv !== uv) return false;
165
- if (tags.armv && tags.armv !== armv) return false;
166
- if (tags.libc && tags.libc !== libc) return false;
167
- return true;
168
- };
169
- }
170
- function runtimeAgnostic(tags) {
171
- return tags.runtime === "node" && tags.napi;
172
- }
173
- function compareTags(runtime2) {
174
- return function(a, b) {
175
- if (a.runtime !== b.runtime) {
176
- return a.runtime === runtime2 ? -1 : 1;
177
- } else if (a.abi !== b.abi) {
178
- return a.abi ? -1 : 1;
179
- } else if (a.specificity !== b.specificity) {
180
- return a.specificity > b.specificity ? -1 : 1;
181
- } else {
182
- return 0;
183
- }
184
- };
185
- }
186
- function isNwjs() {
187
- return !!(process.versions && process.versions.nw);
188
- }
189
- function isElectron() {
190
- if (process.versions && process.versions.electron) return true;
191
- if (process.env.ELECTRON_RUN_AS_NODE) return true;
192
- return typeof window !== "undefined" && window.process && window.process.type === "renderer";
193
- }
194
- function isAlpine(platform2) {
195
- return platform2 === "linux" && fs3.existsSync("/etc/alpine-release");
196
- }
197
- load.parseTags = parseTags;
198
- load.matchTags = matchTags;
199
- load.compareTags = compareTags;
200
- load.parseTuple = parseTuple;
201
- load.matchTuple = matchTuple;
202
- load.compareTuples = compareTuples;
203
- }
204
- });
205
-
206
- // node_modules/node-gyp-build/index.js
207
- var require_node_gyp_build2 = __commonJS({
208
- "node_modules/node-gyp-build/index.js"(exports2, module2) {
209
- "use strict";
210
- var runtimeRequire = typeof __webpack_require__ === "function" ? __non_webpack_require__ : require;
211
- if (typeof runtimeRequire.addon === "function") {
212
- module2.exports = runtimeRequire.addon.bind(runtimeRequire);
213
- } else {
214
- module2.exports = require_node_gyp_build();
215
- }
216
- }
217
- });
218
-
219
- // node_modules/usb/dist/usb/bindings.js
220
- var require_bindings = __commonJS({
221
- "node_modules/usb/dist/usb/bindings.js"(exports2, module2) {
222
- "use strict";
223
- Object.defineProperty(exports2, "__esModule", { value: true });
224
- var path_1 = require("path");
225
- var usb = require_node_gyp_build2()(process.env.NODE_USB_PATH || (0, path_1.join)(__dirname, "..", ".."));
226
- module2.exports = usb;
227
- }
228
- });
229
-
230
- // node_modules/usb/dist/usb/endpoint.js
231
- var require_endpoint = __commonJS({
232
- "node_modules/usb/dist/usb/endpoint.js"(exports2) {
233
- "use strict";
234
- Object.defineProperty(exports2, "__esModule", { value: true });
235
- exports2.OutEndpoint = exports2.InEndpoint = exports2.Endpoint = void 0;
236
- var events_1 = require("events");
237
- var bindings_1 = require_bindings();
238
- var util_1 = require("util");
239
- var isBuffer = (obj) => obj && obj instanceof Buffer;
240
- var Endpoint = class extends events_1.EventEmitter {
241
- constructor(device, descriptor) {
242
- super();
243
- this.device = device;
244
- this.timeout = 0;
245
- this.descriptor = descriptor;
246
- this.address = descriptor.bEndpointAddress;
247
- this.transferType = descriptor.bmAttributes & 3;
248
- }
249
- /** Clear the halt/stall condition for this endpoint. */
250
- clearHalt(callback) {
251
- return this.device.__clearHalt(this.address, callback);
252
- }
253
- /**
254
- * Create a new `Transfer` object for this endpoint.
255
- *
256
- * The passed callback will be called when the transfer is submitted and finishes. Its arguments are the error (if any), the submitted buffer, and the amount of data actually written (for
257
- * OUT transfers) or read (for IN transfers).
258
- *
259
- * @param timeout Timeout for the transfer (0 means unlimited).
260
- * @param callback Transfer completion callback.
261
- */
262
- makeTransfer(timeout, callback) {
263
- return new bindings_1.Transfer(this.device, this.address, this.transferType, timeout, callback);
264
- }
265
- };
266
- exports2.Endpoint = Endpoint;
267
- var InEndpoint = class extends Endpoint {
268
- constructor(device, descriptor) {
269
- super(device, descriptor);
270
- this.direction = "in";
271
- this.pollTransfers = [];
272
- this.pollTransferSize = 0;
273
- this.pollPending = 0;
274
- this.pollActive = false;
275
- this.transferAsync = (0, util_1.promisify)(this.transfer).bind(this);
276
- }
277
- /**
278
- * Perform a transfer to read data from the endpoint.
279
- *
280
- * If length is greater than maxPacketSize, libusb will automatically split the transfer in multiple packets, and you will receive one callback with all data once all packets are complete.
281
- *
282
- * `this` in the callback is the InEndpoint object.
283
- *
284
- * The device must be open to use this method.
285
- * @param length
286
- * @param callback
287
- */
288
- transfer(length, callback) {
289
- const buffer = Buffer.alloc(length);
290
- const cb = (error, _buffer, actualLength) => {
291
- callback.call(this, error, buffer.slice(0, actualLength));
292
- };
293
- try {
294
- this.makeTransfer(this.timeout, cb).submit(buffer);
295
- } catch (e) {
296
- process.nextTick(() => callback.call(this, e));
297
- }
298
- return this;
299
- }
300
- /**
301
- * Start polling the endpoint.
302
- *
303
- * The library will keep `nTransfers` transfers of size `transferSize` pending in the kernel at all times to ensure continuous data flow.
304
- * This is handled by the libusb event thread, so it continues even if the Node v8 thread is busy. The `data` and `error` events are emitted as transfers complete.
305
- *
306
- * The device must be open to use this method.
307
- * @param nTransfers
308
- * @param transferSize
309
- * @param callback
310
- */
311
- startPoll(nTransfers, transferSize, callback) {
312
- const transferDone = (error, transfer, buffer, actualLength) => {
313
- if (!error) {
314
- this.emit("data", buffer.slice(0, actualLength));
315
- } else if (error.errno !== bindings_1.LIBUSB_TRANSFER_CANCELLED) {
316
- if (this.pollActive) {
317
- this.emit("error", error);
318
- this.stopPoll();
319
- }
320
- }
321
- if (this.pollActive) {
322
- startTransfer(transfer);
323
- } else {
324
- this.pollPending--;
325
- if (this.pollPending === 0) {
326
- this.pollTransfers = [];
327
- this.pollActive = false;
328
- this.emit("end");
329
- if (callback) {
330
- const cancelled = (error === null || error === void 0 ? void 0 : error.errno) === bindings_1.LIBUSB_TRANSFER_CANCELLED;
331
- callback(cancelled ? void 0 : error, buffer, actualLength, cancelled);
332
- }
333
- }
334
- }
335
- };
336
- const startTransfer = (transfer) => {
337
- try {
338
- transfer.submit(Buffer.alloc(this.pollTransferSize), (error, buffer, actualLength) => {
339
- transferDone(error, transfer, buffer, actualLength);
340
- });
341
- } catch (e) {
342
- this.emit("error", e);
343
- this.stopPoll();
344
- }
345
- };
346
- this.pollTransfers = this.startPollTransfers(nTransfers, transferSize, function(error, buffer, actualLength) {
347
- transferDone(error, this, buffer, actualLength);
348
- });
349
- this.pollTransfers.forEach(startTransfer);
350
- this.pollPending = this.pollTransfers.length;
351
- return this.pollTransfers;
352
- }
353
- startPollTransfers(nTransfers = 3, transferSize = this.descriptor.wMaxPacketSize, callback) {
354
- if (this.pollActive) {
355
- throw new Error("Polling already active");
356
- }
357
- this.pollTransferSize = transferSize;
358
- this.pollActive = true;
359
- this.pollPending = 0;
360
- const transfers = [];
361
- for (let i = 0; i < nTransfers; i++) {
362
- const transfer = this.makeTransfer(0, callback);
363
- transfers[i] = transfer;
364
- }
365
- return transfers;
366
- }
367
- /**
368
- * Stop polling.
369
- *
370
- * Further data may still be received. The `end` event is emitted and the callback is called once all transfers have completed or canceled.
371
- *
372
- * The device must be open to use this method.
373
- * @param callback
374
- */
375
- stopPoll(callback) {
376
- if (!this.pollActive) {
377
- throw new Error("Polling is not active.");
378
- }
379
- for (let i = 0; i < this.pollTransfers.length; i++) {
380
- try {
381
- this.pollTransfers[i].cancel();
382
- } catch (error) {
383
- this.emit("error", error);
384
- }
385
- }
386
- this.pollActive = false;
387
- if (callback)
388
- this.once("end", callback);
389
- }
390
- };
391
- exports2.InEndpoint = InEndpoint;
392
- var OutEndpoint = class extends Endpoint {
393
- constructor(device, descriptor) {
394
- super(device, descriptor);
395
- this.direction = "out";
396
- this.transferAsync = (0, util_1.promisify)(this.transfer).bind(this);
397
- }
398
- /**
399
- * Perform a transfer to write `data` to the endpoint.
400
- *
401
- * If length is greater than maxPacketSize, libusb will automatically split the transfer in multiple packets, and you will receive one callback once all packets are complete.
402
- *
403
- * `this` in the callback is the OutEndpoint object.
404
- *
405
- * The device must be open to use this method.
406
- * @param buffer
407
- * @param callback
408
- */
409
- transfer(buffer, callback) {
410
- if (!buffer) {
411
- buffer = Buffer.alloc(0);
412
- } else if (!isBuffer(buffer)) {
413
- buffer = Buffer.from(buffer);
414
- }
415
- const cb = (error, _buffer, actual) => {
416
- if (callback) {
417
- callback.call(this, error, actual || 0);
418
- }
419
- };
420
- try {
421
- this.makeTransfer(this.timeout, cb).submit(buffer);
422
- } catch (e) {
423
- process.nextTick(() => cb(e));
424
- }
425
- return this;
426
- }
427
- transferWithZLP(buffer, callback) {
428
- if (buffer.length % this.descriptor.wMaxPacketSize === 0) {
429
- this.transfer(buffer);
430
- this.transfer(Buffer.alloc(0), callback);
431
- } else {
432
- this.transfer(buffer, callback);
433
- }
434
- }
435
- };
436
- exports2.OutEndpoint = OutEndpoint;
437
- }
438
- });
439
-
440
- // node_modules/usb/dist/usb/interface.js
441
- var require_interface = __commonJS({
442
- "node_modules/usb/dist/usb/interface.js"(exports2) {
443
- "use strict";
444
- Object.defineProperty(exports2, "__esModule", { value: true });
445
- exports2.Interface = void 0;
446
- var bindings_1 = require_bindings();
447
- var endpoint_1 = require_endpoint();
448
- var util_1 = require("util");
449
- var Interface = class {
450
- constructor(device, id) {
451
- this.device = device;
452
- this.id = id;
453
- this.altSetting = 0;
454
- this.refresh();
455
- this.releaseAsync = (0, util_1.promisify)(this.release).bind(this);
456
- this.setAltSettingAsync = (0, util_1.promisify)(this.setAltSetting).bind(this);
457
- }
458
- refresh() {
459
- if (!this.device.configDescriptor) {
460
- return;
461
- }
462
- this.descriptor = this.device.configDescriptor.interfaces[this.id][this.altSetting];
463
- this.interfaceNumber = this.descriptor.bInterfaceNumber;
464
- this.endpoints = [];
465
- const len = this.descriptor.endpoints.length;
466
- for (let i = 0; i < len; i++) {
467
- const desc = this.descriptor.endpoints[i];
468
- const c = desc.bEndpointAddress & bindings_1.LIBUSB_ENDPOINT_IN ? endpoint_1.InEndpoint : endpoint_1.OutEndpoint;
469
- this.endpoints[i] = new c(this.device, desc);
470
- }
471
- }
472
- /**
473
- * Claims the interface. This method must be called before using any endpoints of this interface.
474
- *
475
- * The device must be open to use this method.
476
- */
477
- claim() {
478
- this.device.__claimInterface(this.id);
479
- }
480
- release(closeEndpointsOrCallback, callback) {
481
- let closeEndpoints = false;
482
- if (typeof closeEndpointsOrCallback === "boolean") {
483
- closeEndpoints = closeEndpointsOrCallback;
484
- } else {
485
- callback = closeEndpointsOrCallback;
486
- }
487
- const next = () => {
488
- this.device.__releaseInterface(this.id, (error) => {
489
- if (!error) {
490
- this.altSetting = 0;
491
- this.refresh();
492
- }
493
- if (callback) {
494
- callback.call(this, error);
495
- }
496
- });
497
- };
498
- if (!closeEndpoints || this.endpoints.length === 0) {
499
- next();
500
- } else {
501
- let n = this.endpoints.length;
502
- this.endpoints.forEach((ep) => {
503
- if (ep.direction === "in" && ep.pollActive) {
504
- ep.once("end", () => {
505
- if (--n === 0) {
506
- next();
507
- }
508
- });
509
- ep.stopPoll();
510
- } else {
511
- if (--n === 0) {
512
- next();
513
- }
514
- }
515
- });
516
- }
517
- }
518
- /**
519
- * Returns `false` if a kernel driver is not active; `true` if active.
520
- *
521
- * The device must be open to use this method.
522
- */
523
- isKernelDriverActive() {
524
- return this.device.__isKernelDriverActive(this.id);
525
- }
526
- /**
527
- * Detaches the kernel driver from the interface.
528
- *
529
- * The device must be open to use this method.
530
- */
531
- detachKernelDriver() {
532
- return this.device.__detachKernelDriver(this.id);
533
- }
534
- /**
535
- * Re-attaches the kernel driver for the interface.
536
- *
537
- * The device must be open to use this method.
538
- */
539
- attachKernelDriver() {
540
- return this.device.__attachKernelDriver(this.id);
541
- }
542
- /**
543
- * Sets the alternate setting. It updates the `interface.endpoints` array to reflect the endpoints found in the alternate setting.
544
- *
545
- * The device must be open to use this method.
546
- * @param altSetting
547
- * @param callback
548
- */
549
- setAltSetting(altSetting, callback) {
550
- this.device.__setInterface(this.id, altSetting, (error) => {
551
- if (!error) {
552
- this.altSetting = altSetting;
553
- this.refresh();
554
- }
555
- if (callback) {
556
- callback.call(this, error);
557
- }
558
- });
559
- }
560
- /**
561
- * Return the InEndpoint or OutEndpoint with the specified address.
562
- *
563
- * The device must be open to use this method.
564
- * @param addr
565
- */
566
- endpoint(addr) {
567
- return this.endpoints.find((item) => item.address === addr);
568
- }
569
- };
570
- exports2.Interface = Interface;
571
- }
572
- });
573
-
574
- // node_modules/usb/dist/usb/capability.js
575
- var require_capability = __commonJS({
576
- "node_modules/usb/dist/usb/capability.js"(exports2) {
577
- "use strict";
578
- Object.defineProperty(exports2, "__esModule", { value: true });
579
- exports2.Capability = void 0;
580
- var Capability = class {
581
- constructor(device, id) {
582
- this.device = device;
583
- this.id = id;
584
- if (!device._bosDescriptor) {
585
- throw new Error("bosDescriptor not found");
586
- }
587
- this.descriptor = device._bosDescriptor.capabilities[this.id];
588
- this.type = this.descriptor.bDevCapabilityType;
589
- this.data = this.descriptor.dev_capability_data;
590
- }
591
- };
592
- exports2.Capability = Capability;
593
- }
594
- });
595
-
596
- // node_modules/usb/dist/usb/device.js
597
- var require_device = __commonJS({
598
- "node_modules/usb/dist/usb/device.js"(exports2) {
599
- "use strict";
600
- Object.defineProperty(exports2, "__esModule", { value: true });
601
- exports2.ExtendedDevice = void 0;
602
- var usb = require_bindings();
603
- var interface_1 = require_interface();
604
- var capability_1 = require_capability();
605
- var isBuffer = (obj) => !!obj && obj instanceof Uint8Array;
606
- var DEFAULT_TIMEOUT = 1e3;
607
- var ExtendedDevice = class {
608
- constructor() {
609
- this._timeout = DEFAULT_TIMEOUT;
610
- }
611
- /**
612
- * Timeout in milliseconds to use for control transfers.
613
- */
614
- get timeout() {
615
- return this._timeout || DEFAULT_TIMEOUT;
616
- }
617
- set timeout(value) {
618
- this._timeout = value;
619
- }
620
- /**
621
- * Object with properties for the fields of the active configuration descriptor.
622
- */
623
- get configDescriptor() {
624
- try {
625
- return this.__getConfigDescriptor();
626
- } catch (e) {
627
- const errno = e.errno;
628
- if (errno === usb.LIBUSB_ERROR_NOT_FOUND || errno === usb.LIBUSB_ERROR_NO_DEVICE) {
629
- return void 0;
630
- }
631
- throw e;
632
- }
633
- }
634
- /**
635
- * Contains all config descriptors of the device (same structure as .configDescriptor above)
636
- */
637
- get allConfigDescriptors() {
638
- try {
639
- return this.__getAllConfigDescriptors();
640
- } catch (e) {
641
- const errno = e.errno;
642
- if (errno === usb.LIBUSB_ERROR_NOT_FOUND || errno === usb.LIBUSB_ERROR_NO_DEVICE) {
643
- return [];
644
- }
645
- throw e;
646
- }
647
- }
648
- /**
649
- * Contains the parent of the device, such as a hub. If there is no parent this property is set to `null`.
650
- */
651
- get parent() {
652
- return this.__getParent();
653
- }
654
- /**
655
- * Open the device.
656
- * @param defaultConfig
657
- */
658
- open(defaultConfig = true) {
659
- this.__open();
660
- this.interfaces = [];
661
- if (defaultConfig === false) {
662
- return;
663
- }
664
- const len = this.configDescriptor ? this.configDescriptor.interfaces.length : 0;
665
- for (let i = 0; i < len; i++) {
666
- this.interfaces[i] = new interface_1.Interface(this, i);
667
- }
668
- }
669
- /**
670
- * Close the device.
671
- *
672
- * The device must be open to use this method.
673
- */
674
- close() {
675
- this.__close();
676
- this.interfaces = void 0;
677
- }
678
- /**
679
- * Set the device configuration to something other than the default (0). To use this, first call `.open(false)` (which tells it not to auto configure),
680
- * then before claiming an interface, call this method.
681
- *
682
- * The device must be open to use this method.
683
- * @param desired
684
- * @param callback
685
- */
686
- setConfiguration(desired, callback) {
687
- this.__setConfiguration(desired, (error) => {
688
- if (!error) {
689
- this.interfaces = [];
690
- const len = this.configDescriptor ? this.configDescriptor.interfaces.length : 0;
691
- for (let i = 0; i < len; i++) {
692
- this.interfaces[i] = new interface_1.Interface(this, i);
693
- }
694
- }
695
- if (callback) {
696
- callback.call(this, error);
697
- }
698
- });
699
- }
700
- /**
701
- * Enable/disable libusb's automatic kernel driver detachment
702
- * When this is enabled libusb will automatically detach the kernel driver on an interface when claiming the interface, and attach it when releasing the interface
703
- *
704
- * The device must be open to use this method.
705
- */
706
- setAutoDetachKernelDriver(enable) {
707
- return this.__setAutoDetachKernelDriver(enable ? 1 : 0);
708
- }
709
- /**
710
- * Perform a control transfer with `libusb_control_transfer`.
711
- *
712
- * Parameter `data_or_length` can be an integer length for an IN transfer, or a `Buffer` for an OUT transfer. The type must match the direction specified in the MSB of bmRequestType.
713
- *
714
- * The `data` parameter of the callback is actual transferred for OUT transfers, or will be passed a Buffer for IN transfers.
715
- *
716
- * The device must be open to use this method.
717
- * @param bmRequestType
718
- * @param bRequest
719
- * @param wValue
720
- * @param wIndex
721
- * @param data_or_length
722
- * @param callback
723
- */
724
- controlTransfer(bmRequestType, bRequest, wValue, wIndex, data_or_length, callback) {
725
- const isIn = !!(bmRequestType & usb.LIBUSB_ENDPOINT_IN);
726
- const wLength = isIn ? data_or_length : data_or_length.length;
727
- if (isIn) {
728
- if (wLength < 0) {
729
- throw new TypeError("Expected size number for IN transfer (based on bmRequestType)");
730
- }
731
- } else {
732
- if (!isBuffer(data_or_length)) {
733
- throw new TypeError("Expected buffer for OUT transfer (based on bmRequestType)");
734
- }
735
- }
736
- const buf = Buffer.alloc(wLength + usb.LIBUSB_CONTROL_SETUP_SIZE);
737
- buf.writeUInt8(bmRequestType, 0);
738
- buf.writeUInt8(bRequest, 1);
739
- buf.writeUInt16LE(wValue, 2);
740
- buf.writeUInt16LE(wIndex, 4);
741
- buf.writeUInt16LE(wLength, 6);
742
- if (!isIn) {
743
- buf.set(data_or_length, usb.LIBUSB_CONTROL_SETUP_SIZE);
744
- }
745
- const transfer = new usb.Transfer(this, 0, usb.LIBUSB_TRANSFER_TYPE_CONTROL, this.timeout, (error, buf2, actual) => {
746
- if (callback) {
747
- if (isIn) {
748
- callback.call(this, error, buf2.slice(usb.LIBUSB_CONTROL_SETUP_SIZE, usb.LIBUSB_CONTROL_SETUP_SIZE + actual));
749
- } else {
750
- callback.call(this, error, actual);
751
- }
752
- }
753
- });
754
- try {
755
- transfer.submit(buf);
756
- } catch (e) {
757
- if (callback) {
758
- process.nextTick(() => callback.call(this, e, void 0));
759
- }
760
- }
761
- return this;
762
- }
763
- /**
764
- * Return the interface with the specified interface number.
765
- *
766
- * The device must be open to use this method.
767
- * @param addr
768
- */
769
- interface(addr) {
770
- if (!this.interfaces) {
771
- throw new Error("Device must be open before searching for interfaces");
772
- }
773
- addr = addr || 0;
774
- for (let i = 0; i < this.interfaces.length; i++) {
775
- if (this.interfaces[i].interfaceNumber === addr) {
776
- return this.interfaces[i];
777
- }
778
- }
779
- throw new Error(`Interface not found for address: ${addr}`);
780
- }
781
- /**
782
- * Perform a control transfer to retrieve a string descriptor
783
- *
784
- * The device must be open to use this method.
785
- * @param desc_index
786
- * @param callback
787
- */
788
- getStringDescriptor(desc_index, callback) {
789
- if (desc_index === 0) {
790
- callback();
791
- return;
792
- }
793
- const langid = 1033;
794
- const length = 255;
795
- this.controlTransfer(usb.LIBUSB_ENDPOINT_IN, usb.LIBUSB_REQUEST_GET_DESCRIPTOR, usb.LIBUSB_DT_STRING << 8 | desc_index, langid, length, (error, buffer) => {
796
- if (error) {
797
- return callback(error);
798
- }
799
- callback(void 0, isBuffer(buffer) ? buffer.toString("utf16le", 2) : void 0);
800
- });
801
- }
802
- /**
803
- * Perform a control transfer to retrieve an object with properties for the fields of the Binary Object Store descriptor.
804
- *
805
- * The device must be open to use this method.
806
- * @param callback
807
- */
808
- getBosDescriptor(callback) {
809
- if (this._bosDescriptor) {
810
- return callback(void 0, this._bosDescriptor);
811
- }
812
- if (this.deviceDescriptor.bcdUSB < 513) {
813
- return callback(void 0, void 0);
814
- }
815
- this.controlTransfer(usb.LIBUSB_ENDPOINT_IN, usb.LIBUSB_REQUEST_GET_DESCRIPTOR, usb.LIBUSB_DT_BOS << 8, 0, usb.LIBUSB_DT_BOS_SIZE, (error, buffer) => {
816
- if (error) {
817
- if (error.errno === usb.LIBUSB_TRANSFER_STALL)
818
- return callback(void 0, void 0);
819
- return callback(error, void 0);
820
- }
821
- if (!isBuffer(buffer)) {
822
- return callback(void 0, void 0);
823
- }
824
- const totalLength = buffer.readUInt16LE(2);
825
- this.controlTransfer(usb.LIBUSB_ENDPOINT_IN, usb.LIBUSB_REQUEST_GET_DESCRIPTOR, usb.LIBUSB_DT_BOS << 8, 0, totalLength, (error2, buffer2) => {
826
- if (error2) {
827
- if (error2.errno === usb.LIBUSB_TRANSFER_STALL)
828
- return callback(void 0, void 0);
829
- return callback(error2, void 0);
830
- }
831
- if (!isBuffer(buffer2)) {
832
- return callback(void 0, void 0);
833
- }
834
- const descriptor = {
835
- bLength: buffer2.readUInt8(0),
836
- bDescriptorType: buffer2.readUInt8(1),
837
- wTotalLength: buffer2.readUInt16LE(2),
838
- bNumDeviceCaps: buffer2.readUInt8(4),
839
- capabilities: []
840
- };
841
- let i = usb.LIBUSB_DT_BOS_SIZE;
842
- while (i < descriptor.wTotalLength) {
843
- const capability = {
844
- bLength: buffer2.readUInt8(i + 0),
845
- bDescriptorType: buffer2.readUInt8(i + 1),
846
- bDevCapabilityType: buffer2.readUInt8(i + 2),
847
- dev_capability_data: buffer2.slice(i + 3, i + buffer2.readUInt8(i + 0))
848
- };
849
- descriptor.capabilities.push(capability);
850
- i += capability.bLength;
851
- }
852
- this._bosDescriptor = descriptor;
853
- callback(void 0, this._bosDescriptor);
854
- });
855
- });
856
- }
857
- /**
858
- * Retrieve a list of Capability objects for the Binary Object Store capabilities of the device.
859
- *
860
- * The device must be open to use this method.
861
- * @param callback
862
- */
863
- getCapabilities(callback) {
864
- const capabilities = [];
865
- this.getBosDescriptor((error, descriptor) => {
866
- if (error)
867
- return callback(error, void 0);
868
- const len = descriptor ? descriptor.capabilities.length : 0;
869
- for (let i = 0; i < len; i++) {
870
- capabilities.push(new capability_1.Capability(this, i));
871
- }
872
- callback(void 0, capabilities);
873
- });
874
- }
875
- };
876
- exports2.ExtendedDevice = ExtendedDevice;
877
- }
878
- });
879
-
880
- // node_modules/usb/dist/usb/index.js
881
- var require_usb = __commonJS({
882
- "node_modules/usb/dist/usb/index.js"(exports2, module2) {
883
- "use strict";
884
- var events_1 = require("events");
885
- var device_1 = require_device();
886
- var usb = require_bindings();
887
- if (usb.INIT_ERROR) {
888
- console.warn("Failed to initialize libusb.");
889
- }
890
- Object.setPrototypeOf(usb, events_1.EventEmitter.prototype);
891
- Object.defineProperty(usb, "pollHotplug", {
892
- value: false,
893
- writable: true
894
- });
895
- Object.defineProperty(usb, "pollHotplugDelay", {
896
- value: 500,
897
- writable: true
898
- });
899
- if (usb.Device) {
900
- Object.getOwnPropertyNames(device_1.ExtendedDevice.prototype).forEach((name) => {
901
- Object.defineProperty(usb.Device.prototype, name, Object.getOwnPropertyDescriptor(device_1.ExtendedDevice.prototype, name) || /* @__PURE__ */ Object.create(null));
902
- });
903
- }
904
- var hotPlugDevices = /* @__PURE__ */ new Set();
905
- var emitHotplugEvents = () => {
906
- const devices = new Set(usb.getDeviceList());
907
- for (const device of devices) {
908
- if (!hotPlugDevices.has(device)) {
909
- usb.emit("attach", device);
910
- }
911
- }
912
- for (const device of hotPlugDevices) {
913
- if (!devices.has(device)) {
914
- usb.emit("detach", device);
915
- }
916
- }
917
- hotPlugDevices = devices;
918
- };
919
- var pollingHotplug = false;
920
- var pollHotplug = (start = false) => {
921
- if (start) {
922
- pollingHotplug = true;
923
- } else if (!pollingHotplug) {
924
- return;
925
- } else {
926
- emitHotplugEvents();
927
- }
928
- setTimeout(() => pollHotplug(), usb.pollHotplugDelay);
929
- };
930
- var devicesChanged = () => setTimeout(() => emitHotplugEvents(), usb.pollHotplugDelay);
931
- var hotplugSupported = 0;
932
- var startHotplug = () => {
933
- hotplugSupported = usb.pollHotplug ? 0 : usb._supportedHotplugEvents();
934
- if (hotplugSupported !== 1) {
935
- hotPlugDevices = new Set(usb.getDeviceList());
936
- }
937
- if (hotplugSupported) {
938
- usb._enableHotplugEvents();
939
- if (hotplugSupported === 2) {
940
- usb.on("attachIds", devicesChanged);
941
- usb.on("detachIds", devicesChanged);
942
- }
943
- } else {
944
- pollHotplug(true);
945
- }
946
- };
947
- var stopHotplug = () => {
948
- if (hotplugSupported) {
949
- usb._disableHotplugEvents();
950
- if (hotplugSupported === 2) {
951
- usb.off("attachIds", devicesChanged);
952
- usb.off("detachIds", devicesChanged);
953
- }
954
- } else {
955
- pollingHotplug = false;
956
- }
957
- };
958
- usb.on("newListener", (event) => {
959
- if (event !== "attach" && event !== "detach") {
960
- return;
961
- }
962
- const listenerCount = usb.listenerCount("attach") + usb.listenerCount("detach");
963
- if (listenerCount === 0) {
964
- startHotplug();
965
- }
966
- });
967
- usb.on("removeListener", (event) => {
968
- if (event !== "attach" && event !== "detach") {
969
- return;
970
- }
971
- const listenerCount = usb.listenerCount("attach") + usb.listenerCount("detach");
972
- if (listenerCount === 0) {
973
- stopHotplug();
974
- }
975
- });
976
- module2.exports = usb;
977
- }
978
- });
979
-
980
- // node_modules/usb/dist/webusb/webusb-device.js
981
- var require_webusb_device = __commonJS({
982
- "node_modules/usb/dist/webusb/webusb-device.js"(exports2) {
983
- "use strict";
984
- Object.defineProperty(exports2, "__esModule", { value: true });
985
- exports2.WebUSBDevice = void 0;
986
- var usb = require_usb();
987
- var util_1 = require("util");
988
- var os_1 = require("os");
989
- var LIBUSB_TRANSFER_TYPE_MASK = 3;
990
- var ENDPOINT_NUMBER_MASK = 127;
991
- var CLEAR_FEATURE = 1;
992
- var ENDPOINT_HALT = 0;
993
- var WebUSBDevice = class _WebUSBDevice {
994
- static async createInstance(device, autoDetachKernelDriver = true) {
995
- const instance = new _WebUSBDevice(device, autoDetachKernelDriver);
996
- await instance.initialize();
997
- return instance;
998
- }
999
- constructor(device, autoDetachKernelDriver) {
1000
- this.device = device;
1001
- this.autoDetachKernelDriver = autoDetachKernelDriver;
1002
- this.manufacturerName = null;
1003
- this.productName = null;
1004
- this.serialNumber = null;
1005
- this.configurations = [];
1006
- const usbVersion = this.decodeVersion(device.deviceDescriptor.bcdUSB);
1007
- this.usbVersionMajor = usbVersion.major;
1008
- this.usbVersionMinor = usbVersion.minor;
1009
- this.usbVersionSubminor = usbVersion.sub;
1010
- this.deviceClass = device.deviceDescriptor.bDeviceClass;
1011
- this.deviceSubclass = device.deviceDescriptor.bDeviceSubClass;
1012
- this.deviceProtocol = device.deviceDescriptor.bDeviceProtocol;
1013
- this.vendorId = device.deviceDescriptor.idVendor;
1014
- this.productId = device.deviceDescriptor.idProduct;
1015
- const deviceVersion = this.decodeVersion(device.deviceDescriptor.bcdDevice);
1016
- this.deviceVersionMajor = deviceVersion.major;
1017
- this.deviceVersionMinor = deviceVersion.minor;
1018
- this.deviceVersionSubminor = deviceVersion.sub;
1019
- this.controlTransferAsync = (0, util_1.promisify)(this.device.controlTransfer).bind(this.device);
1020
- this.setConfigurationAsync = (0, util_1.promisify)(this.device.setConfiguration).bind(this.device);
1021
- this.resetAsync = (0, util_1.promisify)(this.device.reset).bind(this.device);
1022
- this.getStringDescriptorAsync = (0, util_1.promisify)(this.device.getStringDescriptor).bind(this.device);
1023
- }
1024
- get configuration() {
1025
- if (!this.device.configDescriptor) {
1026
- return null;
1027
- }
1028
- const currentConfiguration = this.device.configDescriptor.bConfigurationValue;
1029
- return this.configurations.find((configuration) => configuration.configurationValue === currentConfiguration) || null;
1030
- }
1031
- get opened() {
1032
- return !!this.device.interfaces;
1033
- }
1034
- async open() {
1035
- try {
1036
- if (this.opened) {
1037
- return;
1038
- }
1039
- this.device.open();
1040
- if ((0, os_1.platform)() !== "win32") {
1041
- this.device.setAutoDetachKernelDriver(this.autoDetachKernelDriver);
1042
- }
1043
- } catch (error) {
1044
- throw new Error(`open error: ${error}`);
1045
- }
1046
- }
1047
- async close() {
1048
- try {
1049
- if (!this.opened) {
1050
- return;
1051
- }
1052
- try {
1053
- if (this.configuration) {
1054
- for (const iface of this.configuration.interfaces) {
1055
- await this._releaseInterface(iface.interfaceNumber);
1056
- this.configuration.interfaces[this.configuration.interfaces.indexOf(iface)] = {
1057
- interfaceNumber: iface.interfaceNumber,
1058
- alternate: iface.alternate,
1059
- alternates: iface.alternates,
1060
- claimed: false
1061
- };
1062
- }
1063
- }
1064
- } catch (_error) {
1065
- }
1066
- this.device.close();
1067
- } catch (error) {
1068
- throw new Error(`close error: ${error}`);
1069
- }
1070
- }
1071
- async selectConfiguration(configurationValue) {
1072
- if (!this.opened || !this.device.configDescriptor) {
1073
- throw new Error("selectConfiguration error: invalid state");
1074
- }
1075
- if (this.device.configDescriptor.bConfigurationValue === configurationValue) {
1076
- return;
1077
- }
1078
- const config = this.configurations.find((configuration) => configuration.configurationValue === configurationValue);
1079
- if (!config) {
1080
- throw new Error("selectConfiguration error: configuration not found");
1081
- }
1082
- try {
1083
- await this.setConfigurationAsync(configurationValue);
1084
- } catch (error) {
1085
- throw new Error(`selectConfiguration error: ${error}`);
1086
- }
1087
- }
1088
- async claimInterface(interfaceNumber) {
1089
- if (!this.opened) {
1090
- throw new Error("claimInterface error: invalid state");
1091
- }
1092
- if (!this.configuration) {
1093
- throw new Error("claimInterface error: interface not found");
1094
- }
1095
- const iface = this.configuration.interfaces.find((usbInterface) => usbInterface.interfaceNumber === interfaceNumber);
1096
- if (!iface) {
1097
- throw new Error("claimInterface error: interface not found");
1098
- }
1099
- if (iface.claimed) {
1100
- return;
1101
- }
1102
- try {
1103
- this.device.interface(interfaceNumber).claim();
1104
- this.configuration.interfaces[this.configuration.interfaces.indexOf(iface)] = {
1105
- interfaceNumber,
1106
- alternate: iface.alternate,
1107
- alternates: iface.alternates,
1108
- claimed: true
1109
- };
1110
- } catch (error) {
1111
- throw new Error(`claimInterface error: ${error}`);
1112
- }
1113
- }
1114
- async releaseInterface(interfaceNumber) {
1115
- await this._releaseInterface(interfaceNumber);
1116
- if (this.configuration) {
1117
- const iface = this.configuration.interfaces.find((usbInterface) => usbInterface.interfaceNumber === interfaceNumber);
1118
- if (iface) {
1119
- this.configuration.interfaces[this.configuration.interfaces.indexOf(iface)] = {
1120
- interfaceNumber,
1121
- alternate: iface.alternate,
1122
- alternates: iface.alternates,
1123
- claimed: false
1124
- };
1125
- }
1126
- }
1127
- }
1128
- async selectAlternateInterface(interfaceNumber, alternateSetting) {
1129
- if (!this.opened) {
1130
- throw new Error("selectAlternateInterface error: invalid state");
1131
- }
1132
- if (!this.configuration) {
1133
- throw new Error("selectAlternateInterface error: interface not found");
1134
- }
1135
- const iface = this.configuration.interfaces.find((usbInterface) => usbInterface.interfaceNumber === interfaceNumber);
1136
- if (!iface) {
1137
- throw new Error("selectAlternateInterface error: interface not found");
1138
- }
1139
- if (!iface.claimed) {
1140
- throw new Error("selectAlternateInterface error: invalid state");
1141
- }
1142
- try {
1143
- const iface2 = this.device.interface(interfaceNumber);
1144
- await iface2.setAltSettingAsync(alternateSetting);
1145
- } catch (error) {
1146
- throw new Error(`selectAlternateInterface error: ${error}`);
1147
- }
1148
- }
1149
- async controlTransferIn(setup, length) {
1150
- try {
1151
- this.checkDeviceOpen();
1152
- const type = this.controlTransferParamsToType(setup, usb.LIBUSB_ENDPOINT_IN);
1153
- const result = await this.controlTransferAsync(type, setup.request, setup.value, setup.index, length);
1154
- return {
1155
- data: result ? new DataView(new Uint8Array(result).buffer) : void 0,
1156
- status: "ok"
1157
- };
1158
- } catch (error) {
1159
- if (error.errno === usb.LIBUSB_TRANSFER_STALL) {
1160
- return {
1161
- status: "stall"
1162
- };
1163
- }
1164
- if (error.errno === usb.LIBUSB_TRANSFER_OVERFLOW) {
1165
- return {
1166
- status: "babble"
1167
- };
1168
- }
1169
- throw new Error(`controlTransferIn error: ${error}`);
1170
- }
1171
- }
1172
- async controlTransferOut(setup, data) {
1173
- try {
1174
- this.checkDeviceOpen();
1175
- const type = this.controlTransferParamsToType(setup, usb.LIBUSB_ENDPOINT_OUT);
1176
- const buffer = data ? Buffer.from(data) : Buffer.alloc(0);
1177
- const bytesWritten = await this.controlTransferAsync(type, setup.request, setup.value, setup.index, buffer);
1178
- return {
1179
- bytesWritten,
1180
- status: "ok"
1181
- };
1182
- } catch (error) {
1183
- if (error.errno === usb.LIBUSB_TRANSFER_STALL) {
1184
- return {
1185
- bytesWritten: 0,
1186
- status: "stall"
1187
- };
1188
- }
1189
- throw new Error(`controlTransferOut error: ${error}`);
1190
- }
1191
- }
1192
- async clearHalt(direction, endpointNumber) {
1193
- try {
1194
- const wIndex = endpointNumber | (direction === "in" ? usb.LIBUSB_ENDPOINT_IN : usb.LIBUSB_ENDPOINT_OUT);
1195
- await this.controlTransferAsync(usb.LIBUSB_RECIPIENT_ENDPOINT, CLEAR_FEATURE, ENDPOINT_HALT, wIndex, Buffer.from(new Uint8Array()));
1196
- } catch (error) {
1197
- throw new Error(`clearHalt error: ${error}`);
1198
- }
1199
- }
1200
- async transferIn(endpointNumber, length) {
1201
- try {
1202
- this.checkDeviceOpen();
1203
- const endpoint = this.getEndpoint(endpointNumber | usb.LIBUSB_ENDPOINT_IN);
1204
- const result = await endpoint.transferAsync(length);
1205
- return {
1206
- data: result ? new DataView(new Uint8Array(result).buffer) : void 0,
1207
- status: "ok"
1208
- };
1209
- } catch (error) {
1210
- if (error.errno === usb.LIBUSB_TRANSFER_STALL) {
1211
- return {
1212
- status: "stall"
1213
- };
1214
- }
1215
- if (error.errno === usb.LIBUSB_TRANSFER_OVERFLOW) {
1216
- return {
1217
- status: "babble"
1218
- };
1219
- }
1220
- throw new Error(`transferIn error: ${error}`);
1221
- }
1222
- }
1223
- async transferOut(endpointNumber, data) {
1224
- try {
1225
- this.checkDeviceOpen();
1226
- const endpoint = this.getEndpoint(endpointNumber | usb.LIBUSB_ENDPOINT_OUT);
1227
- const buffer = Buffer.from(data);
1228
- const bytesWritten = await endpoint.transferAsync(buffer);
1229
- return {
1230
- bytesWritten,
1231
- status: "ok"
1232
- };
1233
- } catch (error) {
1234
- if (error.errno === usb.LIBUSB_TRANSFER_STALL) {
1235
- return {
1236
- bytesWritten: 0,
1237
- status: "stall"
1238
- };
1239
- }
1240
- throw new Error(`transferOut error: ${error}`);
1241
- }
1242
- }
1243
- async reset() {
1244
- try {
1245
- await this.resetAsync();
1246
- } catch (error) {
1247
- throw new Error(`reset error: ${error}`);
1248
- }
1249
- }
1250
- async isochronousTransferIn(_endpointNumber, _packetLengths) {
1251
- throw new Error("isochronousTransferIn error: method not implemented");
1252
- }
1253
- async isochronousTransferOut(_endpointNumber, _data, _packetLengths) {
1254
- throw new Error("isochronousTransferOut error: method not implemented");
1255
- }
1256
- async forget() {
1257
- throw new Error("forget error: method not implemented");
1258
- }
1259
- async initialize() {
1260
- try {
1261
- if (!this.opened) {
1262
- this.device.open();
1263
- if (this.deviceClass === 255 && (0, os_1.platform)() === "darwin") {
1264
- await this.setConfigurationAsync(1);
1265
- }
1266
- }
1267
- this.manufacturerName = await this.getStringDescriptor(this.device.deviceDescriptor.iManufacturer);
1268
- this.productName = await this.getStringDescriptor(this.device.deviceDescriptor.iProduct);
1269
- this.serialNumber = await this.getStringDescriptor(this.device.deviceDescriptor.iSerialNumber);
1270
- this.configurations = await this.getConfigurations();
1271
- } catch (error) {
1272
- throw new Error(`initialize error: ${error}`);
1273
- } finally {
1274
- if (this.opened) {
1275
- this.device.close();
1276
- }
1277
- }
1278
- }
1279
- decodeVersion(version) {
1280
- const hex = `0000${version.toString(16)}`.slice(-4);
1281
- return {
1282
- major: parseInt(hex.substr(0, 2), void 0),
1283
- minor: parseInt(hex.substr(2, 1), void 0),
1284
- sub: parseInt(hex.substr(3, 1), void 0)
1285
- };
1286
- }
1287
- async getStringDescriptor(index) {
1288
- try {
1289
- const buffer = await this.getStringDescriptorAsync(index);
1290
- return buffer ? buffer.toString() : "";
1291
- } catch (error) {
1292
- return "";
1293
- }
1294
- }
1295
- async getConfigurations() {
1296
- const configs = [];
1297
- for (const config of this.device.allConfigDescriptors) {
1298
- const interfaces = [];
1299
- for (const iface of config.interfaces) {
1300
- const alternates = [];
1301
- for (const alternate2 of iface) {
1302
- const endpoints = [];
1303
- for (const endpoint of alternate2.endpoints) {
1304
- endpoints.push({
1305
- endpointNumber: endpoint.bEndpointAddress & ENDPOINT_NUMBER_MASK,
1306
- direction: endpoint.bEndpointAddress & usb.LIBUSB_ENDPOINT_IN ? "in" : "out",
1307
- type: (endpoint.bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) === usb.LIBUSB_TRANSFER_TYPE_BULK ? "bulk" : (endpoint.bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) === usb.LIBUSB_TRANSFER_TYPE_INTERRUPT ? "interrupt" : "isochronous",
1308
- packetSize: endpoint.wMaxPacketSize
1309
- });
1310
- }
1311
- alternates.push({
1312
- alternateSetting: alternate2.bAlternateSetting,
1313
- interfaceClass: alternate2.bInterfaceClass,
1314
- interfaceSubclass: alternate2.bInterfaceSubClass,
1315
- interfaceProtocol: alternate2.bInterfaceProtocol,
1316
- interfaceName: await this.getStringDescriptor(alternate2.iInterface),
1317
- endpoints
1318
- });
1319
- }
1320
- const interfaceNumber = iface[0].bInterfaceNumber;
1321
- const alternate = alternates.find((alt) => alt.alternateSetting === this.device.interface(interfaceNumber).altSetting);
1322
- if (alternate) {
1323
- interfaces.push({
1324
- interfaceNumber,
1325
- alternate,
1326
- alternates,
1327
- claimed: false
1328
- });
1329
- }
1330
- }
1331
- configs.push({
1332
- configurationValue: config.bConfigurationValue,
1333
- configurationName: await this.getStringDescriptor(config.iConfiguration),
1334
- interfaces
1335
- });
1336
- }
1337
- return configs;
1338
- }
1339
- getEndpoint(address) {
1340
- if (!this.device.interfaces) {
1341
- return void 0;
1342
- }
1343
- for (const iface of this.device.interfaces) {
1344
- const endpoint = iface.endpoint(address);
1345
- if (endpoint) {
1346
- return endpoint;
1347
- }
1348
- }
1349
- return void 0;
1350
- }
1351
- controlTransferParamsToType(setup, direction) {
1352
- const recipient = setup.recipient === "device" ? usb.LIBUSB_RECIPIENT_DEVICE : setup.recipient === "interface" ? usb.LIBUSB_RECIPIENT_INTERFACE : setup.recipient === "endpoint" ? usb.LIBUSB_RECIPIENT_ENDPOINT : usb.LIBUSB_RECIPIENT_OTHER;
1353
- const requestType = setup.requestType === "standard" ? usb.LIBUSB_REQUEST_TYPE_STANDARD : setup.requestType === "class" ? usb.LIBUSB_REQUEST_TYPE_CLASS : usb.LIBUSB_REQUEST_TYPE_VENDOR;
1354
- return recipient | requestType | direction;
1355
- }
1356
- async _releaseInterface(interfaceNumber) {
1357
- if (!this.opened) {
1358
- throw new Error("releaseInterface error: invalid state");
1359
- }
1360
- if (!this.configuration) {
1361
- throw new Error("releaseInterface error: interface not found");
1362
- }
1363
- const iface = this.configuration.interfaces.find((usbInterface) => usbInterface.interfaceNumber === interfaceNumber);
1364
- if (!iface) {
1365
- throw new Error("releaseInterface error: interface not found");
1366
- }
1367
- if (!iface.claimed) {
1368
- return;
1369
- }
1370
- try {
1371
- const iface2 = this.device.interface(interfaceNumber);
1372
- await iface2.releaseAsync();
1373
- } catch (error) {
1374
- throw new Error(`releaseInterface error: ${error}`);
1375
- }
1376
- }
1377
- checkDeviceOpen() {
1378
- if (!this.opened) {
1379
- throw new Error("The device must be opened first");
1380
- }
1381
- }
1382
- };
1383
- exports2.WebUSBDevice = WebUSBDevice;
1384
- }
1385
- });
1386
-
1387
- // node_modules/usb/dist/webusb/index.js
1388
- var require_webusb = __commonJS({
1389
- "node_modules/usb/dist/webusb/index.js"(exports2) {
1390
- "use strict";
1391
- Object.defineProperty(exports2, "__esModule", { value: true });
1392
- exports2.WebUSB = exports2.getWebUsb = void 0;
1393
- var usb = require_usb();
1394
- var events_1 = require("events");
1395
- var webusb_device_1 = require_webusb_device();
1396
- var getWebUsb = () => {
1397
- if (navigator && navigator.usb) {
1398
- return navigator.usb;
1399
- }
1400
- return new WebUSB();
1401
- };
1402
- exports2.getWebUsb = getWebUsb;
1403
- var NamedError = class extends Error {
1404
- constructor(message, name) {
1405
- super(message);
1406
- this.name = name;
1407
- }
1408
- };
1409
- var WebUSB = class {
1410
- constructor(options = {}) {
1411
- this.options = options;
1412
- this.emitter = new events_1.EventEmitter();
1413
- this.knownDevices = /* @__PURE__ */ new Map();
1414
- this.authorisedDevices = /* @__PURE__ */ new Set();
1415
- const deviceConnectCallback = async (device) => {
1416
- const webDevice = await this.getWebDevice(device);
1417
- if (webDevice && this.isAuthorisedDevice(webDevice)) {
1418
- const event = {
1419
- type: "connect",
1420
- device: webDevice
1421
- };
1422
- this.emitter.emit("connect", event);
1423
- }
1424
- };
1425
- const deviceDisconnectCallback = async (device) => {
1426
- if (this.knownDevices.has(device)) {
1427
- const webDevice = this.knownDevices.get(device);
1428
- if (webDevice && this.isAuthorisedDevice(webDevice)) {
1429
- const event = {
1430
- type: "disconnect",
1431
- device: webDevice
1432
- };
1433
- this.emitter.emit("disconnect", event);
1434
- }
1435
- }
1436
- };
1437
- this.emitter.on("newListener", (event) => {
1438
- const listenerCount = this.emitter.listenerCount(event);
1439
- if (listenerCount !== 0) {
1440
- return;
1441
- }
1442
- if (event === "connect") {
1443
- usb.addListener("attach", deviceConnectCallback);
1444
- } else if (event === "disconnect") {
1445
- usb.addListener("detach", deviceDisconnectCallback);
1446
- }
1447
- });
1448
- this.emitter.on("removeListener", (event) => {
1449
- const listenerCount = this.emitter.listenerCount(event);
1450
- if (listenerCount !== 0) {
1451
- return;
1452
- }
1453
- if (event === "connect") {
1454
- usb.removeListener("attach", deviceConnectCallback);
1455
- } else if (event === "disconnect") {
1456
- usb.removeListener("detach", deviceDisconnectCallback);
1457
- }
1458
- });
1459
- }
1460
- set onconnect(fn) {
1461
- if (this._onconnect) {
1462
- this.removeEventListener("connect", this._onconnect);
1463
- this._onconnect = void 0;
1464
- }
1465
- if (fn) {
1466
- this._onconnect = fn;
1467
- this.addEventListener("connect", this._onconnect);
1468
- }
1469
- }
1470
- set ondisconnect(fn) {
1471
- if (this._ondisconnect) {
1472
- this.removeEventListener("disconnect", this._ondisconnect);
1473
- this._ondisconnect = void 0;
1474
- }
1475
- if (fn) {
1476
- this._ondisconnect = fn;
1477
- this.addEventListener("disconnect", this._ondisconnect);
1478
- }
1479
- }
1480
- addEventListener(type, listener) {
1481
- this.emitter.addListener(type, listener);
1482
- }
1483
- removeEventListener(type, callback) {
1484
- this.emitter.removeListener(type, callback);
1485
- }
1486
- dispatchEvent(_event) {
1487
- return false;
1488
- }
1489
- /**
1490
- * Requests a single Web USB device
1491
- * @param options The options to use when scanning
1492
- * @returns Promise containing the selected device
1493
- */
1494
- async requestDevice(options) {
1495
- if (!options) {
1496
- throw new TypeError("requestDevice error: 1 argument required, but only 0 present");
1497
- }
1498
- if (options.constructor !== {}.constructor) {
1499
- throw new TypeError("requestDevice error: parameter 1 (options) is not an object");
1500
- }
1501
- if (!options.filters) {
1502
- throw new TypeError("requestDevice error: required member filters is undefined");
1503
- }
1504
- if (options.filters.constructor !== [].constructor) {
1505
- throw new TypeError("requestDevice error: the provided value cannot be converted to a sequence");
1506
- }
1507
- options.filters.forEach((filter) => {
1508
- if (filter.protocolCode && !filter.subclassCode) {
1509
- throw new TypeError("requestDevice error: subclass code is required");
1510
- }
1511
- if (filter.subclassCode && !filter.classCode) {
1512
- throw new TypeError("requestDevice error: class code is required");
1513
- }
1514
- });
1515
- let devices = await this.loadDevices(options.filters);
1516
- devices = devices.filter((device) => this.filterDevice(device, options.filters));
1517
- if (devices.length === 0) {
1518
- throw new NamedError("Failed to execute 'requestDevice' on 'USB': No device selected.", "NotFoundError");
1519
- }
1520
- try {
1521
- const device = this.options.devicesFound ? await this.options.devicesFound(devices) : devices[0];
1522
- if (!device) {
1523
- throw new NamedError("Failed to execute 'requestDevice' on 'USB': No device selected.", "NotFoundError");
1524
- }
1525
- this.authorisedDevices.add({
1526
- vendorId: device.vendorId,
1527
- productId: device.productId,
1528
- classCode: device.deviceClass,
1529
- subclassCode: device.deviceSubclass,
1530
- protocolCode: device.deviceProtocol,
1531
- serialNumber: device.serialNumber || void 0
1532
- });
1533
- return device;
1534
- } catch (error) {
1535
- throw new NamedError("Failed to execute 'requestDevice' on 'USB': No device selected.", "NotFoundError");
1536
- }
1537
- }
1538
- /**
1539
- * Gets all allowed Web USB devices which are connected
1540
- * @returns Promise containing an array of devices
1541
- */
1542
- async getDevices() {
1543
- const preFilters = this.options.allowAllDevices ? void 0 : this.options.allowedDevices;
1544
- const devices = await this.loadDevices(preFilters);
1545
- return devices.filter((device) => this.isAuthorisedDevice(device));
1546
- }
1547
- async loadDevices(preFilters) {
1548
- let devices = usb.getDeviceList();
1549
- devices = this.quickFilter(devices, preFilters);
1550
- const refreshedKnownDevices = /* @__PURE__ */ new Map();
1551
- for (const device of devices) {
1552
- const webDevice = await this.getWebDevice(device);
1553
- if (webDevice) {
1554
- refreshedKnownDevices.set(device, webDevice);
1555
- }
1556
- }
1557
- this.knownDevices = refreshedKnownDevices;
1558
- return [...this.knownDevices.values()];
1559
- }
1560
- // Get a WebUSBDevice corresponding to underlying device.
1561
- // Returns undefined the device was not found and could not be created.
1562
- async getWebDevice(device) {
1563
- if (!this.knownDevices.has(device)) {
1564
- if (this.options.deviceTimeout) {
1565
- device.timeout = this.options.deviceTimeout;
1566
- }
1567
- try {
1568
- const webDevice = await webusb_device_1.WebUSBDevice.createInstance(device, this.options.autoDetachKernelDriver);
1569
- this.knownDevices.set(device, webDevice);
1570
- } catch {
1571
- }
1572
- }
1573
- return this.knownDevices.get(device);
1574
- }
1575
- // Undertake quick filter on devices before creating WebUSB devices if possible
1576
- quickFilter(devices, preFilters) {
1577
- if (!preFilters || !preFilters.length) {
1578
- return devices;
1579
- }
1580
- return devices.filter((device) => preFilters.some((filter) => {
1581
- if (filter.vendorId && filter.vendorId !== device.deviceDescriptor.idVendor)
1582
- return false;
1583
- if (filter.productId && filter.productId !== device.deviceDescriptor.idProduct)
1584
- return false;
1585
- return true;
1586
- }));
1587
- }
1588
- // Filter WebUSB devices
1589
- filterDevice(device, filters) {
1590
- if (!filters || !filters.length) {
1591
- return true;
1592
- }
1593
- return filters.some((filter) => {
1594
- if (filter.vendorId && filter.vendorId !== device.vendorId)
1595
- return false;
1596
- if (filter.productId && filter.productId !== device.productId)
1597
- return false;
1598
- if (filter.classCode) {
1599
- if (!device.configuration) {
1600
- return false;
1601
- }
1602
- const match = device.configuration.interfaces.some((iface) => {
1603
- if (filter.classCode && filter.classCode !== iface.alternate.interfaceClass)
1604
- return false;
1605
- if (filter.subclassCode && filter.subclassCode !== iface.alternate.interfaceSubclass)
1606
- return false;
1607
- if (filter.protocolCode && filter.protocolCode !== iface.alternate.interfaceProtocol)
1608
- return false;
1609
- return true;
1610
- });
1611
- if (match) {
1612
- return true;
1613
- }
1614
- }
1615
- if (filter.classCode && filter.classCode !== device.deviceClass)
1616
- return false;
1617
- if (filter.subclassCode && filter.subclassCode !== device.deviceSubclass)
1618
- return false;
1619
- if (filter.protocolCode && filter.protocolCode !== device.deviceProtocol)
1620
- return false;
1621
- if (filter.serialNumber && filter.serialNumber !== device.serialNumber)
1622
- return false;
1623
- return true;
1624
- });
1625
- }
1626
- // Check whether a device is authorised
1627
- isAuthorisedDevice(device) {
1628
- if (this.options.allowAllDevices) {
1629
- return true;
1630
- }
1631
- if (this.options.allowedDevices && this.filterDevice(device, this.options.allowedDevices)) {
1632
- return true;
1633
- }
1634
- return [...this.authorisedDevices.values()].some((authorised) => authorised.vendorId === device.vendorId && authorised.productId === device.productId && authorised.classCode === device.deviceClass && authorised.subclassCode === device.deviceSubclass && authorised.protocolCode === device.deviceProtocol && authorised.serialNumber === device.serialNumber);
1635
- }
1636
- };
1637
- exports2.WebUSB = WebUSB;
1638
- }
1639
- });
1640
-
1641
- // node_modules/usb/dist/usb/descriptors.js
1642
- var require_descriptors = __commonJS({
1643
- "node_modules/usb/dist/usb/descriptors.js"(exports2) {
1644
- "use strict";
1645
- Object.defineProperty(exports2, "__esModule", { value: true });
1646
- }
1647
- });
1648
-
1649
- // node_modules/usb/dist/index.js
1650
- var require_dist = __commonJS({
1651
- "node_modules/usb/dist/index.js"(exports2) {
1652
- "use strict";
1653
- var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
1654
- if (k2 === void 0) k2 = k;
1655
- var desc = Object.getOwnPropertyDescriptor(m, k);
1656
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1657
- desc = { enumerable: true, get: function() {
1658
- return m[k];
1659
- } };
1660
- }
1661
- Object.defineProperty(o, k2, desc);
1662
- } : function(o, m, k, k2) {
1663
- if (k2 === void 0) k2 = k;
1664
- o[k2] = m[k];
1665
- });
1666
- var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
1667
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p)) __createBinding(exports3, m, p);
1668
- };
1669
- Object.defineProperty(exports2, "__esModule", { value: true });
1670
- exports2.LibUSBException = exports2.useUsbDkBackend = exports2.getDeviceList = exports2.Transfer = exports2.Device = exports2.webusb = exports2.findBySerialNumber = exports2.findByIds = exports2.usb = void 0;
1671
- var util_1 = require("util");
1672
- var webusb_1 = require_webusb();
1673
- var usb = require_usb();
1674
- exports2.usb = usb;
1675
- var findByIds = (vid, pid) => {
1676
- const devices = usb.getDeviceList();
1677
- return devices.find((item) => item.deviceDescriptor.idVendor === vid && item.deviceDescriptor.idProduct === pid);
1678
- };
1679
- exports2.findByIds = findByIds;
1680
- var findBySerialNumber = async (serialNumber) => {
1681
- const devices = usb.getDeviceList();
1682
- const opened = (device) => !!device.interfaces;
1683
- for (const device of devices) {
1684
- try {
1685
- if (!opened(device)) {
1686
- device.open();
1687
- }
1688
- const getStringDescriptor = (0, util_1.promisify)(device.getStringDescriptor).bind(device);
1689
- const buffer = await getStringDescriptor(device.deviceDescriptor.iSerialNumber);
1690
- if (buffer && buffer.toString() === serialNumber) {
1691
- return device;
1692
- }
1693
- } catch {
1694
- } finally {
1695
- try {
1696
- if (opened(device)) {
1697
- device.close();
1698
- }
1699
- } catch {
1700
- }
1701
- }
1702
- }
1703
- return void 0;
1704
- };
1705
- exports2.findBySerialNumber = findBySerialNumber;
1706
- var webusb = new webusb_1.WebUSB();
1707
- exports2.webusb = webusb;
1708
- var usb_1 = require_usb();
1709
- Object.defineProperty(exports2, "Device", { enumerable: true, get: function() {
1710
- return usb_1.Device;
1711
- } });
1712
- Object.defineProperty(exports2, "Transfer", { enumerable: true, get: function() {
1713
- return usb_1.Transfer;
1714
- } });
1715
- Object.defineProperty(exports2, "getDeviceList", { enumerable: true, get: function() {
1716
- return usb_1.getDeviceList;
1717
- } });
1718
- Object.defineProperty(exports2, "useUsbDkBackend", { enumerable: true, get: function() {
1719
- return usb_1.useUsbDkBackend;
1720
- } });
1721
- Object.defineProperty(exports2, "LibUSBException", { enumerable: true, get: function() {
1722
- return usb_1.LibUSBException;
1723
- } });
1724
- __exportStar(require_capability(), exports2);
1725
- __exportStar(require_descriptors(), exports2);
1726
- __exportStar(require_endpoint(), exports2);
1727
- __exportStar(require_interface(), exports2);
1728
- __exportStar(require_webusb(), exports2);
1729
- __exportStar(require_webusb_device(), exports2);
1730
- }
1731
- });
1732
-
1733
33
  // src/png-decode.ts
1734
34
  var png_decode_exports = {};
1735
35
  __export(png_decode_exports, {
@@ -2053,10 +353,10 @@ var UsbTransportDevice = class extends import_events.EventEmitter {
2053
353
  this.iface = null;
2054
354
  }
2055
355
  };
2056
- function listUsbDevices(log) {
356
+ async function listUsbDevices(log) {
2057
357
  let usb;
2058
358
  try {
2059
- usb = require_dist();
359
+ usb = require("usb");
2060
360
  } catch {
2061
361
  log.debug?.("usb package not available, skipping raw USB discovery");
2062
362
  return [];
@@ -2067,10 +367,34 @@ function listUsbDevices(log) {
2067
367
  for (const device of deviceList) {
2068
368
  const desc = device.deviceDescriptor;
2069
369
  if (desc.idVendor === SIGNOTEC_VID && desc.idProduct === SIGNOTEC_PID) {
370
+ let serialNumber = "";
371
+ let product = "Signotec Pad";
372
+ if (desc.iSerialNumber || desc.iProduct) {
373
+ try {
374
+ device.open();
375
+ if (desc.iSerialNumber) {
376
+ serialNumber = await new Promise((resolve) => {
377
+ device.getStringDescriptor(desc.iSerialNumber, (err, val) => {
378
+ resolve(err ? "" : (val || "").trim());
379
+ });
380
+ });
381
+ }
382
+ if (desc.iProduct) {
383
+ product = await new Promise((resolve) => {
384
+ device.getStringDescriptor(desc.iProduct, (err, val) => {
385
+ resolve(err ? "Signotec Pad" : (val || "Signotec Pad").trim());
386
+ });
387
+ });
388
+ }
389
+ device.close();
390
+ } catch (err) {
391
+ log.debug?.("Could not read USB string descriptors:", err.message);
392
+ }
393
+ }
2070
394
  results.push({
2071
395
  path: `usb:${desc.idVendor}:${desc.idProduct}:${device.busNumber}:${device.deviceAddress}`,
2072
- serialNumber: "",
2073
- product: "Signotec Pad",
396
+ serialNumber,
397
+ product,
2074
398
  _usbDevice: device
2075
399
  });
2076
400
  }
@@ -2188,7 +512,7 @@ var HidProtocol = class {
2188
512
  * HID devices are found (e.g., Windows without HID class driver).
2189
513
  * @returns Array of device descriptors (never throws).
2190
514
  */
2191
- listDevices() {
515
+ async listDevices() {
2192
516
  this.usbDeviceMap.clear();
2193
517
  try {
2194
518
  const hidDevices = this.HID.devices().filter((d) => d.vendorId === SIGNOTEC_VID2 && d.productId === SIGNOTEC_PID2).map((d) => ({
@@ -2205,7 +529,7 @@ var HidProtocol = class {
2205
529
  }
2206
530
  this.log.info("No Signotec pads found via HID, trying raw USB...");
2207
531
  try {
2208
- const usbDevices = listUsbDevices(this.log);
532
+ const usbDevices = await listUsbDevices(this.log);
2209
533
  if (usbDevices.length > 0) {
2210
534
  this.log.info(`Found ${usbDevices.length} Signotec pad(s) via raw USB`);
2211
535
  for (const d of usbDevices) {
@@ -3486,7 +1810,7 @@ function createHidDriver(config) {
3486
1810
  const maxAttempts = config?.reconnectAttempts ?? 10;
3487
1811
  const interval = config?.reconnectIntervalMs ?? 2e3;
3488
1812
  let attempts = 0;
3489
- const tryReconnect = () => {
1813
+ const tryReconnect = async () => {
3490
1814
  attempts++;
3491
1815
  if (attempts > maxAttempts) {
3492
1816
  log.error(`Signotec pad reconnection failed after ${maxAttempts} attempts`);
@@ -3497,7 +1821,7 @@ function createHidDriver(config) {
3497
1821
  log.info(`Signotec reconnect attempt ${attempts}/${maxAttempts}...`);
3498
1822
  try {
3499
1823
  const prot = new HidProtocol(config);
3500
- const devices = prot.listDevices();
1824
+ const devices = await prot.listDevices();
3501
1825
  if (devices.length > 0) {
3502
1826
  log.info("Signotec pad reconnected - cancelling session (state lost)");
3503
1827
  currentHandlers?.onUserEvent("cancel", { serialNo: currentSerialNo || "unknown" });
@@ -3561,7 +1885,7 @@ function createHidDriver(config) {
3561
1885
  await cleanup();
3562
1886
  }
3563
1887
  protocol = new HidProtocol(config);
3564
- const devices = protocol.listDevices();
1888
+ const devices = await protocol.listDevices();
3565
1889
  if (devices.length === 0) {
3566
1890
  protocol = null;
3567
1891
  throw new Error(`No device with serialNo.: ${serialNo} was found.`);
@@ -3620,14 +1944,44 @@ function createHidDriver(config) {
3620
1944
  }
3621
1945
  emit("info", "Signing session started", "session", { serialNo: currentSerialNo });
3622
1946
  }
1947
+ function emergencyClose() {
1948
+ const prot = protocol;
1949
+ if (!prot) return;
1950
+ protocol = null;
1951
+ try {
1952
+ prot.close();
1953
+ } catch {
1954
+ }
1955
+ }
1956
+ let exitHandlersInstalled = false;
1957
+ function installExitHandlers() {
1958
+ if (exitHandlersInstalled) return;
1959
+ exitHandlersInstalled = true;
1960
+ process.on("exit", emergencyClose);
1961
+ const gracefulExit = async (signal) => {
1962
+ log.info(`Received ${signal}, closing Signotec device...`);
1963
+ try {
1964
+ await cleanup();
1965
+ } catch {
1966
+ }
1967
+ process.removeListener(signal, gracefulExit);
1968
+ process.kill(process.pid, signal);
1969
+ };
1970
+ process.on("SIGINT", gracefulExit);
1971
+ process.on("SIGTERM", gracefulExit);
1972
+ if (process.platform === "win32") {
1973
+ process.on("SIGBREAK", gracefulExit);
1974
+ }
1975
+ }
1976
+ installExitHandlers();
3623
1977
  const driver = {
3624
- getSignotecPads() {
1978
+ async getSignotecPads() {
3625
1979
  if (cachedDeviceList && Date.now() - cacheTimestamp < CACHE_TTL) {
3626
1980
  return cachedDeviceList;
3627
1981
  }
3628
1982
  try {
3629
1983
  const prot = new HidProtocol(config);
3630
- const devices = prot.listDevices();
1984
+ const devices = await prot.listDevices();
3631
1985
  cachedDeviceList = devices.map((d, i) => ({
3632
1986
  serialNo: d.serialNumber || `signotec-${i}`,
3633
1987
  type: 1,
@@ -3726,7 +2080,7 @@ function createHidDriver(config) {
3726
2080
  }
3727
2081
  try {
3728
2082
  const prot = new HidProtocol(config);
3729
- const devices = prot.listDevices();
2083
+ const devices = await prot.listDevices();
3730
2084
  if (devices.length === 0) {
3731
2085
  log.error("No Signotec device connected for standby image upload");
3732
2086
  return false;
@@ -3761,7 +2115,7 @@ function createHidDriver(config) {
3761
2115
  const start = Date.now();
3762
2116
  const interval = 1e3;
3763
2117
  while (Date.now() - start < timeoutMs) {
3764
- const pads = driver.getSignotecPads();
2118
+ const pads = await driver.getSignotecPads();
3765
2119
  if (pads.length > 0) return pads[0];
3766
2120
  await new Promise((r) => setTimeout(r, interval));
3767
2121
  }