@authme/identity-verification 2.7.4 → 2.8.0

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/index.cjs CHANGED
@@ -7,6 +7,7 @@ require('core-js/modules/web.dom-collections.iterator.js');
7
7
  require('core-js/modules/es.object.assign.js');
8
8
  require('core-js/modules/es.array.includes.js');
9
9
  require('core-js/modules/es.string.includes.js');
10
+ require('core-js/modules/es.promise.js');
10
11
  var core = require('@authme/core');
11
12
  var engine = require('@authme/engine');
12
13
  var idRecognition = require('@authme/id-recognition');
@@ -16,7 +17,6 @@ require('core-js/modules/es.regexp.to-string.js');
16
17
  var liveness = require('@authme/liveness');
17
18
  require('core-js/modules/es.parse-float.js');
18
19
  require('core-js/modules/es.number.to-fixed.js');
19
- require('core-js/modules/es.promise.js');
20
20
  require('core-js/modules/es.symbol.description.js');
21
21
  var lottie = require('lottie-web');
22
22
  require('core-js/modules/es.array.reduce.js');
@@ -82,7 +82,8 @@ const defaultIdentityVerificationConfig = {
82
82
  apiBaseUrl: '/',
83
83
  scriptPath: '/assets/',
84
84
  dataTransferMethod: 'binary',
85
- OCRIdcardResultFormat: 'default'
85
+ OCRIdcardResultFormat: 'default',
86
+ customParameters: ''
86
87
  };
87
88
  const defaultExtraDocumentConfig = {
88
89
  active: true,
@@ -25451,6 +25452,25 @@ const countdownTimer = (time, doSomething) => {
25451
25452
  end: getStatus
25452
25453
  };
25453
25454
  };
25455
+ const blobToBase64 = image => __awaiter(void 0, void 0, void 0, function* () {
25456
+ return new Promise((resolve, reject) => {
25457
+ // Use FileReader to convert Blob to base64
25458
+ const reader = new FileReader();
25459
+ reader.onloadend = function () {
25460
+ if (reader.result) {
25461
+ // Strip off the data URL prefix to get just the base64-encoded bytes
25462
+ const base64String = reader.result.split(',')[1];
25463
+ resolve(base64String);
25464
+ } else {
25465
+ reject(new Error('Failed to convert Blob to base64'));
25466
+ }
25467
+ };
25468
+ reader.onerror = function (error) {
25469
+ reject(error);
25470
+ };
25471
+ reader.readAsDataURL(image);
25472
+ });
25473
+ });
25454
25474
 
25455
25475
  const translateService = core.getTranslateInstance();
25456
25476
  // TODO 處理參數
@@ -27430,13 +27450,28 @@ class LivenessModule {
27430
27450
  const frameList = [];
27431
27451
  const resultList = [];
27432
27452
  let id = '';
27453
+ let pubKey = '';
27454
+ let shouldEncrypt = false;
27455
+ const encryptDataBase64 = data => __awaiter(this, void 0, void 0, function* () {
27456
+ const dataString = JSON.stringify(data);
27457
+ const encoder = new TextEncoder();
27458
+ const uint8Array = encoder.encode(dataString);
27459
+ // TODO check encrypt function
27460
+ const resultEncrypt = yield this.fasService.encryptBlob(uint8Array, pubKey);
27461
+ return resultEncrypt;
27462
+ });
27433
27463
  try {
27434
27464
  const result = yield rxjs.firstValueFrom(startLiveness({
27435
27465
  init: () => __awaiter(this, void 0, void 0, function* () {
27466
+ var _a;
27436
27467
  const resp = yield liveness.LivenessAPI.IdentityVerification.init(true, config.passive, config.compareCustomerClientId);
27437
27468
  id = resp.id;
27438
- if (resp.parameters.pubKey) {
27439
- yield this.fasService.setPublicKeyForJson(resp.parameters.pubKey);
27469
+ pubKey = resp.parameters.pubKey;
27470
+ shouldEncrypt = (_a = resp.shouldEncrypt) !== null && _a !== void 0 ? _a : shouldEncrypt;
27471
+ if (!shouldEncrypt) {
27472
+ yield this.fasService.setPublicKeyForJson(pubKey);
27473
+ } else {
27474
+ yield this.fasService.setPublicKeyForJson('');
27440
27475
  }
27441
27476
  yield this.fasService.init();
27442
27477
  const params = yield this.fasService.getParams();
@@ -27474,10 +27509,10 @@ class LivenessModule {
27474
27509
  return params;
27475
27510
  }),
27476
27511
  onFrame: (data, base64) => __awaiter(this, void 0, void 0, function* () {
27477
- var _a;
27512
+ var _b;
27478
27513
  const result = yield this.fasService.recognition(data);
27479
27514
  if (this.canvas) {
27480
- const debugData = yield (_a = this.fasService) === null || _a === void 0 ? void 0 : _a.getDebugImageData(data);
27515
+ const debugData = yield (_b = this.fasService) === null || _b === void 0 ? void 0 : _b.getDebugImageData(data);
27481
27516
  const ctx = this.canvas.getContext('2d');
27482
27517
  this.canvas.width = frameWidth;
27483
27518
  this.canvas.height = frameHeight;
@@ -27515,13 +27550,13 @@ class LivenessModule {
27515
27550
  const meta = yield this.fasService.getReport();
27516
27551
  yield SendRequestWithRetry$2(() => this.postResult(id, frameList, resultList, meta, {
27517
27552
  uploadFullFrame: config.uploadFullFrame
27518
- }));
27553
+ }, shouldEncrypt, encryptDataBase64));
27519
27554
  const result = yield this.getResult(id);
27520
27555
  return result.isPass;
27521
27556
  }),
27522
27557
  onDestroy: () => __awaiter(this, void 0, void 0, function* () {
27523
- var _b;
27524
- yield (_b = this.fasService) === null || _b === void 0 ? void 0 : _b.destroy();
27558
+ var _c;
27559
+ yield (_c = this.fasService) === null || _c === void 0 ? void 0 : _c.destroy();
27525
27560
  }),
27526
27561
  getNormalizedROI: () => __awaiter(this, void 0, void 0, function* () {
27527
27562
  return yield this.fasService.getNormalizedFaceROI();
@@ -27560,7 +27595,7 @@ class LivenessModule {
27560
27595
  }
27561
27596
  });
27562
27597
  }
27563
- postResult(id, frameList, resultList, meta, options = {}) {
27598
+ postResult(id, frameList, resultList, meta, options = {}, shouldEncrypt, encryptDataBase64) {
27564
27599
  return __awaiter(this, void 0, void 0, function* () {
27565
27600
  let uploadTarget = [];
27566
27601
  // 1. iIsKeyFrame Image
@@ -27583,31 +27618,66 @@ class LivenessModule {
27583
27618
  id,
27584
27619
  index: x.index,
27585
27620
  data: x.data
27586
- })).map(body => this.engine.getConfig().dataTransferMethod === 'base64' ? liveness.LivenessAPI.IdentityVerification.uploadFrame(body) : liveness.LivenessAPI.IdentityVerification.uploadFrameFile(body)));
27587
- return liveness.LivenessAPI.IdentityVerification.uploadMeta({
27621
+ })).map(body => __awaiter(this, void 0, void 0, function* () {
27622
+ var _a;
27623
+ // this.engine.getConfig().dataTransferMethod === 'base64'
27624
+ // ? LivenessAPI.IdentityVerification.uploadFrame(body)
27625
+ // : LivenessAPI.IdentityVerification.uploadFrameFile(body)
27626
+ if (shouldEncrypt) {
27627
+ body.data = (_a = body === null || body === void 0 ? void 0 : body.data) === null || _a === void 0 ? void 0 : _a.split('base64,')[1];
27628
+ return liveness.LivenessAPI.IdentityVerification.uploadFrame({
27629
+ id: body.id,
27630
+ encryptedBase64String: yield encryptDataBase64(body)
27631
+ });
27632
+ } else {
27633
+ return liveness.LivenessAPI.IdentityVerification.uploadFrameFile(body);
27634
+ }
27635
+ })));
27636
+ const postData = {
27588
27637
  id,
27589
27638
  data: meta
27590
- });
27639
+ };
27640
+ if (shouldEncrypt) {
27641
+ postData.data = atob(meta);
27642
+ return liveness.LivenessAPI.IdentityVerification.uploadMeta({
27643
+ id: id,
27644
+ encryptedBase64String: yield encryptDataBase64(postData)
27645
+ });
27646
+ } else {
27647
+ return liveness.LivenessAPI.IdentityVerification.uploadMeta(postData);
27648
+ }
27649
+ // return LivenessAPI.IdentityVerification.uploadMeta({
27650
+ // id,
27651
+ // data: meta,
27652
+ // });
27591
27653
  });
