Wraps smartcard on mac/linux and pcsc on windows.
npm install smartcard-interfacebash
$ npm install smartcard-interface
`
Usage
`js
const { DeviceManager } = require("smartcard-interface");
let devices = new DeviceManager();
// Called when a device is inserted.
devices.on("activate", (e) => {
let device = e.device;
console.log("Device activated", device.name);
device.on("insert", async (e) => {
let card = e.card;
console.log("Card inserted", card.getAtr());
card.connect();
// Select an applet.
let selectResponse = await card.sendCommand(Buffer.from([
0x00,
0xA4,
0x04,
0x00,
0x09,
...Buffer.from("000000000000000000", "hex") // AID
]));
console.log(selectResponse);
// Send a command into the applet.
let pubKey = await card.sendCommand(Buffer.from([
0x00, // CLA
0x32, // INS
0x00, // P1
0x00, // P2
0x20 // LE
]));
console.log(pubKey);
card.close();
});
device.on("removed", (e) => {
let card = e.card;
console.log("Card removed", card.getAtr());
});
});
`
Documentation
Classes
Card
Container for cards
Kind: global class
Properties
| Name | Type | Description |
| --- | --- | --- |
| card | smartcard.Card | The card to wrap |
| device | Device | Parent device |
* Card
* new Card()
* .getAtr() ⇒ string
* .connect()
* .close()
* .sendCommand(APDUBuffer) ⇒ Promise.<Device>
$3
Wraps a smartcard.Card
$3
Returns the card atr.
Kind: instance method of Card
Returns: string - card atr
$3
Connects to the card. Do this before sending commands.
Kind: instance method of Card
$3
Closes the current connection.
Kind: instance method of Card
$3
Executes the APDUBuffer on the card.
Kind: instance method of Card
Returns: Promise.<Device> - Output APDU
| Param | Type | Description |
| --- | --- | --- |
| APDUBuffer | Buffer | Buffer of bytes |
Example
`js
let aid = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
card.connect(); // You need to connect in order to issue commands.
// Selects the aid above.
let response = await card.sendCommand(Buffer.from([
[0x00, 0xA4, 0x04, 0x00, 0x00, 0x09, ...aid]
]));
console.log("Response", response); // Buffer < 90 00 >
card.close(); // Don't forget to close the connection when you're done.
`
Device
Container for card readers
Kind: global class
Properties
| Name | Type | Description |
| --- | --- | --- |
| name | string | Device name. |
| index | number | Device index. |
* Device
* new Device(device, index)
* "insert"
* "remove"
$3
Wraps a smartcard.Device
| Param | Type | Description |
| --- | --- | --- |
| device | smartcard.Device | The device to wrap |
| index | number | Raw device index usually 0` |
Device
Card | The card that was inserted. |
Device
Card | The card that was removed. |