Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@pokusew/pcsclite
Advanced tools
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.
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:
apt-get install libpcsclite1 libpcsclite-dev
To run any code you will also need to have installed the pcsc daemon:
apt-get install pcscd
Once you have all needed libraries, you can install node-pcsclite using npm:
npm install @pokusew/pcsclite --save
or using Yarn:
yarn add @pokusew/pcsclite
👉 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.
const pcsclite = require('@pokusew/pcsclite');
const pcsc = pcsclite();
pcsc.on('reader', (reader) => {
console.log('New reader detected', reader.name);
reader.on('error', err => {
console.log('Error(', reader.name, '):', err.message);
});
reader.on('status', (status) => {
console.log('Status(', reader.name, '):', status);
// check what has changed
const changes = reader.state ^ status.state;
if (!changes) {
return;
}
if ((changes & reader.SCARD_STATE_EMPTY) && (status.state & reader.SCARD_STATE_EMPTY)) {
console.log("card removed");
reader.disconnect(reader.SCARD_LEAVE_CARD, err => {
if (err) {
console.log(err);
return;
}
console.log('Disconnected');
});
}
else if ((changes & reader.SCARD_STATE_PRESENT) && (status.state & reader.SCARD_STATE_PRESENT)) {
console.log("card inserted");
reader.connect({ share_mode: reader.SCARD_SHARE_SHARED }, (err, protocol) => {
if (err) {
console.log(err);
return;
}
console.log('Protocol(', reader.name, '):', protocol);
reader.transmit(Buffer.from([0x00, 0xB0, 0x00, 0x00, 0x20]), 40, protocol, (err, data) => {
if (err) {
console.log(err);
return;
}
console.log('Data received', data);
reader.close();
pcsc.close();
});
});
}
});
reader.on('end', () => {
console.log('Reader', reader.name, 'removed');
});
});
pcsc.on('error', err => {
console.log('PCSC error', err.message);
});
TODO document
The PCSCLite object is an EventEmitter that notifies the existence of Card Readers.
error
Error Object
. The error.reader
CardReader
. A CardReader object associated to the card reader detectedEmitted whenever a new card reader is detected.
It frees the resources associated with this PCSCLite instance. At a low level it
calls SCardCancel
so it stops watching for new readers.
An object containing all detected readers by name. Updated as readers are attached and removed.
The CardReader object is an EventEmitter that allows to manipulate a card reader.
error
Error Object
. The error.end
Emitted when the card reader has been removed.
status
Object
.
SCardGetStatusChange
Emitted whenever the status of the reader changes.
Object
Optional
Number
Shared mode. Defaults to SCARD_SHARE_EXCLUSIVE
Number
Preferred protocol. Defaults to SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1
Function
called when connection operation ends
Error
Number
Established protocol to this connection.Wrapper around SCardConnect
.
Establishes a connection to the reader.
Number
. Reader function to execute. Defaults to SCARD_UNPOWER_CARD
Function
called when disconnection operation ends
Error
Wrapper around SCardDisconnect
.
Terminates a connection to the reader.
Buffer
input data to be transmittedNumber
. Max. expected length of the responseNumber
. Protocol to be used in the transmissionFunction
called when transmit operation ends
Error
Buffer
Wrapper around SCardTransmit
.
Sends an APDU to the smart card contained in the reader connected to.
Buffer
input data to be transmittedNumber
. Control code for the operationNumber
. Max. expected length of the responseFunction
called when control operation ends
Error
Buffer
Wrapper around SCardControl
.
Sends a command directly to the IFD Handler (reader driver) to be processed by the reader.
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.
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.
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?.
TODO document
in the meantime see #10
@pokusew/pcsclite officially supports the following Node.js versions: 8.x, 9.x, 10.x, 11.x, 12.x, 13.x.
FAQs
Bindings over PC/SC to access Smart Cards
The npm package @pokusew/pcsclite receives a total of 313 weekly downloads. As such, @pokusew/pcsclite popularity was classified as not popular.
We found that @pokusew/pcsclite demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.