@authme/identity-verification 2.7.4 → 2.8.1-patch.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/index.js CHANGED
@@ -3,16 +3,16 @@ import 'core-js/modules/web.dom-collections.iterator.js';
3
3
  import 'core-js/modules/es.object.assign.js';
4
4
  import 'core-js/modules/es.array.includes.js';
5
5
  import 'core-js/modules/es.string.includes.js';
6
- import { getTranslateInstance, EventListenerService, TrackingEvent, generateStatus, StatusDescription, StatusView, StatusAction, AuthmeError, ErrorCode, Feature, StatusEvent, setRequestLoggingFunc, setAccessToken } from '@authme/core';
7
- import { EAuthMeFASServiceStatus, EAuthMeIDCardAntiFraudStage as EAuthMeIDCardAntiFraudStage$1, EAuthMeCardClass as EAuthMeCardClass$1, AuthmeFunctionModule, MlEngine, EngineModule, EAuthMeEngineReturnCode } from '@authme/engine';
8
- import { IdRecognitionCardType, CountryCode, EAuthMeCardClass, EAuthMeIDCardAntiFraudStatus, EAuthMeIDCardAntiFraudStage, thicknessDefaultConfig, mapCardtypeToAuthmeClass, cardTypeTitle, cardTypeConfirmTitle, cardTypeHeader, getRecognitionColumnOrder, EAuthMeCardOCRStatus, EAuthMeMRZServiceStatus, saveExtraDoc, initScanDocumentResourceBase64, MRZService, init, initScanDocument, uploadFrameBase64, ResourceImageType, finishScanDocument, CardOCR, IdCardAntiFraudService, recognitionEncrypt, RecognitionFileType, twoWayAuthmeCardClassMap, getCardSubTypes, getCardTypes, confirmScan } from '@authme/id-recognition';
9
- import { getCssVariable, RGBToLottieColor, colorToRGB, Icon, useState, clearCanvas, getImageData, isMobile, hidePopup, showPopup, waitTime, TIME_UNIT, AuthmeError as AuthmeError$1, ErrorCode as ErrorCode$1, requestCamera, showElement, asyncOnLineShowErrorMessage, getCanvasSize, startSpinner, stopSpinner, showErrorMessage, hideElement, dataURItoBlob, checkOnlineStatus, UintArrayToBlob, isIphone14proOrProMax, cropByRatio, asyncShowErrorMessage, switchCamera, asyncShowPopup, retryPromiseWithCondition, hideErrorMessage, backgroundRequest, debugTools, showErrorMessageEventName, RUN_FUNCTION_NAME, Storage, STORAGE_KEY, splitResult, combineResult, startLoadingSDK, stopLoadingSDK } from '@authme/util';
6
+ import 'core-js/modules/es.promise.js';
7
+ import { getTranslateInstance, EventListenerService, TrackingEvent, generateStatus, StatusDescription, StatusView, StatusAction, AuthmeError, ErrorCode, Feature, StatusEvent, setRequestLoggingFunc, setAccessToken, getCustomerState } from '@authme/core';
8
+ import { EAuthMeFASServiceStatus, EAuthMeIDCardAntiFraudStage as EAuthMeIDCardAntiFraudStage$1, EAuthMeCardClass as EAuthMeCardClass$1, AuthmeFunctionModule, MlEngine, EngineModule, EAuthMeEngineReturnCode, AuthmeEngineModuleBase } from '@authme/engine';
9
+ import { IdRecognitionCardType, CountryCode, EAuthMeCardClass, EAuthMeIDCardAntiFraudStatus, EAuthMeIDCardAntiFraudStage, thicknessDefaultConfig, mapCardtypeToAuthmeClass, getRecognitionColumnOrder, cardTypeTitle, cardTypeConfirmTitle, cardTypeHeader, EAuthMeCardOCRStatus, EAuthMeMRZServiceStatus, saveExtraDoc, initScanDocumentResourceBase64, MRZService, initScan, initScanDocument, ResourceImageType, uploadFrameBase64, finishScanDocument, CardOCR, IdCardAntiFraudService, RecognitionFileType, recognizeBase64, twoWayAuthmeCardClassMap, getCardSubTypes, getCardTypes, confirmScan } from '@authme/id-recognition';
10
+ import { getCssVariable, RGBToLottieColor, colorToRGB, Icon, useState, clearCanvas, getImageData, isMobile, hidePopup, showPopup, waitTime, TIME_UNIT, AuthmeError as AuthmeError$1, ErrorCode as ErrorCode$1, requestCamera, showElement, asyncOnLineShowErrorMessage, getCanvasSize, startSpinner, stopSpinner, showErrorMessage, hideElement, dataURItoBlob, checkOnlineStatus, Storage, UintArrayToBlob, isIphone14proOrProMax, cropByRatio, asyncShowErrorMessage, switchCamera, asyncShowPopup, retryPromiseWithCondition, hideErrorMessage, backgroundRequest, debugTools, showErrorMessageEventName, RUN_FUNCTION_NAME, STORAGE_KEY, splitResult, combineResult, startLoadingSDK, stopLoadingSDK } from '@authme/util';
10
11
  import { mergeMap, animationFrames, filter, tap, map, from, catchError, EMPTY, of, merge, fromEvent, concatAll, takeUntil, Subject, defer, switchMap, throttleTime, take, concatMap, throwError, finalize, Observable, interval, mapTo, firstValueFrom, shareReplay, switchMapTo, takeWhile as takeWhile$1, race } from 'rxjs';
11
12
  import 'core-js/modules/es.regexp.to-string.js';
12
13
  import { FasRecognitionResult, EAuthMeFASServiceStage, FasService, LivenessAPI, EAuthMeMouthStatus, LivenessResultStatus } from '@authme/liveness';
13
14
  import 'core-js/modules/es.parse-float.js';
14
15
  import 'core-js/modules/es.number.to-fixed.js';
15
- import 'core-js/modules/es.promise.js';
16
16
  import 'core-js/modules/es.symbol.description.js';
17
17
  import lottie from 'lottie-web';
18
18
  import 'core-js/modules/es.array.reduce.js';
@@ -74,7 +74,8 @@ const defaultIdentityVerificationConfig = {
74
74
  apiBaseUrl: '/',
75
75
  scriptPath: '/assets/',
76
76
  dataTransferMethod: 'binary',
77
- OCRIdcardResultFormat: 'default'
77
+ OCRIdcardResultFormat: 'default',
78
+ customParameters: ''
78
79
  };
