new GrabbaMRTD()
Access Grabba MRTD via grabba.mrtd
Methods
-
getDataFromMRZ(onSuccess, onError, trackData, fileID)
-
Using the MRZ from a presented identity document, attempt to read a file on the smartcard using the ICAO9303 standard.
Parameters:
Name Type Description onSuccess
function Called on success with the following parameter:
{int[]} tlv raw array containing BER TLV data.
This array can be parsed using the grabba.bertlv.processRawBerTlv(tlv) to create a parsed BerTlv representation.onError
function Called on error with the following parameters:
{String} error description.trackData
String Passport MRZ data fileID
int File ID to be read Example
//An example of the getDataFromMRZ function var successCallback = function(tlv) { //tlv contains the raw BER TLV. We can process this into a JSON object using grabba.bertlv utilities var tlv = grabba.bertlv.processRawBerTlv(tlv); //tlv now contains the BER-TLV object. Find the image tag - this is tag 0x5F2E or 0x7F2E as per the ICAO standard var jpeg = tlv.findObjectByTag(0x5F2E); if (jpeg === null) { jpeg = tlv.findObjectByTag(0x7F2E); } if (jpeg !== null) { //There is non-JPEG data before the JPEG image //Find the start of image marker var data = jpeg.primitiveValue; var offset = 0; for (offset = 0; offset < data.length - 12; offset++) { if (data[offset] === 0xFF && data[offset + 1] === 0xD8) { break; } //check for JPEG2000 headers else if (data[offset] === 0x00 && data[offset + 1] === 0x00 && // data[offset + 2] === 0x00 && data[offset + 3] === 0x0C && // data[offset + 4] === 0x6A && data[offset + 5] === 0x50 && // data[offset + 6] === 0x20 && data[offset + 7] === 0x20 && // data[offset + 8] === 0x0D && data[offset + 9] === 0x0A && // data[offset + 10] === 0x87 && data[offset + 11] === 0x0A) { // Found the Start of image marker break; } else if (data[offset] === 0x0D && data[offset + 1] === 0x0A && // data[offset + 2] === 0x87 && data[offset + 3] === 0x0A) { // Found the Start of image marker break; } else if (data[offset] === 0xFF && data[offset + 1] === 0x4F && // data[offset + 2] === 0xFF && data[offset + 3] === 0x51) { // Found the Start of image marker break; } } //Convert image to Base64 using grabba.util grabba.util.convertJpegToBase64(function(imageBase64){ //Display the image document.getElementById("photo").src = imageBase64; }, function(errorString) { alert('on error ' + errorString); }, data, offset); } }; grabba.mrtd.getDataFromMRZ(successCallback, $scope.onError, document.getElementById("passportMRZData").textContent, 0x0102);
-
registerCallback(callback, onError)
-
Register callbacks for Passport MRTD related events.
If no callbacks are passed to this function, all present callbacks will be cleared.Parameters:
Name Type Description callback
Object An object which implements the following functions:
progressEvent : : function(progress){}
Called when MRTD progress events occur with one variable as follows:
{int} progress The progress percentage.onError
function Called on error with the following parameters:
{String} error description.Example
//An example of an implemented MRTD callback is as follows: var mrtdCallbacks = { progressEvent: function(percentage) { //This callback provides progress updates on the MRTD file transfer after authentication is complete. document.getElementById("statusMessage").textContent = "Progress: " + percentage + "%"; } }; grabba.mrtd.registerCallback(mrtdCallbacks, onError);