27592
27654
  }
27655
+
27593
27656
  getResult(id) {
27594
27657
  return __awaiter(this, void 0, void 0, function* () {
27595
- let result = yield liveness.LivenessAPI.IdentityVerification.getResult(id);
27596
- while (result.state === liveness.LivenessResultStatus.UPLOADING) {
27597
- yield util.waitTime(1000);
27658
+ // while (result.state === LivenessResultStatus.UPLOADING) {
27659
+ // await waitTime(1000);
27660
+ // result = await LivenessAPI.IdentityVerification.getResult(id);
27661
+ // }
27662
+ // if (result.state === LivenessResultStatus.VALIDATING) {
27663
+ // return { ...result, isPass: true };
27664
+ // }
27665
+ const retryCount = 2;
27666
+ const loop = retryCount + 1;
27667
+ let result = {};
27668
+ for (let i = loop; i > 0; i--) {
27598
27669
  result = yield liveness.LivenessAPI.IdentityVerification.getResult(id);
27599
- }
27600
- if (result.state === liveness.LivenessResultStatus.VALIDATING) {
27601
- return Object.assign(Object.assign({}, result), {
27602
- isPass: true
27603
- });
27670
+ if (result.state === liveness.LivenessResultStatus.DONE) {
27671
+ return result;
27672
+ }
27673
+ yield util.waitTime(2000);
27604
27674
  }
27605
27675
  return result;
27606
27676
  });
27607
27677
  }
27608
27678
  }
27609
27679
 
