Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
cordova-plugin-hce
Advanced tools
This plugin provides Host Card Emulation (HCE) for Apache Cordova. Host-based card emulation allows a Cordova application emulate a NFC Smart Card (without using the secure element) and talk directly to the NFC reader.
This plugin provides a low-level access. The plugin receives commands as Uint8Arrays and expects responses to be Uint8Arrays. As a developer, you must implement higher level protocols based on your applications needs.
Host Card Emulation requires NFC.
The AID for your application must be passed as a variable when installing the plugin.
cordova plugin add cordova-plugin-hce --variable AID_FILTER=F222222222
The hce object provides functions that allow your application to emulate a smart card.
Register to receive APDU commands from the remote device.
hce.registerCommandCallback(onCommand);
Function registerCommandCallback
allows your JavaScript code to handle APDU responses from the NFC reader. Commands will be sent as Uint8Array to the success callback. The success callback is long lived and may be called many times.
Responses are sent back using hce.sendResponse
. Android recommends "...response APDUs must be sent as quickly as possible, given the fact that the user is likely holding his device over an NFC reader when this method is called." For more info see [HostApduService.processCommandApdu](http://developer.android.com/reference/android/nfc/cardemulation/HostApduService.html#processCommandApdu(byte[], android.os.Bundle)).
hce.registerCommandCallback(onCommand);
var onCommand = function(command) {
var commandAsBytes = new Uint8Array(command);
var commandAsString = hce.util.byteArrayToHexString(commandAsBytes);
// do something with the command
// send the response
hce.sendReponse(commandResponse);
}
Sends a response APDU back to the remote device.
hce.sendResponse(responseApdu, success);
Function sendResponse
is intended to be called from within the success handler of hce.registerCommandCallback
. Response commands should be sent a Uint8Array.
See HostApduService.sendResponseApdu.
Register to receive callback when host service is deactivated.
hce.registerDeactivatedCallback(onDeactivated);
Function registerDeactivatedCallback
allows the plugin to be notified when the host service is deactivated. A reason code is passed to the success callback.
See HostApduService.onDeactivated.
hce.registerDeactivatedCallback(onDeactivated);
var onDeactivated = function(reason) {
console.log("Deactivated. Reason code = " + reason);
}
The hce.util object provides utility function for APDU operations.
This plugin is a wrapper around the Android HCE functionality. Reference the Android HCE documentation for more info.
See the HCE Demo application for one possible use of this plugin. The HCE demo application duplicates Android's card emulation example in Cordova and is intended to work with the Android card reader example.
Apache 2.0
FAQs
Host Card Emulation (HCE) Plugin
We found that cordova-plugin-hce demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.