-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
30 lines (28 loc) · 1.11 KB
/
index.js
File metadata and controls
30 lines (28 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const GlobalPlatform = require("node-gp")
const smartcard = require('smartcard')
const Devices = smartcard.Devices
const devices = new Devices()
devices.on('device-activated', event => {
event.device.on('card-inserted', async event => {
// delay because of system smartcard contention locking out access
await new Promise(resolve => setTimeout(resolve, 3000))
const transceive = event.card.issueCommand.bind(event.card)
const gpcard = new GlobalPlatform(transceive)
gpcard.connect().then(() => {
console.log("connected")
// now you have a connected device
gpcard.getPackages().then(packages => {
if (packages.length) {
for (let package of packages) {
// print out package aids
console.log("found package: " + Buffer.from(package.aid).toString("hex"))
}
} else {
console.log("no packages on this device")
}
})
}).catch(error => {
console.error(error)
})
})
})