79
80
  const defaultExtraDocumentConfig = {
80
81
  active: true,
@@ -120,7 +121,9 @@ const defaultIdRecognitionConfig = {
120
121
  antiFraudIMetalTagValidCountTh: false,
121
122
  cardTypes: [],
122
123
  cardTypeConfigs: [],
123
- captureTimeout: -1
124
+ captureTimeout: -1,
125
+ resultImageFormat: 'jpg',
126
+ confirmPageEnabled: true
124
127
  };
125
128
 
126
129
  function setCorrectViewHeight() {
@@ -24468,9 +24471,14 @@ function renderConfirmUI({
24468
24471
  document.body.appendChild(confirmContainerElem);
24469
24472
  return new Promise((resolve, reject) => {
24470
24473
  confirmContainerElem.querySelector('.confirm-btn').addEventListener('click', e => {
24471
- const modifiedDetails = Object.fromEntries(Object.keys(items.details).map(column => {
24472
- var _a, _b;
24473
- return [column, (_b = (_a = confirmContainerElem.querySelector(`[name="${column}"]`)) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : ''];
24474
+ const modifiedDetails = Object.fromEntries(Object.entries(items.details).map(([column, originalValue]) => {
24475
+ var _a;
24476
+ const inputElement = confirmContainerElem.querySelector(`[name="${column}"]`);
24477
+ const inputValue = (_a = inputElement === null || inputElement === void 0 ? void 0 : inputElement.value) !== null && _a !== void 0 ? _a : '';
24478
+ return [column, {
24479
+ isModified: inputValue !== originalValue,
24480
+ value: inputValue
24481
+ }];
24474
24482
  }));
24475
24483
  sendStatusAction$1(StatusAction.Confirm);
24476
24484
  confirmContainerElem.remove();
@@ -25443,6 +25451,72 @@ const countdownTimer = (time, doSomething) => {
25443
25451
  end: getStatus
25444
25452
  };
25445
25453
  };
25454
+ const blobToBase64 = image => __awaiter(void 0, void 0, void 0, function* () {
25455
+ return new Promise((resolve, reject) => {
25456
+ // Use FileReader to convert Blob to base64
25457
+ const reader = new FileReader();
25458
+ reader.onloadend = function () {
25459
+ if (reader.result) {
25460
+ // Strip off the data URL prefix to get just the base64-encoded bytes
25461
+ const base64String = reader.result.split(',')[1];
25462
+ resolve(base64String);
25463
+ } else {
25464
+ reject(new Error('Failed to convert Blob to base64'));
25465
+ }
25466
+ };
25467
+ reader.onerror = function (error) {
25468
+ reject(error);
25469
+ };
25470
+ reader.readAsDataURL(image);
25471
+ });
25472
+ });
25473
+ const blobToImageBase64 = image => __awaiter(void 0, void 0, void 0, function* () {
25474
+ return new Promise((resolve, reject) => {
25475
+ const reader = new FileReader();
25476
+ reader.readAsDataURL(image);
25477
+ reader.onloadend = () => resolve(reader.result);
25478
+ reader.onerror = reject;
25479
+ });
25480
+ });
25481
+ const result2ModifiedData = (result, modifiedResult) => {
25482
+ if (!modifiedResult) {
25483
+ const obj = {};
25484
+ for (const key in result) {
25485
+ obj[key] = {
25486
+ isModified: false,
25487
+ value: result[key]
25488
+ };
25489
+ }
25490
+ return obj;
25491
+ }
25492
+ const modifiedData = {};
25493
+ Object.keys(result).forEach(key => {
25494
+ var _a;
25495
+ if ((_a = modifiedResult[key]) === null || _a === void 0 ? void 0 : _a.isModified) {
25496
+ modifiedData[key] = {
25497
+ isModified: true,
25498
+ value: modifiedResult[key].value
25499
+ };
25500
+ } else {
25501
+ modifiedData[key] = {
25502
+ isModified: false,
25503
+ value: result[key]
25504
+ };
25505
+ }
25506
+ });
25507
+ return modifiedData;
25508
+ };
25509
+ const modifiedData2Result = modifiedResult => {
25510
+ const result = {};
25511
+ if (!modifiedResult) {
25512
+ console.error('modifiedData2Result: modifiedResult is empty');
25513
+ return;
25514
+ }
25515
+ Object.keys(modifiedResult).forEach(key => {
25516
+ result[key] = modifiedResult[key].value;
25517
+ });
25518
+ return result;
25519
+ };
25446
25520
 
25447
25521
  const translateService = getTranslateInstance();
25448
25522
  // TODO 處理參數
@@ -26227,7 +26301,7 @@ function startOCR(config) {
26227
26301
  if (toastManualCapture) {
26228
26302
  toastManualCapture.clear();
26229
26303
  }
26230
- return from(type === EAuthMeCardClass.Passport && config.ocrConfig.disablePassportConfirm ? of(false) : checkConfirmImageManual(canvasSizeInfo)).pipe(switchMap(needRetry => {
26304
+ return from(type === EAuthMeCardClass.Passport && config.ocrConfig.disablePassportConfirm || !config.ocrConfig.confirmPageEnabled ? of(false) : checkConfirmImageManual(canvasSizeInfo)).pipe(switchMap(needRetry => {
26231
26305
  startSpinner(translateService.translate('sdk.general.uploading'));
26232
26306
  if (needRetry) {
26233
26307
  hideElement(confirmImageContainer);
@@ -26277,7 +26351,7 @@ function startOCR(config) {
26277
26351
  })), tap(() => received = true))))));
26278
26352
  };
26279
26353
  const autoCapture = canvasSizeInfo => {
26280
- return of(canvasSizeInfo).pipe(handleOcrSendFrame(canvasSizeInfo, image, video, config.recognition, 30, false, 'jpg', cardType, type), tap(x => applyTextByResult(x.result)), filter(({
26354
+ return of(canvasSizeInfo).pipe(handleOcrSendFrame(canvasSizeInfo, image, video, config.recognition, 30, false, config.ocrConfig.resultImageFormat, cardType, type), tap(x => applyTextByResult(x.result)), filter(({
26281
26355
  result
26282
26356
  }) => result.eStatus === EAuthMeCardOCRStatus.Pass || result.eStatus === EAuthMeMRZServiceStatus.Success), take(1), tap(() => {
26283
26357
  if (countdownCaptureTimer && countdownCaptureTimer.end && !countdownCaptureTimer.end()) {
@@ -26295,7 +26369,7 @@ function startOCR(config) {
26295
26369
  hideElement(scanAnimationContainer);
26296
26370
  }), map(() => resp))), switchMap(({
26297
26371
  result
26298
- }) => from(type === EAuthMeCardClass.Passport && config.ocrConfig.disablePassportConfirm ? of(false) : checkConfirmImage(result.imageData, result.iWidth, result.iHeight)).pipe(switchMap(needRetry => {
26372
+ }) => from(type === EAuthMeCardClass.Passport && config.ocrConfig.disablePassportConfirm || !config.ocrConfig.confirmPageEnabled ? of(false) : checkConfirmImage(result.imageData, result.iWidth, result.iHeight)).pipe(switchMap(needRetry => {
26299
26373
  if (countdownCaptureTimer && countdownCaptureTimer.end) {
26300
26374
  if (needRetry && !countdownCaptureTimer.end()) {
26301
26375
  countdownCaptureTimer = countdownTimer(captureTimeoutTimer, () => {
@@ -26415,7 +26489,8 @@ function startOCR(config) {
26415
26489
  }), switchMap(canvasSizeInfo => from(config.init(canvasSizeInfo.canvasWidth, canvasSizeInfo.canvasHeight)).pipe(tap(x => ocrEngineConfig = x), tap(() => __awaiter(this, void 0, void 0, function* () {
26416
26490
  if (config.ocrConfig.needAntiFraud) return;
26417
26491
  stopSpinner();
26418
- })), tap(() => eventListenerService$1.start()))))).pipe(tap(() => {
26492
+ })), tap(() => eventListenerService$1.start()) // TODO check useless
26493
+ )))).pipe(tap(() => {
26419
26494
  sendStatusAction$1(StatusAction.Uploading);
26420
26495
  hideElement(videoContainer);
26421
26496
  startSpinner(translateService.translate('sdk.general.uploading'));
@@ -26423,36 +26498,41 @@ function startOCR(config) {
26423
26498
  setStatusEvent$1(cardClassResultMapping(config.acceptTypes[config.acceptTypes.length - 1]));
26424
26499
  stopSpinner();
26425
26500
  container.style.display = 'none';
26426
- }), concatMap(result => {
26501
+ }), concatMap(result => __awaiter(this, void 0, void 0, function* () {
26427
26502
  setStatusView(StatusView.Confirm);
26428
- function resultFromConfirmUI() {
26429
- return __awaiter(this, void 0, void 0, function* () {
26430
- if (sdkFlowTimeout) clearTimeout(sdkFlowTimeout);
26431
- return Object.assign(Object.assign({}, result), {
26432
- details: yield renderConfirmUI({
26433
- cardType: config.ocrConfig.type,
26434
- items: {
26435
- columns: Object.keys(result.details).sort((a, b) => {
26436
- const aScore = getRecognitionColumnOrder(a);
26437
- const bScore = getRecognitionColumnOrder(b);
26438
- return aScore - bScore || a.localeCompare(b);
26439
- }),
26440
- details: result.details
26441
- },
26442
- options: {
26443
- headerIcon: config.ocrConfig.icon,
26444
- translate: key => translateService.translate(key)
26445
- }
26446
- })
26447
- });
26503
+ let modifiedData = result2ModifiedData(result.details);
26504
+ if (config.ocrConfig.displayResultPage) {
26505
+ modifiedData = yield renderConfirmUI({
26506
+ cardType: config.ocrConfig.type,
26507
+ items: {
26508
+ columns: Object.keys(result.details).sort((a, b) => {
26509
+ const aScore = getRecognitionColumnOrder(a);
26510
+ const bScore = getRecognitionColumnOrder(b);
26511
+ return aScore - bScore || a.localeCompare(b);
26512
+ }),
26513
+ details: result.details
26514
+ },
26515
+ options: {
26516
+ headerIcon: config.ocrConfig.icon,
26517
+ translate: key => translateService.translate(key)
26518
+ }
26448
26519
  });
26449
26520
  }
26450
26521
  flags.onConfirm = true;
26451
- return config.ocrConfig.displayResultPage ? defer(resultFromConfirmUI) : of(result);
26452
- }), map(x => ({
26453
- isSuccess: true,
26454
- message: '',
26455
- data: x
26522
+ Storage.setItem('scanId', result.scanId);
26523
+ Storage.setItem('data', result.details);
26524
+ Storage.setItem('confirmedData', modifiedData2Result(modifiedData));
26525
+ return {
26526
+ scanId: result.scanId,
26527
+ isSuccess: true,
26528
+ message: '',
26529
+ data: result.details,
26530
+ modifiedData: modifiedData,
26531
+ backCropImage: result.backCropImage,
26532
+ frontCropImage: result.frontCropImage,
26533
+ frontImage: result.frontImage,
26534
+ backImage: result.backImage
26535
+ };
26456
26536
  })), takeUntil(unsubscribe$), finalize(() => {
26457
26537
  sendStatusDescription$1(StatusDescription.Complete);
26458
26538
  stopSpinner();
@@ -26462,7 +26542,7 @@ function startOCR(config) {
26462
26542
  const type = currentType('get', null).type;
26463
26543
  const cardType = currentType('get', null).cardType;
26464
26544
  const ctx = image.getContext('2d');
26465
- const imageData = getImageData(image, ctx, video, canvasSizeInfo, false, 'jpg');
26545
+ const imageData = getImageData(image, ctx, video, canvasSizeInfo, false, config.ocrConfig.resultImageFormat);
26466
26546
  const imageBlob = UintArrayToBlob(canvasSizeInfo.width, canvasSizeInfo.height, imageData.data);
26467
26547
  const cancelResultObj = {
26468
26548
  isSuccess: false,
@@ -27422,13 +27502,28 @@ class LivenessModule {
27422
27502
  const frameList = [];
27423
27503
  const resultList = [];
27424
27504
  let id = '';
27505
+ let pubKey = '';
27506
+ let shouldEncrypt = false;
27507
+ const encryptDataBase64 = data => __awaiter(this, void 0, void 0, function* () {
27508
+ const dataString = JSON.stringify(data);
27509
+ const encoder = new TextEncoder();
27510
+ const uint8Array = encoder.encode(dataString);
27511
+ // TODO check encrypt function
27512
+ const resultEncrypt = yield this.fasService.encryptBlob(uint8Array, pubKey);
27513
+ return resultEncrypt;
27514
+ });
27425
27515
  try {
27426
27516
  const result = yield firstValueFrom(startLiveness({
27427
27517
  init: () => __awaiter(this, void 0, void 0, function* () {
27518
+ var _a;
27428
27519
  const resp = yield LivenessAPI.IdentityVerification.init(true, config.passive, config.compareCustomerClientId);
27429
27520
  id = resp.id;
27430
- if (resp.parameters.pubKey) {
27431
- yield this.fasService.setPublicKeyForJson(resp.parameters.pubKey);
27521
+ pubKey = resp.parameters.pubKey;
27522
+ shouldEncrypt = (_a = resp.shouldEncrypt) !== null && _a !== void 0 ? _a : shouldEncrypt;
27523
+ if (!shouldEncrypt) {
27524
+ yield this.fasService.setPublicKeyForJson(pubKey);
27525
+ } else {
27526
+ yield this.fasService.setPublicKeyForJson('');
27432
27527
  }
27433
27528
  yield this.fasService.init();
27434
27529
  const params = yield this.fasService.getParams();
@@ -27466,10 +27561,10 @@ class LivenessModule {
27466
27561
  return params;
27467
27562
  }),
27468
27563
  onFrame: (data, base64) => __awaiter(this, void 0, void 0, function* () {
27469
- var _a;
27564
+ var _b;
27470
27565
  const result = yield this.fasService.recognition(data);
27471
27566
  if (this.canvas) {
27472
- const debugData = yield (_a = this.fasService) === null || _a === void 0 ? void 0 : _a.getDebugImageData(data);
27567
+ const debugData = yield (_b = this.fasService) === null || _b === void 0 ? void 0 : _b.getDebugImageData(data);
27473
27568
  const ctx = this.canvas.getContext('2d');
27474
27569
  this.canvas.width = frameWidth;
27475
27570
  this.canvas.height = frameHeight;
@@ -27507,13 +27602,13 @@ class LivenessModule {
27507
27602
  const meta = yield this.fasService.getReport();
27508
27603
  yield SendRequestWithRetry$2(() => this.postResult(id, frameList, resultList, meta, {
27509
27604
  uploadFullFrame: config.uploadFullFrame
27510
- }));
27605
+ }, shouldEncrypt, encryptDataBase64));
27511
27606
  const result = yield this.getResult(id);
27512
27607
  return result.isPass;
27513
27608
  }),
27514
27609
  onDestroy: () => __awaiter(this, void 0, void 0, function* () {
27515
- var _b;
27516
- yield (_b = this.fasService) === null || _b === void 0 ? void 0 : _b.destroy();
27610
+ var _c;
27611
+ yield (_c = this.fasService) === null || _c === void 0 ? void 0 : _c.destroy();
27517
27612
  }),
27518
27613
  getNormalizedROI: () => __awaiter(this, void 0, void 0, function* () {
27519
27614
  return yield this.fasService.getNormalizedFaceROI();
@@ -27552,7 +27647,7 @@ class LivenessModule {
27552
27647
  }
27553
27648
  });
27554
27649
  }
27555
- postResult(id, frameList, resultList, meta, options = {}) {
27650
+ postResult(id, frameList, resultList, meta, options = {}, shouldEncrypt, encryptDataBase64) {
27556
27651
  return __awaiter(this, void 0, void 0, function* () {
27557
27652
  let uploadTarget = [];
27558
27653
  // 1. iIsKeyFrame Image
@@ -27575,31 +27670,66 @@ class LivenessModule {
27575
27670
  id,
27576
27671
  index: x.index,
27577
27672
  data: x.data
27578
- })).map(body => this.engine.getConfig().dataTransferMethod === 'base64' ? LivenessAPI.IdentityVerification.uploadFrame(body) : LivenessAPI.IdentityVerification.uploadFrameFile(body)));
27579
- return LivenessAPI.IdentityVerification.uploadMeta({
27673
+ })).map(body => __awaiter(this, void 0, void 0, function* () {
27674
+ var _a;
27675
+ // this.engine.getConfig().dataTransferMethod === 'base64'
27676
+ // ? LivenessAPI.IdentityVerification.uploadFrame(body)
27677
+ // : LivenessAPI.IdentityVerification.uploadFrameFile(body)
27678
+ if (shouldEncrypt) {
27679
+ body.data = (_a = body === null || body === void 0 ? void 0 : body.data) === null || _a === void 0 ? void 0 : _a.split('base64,')[1];
27680
+ return LivenessAPI.IdentityVerification.uploadFrame({
27681
+ id: body.id,
27682
+ encryptedBase64String: yield encryptDataBase64(body)
27683
+ });
27684
+ } else {
27685
+ return LivenessAPI.IdentityVerification.uploadFrameFile(body);
27686
+ }
27687
+ })));
27688
+ const postData = {
27580
27689
  id,
27581
27690
  data: meta
27582
- });
27691
+ };
27692
+ if (shouldEncrypt) {
27693
+ postData.data = atob(meta);
27694
+ return LivenessAPI.IdentityVerification.uploadMeta({
27695
+ id: id,
27696
+ encryptedBase64String: yield encryptDataBase64(postData)
27697
+ });
27698
+ } else {
27699
+ return LivenessAPI.IdentityVerification.uploadMeta(postData);
27700
+ }
27701
+ // return LivenessAPI.IdentityVerification.uploadMeta({
27702
+ // id,
27703
+ // data: meta,
27704
+ // });
27583
27705
  });
27584
27706
  }
27707
+
27585
27708
  getResult(id) {
27586
27709
  return __awaiter(this, void 0, void 0, function* () {
27587
- let result = yield LivenessAPI.IdentityVerification.getResult(id);
27588
- while (result.state === LivenessResultStatus.UPLOADING) {
27589
- yield waitTime(1000);
27710
+ // while (result.state === LivenessResultStatus.UPLOADING) {
27711
+ // await waitTime(1000);
27712
+ // result = await LivenessAPI.IdentityVerification.getResult(id);
27713
+ // }
27714
+ // if (result.state === LivenessResultStatus.VALIDATING) {
27715
+ // return { ...result, isPass: true };
27716
+ // }
27717
+ const retryCount = 2;
27718
+ const loop = retryCount + 1;
27719
+ let result = {};
27720
+ for (let i = loop; i > 0; i--) {
27590
27721
  result = yield LivenessAPI.IdentityVerification.getResult(id);
27591
- }
27592
- if (result.state === LivenessResultStatus.VALIDATING) {
27593
- return Object.assign(Object.assign({}, result), {
27594
- isPass: true
27595
- });
27722
+ if (result.state === LivenessResultStatus.DONE) {
27723
+ return result;
27724
+ }
27725
+ yield waitTime(2000);
27596
27726
  }
27597
27727
  return result;
27598
27728
  });
27599
27729
  }
27600
27730
  }
27601
27731
 
27602
- function initFrameView(cardPoints, scanId, faceMode, scanView, cardType, cardTypeConfig, setBorderType, setCardBorderColor, setBorderSuccess) {
27732
+ function initFrameView(cardPoints, scanId, faceMode, scanView, cardType, cardTypeConfig, setBorderType, setCardBorderColor, setBorderSuccess, shouldEncrypt, encryptDataBase64) {
27603
27733
  return __awaiter(this, void 0, void 0, function* () {
27604
27734
  const scanAnimationContainer = document.querySelector('.scan');
27605
27735
  document.querySelector('#authme_frame_border');
@@ -27763,7 +27893,23 @@ function initFrameView(cardPoints, scanId, faceMode, scanView, cardType, cardTyp
27763
27893
  for (let i = 0; i < scanViewSetting.content.length; i++) {
27764
27894
  const contentSetting = scanViewSetting.content[i];
27765
27895
  if (contentSetting.type === 'svg') {
27766
- const imageData = yield initScanDocumentResourceBase64(scanId, contentSetting.content);
27896
+ let imageData;
27897
+ const postData = {
27898
+ scanId: scanId,
27899
+ ResourceId: contentSetting.content
27900
+ };
27901
+ if (shouldEncrypt) {
27902
+ imageData = yield initScanDocumentResourceBase64({
27903
+ id: scanId,
27904
+ encryptedBase64String: yield encryptDataBase64(postData)
27905
+ });
27906
+ } else {
27907
+ imageData = yield initScanDocumentResourceBase64(postData);
27908
+ }
27909
+ // const imageData = await initScanDocumentResourceBase64(
27910
+ // scanId,
27911
+ // contentSetting.content
27912
+ // );
27767
27913
  frameImage(faceMode, i, imageData.data, contentSetting.color, contentSetting.opacity);
27768
27914
  }
27769
27915
  if (contentSetting.type === 'text') {
@@ -27808,6 +27954,7 @@ class MRZModule {
27808
27954
  let latestTField = null;
27809
27955
  const virtualCanvas = document.createElement('canvas');
27810
27956
  const docInfos = {};
27957
+ let shouldEncrypt = false;
27811
27958
  const encryptImageBase64 = blob => __awaiter(this, void 0, void 0, function* () {
27812
27959
  const imageArrayBuffer = yield blobToArrayBuffer(blob);
27813
27960
  const uint8Array = new Uint8Array(imageArrayBuffer);
@@ -27822,17 +27969,25 @@ class MRZModule {
27822
27969
  reader.readAsArrayBuffer(blob);
27823
27970
  });
27824
27971
  });
27972
+ const encryptDataBase64 = data => __awaiter(this, void 0, void 0, function* () {
27973
+ const dataString = JSON.stringify(data);
27974
+ const encoder = new TextEncoder();
27975
+ const uint8Array = encoder.encode(dataString);
27976
+ const resultEncrypt = yield this.mrzService.encryptBlob(uint8Array, pubKey);
27977
+ return resultEncrypt;
27978
+ });
27825
27979
  try {
27826
27980
  return yield firstValueFrom(startOCR({
27827
27981
  ocrConfig: config,
27828
27982
  init: (width, height) => __awaiter(this, void 0, void 0, function* () {
27829
- var _a, _b;
27983
+ var _a, _b, _c;
27830
27984
  frameWidth = width;
27831
27985
  frameHeight = height;
27832
- const resp = yield SendRequestWithRetry$1(() => init(config.type, config.country, config.needConfirm, config.cardTypes));
27986
+ const resp = yield SendRequestWithRetry$1(() => initScan(config.type, config.country, config.needConfirm, config.cardTypes));
27987
+ shouldEncrypt = (_a = resp.shouldEncrypt) !== null && _a !== void 0 ? _a : shouldEncrypt;
27833
27988
  pubKey = resp.parameters.pubKey;
27834
27989
  scanId = resp.scanId;
27835
- uploadFullFrame = (_b = (_a = resp.parameters.fraud) === null || _a === void 0 ? void 0 : _a.collectAllFrames) !== null && _b !== void 0 ? _b : config.uploadFullFrame;
27990
+ uploadFullFrame = (_c = (_b = resp.parameters.fraud) === null || _b === void 0 ? void 0 : _b.collectAllFrames) !== null && _c !== void 0 ? _c : config.uploadFullFrame;
27836
27991
  if (resp.parameters.pubKey) {
27837
27992
  this.engine.setPublicKeyForJson(pubKey);
27838
27993
  }
@@ -27851,7 +28006,20 @@ class MRZModule {
27851
28006
  docInfos[type].ocrImg = null;
27852
28007
  docInfos[type].ocrOriginImg = null;
27853
28008
  } else {
27854
- const resp = yield SendRequestWithRetry$1(() => initScanDocument(scanId, cardType));
28009
+ const resp = yield SendRequestWithRetry$1(() => __awaiter(this, void 0, void 0, function* () {
28010
+ const postData = {
28011
+ scanId: scanId,
28012
+ cardType: cardType
28013
+ };
28014
+ if (shouldEncrypt) {
28015
+ return initScanDocument({
28016
+ id: scanId,
28017
+ encryptedBase64String: yield encryptDataBase64(postData)
28018
+ });
28019
+ } else {
28020
+ return initScanDocument(postData);
28021
+ }
28022
+ }));
27855
28023
  if (docInfos[type]) {
27856
28024
  docInfos[type].docId = resp.scanDocumentId;
27857
28025
  } else {
@@ -27864,17 +28032,17 @@ class MRZModule {
27864
28032
  };
27865
28033
  }
27866
28034
  if (resp.scanView) {
27867
- initFrameView(points, scanId, faceMode, resp.scanView, cardType, '', setBorderType, setCardBorderColor, setBorderSuccess);
28035
+ initFrameView(points, scanId, faceMode, resp.scanView, cardType, '', setBorderType, setCardBorderColor, setBorderSuccess, shouldEncrypt, encryptDataBase64);
27868
28036
  }
27869
28037
  }
27870
28038
  return true;
27871
28039
  }),
27872
28040
  acceptTypes,
27873
28041
  recognition: data => __awaiter(this, void 0, void 0, function* () {
27874
- var _c;
28042
+ var _d;
27875
28043
  const mrzResult = yield this.mrzService.recognition(data);
27876
28044
  if (this.canvas) {
27877
- const debugData = yield (_c = this.mrzService) === null || _c === void 0 ? void 0 : _c.getDebugImageData(data);
28045
+ const debugData = yield (_d = this.mrzService) === null || _d === void 0 ? void 0 : _d.getDebugImageData(data);
27878
28046
  const ctx = this.canvas.getContext('2d');
27879
28047
  this.canvas.width = frameWidth;
27880
28048
  this.canvas.height = frameHeight;
@@ -27917,8 +28085,34 @@ class MRZModule {
27917
28085
  const image = UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas);
27918
28086
  const requestImg = yield encryptImageBase64(image);
27919
28087
  // downloadImage(image, `${frameIndex}-${docInfos[type as EAuthMeCardClass].docId}-${new Date().getTime().toString()}.jpg`)
27920
- backgroundRequest(() => uploadFrameBase64(docInfos[EAuthMeCardClass.Passport].docId, requestImg, frameIndex++));
28088
+ backgroundRequest(() => __awaiter(this, void 0, void 0, function* () {
28089
+ const postData = {
28090
+ scanDocumentId: docInfos[EAuthMeCardClass.Passport].docId,
28091
+ image: requestImg,
28092
+ type: ResourceImageType.Recognition,
28093
+ info: {
28094
+ report: undefined,
28095
+ index: frameIndex++
28096
+ }
28097
+ };
28098
+ if (shouldEncrypt) {
28099
+ postData.image = yield blobToBase64(image);
28100
+ return uploadFrameBase64({
28101
+ id: scanId,
28102
+ encryptedBase64String: yield encryptDataBase64(postData)
28103
+ });
28104
+ } else {
28105
+ return uploadFrameBase64(postData);
28106
+ }
28107
+ })
28108
+ // uploadFrameBase64(
28109
+ // docInfos[EAuthMeCardClass.Passport].docId,
28110
+ // requestImg,
28111
+ // frameIndex++
28112
+ // )
28113
+ );
27921
28114
  }
28115
+
27922
28116
  const tField = latestTField;
27923
28117
  if (!tField) {
27924
28118
  return mrzResult;
@@ -27934,8 +28128,57 @@ class MRZModule {
27934
28128
  docInfos[option.type].docId = '';
27935
28129
  const requestImg = yield encryptImageBase64(docInfos[option.type].ocrOriginImg);
27936
28130
  const report = yield this.mrzService.getReport();
27937
- yield SendRequestWithRetry$1(() => uploadFrameBase64(docId, requestImg, frameIndex++, ResourceImageType.Recognition, report));
27938
- yield SendRequestWithRetry$1(() => finishScanDocument(docId, latestTField !== null && latestTField !== void 0 ? latestTField : {}, docInfos[option.type].fraudResult));
28131
+ yield SendRequestWithRetry$1(() => __awaiter(this, void 0, void 0, function* () {
28132
+ const postData = {
28133
+ scanDocumentId: docId,
28134
+ image: requestImg,
28135
+ type: ResourceImageType.Recognition,
28136
+ info: {
28137
+ report: report,
28138
+ index: frameIndex++
28139
+ }
28140
+ };
28141
+ if (shouldEncrypt) {
28142
+ postData.image = yield blobToBase64(docInfos[option.type].ocrOriginImg);
28143
+ return uploadFrameBase64({
28144
+ id: scanId,
28145
+ encryptedBase64String: yield encryptDataBase64(postData)
28146
+ });
28147
+ } else {
28148
+ return uploadFrameBase64(postData);
28149
+ }
28150
+ })
28151
+ // uploadFrameBase64(
28152
+ // docId,
28153
+ // requestImg,
28154
+ // frameIndex++,
28155
+ // ResourceImageType.Recognition,
28156
+ // report
28157
+ // )
28158
+ );
28159
+
28160
+ yield SendRequestWithRetry$1(() => __awaiter(this, void 0, void 0, function* () {
28161
+ const postData = {
28162
+ scanDocumentId: docId,
28163
+ details: latestTField !== null && latestTField !== void 0 ? latestTField : {},
28164
+ fraud: docInfos[option.type].fraudResult
28165
+ };
28166
+ if (shouldEncrypt) {
28167
+ return finishScanDocument({
28168
+ id: scanId,
28169
+ encryptedBase64String: yield encryptDataBase64(postData)
28170
+ });
28171
+ } else {
28172
+ return finishScanDocument(postData);
28173
+ }
28174
+ })
28175
+ // finishScanDocument(
28176
+ // docId,
28177
+ // latestTField ?? {},
28178
+ // docInfos[option.type].fraudResult
28179
+ // )
28180
+ );
28181
+
27939
28182
  return true;
27940
28183
  } else {
27941
28184
  return false;
@@ -27950,14 +28193,14 @@ class MRZModule {
27950
28193
  throw 'MRZ Fraud Not Supported.';
27951
28194
  }),
27952
28195
  setFrameSize: (width, height) => __awaiter(this, void 0, void 0, function* () {
27953
- var _d;
28196
+ var _e;
27954
28197
  frameWidth = width;
27955
28198
  frameHeight = height;
27956
- yield (_d = this.mrzService) === null || _d === void 0 ? void 0 : _d.setFrameSize(width, height);
28199
+ yield (_e = this.mrzService) === null || _e === void 0 ? void 0 : _e.setFrameSize(width, height);
27957
28200
  }),
27958
28201
  onSuccess: () => __awaiter(this, void 0, void 0, function* () {
27959
- var _e;
27960
- (_e = this.mrzService) === null || _e === void 0 ? void 0 : _e.destroy();
28202
+ var _f;
28203
+ (_f = this.mrzService) === null || _f === void 0 ? void 0 : _f.destroy();
27961
28204
  yield waitTime(1000);
27962
28205
  return {
27963
28206
  scanId: scanId,
@@ -27965,8 +28208,8 @@ class MRZModule {
27965
28208
  };
27966
28209
  }),
27967
28210
  onDestroy: () => __awaiter(this, void 0, void 0, function* () {
27968
- var _f;
27969
- yield (_f = this.mrzService) === null || _f === void 0 ? void 0 : _f.destroy();
28211
+ var _g;
28212
+ yield (_g = this.mrzService) === null || _g === void 0 ? void 0 : _g.destroy();
27970
28213
  }),
27971
28214
  getAntiFraudStageList: () => []
27972
28215
  }));
@@ -27997,6 +28240,25 @@ function unionMerge(a, b) {
27997
28240
  }
27998
28241
  return result;
27999
28242
  }
28243
+ // function blobToBase64(image: Blob): Promise<string> {
28244
+ // return new Promise((resolve, reject) => {
28245
+ // // Use FileReader to convert Blob to base64
28246
+ // const reader = new FileReader();
28247
+ // reader.onloadend = function () {
28248
+ // if (reader.result) {
28249
+ // // Strip off the data URL prefix to get just the base64-encoded bytes
28250
+ // const base64String = (reader.result as string).split(',')[1];
28251
+ // resolve(base64String);
28252
+ // } else {
28253
+ // reject(new Error('Failed to convert Blob to base64'));
28254
+ // }
28255
+ // };
28256
+ // reader.onerror = function (error) {
28257
+ // reject(error);
28258
+ // };
28259
+ // reader.readAsDataURL(image);
28260
+ // });
28261
+ // }
28000
28262
  function SendRequestWithRetry(promiseFactory, options = {}) {
28001
28263
  return retryPromiseWithCondition(promiseFactory, e => __awaiter(this, void 0, void 0, function* () {
28002
28264
  var _a, _b, _c;
@@ -28174,6 +28436,11 @@ class OCRModule {
28174
28436
  let frameIndex = 0;
28175
28437
  let uploadFullFrame = false;
28176
28438
  let fraudTimeout = DEFAULT_ANTI_FRAUD_TIMEOUT;
28439
+ let shouldEncrypt = false;
28440
+ let frontImage = null;
28441
+ let backImage = null;
28442
+ let frontCropImage = null;
28443
+ let backCropImage = null;
28177
28444
  const {
28178
28445
  getDebugLogsLength,
28179
28446
  modifyDeubgLog,
@@ -28206,6 +28473,14 @@ class OCRModule {
28206
28473
  reader.readAsArrayBuffer(blob);
28207
28474
  });
28208
28475
  });
28476
+ const encryptDataBase64 = data => __awaiter(this, void 0, void 0, function* () {
28477
+ const dataString = JSON.stringify(data);
28478
+ const encoder = new TextEncoder();
28479
+ const uint8Array = encoder.encode(dataString);
28480
+ const resultEncrypt = yield this.ocrService.encryptBlob(uint8Array, pubKey);
28481
+ return resultEncrypt;
28482
+ });
28483
+ Storage.setItem('encryptDataBase64', encryptDataBase64);
28209
28484
  try {
28210
28485
  const translateService = getTranslateInstance();
28211
28486
  const eventNameWrong$ = new Subject();
@@ -28213,11 +28488,11 @@ class OCRModule {
28213
28488
  cardTypeConfigs: cardTypeConfigs,
28214
28489
  ocrConfig: config,
28215
28490
  init: (width, height) => __awaiter(this, void 0, void 0, function* () {
28216
- var _a, _b, _c, _d;
28491
+ var _a, _b, _c, _d, _e;
28217
28492
  frameWidth = width;
28218
28493
  frameHeight = height;
28219
28494
  const resp = yield SendRequestWithRetry(() => {
28220
- return init(config.type, config.country, config.needConfirm, config.cardTypes);
28495
+ return initScan(config.type, config.country, config.needConfirm, config.cardTypes);
28221
28496
  }, {
28222
28497
  onErrorHandler(e) {
28223
28498
  var _a, _b, _c;
@@ -28243,11 +28518,15 @@ class OCRModule {
28243
28518
  }
28244
28519
  });
28245
28520
  scanId = resp.scanId;
28521
+ shouldEncrypt = (_a = resp.shouldEncrypt) !== null && _a !== void 0 ? _a : shouldEncrypt;
28522
+ Storage.setItem('shouldEncrypt', shouldEncrypt);
28246
28523
  pubKey = resp.parameters.pubKey;
28247
- uploadFullFrame = (_b = (_a = resp.parameters.fraud) === null || _a === void 0 ? void 0 : _a.collectAllFrames) !== null && _b !== void 0 ? _b : config.uploadFullFrame;
28248
- fraudTimeout = (_d = (_c = resp.parameters.fraud) === null || _c === void 0 ? void 0 : _c.totalTimeout) !== null && _d !== void 0 ? _d : DEFAULT_ANTI_FRAUD_TIMEOUT;
28249
- if (resp.parameters.pubKey) {
28524
+ uploadFullFrame = (_c = (_b = resp.parameters.fraud) === null || _b === void 0 ? void 0 : _b.collectAllFrames) !== null && _c !== void 0 ? _c : config.uploadFullFrame;
28525
+ fraudTimeout = (_e = (_d = resp.parameters.fraud) === null || _d === void 0 ? void 0 : _d.totalTimeout) !== null && _e !== void 0 ? _e : DEFAULT_ANTI_FRAUD_TIMEOUT;
28526
+ if (!shouldEncrypt) {
28250
28527
  this.engine.setPublicKeyForJson(pubKey);
28528
+ } else {
28529
+ this.engine.setPublicKeyForJson('');
28251
28530
  }
28252
28531
  if (config.type === IdRecognitionCardType.IDCard && config.needAntiFraud) {
28253
28532
  yield this.antiFraudInstance.init();
@@ -28292,7 +28571,20 @@ class OCRModule {
28292
28571
  docInfos[cardType].ocrImg = null;
28293
28572
  docInfos[cardType].ocrOriginImg = null;
28294
28573
  } else {
28295
- const resp = yield SendRequestWithRetry(() => initScanDocument(scanId, cardType));
28574
+ const resp = yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
28575
+ const postData = {
28576
+ scanId: scanId,
28577
+ cardType: cardType
28578
+ };
28579
+ if (shouldEncrypt) {
28580
+ return initScanDocument({
28581
+ id: scanId,
28582
+ encryptedBase64String: yield encryptDataBase64(postData)
28583
+ });
28584
+ } else {
28585
+ return initScanDocument(postData);
28586
+ }
28587
+ }));
28296
28588
  if (docInfos[cardType]) {
28297
28589
  docInfos[cardType].docId = resp.scanDocumentId;
28298
28590
  } else {
@@ -28362,7 +28654,23 @@ class OCRModule {
28362
28654
  for (let i = 0; i < scanViewSetting.content.length; i++) {
28363
28655
  const contentSetting = scanViewSetting.content[i];
28364
28656
  if (contentSetting.type === 'svg') {
28365
- const imageData = yield initScanDocumentResourceBase64(scanId, contentSetting.content);
28657
+ let imageData;
28658
+ const postData = {
28659
+ scanId: scanId,
28660
+ ResourceId: contentSetting.content
28661
+ };
28662
+ if (shouldEncrypt) {
28663
+ imageData = yield initScanDocumentResourceBase64({
28664
+ id: scanId,
28665
+ encryptedBase64String: yield encryptDataBase64(postData)
28666
+ });
28667
+ } else {
28668
+ imageData = yield initScanDocumentResourceBase64(postData);
28669
+ }
28670
+ // const imageData = await initScanDocumentResourceBase64(
28671
+ // scanId,
28672
+ // contentSetting.content
28673
+ // );
28366
28674
  frameImage(faceMode, i, imageData.data, contentSetting.color, contentSetting.opacity);
28367
28675
  }
28368
28676
  if (contentSetting.type === 'text') {
@@ -28402,7 +28710,20 @@ class OCRModule {
28402
28710
  docInfos[cardType].ocrImg = null;
28403
28711
  docInfos[cardType].ocrOriginImg = null;
28404
28712
  } else {
28405
- const resp = yield SendRequestWithRetry(() => initScanDocument(scanId, cardType));
28713
+ const resp = yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
28714
+ const postData = {
28715
+ scanId: scanId,
28716
+ cardType: cardType
28717
+ };
28718
+ if (shouldEncrypt) {
28719
+ return initScanDocument({
28720
+ id: scanId,
28721
+ encryptedBase64String: yield encryptDataBase64(postData)
28722
+ });
28723
+ } else {
28724
+ return initScanDocument(postData);
28725
+ }
28726
+ }));
28406
28727
  if (docInfos[cardType]) {
28407
28728
  docInfos[cardType].docId = resp.scanDocumentId;
28408
28729
  } else {
@@ -28526,7 +28847,23 @@ class OCRModule {
28526
28847
  for (let i = 0; i < scanViewSetting.content.length; i++) {
28527
28848
  const contentSetting = scanViewSetting.content[i];
28528
28849
  if (contentSetting.type === 'svg') {
28529
- const imageData = yield initScanDocumentResourceBase64(scanId, contentSetting.content);
28850
+ let imageData;
28851
+ const postData = {
28852
+ scanId: scanId,
28853
+ ResourceId: contentSetting.content
28854
+ };
28855
+ if (shouldEncrypt) {
28856
+ imageData = yield initScanDocumentResourceBase64({
28857
+ id: scanId,
28858
+ encryptedBase64String: yield encryptDataBase64(postData)
28859
+ });
28860
+ } else {
28861
+ imageData = yield initScanDocumentResourceBase64(postData);
28862
+ }
28863
+ // const imageData = await initScanDocumentResourceBase64(
28864
+ // scanId,
28865
+ // contentSetting.content
28866
+ // );
28530
28867
  frameImage(faceMode, i, imageData.data, contentSetting.color, contentSetting.opacity);
28531
28868
  }
28532
28869
  if (contentSetting.type === 'text') {
@@ -28539,11 +28876,11 @@ class OCRModule {
28539
28876
  };
28540
28877
  }),
28541
28878
  onThicknessFrame: (data, _base64, cardType, type) => __awaiter(this, void 0, void 0, function* () {
28542
- var _e, _f;
28879
+ var _f, _g;
28543
28880
  nextDebugRound(type);
28544
28881
  const antiFraudRecogitionResult = yield functionLogging(() => __awaiter(this, void 0, void 0, function* () {
28545
- var _g;
28546
- return yield (_g = this.antiFraudInstance) === null || _g === void 0 ? void 0 : _g.recognition(data);
28882
+ var _h;
28883
+ return yield (_h = this.antiFraudInstance) === null || _h === void 0 ? void 0 : _h.recognition(data);
28547
28884
  }), {
28548
28885
  runFunction: RUN_FUNCTION_NAME.ANTI_FARUD_RECOGNITION,
28549
28886
  isAntiFraud: true
@@ -28552,7 +28889,7 @@ class OCRModule {
28552
28889
  return antiFraudRecogitionResult;
28553
28890
  }
28554
28891
  if (this.canvas) {
28555
- const debugData = yield (_e = this.antiFraudInstance) === null || _e === void 0 ? void 0 : _e.getDebugImageData(data);
28892
+ const debugData = yield (_f = this.antiFraudInstance) === null || _f === void 0 ? void 0 : _f.getDebugImageData(data);
28556
28893
  const ctx = this.canvas.getContext('2d');
28557
28894
  this.canvas.width = frameWidth;
28558
28895
  this.canvas.height = frameHeight;
@@ -28564,12 +28901,12 @@ class OCRModule {
28564
28901
  saveDebugImage({
28565
28902
  data,
28566
28903
  type,
28567
- getDebugImageData: (_f = this.antiFraudInstance) === null || _f === void 0 ? void 0 : _f.getDebugImageData.bind(this.antiFraudInstance),
28904
+ getDebugImageData: (_g = this.antiFraudInstance) === null || _g === void 0 ? void 0 : _g.getDebugImageData.bind(this.antiFraudInstance),
28568
28905
  result,
28569
28906
  width: frameWidth,
28570
28907
  height: frameHeight
28571
28908
  });
28572
- const fraudOriginImg = UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas);
28909
+ const fraudOriginImg = UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas, config.resultImageFormat);
28573
28910
  const thicknessResult = Object.assign(Object.assign({}, antiFraudRecogitionResult), {
28574
28911
  imageData: data
28575
28912
  });
@@ -28586,10 +28923,27 @@ class OCRModule {
28586
28923
  isAntiFraud: true
28587
28924
  });
28588
28925
  frameIndex++;
28589
- backgroundRequest(() => uploadFrameBase64(docId, requestImg, frameIndex, ResourceImageType.Recognition // upload fill frame 時先使用 recognition 當成一個過渡方案, 目前後端會對這個處理存成 original image, 後續會再調整
28590
- ));
28926
+ backgroundRequest(() => __awaiter(this, void 0, void 0, function* () {
28927
+ const postData = {
28928
+ scanDocumentId: docId,
28929
+ image: requestImg,
28930
+ type: ResourceImageType.Recognition,
28931
+ info: {
28932
+ report: undefined,
28933
+ index: frameIndex
28934
+ }
28935
+ };
28936
+ if (shouldEncrypt) {
28937
+ postData.image = yield blobToBase64(fraudOriginImg);
28938
+ return uploadFrameBase64({
28939
+ id: scanId,
28940
+ encryptedBase64String: yield encryptDataBase64(postData)
28941
+ });
28942
+ } else {
28943
+ return uploadFrameBase64(postData);
28944
+ }
28945
+ }));
28591
28946
  }
28592
-
28593
28947
  return thicknessResult;
28594
28948
  }),
28595
28949
  confirmThickness: (imageData, cardType) => __awaiter(this, void 0, void 0, function* () {
@@ -28597,8 +28951,53 @@ class OCRModule {
28597
28951
  const docId = docInfos[cardType].docId;
28598
28952
  const requestImg = yield encryptImageBase64(imageData);
28599
28953
  try {
28600
- yield SendRequestWithRetry(() => uploadFrameBase64(docId, requestImg, frameIndex, ResourceImageType.Attach, undefined));
28601
- yield SendRequestWithRetry(() => finishScanDocument(docId, {}, null));
28954
+ yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
28955
+ const postData = {
28956
+ scanDocumentId: docId,
28957
+ image: requestImg,
28958
+ type: ResourceImageType.Attach,
28959
+ info: {
28960
+ report: undefined,
28961
+ index: frameIndex
28962
+ }
28963
+ };
28964
+ if (shouldEncrypt) {
28965
+ postData.image = yield blobToBase64(imageData);
28966
+ return uploadFrameBase64({
28967
+ id: scanId,
28968
+ encryptedBase64String: yield encryptDataBase64(postData)
28969
+ });
28970
+ } else {
28971
+ return uploadFrameBase64(postData);
28972
+ }
28973
+ })
28974
+ // uploadFrameBase64(
28975
+ // docId,
28976
+ // requestImg,
28977
+ // frameIndex,
28978
+ // ResourceImageType.Attach,
28979
+ // undefined
28980
+ // )
28981
+ );
28982
+
28983
+ yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
28984
+ const postData = {
28985
+ scanDocumentId: docId,
28986
+ details: {},
28987
+ fraud: null
28988
+ };
28989
+ if (shouldEncrypt) {
28990
+ return finishScanDocument({
28991
+ id: scanId,
28992
+ encryptedBase64String: yield encryptDataBase64(postData)
28993
+ });
28994
+ } else {
28995
+ return finishScanDocument(postData);
28996
+ }
28997
+ })
28998
+ // finishScanDocument(docId, {}, null)
28999
+ );
29000
+
28602
29001
  return true;
28603
29002
  } catch (error) {
28604
29003
  console.error('confirmThickness:', error);
@@ -28634,10 +29033,10 @@ class OCRModule {
28634
29033
  width: frameWidth,
28635
29034
  height: frameHeight
28636
29035
  });
28637
- const ocrOriginImg = UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas);
29036
+ const ocrOriginImg = UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas, config.resultImageFormat);
28638
29037
  const eClass = cardType !== null && cardType !== void 0 ? cardType : '';
28639
29038
  if (result.eStatus === EAuthMeCardOCRStatus.Pass && result.imageData && !!docInfos[eClass].docId) {
28640
- const resultOcrImg = UintArrayToBlob(result.iWidth, result.iHeight, result === null || result === void 0 ? void 0 : result.imageData, virtualCanvas);
29039
+ const resultOcrImg = UintArrayToBlob(result.iWidth, result.iHeight, result === null || result === void 0 ? void 0 : result.imageData, virtualCanvas, config.resultImageFormat);
28641
29040
  docInfos[eClass].ocrImg = resultOcrImg;
28642
29041
  docInfos[eClass].ocrOriginImg = ocrOriginImg;
28643
29042
  yield _service.stop();
@@ -28656,7 +29055,38 @@ class OCRModule {
28656
29055
  const requestImg = yield encryptImageBase64(image);
28657
29056
  // downloadImage(image, `${frameIndex}-${docInfos[type as EAuthMeCardClass].docId}-${new Date().getTime().toString()}.jpg`)
28658
29057
  frameIndex++;
28659
- backgroundRequest(() => uploadFrameBase64(docInfos[cardType !== null && cardType !== void 0 ? cardType : ''].docId, requestImg, frameIndex));
29058
+ backgroundRequest(() => __awaiter(this, void 0, void 0, function* () {
29059
+ console.log('recognition', docInfos[cardType !== null && cardType !== void 0 ? cardType : ''].docId);
29060
+ if (docInfos[eClass].docId === '') {
29061
+ console.warn('didnt find docid, retry');
29062
+ return false;
29063
+ }
29064
+ const postData = {
29065
+ scanDocumentId: docInfos[cardType !== null && cardType !== void 0 ? cardType : ''].docId,
29066
+ image: requestImg,
29067
+ type: ResourceImageType.Recognition,
29068
+ info: {
29069
+ report: undefined,
29070
+ index: frameIndex
29071
+ }
29072
+ };
29073
+ if (shouldEncrypt) {
29074
+ postData.image = yield blobToBase64(image);
29075
+ return uploadFrameBase64({
29076
+ id: scanId,
29077
+ encryptedBase64String: yield encryptDataBase64(postData)
29078
+ });
29079
+ } else {
29080
+ return uploadFrameBase64(postData);
29081
+ }
29082
+ })
29083
+ // uploadFrameBase64(
29084
+ // docInfos[cardType ?? ''].docId,
29085
+ // requestImg,
29086
+ // frameIndex
29087
+ // )
29088
+ );
29089
+
28660
29090
  pushNewDebugImage(ocrOriginImg, {
28661
29091
  result: result,
28662
29092
  status: 'recognition',
@@ -28681,45 +29111,131 @@ class OCRModule {
28681
29111
  this.ocrService.stop();
28682
29112
  }
28683
29113
  const docId = docInfos[option.cardType].docId;
28684
- if (docId) {
28685
- const needFraudOption = config.needAntiFraud && option.type === EAuthMeCardClass$1.TWN_IDCard_Front;
28686
- let ocrOriginImg;
28687
- if (option.imageData) {
28688
- ocrOriginImg = option.imageData;
29114
+ if (!docId) {
29115
+ console.warn('didnt find docid , retry');
29116
+ return false;
29117
+ }
29118
+ const ocrImg = option.imageData ? option.imageData : docInfos[option.cardType].ocrImg;
29119
+ const needFraudOption = config.needAntiFraud && option.type === EAuthMeCardClass$1.TWN_IDCard_Front;
29120
+ let ocrOriginImg;
29121
+ if (option.imageData) {
29122
+ ocrOriginImg = option.imageData;
29123
+ } else {
29124
+ ocrOriginImg = docInfos[option.cardType].ocrOriginImg;
29125
+ }
29126
+ // const base64Image = await blobToBase64(ocrOriginImg);
29127
+ // console.log('confirmImage', base64Image);
29128
+ const requestImg = yield encryptImageBase64(ocrOriginImg);
29129
+ const report = yield this.ocrService.getReport();
29130
+ docInfos[option.cardType].docId = '';
29131
+ modifyDeubgLog(getDebugLogsLength() - 1, {
29132
+ report: report
29133
+ });
29134
+ frameIndex++;
29135
+ yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
29136
+ const postData = {
29137
+ scanDocumentId: docId,
29138
+ image: requestImg,
29139
+ type: ResourceImageType.Recognition,
29140
+ info: {
29141
+ report: report,
29142
+ index: frameIndex
29143
+ }
29144
+ };
29145
+ if (shouldEncrypt) {
29146
+ postData.image = yield blobToBase64(ocrOriginImg);
29147
+ return uploadFrameBase64({
29148
+ id: scanId,
29149
+ encryptedBase64String: yield encryptDataBase64(postData)
29150
+ });
28689
29151
  } else {
28690
- ocrOriginImg = docInfos[option.cardType].ocrOriginImg;
29152
+ return uploadFrameBase64(postData);
28691
29153
  }
28692
- // const base64Image = await blobToBase64(ocrOriginImg);
28693
- // console.log('confirmImage', base64Image);
28694
- const requestImg = yield encryptImageBase64(ocrOriginImg);
28695
- const report = yield this.ocrService.getReport();
28696
- docInfos[option.cardType].docId = '';
28697
- modifyDeubgLog(getDebugLogsLength() - 1, {
28698
- report: report
28699
- });
28700
- frameIndex++;
28701
- yield SendRequestWithRetry(() => uploadFrameBase64(docId, requestImg, frameIndex, ResourceImageType.Recognition, report));
28702
- frameIndex = 0;
28703
- try {
28704
- const ocrImg = option.imageData ? option.imageData : docInfos[option.cardType].ocrImg;
28705
- const _requestImg = yield encryptImageBase64(ocrImg);
28706
- const resp = yield SendRequestWithRetry(() => recognitionEncrypt(docId, _requestImg, report, RecognitionFileType.FlatImage));
28707
- if (resp.retry) {
28708
- yield asyncShowPopup(translateService.translate('sdk.verify.error.blurRetake.title'), translateService.translate('sdk.verify.error.blurRetake.content'), true);
28709
- throw 'recognition failed';
29154
+ })
29155
+ // uploadFrameBase64(
29156
+ // docId,
29157
+ // requestImg,
29158
+ // frameIndex,
29159
+ // ResourceImageType.Recognition,
29160
+ // report
29161
+ // )
29162
+ );
29163
+
29164
+ frameIndex = 0;
29165
+ try {
29166
+ const _requestImg = yield encryptImageBase64(ocrImg);
29167
+ const resp = yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
29168
+ const postData = {
29169
+ scanDocumentId: docId,
29170
+ image: _requestImg,
29171
+ fileType: RecognitionFileType.FlatImage,
29172
+ info: {
29173
+ report: report
29174
+ }
29175
+ };
29176
+ let response;
29177
+ if (shouldEncrypt) {
29178
+ postData.image = yield blobToBase64(ocrImg);
29179
+ response = yield recognizeBase64({
29180
+ id: scanId,
29181
+ encryptedBase64String: yield encryptDataBase64(postData)
29182
+ });
29183
+ } else {
29184
+ response = yield recognizeBase64(postData);
28710
29185
  }
28711
- result = unionMerge(result, resp && resp.details || {});
28712
- yield SendRequestWithRetry(() => finishScanDocument(docId, resp.details, needFraudOption ? this.fraudResult : null));
28713
- delete docInfos[option.cardType];
28714
- return true;
28715
- } catch (error) {
28716
- console.log('confirmImage fail,retrying ');
28717
- console.error(error);
28718
- docInfos[option.cardType].docId = docId;
28719
- return false;
29186
+ if (response === null || response === void 0 ? void 0 : response.detectCardResult) {
29187
+ if (option.cardType.toLocaleLowerCase().includes('front')) {
29188
+ frontImage = yield blobToImageBase64(ocrOriginImg);
29189
+ frontCropImage = yield blobToImageBase64(ocrImg);
29190
+ }
29191
+ if (option.cardType.toLocaleLowerCase().includes('back')) {
29192
+ backImage = yield blobToImageBase64(ocrOriginImg);
29193
+ backCropImage = yield blobToImageBase64(ocrImg);
29194
+ }
29195
+ }
29196
+ return response;
29197
+ })
29198
+ // recognizeBase64(
29199
+ // docId,
29200
+ // requestImg,
29201
+ // report,
29202
+ // RecognitionFileType.FlatImage
29203
+ // )
29204
+ );
29205
+
29206
+ if (resp.retry) {
29207
+ yield asyncShowPopup(translateService.translate('sdk.verify.error.blurRetake.title'), translateService.translate('sdk.verify.error.blurRetake.content'), true);
29208
+ throw 'recognition failed';
28720
29209
  }
28721
- } else {
28722
- console.error('didnt find docid , retry ');
29210
+ result = unionMerge(result, resp && resp.details || {});
29211
+ yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
29212
+ const postData = {
29213
+ scanDocumentId: docId,
29214
+ details: resp.details,
29215
+ fraud: needFraudOption ? this.fraudResult : null
29216
+ };
29217
+ if (shouldEncrypt) {
29218
+ return finishScanDocument({
29219
+ id: scanId,
29220
+ encryptedBase64String: yield encryptDataBase64(postData)
29221
+ });
29222
+ } else {
29223
+ return finishScanDocument(postData);
29224
+ }
29225
+ })
29226
+ // finishScanDocument(
29227
+ // docId,
29228
+ // resp.details,
29229
+ // needFraudOption ? this.fraudResult : null
29230
+ // )
29231
+ );
29232
+
29233
+ delete docInfos[option.cardType];
29234
+ return true;
29235
+ } catch (error) {
29236
+ console.log('confirmImage fail,retrying ');
29237
+ console.error(error);
29238
+ docInfos[option.cardType].docId = docId;
28723
29239
  return false;
28724
29240
  }
28725
29241
  }),
@@ -28740,7 +29256,35 @@ class OCRModule {
28740
29256
  report: report
28741
29257
  });
28742
29258
  frameIndex++;
28743
- SendRequestWithRetry(() => uploadFrameBase64(docId, requestImg, frameIndex, ResourceImageType.Recognition, report));
29259
+ SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
29260
+ const postData = {
29261
+ scanDocumentId: docId,
29262
+ image: requestImg,
29263
+ type: ResourceImageType.Recognition,
29264
+ info: {
29265
+ report: report,
29266
+ index: frameIndex
29267
+ }
29268
+ };
29269
+ if (shouldEncrypt) {
29270
+ postData.image = yield blobToBase64(ocrOriginImg);
29271
+ return uploadFrameBase64({
29272
+ id: scanId,
29273
+ encryptedBase64String: yield encryptDataBase64(postData)
29274
+ });
29275
+ } else {
29276
+ return uploadFrameBase64(postData);
29277
+ }
29278
+ })
29279
+ // uploadFrameBase64(
29280
+ // docId,
29281
+ // requestImg,
29282
+ // frameIndex,
29283
+ // ResourceImageType.Recognition,
29284
+ // report
29285
+ // )
29286
+ );
29287
+
28744
29288
  frameIndex = 0;
28745
29289
  return true;
28746
29290
  } else {
@@ -28768,7 +29312,20 @@ class OCRModule {
28768
29312
  fraudOriginImg: null,
28769
29313
  fraudResult: false
28770
29314
  };
28771
- const resp = yield SendRequestWithRetry(() => initScanDocument(scanId, twoWayAuthmeCardClassMap.toServer(twnidCardFront)));
29315
+ const resp = yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
29316
+ const postData = {
29317
+ scanId: scanId,
29318
+ cardType: twoWayAuthmeCardClassMap.toServer(twnidCardFront)
29319
+ };
29320
+ if (shouldEncrypt) {
29321
+ return initScanDocument({
29322
+ id: scanId,
29323
+ encryptedBase64String: yield encryptDataBase64(postData)
29324
+ });
29325
+ } else {
29326
+ return initScanDocument(postData);
29327
+ }
29328
+ }));
28772
29329
  if (docInfos[twnidCardFront]) {
28773
29330
  docInfos[twnidCardFront].docId = resp.scanDocumentId;
28774
29331
  } else {
@@ -28794,12 +29351,12 @@ class OCRModule {
28794
29351
  return true;
28795
29352
  }),
28796
29353
  onAntiFraudFrame: data => __awaiter(this, void 0, void 0, function* () {
28797
- var _h, _j;
29354
+ var _j, _k;
28798
29355
  const type = EAuthMeCardClass$1.TWN_IDCard_Front;
28799
29356
  nextDebugRound(type);
28800
29357
  const antiFraudRecogitionResult = yield functionLogging(() => __awaiter(this, void 0, void 0, function* () {
28801
- var _k;
28802
- return yield (_k = this.antiFraudInstance) === null || _k === void 0 ? void 0 : _k.recognition(data);
29358
+ var _l;
29359
+ return yield (_l = this.antiFraudInstance) === null || _l === void 0 ? void 0 : _l.recognition(data);
28803
29360
  }), {
28804
29361
  runFunction: RUN_FUNCTION_NAME.ANTI_FARUD_RECOGNITION,
28805
29362
  isAntiFraud: true
@@ -28808,7 +29365,7 @@ class OCRModule {
28808
29365
  return antiFraudRecogitionResult;
28809
29366
  }
28810
29367
  if (this.canvas) {
28811
- const debugData = yield (_h = this.antiFraudInstance) === null || _h === void 0 ? void 0 : _h.getDebugImageData(data);
29368
+ const debugData = yield (_j = this.antiFraudInstance) === null || _j === void 0 ? void 0 : _j.getDebugImageData(data);
28812
29369
  const ctx = this.canvas.getContext('2d');
28813
29370
  this.canvas.width = frameWidth;
28814
29371
  this.canvas.height = frameHeight;
@@ -28820,12 +29377,12 @@ class OCRModule {
28820
29377
  saveDebugImage({
28821
29378
  data,
28822
29379
  type,
28823
- getDebugImageData: (_j = this.antiFraudInstance) === null || _j === void 0 ? void 0 : _j.getDebugImageData.bind(this.antiFraudInstance),
29380
+ getDebugImageData: (_k = this.antiFraudInstance) === null || _k === void 0 ? void 0 : _k.getDebugImageData.bind(this.antiFraudInstance),
28824
29381
  result,
28825
29382
  width: frameWidth,
28826
29383
  height: frameHeight
28827
29384
  });
28828
- const fraudOriginImg = UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas);
29385
+ const fraudOriginImg = UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas, config.resultImageFormat);
28829
29386
  if (antiFraudRecogitionResult.eStatus === EAuthMeIDCardAntiFraudStatus.Pass || antiFraudRecogitionResult.eStatus === EAuthMeIDCardAntiFraudStatus.Failed) {
28830
29387
  docInfos[type].fraudOriginImg = fraudOriginImg;
28831
29388
  this.fraudResult = antiFraudRecogitionResult.eStatus === EAuthMeIDCardAntiFraudStatus.Pass;
@@ -28842,7 +29399,35 @@ class OCRModule {
28842
29399
  isAntiFraud: true
28843
29400
  });
28844
29401
  frameIndex++;
28845
- yield SendRequestWithRetry(() => uploadFrameBase64(docId, requestImg, frameIndex, ResourceImageType.Fraud, report));
29402
+ yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
29403
+ const postData = {
29404
+ scanDocumentId: docId,
29405
+ image: requestImg,
29406
+ type: ResourceImageType.Fraud,
29407
+ info: {
29408
+ report: report,
29409
+ index: frameIndex
29410
+ }
29411
+ };
29412
+ if (shouldEncrypt) {
29413
+ postData.image = yield blobToBase64(ocrImg);
29414
+ return uploadFrameBase64({
29415
+ id: scanId,
29416
+ encryptedBase64String: yield encryptDataBase64(postData)
29417
+ });
29418
+ } else {
29419
+ return uploadFrameBase64(postData);
29420
+ }
29421
+ })
29422
+ // uploadFrameBase64(
29423
+ // docId,
29424
+ // requestImg,
29425
+ // frameIndex,
29426
+ // ResourceImageType.Fraud,
29427
+ // report
29428
+ // )
29429
+ );
29430
+
28846
29431
  frameIndex = 0;
28847
29432
  yield this.antiFraudInstance.destroy();
28848
29433
  } else if (uploadFullFrame) {
@@ -28856,49 +29441,86 @@ class OCRModule {
28856
29441
  isAntiFraud: true
28857
29442
  });
28858
29443
  frameIndex++;
28859
- backgroundRequest(() => uploadFrameBase64(docId, requestImg, frameIndex, ResourceImageType.Fraud));
29444
+ backgroundRequest(() => __awaiter(this, void 0, void 0, function* () {
29445
+ const postData = {
29446
+ scanDocumentId: docId,
29447
+ image: requestImg,
29448
+ type: ResourceImageType.Fraud,
29449
+ info: {
29450
+ report: undefined,
29451
+ index: frameIndex
29452
+ }
29453
+ };
29454
+ if (shouldEncrypt) {
29455
+ postData.image = yield blobToBase64(fraudOriginImg);
29456
+ return uploadFrameBase64({
29457
+ id: scanId,
29458
+ encryptedBase64String: yield encryptDataBase64(postData)
29459
+ });
29460
+ } else {
29461
+ return uploadFrameBase64(postData);
29462
+ }
29463
+ })
29464
+ // uploadFrameBase64(
29465
+ // docId,
29466
+ // requestImg,
29467
+ // frameIndex,
29468
+ // ResourceImageType.Fraud
29469
+ // )
29470
+ );
28860
29471
  }
29472
+
28861
29473
  return antiFraudRecogitionResult;
28862
29474
  }),
28863
29475
  getAntiFraudStageList: () => {
28864
29476
  return antiFraudStageList;
28865
29477
  },
28866
29478
  setFrameSize: (width, height, points) => __awaiter(this, void 0, void 0, function* () {
28867
- var _l, _m, _o, _p;
29479
+ var _m, _o, _p, _q;
28868
29480
  frameWidth = width;
28869
29481
  frameHeight = height;
28870
- yield (_l = this.ocrService) === null || _l === void 0 ? void 0 : _l.setFrameSize(width, height);
28871
- yield (_m = this.antiFraudInstance) === null || _m === void 0 ? void 0 : _m.setFrameSize(width, height);
29482
+ yield (_m = this.ocrService) === null || _m === void 0 ? void 0 : _m.setFrameSize(width, height);
29483
+ yield (_o = this.antiFraudInstance) === null || _o === void 0 ? void 0 : _o.setFrameSize(width, height);
28872
29484
  if (config.type === IdRecognitionCardType.ResidentCard) {
28873
29485
  // workaround: resident card need MRZ, refactor later.
28874
- yield (_o = this.residentCardMrzService) === null || _o === void 0 ? void 0 : _o.setFrameSize(width, height);
29486
+ yield (_p = this.residentCardMrzService) === null || _p === void 0 ? void 0 : _p.setFrameSize(width, height);
28875
29487
  }
28876
29488
  if (points) {
28877
- yield (_p = this.ocrService) === null || _p === void 0 ? void 0 : _p.setMaskPosition(points.map(([x, y]) => [Number(x.toFixed(2)), Number(y.toFixed(2))]));
29489
+ yield (_q = this.ocrService) === null || _q === void 0 ? void 0 : _q.setMaskPosition(points.map(([x, y]) => [Number(x.toFixed(2)), Number(y.toFixed(2))]));
28878
29490
  }
28879
29491
  }),
28880
29492
  onSuccess: () => __awaiter(this, void 0, void 0, function* () {
28881
- var _q, _r, _s;
29493
+ var _r, _s, _t;
28882
29494
  durationTime.end();
28883
29495
  const ocrIdcardResultFormat = Storage.getItem(STORAGE_KEY['OCR_IDCARD_RESULT_FORMAT']);
28884
- (_q = this.antiFraudInstance) === null || _q === void 0 ? void 0 : _q.destroy();
28885
- (_r = this.ocrService) === null || _r === void 0 ? void 0 : _r.destroy();
29496
+ (_r = this.antiFraudInstance) === null || _r === void 0 ? void 0 : _r.destroy();
29497
+ (_s = this.ocrService) === null || _s === void 0 ? void 0 : _s.destroy();
28886
29498
  // workaround: resident card need MRZ, refactor later.
28887
- (_s = this.residentCardMrzService) === null || _s === void 0 ? void 0 : _s.destroy();
29499
+ (_t = this.residentCardMrzService) === null || _t === void 0 ? void 0 : _t.destroy();
28888
29500
  if (config.type === IdRecognitionCardType.IDCard && ocrIdcardResultFormat === 'splitDateAndAddress') {
28889
29501
  result = splitResult(result);
28890
29502
  }
28891
29503
  yield waitTime(1000);
29504
+ // if (Object.keys(result).length === 0) {
29505
+ // frontCropImage = null;
29506
+ // backCropImage = null;
29507
+ // frontImage = null;
29508
+ // backImage = null;
29509
+ // }
28892
29510
  return {
28893
29511
  scanId: scanId,
28894
- details: Object.assign({}, result)
29512
+ details: Object.assign({}, result),
29513
+ frontImage,
29514
+ backImage,
29515
+ frontCropImage,
29516
+ backCropImage
28895
29517
  };
28896
29518
  }),
28897
29519
  onDestroy: () => __awaiter(this, void 0, void 0, function* () {
28898
- var _t, _u;
29520
+ var _u, _v;
28899
29521
  durationTime.end();
28900
- yield (_t = this.ocrService) === null || _t === void 0 ? void 0 : _t.destroy();
28901
- yield (_u = this.antiFraudInstance) === null || _u === void 0 ? void 0 : _u.destroy();
29522
+ yield (_u = this.ocrService) === null || _u === void 0 ? void 0 : _u.destroy();
29523
+ yield (_v = this.antiFraudInstance) === null || _v === void 0 ? void 0 : _v.destroy();
28902
29524
  }),
28903
29525
  getCardMatchROI: () => __awaiter(this, void 0, void 0, function* () {
28904
29526
  return yield this.antiFraudInstance.getCardMatchROI();
@@ -28990,7 +29612,7 @@ function renderCardTypeAndCountryConfig(config) {
28990
29612
  <label class="country-select-label">${translate('sdk.home.selectCountry')}</label>
28991
29613
  <div class="country-select-dropdown">
28992
29614
  <div class="country-select-dropdown-frame">
28993
- <div class="country-select-dropdown-text">${translate(`sdk.home.selectCountry.${CountryCode.TWN}`)}</div>
29615
+ <div class="country-select-dropdown-text">${translate(`sdk.home.selectCountry.${config.defaultCountry}`)}</div>
28994
29616
  <div class="country-select-dropdown-icon"></div>
28995
29617
  </div>
28996
29618
  <div class="dropdown-country-list"></div>
@@ -29177,6 +29799,7 @@ class AuthmeIdentityVerification extends AuthmeFunctionModule {
29177
29799
  // 在尚未執行實際的 method 的時候,並不會佔用時間初始化。
29178
29800
  Storage.setItem(STORAGE_KEY.LOADING_LOTTIE, loadingLottie);
29179
29801
  Storage.setItem(STORAGE_KEY.OCR_IDCARD_RESULT_FORMAT, config.OCRIdcardResultFormat);
29802
+ Storage.setItem('customParameters', config.customParameters);
29180
29803
  (_b = this.engine) !== null && _b !== void 0 ? _b : this.engine = new MlEngine(engineConfig);
29181
29804
  yield this.engine.setConfig(engineConfig);
29182
29805
  (_c = this.ocrModule) !== null && _c !== void 0 ? _c : this.ocrModule = new OCRModule(this.engine, canvas);
@@ -29277,11 +29900,39 @@ class AuthmeIdentityVerification extends AuthmeFunctionModule {
29277
29900
  confirmOCRResult(data) {
29278
29901
  return __awaiter(this, void 0, void 0, function* () {
29279
29902
  const ocrIdcardResultFormat = Storage.getItem(STORAGE_KEY['OCR_IDCARD_RESULT_FORMAT']);
29903
+ const shouldEncrypt = Storage.getItem('shouldEncrypt');
29904
+ const encryptDataBase64 = Storage.getItem('encryptDataBase64');
29905
+ const tmpObj = {};
29280
29906
  if (ocrIdcardResultFormat === 'splitDateAndAddress') {
29281
29907
  data.details = combineResult(data.details);
29282
29908
  }
29283
- yield confirmScan(data.scanId, data.details);
29284
- return true;
29909
+ const postData = {
29910
+ scanId: Storage.getItem('scanId'),
29911
+ details: Storage.getItem('confirmedData')
29912
+ };
29913
+ let res;
29914
+ if (shouldEncrypt) {
29915
+ res = yield confirmScan({
29916
+ id: data.scanId,
29917
+ encryptedBase64String: yield encryptDataBase64(postData)
29918
+ });
29919
+ } else {
29920
+ res = yield confirmScan(postData);
29921
+ }
29922
+ for (let index = 0; index < res.confirmedFields.length; index++) {
29923
+ const element = res.confirmedFields[index];
29924
+ tmpObj[element.fieldName] = {
29925
+ isModified: element.isModified,
29926
+ value: element.value
29927
+ };
29928
+ }
29929
+ // await confirmScan(data.scanId, data.details);
29930
+ return {
29931
+ isSuccess: true,
29932
+ message: '',
29933
+ data: Storage.getItem('data'),
29934
+ modifiedData: tmpObj
29935
+ };
29285
29936
  });
29286
29937
  }
29287
29938
  // 考慮未來棄用 auth method ,並將將 auth 的部分,
@@ -29320,11 +29971,67 @@ class AuthmeIdentityVerification extends AuthmeFunctionModule {
29320
29971
  return (_a = this.tearDownPromise) !== null && _a !== void 0 ? _a : this.tearDownPromise = this._tearDown();
29321
29972
  });
29322
29973
  }
29974
+ cleanAllModel() {
29975
+ var _a;
29976
+ return __awaiter(this, void 0, void 0, function* () {
29977
+ AuthmeEngineModuleBase.reset_MODEL_CACHE();
29978
+ return (_a = this.tearDownPromise) !== null && _a !== void 0 ? _a : this.tearDownPromise = this._tearDown();
29979
+ });
29980
+ }
29981
+ getCustomerState(arg) {
29982
+ return __awaiter(this, void 0, void 0, function* () {
29983
+ const paramsDefault = {
29984
+ waitingTime: 3,
29985
+ retryTimes: 2
29986
+ };
29987
+ if (arg === null || arg === void 0 ? void 0 : arg.retryTimes) {
29988
+ if (typeof arg.retryTimes !== 'number') {
29989
+ console.error('retryTimes should be a number');
29990
+ return;
29991
+ }
29992
+ if (arg.retryTimes <= 0) {
29993
+ console.error('retryTimes should be greater than 0');
29994
+ return;
29995
+ }
29996
+ }
29997
+ if (arg === null || arg === void 0 ? void 0 : arg.waitingTime) {
29998
+ if (typeof arg.waitingTime !== 'number') {
29999
+ console.error('waitingTime should be a number');
30000
+ return;
30001
+ }
30002
+ if (arg.waitingTime <= 0) {
30003
+ console.error('waitingTime should be greater than 0');
30004
+ return;
30005
+ }
30006
+ }
30007
+ const params = Object.assign(Object.assign({}, paramsDefault), arg);
30008
+ params.retryTimes++;
30009
+ let stop = false;
30010
+ for (let i = 0; i < params.retryTimes; i++) {
30011
+ if (!stop) {
30012
+ const res = yield getCustomerState();
30013
+ if (res.state === 'Approved') {
30014
+ stop = true;
30015
+ return res;
30016
+ } else if (res.state === 'Rejected') {
30017
+ stop = true;
30018
+ return res;
30019
+ } else {
30020
+ yield new Promise(resolve => setTimeout(resolve, params.waitingTime * 1000));
30021
+ }
30022
+ if (i === params.retryTimes - 1) {
30023
+ return res;
30024
+ }
30025
+ }
30026
+ }
30027
+ // return getCustomerState();
30028
+ });
30029
+ }
29323
30030
  }
29324
30031
 
29325
30032
  var name = "authme/sdk";
29326
- var version$1 = "2.7.4";
29327
- var date = "2024-12-04T02:44:31+0000";
30033
+ var version$1 = "2.8.1-patch.1";
30034
+ var date = "2025-06-12T13:55:46+0000";
29328
30035
  var packageInfo = {
29329
30036
  name: name,
29330
30037
  version: version$1,