27610
- function initFrameView(cardPoints, scanId, faceMode, scanView, cardType, cardTypeConfig, setBorderType, setCardBorderColor, setBorderSuccess) {
27680
+ function initFrameView(cardPoints, scanId, faceMode, scanView, cardType, cardTypeConfig, setBorderType, setCardBorderColor, setBorderSuccess, shouldEncrypt, encryptDataBase64) {
27611
27681
  return __awaiter(this, void 0, void 0, function* () {
27612
27682
  const scanAnimationContainer = document.querySelector('.scan');
27613
27683
  document.querySelector('#authme_frame_border');
@@ -27771,7 +27841,23 @@ function initFrameView(cardPoints, scanId, faceMode, scanView, cardType, cardTyp
27771
27841
  for (let i = 0; i < scanViewSetting.content.length; i++) {
27772
27842
  const contentSetting = scanViewSetting.content[i];
27773
27843
  if (contentSetting.type === 'svg') {
27774
- const imageData = yield idRecognition.initScanDocumentResourceBase64(scanId, contentSetting.content);
27844
+ let imageData;
27845
+ const postData = {
27846
+ scanId: scanId,
27847
+ ResourceId: contentSetting.content
27848
+ };
27849
+ if (shouldEncrypt) {
27850
+ imageData = yield idRecognition.initScanDocumentResourceBase64({
27851
+ id: scanId,
27852
+ encryptedBase64String: yield encryptDataBase64(postData)
27853
+ });
27854
+ } else {
27855
+ imageData = yield idRecognition.initScanDocumentResourceBase64(postData);
27856
+ }
27857
+ // const imageData = await initScanDocumentResourceBase64(
27858
+ // scanId,
27859
+ // contentSetting.content
27860
+ // );
27775
27861
  frameImage(faceMode, i, imageData.data, contentSetting.color, contentSetting.opacity);
27776
27862
  }
27777
27863
  if (contentSetting.type === 'text') {
@@ -27816,6 +27902,7 @@ class MRZModule {
27816
27902
  let latestTField = null;
27817
27903
  const virtualCanvas = document.createElement('canvas');
27818
27904
  const docInfos = {};
27905
+ let shouldEncrypt = false;
27819
27906
  const encryptImageBase64 = blob => __awaiter(this, void 0, void 0, function* () {
27820
27907
  const imageArrayBuffer = yield blobToArrayBuffer(blob);
27821
27908
  const uint8Array = new Uint8Array(imageArrayBuffer);
@@ -27830,17 +27917,25 @@ class MRZModule {
27830
27917
  reader.readAsArrayBuffer(blob);
27831
27918
  });
27832
27919
  });
27920
+ const encryptDataBase64 = data => __awaiter(this, void 0, void 0, function* () {
27921
+ const dataString = JSON.stringify(data);
27922
+ const encoder = new TextEncoder();
27923
+ const uint8Array = encoder.encode(dataString);
27924
+ const resultEncrypt = yield this.mrzService.encryptBlob(uint8Array, pubKey);
27925
+ return resultEncrypt;
27926
+ });
27833
27927
  try {
27834
27928
  return yield rxjs.firstValueFrom(startOCR({
27835
27929
  ocrConfig: config,
27836
27930
  init: (width, height) => __awaiter(this, void 0, void 0, function* () {
27837
- var _a, _b;
27931
+ var _a, _b, _c;
27838
27932
  frameWidth = width;
27839
27933
  frameHeight = height;
27840
- const resp = yield SendRequestWithRetry$1(() => idRecognition.init(config.type, config.country, config.needConfirm, config.cardTypes));
27934
+ const resp = yield SendRequestWithRetry$1(() => idRecognition.initScan(config.type, config.country, config.needConfirm, config.cardTypes));
27935
+ shouldEncrypt = (_a = resp.shouldEncrypt) !== null && _a !== void 0 ? _a : shouldEncrypt;
27841
27936
  pubKey = resp.parameters.pubKey;
27842
27937
  scanId = resp.scanId;
27843
- uploadFullFrame = (_b = (_a = resp.parameters.fraud) === null || _a === void 0 ? void 0 : _a.collectAllFrames) !== null && _b !== void 0 ? _b : config.uploadFullFrame;
27938
+ uploadFullFrame = (_c = (_b = resp.parameters.fraud) === null || _b === void 0 ? void 0 : _b.collectAllFrames) !== null && _c !== void 0 ? _c : config.uploadFullFrame;
27844
27939
  if (resp.parameters.pubKey) {
27845
27940
  this.engine.setPublicKeyForJson(pubKey);
27846
27941
  }
@@ -27859,7 +27954,20 @@ class MRZModule {
27859
27954
  docInfos[type].ocrImg = null;
27860
27955
  docInfos[type].ocrOriginImg = null;
27861
27956
  } else {
27862
- const resp = yield SendRequestWithRetry$1(() => idRecognition.initScanDocument(scanId, cardType));
27957
+ const resp = yield SendRequestWithRetry$1(() => __awaiter(this, void 0, void 0, function* () {
27958
+ const postData = {
27959
+ scanId: scanId,
27960
+ cardType: cardType
27961
+ };
27962
+ if (shouldEncrypt) {
27963
+ return idRecognition.initScanDocument({
27964
+ id: scanId,
27965
+ encryptedBase64String: yield encryptDataBase64(postData)
27966
+ });
27967
+ } else {
27968
+ return idRecognition.initScanDocument(postData);
27969
+ }
27970
+ }));
27863
27971
  if (docInfos[type]) {
27864
27972
  docInfos[type].docId = resp.scanDocumentId;
27865
27973
  } else {
@@ -27872,17 +27980,17 @@ class MRZModule {
27872
27980
  };
27873
27981
  }
27874
27982
  if (resp.scanView) {
27875
- initFrameView(points, scanId, faceMode, resp.scanView, cardType, '', setBorderType, setCardBorderColor, setBorderSuccess);
27983
+ initFrameView(points, scanId, faceMode, resp.scanView, cardType, '', setBorderType, setCardBorderColor, setBorderSuccess, shouldEncrypt, encryptDataBase64);
27876
27984
  }
27877
27985
  }
27878
27986
  return true;
27879
27987
  }),
27880
27988
  acceptTypes,
27881
27989
  recognition: data => __awaiter(this, void 0, void 0, function* () {
27882
- var _c;
27990
+ var _d;
27883
27991
  const mrzResult = yield this.mrzService.recognition(data);
27884
27992
  if (this.canvas) {
27885
- const debugData = yield (_c = this.mrzService) === null || _c === void 0 ? void 0 : _c.getDebugImageData(data);
27993
+ const debugData = yield (_d = this.mrzService) === null || _d === void 0 ? void 0 : _d.getDebugImageData(data);
27886
27994
  const ctx = this.canvas.getContext('2d');
27887
27995
  this.canvas.width = frameWidth;
27888
27996
  this.canvas.height = frameHeight;
@@ -27925,8 +28033,34 @@ class MRZModule {
27925
28033
  const image = util.UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas);
27926
28034
  const requestImg = yield encryptImageBase64(image);
27927
28035
  // downloadImage(image, `${frameIndex}-${docInfos[type as EAuthMeCardClass].docId}-${new Date().getTime().toString()}.jpg`)
27928
- util.backgroundRequest(() => idRecognition.uploadFrameBase64(docInfos[idRecognition.EAuthMeCardClass.Passport].docId, requestImg, frameIndex++));
28036
+ util.backgroundRequest(() => __awaiter(this, void 0, void 0, function* () {
28037
+ const postData = {
28038
+ scanDocumentId: docInfos[idRecognition.EAuthMeCardClass.Passport].docId,
28039
+ image: requestImg,
28040
+ type: idRecognition.ResourceImageType.Recognition,
28041
+ info: {
28042
+ report: undefined,
28043
+ index: frameIndex++
28044
+ }
28045
+ };
28046
+ if (shouldEncrypt) {
28047
+ postData.image = yield blobToBase64(image);
28048
+ return idRecognition.uploadFrameBase64({
28049
+ id: scanId,
28050
+ encryptedBase64String: yield encryptDataBase64(postData)
28051
+ });
28052
+ } else {
28053
+ return idRecognition.uploadFrameBase64(postData);
28054
+ }
28055
+ })
28056
+ // uploadFrameBase64(
28057
+ // docInfos[EAuthMeCardClass.Passport].docId,
28058
+ // requestImg,
28059
+ // frameIndex++
28060
+ // )
28061
+ );
27929
28062
  }
28063
+
27930
28064
  const tField = latestTField;
27931
28065
  if (!tField) {
27932
28066
  return mrzResult;
@@ -27942,8 +28076,57 @@ class MRZModule {
27942
28076
  docInfos[option.type].docId = '';
27943
28077
  const requestImg = yield encryptImageBase64(docInfos[option.type].ocrOriginImg);
27944
28078
  const report = yield this.mrzService.getReport();
27945
- yield SendRequestWithRetry$1(() => idRecognition.uploadFrameBase64(docId, requestImg, frameIndex++, idRecognition.ResourceImageType.Recognition, report));
27946
- yield SendRequestWithRetry$1(() => idRecognition.finishScanDocument(docId, latestTField !== null && latestTField !== void 0 ? latestTField : {}, docInfos[option.type].fraudResult));
28079
+ yield SendRequestWithRetry$1(() => __awaiter(this, void 0, void 0, function* () {
28080
+ const postData = {
28081
+ scanDocumentId: docId,
28082
+ image: requestImg,
28083
+ type: idRecognition.ResourceImageType.Recognition,
28084
+ info: {
28085
+ report: report,
28086
+ index: frameIndex++
28087
+ }
28088
+ };
28089
+ if (shouldEncrypt) {
28090
+ postData.image = yield blobToBase64(docInfos[option.type].ocrOriginImg);
28091
+ return idRecognition.uploadFrameBase64({
28092
+ id: scanId,
28093
+ encryptedBase64String: yield encryptDataBase64(postData)
28094
+ });
28095
+ } else {
28096
+ return idRecognition.uploadFrameBase64(postData);
28097
+ }
28098
+ })
28099
+ // uploadFrameBase64(
28100
+ // docId,
28101
+ // requestImg,
28102
+ // frameIndex++,
28103
+ // ResourceImageType.Recognition,
28104
+ // report
28105
+ // )
28106
+ );
28107
+
28108
+ yield SendRequestWithRetry$1(() => __awaiter(this, void 0, void 0, function* () {
28109
+ const postData = {
28110
+ scanDocumentId: docId,
28111
+ details: latestTField !== null && latestTField !== void 0 ? latestTField : {},
28112
+ fraud: docInfos[option.type].fraudResult
28113
+ };
28114
+ if (shouldEncrypt) {
28115
+ return idRecognition.finishScanDocument({
28116
+ id: scanId,
28117
+ encryptedBase64String: yield encryptDataBase64(postData)
28118
+ });
28119
+ } else {
28120
+ return idRecognition.finishScanDocument(postData);
28121
+ }
28122
+ })
28123
+ // finishScanDocument(
28124
+ // docId,
28125
+ // latestTField ?? {},
28126
+ // docInfos[option.type].fraudResult
28127
+ // )
28128
+ );
28129
+
27947
28130
  return true;
27948
28131
  } else {
27949
28132
  return false;
@@ -27958,14 +28141,14 @@ class MRZModule {
27958
28141
  throw 'MRZ Fraud Not Supported.';
27959
28142
  }),
27960
28143
  setFrameSize: (width, height) => __awaiter(this, void 0, void 0, function* () {
27961
- var _d;
28144
+ var _e;
27962
28145
  frameWidth = width;
27963
28146
  frameHeight = height;
27964
- yield (_d = this.mrzService) === null || _d === void 0 ? void 0 : _d.setFrameSize(width, height);
28147
+ yield (_e = this.mrzService) === null || _e === void 0 ? void 0 : _e.setFrameSize(width, height);
27965
28148
  }),
27966
28149
  onSuccess: () => __awaiter(this, void 0, void 0, function* () {
27967
- var _e;
27968
- (_e = this.mrzService) === null || _e === void 0 ? void 0 : _e.destroy();
28150
+ var _f;
28151
+ (_f = this.mrzService) === null || _f === void 0 ? void 0 : _f.destroy();
27969
28152
  yield util.waitTime(1000);
27970
28153
  return {
27971
28154
  scanId: scanId,
@@ -27973,8 +28156,8 @@ class MRZModule {
27973
28156
  };
27974
28157
  }),
27975
28158
  onDestroy: () => __awaiter(this, void 0, void 0, function* () {
27976
- var _f;
27977
- yield (_f = this.mrzService) === null || _f === void 0 ? void 0 : _f.destroy();
28159
+ var _g;
28160
+ yield (_g = this.mrzService) === null || _g === void 0 ? void 0 : _g.destroy();
27978
28161
  }),
27979
28162
  getAntiFraudStageList: () => []
27980
28163
  }));
@@ -28005,6 +28188,25 @@ function unionMerge(a, b) {
28005
28188
  }
28006
28189
  return result;
28007
28190
  }
28191
+ // function blobToBase64(image: Blob): Promise<string> {
28192
+ // return new Promise((resolve, reject) => {
28193
+ // // Use FileReader to convert Blob to base64
28194
+ // const reader = new FileReader();
28195
+ // reader.onloadend = function () {
28196
+ // if (reader.result) {
28197
+ // // Strip off the data URL prefix to get just the base64-encoded bytes
28198
+ // const base64String = (reader.result as string).split(',')[1];
28199
+ // resolve(base64String);
28200
+ // } else {
28201
+ // reject(new Error('Failed to convert Blob to base64'));
28202
+ // }
28203
+ // };
28204
+ // reader.onerror = function (error) {
28205
+ // reject(error);
28206
+ // };
28207
+ // reader.readAsDataURL(image);
28208
+ // });
28209
+ // }
28008
28210
  function SendRequestWithRetry(promiseFactory, options = {}) {
28009
28211
  return util.retryPromiseWithCondition(promiseFactory, e => __awaiter(this, void 0, void 0, function* () {
28010
28212
  var _a, _b, _c;
@@ -28182,6 +28384,7 @@ class OCRModule {
28182
28384
  let frameIndex = 0;
28183
28385
  let uploadFullFrame = false;
28184
28386
  let fraudTimeout = DEFAULT_ANTI_FRAUD_TIMEOUT;
28387
+ let shouldEncrypt = false;
28185
28388
  const {
28186
28389
  getDebugLogsLength,
28187
28390
  modifyDeubgLog,
@@ -28214,6 +28417,14 @@ class OCRModule {
28214
28417
  reader.readAsArrayBuffer(blob);
28215
28418
  });
28216
28419
  });
28420
+ const encryptDataBase64 = data => __awaiter(this, void 0, void 0, function* () {
28421
+ const dataString = JSON.stringify(data);
28422
+ const encoder = new TextEncoder();
28423
+ const uint8Array = encoder.encode(dataString);
28424
+ const resultEncrypt = yield this.ocrService.encryptBlob(uint8Array, pubKey);
28425
+ return resultEncrypt;
28426
+ });
28427
+ util.Storage.setItem('encryptDataBase64', encryptDataBase64);
28217
28428
  try {
28218
28429
  const translateService = core.getTranslateInstance();
28219
28430
  const eventNameWrong$ = new rxjs.Subject();
@@ -28221,11 +28432,11 @@ class OCRModule {
28221
28432
  cardTypeConfigs: cardTypeConfigs,
28222
28433
  ocrConfig: config,
28223
28434
  init: (width, height) => __awaiter(this, void 0, void 0, function* () {
28224
- var _a, _b, _c, _d;
28435
+ var _a, _b, _c, _d, _e;
28225
28436
  frameWidth = width;
28226
28437
  frameHeight = height;
28227
28438
  const resp = yield SendRequestWithRetry(() => {
28228
- return idRecognition.init(config.type, config.country, config.needConfirm, config.cardTypes);
28439
+ return idRecognition.initScan(config.type, config.country, config.needConfirm, config.cardTypes);
28229
28440
  }, {
28230
28441
  onErrorHandler(e) {
28231
28442
  var _a, _b, _c;
@@ -28251,11 +28462,15 @@ class OCRModule {
28251
28462
  }
28252
28463
  });
28253
28464
  scanId = resp.scanId;
28465
+ shouldEncrypt = (_a = resp.shouldEncrypt) !== null && _a !== void 0 ? _a : shouldEncrypt;
28466
+ util.Storage.setItem('shouldEncrypt', shouldEncrypt);
28254
28467
  pubKey = resp.parameters.pubKey;
28255
- uploadFullFrame = (_b = (_a = resp.parameters.fraud) === null || _a === void 0 ? void 0 : _a.collectAllFrames) !== null && _b !== void 0 ? _b : config.uploadFullFrame;
28256
- fraudTimeout = (_d = (_c = resp.parameters.fraud) === null || _c === void 0 ? void 0 : _c.totalTimeout) !== null && _d !== void 0 ? _d : DEFAULT_ANTI_FRAUD_TIMEOUT;
28257
- if (resp.parameters.pubKey) {
28468
+ uploadFullFrame = (_c = (_b = resp.parameters.fraud) === null || _b === void 0 ? void 0 : _b.collectAllFrames) !== null && _c !== void 0 ? _c : config.uploadFullFrame;
28469
+ fraudTimeout = (_e = (_d = resp.parameters.fraud) === null || _d === void 0 ? void 0 : _d.totalTimeout) !== null && _e !== void 0 ? _e : DEFAULT_ANTI_FRAUD_TIMEOUT;
28470
+ if (!shouldEncrypt) {
28258
28471
  this.engine.setPublicKeyForJson(pubKey);
28472
+ } else {
28473
+ this.engine.setPublicKeyForJson('');
28259
28474
  }
28260
28475
  if (config.type === idRecognition.IdRecognitionCardType.IDCard && config.needAntiFraud) {
28261
28476
  yield this.antiFraudInstance.init();
@@ -28300,7 +28515,20 @@ class OCRModule {
28300
28515
  docInfos[cardType].ocrImg = null;
28301
28516
  docInfos[cardType].ocrOriginImg = null;
28302
28517
  } else {
28303
- const resp = yield SendRequestWithRetry(() => idRecognition.initScanDocument(scanId, cardType));
28518
+ const resp = yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
28519
+ const postData = {
28520
+ scanId: scanId,
28521
+ cardType: cardType
28522
+ };
28523
+ if (shouldEncrypt) {
28524
+ return idRecognition.initScanDocument({
28525
+ id: scanId,
28526
+ encryptedBase64String: yield encryptDataBase64(postData)
28527
+ });
28528
+ } else {
28529
+ return idRecognition.initScanDocument(postData);
28530
+ }
28531
+ }));
28304
28532
  if (docInfos[cardType]) {
28305
28533
  docInfos[cardType].docId = resp.scanDocumentId;
28306
28534
  } else {
@@ -28370,7 +28598,23 @@ class OCRModule {
28370
28598
  for (let i = 0; i < scanViewSetting.content.length; i++) {
28371
28599
  const contentSetting = scanViewSetting.content[i];
28372
28600
  if (contentSetting.type === 'svg') {
28373
- const imageData = yield idRecognition.initScanDocumentResourceBase64(scanId, contentSetting.content);
28601
+ let imageData;
28602
+ const postData = {
28603
+ scanId: scanId,
28604
+ ResourceId: contentSetting.content
28605
+ };
28606
+ if (shouldEncrypt) {
28607
+ imageData = yield idRecognition.initScanDocumentResourceBase64({
28608
+ id: scanId,
28609
+ encryptedBase64String: yield encryptDataBase64(postData)
28610
+ });
28611
+ } else {
28612
+ imageData = yield idRecognition.initScanDocumentResourceBase64(postData);
28613
+ }
28614
+ // const imageData = await initScanDocumentResourceBase64(
28615
+ // scanId,
28616
+ // contentSetting.content
28617
+ // );
28374
28618
  frameImage(faceMode, i, imageData.data, contentSetting.color, contentSetting.opacity);
28375
28619
  }
28376
28620
  if (contentSetting.type === 'text') {
@@ -28410,7 +28654,20 @@ class OCRModule {
28410
28654
  docInfos[cardType].ocrImg = null;
28411
28655
  docInfos[cardType].ocrOriginImg = null;
28412
28656
  } else {
28413
- const resp = yield SendRequestWithRetry(() => idRecognition.initScanDocument(scanId, cardType));
28657
+ const resp = yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
28658
+ const postData = {
28659
+ scanId: scanId,
28660
+ cardType: cardType
28661
+ };
28662
+ if (shouldEncrypt) {
28663
+ return idRecognition.initScanDocument({
28664
+ id: scanId,
28665
+ encryptedBase64String: yield encryptDataBase64(postData)
28666
+ });
28667
+ } else {
28668
+ return idRecognition.initScanDocument(postData);
28669
+ }
28670
+ }));
28414
28671
  if (docInfos[cardType]) {
28415
28672
  docInfos[cardType].docId = resp.scanDocumentId;
28416
28673
  } else {
@@ -28534,7 +28791,23 @@ class OCRModule {
28534
28791
  for (let i = 0; i < scanViewSetting.content.length; i++) {
28535
28792
  const contentSetting = scanViewSetting.content[i];
28536
28793
  if (contentSetting.type === 'svg') {
28537
- const imageData = yield idRecognition.initScanDocumentResourceBase64(scanId, contentSetting.content);
28794
+ let imageData;
28795
+ const postData = {
28796
+ scanId: scanId,
28797
+ ResourceId: contentSetting.content
28798
+ };
28799
+ if (shouldEncrypt) {
28800
+ imageData = yield idRecognition.initScanDocumentResourceBase64({
28801
+ id: scanId,
28802
+ encryptedBase64String: yield encryptDataBase64(postData)
28803
+ });
28804
+ } else {
28805
+ imageData = yield idRecognition.initScanDocumentResourceBase64(postData);
28806
+ }
28807
+ // const imageData = await initScanDocumentResourceBase64(
28808
+ // scanId,
28809
+ // contentSetting.content
28810
+ // );
28538
28811
  frameImage(faceMode, i, imageData.data, contentSetting.color, contentSetting.opacity);
28539
28812
  }
28540
28813
  if (contentSetting.type === 'text') {
@@ -28547,11 +28820,11 @@ class OCRModule {
28547
28820
  };
28548
28821
  }),
28549
28822
  onThicknessFrame: (data, _base64, cardType, type) => __awaiter(this, void 0, void 0, function* () {
28550
- var _e, _f;
28823
+ var _f, _g;
28551
28824
  nextDebugRound(type);
28552
28825
  const antiFraudRecogitionResult = yield functionLogging(() => __awaiter(this, void 0, void 0, function* () {
28553
- var _g;
28554
- return yield (_g = this.antiFraudInstance) === null || _g === void 0 ? void 0 : _g.recognition(data);
28826
+ var _h;
28827
+ return yield (_h = this.antiFraudInstance) === null || _h === void 0 ? void 0 : _h.recognition(data);
28555
28828
  }), {
28556
28829
  runFunction: util.RUN_FUNCTION_NAME.ANTI_FARUD_RECOGNITION,
28557
28830
  isAntiFraud: true
@@ -28560,7 +28833,7 @@ class OCRModule {
28560
28833
  return antiFraudRecogitionResult;
28561
28834
  }
28562
28835
  if (this.canvas) {
28563
- const debugData = yield (_e = this.antiFraudInstance) === null || _e === void 0 ? void 0 : _e.getDebugImageData(data);
28836
+ const debugData = yield (_f = this.antiFraudInstance) === null || _f === void 0 ? void 0 : _f.getDebugImageData(data);
28564
28837
  const ctx = this.canvas.getContext('2d');
28565
28838
  this.canvas.width = frameWidth;
28566
28839
  this.canvas.height = frameHeight;
@@ -28572,7 +28845,7 @@ class OCRModule {
28572
28845
  saveDebugImage({
28573
28846
  data,
28574
28847
  type,
28575
- getDebugImageData: (_f = this.antiFraudInstance) === null || _f === void 0 ? void 0 : _f.getDebugImageData.bind(this.antiFraudInstance),
28848
+ getDebugImageData: (_g = this.antiFraudInstance) === null || _g === void 0 ? void 0 : _g.getDebugImageData.bind(this.antiFraudInstance),
28576
28849
  result,
28577
28850
  width: frameWidth,
28578
28851
  height: frameHeight
@@ -28594,10 +28867,27 @@ class OCRModule {
28594
28867
  isAntiFraud: true
28595
28868
  });
28596
28869
  frameIndex++;
28597
- util.backgroundRequest(() => idRecognition.uploadFrameBase64(docId, requestImg, frameIndex, idRecognition.ResourceImageType.Recognition // upload fill frame 時先使用 recognition 當成一個過渡方案, 目前後端會對這個處理存成 original image, 後續會再調整
28598
- ));
28870
+ util.backgroundRequest(() => __awaiter(this, void 0, void 0, function* () {
28871
+ const postData = {
28872
+ scanDocumentId: docId,
28873
+ image: requestImg,
28874
+ type: idRecognition.ResourceImageType.Recognition,
28875
+ info: {
28876
+ report: undefined,
28877
+ index: frameIndex
28878
+ }
28879
+ };
28880
+ if (shouldEncrypt) {
28881
+ postData.image = yield blobToBase64(fraudOriginImg);
28882
+ return idRecognition.uploadFrameBase64({
28883
+ id: scanId,
28884
+ encryptedBase64String: yield encryptDataBase64(postData)
28885
+ });
28886
+ } else {
28887
+ return idRecognition.uploadFrameBase64(postData);
28888
+ }
28889
+ }));
28599
28890
  }
28600
-
28601
28891
  return thicknessResult;
28602
28892
  }),
28603
28893
  confirmThickness: (imageData, cardType) => __awaiter(this, void 0, void 0, function* () {
@@ -28605,8 +28895,53 @@ class OCRModule {
28605
28895
  const docId = docInfos[cardType].docId;
28606
28896
  const requestImg = yield encryptImageBase64(imageData);
28607
28897
  try {
28608
- yield SendRequestWithRetry(() => idRecognition.uploadFrameBase64(docId, requestImg, frameIndex, idRecognition.ResourceImageType.Attach, undefined));
28609
- yield SendRequestWithRetry(() => idRecognition.finishScanDocument(docId, {}, null));
28898
+ yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
28899
+ const postData = {
28900
+ scanDocumentId: docId,
28901
+ image: requestImg,
28902
+ type: idRecognition.ResourceImageType.Attach,
28903
+ info: {
28904
+ report: undefined,
28905
+ index: frameIndex
28906
+ }
28907
+ };
28908
+ if (shouldEncrypt) {
28909
+ postData.image = yield blobToBase64(imageData);
28910
+ return idRecognition.uploadFrameBase64({
28911
+ id: scanId,
28912
+ encryptedBase64String: yield encryptDataBase64(postData)
28913
+ });
28914
+ } else {
28915
+ return idRecognition.uploadFrameBase64(postData);
28916
+ }
28917
+ })
28918
+ // uploadFrameBase64(
28919
+ // docId,
28920
+ // requestImg,
28921
+ // frameIndex,
28922
+ // ResourceImageType.Attach,
28923
+ // undefined
28924
+ // )
28925
+ );
28926
+
28927
+ yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
28928
+ const postData = {
28929
+ scanDocumentId: docId,
28930
+ details: {},
28931
+ fraud: null
28932
+ };
28933
+ if (shouldEncrypt) {
28934
+ return idRecognition.finishScanDocument({
28935
+ id: scanId,
28936
+ encryptedBase64String: yield encryptDataBase64(postData)
28937
+ });
28938
+ } else {
28939
+ return idRecognition.finishScanDocument(postData);
28940
+ }
28941
+ })
28942
+ // finishScanDocument(docId, {}, null)
28943
+ );
28944
+
28610
28945
  return true;
28611
28946
  } catch (error) {
28612
28947
  console.error('confirmThickness:', error);
@@ -28664,7 +28999,33 @@ class OCRModule {
28664
28999
  const requestImg = yield encryptImageBase64(image);
28665
29000
  // downloadImage(image, `${frameIndex}-${docInfos[type as EAuthMeCardClass].docId}-${new Date().getTime().toString()}.jpg`)
28666
29001
  frameIndex++;
28667
- util.backgroundRequest(() => idRecognition.uploadFrameBase64(docInfos[cardType !== null && cardType !== void 0 ? cardType : ''].docId, requestImg, frameIndex));
29002
+ util.backgroundRequest(() => __awaiter(this, void 0, void 0, function* () {
29003
+ const postData = {
29004
+ scanDocumentId: docInfos[cardType !== null && cardType !== void 0 ? cardType : ''].docId,
29005
+ image: requestImg,
29006
+ type: idRecognition.ResourceImageType.Recognition,
29007
+ info: {
29008
+ report: undefined,
29009
+ index: frameIndex
29010
+ }
29011
+ };
29012
+ if (shouldEncrypt) {
29013
+ postData.image = yield blobToBase64(image);
29014
+ return idRecognition.uploadFrameBase64({
29015
+ id: scanId,
29016
+ encryptedBase64String: yield encryptDataBase64(postData)
29017
+ });
29018
+ } else {
29019
+ return idRecognition.uploadFrameBase64(postData);
29020
+ }
29021
+ })
29022
+ // uploadFrameBase64(
29023
+ // docInfos[cardType ?? ''].docId,
29024
+ // requestImg,
29025
+ // frameIndex
29026
+ // )
29027
+ );
29028
+
28668
29029
  pushNewDebugImage(ocrOriginImg, {
28669
29030
  result: result,
28670
29031
  status: 'recognition',
@@ -28706,18 +29067,93 @@ class OCRModule {
28706
29067
  report: report
28707
29068
  });
28708
29069
  frameIndex++;
28709
- yield SendRequestWithRetry(() => idRecognition.uploadFrameBase64(docId, requestImg, frameIndex, idRecognition.ResourceImageType.Recognition, report));
29070
+ yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
29071
+ const postData = {
29072
+ scanDocumentId: docId,
29073
+ image: requestImg,
29074
+ type: idRecognition.ResourceImageType.Recognition,
29075
+ info: {
29076
+ report: report,
29077
+ index: frameIndex
29078
+ }
29079
+ };
29080
+ if (shouldEncrypt) {
29081
+ postData.image = yield blobToBase64(ocrOriginImg);
29082
+ return idRecognition.uploadFrameBase64({
29083
+ id: scanId,
29084
+ encryptedBase64String: yield encryptDataBase64(postData)
29085
+ });
29086
+ } else {
29087
+ return idRecognition.uploadFrameBase64(postData);
29088
+ }
29089
+ })
29090
+ // uploadFrameBase64(
29091
+ // docId,
29092
+ // requestImg,
29093
+ // frameIndex,
29094
+ // ResourceImageType.Recognition,
29095
+ // report
29096
+ // )
29097
+ );
29098
+
28710
29099
  frameIndex = 0;
28711
29100
  try {
28712
29101
  const ocrImg = option.imageData ? option.imageData : docInfos[option.cardType].ocrImg;
28713
29102
  const _requestImg = yield encryptImageBase64(ocrImg);
28714
- const resp = yield SendRequestWithRetry(() => idRecognition.recognitionEncrypt(docId, _requestImg, report, idRecognition.RecognitionFileType.FlatImage));
29103
+ const resp = yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
29104
+ const postData = {
29105
+ scanDocumentId: docId,
29106
+ image: _requestImg,
29107
+ fileType: idRecognition.RecognitionFileType.FlatImage,
29108
+ info: {
29109
+ report: report
29110
+ }
29111
+ };
29112
+ if (shouldEncrypt) {
29113
+ postData.image = yield blobToBase64(ocrImg);
29114
+ return idRecognition.recognizeBase64({
29115
+ id: scanId,
29116
+ encryptedBase64String: yield encryptDataBase64(postData)
29117
+ });
29118
+ } else {
29119
+ return idRecognition.recognizeBase64(postData);
29120
+ }
29121
+ })
29122
+ // recognizeBase64(
29123
+ // docId,
29124
+ // requestImg,
29125
+ // report,
29126
+ // RecognitionFileType.FlatImage
29127
+ // )
29128
+ );
29129
+
28715
29130
  if (resp.retry) {
28716
29131
  yield util.asyncShowPopup(translateService.translate('sdk.verify.error.blurRetake.title'), translateService.translate('sdk.verify.error.blurRetake.content'), true);
28717
29132
  throw 'recognition failed';
28718
29133
  }
28719
29134
  result = unionMerge(result, resp && resp.details || {});
28720
- yield SendRequestWithRetry(() => idRecognition.finishScanDocument(docId, resp.details, needFraudOption ? this.fraudResult : null));
29135
+ yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
29136
+ const postData = {
29137
+ scanDocumentId: docId,
29138
+ details: resp.details,
29139
+ fraud: needFraudOption ? this.fraudResult : null
29140
+ };
29141
+ if (shouldEncrypt) {
29142
+ return idRecognition.finishScanDocument({
29143
+ id: scanId,
29144
+ encryptedBase64String: yield encryptDataBase64(postData)
29145
+ });
29146
+ } else {
29147
+ return idRecognition.finishScanDocument(postData);
29148
+ }
29149
+ })
29150
+ // finishScanDocument(
29151
+ // docId,
29152
+ // resp.details,
29153
+ // needFraudOption ? this.fraudResult : null
29154
+ // )
29155
+ );
29156
+
28721
29157
  delete docInfos[option.cardType];
28722
29158
  return true;
28723
29159
  } catch (error) {
@@ -28748,7 +29184,35 @@ class OCRModule {
28748
29184
  report: report
28749
29185
  });
28750
29186
  frameIndex++;
28751
- SendRequestWithRetry(() => idRecognition.uploadFrameBase64(docId, requestImg, frameIndex, idRecognition.ResourceImageType.Recognition, report));
29187
+ SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
29188
+ const postData = {
29189
+ scanDocumentId: docId,
29190
+ image: requestImg,
29191
+ type: idRecognition.ResourceImageType.Recognition,
29192
+ info: {
29193
+ report: report,
29194
+ index: frameIndex
29195
+ }
29196
+ };
29197
+ if (shouldEncrypt) {
29198
+ postData.image = yield blobToBase64(ocrOriginImg);
29199
+ return idRecognition.uploadFrameBase64({
29200
+ id: scanId,
29201
+ encryptedBase64String: yield encryptDataBase64(postData)
29202
+ });
29203
+ } else {
29204
+ return idRecognition.uploadFrameBase64(postData);
29205
+ }
29206
+ })
29207
+ // uploadFrameBase64(
29208
+ // docId,
29209
+ // requestImg,
29210
+ // frameIndex,
29211
+ // ResourceImageType.Recognition,
29212
+ // report
29213
+ // )
29214
+ );
29215
+
28752
29216
  frameIndex = 0;
28753
29217
  return true;
28754
29218
  } else {
@@ -28776,7 +29240,20 @@ class OCRModule {
28776
29240
  fraudOriginImg: null,
28777
29241
  fraudResult: false
28778
29242
  };
28779
- const resp = yield SendRequestWithRetry(() => idRecognition.initScanDocument(scanId, idRecognition.twoWayAuthmeCardClassMap.toServer(twnidCardFront)));
29243
+ const resp = yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
29244
+ const postData = {
29245
+ scanId: scanId,
29246
+ cardType: idRecognition.twoWayAuthmeCardClassMap.toServer(twnidCardFront)
29247
+ };
29248
+ if (shouldEncrypt) {
29249
+ return idRecognition.initScanDocument({
29250
+ id: scanId,
29251
+ encryptedBase64String: yield encryptDataBase64(postData)
29252
+ });
29253
+ } else {
29254
+ return idRecognition.initScanDocument(postData);
29255
+ }
29256
+ }));
28780
29257
  if (docInfos[twnidCardFront]) {
28781
29258
  docInfos[twnidCardFront].docId = resp.scanDocumentId;
28782
29259
  } else {
@@ -28802,12 +29279,12 @@ class OCRModule {
28802
29279
  return true;
28803
29280
  }),
28804
29281
  onAntiFraudFrame: data => __awaiter(this, void 0, void 0, function* () {
28805
- var _h, _j;
29282
+ var _j, _k;
28806
29283
  const type = engine.EAuthMeCardClass.TWN_IDCard_Front;
28807
29284
  nextDebugRound(type);
28808
29285
  const antiFraudRecogitionResult = yield functionLogging(() => __awaiter(this, void 0, void 0, function* () {
28809
- var _k;
28810
- return yield (_k = this.antiFraudInstance) === null || _k === void 0 ? void 0 : _k.recognition(data);
29286
+ var _l;
29287
+ return yield (_l = this.antiFraudInstance) === null || _l === void 0 ? void 0 : _l.recognition(data);
28811
29288
  }), {
28812
29289
  runFunction: util.RUN_FUNCTION_NAME.ANTI_FARUD_RECOGNITION,
28813
29290
  isAntiFraud: true
@@ -28816,7 +29293,7 @@ class OCRModule {
28816
29293
  return antiFraudRecogitionResult;
28817
29294
  }
28818
29295
  if (this.canvas) {
28819
- const debugData = yield (_h = this.antiFraudInstance) === null || _h === void 0 ? void 0 : _h.getDebugImageData(data);
29296
+ const debugData = yield (_j = this.antiFraudInstance) === null || _j === void 0 ? void 0 : _j.getDebugImageData(data);
28820
29297
  const ctx = this.canvas.getContext('2d');
28821
29298
  this.canvas.width = frameWidth;
28822
29299
  this.canvas.height = frameHeight;
@@ -28828,7 +29305,7 @@ class OCRModule {
28828
29305
  saveDebugImage({
28829
29306
  data,
28830
29307
  type,
28831
- getDebugImageData: (_j = this.antiFraudInstance) === null || _j === void 0 ? void 0 : _j.getDebugImageData.bind(this.antiFraudInstance),
29308
+ getDebugImageData: (_k = this.antiFraudInstance) === null || _k === void 0 ? void 0 : _k.getDebugImageData.bind(this.antiFraudInstance),
28832
29309
  result,
28833
29310
  width: frameWidth,
28834
29311
  height: frameHeight
@@ -28850,7 +29327,35 @@ class OCRModule {
28850
29327
  isAntiFraud: true
28851
29328
  });
28852
29329
  frameIndex++;
28853
- yield SendRequestWithRetry(() => idRecognition.uploadFrameBase64(docId, requestImg, frameIndex, idRecognition.ResourceImageType.Fraud, report));
29330
+ yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
29331
+ const postData = {
29332
+ scanDocumentId: docId,
29333
+ image: requestImg,
29334
+ type: idRecognition.ResourceImageType.Fraud,
29335
+ info: {
29336
+ report: report,
29337
+ index: frameIndex
29338
+ }
29339
+ };
29340
+ if (shouldEncrypt) {
29341
+ postData.image = yield blobToBase64(ocrImg);
29342
+ return idRecognition.uploadFrameBase64({
29343
+ id: scanId,
29344
+ encryptedBase64String: yield encryptDataBase64(postData)
29345
+ });
29346
+ } else {
29347
+ return idRecognition.uploadFrameBase64(postData);
29348
+ }
29349
+ })
29350
+ // uploadFrameBase64(
29351
+ // docId,
29352
+ // requestImg,
29353
+ // frameIndex,
29354
+ // ResourceImageType.Fraud,
29355
+ // report
29356
+ // )
29357
+ );
29358
+
28854
29359
  frameIndex = 0;
28855
29360
  yield this.antiFraudInstance.destroy();
28856
29361
  } else if (uploadFullFrame) {
@@ -28864,35 +29369,62 @@ class OCRModule {
28864
29369
  isAntiFraud: true
28865
29370
  });
28866
29371
  frameIndex++;
28867
- util.backgroundRequest(() => idRecognition.uploadFrameBase64(docId, requestImg, frameIndex, idRecognition.ResourceImageType.Fraud));
29372
+ util.backgroundRequest(() => __awaiter(this, void 0, void 0, function* () {
29373
+ const postData = {
29374
+ scanDocumentId: docId,
29375
+ image: requestImg,
29376
+ type: idRecognition.ResourceImageType.Fraud,
29377
+ info: {
29378
+ report: undefined,
29379
+ index: frameIndex
29380
+ }
29381
+ };
29382
+ if (shouldEncrypt) {
29383
+ postData.image = yield blobToBase64(fraudOriginImg);
29384
+ return idRecognition.uploadFrameBase64({
29385
+ id: scanId,
29386
+ encryptedBase64String: yield encryptDataBase64(postData)
29387
+ });
29388
+ } else {
29389
+ return idRecognition.uploadFrameBase64(postData);
29390
+ }
29391
+ })
29392
+ // uploadFrameBase64(
29393
+ // docId,
29394
+ // requestImg,
29395
+ // frameIndex,
29396
+ // ResourceImageType.Fraud
29397
+ // )
29398
+ );
28868
29399
  }
29400
+
28869
29401
  return antiFraudRecogitionResult;
28870
29402
  }),
28871
29403
  getAntiFraudStageList: () => {
28872
29404
  return antiFraudStageList;
28873
29405
  },
28874
29406
  setFrameSize: (width, height, points) => __awaiter(this, void 0, void 0, function* () {
28875
- var _l, _m, _o, _p;
29407
+ var _m, _o, _p, _q;
28876
29408
  frameWidth = width;
28877
29409
  frameHeight = height;
28878
- yield (_l = this.ocrService) === null || _l === void 0 ? void 0 : _l.setFrameSize(width, height);
28879
- yield (_m = this.antiFraudInstance) === null || _m === void 0 ? void 0 : _m.setFrameSize(width, height);
29410
+ yield (_m = this.ocrService) === null || _m === void 0 ? void 0 : _m.setFrameSize(width, height);
29411
+ yield (_o = this.antiFraudInstance) === null || _o === void 0 ? void 0 : _o.setFrameSize(width, height);
28880
29412
  if (config.type === idRecognition.IdRecognitionCardType.ResidentCard) {
28881
29413
  // workaround: resident card need MRZ, refactor later.
28882
- yield (_o = this.residentCardMrzService) === null || _o === void 0 ? void 0 : _o.setFrameSize(width, height);
29414
+ yield (_p = this.residentCardMrzService) === null || _p === void 0 ? void 0 : _p.setFrameSize(width, height);
28883
29415
  }
28884
29416
  if (points) {
28885
- yield (_p = this.ocrService) === null || _p === void 0 ? void 0 : _p.setMaskPosition(points.map(([x, y]) => [Number(x.toFixed(2)), Number(y.toFixed(2))]));
29417
+ yield (_q = this.ocrService) === null || _q === void 0 ? void 0 : _q.setMaskPosition(points.map(([x, y]) => [Number(x.toFixed(2)), Number(y.toFixed(2))]));
28886
29418
  }
28887
29419
  }),
28888
29420
  onSuccess: () => __awaiter(this, void 0, void 0, function* () {
28889
- var _q, _r, _s;
29421
+ var _r, _s, _t;
28890
29422
  durationTime.end();
28891
29423
  const ocrIdcardResultFormat = util.Storage.getItem(util.STORAGE_KEY['OCR_IDCARD_RESULT_FORMAT']);
28892
- (_q = this.antiFraudInstance) === null || _q === void 0 ? void 0 : _q.destroy();
28893
- (_r = this.ocrService) === null || _r === void 0 ? void 0 : _r.destroy();
29424
+ (_r = this.antiFraudInstance) === null || _r === void 0 ? void 0 : _r.destroy();
29425
+ (_s = this.ocrService) === null || _s === void 0 ? void 0 : _s.destroy();
28894
29426
  // workaround: resident card need MRZ, refactor later.
28895
- (_s = this.residentCardMrzService) === null || _s === void 0 ? void 0 : _s.destroy();
29427
+ (_t = this.residentCardMrzService) === null || _t === void 0 ? void 0 : _t.destroy();
28896
29428
  if (config.type === idRecognition.IdRecognitionCardType.IDCard && ocrIdcardResultFormat === 'splitDateAndAddress') {
28897
29429
  result = util.splitResult(result);
28898
29430
  }
@@ -28903,10 +29435,10 @@ class OCRModule {
28903
29435
  };
28904
29436
  }),
28905
29437
  onDestroy: () => __awaiter(this, void 0, void 0, function* () {
28906
- var _t, _u;
29438
+ var _u, _v;
28907
29439
  durationTime.end();
28908
- yield (_t = this.ocrService) === null || _t === void 0 ? void 0 : _t.destroy();
28909
- yield (_u = this.antiFraudInstance) === null || _u === void 0 ? void 0 : _u.destroy();
29440
+ yield (_u = this.ocrService) === null || _u === void 0 ? void 0 : _u.destroy();
29441
+ yield (_v = this.antiFraudInstance) === null || _v === void 0 ? void 0 : _v.destroy();
28910
29442
  }),
28911
29443
  getCardMatchROI: () => __awaiter(this, void 0, void 0, function* () {
28912
29444
  return yield this.antiFraudInstance.getCardMatchROI();
@@ -28998,7 +29530,7 @@ function renderCardTypeAndCountryConfig(config) {
28998
29530
  <label class="country-select-label">${translate('sdk.home.selectCountry')}</label>
28999
29531
  <div class="country-select-dropdown">
29000
29532
  <div class="country-select-dropdown-frame">
29001
- <div class="country-select-dropdown-text">${translate(`sdk.home.selectCountry.${idRecognition.CountryCode.TWN}`)}</div>
29533
+ <div class="country-select-dropdown-text">${translate(`sdk.home.selectCountry.${config.defaultCountry}`)}</div>
29002
29534
  <div class="country-select-dropdown-icon"></div>
29003
29535
  </div>
29004
29536
  <div class="dropdown-country-list"></div>
@@ -29185,6 +29717,7 @@ class AuthmeIdentityVerification extends engine.AuthmeFunctionModule {
29185
29717
  // 在尚未執行實際的 method 的時候,並不會佔用時間初始化。
29186
29718
  util.Storage.setItem(util.STORAGE_KEY.LOADING_LOTTIE, loadingLottie);
29187
29719
  util.Storage.setItem(util.STORAGE_KEY.OCR_IDCARD_RESULT_FORMAT, config.OCRIdcardResultFormat);
29720
+ util.Storage.setItem('customParameters', config.customParameters);
29188
29721
  (_b = this.engine) !== null && _b !== void 0 ? _b : this.engine = new engine.MlEngine(engineConfig);
29189
29722
  yield this.engine.setConfig(engineConfig);
29190
29723
  (_c = this.ocrModule) !== null && _c !== void 0 ? _c : this.ocrModule = new OCRModule(this.engine, canvas);
@@ -29285,10 +29818,24 @@ class AuthmeIdentityVerification extends engine.AuthmeFunctionModule {
29285
29818
  confirmOCRResult(data) {
29286
29819
  return __awaiter(this, void 0, void 0, function* () {
29287
29820
  const ocrIdcardResultFormat = util.Storage.getItem(util.STORAGE_KEY['OCR_IDCARD_RESULT_FORMAT']);
29821
+ const shouldEncrypt = util.Storage.getItem('shouldEncrypt');
29822
+ const encryptDataBase64 = util.Storage.getItem('encryptDataBase64');
29288
29823
  if (ocrIdcardResultFormat === 'splitDateAndAddress') {
29289
29824
  data.details = util.combineResult(data.details);
29290
29825
  }
29291
- yield idRecognition.confirmScan(data.scanId, data.details);
29826
+ const postData = {
29827
+ scanId: data.scanId,
29828
+ details: data.details
29829
+ };
29830
+ if (shouldEncrypt) {
29831
+ yield idRecognition.confirmScan({
29832
+ id: data.scanId,
29833
+ encryptedBase64String: yield encryptDataBase64(postData)
29834
+ });
29835
+ } else {
29836
+ yield idRecognition.confirmScan(postData);
29837
+ }
29838
+ // await confirmScan(data.scanId, data.details);
29292
29839
  return true;
29293
29840
  });
29294
29841
  }
@@ -29328,11 +29875,67 @@ class AuthmeIdentityVerification extends engine.AuthmeFunctionModule {
29328
29875
  return (_a = this.tearDownPromise) !== null && _a !== void 0 ? _a : this.tearDownPromise = this._tearDown();
29329
29876
  });
29330
29877
  }
29878
+ cleanAllModel() {
29879
+ var _a;
29880
+ return __awaiter(this, void 0, void 0, function* () {
29881
+ engine.AuthmeEngineModuleBase.reset_MODEL_CACHE();
29882
+ return (_a = this.tearDownPromise) !== null && _a !== void 0 ? _a : this.tearDownPromise = this._tearDown();
29883
+ });
29884
+ }
29885
+ getCustomerState(arg) {
29886
+ return __awaiter(this, void 0, void 0, function* () {
29887
+ const paramsDefault = {
29888
+ waitingTime: 3,
29889
+ retryTimes: 2
29890
+ };
29891
+ if (arg === null || arg === void 0 ? void 0 : arg.retryTimes) {
29892
+ if (typeof arg.retryTimes !== 'number') {
29893
+ console.error('retryTimes should be a number');
29894
+ return;
29895
+ }
29896
+ if (arg.retryTimes <= 0) {
29897
+ console.error('retryTimes should be greater than 0');
29898
+ return;
29899
+ }
29900
+ }
29901
+ if (arg === null || arg === void 0 ? void 0 : arg.waitingTime) {
29902
+ if (typeof arg.waitingTime !== 'number') {
29903
+ console.error('waitingTime should be a number');
29904
+ return;
29905
+ }
29906
+ if (arg.waitingTime <= 0) {
29907
+ console.error('waitingTime should be greater than 0');
29908
+ return;
29909
+ }
29910
+ }
29911
+ const params = Object.assign(Object.assign({}, paramsDefault), arg);
29912
+ params.retryTimes++;
29913
+ let stop = false;
29914
+ for (let i = 0; i < params.retryTimes; i++) {
29915
+ if (!stop) {
29916
+ const res = yield core.getCustomerState();
29917
+ if (res.state === 'Approved') {
29918
+ stop = true;
29919
+ return res;
29920
+ } else if (res.state === 'Rejected') {
29921
+ stop = true;
29922
+ return res;
29923
+ } else {
29924
+ yield new Promise(resolve => setTimeout(resolve, params.waitingTime * 1000));
29925
+ }
29926
+ if (i === params.retryTimes - 1) {
29927
+ return res;
29928
+ }
29929
+ }
29930
+ }
29931
+ // return getCustomerState();
29932
+ });
29933
+ }
29331
29934
  }
29332
29935
 
29333
29936
  var name = "authme/sdk";
29334
- var version$1 = "2.7.4";
29335
- var date = "2024-12-04T02:44:31+0000";
29937
+ var version$1 = "2.8.0";
29938
+ var date = "2025-01-13T09:38:31+0000";
29336
29939
  var packageInfo = {
29337
29940
  name: name,
29338
29941
  version: version$1,