Gets an attribute from the IFD Handler.
ID of the requested attribute. attributes.ids provides a non-exhaustive list of available attribute IDs that may be useful.
Optional
outputBuffer: ArrayBufferBacking buffer for the response. If omitted, a new buffer will be allocated with enough space for the response.
The attribute value response.
Sets an attribute of the IFD Handler.
ID of the requested attribute. attributes.ids provides a non-exhaustive list of available attribute IDs that may be useful.
The new byte data value of the attribute.
Sends a command directly to the IFD Handler (reader driver).
This is useful for creating client side reader drivers for functions like PIN pads, biometrics, or other extensions to the normal smart card reader that are not normally handled by PC/SC.
import * as pcsc from "pcsc-mini";
const IOCTL_GET_FEATURE_REQUEST = pcsc.controlCode(3400);
function getFeatures(card: pcsc.Card): Promise<Uint8Array> {
return card.control(IOCTL_GET_FEATURE_REQUEST);
}
The card reader device control code. For cross platform compatibility, use controlCode to construct the control code.
Optional
command: Uint8Array<ArrayBufferLike>Control command data, if any.
Optional
outputBuffer: ArrayBufferBacking buffer for the response. If omitted, a new buffer will be allocated with enough space for the response.
The response data from the reader.
Closes the connection to the card, rendering this instance invalid.
Action to take after disconnection.
Attempts to re-establish a previously reset connection.
If connected in CardMode.SHARED, another process may reset the card, causing successive commands to return an error. In those cases, calling reconnect will restore the connection accordingly.
For the sake of portability across platforms, the reconnect request is sent with the previously active protocol. To change protocols, first disconnect and then establish a new connection.
Access mode for the restored connection.
Action to take on the card when reconnecting.
Establishes a temporary CardMode.EXCLUSIVE connection to the card, if originally connected with CardMode.SHARED, creating a lock for issuing multiple commands without interruption from other processes.
Must be followed up with a matching call to Transaction.end() when done with the session.
import * as pcsc from "pcsc-mini";
async function longRunningProcess(card: pcsc.Card) {
const txn = card.transaction();
try {
const r1 = await card.transmit(Uint8Array.of(0xca, 0xfe, 0xf0, 0x0d));
const r2 = await card.transmit(Uint8Array.of(0xfa, 0xde, 0xfa, 0xce));
return processResults(r1, r2);
} catch (err) {
console.error("Something went wrong:", err);
} finally {
txn.end(pcsc.CardDisposition.LEAVE);
}
}
A handle to the newly active transaction.
Sends an APDU to the card.
import { Buffer } from "node:buffer";
import * as pcsc from "pcsc-mini";
async function getData(card: pcsc.Card) {
const buf = new ArrayBuffer(pcsc.MAX_BUFFER_LEN);
try {
const res1 = await card.transmit(Uint8Array.of(0xca, 0xfe), buf);
const foo = processRes1(res1);
const res2 = await card.transmit(Buffer.of(0xf0, 0x0d), buf);
const bar = processRes2(res2);
return processResults(foo, bar);
} catch (err) {
console.error("Something went wrong:", err);
return null;
}
}
The APDU byte data.
Optional
outputBuffer: ArrayBufferBacking buffer for the response. If omitted, a new buffer will be allocated with enough space for the response.
The response data from the card.
Sends an APDU to the card with a specific protocol. Useful for CardMode.DIRECT connections, when a specific protocol has not yet been negotiated.
import { Buffer } from "node:buffer";
import * as pcsc from "pcsc-mini";
async function getData(card: pcsc.Card) {
try {
const foo = await card.transmit(
pcsc.Protocol.T1,
Uint8Array.of(0xca, 0xfe),
);
const bar = await card.transmit(
pcsc.Protocol.T1,
Buffer.of(0xf0, 0x0d),
);
return processResults(foo, bar);
} catch (err) {
console.error("Something went wrong:", err);
return null;
}
}
The APDU byte data.
Optional
outputBuffer: ArrayBufferBacking buffer for the response. If omitted, a new buffer will be allocated with enough space for the response.
The response data from the card.
Represents a connection to an inserted smart card.
Example