smartcard 3.7.1 → 3.8.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/README.md +42 -1
- package/binding.gyp +46 -3
- package/dist/lib/card-wrapper.d.ts.map +1 -1
- package/dist/lib/card-wrapper.js +37 -1
- package/dist/lib/card-wrapper.js.map +1 -1
- package/dist/lib/devices.d.ts +12 -5
- package/dist/lib/devices.d.ts.map +1 -1
- package/dist/lib/devices.js +142 -41
- package/dist/lib/devices.js.map +1 -1
- package/dist/lib/errors.d.ts +24 -2
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +66 -7
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +25 -11
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/t0-handler.d.ts.map +1 -1
- package/dist/lib/t0-handler.js +60 -12
- package/dist/lib/t0-handler.js.map +1 -1
- package/dist/lib/types.d.ts +7 -3
- package/dist/lib/types.d.ts.map +1 -1
- package/package.json +14 -2
- package/src/addon.cpp +20 -0
- package/src/async_workers.cpp +23 -10
- package/src/async_workers.h +24 -1
- package/src/pcsc_card.cpp +24 -19
- package/src/pcsc_card.h +11 -3
- package/src/pcsc_context.cpp +35 -36
- package/src/pcsc_context.h +6 -5
- package/src/pcsc_context_handle.h +39 -0
- package/src/pcsc_errors.h +35 -0
- package/src/pcsc_napi_error.h +43 -0
- package/src/pcsc_reader.cpp +12 -4
- package/src/pcsc_reader.h +7 -3
- package/src/reader_monitor.cpp +254 -170
- package/src/reader_monitor.h +13 -3
- package/src/reader_state_utils.h +24 -0
package/README.md
CHANGED
|
@@ -297,6 +297,22 @@ interface Card {
|
|
|
297
297
|
}
|
|
298
298
|
```
|
|
299
299
|
|
|
300
|
+
Reset a card in place with `reconnect` — no physical removal needed:
|
|
301
|
+
|
|
302
|
+
```javascript
|
|
303
|
+
const { SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, SCARD_PROTOCOL_T1, SCARD_RESET_CARD, SCARD_UNPOWER_CARD } = require('smartcard');
|
|
304
|
+
|
|
305
|
+
// Warm reset
|
|
306
|
+
await card.reconnect(SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, SCARD_RESET_CARD);
|
|
307
|
+
|
|
308
|
+
// Cold reset (power off, then power back on)
|
|
309
|
+
await card.reconnect(SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, SCARD_UNPOWER_CARD);
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
Some reader and card combinations (an SCR35xx with a T=0-only card, for one) report the card unresponsive when a reset offers T=1 as well as T=0. When that happens, cards from `Devices` (or `wrapCard()`) retry the reconnect once with the protocol the card is already using, if you offered it. `Devices` works around the same quirk when it first connects.
|
|
313
|
+
|
|
314
|
+
`disconnect(disposition)` accepts the same constants to reset or unpower the card on the way out.
|
|
315
|
+
|
|
300
316
|
### Devices
|
|
301
317
|
|
|
302
318
|
High-level event-driven API.
|
|
@@ -440,6 +456,8 @@ try {
|
|
|
440
456
|
}
|
|
441
457
|
```
|
|
442
458
|
|
|
459
|
+
PC/SC failures from the low-level `Context`, `Reader` and `Card` and from `Devices` `'error'` events are all `PCSCError`s, or one of the subclasses above (also `NoReadersError`, `ServiceNotRunningError` and `SharingViolationError`), with the PC/SC code in `err.code`. Once a `Context` is closed, its readers and cards throw a `PCSCError` with code `0x80100003` (`SCARD_E_INVALID_HANDLE`).
|
|
460
|
+
|
|
443
461
|
## Troubleshooting
|
|
444
462
|
|
|
445
463
|
### "No readers available"
|
|
@@ -457,6 +475,30 @@ try {
|
|
|
457
475
|
### Build errors on Linux
|
|
458
476
|
- Install development headers: `sudo apt-get install libpcsclite-dev`
|
|
459
477
|
|
|
478
|
+
### "Could not resolve: ../../build/Release/smartcard_napi.node"
|
|
479
|
+
The native addon is compiled by `node-gyp` during `npm install`. If the file is missing:
|
|
480
|
+
- **Bun**: install scripts are skipped for untrusted packages — add `"trustedDependencies": ["smartcard"]` to your package.json and reinstall
|
|
481
|
+
- **Bundlers** (esbuild, webpack, electrobun): native addons can't be bundled — mark `smartcard` as external so the require happens at runtime
|
|
482
|
+
- Rebuild manually: `npm rebuild smartcard`
|
|
483
|
+
|
|
484
|
+
### Docker & containers
|
|
485
|
+
The library talks to the PC/SC daemon. Either mount the host daemon's socket:
|
|
486
|
+
|
|
487
|
+
```dockerfile
|
|
488
|
+
# In the image (libpcsclite-dev is needed at npm install time to build the addon)
|
|
489
|
+
RUN apt-get install -y libpcsclite1
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
```bash
|
|
493
|
+
docker run -v /var/run/pcscd:/var/run/pcscd myapp
|
|
494
|
+
```
|
|
495
|
+
|
|
496
|
+
Or run `pcscd` inside the container with USB passthrough:
|
|
497
|
+
|
|
498
|
+
```bash
|
|
499
|
+
docker run --privileged -v /dev/bus/usb:/dev/bus/usb myapp
|
|
500
|
+
```
|
|
501
|
+
|
|
460
502
|
## Migrating from v1.x
|
|
461
503
|
|
|
462
504
|
Version 2.0 is a complete rewrite using N-API for stability across Node.js versions.
|
|
@@ -516,5 +558,4 @@ MIT
|
|
|
516
558
|
|
|
517
559
|
## Related Projects
|
|
518
560
|
|
|
519
|
-
- [nfc-pcsc](https://www.npmjs.com/package/nfc-pcsc) - NFC library built on smartcard
|
|
520
561
|
- [emv](https://github.com/tomkp/emv) - Interactive EMV chip card explorer built on smartcard. Features a terminal UI for discovering payment applications, reading card data, verifying PINs, and exploring EMV tag structures. Supports GET PROCESSING OPTIONS, application cryptogram generation (ARQC/TC), and Dynamic Data Authentication (DDA).
|
package/binding.gyp
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
+
"variables": {
|
|
3
|
+
"smartcard_build_tests%": "false"
|
|
4
|
+
},
|
|
2
5
|
"targets": [{
|
|
3
6
|
"target_name": "smartcard_napi",
|
|
4
7
|
"cflags!": ["-fno-exceptions"],
|
|
@@ -23,7 +26,8 @@
|
|
|
23
26
|
"libraries": ["-lwinscard"],
|
|
24
27
|
"msvs_settings": {
|
|
25
28
|
"VCCLCompilerTool": {
|
|
26
|
-
"ExceptionHandling": 1
|
|
29
|
+
"ExceptionHandling": 1,
|
|
30
|
+
"AdditionalOptions": ["/std:c++17"]
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
33
|
}],
|
|
@@ -32,14 +36,53 @@
|
|
|
32
36
|
"xcode_settings": {
|
|
33
37
|
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
|
|
34
38
|
"CLANG_CXX_LIBRARY": "libc++",
|
|
39
|
+
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
|
|
35
40
|
"MACOSX_DEPLOYMENT_TARGET": "10.15"
|
|
36
41
|
}
|
|
37
42
|
}],
|
|
38
43
|
["OS=='linux'", {
|
|
39
44
|
"libraries": ["-lpcsclite"],
|
|
40
45
|
"include_dirs": ["/usr/include/PCSC"],
|
|
41
|
-
"cflags_cc": ["-fexceptions"]
|
|
46
|
+
"cflags_cc": ["-std=c++17", "-fexceptions"]
|
|
42
47
|
}]
|
|
43
48
|
]
|
|
44
|
-
}]
|
|
49
|
+
}],
|
|
50
|
+
"conditions": [
|
|
51
|
+
["smartcard_build_tests=='true'", {
|
|
52
|
+
"targets": [{
|
|
53
|
+
"target_name": "smartcard_tests",
|
|
54
|
+
"type": "executable",
|
|
55
|
+
"sources": [
|
|
56
|
+
"src/test/test_main.cpp",
|
|
57
|
+
"src/test/reader_state_utils_test.cpp"
|
|
58
|
+
],
|
|
59
|
+
"include_dirs": [
|
|
60
|
+
"src"
|
|
61
|
+
],
|
|
62
|
+
"cflags!": ["-fno-exceptions"],
|
|
63
|
+
"cflags_cc!": ["-fno-exceptions"],
|
|
64
|
+
"conditions": [
|
|
65
|
+
["OS=='win'", {
|
|
66
|
+
"msvs_settings": {
|
|
67
|
+
"VCCLCompilerTool": {
|
|
68
|
+
"ExceptionHandling": 1,
|
|
69
|
+
"AdditionalOptions": ["/std:c++17"]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}],
|
|
73
|
+
["OS=='mac'", {
|
|
74
|
+
"xcode_settings": {
|
|
75
|
+
"GCC_ENABLE_CPP_EXCEPTIONS": "YES",
|
|
76
|
+
"CLANG_CXX_LIBRARY": "libc++",
|
|
77
|
+
"CLANG_CXX_LANGUAGE_STANDARD": "c++17",
|
|
78
|
+
"MACOSX_DEPLOYMENT_TARGET": "10.15"
|
|
79
|
+
}
|
|
80
|
+
}],
|
|
81
|
+
["OS=='linux'", {
|
|
82
|
+
"cflags_cc": ["-std=c++17", "-fexceptions"]
|
|
83
|
+
}]
|
|
84
|
+
]
|
|
85
|
+
}]
|
|
86
|
+
}]
|
|
87
|
+
]
|
|
45
88
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"card-wrapper.d.ts","sourceRoot":"","sources":["../../lib/card-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"card-wrapper.d.ts","sourceRoot":"","sources":["../../lib/card-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAWjE;;GAEG;AACH,qBAAa,WAAY,YAAW,IAAI;IACpC,OAAO,CAAC,WAAW,CAAO;gBAEd,UAAU,EAAE,IAAI;IAI5B,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,IAAI,GAAG,IAAI,MAAM,GAAG,IAAI,CAEvB;IAEK,QAAQ,CACV,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,EAC1B,OAAO,CAAC,EAAE,eAAe,GAC1B,OAAO,CAAC,MAAM,CAAC;IASlB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAIhE,SAAS,IAAI,UAAU;IAIvB,UAAU,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI;IAIhC,SAAS,CACX,SAAS,CAAC,EAAE,MAAM,EAClB,QAAQ,CAAC,EAAE,MAAM,EACjB,cAAc,CAAC,EAAE,MAAM,GACxB,OAAO,CAAC,MAAM,CAAC;CAwCrB;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,UAAU,EAAE,IAAI,GAAG,IAAI,CAE/C"}
|
package/dist/lib/card-wrapper.js
CHANGED
|
@@ -9,6 +9,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.CardWrapper = void 0;
|
|
10
10
|
exports.wrapCard = wrapCard;
|
|
11
11
|
const t0_handler_1 = require("./t0-handler");
|
|
12
|
+
const errors_1 = require("./errors");
|
|
13
|
+
/**
|
|
14
|
+
* What the native layer offers when reconnect() is given no protocol.
|
|
15
|
+
* T=0 and T=1 are 1 and 2 in pcsc-lite, macOS and WinSCard alike (only RAW
|
|
16
|
+
* differs between them).
|
|
17
|
+
*/
|
|
18
|
+
const DEFAULT_PROTOCOLS = 0x1 | 0x2;
|
|
12
19
|
/**
|
|
13
20
|
* Wraps a native Card to add autoGetResponse support to transmit()
|
|
14
21
|
*/
|
|
@@ -44,7 +51,36 @@ class CardWrapper {
|
|
|
44
51
|
return this._nativeCard.disconnect(disposition);
|
|
45
52
|
}
|
|
46
53
|
async reconnect(shareMode, protocol, initialization) {
|
|
47
|
-
|
|
54
|
+
const active = this._nativeCard.protocol;
|
|
55
|
+
try {
|
|
56
|
+
return await this._nativeCard.reconnect(shareMode, protocol, initialization);
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
// Some reader and card combinations (issue #34: an SCR35xx with a
|
|
60
|
+
// T=0-only card) report the card unresponsive when a reset offers
|
|
61
|
+
// T=1 as well. Retry once with the protocol the card is already
|
|
62
|
+
// using, but only if the caller offered it. The failed attempt has
|
|
63
|
+
// usually reset the card already, so this resets it a second time.
|
|
64
|
+
const requested = protocol ?? DEFAULT_PROTOCOLS;
|
|
65
|
+
const offered = (requested & active) === active;
|
|
66
|
+
if (!active ||
|
|
67
|
+
!offered ||
|
|
68
|
+
requested === active ||
|
|
69
|
+
!(0, errors_1.isUnresponsiveCardError)(err)) {
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
return await this._nativeCard.reconnect(shareMode, active, initialization);
|
|
74
|
+
}
|
|
75
|
+
catch (retryErr) {
|
|
76
|
+
// Report the failure of the call that was made; keep the
|
|
77
|
+
// fallback's failure as its cause
|
|
78
|
+
if (err instanceof Error && err.cause === undefined) {
|
|
79
|
+
err.cause = retryErr;
|
|
80
|
+
}
|
|
81
|
+
throw err;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
48
84
|
}
|
|
49
85
|
}
|
|
50
86
|
exports.CardWrapper = CardWrapper;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"card-wrapper.js","sourceRoot":"","sources":["../../lib/card-wrapper.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;
|
|
1
|
+
{"version":3,"file":"card-wrapper.js","sourceRoot":"","sources":["../../lib/card-wrapper.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AA4GH,4BAEC;AA3GD,6CAAwD;AACxD,qCAAmD;AAEnD;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,GAAG,GAAG,GAAG,CAAC;AAEpC;;GAEG;AACH,MAAa,WAAW;IACZ,WAAW,CAAO;IAE1B,YAAY,UAAgB;QACxB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;IAClC,CAAC;IAED,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;IAC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C,KAAK,MAAM,CAAC;YAChD,IACI,CAAC,MAAM;gBACP,CAAC,OAAO;gBACR,SAAS,KAAK,MAAM;gBACpB,CAAC,IAAA,gCAAuB,EAAC,GAAY,CAAC,EACxC,CAAC;gBACC,MAAM,GAAG,CAAC;YACd,CAAC;YACD,IAAI,CAAC;gBACD,OAAO,MAAM,IAAI,CAAC,WAAW,CAAC,SAAS,CACnC,SAAS,EACT,MAAM,EACN,cAAc,CACjB,CAAC;YACN,CAAC;YAAC,OAAO,QAAQ,EAAE,CAAC;gBAChB,yDAAyD;gBACzD,kCAAkC;gBAClC,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;oBAClD,GAAG,CAAC,KAAK,GAAG,QAAQ,CAAC;gBACzB,CAAC;gBACD,MAAM,GAAG,CAAC;YACd,CAAC;QACL,CAAC;IACL,CAAC;CACJ;AAvFD,kCAuFC;AAED;;GAEG;AACH,SAAgB,QAAQ,CAAC,UAAgB;IACrC,OAAO,IAAI,WAAW,CAAC,UAAU,CAAC,CAAC;AACvC,CAAC"}
|
package/dist/lib/devices.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import type { Card, DeviceEvents, DevicesOptions, Reader } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Check if an error indicates an unresponsive card (SCARD_W_UNRESPONSIVE_CARD).
|
|
5
|
-
* Used to determine if we should fallback to T=0 protocol.
|
|
6
|
-
*/
|
|
7
|
-
export declare function isUnresponsiveCardError(err: Error): boolean;
|
|
8
3
|
/**
|
|
9
4
|
* High-level event-driven API for PC/SC devices
|
|
10
5
|
*
|
|
@@ -24,6 +19,7 @@ export declare class Devices extends EventEmitter {
|
|
|
24
19
|
private _running;
|
|
25
20
|
private _readers;
|
|
26
21
|
private _eventQueue;
|
|
22
|
+
private _generation;
|
|
27
23
|
private _Context;
|
|
28
24
|
private _ReaderMonitor;
|
|
29
25
|
private _SCARD_STATE_PRESENT;
|
|
@@ -63,10 +59,21 @@ export declare class Devices extends EventEmitter {
|
|
|
63
59
|
* Queues events to prevent race conditions when multiple events arrive concurrently
|
|
64
60
|
*/
|
|
65
61
|
private _handleEvent;
|
|
62
|
+
/**
|
|
63
|
+
* Emit an error without killing the event pump: with no 'error' listener
|
|
64
|
+
* EventEmitter throws, which would reject the event queue and stop all
|
|
65
|
+
* future event processing.
|
|
66
|
+
*/
|
|
67
|
+
private _safeEmitError;
|
|
66
68
|
/**
|
|
67
69
|
* Process a single event (called sequentially via queue)
|
|
68
70
|
*/
|
|
69
71
|
private _processEvent;
|
|
72
|
+
/**
|
|
73
|
+
* Replace the PC/SC context after the native monitor recovered from a
|
|
74
|
+
* service restart (the old handle is dead).
|
|
75
|
+
*/
|
|
76
|
+
private _recreateContext;
|
|
70
77
|
/**
|
|
71
78
|
* Handle reader attached
|
|
72
79
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devices.d.ts","sourceRoot":"","sources":["../../lib/devices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EACR,IAAI,EAGJ,YAAY,EACZ,cAAc,EAGd,MAAM,EAGT,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"devices.d.ts","sourceRoot":"","sources":["../../lib/devices.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EACR,IAAI,EAGJ,YAAY,EACZ,cAAc,EAGd,MAAM,EAGT,MAAM,SAAS,CAAC;AAejB;;;;;;;;;;;;GAYG;AACH,qBAAa,OAAQ,SAAQ,YAAY;IACrC,OAAO,CAAC,QAAQ,CAA8B;IAC9C,OAAO,CAAC,QAAQ,CAAwB;IACxC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAA0C;IAC1D,OAAO,C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AAS,MAAM,YAAY,EACpC,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GAC1B,IAAI;IAIP,cAAc,CAAC,CAAC,SAAS,MAAM,YAAY,EACvC,KAAK,EAAE,CAAC,EACR,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GAC1B,IAAI;IAIP,IAAI,CAAC,CAAC,SAAS,MAAM,YAAY,EAC7B,KAAK,EAAE,CAAC,EACR,GAAG,IAAI,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GACrC,OAAO;CAGb"}
|
package/dist/lib/devices.js
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Devices = void 0;
|
|
4
|
-
exports.isUnresponsiveCardError = isUnresponsiveCardError;
|
|
5
4
|
const events_1 = require("events");
|
|
6
5
|
const card_wrapper_1 = require("./card-wrapper");
|
|
6
|
+
const errors_1 = require("./errors");
|
|
7
7
|
const addon = require('../../build/Release/smartcard_napi.node');
|
|
8
|
-
/**
|
|
9
|
-
* Check if an error indicates an unresponsive card (SCARD_W_UNRESPONSIVE_CARD).
|
|
10
|
-
* Used to determine if we should fallback to T=0 protocol.
|
|
11
|
-
*/
|
|
12
|
-
function isUnresponsiveCardError(err) {
|
|
13
|
-
if (!err || typeof err.message !== 'string') {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
return err.message.toLowerCase().includes('unresponsive');
|
|
17
|
-
}
|
|
18
8
|
/**
|
|
19
9
|
* High-level event-driven API for PC/SC devices
|
|
20
10
|
*
|
|
@@ -34,6 +24,7 @@ class Devices extends events_1.EventEmitter {
|
|
|
34
24
|
_running = false;
|
|
35
25
|
_readers = new Map();
|
|
36
26
|
_eventQueue = Promise.resolve();
|
|
27
|
+
_generation = 0;
|
|
37
28
|
// Dependencies (can be injected for testing)
|
|
38
29
|
_Context;
|
|
39
30
|
_ReaderMonitor;
|
|
@@ -68,16 +59,48 @@ class Devices extends events_1.EventEmitter {
|
|
|
68
59
|
try {
|
|
69
60
|
// Create context for card connections
|
|
70
61
|
this._context = new this._Context();
|
|
62
|
+
// A rejected queue from a previous session must not block this one
|
|
63
|
+
this._eventQueue = Promise.resolve();
|
|
71
64
|
// Create native monitor
|
|
72
65
|
this._monitor = new this._ReaderMonitor();
|
|
73
|
-
this._running = true;
|
|
74
66
|
// Start native monitoring with callback
|
|
75
67
|
this._monitor.start((event) => {
|
|
76
68
|
this._handleEvent(event);
|
|
77
69
|
});
|
|
70
|
+
// Set only after everything succeeded, so a partial failure
|
|
71
|
+
// leaves start() retryable. Events queue as microtasks, so none
|
|
72
|
+
// is processed before this line runs.
|
|
73
|
+
this._running = true;
|
|
78
74
|
}
|
|
79
75
|
catch (err) {
|
|
80
|
-
|
|
76
|
+
// Roll back whatever was created so a later start() can succeed
|
|
77
|
+
if (this._monitor) {
|
|
78
|
+
try {
|
|
79
|
+
this._monitor.stop();
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
// Monitor never started
|
|
83
|
+
}
|
|
84
|
+
this._monitor = null;
|
|
85
|
+
}
|
|
86
|
+
if (this._context) {
|
|
87
|
+
try {
|
|
88
|
+
this._context.close();
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
// Ignore close errors
|
|
92
|
+
}
|
|
93
|
+
this._context = null;
|
|
94
|
+
}
|
|
95
|
+
const error = (0, errors_1.toPCSCError)(err);
|
|
96
|
+
if (this.listenerCount('error') > 0) {
|
|
97
|
+
this.emit('error', error);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
// No listener: fail loudly to the caller instead of
|
|
101
|
+
// silently doing nothing - but only after the rollback above
|
|
102
|
+
throw error;
|
|
103
|
+
}
|
|
81
104
|
}
|
|
82
105
|
}
|
|
83
106
|
/**
|
|
@@ -85,6 +108,9 @@ class Devices extends events_1.EventEmitter {
|
|
|
85
108
|
*/
|
|
86
109
|
stop() {
|
|
87
110
|
this._running = false;
|
|
111
|
+
// Invalidate in-flight handlers parked on an await: a handler that
|
|
112
|
+
// resumes after this stop (or a later restart) must not touch state
|
|
113
|
+
this._generation++;
|
|
88
114
|
if (this._monitor) {
|
|
89
115
|
try {
|
|
90
116
|
this._monitor.stop();
|
|
@@ -157,8 +183,22 @@ class Devices extends events_1.EventEmitter {
|
|
|
157
183
|
* Queues events to prevent race conditions when multiple events arrive concurrently
|
|
158
184
|
*/
|
|
159
185
|
_handleEvent(event) {
|
|
160
|
-
// Chain this event onto the queue to serialize processing
|
|
161
|
-
|
|
186
|
+
// Chain this event onto the queue to serialize processing. The catch
|
|
187
|
+
// keeps the chain alive: a rejected link would otherwise silently
|
|
188
|
+
// stop all future event processing.
|
|
189
|
+
this._eventQueue = this._eventQueue
|
|
190
|
+
.then(() => this._processEvent(event))
|
|
191
|
+
.catch((err) => this._safeEmitError(err));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Emit an error without killing the event pump: with no 'error' listener
|
|
195
|
+
* EventEmitter throws, which would reject the event queue and stop all
|
|
196
|
+
* future event processing.
|
|
197
|
+
*/
|
|
198
|
+
_safeEmitError(err) {
|
|
199
|
+
if (this.listenerCount('error') > 0) {
|
|
200
|
+
this.emit('error', (0, errors_1.toPCSCError)(err));
|
|
201
|
+
}
|
|
162
202
|
}
|
|
163
203
|
/**
|
|
164
204
|
* Process a single event (called sequentially via queue)
|
|
@@ -167,7 +207,7 @@ class Devices extends events_1.EventEmitter {
|
|
|
167
207
|
if (!this._running) {
|
|
168
208
|
return;
|
|
169
209
|
}
|
|
170
|
-
const { type, reader: readerName, state, atr } = event;
|
|
210
|
+
const { type, reader: readerName, state, atr, code } = event;
|
|
171
211
|
switch (type) {
|
|
172
212
|
case 'reader-attached':
|
|
173
213
|
await this._handleReaderAttached(readerName, state, atr);
|
|
@@ -181,12 +221,40 @@ class Devices extends events_1.EventEmitter {
|
|
|
181
221
|
case 'card-removed':
|
|
182
222
|
this._handleCardRemoved(readerName);
|
|
183
223
|
break;
|
|
224
|
+
case 'monitor-recovered':
|
|
225
|
+
// The native monitor re-established its PC/SC context after a
|
|
226
|
+
// service restart; ours died with the same restart - replace it.
|
|
227
|
+
this._recreateContext();
|
|
228
|
+
break;
|
|
184
229
|
case 'error':
|
|
185
230
|
// readerName contains error message for error events
|
|
186
|
-
this.
|
|
231
|
+
this._safeEmitError(code !== undefined
|
|
232
|
+
? (0, errors_1.createPCSCError)(readerName, code)
|
|
233
|
+
: new Error(readerName));
|
|
187
234
|
break;
|
|
188
235
|
}
|
|
189
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Replace the PC/SC context after the native monitor recovered from a
|
|
239
|
+
* service restart (the old handle is dead).
|
|
240
|
+
*/
|
|
241
|
+
_recreateContext() {
|
|
242
|
+
if (this._context) {
|
|
243
|
+
try {
|
|
244
|
+
this._context.close();
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
// Dead context - nothing left to release
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
try {
|
|
251
|
+
this._context = new this._Context();
|
|
252
|
+
}
|
|
253
|
+
catch (err) {
|
|
254
|
+
this._context = null;
|
|
255
|
+
this._safeEmitError(err);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
190
258
|
/**
|
|
191
259
|
* Handle reader attached
|
|
192
260
|
*/
|
|
@@ -231,39 +299,72 @@ class Devices extends events_1.EventEmitter {
|
|
|
231
299
|
this._readers.set(readerName, state);
|
|
232
300
|
}
|
|
233
301
|
state.hasCard = true;
|
|
302
|
+
const generation = this._generation;
|
|
234
303
|
// Try to connect to the card
|
|
235
304
|
try {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
305
|
+
// The reader list can lag the monitor event during PnP churn -
|
|
306
|
+
// retry briefly before giving up (Issue #117)
|
|
307
|
+
let reader;
|
|
308
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
309
|
+
if (attempt > 0) {
|
|
310
|
+
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
311
|
+
// Bail if monitoring stopped or restarted while we slept
|
|
312
|
+
if (!this._running || this._generation !== generation) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
const readers = this._context
|
|
317
|
+
? this._context.listReaders()
|
|
318
|
+
: [];
|
|
319
|
+
reader = readers.find((r) => r.name === readerName);
|
|
320
|
+
if (reader) {
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (!reader) {
|
|
325
|
+
// Reader vanished mid-churn: leave no half-state behind - the
|
|
326
|
+
// queued reader-detached will finish the cleanup
|
|
327
|
+
state.hasCard = false;
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
let nativeCard;
|
|
331
|
+
try {
|
|
332
|
+
// First try with both T=0 and T=1 protocols
|
|
333
|
+
nativeCard = await reader.connect(this._SCARD_SHARE_SHARED, this._SCARD_PROTOCOL_T0 | this._SCARD_PROTOCOL_T1);
|
|
334
|
+
}
|
|
335
|
+
catch (dualProtocolErr) {
|
|
336
|
+
// If dual protocol fails with unresponsive card error,
|
|
337
|
+
// fallback to T=0 only (issue #34)
|
|
338
|
+
if ((0, errors_1.isUnresponsiveCardError)(dualProtocolErr)) {
|
|
339
|
+
nativeCard = await reader.connect(this._SCARD_SHARE_SHARED, this._SCARD_PROTOCOL_T0);
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
// Re-throw if it's a different error
|
|
343
|
+
throw dualProtocolErr;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (!this._running || this._generation !== generation) {
|
|
347
|
+
// stop() ran while connect was in flight - it cannot see this
|
|
348
|
+
// card, so release the handle here
|
|
240
349
|
try {
|
|
241
|
-
|
|
242
|
-
nativeCard = await reader.connect(this._SCARD_SHARE_SHARED, this._SCARD_PROTOCOL_T0 | this._SCARD_PROTOCOL_T1);
|
|
350
|
+
nativeCard.disconnect();
|
|
243
351
|
}
|
|
244
|
-
catch
|
|
245
|
-
//
|
|
246
|
-
// fallback to T=0 only (issue #34)
|
|
247
|
-
if (isUnresponsiveCardError(dualProtocolErr)) {
|
|
248
|
-
nativeCard = await reader.connect(this._SCARD_SHARE_SHARED, this._SCARD_PROTOCOL_T0);
|
|
249
|
-
}
|
|
250
|
-
else {
|
|
251
|
-
// Re-throw if it's a different error
|
|
252
|
-
throw dualProtocolErr;
|
|
253
|
-
}
|
|
352
|
+
catch {
|
|
353
|
+
// Ignore disconnect errors
|
|
254
354
|
}
|
|
255
|
-
|
|
256
|
-
const card = (0, card_wrapper_1.wrapCard)(nativeCard);
|
|
257
|
-
state.card = card;
|
|
258
|
-
this.emit('card-inserted', {
|
|
259
|
-
reader: { name: readerName, state: eventState, atr: atr },
|
|
260
|
-
card: card,
|
|
261
|
-
});
|
|
355
|
+
return;
|
|
262
356
|
}
|
|
357
|
+
// Wrap the native card to add autoGetResponse support
|
|
358
|
+
const card = (0, card_wrapper_1.wrapCard)(nativeCard);
|
|
359
|
+
state.card = card;
|
|
360
|
+
this.emit('card-inserted', {
|
|
361
|
+
reader: { name: readerName, state: eventState, atr: atr },
|
|
362
|
+
card: card,
|
|
363
|
+
});
|
|
263
364
|
}
|
|
264
365
|
catch (err) {
|
|
265
366
|
// Emit error but don't fail
|
|
266
|
-
this.
|
|
367
|
+
this._safeEmitError(err);
|
|
267
368
|
}
|
|
268
369
|
}
|
|
269
370
|
/**
|
package/dist/lib/devices.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devices.js","sourceRoot":"","sources":["../../lib/devices.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"devices.js","sourceRoot":"","sources":["../../lib/devices.ts"],"names":[],"mappings":";;;AAAA,mCAAsC;AAatC,iDAA0C;AAC1C,qCAIkB;AAElB,MAAM,KAAK,GAAG,OAAO,CAAC,yCAAyC,CAAgB,CAAC;AAOhF;;;;;;;;;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.d.ts
CHANGED
|
@@ -24,10 +24,11 @@ export declare class NoReadersError extends PCSCError {
|
|
|
24
24
|
constructor(message?: string);
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
* Error thrown when PC/SC service is not running
|
|
27
|
+
* Error thrown when PC/SC service is not running (SCARD_E_NO_SERVICE), or
|
|
28
|
+
* stopped while in use (SCARD_E_SERVICE_STOPPED)
|
|
28
29
|
*/
|
|
29
30
|
export declare class ServiceNotRunningError extends PCSCError {
|
|
30
|
-
constructor(message?: string);
|
|
31
|
+
constructor(message?: string, code?: number);
|
|
31
32
|
}
|
|
32
33
|
/**
|
|
33
34
|
* Error thrown when there's a sharing violation
|
|
@@ -35,8 +36,29 @@ export declare class ServiceNotRunningError extends PCSCError {
|
|
|
35
36
|
export declare class SharingViolationError extends PCSCError {
|
|
36
37
|
constructor(message?: string);
|
|
37
38
|
}
|
|
39
|
+
export declare const SCARD_W_UNRESPONSIVE_CARD = 2148532326;
|
|
38
40
|
/**
|
|
39
41
|
* Factory function to create the appropriate error class based on PC/SC error code
|
|
40
42
|
*/
|
|
41
43
|
export declare function createPCSCError(message: string, code: number): PCSCError;
|
|
44
|
+
/**
|
|
45
|
+
* The PC/SC error code an error carries, as an unsigned value, or undefined
|
|
46
|
+
* if it has none. Only codes in the PC/SC facility (0x8010xxxx) count: other
|
|
47
|
+
* libraries' errors (DOMException, gRPC, ...) also have numeric codes.
|
|
48
|
+
*/
|
|
49
|
+
export declare function getPCSCErrorCode(err: unknown): number | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* Check if an error indicates an unresponsive card (SCARD_W_UNRESPONSIVE_CARD).
|
|
52
|
+
* Used for the protocol fallbacks in Devices (connect) and CardWrapper
|
|
53
|
+
* (reconnect).
|
|
54
|
+
*/
|
|
55
|
+
export declare function isUnresponsiveCardError(err: Error): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Normalize an error into the typed hierarchy.
|
|
58
|
+
*
|
|
59
|
+
* The native layer already throws typed errors; this upgrades any other
|
|
60
|
+
* Error carrying a PC/SC `code` and wraps non-Error values. Everything else
|
|
61
|
+
* passes through unchanged.
|
|
62
|
+
*/
|
|
63
|
+
export declare function toPCSCError(err: unknown): Error;
|
|
42
64
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/lib/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../lib/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAM5C;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,SAAS;gBAC/B,OAAO,SAAqB;CAI3C;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,SAAS;gBAC3B,OAAO,SAAwB;CAI9C;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,SAAS;gBAC7B,OAAO,SAAyB;CAI/C;AAED
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../lib/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAM5C;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,SAAS;gBAC/B,OAAO,SAAqB;CAI3C;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,SAAS;gBAC3B,OAAO,SAAwB;CAI9C;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,SAAS;gBAC7B,OAAO,SAAyB;CAI/C;AAED;;;GAGG;AACH,qBAAa,sBAAuB,SAAQ,SAAS;gBACrC,OAAO,SAA8B,EAAE,IAAI,SAAa;CAIvE;AAED;;GAEG;AACH,qBAAa,qBAAsB,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