@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.cjs +867 -160
- package/index.js +871 -164
- package/package.json +6 -6
- package/src/lib/identity-verification-feature-identity-verification.d.ts +7 -2
- package/src/lib/interface/config.interface.d.ts +3 -0
- package/src/lib/interface/result.model.d.ts +16 -13
- package/src/lib/ui/ocr-flow.d.ts +4 -0
- package/src/lib/ui/ocr.ui.d.ts +1 -3
- package/src/lib/v2/component/frameView.d.ts +1 -1
- package/src/lib/v2/utilities/index.d.ts +14 -0
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,
|
|
@@ -128,7 +129,9 @@ const defaultIdRecognitionConfig = {
|
|
|
128
129
|
antiFraudIMetalTagValidCountTh: false,
|
|
129
130
|
cardTypes: [],
|
|
130
131
|
cardTypeConfigs: [],
|
|
131
|
-
captureTimeout: -1
|
|
132
|
+
captureTimeout: -1,
|
|
133
|
+
resultImageFormat: 'jpg',
|
|
134
|
+
confirmPageEnabled: true
|
|
132
135
|
};
|
|
133
136
|
|
|
134
137
|
function setCorrectViewHeight() {
|
|
@@ -24476,9 +24479,14 @@ function renderConfirmUI({
|
|
|
24476
24479
|
document.body.appendChild(confirmContainerElem);
|
|
24477
24480
|
return new Promise((resolve, reject) => {
|
|
24478
24481
|
confirmContainerElem.querySelector('.confirm-btn').addEventListener('click', e => {
|
|
24479
|
-
const modifiedDetails = Object.fromEntries(Object.
|
|
24480
|
-
var _a
|
|
24481
|
-
|
|
24482
|
+
const modifiedDetails = Object.fromEntries(Object.entries(items.details).map(([column, originalValue]) => {
|
|
24483
|
+
var _a;
|
|
24484
|
+
const inputElement = confirmContainerElem.querySelector(`[name="${column}"]`);
|
|
24485
|
+
const inputValue = (_a = inputElement === null || inputElement === void 0 ? void 0 : inputElement.value) !== null && _a !== void 0 ? _a : '';
|
|
24486
|
+
return [column, {
|
|
24487
|
+
isModified: inputValue !== originalValue,
|
|
24488
|
+
value: inputValue
|
|
24489
|
+
}];
|
|
24482
24490
|
}));
|
|
24483
24491
|
sendStatusAction$1(core.StatusAction.Confirm);
|
|
24484
24492
|
confirmContainerElem.remove();
|
|
@@ -25451,6 +25459,72 @@ const countdownTimer = (time, doSomething) => {
|
|
|
25451
25459
|
end: getStatus
|
|
25452
25460
|
};
|
|
25453
25461
|
};
|
|
25462
|
+
const blobToBase64 = image => __awaiter(void 0, void 0, void 0, function* () {
|
|
25463
|
+
return new Promise((resolve, reject) => {
|
|
25464
|
+
// Use FileReader to convert Blob to base64
|
|
25465
|
+
const reader = new FileReader();
|
|
25466
|
+
reader.onloadend = function () {
|
|
25467
|
+
if (reader.result) {
|
|
25468
|
+
// Strip off the data URL prefix to get just the base64-encoded bytes
|
|
25469
|
+
const base64String = reader.result.split(',')[1];
|
|
25470
|
+
resolve(base64String);
|
|
25471
|
+
} else {
|
|
25472
|
+
reject(new Error('Failed to convert Blob to base64'));
|
|
25473
|
+
}
|
|
25474
|
+
};
|
|
25475
|
+
reader.onerror = function (error) {
|
|
25476
|
+
reject(error);
|
|
25477
|
+
};
|
|
25478
|
+
reader.readAsDataURL(image);
|
|
25479
|
+
});
|
|
25480
|
+
});
|
|
25481
|
+
const blobToImageBase64 = image => __awaiter(void 0, void 0, void 0, function* () {
|
|
25482
|
+
return new Promise((resolve, reject) => {
|
|
25483
|
+
const reader = new FileReader();
|
|
25484
|
+
reader.readAsDataURL(image);
|
|
25485
|
+
reader.onloadend = () => resolve(reader.result);
|
|
25486
|
+
reader.onerror = reject;
|
|
25487
|
+
});
|
|
25488
|
+
});
|
|
25489
|
+
const result2ModifiedData = (result, modifiedResult) => {
|
|
25490
|
+
if (!modifiedResult) {
|
|
25491
|
+
const obj = {};
|
|
25492
|
+
for (const key in result) {
|
|
25493
|
+
obj[key] = {
|
|
25494
|
+
isModified: false,
|
|
25495
|
+
value: result[key]
|
|
25496
|
+
};
|
|
25497
|
+
}
|
|
25498
|
+
return obj;
|
|
25499
|
+
}
|
|
25500
|
+
const modifiedData = {};
|
|
25501
|
+
Object.keys(result).forEach(key => {
|
|
25502
|
+
var _a;
|
|
25503
|
+
if ((_a = modifiedResult[key]) === null || _a === void 0 ? void 0 : _a.isModified) {
|
|
25504
|
+
modifiedData[key] = {
|
|
25505
|
+
isModified: true,
|
|
25506
|
+
value: modifiedResult[key].value
|
|
25507
|
+
};
|
|
25508
|
+
} else {
|
|
25509
|
+
modifiedData[key] = {
|
|
25510
|
+
isModified: false,
|
|
25511
|
+
value: result[key]
|
|
25512
|
+
};
|
|
25513
|
+
}
|
|
25514
|
+
});
|
|
25515
|
+
return modifiedData;
|
|
25516
|
+
};
|
|
25517
|
+
const modifiedData2Result = modifiedResult => {
|
|
25518
|
+
const result = {};
|
|
25519
|
+
if (!modifiedResult) {
|
|
25520
|
+
console.error('modifiedData2Result: modifiedResult is empty');
|
|
25521
|
+
return;
|
|
25522
|
+
}
|
|
25523
|
+
Object.keys(modifiedResult).forEach(key => {
|
|
25524
|
+
result[key] = modifiedResult[key].value;
|
|
25525
|
+
});
|
|
25526
|
+
return result;
|
|
25527
|
+
};
|
|
25454
25528
|
|
|
25455
25529
|
const translateService = core.getTranslateInstance();
|
|
25456
25530
|
// TODO 處理參數
|
|
@@ -26235,7 +26309,7 @@ function startOCR(config) {
|
|
|
26235
26309
|
if (toastManualCapture) {
|
|
26236
26310
|
toastManualCapture.clear();
|
|
26237
26311
|
}
|
|
26238
|
-
return rxjs.from(type === idRecognition.EAuthMeCardClass.Passport && config.ocrConfig.disablePassportConfirm ? rxjs.of(false) : checkConfirmImageManual(canvasSizeInfo)).pipe(rxjs.switchMap(needRetry => {
|
|
26312
|
+
return rxjs.from(type === idRecognition.EAuthMeCardClass.Passport && config.ocrConfig.disablePassportConfirm || !config.ocrConfig.confirmPageEnabled ? rxjs.of(false) : checkConfirmImageManual(canvasSizeInfo)).pipe(rxjs.switchMap(needRetry => {
|
|
26239
26313
|
util.startSpinner(translateService.translate('sdk.general.uploading'));
|
|
26240
26314
|
if (needRetry) {
|
|
26241
26315
|
util.hideElement(confirmImageContainer);
|
|
@@ -26285,7 +26359,7 @@ function startOCR(config) {
|
|
|
26285
26359
|
})), rxjs.tap(() => received = true))))));
|
|
26286
26360
|
};
|
|
26287
26361
|
const autoCapture = canvasSizeInfo => {
|
|
26288
|
-
return rxjs.of(canvasSizeInfo).pipe(handleOcrSendFrame(canvasSizeInfo, image, video, config.recognition, 30, false,
|
|
26362
|
+
return rxjs.of(canvasSizeInfo).pipe(handleOcrSendFrame(canvasSizeInfo, image, video, config.recognition, 30, false, config.ocrConfig.resultImageFormat, cardType, type), rxjs.tap(x => applyTextByResult(x.result)), rxjs.filter(({
|
|
26289
26363
|
result
|
|
26290
26364
|
}) => result.eStatus === idRecognition.EAuthMeCardOCRStatus.Pass || result.eStatus === idRecognition.EAuthMeMRZServiceStatus.Success), rxjs.take(1), rxjs.tap(() => {
|
|
26291
26365
|
if (countdownCaptureTimer && countdownCaptureTimer.end && !countdownCaptureTimer.end()) {
|
|
@@ -26303,7 +26377,7 @@ function startOCR(config) {
|
|
|
26303
26377
|
util.hideElement(scanAnimationContainer);
|
|
26304
26378
|
}), rxjs.map(() => resp))), rxjs.switchMap(({
|
|
26305
26379
|
result
|
|
26306
|
-
}) => rxjs.from(type === idRecognition.EAuthMeCardClass.Passport && config.ocrConfig.disablePassportConfirm ? rxjs.of(false) : checkConfirmImage(result.imageData, result.iWidth, result.iHeight)).pipe(rxjs.switchMap(needRetry => {
|
|
26380
|
+
}) => rxjs.from(type === idRecognition.EAuthMeCardClass.Passport && config.ocrConfig.disablePassportConfirm || !config.ocrConfig.confirmPageEnabled ? rxjs.of(false) : checkConfirmImage(result.imageData, result.iWidth, result.iHeight)).pipe(rxjs.switchMap(needRetry => {
|
|
26307
26381
|
if (countdownCaptureTimer && countdownCaptureTimer.end) {
|
|
26308
26382
|
if (needRetry && !countdownCaptureTimer.end()) {
|
|
26309
26383
|
countdownCaptureTimer = countdownTimer(captureTimeoutTimer, () => {
|
|
@@ -26423,7 +26497,8 @@ function startOCR(config) {
|
|
|
26423
26497
|
}), rxjs.switchMap(canvasSizeInfo => rxjs.from(config.init(canvasSizeInfo.canvasWidth, canvasSizeInfo.canvasHeight)).pipe(rxjs.tap(x => ocrEngineConfig = x), rxjs.tap(() => __awaiter(this, void 0, void 0, function* () {
|
|
26424
26498
|
if (config.ocrConfig.needAntiFraud) return;
|
|
26425
26499
|
util.stopSpinner();
|
|
26426
|
-
})), rxjs.tap(() => eventListenerService$1.start())
|
|
26500
|
+
})), rxjs.tap(() => eventListenerService$1.start()) // TODO check useless
|
|
26501
|
+
)))).pipe(rxjs.tap(() => {
|
|
26427
26502
|
sendStatusAction$1(core.StatusAction.Uploading);
|
|
26428
26503
|
util.hideElement(videoContainer);
|
|
26429
26504
|
util.startSpinner(translateService.translate('sdk.general.uploading'));
|
|
@@ -26431,36 +26506,41 @@ function startOCR(config) {
|
|
|
26431
26506
|
setStatusEvent$1(cardClassResultMapping(config.acceptTypes[config.acceptTypes.length - 1]));
|
|
26432
26507
|
util.stopSpinner();
|
|
26433
26508
|
container.style.display = 'none';
|
|
26434
|
-
}), rxjs.concatMap(result => {
|
|
26509
|
+
}), rxjs.concatMap(result => __awaiter(this, void 0, void 0, function* () {
|
|
26435
26510
|
setStatusView(core.StatusView.Confirm);
|
|
26436
|
-
|
|
26437
|
-
|
|
26438
|
-
|
|
26439
|
-
|
|
26440
|
-
|
|
26441
|
-
|
|
26442
|
-
|
|
26443
|
-
|
|
26444
|
-
|
|
26445
|
-
|
|
26446
|
-
|
|
26447
|
-
|
|
26448
|
-
|
|
26449
|
-
|
|
26450
|
-
|
|
26451
|
-
|
|
26452
|
-
translate: key => translateService.translate(key)
|
|
26453
|
-
}
|
|
26454
|
-
})
|
|
26455
|
-
});
|
|
26511
|
+
let modifiedData = result2ModifiedData(result.details);
|
|
26512
|
+
if (config.ocrConfig.displayResultPage) {
|
|
26513
|
+
modifiedData = yield renderConfirmUI({
|
|
26514
|
+
cardType: config.ocrConfig.type,
|
|
26515
|
+
items: {
|
|
26516
|
+
columns: Object.keys(result.details).sort((a, b) => {
|
|
26517
|
+
const aScore = idRecognition.getRecognitionColumnOrder(a);
|
|
26518
|
+
const bScore = idRecognition.getRecognitionColumnOrder(b);
|
|
26519
|
+
return aScore - bScore || a.localeCompare(b);
|
|
26520
|
+
}),
|
|
26521
|
+
details: result.details
|
|
26522
|
+
},
|
|
26523
|
+
options: {
|
|
26524
|
+
headerIcon: config.ocrConfig.icon,
|
|
26525
|
+
translate: key => translateService.translate(key)
|
|
26526
|
+
}
|
|
26456
26527
|
});
|
|
26457
26528
|
}
|
|
26458
26529
|
flags.onConfirm = true;
|
|
26459
|
-
|
|
26460
|
-
|
|
26461
|
-
|
|
26462
|
-
|
|
26463
|
-
|
|
26530
|
+
util.Storage.setItem('scanId', result.scanId);
|
|
26531
|
+
util.Storage.setItem('data', result.details);
|
|
26532
|
+
util.Storage.setItem('confirmedData', modifiedData2Result(modifiedData));
|
|
26533
|
+
return {
|
|
26534
|
+
scanId: result.scanId,
|
|
26535
|
+
isSuccess: true,
|
|
26536
|
+
message: '',
|
|
26537
|
+
data: result.details,
|
|
26538
|
+
modifiedData: modifiedData,
|
|
26539
|
+
backCropImage: result.backCropImage,
|
|
26540
|
+
frontCropImage: result.frontCropImage,
|
|
26541
|
+
frontImage: result.frontImage,
|
|
26542
|
+
backImage: result.backImage
|
|
26543
|
+
};
|
|
26464
26544
|
})), rxjs.takeUntil(unsubscribe$), rxjs.finalize(() => {
|
|
26465
26545
|
sendStatusDescription$1(core.StatusDescription.Complete);
|
|
26466
26546
|
util.stopSpinner();
|
|
@@ -26470,7 +26550,7 @@ function startOCR(config) {
|
|
|
26470
26550
|
const type = currentType('get', null).type;
|
|
26471
26551
|
const cardType = currentType('get', null).cardType;
|
|
26472
26552
|
const ctx = image.getContext('2d');
|
|
26473
|
-
const imageData = util.getImageData(image, ctx, video, canvasSizeInfo, false,
|
|
26553
|
+
const imageData = util.getImageData(image, ctx, video, canvasSizeInfo, false, config.ocrConfig.resultImageFormat);
|
|
26474
26554
|
const imageBlob = util.UintArrayToBlob(canvasSizeInfo.width, canvasSizeInfo.height, imageData.data);
|
|
26475
26555
|
const cancelResultObj = {
|
|
26476
26556
|
isSuccess: false,
|
|
@@ -27430,13 +27510,28 @@ class LivenessModule {
|
|
|
27430
27510
|
const frameList = [];
|
|
27431
27511
|
const resultList = [];
|
|
27432
27512
|
let id = '';
|
|
27513
|
+
let pubKey = '';
|
|
27514
|
+
let shouldEncrypt = false;
|
|
27515
|
+
const encryptDataBase64 = data => __awaiter(this, void 0, void 0, function* () {
|
|
27516
|
+
const dataString = JSON.stringify(data);
|
|
27517
|
+
const encoder = new TextEncoder();
|
|
27518
|
+
const uint8Array = encoder.encode(dataString);
|
|
27519
|
+
// TODO check encrypt function
|
|
27520
|
+
const resultEncrypt = yield this.fasService.encryptBlob(uint8Array, pubKey);
|
|
27521
|
+
return resultEncrypt;
|
|
27522
|
+
});
|
|
27433
27523
|
try {
|
|
27434
27524
|
const result = yield rxjs.firstValueFrom(startLiveness({
|
|
27435
27525
|
init: () => __awaiter(this, void 0, void 0, function* () {
|
|
27526
|
+
var _a;
|
|
27436
27527
|
const resp = yield liveness.LivenessAPI.IdentityVerification.init(true, config.passive, config.compareCustomerClientId);
|
|
27437
27528
|
id = resp.id;
|
|
27438
|
-
|
|
27439
|
-
|
|
27529
|
+
pubKey = resp.parameters.pubKey;
|
|
27530
|
+
shouldEncrypt = (_a = resp.shouldEncrypt) !== null && _a !== void 0 ? _a : shouldEncrypt;
|
|
27531
|
+
if (!shouldEncrypt) {
|
|
27532
|
+
yield this.fasService.setPublicKeyForJson(pubKey);
|
|
27533
|
+
} else {
|
|
27534
|
+
yield this.fasService.setPublicKeyForJson('');
|
|
27440
27535
|
}
|
|
27441
27536
|
yield this.fasService.init();
|
|
27442
27537
|
const params = yield this.fasService.getParams();
|
|
@@ -27474,10 +27569,10 @@ class LivenessModule {
|
|
|
27474
27569
|
return params;
|
|
27475
27570
|
}),
|
|
27476
27571
|
onFrame: (data, base64) => __awaiter(this, void 0, void 0, function* () {
|
|
27477
|
-
var
|
|
27572
|
+
var _b;
|
|
27478
27573
|
const result = yield this.fasService.recognition(data);
|
|
27479
27574
|
if (this.canvas) {
|
|
27480
|
-
const debugData = yield (
|
|
27575
|
+
const debugData = yield (_b = this.fasService) === null || _b === void 0 ? void 0 : _b.getDebugImageData(data);
|
|
27481
27576
|
const ctx = this.canvas.getContext('2d');
|
|
27482
27577
|
this.canvas.width = frameWidth;
|
|
27483
27578
|
this.canvas.height = frameHeight;
|
|
@@ -27515,13 +27610,13 @@ class LivenessModule {
|
|
|
27515
27610
|
const meta = yield this.fasService.getReport();
|
|
27516
27611
|
yield SendRequestWithRetry$2(() => this.postResult(id, frameList, resultList, meta, {
|
|
27517
27612
|
uploadFullFrame: config.uploadFullFrame
|
|
27518
|
-
}));
|
|
27613
|
+
}, shouldEncrypt, encryptDataBase64));
|
|
27519
27614
|
const result = yield this.getResult(id);
|
|
27520
27615
|
return result.isPass;
|
|
27521
27616
|
}),
|
|
27522
27617
|
onDestroy: () => __awaiter(this, void 0, void 0, function* () {
|
|
27523
|
-
var
|
|
27524
|
-
yield (
|
|
27618
|
+
var _c;
|
|
27619
|
+
yield (_c = this.fasService) === null || _c === void 0 ? void 0 : _c.destroy();
|
|
27525
27620
|
}),
|
|
27526
27621
|
getNormalizedROI: () => __awaiter(this, void 0, void 0, function* () {
|
|
27527
27622
|
return yield this.fasService.getNormalizedFaceROI();
|
|
@@ -27560,7 +27655,7 @@ class LivenessModule {
|
|
|
27560
27655
|
}
|
|
27561
27656
|
});
|
|
27562
27657
|
}
|
|
27563
|
-
postResult(id, frameList, resultList, meta, options = {}) {
|
|
27658
|
+
postResult(id, frameList, resultList, meta, options = {}, shouldEncrypt, encryptDataBase64) {
|
|
27564
27659
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27565
27660
|
let uploadTarget = [];
|
|
27566
27661
|
// 1. iIsKeyFrame Image
|
|
@@ -27583,31 +27678,66 @@ class LivenessModule {
|
|
|
27583
27678
|
id,
|
|
27584
27679
|
index: x.index,
|
|
27585
27680
|
data: x.data
|
|
27586
|
-
})).map(body => this
|
|
27587
|
-
|
|
27681
|
+
})).map(body => __awaiter(this, void 0, void 0, function* () {
|
|
27682
|
+
var _a;
|
|
27683
|
+
// this.engine.getConfig().dataTransferMethod === 'base64'
|
|
27684
|
+
// ? LivenessAPI.IdentityVerification.uploadFrame(body)
|
|
27685
|
+
// : LivenessAPI.IdentityVerification.uploadFrameFile(body)
|
|
27686
|
+
if (shouldEncrypt) {
|
|
27687
|
+
body.data = (_a = body === null || body === void 0 ? void 0 : body.data) === null || _a === void 0 ? void 0 : _a.split('base64,')[1];
|
|
27688
|
+
return liveness.LivenessAPI.IdentityVerification.uploadFrame({
|
|
27689
|
+
id: body.id,
|
|
27690
|
+
encryptedBase64String: yield encryptDataBase64(body)
|
|
27691
|
+
});
|
|
27692
|
+
} else {
|
|
27693
|
+
return liveness.LivenessAPI.IdentityVerification.uploadFrameFile(body);
|
|
27694
|
+
}
|
|
27695
|
+
})));
|
|
27696
|
+
const postData = {
|
|
27588
27697
|
id,
|
|
27589
27698
|
data: meta
|
|
27590
|
-
}
|
|
27699
|
+
};
|
|
27700
|
+
if (shouldEncrypt) {
|
|
27701
|
+
postData.data = atob(meta);
|
|
27702
|
+
return liveness.LivenessAPI.IdentityVerification.uploadMeta({
|
|
27703
|
+
id: id,
|
|
27704
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
27705
|
+
});
|
|
27706
|
+
} else {
|
|
27707
|
+
return liveness.LivenessAPI.IdentityVerification.uploadMeta(postData);
|
|
27708
|
+
}
|
|
27709
|
+
// return LivenessAPI.IdentityVerification.uploadMeta({
|
|
27710
|
+
// id,
|
|
27711
|
+
// data: meta,
|
|
27712
|
+
// });
|
|
27591
27713
|
});
|
|
27592
27714
|
}
|
|
27715
|
+
|
|
27593
27716
|
getResult(id) {
|
|
27594
27717
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27595
|
-
|
|
27596
|
-
|
|
27597
|
-
|
|
27718
|
+
// while (result.state === LivenessResultStatus.UPLOADING) {
|
|
27719
|
+
// await waitTime(1000);
|
|
27720
|
+
// result = await LivenessAPI.IdentityVerification.getResult(id);
|
|
27721
|
+
// }
|
|
27722
|
+
// if (result.state === LivenessResultStatus.VALIDATING) {
|
|
27723
|
+
// return { ...result, isPass: true };
|
|
27724
|
+
// }
|
|
27725
|
+
const retryCount = 2;
|
|
27726
|
+
const loop = retryCount + 1;
|
|
27727
|
+
let result = {};
|
|
27728
|
+
for (let i = loop; i > 0; i--) {
|
|
27598
27729
|
result = yield liveness.LivenessAPI.IdentityVerification.getResult(id);
|
|
27599
|
-
|
|
27600
|
-
|
|
27601
|
-
|
|
27602
|
-
|
|
27603
|
-
});
|
|
27730
|
+
if (result.state === liveness.LivenessResultStatus.DONE) {
|
|
27731
|
+
return result;
|
|
27732
|
+
}
|
|
27733
|
+
yield util.waitTime(2000);
|
|
27604
27734
|
}
|
|
27605
27735
|
return result;
|
|
27606
27736
|
});
|
|
27607
27737
|
}
|
|
27608
27738
|
}
|
|
27609
27739
|
|
|
27610
|
-
function initFrameView(cardPoints, scanId, faceMode, scanView, cardType, cardTypeConfig, setBorderType, setCardBorderColor, setBorderSuccess) {
|
|
27740
|
+
function initFrameView(cardPoints, scanId, faceMode, scanView, cardType, cardTypeConfig, setBorderType, setCardBorderColor, setBorderSuccess, shouldEncrypt, encryptDataBase64) {
|
|
27611
27741
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27612
27742
|
const scanAnimationContainer = document.querySelector('.scan');
|
|
27613
27743
|
document.querySelector('#authme_frame_border');
|
|
@@ -27771,7 +27901,23 @@ function initFrameView(cardPoints, scanId, faceMode, scanView, cardType, cardTyp
|
|
|
27771
27901
|
for (let i = 0; i < scanViewSetting.content.length; i++) {
|
|
27772
27902
|
const contentSetting = scanViewSetting.content[i];
|
|
27773
27903
|
if (contentSetting.type === 'svg') {
|
|
27774
|
-
|
|
27904
|
+
let imageData;
|
|
27905
|
+
const postData = {
|
|
27906
|
+
scanId: scanId,
|
|
27907
|
+
ResourceId: contentSetting.content
|
|
27908
|
+
};
|
|
27909
|
+
if (shouldEncrypt) {
|
|
27910
|
+
imageData = yield idRecognition.initScanDocumentResourceBase64({
|
|
27911
|
+
id: scanId,
|
|
27912
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
27913
|
+
});
|
|
27914
|
+
} else {
|
|
27915
|
+
imageData = yield idRecognition.initScanDocumentResourceBase64(postData);
|
|
27916
|
+
}
|
|
27917
|
+
// const imageData = await initScanDocumentResourceBase64(
|
|
27918
|
+
// scanId,
|
|
27919
|
+
// contentSetting.content
|
|
27920
|
+
// );
|
|
27775
27921
|
frameImage(faceMode, i, imageData.data, contentSetting.color, contentSetting.opacity);
|
|
27776
27922
|
}
|
|
27777
27923
|
if (contentSetting.type === 'text') {
|
|
@@ -27816,6 +27962,7 @@ class MRZModule {
|
|
|
27816
27962
|
let latestTField = null;
|
|
27817
27963
|
const virtualCanvas = document.createElement('canvas');
|
|
27818
27964
|
const docInfos = {};
|
|
27965
|
+
let shouldEncrypt = false;
|
|
27819
27966
|
const encryptImageBase64 = blob => __awaiter(this, void 0, void 0, function* () {
|
|
27820
27967
|
const imageArrayBuffer = yield blobToArrayBuffer(blob);
|
|
27821
27968
|
const uint8Array = new Uint8Array(imageArrayBuffer);
|
|
@@ -27830,17 +27977,25 @@ class MRZModule {
|
|
|
27830
27977
|
reader.readAsArrayBuffer(blob);
|
|
27831
27978
|
});
|
|
27832
27979
|
});
|
|
27980
|
+
const encryptDataBase64 = data => __awaiter(this, void 0, void 0, function* () {
|
|
27981
|
+
const dataString = JSON.stringify(data);
|
|
27982
|
+
const encoder = new TextEncoder();
|
|
27983
|
+
const uint8Array = encoder.encode(dataString);
|
|
27984
|
+
const resultEncrypt = yield this.mrzService.encryptBlob(uint8Array, pubKey);
|
|
27985
|
+
return resultEncrypt;
|
|
27986
|
+
});
|
|
27833
27987
|
try {
|
|
27834
27988
|
return yield rxjs.firstValueFrom(startOCR({
|
|
27835
27989
|
ocrConfig: config,
|
|
27836
27990
|
init: (width, height) => __awaiter(this, void 0, void 0, function* () {
|
|
27837
|
-
var _a, _b;
|
|
27991
|
+
var _a, _b, _c;
|
|
27838
27992
|
frameWidth = width;
|
|
27839
27993
|
frameHeight = height;
|
|
27840
|
-
const resp = yield SendRequestWithRetry$1(() => idRecognition.
|
|
27994
|
+
const resp = yield SendRequestWithRetry$1(() => idRecognition.initScan(config.type, config.country, config.needConfirm, config.cardTypes));
|
|
27995
|
+
shouldEncrypt = (_a = resp.shouldEncrypt) !== null && _a !== void 0 ? _a : shouldEncrypt;
|
|
27841
27996
|
pubKey = resp.parameters.pubKey;
|
|
27842
27997
|
scanId = resp.scanId;
|
|
27843
|
-
uploadFullFrame = (
|
|
27998
|
+
uploadFullFrame = (_c = (_b = resp.parameters.fraud) === null || _b === void 0 ? void 0 : _b.collectAllFrames) !== null && _c !== void 0 ? _c : config.uploadFullFrame;
|
|
27844
27999
|
if (resp.parameters.pubKey) {
|
|
27845
28000
|
this.engine.setPublicKeyForJson(pubKey);
|
|
27846
28001
|
}
|
|
@@ -27859,7 +28014,20 @@ class MRZModule {
|
|
|
27859
28014
|
docInfos[type].ocrImg = null;
|
|
27860
28015
|
docInfos[type].ocrOriginImg = null;
|
|
27861
28016
|
} else {
|
|
27862
|
-
const resp = yield SendRequestWithRetry$1(() =>
|
|
28017
|
+
const resp = yield SendRequestWithRetry$1(() => __awaiter(this, void 0, void 0, function* () {
|
|
28018
|
+
const postData = {
|
|
28019
|
+
scanId: scanId,
|
|
28020
|
+
cardType: cardType
|
|
28021
|
+
};
|
|
28022
|
+
if (shouldEncrypt) {
|
|
28023
|
+
return idRecognition.initScanDocument({
|
|
28024
|
+
id: scanId,
|
|
28025
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
28026
|
+
});
|
|
28027
|
+
} else {
|
|
28028
|
+
return idRecognition.initScanDocument(postData);
|
|
28029
|
+
}
|
|
28030
|
+
}));
|
|
27863
28031
|
if (docInfos[type]) {
|
|
27864
28032
|
docInfos[type].docId = resp.scanDocumentId;
|
|
27865
28033
|
} else {
|
|
@@ -27872,17 +28040,17 @@ class MRZModule {
|
|
|
27872
28040
|
};
|
|
27873
28041
|
}
|
|
27874
28042
|
if (resp.scanView) {
|
|
27875
|
-
initFrameView(points, scanId, faceMode, resp.scanView, cardType, '', setBorderType, setCardBorderColor, setBorderSuccess);
|
|
28043
|
+
initFrameView(points, scanId, faceMode, resp.scanView, cardType, '', setBorderType, setCardBorderColor, setBorderSuccess, shouldEncrypt, encryptDataBase64);
|
|
27876
28044
|
}
|
|
27877
28045
|
}
|
|
27878
28046
|
return true;
|
|
27879
28047
|
}),
|
|
27880
28048
|
acceptTypes,
|
|
27881
28049
|
recognition: data => __awaiter(this, void 0, void 0, function* () {
|
|
27882
|
-
var
|
|
28050
|
+
var _d;
|
|
27883
28051
|
const mrzResult = yield this.mrzService.recognition(data);
|
|
27884
28052
|
if (this.canvas) {
|
|
27885
|
-
const debugData = yield (
|
|
28053
|
+
const debugData = yield (_d = this.mrzService) === null || _d === void 0 ? void 0 : _d.getDebugImageData(data);
|
|
27886
28054
|
const ctx = this.canvas.getContext('2d');
|
|
27887
28055
|
this.canvas.width = frameWidth;
|
|
27888
28056
|
this.canvas.height = frameHeight;
|
|
@@ -27925,8 +28093,34 @@ class MRZModule {
|
|
|
27925
28093
|
const image = util.UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas);
|
|
27926
28094
|
const requestImg = yield encryptImageBase64(image);
|
|
27927
28095
|
// downloadImage(image, `${frameIndex}-${docInfos[type as EAuthMeCardClass].docId}-${new Date().getTime().toString()}.jpg`)
|
|
27928
|
-
util.backgroundRequest(() =>
|
|
28096
|
+
util.backgroundRequest(() => __awaiter(this, void 0, void 0, function* () {
|
|
28097
|
+
const postData = {
|
|
28098
|
+
scanDocumentId: docInfos[idRecognition.EAuthMeCardClass.Passport].docId,
|
|
28099
|
+
image: requestImg,
|
|
28100
|
+
type: idRecognition.ResourceImageType.Recognition,
|
|
28101
|
+
info: {
|
|
28102
|
+
report: undefined,
|
|
28103
|
+
index: frameIndex++
|
|
28104
|
+
}
|
|
28105
|
+
};
|
|
28106
|
+
if (shouldEncrypt) {
|
|
28107
|
+
postData.image = yield blobToBase64(image);
|
|
28108
|
+
return idRecognition.uploadFrameBase64({
|
|
28109
|
+
id: scanId,
|
|
28110
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
28111
|
+
});
|
|
28112
|
+
} else {
|
|
28113
|
+
return idRecognition.uploadFrameBase64(postData);
|
|
28114
|
+
}
|
|
28115
|
+
})
|
|
28116
|
+
// uploadFrameBase64(
|
|
28117
|
+
// docInfos[EAuthMeCardClass.Passport].docId,
|
|
28118
|
+
// requestImg,
|
|
28119
|
+
// frameIndex++
|
|
28120
|
+
// )
|
|
28121
|
+
);
|
|
27929
28122
|
}
|
|
28123
|
+
|
|
27930
28124
|
const tField = latestTField;
|
|
27931
28125
|
if (!tField) {
|
|
27932
28126
|
return mrzResult;
|
|
@@ -27942,8 +28136,57 @@ class MRZModule {
|
|
|
27942
28136
|
docInfos[option.type].docId = '';
|
|
27943
28137
|
const requestImg = yield encryptImageBase64(docInfos[option.type].ocrOriginImg);
|
|
27944
28138
|
const report = yield this.mrzService.getReport();
|
|
27945
|
-
yield SendRequestWithRetry$1(() =>
|
|
27946
|
-
|
|
28139
|
+
yield SendRequestWithRetry$1(() => __awaiter(this, void 0, void 0, function* () {
|
|
28140
|
+
const postData = {
|
|
28141
|
+
scanDocumentId: docId,
|
|
28142
|
+
image: requestImg,
|
|
28143
|
+
type: idRecognition.ResourceImageType.Recognition,
|
|
28144
|
+
info: {
|
|
28145
|
+
report: report,
|
|
28146
|
+
index: frameIndex++
|
|
28147
|
+
}
|
|
28148
|
+
};
|
|
28149
|
+
if (shouldEncrypt) {
|
|
28150
|
+
postData.image = yield blobToBase64(docInfos[option.type].ocrOriginImg);
|
|
28151
|
+
return idRecognition.uploadFrameBase64({
|
|
28152
|
+
id: scanId,
|
|
28153
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
28154
|
+
});
|
|
28155
|
+
} else {
|
|
28156
|
+
return idRecognition.uploadFrameBase64(postData);
|
|
28157
|
+
}
|
|
28158
|
+
})
|
|
28159
|
+
// uploadFrameBase64(
|
|
28160
|
+
// docId,
|
|
28161
|
+
// requestImg,
|
|
28162
|
+
// frameIndex++,
|
|
28163
|
+
// ResourceImageType.Recognition,
|
|
28164
|
+
// report
|
|
28165
|
+
// )
|
|
28166
|
+
);
|
|
28167
|
+
|
|
28168
|
+
yield SendRequestWithRetry$1(() => __awaiter(this, void 0, void 0, function* () {
|
|
28169
|
+
const postData = {
|
|
28170
|
+
scanDocumentId: docId,
|
|
28171
|
+
details: latestTField !== null && latestTField !== void 0 ? latestTField : {},
|
|
28172
|
+
fraud: docInfos[option.type].fraudResult
|
|
28173
|
+
};
|
|
28174
|
+
if (shouldEncrypt) {
|
|
28175
|
+
return idRecognition.finishScanDocument({
|
|
28176
|
+
id: scanId,
|
|
28177
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
28178
|
+
});
|
|
28179
|
+
} else {
|
|
28180
|
+
return idRecognition.finishScanDocument(postData);
|
|
28181
|
+
}
|
|
28182
|
+
})
|
|
28183
|
+
// finishScanDocument(
|
|
28184
|
+
// docId,
|
|
28185
|
+
// latestTField ?? {},
|
|
28186
|
+
// docInfos[option.type].fraudResult
|
|
28187
|
+
// )
|
|
28188
|
+
);
|
|
28189
|
+
|
|
27947
28190
|
return true;
|
|
27948
28191
|
} else {
|
|
27949
28192
|
return false;
|
|
@@ -27958,14 +28201,14 @@ class MRZModule {
|
|
|
27958
28201
|
throw 'MRZ Fraud Not Supported.';
|
|
27959
28202
|
}),
|
|
27960
28203
|
setFrameSize: (width, height) => __awaiter(this, void 0, void 0, function* () {
|
|
27961
|
-
var
|
|
28204
|
+
var _e;
|
|
27962
28205
|
frameWidth = width;
|
|
27963
28206
|
frameHeight = height;
|
|
27964
|
-
yield (
|
|
28207
|
+
yield (_e = this.mrzService) === null || _e === void 0 ? void 0 : _e.setFrameSize(width, height);
|
|
27965
28208
|
}),
|
|
27966
28209
|
onSuccess: () => __awaiter(this, void 0, void 0, function* () {
|
|
27967
|
-
var
|
|
27968
|
-
(
|
|
28210
|
+
var _f;
|
|
28211
|
+
(_f = this.mrzService) === null || _f === void 0 ? void 0 : _f.destroy();
|
|
27969
28212
|
yield util.waitTime(1000);
|
|
27970
28213
|
return {
|
|
27971
28214
|
scanId: scanId,
|
|
@@ -27973,8 +28216,8 @@ class MRZModule {
|
|
|
27973
28216
|
};
|
|
27974
28217
|
}),
|
|
27975
28218
|
onDestroy: () => __awaiter(this, void 0, void 0, function* () {
|
|
27976
|
-
var
|
|
27977
|
-
yield (
|
|
28219
|
+
var _g;
|
|
28220
|
+
yield (_g = this.mrzService) === null || _g === void 0 ? void 0 : _g.destroy();
|
|
27978
28221
|
}),
|
|
27979
28222
|
getAntiFraudStageList: () => []
|
|
27980
28223
|
}));
|
|
@@ -28005,6 +28248,25 @@ function unionMerge(a, b) {
|
|
|
28005
28248
|
}
|
|
28006
28249
|
return result;
|
|
28007
28250
|
}
|
|
28251
|
+
// function blobToBase64(image: Blob): Promise<string> {
|
|
28252
|
+
// return new Promise((resolve, reject) => {
|
|
28253
|
+
// // Use FileReader to convert Blob to base64
|
|
28254
|
+
// const reader = new FileReader();
|
|
28255
|
+
// reader.onloadend = function () {
|
|
28256
|
+
// if (reader.result) {
|
|
28257
|
+
// // Strip off the data URL prefix to get just the base64-encoded bytes
|
|
28258
|
+
// const base64String = (reader.result as string).split(',')[1];
|
|
28259
|
+
// resolve(base64String);
|
|
28260
|
+
// } else {
|
|
28261
|
+
// reject(new Error('Failed to convert Blob to base64'));
|
|
28262
|
+
// }
|
|
28263
|
+
// };
|
|
28264
|
+
// reader.onerror = function (error) {
|
|
28265
|
+
// reject(error);
|
|
28266
|
+
// };
|
|
28267
|
+
// reader.readAsDataURL(image);
|
|
28268
|
+
// });
|
|
28269
|
+
// }
|
|
28008
28270
|
function SendRequestWithRetry(promiseFactory, options = {}) {
|
|
28009
28271
|
return util.retryPromiseWithCondition(promiseFactory, e => __awaiter(this, void 0, void 0, function* () {
|
|
28010
28272
|
var _a, _b, _c;
|
|
@@ -28182,6 +28444,11 @@ class OCRModule {
|
|
|
28182
28444
|
let frameIndex = 0;
|
|
28183
28445
|
let uploadFullFrame = false;
|
|
28184
28446
|
let fraudTimeout = DEFAULT_ANTI_FRAUD_TIMEOUT;
|
|
28447
|
+
let shouldEncrypt = false;
|
|
28448
|
+
let frontImage = null;
|
|
28449
|
+
let backImage = null;
|
|
28450
|
+
let frontCropImage = null;
|
|
28451
|
+
let backCropImage = null;
|
|
28185
28452
|
const {
|
|
28186
28453
|
getDebugLogsLength,
|
|
28187
28454
|
modifyDeubgLog,
|
|
@@ -28214,6 +28481,14 @@ class OCRModule {
|
|
|
28214
28481
|
reader.readAsArrayBuffer(blob);
|
|
28215
28482
|
});
|
|
28216
28483
|
});
|
|
28484
|
+
const encryptDataBase64 = data => __awaiter(this, void 0, void 0, function* () {
|
|
28485
|
+
const dataString = JSON.stringify(data);
|
|
28486
|
+
const encoder = new TextEncoder();
|
|
28487
|
+
const uint8Array = encoder.encode(dataString);
|
|
28488
|
+
const resultEncrypt = yield this.ocrService.encryptBlob(uint8Array, pubKey);
|
|
28489
|
+
return resultEncrypt;
|
|
28490
|
+
});
|
|
28491
|
+
util.Storage.setItem('encryptDataBase64', encryptDataBase64);
|
|
28217
28492
|
try {
|
|
28218
28493
|
const translateService = core.getTranslateInstance();
|
|
28219
28494
|
const eventNameWrong$ = new rxjs.Subject();
|
|
@@ -28221,11 +28496,11 @@ class OCRModule {
|
|
|
28221
28496
|
cardTypeConfigs: cardTypeConfigs,
|
|
28222
28497
|
ocrConfig: config,
|
|
28223
28498
|
init: (width, height) => __awaiter(this, void 0, void 0, function* () {
|
|
28224
|
-
var _a, _b, _c, _d;
|
|
28499
|
+
var _a, _b, _c, _d, _e;
|
|
28225
28500
|
frameWidth = width;
|
|
28226
28501
|
frameHeight = height;
|
|
28227
28502
|
const resp = yield SendRequestWithRetry(() => {
|
|
28228
|
-
return idRecognition.
|
|
28503
|
+
return idRecognition.initScan(config.type, config.country, config.needConfirm, config.cardTypes);
|
|
28229
28504
|
}, {
|
|
28230
28505
|
onErrorHandler(e) {
|
|
28231
28506
|
var _a, _b, _c;
|
|
@@ -28251,11 +28526,15 @@ class OCRModule {
|
|
|
28251
28526
|
}
|
|
28252
28527
|
});
|
|
28253
28528
|
scanId = resp.scanId;
|
|
28529
|
+
shouldEncrypt = (_a = resp.shouldEncrypt) !== null && _a !== void 0 ? _a : shouldEncrypt;
|
|
28530
|
+
util.Storage.setItem('shouldEncrypt', shouldEncrypt);
|
|
28254
28531
|
pubKey = resp.parameters.pubKey;
|
|
28255
|
-
uploadFullFrame = (
|
|
28256
|
-
fraudTimeout = (
|
|
28257
|
-
if (
|
|
28532
|
+
uploadFullFrame = (_c = (_b = resp.parameters.fraud) === null || _b === void 0 ? void 0 : _b.collectAllFrames) !== null && _c !== void 0 ? _c : config.uploadFullFrame;
|
|
28533
|
+
fraudTimeout = (_e = (_d = resp.parameters.fraud) === null || _d === void 0 ? void 0 : _d.totalTimeout) !== null && _e !== void 0 ? _e : DEFAULT_ANTI_FRAUD_TIMEOUT;
|
|
28534
|
+
if (!shouldEncrypt) {
|
|
28258
28535
|
this.engine.setPublicKeyForJson(pubKey);
|
|
28536
|
+
} else {
|
|
28537
|
+
this.engine.setPublicKeyForJson('');
|
|
28259
28538
|
}
|
|
28260
28539
|
if (config.type === idRecognition.IdRecognitionCardType.IDCard && config.needAntiFraud) {
|
|
28261
28540
|
yield this.antiFraudInstance.init();
|
|
@@ -28300,7 +28579,20 @@ class OCRModule {
|
|
|
28300
28579
|
docInfos[cardType].ocrImg = null;
|
|
28301
28580
|
docInfos[cardType].ocrOriginImg = null;
|
|
28302
28581
|
} else {
|
|
28303
|
-
const resp = yield SendRequestWithRetry(() =>
|
|
28582
|
+
const resp = yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
|
|
28583
|
+
const postData = {
|
|
28584
|
+
scanId: scanId,
|
|
28585
|
+
cardType: cardType
|
|
28586
|
+
};
|
|
28587
|
+
if (shouldEncrypt) {
|
|
28588
|
+
return idRecognition.initScanDocument({
|
|
28589
|
+
id: scanId,
|
|
28590
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
28591
|
+
});
|
|
28592
|
+
} else {
|
|
28593
|
+
return idRecognition.initScanDocument(postData);
|
|
28594
|
+
}
|
|
28595
|
+
}));
|
|
28304
28596
|
if (docInfos[cardType]) {
|
|
28305
28597
|
docInfos[cardType].docId = resp.scanDocumentId;
|
|
28306
28598
|
} else {
|
|
@@ -28370,7 +28662,23 @@ class OCRModule {
|
|
|
28370
28662
|
for (let i = 0; i < scanViewSetting.content.length; i++) {
|
|
28371
28663
|
const contentSetting = scanViewSetting.content[i];
|
|
28372
28664
|
if (contentSetting.type === 'svg') {
|
|
28373
|
-
|
|
28665
|
+
let imageData;
|
|
28666
|
+
const postData = {
|
|
28667
|
+
scanId: scanId,
|
|
28668
|
+
ResourceId: contentSetting.content
|
|
28669
|
+
};
|
|
28670
|
+
if (shouldEncrypt) {
|
|
28671
|
+
imageData = yield idRecognition.initScanDocumentResourceBase64({
|
|
28672
|
+
id: scanId,
|
|
28673
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
28674
|
+
});
|
|
28675
|
+
} else {
|
|
28676
|
+
imageData = yield idRecognition.initScanDocumentResourceBase64(postData);
|
|
28677
|
+
}
|
|
28678
|
+
// const imageData = await initScanDocumentResourceBase64(
|
|
28679
|
+
// scanId,
|
|
28680
|
+
// contentSetting.content
|
|
28681
|
+
// );
|
|
28374
28682
|
frameImage(faceMode, i, imageData.data, contentSetting.color, contentSetting.opacity);
|
|
28375
28683
|
}
|
|
28376
28684
|
if (contentSetting.type === 'text') {
|
|
@@ -28410,7 +28718,20 @@ class OCRModule {
|
|
|
28410
28718
|
docInfos[cardType].ocrImg = null;
|
|
28411
28719
|
docInfos[cardType].ocrOriginImg = null;
|
|
28412
28720
|
} else {
|
|
28413
|
-
const resp = yield SendRequestWithRetry(() =>
|
|
28721
|
+
const resp = yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
|
|
28722
|
+
const postData = {
|
|
28723
|
+
scanId: scanId,
|
|
28724
|
+
cardType: cardType
|
|
28725
|
+
};
|
|
28726
|
+
if (shouldEncrypt) {
|
|
28727
|
+
return idRecognition.initScanDocument({
|
|
28728
|
+
id: scanId,
|
|
28729
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
28730
|
+
});
|
|
28731
|
+
} else {
|
|
28732
|
+
return idRecognition.initScanDocument(postData);
|
|
28733
|
+
}
|
|
28734
|
+
}));
|
|
28414
28735
|
if (docInfos[cardType]) {
|
|
28415
28736
|
docInfos[cardType].docId = resp.scanDocumentId;
|
|
28416
28737
|
} else {
|
|
@@ -28534,7 +28855,23 @@ class OCRModule {
|
|
|
28534
28855
|
for (let i = 0; i < scanViewSetting.content.length; i++) {
|
|
28535
28856
|
const contentSetting = scanViewSetting.content[i];
|
|
28536
28857
|
if (contentSetting.type === 'svg') {
|
|
28537
|
-
|
|
28858
|
+
let imageData;
|
|
28859
|
+
const postData = {
|
|
28860
|
+
scanId: scanId,
|
|
28861
|
+
ResourceId: contentSetting.content
|
|
28862
|
+
};
|
|
28863
|
+
if (shouldEncrypt) {
|
|
28864
|
+
imageData = yield idRecognition.initScanDocumentResourceBase64({
|
|
28865
|
+
id: scanId,
|
|
28866
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
28867
|
+
});
|
|
28868
|
+
} else {
|
|
28869
|
+
imageData = yield idRecognition.initScanDocumentResourceBase64(postData);
|
|
28870
|
+
}
|
|
28871
|
+
// const imageData = await initScanDocumentResourceBase64(
|
|
28872
|
+
// scanId,
|
|
28873
|
+
// contentSetting.content
|
|
28874
|
+
// );
|
|
28538
28875
|
frameImage(faceMode, i, imageData.data, contentSetting.color, contentSetting.opacity);
|
|
28539
28876
|
}
|
|
28540
28877
|
if (contentSetting.type === 'text') {
|
|
@@ -28547,11 +28884,11 @@ class OCRModule {
|
|
|
28547
28884
|
};
|
|
28548
28885
|
}),
|
|
28549
28886
|
onThicknessFrame: (data, _base64, cardType, type) => __awaiter(this, void 0, void 0, function* () {
|
|
28550
|
-
var
|
|
28887
|
+
var _f, _g;
|
|
28551
28888
|
nextDebugRound(type);
|
|
28552
28889
|
const antiFraudRecogitionResult = yield functionLogging(() => __awaiter(this, void 0, void 0, function* () {
|
|
28553
|
-
var
|
|
28554
|
-
return yield (
|
|
28890
|
+
var _h;
|
|
28891
|
+
return yield (_h = this.antiFraudInstance) === null || _h === void 0 ? void 0 : _h.recognition(data);
|
|
28555
28892
|
}), {
|
|
28556
28893
|
runFunction: util.RUN_FUNCTION_NAME.ANTI_FARUD_RECOGNITION,
|
|
28557
28894
|
isAntiFraud: true
|
|
@@ -28560,7 +28897,7 @@ class OCRModule {
|
|
|
28560
28897
|
return antiFraudRecogitionResult;
|
|
28561
28898
|
}
|
|
28562
28899
|
if (this.canvas) {
|
|
28563
|
-
const debugData = yield (
|
|
28900
|
+
const debugData = yield (_f = this.antiFraudInstance) === null || _f === void 0 ? void 0 : _f.getDebugImageData(data);
|
|
28564
28901
|
const ctx = this.canvas.getContext('2d');
|
|
28565
28902
|
this.canvas.width = frameWidth;
|
|
28566
28903
|
this.canvas.height = frameHeight;
|
|
@@ -28572,12 +28909,12 @@ class OCRModule {
|
|
|
28572
28909
|
saveDebugImage({
|
|
28573
28910
|
data,
|
|
28574
28911
|
type,
|
|
28575
|
-
getDebugImageData: (
|
|
28912
|
+
getDebugImageData: (_g = this.antiFraudInstance) === null || _g === void 0 ? void 0 : _g.getDebugImageData.bind(this.antiFraudInstance),
|
|
28576
28913
|
result,
|
|
28577
28914
|
width: frameWidth,
|
|
28578
28915
|
height: frameHeight
|
|
28579
28916
|
});
|
|
28580
|
-
const fraudOriginImg = util.UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas);
|
|
28917
|
+
const fraudOriginImg = util.UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas, config.resultImageFormat);
|
|
28581
28918
|
const thicknessResult = Object.assign(Object.assign({}, antiFraudRecogitionResult), {
|
|
28582
28919
|
imageData: data
|
|
28583
28920
|
});
|
|
@@ -28594,10 +28931,27 @@ class OCRModule {
|
|
|
28594
28931
|
isAntiFraud: true
|
|
28595
28932
|
});
|
|
28596
28933
|
frameIndex++;
|
|
28597
|
-
util.backgroundRequest(() =>
|
|
28598
|
-
|
|
28934
|
+
util.backgroundRequest(() => __awaiter(this, void 0, void 0, function* () {
|
|
28935
|
+
const postData = {
|
|
28936
|
+
scanDocumentId: docId,
|
|
28937
|
+
image: requestImg,
|
|
28938
|
+
type: idRecognition.ResourceImageType.Recognition,
|
|
28939
|
+
info: {
|
|
28940
|
+
report: undefined,
|
|
28941
|
+
index: frameIndex
|
|
28942
|
+
}
|
|
28943
|
+
};
|
|
28944
|
+
if (shouldEncrypt) {
|
|
28945
|
+
postData.image = yield blobToBase64(fraudOriginImg);
|
|
28946
|
+
return idRecognition.uploadFrameBase64({
|
|
28947
|
+
id: scanId,
|
|
28948
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
28949
|
+
});
|
|
28950
|
+
} else {
|
|
28951
|
+
return idRecognition.uploadFrameBase64(postData);
|
|
28952
|
+
}
|
|
28953
|
+
}));
|
|
28599
28954
|
}
|
|
28600
|
-
|
|
28601
28955
|
return thicknessResult;
|
|
28602
28956
|
}),
|
|
28603
28957
|
confirmThickness: (imageData, cardType) => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -28605,8 +28959,53 @@ class OCRModule {
|
|
|
28605
28959
|
const docId = docInfos[cardType].docId;
|
|
28606
28960
|
const requestImg = yield encryptImageBase64(imageData);
|
|
28607
28961
|
try {
|
|
28608
|
-
yield SendRequestWithRetry(() =>
|
|
28609
|
-
|
|
28962
|
+
yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
|
|
28963
|
+
const postData = {
|
|
28964
|
+
scanDocumentId: docId,
|
|
28965
|
+
image: requestImg,
|
|
28966
|
+
type: idRecognition.ResourceImageType.Attach,
|
|
28967
|
+
info: {
|
|
28968
|
+
report: undefined,
|
|
28969
|
+
index: frameIndex
|
|
28970
|
+
}
|
|
28971
|
+
};
|
|
28972
|
+
if (shouldEncrypt) {
|
|
28973
|
+
postData.image = yield blobToBase64(imageData);
|
|
28974
|
+
return idRecognition.uploadFrameBase64({
|
|
28975
|
+
id: scanId,
|
|
28976
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
28977
|
+
});
|
|
28978
|
+
} else {
|
|
28979
|
+
return idRecognition.uploadFrameBase64(postData);
|
|
28980
|
+
}
|
|
28981
|
+
})
|
|
28982
|
+
// uploadFrameBase64(
|
|
28983
|
+
// docId,
|
|
28984
|
+
// requestImg,
|
|
28985
|
+
// frameIndex,
|
|
28986
|
+
// ResourceImageType.Attach,
|
|
28987
|
+
// undefined
|
|
28988
|
+
// )
|
|
28989
|
+
);
|
|
28990
|
+
|
|
28991
|
+
yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
|
|
28992
|
+
const postData = {
|
|
28993
|
+
scanDocumentId: docId,
|
|
28994
|
+
details: {},
|
|
28995
|
+
fraud: null
|
|
28996
|
+
};
|
|
28997
|
+
if (shouldEncrypt) {
|
|
28998
|
+
return idRecognition.finishScanDocument({
|
|
28999
|
+
id: scanId,
|
|
29000
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
29001
|
+
});
|
|
29002
|
+
} else {
|
|
29003
|
+
return idRecognition.finishScanDocument(postData);
|
|
29004
|
+
}
|
|
29005
|
+
})
|
|
29006
|
+
// finishScanDocument(docId, {}, null)
|
|
29007
|
+
);
|
|
29008
|
+
|
|
28610
29009
|
return true;
|
|
28611
29010
|
} catch (error) {
|
|
28612
29011
|
console.error('confirmThickness:', error);
|
|
@@ -28642,10 +29041,10 @@ class OCRModule {
|
|
|
28642
29041
|
width: frameWidth,
|
|
28643
29042
|
height: frameHeight
|
|
28644
29043
|
});
|
|
28645
|
-
const ocrOriginImg = util.UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas);
|
|
29044
|
+
const ocrOriginImg = util.UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas, config.resultImageFormat);
|
|
28646
29045
|
const eClass = cardType !== null && cardType !== void 0 ? cardType : '';
|
|
28647
29046
|
if (result.eStatus === idRecognition.EAuthMeCardOCRStatus.Pass && result.imageData && !!docInfos[eClass].docId) {
|
|
28648
|
-
const resultOcrImg = util.UintArrayToBlob(result.iWidth, result.iHeight, result === null || result === void 0 ? void 0 : result.imageData, virtualCanvas);
|
|
29047
|
+
const resultOcrImg = util.UintArrayToBlob(result.iWidth, result.iHeight, result === null || result === void 0 ? void 0 : result.imageData, virtualCanvas, config.resultImageFormat);
|
|
28649
29048
|
docInfos[eClass].ocrImg = resultOcrImg;
|
|
28650
29049
|
docInfos[eClass].ocrOriginImg = ocrOriginImg;
|
|
28651
29050
|
yield _service.stop();
|
|
@@ -28664,7 +29063,38 @@ class OCRModule {
|
|
|
28664
29063
|
const requestImg = yield encryptImageBase64(image);
|
|
28665
29064
|
// downloadImage(image, `${frameIndex}-${docInfos[type as EAuthMeCardClass].docId}-${new Date().getTime().toString()}.jpg`)
|
|
28666
29065
|
frameIndex++;
|
|
28667
|
-
util.backgroundRequest(() =>
|
|
29066
|
+
util.backgroundRequest(() => __awaiter(this, void 0, void 0, function* () {
|
|
29067
|
+
console.log('recognition', docInfos[cardType !== null && cardType !== void 0 ? cardType : ''].docId);
|
|
29068
|
+
if (docInfos[eClass].docId === '') {
|
|
29069
|
+
console.warn('didnt find docid, retry');
|
|
29070
|
+
return false;
|
|
29071
|
+
}
|
|
29072
|
+
const postData = {
|
|
29073
|
+
scanDocumentId: docInfos[cardType !== null && cardType !== void 0 ? cardType : ''].docId,
|
|
29074
|
+
image: requestImg,
|
|
29075
|
+
type: idRecognition.ResourceImageType.Recognition,
|
|
29076
|
+
info: {
|
|
29077
|
+
report: undefined,
|
|
29078
|
+
index: frameIndex
|
|
29079
|
+
}
|
|
29080
|
+
};
|
|
29081
|
+
if (shouldEncrypt) {
|
|
29082
|
+
postData.image = yield blobToBase64(image);
|
|
29083
|
+
return idRecognition.uploadFrameBase64({
|
|
29084
|
+
id: scanId,
|
|
29085
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
29086
|
+
});
|
|
29087
|
+
} else {
|
|
29088
|
+
return idRecognition.uploadFrameBase64(postData);
|
|
29089
|
+
}
|
|
29090
|
+
})
|
|
29091
|
+
// uploadFrameBase64(
|
|
29092
|
+
// docInfos[cardType ?? ''].docId,
|
|
29093
|
+
// requestImg,
|
|
29094
|
+
// frameIndex
|
|
29095
|
+
// )
|
|
29096
|
+
);
|
|
29097
|
+
|
|
28668
29098
|
pushNewDebugImage(ocrOriginImg, {
|
|
28669
29099
|
result: result,
|
|
28670
29100
|
status: 'recognition',
|
|
@@ -28689,45 +29119,131 @@ class OCRModule {
|
|
|
28689
29119
|
this.ocrService.stop();
|
|
28690
29120
|
}
|
|
28691
29121
|
const docId = docInfos[option.cardType].docId;
|
|
28692
|
-
if (docId) {
|
|
28693
|
-
|
|
28694
|
-
|
|
28695
|
-
|
|
28696
|
-
|
|
29122
|
+
if (!docId) {
|
|
29123
|
+
console.warn('didnt find docid , retry');
|
|
29124
|
+
return false;
|
|
29125
|
+
}
|
|
29126
|
+
const ocrImg = option.imageData ? option.imageData : docInfos[option.cardType].ocrImg;
|
|
29127
|
+
const needFraudOption = config.needAntiFraud && option.type === engine.EAuthMeCardClass.TWN_IDCard_Front;
|
|
29128
|
+
let ocrOriginImg;
|
|
29129
|
+
if (option.imageData) {
|
|
29130
|
+
ocrOriginImg = option.imageData;
|
|
29131
|
+
} else {
|
|
29132
|
+
ocrOriginImg = docInfos[option.cardType].ocrOriginImg;
|
|
29133
|
+
}
|
|
29134
|
+
// const base64Image = await blobToBase64(ocrOriginImg);
|
|
29135
|
+
// console.log('confirmImage', base64Image);
|
|
29136
|
+
const requestImg = yield encryptImageBase64(ocrOriginImg);
|
|
29137
|
+
const report = yield this.ocrService.getReport();
|
|
29138
|
+
docInfos[option.cardType].docId = '';
|
|
29139
|
+
modifyDeubgLog(getDebugLogsLength() - 1, {
|
|
29140
|
+
report: report
|
|
29141
|
+
});
|
|
29142
|
+
frameIndex++;
|
|
29143
|
+
yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
|
|
29144
|
+
const postData = {
|
|
29145
|
+
scanDocumentId: docId,
|
|
29146
|
+
image: requestImg,
|
|
29147
|
+
type: idRecognition.ResourceImageType.Recognition,
|
|
29148
|
+
info: {
|
|
29149
|
+
report: report,
|
|
29150
|
+
index: frameIndex
|
|
29151
|
+
}
|
|
29152
|
+
};
|
|
29153
|
+
if (shouldEncrypt) {
|
|
29154
|
+
postData.image = yield blobToBase64(ocrOriginImg);
|
|
29155
|
+
return idRecognition.uploadFrameBase64({
|
|
29156
|
+
id: scanId,
|
|
29157
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
29158
|
+
});
|
|
28697
29159
|
} else {
|
|
28698
|
-
|
|
29160
|
+
return idRecognition.uploadFrameBase64(postData);
|
|
28699
29161
|
}
|
|
28700
|
-
|
|
28701
|
-
|
|
28702
|
-
|
|
28703
|
-
|
|
28704
|
-
|
|
28705
|
-
|
|
28706
|
-
|
|
28707
|
-
|
|
28708
|
-
|
|
28709
|
-
|
|
28710
|
-
|
|
28711
|
-
|
|
28712
|
-
|
|
28713
|
-
|
|
28714
|
-
const
|
|
28715
|
-
|
|
28716
|
-
|
|
28717
|
-
|
|
29162
|
+
})
|
|
29163
|
+
// uploadFrameBase64(
|
|
29164
|
+
// docId,
|
|
29165
|
+
// requestImg,
|
|
29166
|
+
// frameIndex,
|
|
29167
|
+
// ResourceImageType.Recognition,
|
|
29168
|
+
// report
|
|
29169
|
+
// )
|
|
29170
|
+
);
|
|
29171
|
+
|
|
29172
|
+
frameIndex = 0;
|
|
29173
|
+
try {
|
|
29174
|
+
const _requestImg = yield encryptImageBase64(ocrImg);
|
|
29175
|
+
const resp = yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
|
|
29176
|
+
const postData = {
|
|
29177
|
+
scanDocumentId: docId,
|
|
29178
|
+
image: _requestImg,
|
|
29179
|
+
fileType: idRecognition.RecognitionFileType.FlatImage,
|
|
29180
|
+
info: {
|
|
29181
|
+
report: report
|
|
29182
|
+
}
|
|
29183
|
+
};
|
|
29184
|
+
let response;
|
|
29185
|
+
if (shouldEncrypt) {
|
|
29186
|
+
postData.image = yield blobToBase64(ocrImg);
|
|
29187
|
+
response = yield idRecognition.recognizeBase64({
|
|
29188
|
+
id: scanId,
|
|
29189
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
29190
|
+
});
|
|
29191
|
+
} else {
|
|
29192
|
+
response = yield idRecognition.recognizeBase64(postData);
|
|
28718
29193
|
}
|
|
28719
|
-
|
|
28720
|
-
|
|
28721
|
-
|
|
28722
|
-
|
|
28723
|
-
|
|
28724
|
-
|
|
28725
|
-
|
|
28726
|
-
|
|
28727
|
-
|
|
29194
|
+
if (response === null || response === void 0 ? void 0 : response.detectCardResult) {
|
|
29195
|
+
if (option.cardType.toLocaleLowerCase().includes('front')) {
|
|
29196
|
+
frontImage = yield blobToImageBase64(ocrOriginImg);
|
|
29197
|
+
frontCropImage = yield blobToImageBase64(ocrImg);
|
|
29198
|
+
}
|
|
29199
|
+
if (option.cardType.toLocaleLowerCase().includes('back')) {
|
|
29200
|
+
backImage = yield blobToImageBase64(ocrOriginImg);
|
|
29201
|
+
backCropImage = yield blobToImageBase64(ocrImg);
|
|
29202
|
+
}
|
|
29203
|
+
}
|
|
29204
|
+
return response;
|
|
29205
|
+
})
|
|
29206
|
+
// recognizeBase64(
|
|
29207
|
+
// docId,
|
|
29208
|
+
// requestImg,
|
|
29209
|
+
// report,
|
|
29210
|
+
// RecognitionFileType.FlatImage
|
|
29211
|
+
// )
|
|
29212
|
+
);
|
|
29213
|
+
|
|
29214
|
+
if (resp.retry) {
|
|
29215
|
+
yield util.asyncShowPopup(translateService.translate('sdk.verify.error.blurRetake.title'), translateService.translate('sdk.verify.error.blurRetake.content'), true);
|
|
29216
|
+
throw 'recognition failed';
|
|
28728
29217
|
}
|
|
28729
|
-
|
|
28730
|
-
|
|
29218
|
+
result = unionMerge(result, resp && resp.details || {});
|
|
29219
|
+
yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
|
|
29220
|
+
const postData = {
|
|
29221
|
+
scanDocumentId: docId,
|
|
29222
|
+
details: resp.details,
|
|
29223
|
+
fraud: needFraudOption ? this.fraudResult : null
|
|
29224
|
+
};
|
|
29225
|
+
if (shouldEncrypt) {
|
|
29226
|
+
return idRecognition.finishScanDocument({
|
|
29227
|
+
id: scanId,
|
|
29228
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
29229
|
+
});
|
|
29230
|
+
} else {
|
|
29231
|
+
return idRecognition.finishScanDocument(postData);
|
|
29232
|
+
}
|
|
29233
|
+
})
|
|
29234
|
+
// finishScanDocument(
|
|
29235
|
+
// docId,
|
|
29236
|
+
// resp.details,
|
|
29237
|
+
// needFraudOption ? this.fraudResult : null
|
|
29238
|
+
// )
|
|
29239
|
+
);
|
|
29240
|
+
|
|
29241
|
+
delete docInfos[option.cardType];
|
|
29242
|
+
return true;
|
|
29243
|
+
} catch (error) {
|
|
29244
|
+
console.log('confirmImage fail,retrying ');
|
|
29245
|
+
console.error(error);
|
|
29246
|
+
docInfos[option.cardType].docId = docId;
|
|
28731
29247
|
return false;
|
|
28732
29248
|
}
|
|
28733
29249
|
}),
|
|
@@ -28748,7 +29264,35 @@ class OCRModule {
|
|
|
28748
29264
|
report: report
|
|
28749
29265
|
});
|
|
28750
29266
|
frameIndex++;
|
|
28751
|
-
SendRequestWithRetry(() =>
|
|
29267
|
+
SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
|
|
29268
|
+
const postData = {
|
|
29269
|
+
scanDocumentId: docId,
|
|
29270
|
+
image: requestImg,
|
|
29271
|
+
type: idRecognition.ResourceImageType.Recognition,
|
|
29272
|
+
info: {
|
|
29273
|
+
report: report,
|
|
29274
|
+
index: frameIndex
|
|
29275
|
+
}
|
|
29276
|
+
};
|
|
29277
|
+
if (shouldEncrypt) {
|
|
29278
|
+
postData.image = yield blobToBase64(ocrOriginImg);
|
|
29279
|
+
return idRecognition.uploadFrameBase64({
|
|
29280
|
+
id: scanId,
|
|
29281
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
29282
|
+
});
|
|
29283
|
+
} else {
|
|
29284
|
+
return idRecognition.uploadFrameBase64(postData);
|
|
29285
|
+
}
|
|
29286
|
+
})
|
|
29287
|
+
// uploadFrameBase64(
|
|
29288
|
+
// docId,
|
|
29289
|
+
// requestImg,
|
|
29290
|
+
// frameIndex,
|
|
29291
|
+
// ResourceImageType.Recognition,
|
|
29292
|
+
// report
|
|
29293
|
+
// )
|
|
29294
|
+
);
|
|
29295
|
+
|
|
28752
29296
|
frameIndex = 0;
|
|
28753
29297
|
return true;
|
|
28754
29298
|
} else {
|
|
@@ -28776,7 +29320,20 @@ class OCRModule {
|
|
|
28776
29320
|
fraudOriginImg: null,
|
|
28777
29321
|
fraudResult: false
|
|
28778
29322
|
};
|
|
28779
|
-
const resp = yield SendRequestWithRetry(() =>
|
|
29323
|
+
const resp = yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
|
|
29324
|
+
const postData = {
|
|
29325
|
+
scanId: scanId,
|
|
29326
|
+
cardType: idRecognition.twoWayAuthmeCardClassMap.toServer(twnidCardFront)
|
|
29327
|
+
};
|
|
29328
|
+
if (shouldEncrypt) {
|
|
29329
|
+
return idRecognition.initScanDocument({
|
|
29330
|
+
id: scanId,
|
|
29331
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
29332
|
+
});
|
|
29333
|
+
} else {
|
|
29334
|
+
return idRecognition.initScanDocument(postData);
|
|
29335
|
+
}
|
|
29336
|
+
}));
|
|
28780
29337
|
if (docInfos[twnidCardFront]) {
|
|
28781
29338
|
docInfos[twnidCardFront].docId = resp.scanDocumentId;
|
|
28782
29339
|
} else {
|
|
@@ -28802,12 +29359,12 @@ class OCRModule {
|
|
|
28802
29359
|
return true;
|
|
28803
29360
|
}),
|
|
28804
29361
|
onAntiFraudFrame: data => __awaiter(this, void 0, void 0, function* () {
|
|
28805
|
-
var
|
|
29362
|
+
var _j, _k;
|
|
28806
29363
|
const type = engine.EAuthMeCardClass.TWN_IDCard_Front;
|
|
28807
29364
|
nextDebugRound(type);
|
|
28808
29365
|
const antiFraudRecogitionResult = yield functionLogging(() => __awaiter(this, void 0, void 0, function* () {
|
|
28809
|
-
var
|
|
28810
|
-
return yield (
|
|
29366
|
+
var _l;
|
|
29367
|
+
return yield (_l = this.antiFraudInstance) === null || _l === void 0 ? void 0 : _l.recognition(data);
|
|
28811
29368
|
}), {
|
|
28812
29369
|
runFunction: util.RUN_FUNCTION_NAME.ANTI_FARUD_RECOGNITION,
|
|
28813
29370
|
isAntiFraud: true
|
|
@@ -28816,7 +29373,7 @@ class OCRModule {
|
|
|
28816
29373
|
return antiFraudRecogitionResult;
|
|
28817
29374
|
}
|
|
28818
29375
|
if (this.canvas) {
|
|
28819
|
-
const debugData = yield (
|
|
29376
|
+
const debugData = yield (_j = this.antiFraudInstance) === null || _j === void 0 ? void 0 : _j.getDebugImageData(data);
|
|
28820
29377
|
const ctx = this.canvas.getContext('2d');
|
|
28821
29378
|
this.canvas.width = frameWidth;
|
|
28822
29379
|
this.canvas.height = frameHeight;
|
|
@@ -28828,12 +29385,12 @@ class OCRModule {
|
|
|
28828
29385
|
saveDebugImage({
|
|
28829
29386
|
data,
|
|
28830
29387
|
type,
|
|
28831
|
-
getDebugImageData: (
|
|
29388
|
+
getDebugImageData: (_k = this.antiFraudInstance) === null || _k === void 0 ? void 0 : _k.getDebugImageData.bind(this.antiFraudInstance),
|
|
28832
29389
|
result,
|
|
28833
29390
|
width: frameWidth,
|
|
28834
29391
|
height: frameHeight
|
|
28835
29392
|
});
|
|
28836
|
-
const fraudOriginImg = util.UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas);
|
|
29393
|
+
const fraudOriginImg = util.UintArrayToBlob(frameWidth, frameHeight, data, virtualCanvas, config.resultImageFormat);
|
|
28837
29394
|
if (antiFraudRecogitionResult.eStatus === idRecognition.EAuthMeIDCardAntiFraudStatus.Pass || antiFraudRecogitionResult.eStatus === idRecognition.EAuthMeIDCardAntiFraudStatus.Failed) {
|
|
28838
29395
|
docInfos[type].fraudOriginImg = fraudOriginImg;
|
|
28839
29396
|
this.fraudResult = antiFraudRecogitionResult.eStatus === idRecognition.EAuthMeIDCardAntiFraudStatus.Pass;
|
|
@@ -28850,7 +29407,35 @@ class OCRModule {
|
|
|
28850
29407
|
isAntiFraud: true
|
|
28851
29408
|
});
|
|
28852
29409
|
frameIndex++;
|
|
28853
|
-
yield SendRequestWithRetry(() =>
|
|
29410
|
+
yield SendRequestWithRetry(() => __awaiter(this, void 0, void 0, function* () {
|
|
29411
|
+
const postData = {
|
|
29412
|
+
scanDocumentId: docId,
|
|
29413
|
+
image: requestImg,
|
|
29414
|
+
type: idRecognition.ResourceImageType.Fraud,
|
|
29415
|
+
info: {
|
|
29416
|
+
report: report,
|
|
29417
|
+
index: frameIndex
|
|
29418
|
+
}
|
|
29419
|
+
};
|
|
29420
|
+
if (shouldEncrypt) {
|
|
29421
|
+
postData.image = yield blobToBase64(ocrImg);
|
|
29422
|
+
return idRecognition.uploadFrameBase64({
|
|
29423
|
+
id: scanId,
|
|
29424
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
29425
|
+
});
|
|
29426
|
+
} else {
|
|
29427
|
+
return idRecognition.uploadFrameBase64(postData);
|
|
29428
|
+
}
|
|
29429
|
+
})
|
|
29430
|
+
// uploadFrameBase64(
|
|
29431
|
+
// docId,
|
|
29432
|
+
// requestImg,
|
|
29433
|
+
// frameIndex,
|
|
29434
|
+
// ResourceImageType.Fraud,
|
|
29435
|
+
// report
|
|
29436
|
+
// )
|
|
29437
|
+
);
|
|
29438
|
+
|
|
28854
29439
|
frameIndex = 0;
|
|
28855
29440
|
yield this.antiFraudInstance.destroy();
|
|
28856
29441
|
} else if (uploadFullFrame) {
|
|
@@ -28864,49 +29449,86 @@ class OCRModule {
|
|
|
28864
29449
|
isAntiFraud: true
|
|
28865
29450
|
});
|
|
28866
29451
|
frameIndex++;
|
|
28867
|
-
util.backgroundRequest(() =>
|
|
29452
|
+
util.backgroundRequest(() => __awaiter(this, void 0, void 0, function* () {
|
|
29453
|
+
const postData = {
|
|
29454
|
+
scanDocumentId: docId,
|
|
29455
|
+
image: requestImg,
|
|
29456
|
+
type: idRecognition.ResourceImageType.Fraud,
|
|
29457
|
+
info: {
|
|
29458
|
+
report: undefined,
|
|
29459
|
+
index: frameIndex
|
|
29460
|
+
}
|
|
29461
|
+
};
|
|
29462
|
+
if (shouldEncrypt) {
|
|
29463
|
+
postData.image = yield blobToBase64(fraudOriginImg);
|
|
29464
|
+
return idRecognition.uploadFrameBase64({
|
|
29465
|
+
id: scanId,
|
|
29466
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
29467
|
+
});
|
|
29468
|
+
} else {
|
|
29469
|
+
return idRecognition.uploadFrameBase64(postData);
|
|
29470
|
+
}
|
|
29471
|
+
})
|
|
29472
|
+
// uploadFrameBase64(
|
|
29473
|
+
// docId,
|
|
29474
|
+
// requestImg,
|
|
29475
|
+
// frameIndex,
|
|
29476
|
+
// ResourceImageType.Fraud
|
|
29477
|
+
// )
|
|
29478
|
+
);
|
|
28868
29479
|
}
|
|
29480
|
+
|
|
28869
29481
|
return antiFraudRecogitionResult;
|
|
28870
29482
|
}),
|
|
28871
29483
|
getAntiFraudStageList: () => {
|
|
28872
29484
|
return antiFraudStageList;
|
|
28873
29485
|
},
|
|
28874
29486
|
setFrameSize: (width, height, points) => __awaiter(this, void 0, void 0, function* () {
|
|
28875
|
-
var
|
|
29487
|
+
var _m, _o, _p, _q;
|
|
28876
29488
|
frameWidth = width;
|
|
28877
29489
|
frameHeight = height;
|
|
28878
|
-
yield (
|
|
28879
|
-
yield (
|
|
29490
|
+
yield (_m = this.ocrService) === null || _m === void 0 ? void 0 : _m.setFrameSize(width, height);
|
|
29491
|
+
yield (_o = this.antiFraudInstance) === null || _o === void 0 ? void 0 : _o.setFrameSize(width, height);
|
|
28880
29492
|
if (config.type === idRecognition.IdRecognitionCardType.ResidentCard) {
|
|
28881
29493
|
// workaround: resident card need MRZ, refactor later.
|
|
28882
|
-
yield (
|
|
29494
|
+
yield (_p = this.residentCardMrzService) === null || _p === void 0 ? void 0 : _p.setFrameSize(width, height);
|
|
28883
29495
|
}
|
|
28884
29496
|
if (points) {
|
|
28885
|
-
yield (
|
|
29497
|
+
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
29498
|
}
|
|
28887
29499
|
}),
|
|
28888
29500
|
onSuccess: () => __awaiter(this, void 0, void 0, function* () {
|
|
28889
|
-
var
|
|
29501
|
+
var _r, _s, _t;
|
|
28890
29502
|
durationTime.end();
|
|
28891
29503
|
const ocrIdcardResultFormat = util.Storage.getItem(util.STORAGE_KEY['OCR_IDCARD_RESULT_FORMAT']);
|
|
28892
|
-
(
|
|
28893
|
-
(
|
|
29504
|
+
(_r = this.antiFraudInstance) === null || _r === void 0 ? void 0 : _r.destroy();
|
|
29505
|
+
(_s = this.ocrService) === null || _s === void 0 ? void 0 : _s.destroy();
|
|
28894
29506
|
// workaround: resident card need MRZ, refactor later.
|
|
28895
|
-
(
|
|
29507
|
+
(_t = this.residentCardMrzService) === null || _t === void 0 ? void 0 : _t.destroy();
|
|
28896
29508
|
if (config.type === idRecognition.IdRecognitionCardType.IDCard && ocrIdcardResultFormat === 'splitDateAndAddress') {
|
|
28897
29509
|
result = util.splitResult(result);
|
|
28898
29510
|
}
|
|
28899
29511
|
yield util.waitTime(1000);
|
|
29512
|
+
// if (Object.keys(result).length === 0) {
|
|
29513
|
+
// frontCropImage = null;
|
|
29514
|
+
// backCropImage = null;
|
|
29515
|
+
// frontImage = null;
|
|
29516
|
+
// backImage = null;
|
|
29517
|
+
// }
|
|
28900
29518
|
return {
|
|
28901
29519
|
scanId: scanId,
|
|
28902
|
-
details: Object.assign({}, result)
|
|
29520
|
+
details: Object.assign({}, result),
|
|
29521
|
+
frontImage,
|
|
29522
|
+
backImage,
|
|
29523
|
+
frontCropImage,
|
|
29524
|
+
backCropImage
|
|
28903
29525
|
};
|
|
28904
29526
|
}),
|
|
28905
29527
|
onDestroy: () => __awaiter(this, void 0, void 0, function* () {
|
|
28906
|
-
var
|
|
29528
|
+
var _u, _v;
|
|
28907
29529
|
durationTime.end();
|
|
28908
|
-
yield (
|
|
28909
|
-
yield (
|
|
29530
|
+
yield (_u = this.ocrService) === null || _u === void 0 ? void 0 : _u.destroy();
|
|
29531
|
+
yield (_v = this.antiFraudInstance) === null || _v === void 0 ? void 0 : _v.destroy();
|
|
28910
29532
|
}),
|
|
28911
29533
|
getCardMatchROI: () => __awaiter(this, void 0, void 0, function* () {
|
|
28912
29534
|
return yield this.antiFraudInstance.getCardMatchROI();
|
|
@@ -28998,7 +29620,7 @@ function renderCardTypeAndCountryConfig(config) {
|
|
|
28998
29620
|
<label class="country-select-label">${translate('sdk.home.selectCountry')}</label>
|
|
28999
29621
|
<div class="country-select-dropdown">
|
|
29000
29622
|
<div class="country-select-dropdown-frame">
|
|
29001
|
-
<div class="country-select-dropdown-text">${translate(`sdk.home.selectCountry.${
|
|
29623
|
+
<div class="country-select-dropdown-text">${translate(`sdk.home.selectCountry.${config.defaultCountry}`)}</div>
|
|
29002
29624
|
<div class="country-select-dropdown-icon"></div>
|
|
29003
29625
|
</div>
|
|
29004
29626
|
<div class="dropdown-country-list"></div>
|
|
@@ -29185,6 +29807,7 @@ class AuthmeIdentityVerification extends engine.AuthmeFunctionModule {
|
|
|
29185
29807
|
// 在尚未執行實際的 method 的時候,並不會佔用時間初始化。
|
|
29186
29808
|
util.Storage.setItem(util.STORAGE_KEY.LOADING_LOTTIE, loadingLottie);
|
|
29187
29809
|
util.Storage.setItem(util.STORAGE_KEY.OCR_IDCARD_RESULT_FORMAT, config.OCRIdcardResultFormat);
|
|
29810
|
+
util.Storage.setItem('customParameters', config.customParameters);
|
|
29188
29811
|
(_b = this.engine) !== null && _b !== void 0 ? _b : this.engine = new engine.MlEngine(engineConfig);
|
|
29189
29812
|
yield this.engine.setConfig(engineConfig);
|
|
29190
29813
|
(_c = this.ocrModule) !== null && _c !== void 0 ? _c : this.ocrModule = new OCRModule(this.engine, canvas);
|
|
@@ -29285,11 +29908,39 @@ class AuthmeIdentityVerification extends engine.AuthmeFunctionModule {
|
|
|
29285
29908
|
confirmOCRResult(data) {
|
|
29286
29909
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29287
29910
|
const ocrIdcardResultFormat = util.Storage.getItem(util.STORAGE_KEY['OCR_IDCARD_RESULT_FORMAT']);
|
|
29911
|
+
const shouldEncrypt = util.Storage.getItem('shouldEncrypt');
|
|
29912
|
+
const encryptDataBase64 = util.Storage.getItem('encryptDataBase64');
|
|
29913
|
+
const tmpObj = {};
|
|
29288
29914
|
if (ocrIdcardResultFormat === 'splitDateAndAddress') {
|
|
29289
29915
|
data.details = util.combineResult(data.details);
|
|
29290
29916
|
}
|
|
29291
|
-
|
|
29292
|
-
|
|
29917
|
+
const postData = {
|
|
29918
|
+
scanId: util.Storage.getItem('scanId'),
|
|
29919
|
+
details: util.Storage.getItem('confirmedData')
|
|
29920
|
+
};
|
|
29921
|
+
let res;
|
|
29922
|
+
if (shouldEncrypt) {
|
|
29923
|
+
res = yield idRecognition.confirmScan({
|
|
29924
|
+
id: data.scanId,
|
|
29925
|
+
encryptedBase64String: yield encryptDataBase64(postData)
|
|
29926
|
+
});
|
|
29927
|
+
} else {
|
|
29928
|
+
res = yield idRecognition.confirmScan(postData);
|
|
29929
|
+
}
|
|
29930
|
+
for (let index = 0; index < res.confirmedFields.length; index++) {
|
|
29931
|
+
const element = res.confirmedFields[index];
|
|
29932
|
+
tmpObj[element.fieldName] = {
|
|
29933
|
+
isModified: element.isModified,
|
|
29934
|
+
value: element.value
|
|
29935
|
+
};
|
|
29936
|
+
}
|
|
29937
|
+
// await confirmScan(data.scanId, data.details);
|
|
29938
|
+
return {
|
|
29939
|
+
isSuccess: true,
|
|
29940
|
+
message: '',
|
|
29941
|
+
data: util.Storage.getItem('data'),
|
|
29942
|
+
modifiedData: tmpObj
|
|
29943
|
+
};
|
|
29293
29944
|
});
|
|
29294
29945
|
}
|
|
29295
29946
|
// 考慮未來棄用 auth method ,並將將 auth 的部分,
|
|
@@ -29328,11 +29979,67 @@ class AuthmeIdentityVerification extends engine.AuthmeFunctionModule {
|
|
|
29328
29979
|
return (_a = this.tearDownPromise) !== null && _a !== void 0 ? _a : this.tearDownPromise = this._tearDown();
|
|
29329
29980
|
});
|
|
29330
29981
|
}
|
|
29982
|
+
cleanAllModel() {
|
|
29983
|
+
var _a;
|
|
29984
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29985
|
+
engine.AuthmeEngineModuleBase.reset_MODEL_CACHE();
|
|
29986
|
+
return (_a = this.tearDownPromise) !== null && _a !== void 0 ? _a : this.tearDownPromise = this._tearDown();
|
|
29987
|
+
});
|
|
29988
|
+
}
|
|
29989
|
+
getCustomerState(arg) {
|
|
29990
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29991
|
+
const paramsDefault = {
|
|
29992
|
+
waitingTime: 3,
|
|
29993
|
+
retryTimes: 2
|
|
29994
|
+
};
|
|
29995
|
+
if (arg === null || arg === void 0 ? void 0 : arg.retryTimes) {
|
|
29996
|
+
if (typeof arg.retryTimes !== 'number') {
|
|
29997
|
+
console.error('retryTimes should be a number');
|
|
29998
|
+
return;
|
|
29999
|
+
}
|
|
30000
|
+
if (arg.retryTimes <= 0) {
|
|
30001
|
+
console.error('retryTimes should be greater than 0');
|
|
30002
|
+
return;
|
|
30003
|
+
}
|
|
30004
|
+
}
|
|
30005
|
+
if (arg === null || arg === void 0 ? void 0 : arg.waitingTime) {
|
|
30006
|
+
if (typeof arg.waitingTime !== 'number') {
|
|
30007
|
+
console.error('waitingTime should be a number');
|
|
30008
|
+
return;
|
|
30009
|
+
}
|
|
30010
|
+
if (arg.waitingTime <= 0) {
|
|
30011
|
+
console.error('waitingTime should be greater than 0');
|
|
30012
|
+
return;
|
|
30013
|
+
}
|
|
30014
|
+
}
|
|
30015
|
+
const params = Object.assign(Object.assign({}, paramsDefault), arg);
|
|
30016
|
+
params.retryTimes++;
|
|
30017
|
+
let stop = false;
|
|
30018
|
+
for (let i = 0; i < params.retryTimes; i++) {
|
|
30019
|
+
if (!stop) {
|
|
30020
|
+
const res = yield core.getCustomerState();
|
|
30021
|
+
if (res.state === 'Approved') {
|
|
30022
|
+
stop = true;
|
|
30023
|
+
return res;
|
|
30024
|
+
} else if (res.state === 'Rejected') {
|
|
30025
|
+
stop = true;
|
|
30026
|
+
return res;
|
|
30027
|
+
} else {
|
|
30028
|
+
yield new Promise(resolve => setTimeout(resolve, params.waitingTime * 1000));
|
|
30029
|
+
}
|
|
30030
|
+
if (i === params.retryTimes - 1) {
|
|
30031
|
+
return res;
|
|
30032
|
+
}
|
|
30033
|
+
}
|
|
30034
|
+
}
|
|
30035
|
+
// return getCustomerState();
|
|
30036
|
+
});
|
|
30037
|
+
}
|
|
29331
30038
|
}
|
|
29332
30039
|
|
|
29333
30040
|
var name = "authme/sdk";
|
|
29334
|
-
var version$1 = "2.
|
|
29335
|
-
var date = "
|
|
30041
|
+
var version$1 = "2.8.1-patch.1";
|
|
30042
|
+
var date = "2025-06-12T13:55:46+0000";
|
|
29336
30043
|
var packageInfo = {
|
|
29337
30044
|
name: name,
|
|
29338
30045
|
version: version$1,
|