Installations
npm install @pokusew/pcsclite
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
10.18.1
NPM Version
6.13.6
Score
72.3
Supply Chain
98.8
Quality
75.6
Maintenance
100
Vulnerability
100
License
Releases
Contributors
Unable to fetch Contributors
Languages
C++ (83.34%)
JavaScript (14.77%)
Python (1.89%)
Developer
pokusew
Download Statistics
Total Downloads
155,405
Last Day
30
Last Week
403
Last Month
1,436
Last Year
29,898
GitHub Statistics
62 Stars
209 Commits
55 Forks
4 Watching
21 Branches
1 Contributors
Bundle Size
4.73 kB
Minified
2.01 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.6.0
Package Id
@pokusew/pcsclite@0.6.0
Unpacked Size
66.01 kB
Size
14.90 kB
File Count
15
NPM Version
6.13.6
Node Version
10.18.1
Total Downloads
Cumulative downloads
Total Downloads
155,405
Last day
-47.4%
30
Compared to previous day
Last week
6.9%
403
Compared to previous week
Last month
-11.5%
1,436
Compared to previous month
Last year
-35.8%
29,898
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
node-pcsclite
Bindings over pcsclite to access Smart Cards. It works in Linux, macOS and Windows.
📌 Looking for library to work easy with NFC tags?
Then take a look at nfc-pcsc which offers an easy to use high level API for detecting / reading and writing NFC tags and cards.
Content
Installation
Requirements: at least Node.js 8 or newer (see this FAQ for more info)
-
Node Native Modules build tools
Because this library uses Node Native Modules (C++ Addons), which are automatically built (using node-gyp) when installing via npm or yarn, you need to have installed C/C++ compiler toolchain and some other tools depending on your OS.
Please refer to the node-gyp > Installation for the list of required tools depending on your OS and steps how to install them.
-
PC/SC API in your OS
On macOS and Windows you don't have to install anything, pcsclite API is provided by the OS.
On Linux/UNIX you'd probably need to install pcsclite library and deamon**.
For example, in Debian/Ubuntu:
1apt-get install libpcsclite1 libpcsclite-dev
To run any code you will also need to have installed the pcsc daemon:
1apt-get install pcscd
-
Once you have all needed libraries, you can install node-pcsclite using npm:
1npm install @pokusew/pcsclite --save
or using Yarn:
1yarn add @pokusew/pcsclite
Example
👉 If you'd prefer an easy to use high level API for detecting / reading and writing NFC tags and cards, take a look at nfc-pcsc.
1const pcsclite = require('@pokusew/pcsclite'); 2 3const pcsc = pcsclite(); 4 5pcsc.on('reader', (reader) => { 6 7 console.log('New reader detected', reader.name); 8 9 reader.on('error', err => { 10 console.log('Error(', reader.name, '):', err.message); 11 }); 12 13 reader.on('status', (status) => { 14 15 console.log('Status(', reader.name, '):', status); 16 17 // check what has changed 18 const changes = reader.state ^ status.state; 19 20 if (!changes) { 21 return; 22 } 23 24 if ((changes & reader.SCARD_STATE_EMPTY) && (status.state & reader.SCARD_STATE_EMPTY)) { 25 26 console.log("card removed"); 27 28 reader.disconnect(reader.SCARD_LEAVE_CARD, err => { 29 30 if (err) { 31 console.log(err); 32 return; 33 } 34 35 console.log('Disconnected'); 36 37 }); 38 39 } 40 else if ((changes & reader.SCARD_STATE_PRESENT) && (status.state & reader.SCARD_STATE_PRESENT)) { 41 42 console.log("card inserted"); 43 44 reader.connect({ share_mode: reader.SCARD_SHARE_SHARED }, (err, protocol) => { 45 46 if (err) { 47 console.log(err); 48 return; 49 } 50 51 console.log('Protocol(', reader.name, '):', protocol); 52 53 reader.transmit(Buffer.from([0x00, 0xB0, 0x00, 0x00, 0x20]), 40, protocol, (err, data) => { 54 55 if (err) { 56 console.log(err); 57 return; 58 } 59 60 console.log('Data received', data); 61 reader.close(); 62 pcsc.close(); 63 64 }); 65 66 }); 67 68 } 69 70 }); 71 72 reader.on('end', () => { 73 console.log('Reader', reader.name, 'removed'); 74 }); 75 76}); 77 78pcsc.on('error', err => { 79 console.log('PCSC error', err.message); 80});
Behavior on different OS
TODO document
API
Class: PCSCLite
The PCSCLite object is an EventEmitter that notifies the existence of Card Readers.
Event: error
- err
Error Object
. The error.
Event: reader
- reader
CardReader
. A CardReader object associated to the card reader detected
Emitted whenever a new card reader is detected.
pcsclite.close()
It frees the resources associated with this PCSCLite instance. At a low level it
calls SCardCancel
so it stops watching for new readers.
pcsclite.readers
An object containing all detected readers by name. Updated as readers are attached and removed.
Class: CardReader
The CardReader object is an EventEmitter that allows to manipulate a card reader.
Event: error
- err
Error Object
. The error.
Event: end
Emitted when the card reader has been removed.
Event: status
- status
Object
.- state The current status of the card reader as returned by
SCardGetStatusChange
- atr ATR of the card inserted (if any)
- state The current status of the card reader as returned by
Emitted whenever the status of the reader changes.
reader.connect([options], callback)
- options
Object
Optional- share_mode
Number
Shared mode. Defaults toSCARD_SHARE_EXCLUSIVE
- protocol
Number
Preferred protocol. Defaults toSCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1
- share_mode
- callback
Function
called when connection operation ends- error
Error
- protocol
Number
Established protocol to this connection.
- error
Wrapper around SCardConnect
.
Establishes a connection to the reader.
reader.disconnect(disposition, callback)
- disposition
Number
. Reader function to execute. Defaults toSCARD_UNPOWER_CARD
- callback
Function
called when disconnection operation ends- error
Error
- error
Wrapper around SCardDisconnect
.
Terminates a connection to the reader.
reader.transmit(input, res_len, protocol, callback)
- input
Buffer
input data to be transmitted - res_len
Number
. Max. expected length of the response - protocol
Number
. Protocol to be used in the transmission - callback
Function
called when transmit operation ends- error
Error
- output
Buffer
- error
Wrapper around SCardTransmit
.
Sends an APDU to the smart card contained in the reader connected to.
reader.control(input, control_code, res_len, callback)
- input
Buffer
input data to be transmitted - control_code
Number
. Control code for the operation - res_len
Number
. Max. expected length of the response - callback
Function
called when control operation ends- error
Error
- output
Buffer
- error
Wrapper around SCardControl
.
Sends a command directly to the IFD Handler (reader driver) to be processed by the reader.
reader.close()
It frees the resources associated with this CardReader instance.
At a low level it calls SCardCancel
so it stops watching for the reader status changes.
FAQ
Can I use this library in my Electron app?
Yes, you can! It works well.
But please read carefully Using Native Node Modules guide in Electron documentation to fully understand the problematic.
Note, that because of Node Native Modules, you must build your app on target platform (you must run Windows build on Windows machine, etc.).
You can use CI/CD server to build your app for certain platforms.
For Windows, I recommend you to use AppVeyor.
For macOS and Linux build, there are plenty of services to choose from, for example CircleCI, Travis CI CodeShip.
Are prebuilt binaries provided?
No, because it brings more problems than it solves. The C++ code (Node Native Modules, C++ Addons) is built automatically during installation (using node-gyp).
That means that cross-compilation is not possible by default. If you want to use this library in your Electron or NW.js, see Can I use this library in my Electron app?.
Disabling drivers to make pcsclite working on Linux
TODO document
in the meantime see #10
Which Node.js versions are supported?
@pokusew/pcsclite officially supports the following Node.js versions: 8.x, 9.x, 10.x, 11.x, 12.x, 13.x.
License
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE.md:0
- Info: FSF or OSI recognized license: ISC License: LICENSE.md:0
Reason
3 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:47: update your workflow using https://app.stepsecurity.io/secureworkflow/pokusew/node-pcsclite/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:51: update your workflow using https://app.stepsecurity.io/secureworkflow/pokusew/node-pcsclite/ci.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:61
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
Found 2/27 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 5 are checked with a SAST tool
Score
3.2
/10
Last Scanned on 2025-01-13
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More