{"id":16951319,"url":"https://github.com/santigimeno/node-pcsclite","last_synced_at":"2025-04-13T02:23:41.143Z","repository":{"id":9051695,"uuid":"10817553","full_name":"santigimeno/node-pcsclite","owner":"santigimeno","description":"Bindings over pcsclite to access Smart Cards","archived":false,"fork":false,"pushed_at":"2024-03-12T15:11:14.000Z","size":181,"stargazers_count":171,"open_issues_count":25,"forks_count":128,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-10-14T21:59:48.124Z","etag":null,"topics":["card-reader","node-pcsclite","pcsc","pcsclite","reader"],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/santigimeno.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-06-20T10:29:56.000Z","updated_at":"2024-10-12T10:05:59.000Z","dependencies_parsed_at":"2024-06-18T14:08:26.015Z","dependency_job_id":null,"html_url":"https://github.com/santigimeno/node-pcsclite","commit_stats":{"total_commits":114,"total_committers":17,"mean_commits":6.705882352941177,"dds":0.4649122807017544,"last_synced_commit":"684df27c18087f7c4fbd300771deb46e7e6c32cb"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santigimeno%2Fnode-pcsclite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santigimeno%2Fnode-pcsclite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santigimeno%2Fnode-pcsclite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santigimeno%2Fnode-pcsclite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/santigimeno","download_url":"https://codeload.github.com/santigimeno/node-pcsclite/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248655015,"owners_count":21140410,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["card-reader","node-pcsclite","pcsc","pcsclite","reader"],"created_at":"2024-10-13T21:59:50.046Z","updated_at":"2025-04-13T02:23:41.119Z","avatar_url":"https://github.com/santigimeno.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-pcsclite\n[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/santigimeno/node-pcsclite?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nBindings over pcsclite to access Smart Cards. Starting with version **0.4.0** it works in **Linux**, **OS X** and **Windows**.\n\n## Installation\n\nYou'll need a node version installed in the system. You have several options:\n\n* Download and install it from the [node website](http://nodejs.org/)\n* Install it from your own distro. For the Debian users:\n\n    `apt-get install nodejs nodejs-legacy`\n\n* Use [nodesource repository](https://github.com/nodesource/distributions) for different distros.\n* Use tools like [nave](https://github.com/isaacs/nave) or [nvm](https://github.com/creationix/nvm)\n\nIn order to install the package you need to have installed in the system the\npcsclite libraries. For example, in Debian/Ubuntu:\n\n    apt-get install libpcsclite1 libpcsclite-dev\n\nOnce they are installed just run:\n\n    npm install pcsclite\n\nTo run any code you will also need to have installed the pcsc daemon:\n\n    apt-get install pcscd\n\n## Example\n\n```js\nvar pcsc = require('pcsclite');\n\nvar pcsc = pcsc();\npcsc.on('reader', function(reader) {\n\n    console.log('New reader detected', reader.name);\n\n    reader.on('error', function(err) {\n        console.log('Error(', this.name, '):', err.message);\n    });\n\n    reader.on('status', function(status) {\n        console.log('Status(', this.name, '):', status);\n        /* check what has changed */\n        var changes = this.state ^ status.state;\n        if (changes) {\n            if ((changes \u0026 this.SCARD_STATE_EMPTY) \u0026\u0026 (status.state \u0026 this.SCARD_STATE_EMPTY)) {\n                console.log(\"card removed\");/* card removed */\n                reader.disconnect(reader.SCARD_LEAVE_CARD, function(err) {\n                    if (err) {\n                        console.log(err);\n                    } else {\n                        console.log('Disconnected');\n                    }\n                });\n            } else if ((changes \u0026 this.SCARD_STATE_PRESENT) \u0026\u0026 (status.state \u0026 this.SCARD_STATE_PRESENT)) {\n                console.log(\"card inserted\");/* card inserted */\n                reader.connect({ share_mode : this.SCARD_SHARE_SHARED }, function(err, protocol) {\n                    if (err) {\n                        console.log(err);\n                    } else {\n                        console.log('Protocol(', reader.name, '):', protocol);\n                        reader.transmit(new Buffer([0x00, 0xB0, 0x00, 0x00, 0x20]), 40, protocol, function(err, data) {\n                            if (err) {\n                                console.log(err);\n                            } else {\n                                console.log('Data received', data);\n                                reader.close();\n                                pcsc.close();\n                            }\n                        });\n                    }\n                });\n            }\n        }\n    });\n\n    reader.on('end', function() {\n        console.log('Reader',  this.name, 'removed');\n    });\n});\n\npcsc.on('error', function(err) {\n    console.log('PCSC error', err.message);\n});\n```\n\n## API\n\n### Class: PCSCLite\n\nThe PCSCLite object is an EventEmitter that notifies the existence of Card Readers.\n\n#### Event:  'error'\n\n* *err* `Error Object`. The error.\n\n#### Event:  'reader'\n\n* *reader* `CardReader`. A CardReader object associated to the card reader detected\n\nEmitted whenever a new card reader is detected.\n\n#### pcsclite.close()\n\nIt frees the resources associated with this PCSCLite instance. At a low level it calls [`SCardCancel`](http://pcsclite.alioth.debian.org/pcsc-lite/node21.html) so it stops watching for new readers.\n\n#### pcsclite.readers\n\nAn object containing all detected readers by name. Updated as readers are attached and removed.\n\n### Class: CardReader\n\nThe CardReader object is an EventEmitter that allows to manipulate a card reader.\n\n#### Event:  'error'\n\n* *err* `Error Object`. The error.\n\n#### Event:  'end'\n\nEmitted when the card reader has been removed.\n\n#### Event:  'status'\n\n* *status* `Object`.\n    * *state* The current status of the card reader as returned by [`SCardGetStatusChange`](http://pcsclite.alioth.debian.org/pcsc-lite/node20.html)\n    * *atr* ATR of the card inserted (if any)\n\nEmitted whenever the status of the reader changes.\n\n#### reader.connect([options], callback)\n\n* *options* `Object` Optional\n    * *share_mode* `Number` Shared mode. Defaults to `SCARD_SHARE_EXCLUSIVE`\n    * *protocol* `Number` Preferred protocol. Defaults to `SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1`\n* *callback* `Function` called when connection operation ends\n    * *error* `Error`\n    * *protocol* `Number` Established protocol to this connection.\n\nWrapper around [`SCardConnect`](http://pcsclite.alioth.debian.org/pcsc-lite/node12.html). Establishes a connection to the reader.\n\n#### reader.disconnect(disposition, callback)\n\n* *disposition* `Number`. Reader function to execute. Defaults to `SCARD_UNPOWER_CARD`\n* *callback* `Function` called when disconnection operation ends\n    * *error* `Error`\n\nWrapper around [`SCardDisconnect`](http://pcsclite.alioth.debian.org/pcsc-lite/node14.html). Terminates a connection to the reader.\n\n#### reader.transmit(input, res_len, protocol, callback)\n\n* *input* `Buffer` input data to be transmitted\n* *res_len* `Number`. Max. expected length of the response\n* *protocol* `Number`. Protocol to be used in the transmission\n* *callback* `Function` called when transmit operation ends\n    * *error* `Error`\n    * *output* `Buffer`\n\nWrapper around [`SCardTransmit`](http://pcsclite.alioth.debian.org/pcsc-lite/node17.html). Sends an APDU to the smart card contained in the reader connected to.\n\n#### reader.control(input, control_code, res_len, callback)\n\n* *input* `Buffer` input data to be transmitted\n* *control_code* `Number`. Control code for the operation\n* *res_len* `Number`. Max. expected length of the response\n* *callback* `Function` called when control operation ends\n    * *error* `Error`\n    * *output* `Buffer`\n\nWrapper around [`SCardControl`](http://pcsclite.alioth.debian.org/pcsc-lite/node18.html). Sends a command directly to the IFD Handler (reader driver) to be processed by the reader.\n\n#### reader.close()\n\nIt frees the resources associated with this CardReader instance. At a low level it calls [`SCardCancel`](http://pcsclite.alioth.debian.org/pcsc-lite/node21.html) so it stops watching for the reader status changes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsantigimeno%2Fnode-pcsclite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsantigimeno%2Fnode-pcsclite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsantigimeno%2Fnode-pcsclite/lists"}