@regulaforensics/cordova-plugin-document-reader-api 5.6.0 → 6.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -42,7 +42,7 @@ If you have issues with license verification when running the application, pleas
42
42
  6. You placed the `license` into the correct folder as described [here](#how-to-build-demo-application).
43
43
 
44
44
  ## Documentation
45
- You can find documentation on API [here](https://docs.regulaforensics.com/cordova).
45
+ You can find documentation on API [here](https://docs.regulaforensics.com/develop/doc-reader-sdk/mobile/cordova).
46
46
 
47
47
  ## Additional information
48
48
  If you have any technical questions, feel free to [contact](mailto:cordova.support@regulaforensics.com) us or create issue [here](https://github.com/regulaforensics/DocumentReader-Cordova-Plugin/issues).
@@ -16,11 +16,12 @@
16
16
  "cordova-android": "^9.0.0",
17
17
  "cordova-ios": "^6.1.1",
18
18
  "cordova-plugin-add-swift-support": "^2.0.2",
19
- "@regulaforensics/cordova-plugin-document-reader-api": "^5.6.0",
20
- "@regulaforensics/cordova-plugin-document-reader-core-fullrfid": "^5.6.0",
19
+ "@regulaforensics/cordova-plugin-document-reader-api": "^6.1.1",
20
+ "@regulaforensics/cordova-plugin-document-reader-core-fullrfid": "^6.1.0",
21
21
  "cordova-plugin-file": "^6.0.2",
22
22
  "cordova-plugin-image-picker": "^1.1.3",
23
- "cordova-plugin-android-permissions": "1.1.0"
23
+ "cordova-plugin-android-permissions": "1.1.0",
24
+ "cordova-plugin-advanced-http": "3.2.1"
24
25
  },
25
26
  "cordova": {
26
27
  "plugins": {
@@ -34,7 +35,8 @@
34
35
  "PHOTO_LIBRARY_USAGE_DESCRIPTION": " "
35
36
  },
36
37
  "cordova-plugin-whitelist": {},
37
- "cordova-plugin-android-permissions": {}
38
+ "cordova-plugin-android-permissions": {},
39
+ "cordova-plugin-advanced-http": {}
38
40
  },
39
41
  "platforms": [
40
42
  "android",
@@ -43,7 +43,7 @@
43
43
 
44
44
  <div>
45
45
  <div id="scenariosRadioGroup"
46
- style="position: absolute; bottom: 100px; top: 225px; left: 75px; width:225px; padding: 5px; text-align:left; overflow: auto"/>
46
+ style="position: absolute; bottom: 140px; top: 225px; left: 75px; width:225px; padding: 5px; text-align:left; overflow: auto"/>
47
47
  </div>
48
48
 
49
49
  <div style="position: absolute; bottom: 10px; width: 100%; text-align: center; align-items: center">
@@ -52,6 +52,11 @@
52
52
  id="rfidCheckboxText"
53
53
  style="color: lightgrey"> Process rfid reading(unavailable)</span><br>
54
54
  </div>
55
+ <div id="encryptionDiv" style="flex-direction: row; padding: 5px">
56
+ <input id="encryptionCheckbox" type="checkbox" name="rfid" disabled><span
57
+ id="encryptionCheckboxText"
58
+ style="color: lightgrey"> Data encryption(unavailable)</span><br>
59
+ </div>
55
60
  <div style="flex-direction: row; padding: 10px">
56
61
  <button id="showScannerButton" style="margin-right: 20px">scan doc</button>
57
62
  <button id="showImagePicker" style="margin-left: 20px">scan image</button>
@@ -7,10 +7,13 @@ var app = {
7
7
  this.receivedEvent('deviceready')
8
8
  document.getElementById("status").innerHTML = "loading......"
9
9
  document.getElementById("status").style.backgroundColor = "grey"
10
+ var http = cordova.plugin.http
10
11
  var DocumentReaderResults = DocumentReader.DocumentReaderResults
11
12
  var DocumentReaderScenario = DocumentReader.DocumentReaderScenario
12
13
  var Enum = DocumentReader.Enum
13
14
  var doRfid = false
15
+ var encryption = false
16
+ const ENCRYPTED_RESULT_SERVICE = "https://api.regulaforensics.com/api/process"
14
17
  var isReadingRfid = false
15
18
  var rfidUIHeader = "Reading RFID"
16
19
  var rfidUIHeaderColor = "black"
@@ -47,10 +50,15 @@ var app = {
47
50
  if (canRfid) {
48
51
  document.getElementById("rfidCheckbox").disabled = false
49
52
  document.getElementById("rfidCheckboxText").style.color = "black"
50
- document.getElementById("rfidCheckboxText").innerHTML = "Process rfid reading"
53
+ document.getElementById("rfidCheckboxText").innerHTML = " Process rfid reading"
51
54
  document.getElementById("rfidCheckboxText").onclick = function () { document.getElementById("rfidCheckbox").click() }
52
55
  document.getElementById("rfidCheckbox").onchange = function () { doRfid = this.checked }
53
56
  }
57
+ document.getElementById("encryptionCheckbox").disabled = false
58
+ document.getElementById("encryptionCheckboxText").style.color = "black"
59
+ document.getElementById("encryptionCheckboxText").innerHTML = " Data encryption"
60
+ document.getElementById("encryptionCheckboxText").onclick = function () { document.getElementById("encryptionCheckbox").click() }
61
+ document.getElementById("encryptionCheckbox").onchange = function () { encryption = this.checked }
54
62
  }
55
63
 
56
64
  function scan() {
@@ -168,7 +176,26 @@ var app = {
168
176
 
169
177
  function usualRFID() {
170
178
  doRfid = false
171
- DocumentReader.startRFIDReader(function (m) { handleCompletion(DocumentReader.DocumentReaderCompletion.fromJson(JSON.parse(m))) }, function (e) { })
179
+ var notification = "rfidNotificationCompletionEvent"
180
+ var paCert = "paCertificateCompletionEvent"
181
+ var taCert = "taCertificateCompletionEvent"
182
+ var taSig = "taSignatureCompletionEvent"
183
+ DocumentReader.startRFIDReader(function (m) {
184
+ if (m.substring(0, notification.length) === notification) {
185
+ m = m.substring(notification.length, m.length)
186
+ console.log(notification + ": " + m)
187
+ } else if (m.substring(0, paCert.length) === paCert) {
188
+ m = m.substring(paCert.length, m.length)
189
+ console.log(paCert + ": " + m)
190
+ } else if (m.substring(0, taCert.length) === taCert) {
191
+ m = m.substring(taCert.length, m.length)
192
+ console.log(taCert + ": " + m)
193
+ } else if (m.substring(0, taSig.length) === taSig) {
194
+ m = m.substring(taSig.length, m.length)
195
+ console.log(taSig + ": " + m)
196
+ } else
197
+ handleCompletion(DocumentReader.DocumentReaderCompletion.fromJson(JSON.parse(m)))
198
+ }, function (e) { })
172
199
  }
173
200
 
174
201
  function handleResults(results) {
@@ -186,7 +213,33 @@ var app = {
186
213
  //customRFID()
187
214
  usualRFID()
188
215
  } else
189
- displayResults(results)
216
+ if (encryption) {
217
+ var input = JSON.parse(results.rawResult)
218
+ var processParam = {
219
+ alreadyCropped: true,
220
+ scenario: "FullProcess"
221
+ }
222
+ var body = {
223
+ List: input["ContainerList"]["List"],
224
+ processParam: processParam
225
+ }
226
+ postRequest(body)
227
+ } else
228
+ displayResults(results)
229
+ }
230
+
231
+ function postRequest(body) {
232
+ document.getElementById("status").innerHTML = "Getting results from server......"
233
+ document.getElementById("status").style.backgroundColor = "grey"
234
+ http.setDataSerializer('utf8')
235
+ http.post(ENCRYPTED_RESULT_SERVICE, JSON.stringify(body), { "content-type": "application/json; utf-8" }, function (response) {
236
+ DocumentReader.parseCoreResults(response.data, function (m) {
237
+ displayResults(DocumentReader.DocumentReaderResults.fromJson(JSON.parse(m))) }, function (e) { })
238
+ }, function (response) {
239
+ console.error(response.error)
240
+ document.getElementById("status").innerHTML = "Something went wrong!"
241
+ document.getElementById("status").style.backgroundColor = "red"
242
+ })
190
243
  }
191
244
 
192
245
  function displayResults(results) {
@@ -274,7 +327,8 @@ var app = {
274
327
  DocumentReader.getAvailableScenarios(function (s) {
275
328
  DocumentReader.isRFIDAvailableForUse(function (r) { postInitialize(JSON.parse(s), r) }, function (e) { })
276
329
  }, function (e) { })
277
- addCertificates()
330
+ DocumentReader.setRfidDelegate(Enum.RFIDDelegate.NO_PA, function (r) { }, function (e) { })
331
+ // addCertificates()
278
332
  }, function (error) {
279
333
  console.log(error)
280
334
  document.getElementById("status").innerHTML = error
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@regulaforensics/cordova-plugin-document-reader-api",
3
- "version": "5.6.0",
3
+ "version": "6.1.1",
4
4
  "description": "Cordova plugin for reading and validation of identification documents (API framework)",
5
5
  "cordova": {
6
6
  "id": "@regulaforensics/cordova-plugin-document-reader-api",
package/plugin.xml CHANGED
@@ -1,5 +1,5 @@
1
1
  <?xml version='1.0' encoding='utf-8'?>
2
- <plugin id="cordova-plugin-document-reader-api" version="5.6.0"
2
+ <plugin id="cordova-plugin-document-reader-api" version="6.1.1"
3
3
  xmlns="http://apache.org/cordova/ns/plugins/1.0">
4
4
  <name>DocumentReaderApi</name>
5
5
  <description>Cordova plugin Document reader api</description>
@@ -18,14 +18,14 @@
18
18
  </config-file>
19
19
  <header-file src="src/ios/RGLDocumentReader.h" />
20
20
  <source-file src="src/ios/RGLDocumentReader.m" />
21
- <header-file src="src/ios/JSONConstructor.h" />
22
- <source-file src="src/ios/JSONConstructor.m" />
21
+ <header-file src="src/ios/RGLWJSONConstructor.h" />
22
+ <source-file src="src/ios/RGLWJSONConstructor.m" />
23
23
  <header-file src="src/ios/RegulaConfig.h" />
24
24
  <source-file src="src/ios/RegulaConfig.m" />
25
25
  <podspec>
26
26
  <config/>
27
27
  <pods>
28
- <pod name="DocumentReader" spec="~> 5.6.2001" />
28
+ <pod name="DocumentReader" spec="~> 6.1.2374" />
29
29
  </pods>
30
30
  </podspec>
31
31
  </platform>
@@ -1,5 +1,6 @@
1
1
  package cordova.plugin.documentreader;
2
2
 
3
+ import android.annotation.SuppressLint;
3
4
  import android.app.Activity;
4
5
  import android.app.PendingIntent;
5
6
  import android.content.Context;
@@ -8,16 +9,26 @@ import android.content.IntentFilter;
8
9
  import android.graphics.Bitmap;
9
10
  import android.nfc.NfcAdapter;
10
11
  import android.nfc.tech.IsoDep;
12
+ import android.support.annotation.NonNull;
13
+ import android.os.Bundle;
11
14
  import android.util.Base64;
12
15
 
13
16
  import com.regula.documentreader.api.completions.IDocumentReaderCompletion;
14
17
  import com.regula.documentreader.api.completions.IDocumentReaderInitCompletion;
15
18
  import com.regula.documentreader.api.completions.IDocumentReaderPrepareCompletion;
19
+ import com.regula.documentreader.api.completions.IRfidPKDCertificateCompletion;
20
+ import com.regula.documentreader.api.completions.IRfidReaderRequest;
21
+ import com.regula.documentreader.api.completions.IRfidTASignatureCompletion;
16
22
  import com.regula.documentreader.api.enums.DocReaderAction;
17
23
  import com.regula.documentreader.api.errors.DocumentReaderException;
24
+ import com.regula.documentreader.api.internal.core.CoreScenarioUtil;
25
+ import com.regula.documentreader.api.params.DocReaderConfig;
18
26
  import com.regula.documentreader.api.params.ImageInputParam;
19
27
  import com.regula.documentreader.api.params.rfid.PKDCertificate;
28
+ import com.regula.documentreader.api.params.rfid.authorization.PAResourcesIssuer;
29
+ import com.regula.documentreader.api.params.rfid.authorization.TAChallenge;
20
30
  import com.regula.documentreader.api.results.DocumentReaderResults;
31
+ import com.regula.documentreader.api.parser.DocReaderResultsJsonParser;
21
32
 
22
33
  import org.apache.cordova.CallbackContext;
23
34
  import org.apache.cordova.CordovaPlugin;
@@ -27,6 +38,8 @@ import org.json.JSONObject;
27
38
  import org.json.JSONException;
28
39
 
29
40
  import java.io.File;
41
+ import java.io.IOException;
42
+ import java.io.InputStream;
30
43
  import java.util.ArrayList;
31
44
  import java.util.List;
32
45
 
@@ -38,6 +51,13 @@ public class DocumentReader extends CordovaPlugin {
38
51
  private boolean backgroundRFIDEnabled = false;
39
52
  private Activity activity;
40
53
  JSONArray data;
54
+ private IRfidPKDCertificateCompletion paCertificateCompletion;
55
+ private IRfidPKDCertificateCompletion taCertificateCompletion;
56
+ private IRfidTASignatureCompletion taSignatureCompletion;
57
+ private final static String rfidNotificationCompletionEvent = "rfidNotificationCompletionEvent";
58
+ private final static String paCertificateCompletionEvent = "paCertificateCompletionEvent";
59
+ private final static String taCertificateCompletionEvent = "taCertificateCompletionEvent";
60
+ private final static String taSignatureCompletionEvent = "taSignatureCompletionEvent";
41
61
  private static int databaseDownloadProgress = 0;
42
62
 
43
63
  private Context getContext() {
@@ -83,7 +103,7 @@ public class DocumentReader extends CordovaPlugin {
83
103
  callbackContext.sendPluginResult(pluginResult);
84
104
  }
85
105
 
86
- private void sendCompletion(int action, DocumentReaderResults results, Throwable error) {
106
+ private void sendCompletion(int action, DocumentReaderResults results, DocumentReaderException error) {
87
107
  PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, JSONConstructor.generateCompletion(action, results, error, getContext()).toString());
88
108
  pluginResult.setKeepCallback(true);
89
109
  callbackContext.sendPluginResult(pluginResult);
@@ -95,6 +115,30 @@ public class DocumentReader extends CordovaPlugin {
95
115
  callbackContext.sendPluginResult(pluginResult);
96
116
  }
97
117
 
118
+ private void sendIRfidNotificationCompletion(int notification, Bundle value) {
119
+ PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, rfidNotificationCompletionEvent + JSONConstructor.generateRfidNotificationCompletion(notification, value).toString());
120
+ pluginResult.setKeepCallback(true);
121
+ callbackContext.sendPluginResult(pluginResult);
122
+ }
123
+
124
+ private void sendPACertificateCompletion(byte[] serialNumber, PAResourcesIssuer issuer) {
125
+ PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, paCertificateCompletionEvent + JSONConstructor.generatePACertificateCompletion(serialNumber, issuer).toString());
126
+ pluginResult.setKeepCallback(true);
127
+ callbackContext.sendPluginResult(pluginResult);
128
+ }
129
+
130
+ private void sendTACertificateCompletion(String keyCAR) {
131
+ PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, taCertificateCompletionEvent + keyCAR);
132
+ pluginResult.setKeepCallback(true);
133
+ callbackContext.sendPluginResult(pluginResult);
134
+ }
135
+ private void sendTASignatureCompletion(TAChallenge challenge) {
136
+ PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, taSignatureCompletionEvent + JSONConstructor.generateTAChallenge(challenge).toString());
137
+ pluginResult.setKeepCallback(true);
138
+ callbackContext.sendPluginResult(pluginResult);
139
+ }
140
+
141
+
98
142
  @Override
99
143
  public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
100
144
  this.callbackContext = callbackContext;
@@ -119,6 +163,9 @@ public class DocumentReader extends CordovaPlugin {
119
163
  };
120
164
  try {
121
165
  switch (action) {
166
+ case "initializeReaderAutomatically":
167
+ initializeReaderAutomatically(callback);
168
+ break;
122
169
  case "getAPIVersion":
123
170
  getAPIVersion(callback);
124
171
  break;
@@ -224,6 +271,9 @@ public class DocumentReader extends CordovaPlugin {
224
271
  case "getRfidSessionStatus":
225
272
  getRfidSessionStatus(callback);
226
273
  break;
274
+ case "setRfidDelegate":
275
+ setRfidDelegate(callback, args(0));
276
+ break;
227
277
  case "setEnableCoreLogs":
228
278
  setEnableCoreLogs(callback, args(0));
229
279
  break;
@@ -263,9 +313,24 @@ public class DocumentReader extends CordovaPlugin {
263
313
  case "setRfidSessionStatus":
264
314
  setRfidSessionStatus(callback, args(0));
265
315
  break;
316
+ case "providePACertificates":
317
+ providePACertificates(callback, args(0));
318
+ break;
319
+ case "provideTACertificates":
320
+ provideTACertificates(callback, args(0));
321
+ break;
322
+ case "provideTASignature":
323
+ provideTASignature(callback, args(0));
324
+ break;
325
+ case "parseCoreResults":
326
+ parseCoreResults(callback, args(0));
327
+ break;
266
328
  case "initializeReaderWithDatabasePath":
267
329
  initializeReaderWithDatabasePath(callback, args(0), args(1));
268
330
  break;
331
+ case "initializeReaderWithDatabase":
332
+ initializeReaderWithDatabase(callback, args(0), args(1));
333
+ break;
269
334
  case "recognizeImageFrame":
270
335
  recognizeImageFrame(callback, args(0), args(1));
271
336
  break;
@@ -300,6 +365,7 @@ public class DocumentReader extends CordovaPlugin {
300
365
  };
301
366
  Intent intent = new Intent(activity.getApplicationContext(), activity.getClass());
302
367
  intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
368
+ @SuppressLint("UnspecifiedImmutableFlag")
303
369
  PendingIntent pendingIntent = PendingIntent.getActivity(activity.getApplicationContext(), 0, intent, 0);
304
370
  NfcAdapter.getDefaultAdapter(getActivity()).enableForegroundDispatch(activity, pendingIntent, filters, techList);
305
371
  }
@@ -311,10 +377,32 @@ public class DocumentReader extends CordovaPlugin {
311
377
  backgroundRFIDEnabled = false;
312
378
  }
313
379
 
380
+ private void initializeReaderAutomatically(Callback callback) {
381
+ if (!Instance().isReady())
382
+ try {
383
+ InputStream is = getContext().getAssets().open("regula.license");
384
+ byte[] license = new byte[is.available()];
385
+ //noinspection ResultOfMethodCallIgnored
386
+ is.read(license);
387
+ Instance().initializeReader(getContext(), new DocReaderConfig(license), getInitCompletion(callback));
388
+ is.close();
389
+ } catch (IOException e) {
390
+ e.printStackTrace();
391
+ callback.error("problem reading license(see logs)");
392
+ }
393
+ else
394
+ callback.success("already initialized");
395
+ }
396
+
314
397
  private void getAvailableScenarios(Callback callback) throws JSONException {
315
398
  callback.success(JSONConstructor.generateList(Instance().availableScenarios, JSONConstructor::generateDocumentReaderScenario).toString());
316
399
  }
317
400
 
401
+ private void parseCoreResults(Callback callback, String json) {
402
+ DocumentReaderResults results = (DocumentReaderResults) DocReaderResultsJsonParser.parseCoreResults(json).get("docReaderResults");
403
+ callback.success(JSONConstructor.generateDocumentReaderResults(results, getContext()).toString());
404
+ }
405
+
318
406
  private void getAPIVersion(Callback callback) {
319
407
  callback.success(Instance().version.api);
320
408
  }
@@ -369,11 +457,11 @@ public class DocumentReader extends CordovaPlugin {
369
457
  }
370
458
 
371
459
  private void selectedScenario(Callback callback) {
372
- callback.success(JSONConstructor.generateDocumentReaderScenarioFull(Instance().getScenario(Instance().processParams().getScenario())).toString());
460
+ callback.success(JSONConstructor.generateCoreDetailedScenario(CoreScenarioUtil.getScenario(Instance().processParams().getScenario())).toString());
373
461
  }
374
462
 
375
463
  private void getScenario(Callback callback, String scenario) {
376
- callback.success(JSONConstructor.generateDocumentReaderScenarioFull(Instance().getScenario(scenario)).toString());
464
+ callback.success(JSONConstructor.generateCoreDetailedScenario(CoreScenarioUtil.getScenario(scenario)).toString());
377
465
  }
378
466
 
379
467
  private void getLicenseExpiryDate(Callback callback) {
@@ -395,11 +483,11 @@ public class DocumentReader extends CordovaPlugin {
395
483
  }
396
484
 
397
485
  private void getDocumentReaderIsReady(Callback callback) {
398
- callback.success(Instance().getDocumentReaderIsReady());
486
+ callback.success(Instance().isReady());
399
487
  }
400
488
 
401
489
  private void getDocumentReaderStatus(Callback callback) {
402
- callback.success(Instance().getDocumentReaderStatus());
490
+ callback.success(Instance().isReady());
403
491
  }
404
492
 
405
493
  private void isRFIDAvailableForUse(Callback callback) {
@@ -407,8 +495,15 @@ public class DocumentReader extends CordovaPlugin {
407
495
  }
408
496
 
409
497
  private void initializeReader(Callback callback, Object license) {
410
- if (!Instance().getDocumentReaderIsReady())
411
- Instance().initializeReader(getContext(), Base64.decode(license.toString(), Base64.DEFAULT), getInitCompletion(callback));
498
+ if (!Instance().isReady())
499
+ Instance().initializeReader(getContext(), new DocReaderConfig(Base64.decode(license.toString(), Base64.DEFAULT)), getInitCompletion(callback));
500
+ else
501
+ callback.success("already initialized");
502
+ }
503
+
504
+ private void initializeReaderWithDatabase(Callback callback, Object license, Object db) {
505
+ if (!Instance().isReady())
506
+ Instance().initializeReader(getContext(), new DocReaderConfig(Base64.decode(license.toString(), Base64.DEFAULT), Base64.decode(db.toString(), Base64.DEFAULT)), getInitCompletion(callback));
412
507
  else
413
508
  callback.success("already initialized");
414
509
  }
@@ -509,7 +604,12 @@ public class DocumentReader extends CordovaPlugin {
509
604
 
510
605
  private void startRFIDReader(@SuppressWarnings("unused") Callback callback) {
511
606
  stopBackgroundRFID();
512
- Instance().startRFIDReader(getContext(), getCompletion());
607
+ IRfidReaderRequest delegate = null;
608
+ if (rfidDelegate == RFIDDelegate.NO_PA)
609
+ delegate = getIRfidReaderRequestNoPA();
610
+ if (rfidDelegate == RFIDDelegate.FULL)
611
+ delegate = getIRfidReaderRequest();
612
+ Instance().startRFIDReader(getContext(), getCompletion(), delegate, this::sendIRfidNotificationCompletion);
513
613
  }
514
614
 
515
615
  private void stopRFIDReader(Callback callback) {
@@ -545,10 +645,52 @@ public class DocumentReader extends CordovaPlugin {
545
645
  startForegroundDispatch(getActivity());
546
646
  }
547
647
 
648
+ private void providePACertificates(Callback callback, JSONArray certificatesJSON) throws JSONException {
649
+ if (paCertificateCompletion == null) {
650
+ callback.error("paCertificateCompletion is null");
651
+ return;
652
+ }
653
+ PKDCertificate[] certificates = new PKDCertificate[certificatesJSON.length()];
654
+ for (int i = 0; i < certificatesJSON.length(); i++) {
655
+ JSONObject certificate = certificatesJSON.getJSONObject(i);
656
+ certificates[i] = new PKDCertificate(Base64.decode(certificate.get("binaryData").toString(), Base64.DEFAULT), certificate.getInt("resourceType"), certificate.has("privateKey") ? Base64.decode(certificate.get("privateKey").toString(), Base64.DEFAULT) : null);
657
+ }
658
+ paCertificateCompletion.onCertificatesReceived(certificates);
659
+ callback.success();
660
+ }
661
+
662
+ private void provideTACertificates(Callback callback, JSONArray certificatesJSON) throws JSONException {
663
+ if (taCertificateCompletion == null) {
664
+ callback.error("taCertificateCompletion is null");
665
+ return;
666
+ }
667
+ PKDCertificate[] certificates = new PKDCertificate[certificatesJSON.length()];
668
+ for (int i = 0; i < certificatesJSON.length(); i++) {
669
+ JSONObject certificate = certificatesJSON.getJSONObject(i);
670
+ certificates[i] = new PKDCertificate(Base64.decode(certificate.get("binaryData").toString(), Base64.DEFAULT), certificate.getInt("resourceType"), certificate.has("privateKey") ? Base64.decode(certificate.get("privateKey").toString(), Base64.DEFAULT) : null);
671
+ }
672
+ taCertificateCompletion.onCertificatesReceived(certificates);
673
+ callback.success();
674
+ }
675
+
676
+ private void provideTASignature(Callback callback, Object signature) {
677
+ if (taSignatureCompletion == null) {
678
+ callback.error("taSignatureCompletion is null");
679
+ return;
680
+ }
681
+ taSignatureCompletion.onSignatureReceived(Base64.decode(signature.toString(), Base64.DEFAULT));
682
+ callback.success();
683
+ }
684
+
548
685
  private void setCameraSessionIsPaused(Callback callback, @SuppressWarnings("unused") boolean ignored) {
549
686
  callback.error("setCameraSessionIsPaused() is an ios-only method");
550
687
  }
551
688
 
689
+ private void setRfidDelegate(Callback callback, int delegate) {
690
+ rfidDelegate = delegate;
691
+ callback.success();
692
+ }
693
+
552
694
  private void getCameraSessionIsPaused(Callback callback) {
553
695
  callback.error("getCameraSessionIsPaused() is an ios-only method");
554
696
  }
@@ -575,7 +717,7 @@ public class DocumentReader extends CordovaPlugin {
575
717
  private IDocumentReaderCompletion getCompletion() {
576
718
  return (action, results, error) -> {
577
719
  sendCompletion(action, results, error);
578
- if (action == DocReaderAction.ERROR || action == DocReaderAction.CANCEL || (action == DocReaderAction.COMPLETE && results.rfidResult == 1))
720
+ if (action == DocReaderAction.ERROR || action == DocReaderAction.CANCEL || (action == DocReaderAction.COMPLETE && results != null && results.rfidResult == 1))
579
721
  stopBackgroundRFID();
580
722
  };
581
723
  }
@@ -609,4 +751,57 @@ public class DocumentReader extends CordovaPlugin {
609
751
  callback.error("Init failed:" + error);
610
752
  };
611
753
  }
754
+
755
+ private IRfidReaderRequest getIRfidReaderRequest() {
756
+ return new IRfidReaderRequest() {
757
+ @Override
758
+ public void onRequestPACertificates(byte[] serialNumber, PAResourcesIssuer issuer, @NonNull IRfidPKDCertificateCompletion completion) {
759
+ paCertificateCompletion = completion;
760
+ completion.onCertificatesReceived(new PKDCertificate[0]);
761
+ sendPACertificateCompletion(serialNumber, issuer);
762
+ }
763
+
764
+ @Override
765
+ public void onRequestTACertificates(String keyCAR, @NonNull IRfidPKDCertificateCompletion completion) {
766
+ taCertificateCompletion = completion;
767
+ sendTACertificateCompletion(keyCAR);
768
+ }
769
+
770
+ @Override
771
+ public void onRequestTASignature(TAChallenge challenge, @NonNull IRfidTASignatureCompletion completion) {
772
+ taSignatureCompletion = completion;
773
+ sendTASignatureCompletion(challenge);
774
+ }
775
+ };
776
+ }
777
+
778
+ private IRfidReaderRequest getIRfidReaderRequestNoPA() {
779
+ return new IRfidReaderRequest() {
780
+ @Override
781
+ public void onRequestPACertificates(byte[] serialNumber, PAResourcesIssuer issuer, @NonNull IRfidPKDCertificateCompletion completion) {
782
+ paCertificateCompletion = null;
783
+ completion.onCertificatesReceived(new PKDCertificate[0]);
784
+ }
785
+
786
+ @Override
787
+ public void onRequestTACertificates(String keyCAR, @NonNull IRfidPKDCertificateCompletion completion) {
788
+ taCertificateCompletion = completion;
789
+ sendTACertificateCompletion(keyCAR);
790
+ }
791
+
792
+ @Override
793
+ public void onRequestTASignature(TAChallenge challenge, @NonNull IRfidTASignatureCompletion completion) {
794
+ taSignatureCompletion = completion;
795
+ sendTASignatureCompletion(challenge);
796
+ }
797
+ };
798
+ }
799
+
800
+ private static int rfidDelegate = RFIDDelegate.NULL;
801
+
802
+ private static class RFIDDelegate {
803
+ public static final int NULL = 0;
804
+ public static final int NO_PA = 1;
805
+ public static final int FULL = 2;
806
+ }
612
807
  }
@@ -17,7 +17,6 @@ import org.json.JSONArray;
17
17
  import org.json.JSONException;
18
18
  import org.json.JSONObject;
19
19
 
20
- import java.io.ByteArrayInputStream;
21
20
  import java.io.ByteArrayOutputStream;
22
21
  import java.util.ArrayList;
23
22
  import java.util.List;
@@ -25,18 +24,21 @@ import java.util.List;
25
24
  class Helpers {
26
25
  static Bitmap bitmapFromBase64(String base64) {
27
26
  byte[] decodedString = Base64.decode(base64, Base64.DEFAULT);
28
- BitmapFactory.Options options = new BitmapFactory.Options();
29
- options.inPreferredConfig = Bitmap.Config.RGB_565;
30
- Bitmap result = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length, options);
27
+ Bitmap result = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
31
28
  int sizeMultiplier = result.getByteCount() / 5000000;
32
29
  if (result.getByteCount() > 5000000)
33
30
  result = Bitmap.createScaledBitmap(result, result.getWidth() / (int) Math.sqrt(sizeMultiplier), result.getHeight() / (int) Math.sqrt(sizeMultiplier), false);
34
31
  return result;
35
32
  }
36
33
 
37
- static Drawable drawableFromBase64(String base64, Context context) {
38
- ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(Base64.decode(base64.getBytes(), Base64.DEFAULT));
39
- return Drawable.createFromResourceStream(context.getResources(), null, byteArrayInputStream, null);
34
+ static BitmapDrawable drawableFromBase64(String base64, Context context)
35
+ {
36
+ byte[] decodedByte = Base64.decode(base64, 0);
37
+ Bitmap bitmap = BitmapFactory.decodeByteArray(decodedByte, 0, decodedByte.length);
38
+ float density = context.getResources().getDisplayMetrics().density;
39
+ int width = (int)(bitmap.getWidth()*density);
40
+ int height = (int)(bitmap.getHeight()*density);
41
+ return new BitmapDrawable(context.getResources(), Bitmap.createScaledBitmap(bitmap, width, height, false));
40
42
  }
41
43
 
42
44
  static Bitmap bitmapFromDrawable(Drawable drawable) {
@@ -132,4 +134,11 @@ class Helpers {
132
134
  result.add(jsonArray.optString(i));
133
135
  return result;
134
136
  }
137
+
138
+ static String[] stringArrayFromJson(JSONArray jsonArray) {
139
+ String[] result = new String[jsonArray.length()];
140
+ for (int i = 0; i < jsonArray.length(); i++)
141
+ result[i] = jsonArray.optString(i);
142
+ return result;
143
+ }
135
144
  }