Skip to content

Instantly share code, notes, and snippets.

@kamituel
Last active August 29, 2015 14:06
Show Gist options
  • Save kamituel/264ee1683c5a3f805be0 to your computer and use it in GitHub Desktop.
Save kamituel/264ee1683c5a3f805be0 to your computer and use it in GitHub Desktop.
SE API usage example
var openSession = function(readers) {
var seReader = readers.filter(function(reader) {
return reader.type === 'uicc';
})[0];
if (!seReader) {
return Promise.reject('No suitable SE found');
}
return seReader.openSession();
};
var openChannel = function(session) {
var testAIDBuffer = ['0', '1', '2'];
var mastercardAID = new Uint8Array(testAIDBuffer);
return session.openLogicalChannel(mastercardAID);
};
var sendFirstAPDU = function(channel) {
var apdu = new SECommand('A', 'B', 'C', 'D');
return channel.transmit(apdu);
};
var sendSecondAPDU = function(response) {
// Do sth wit the response
var apdu = new SECommand('1', '2', '3', '4');
return response.channel.transmit(apdu);
};
var updateUI = function() {
console.log('All okay');
};
var showError = function(error) {
console.error(error);
};
var cleanup = function(response) {
return response.channel.reader.closeAll();
};
var sedom = window.navigator.mozSEManager;
var pRdrs = sedom.getSEReaders();
pRdrs.then(openSession)
.then(openChannel)
.then(sendFirstAPDU)
.then(sendSecondAPDU)
.then(cleanup)
.then(updateUI)
.catch(showError);
@kamituel
Copy link
Author

How to support developers with testing this API on the phone or the emulator? (emulator support? card reader connected to the PC via USB, and acting as a SE for an emulator)

@kamituel
Copy link
Author

Security around field enter/leave events - do we want to constrain this somehow?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment