Simple pcsclite wrapper for mifare 1K card.
Works with promises and provides an easy to use wrapper to communicate with Mifate 1K tags.
Under the hood it is using node-pcsclite, you can follow installation instructions from there.
const mifare = require('mifare-pcsc');
(async () => {
const ctx = mifare();
while (true) {
console.log('Waiting for a card...');
const card = await ctx.waitForCard();
try {
const uid = await card.getUID();
console.log('UID', uid);
} catch (err) {
console.log('Error on getUID', err);
}
await card.disconnect();
}
})();
This context manage the underlying pcsclite library and provide a card polling mechanism.
- err
Error
. The error.
- card
Card
. The connected card.
Returns a Promise that resolve into a Card
when it connects.
This class represents a connected card and methods to interact with it.
Returns a Promise that resolve into a Buffer
that contains the UID.
- nb
Number
. Key number. - key
Buffer
. 6 bytes Key.
Load authentication key into the reader of the card. Returns a Promise.
- block
Number
. Block to authenticate. - type
Number
. Key type, provided bymifare.KEY_TYPE_A
andmifare.KEY_TYPE_B
. - key
Number
. Key number set when usingcard.loadAuthKey
.
Authenticate on block with a key. Returns a Promise.
- block
Number
. Block to read. - length
Number
. Length in bytes to read.
Read a block. Returns a Promise that resolve to a Buffer
containing the data.
- block
Number
. Block to update. - data
Buffer
. Value that should be updated in the block.
Update data in a block. Returns a Promise.
- src
Number
. Block to read data from. - dest
Number
. Block to restore from src.
Restore destination block with source block. Returns a Promise.
Early disconnect of card when finished to use. Optional. Returns a Promise.
- input
Buffer
. Command with data to send to the card. - resLen
Number
. Size of expected response from the card.
Low-level method for sending arbitrary command to the card.
Returns a Promise that resolve into a Buffer
.
- block
Buffer
. Raw trailer block to unpack.
Returns a parser trailer block like so