Last active
August 29, 2015 14:06
-
-
Save kamituel/264ee1683c5a3f805be0 to your computer and use it in GitHub Desktop.
SE API usage example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Security around field enter/leave events - do we want to constrain this somehow?