@authme/engine 2.8.42 → 2.8.44
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.d.ts +1 -0
- package/{index.cjs → index.cjs.js} +291 -327
- package/index.esm.d.ts +1 -0
- package/{index.js → index.esm.js} +292 -326
- package/package.json +6 -10
- package/src/index.d.ts +4 -4
- package/src/lib/api.d.ts +1 -1
- package/src/lib/engine.d.ts +60 -60
- package/src/lib/enum/auth.enum.d.ts +3 -3
- package/src/lib/enum/fas-recognition.enum.d.ts +49 -49
- package/src/lib/enum/id-recognition.enum.d.ts +85 -85
- package/src/lib/enum/index.d.ts +4 -4
- package/src/lib/enum/module.enum.d.ts +9 -9
- package/src/lib/interface/basic-type.interface.d.ts +22 -22
- package/src/lib/interface/config.interface.d.ts +9 -9
- package/src/lib/interface/index.d.ts +3 -3
- package/src/lib/interface/worker-command.interface.d.ts +7 -7
- package/src/lib/version.d.ts +1 -1
|
@@ -1,58 +1,47 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
require('core-js/modules/es.array.iterator.js');
|
|
4
|
+
require('core-js/modules/es.array.push.js');
|
|
5
|
+
require('core-js/modules/es.array.sort.js');
|
|
6
|
+
require('core-js/modules/es.array-buffer.constructor.js');
|
|
7
|
+
require('core-js/modules/es.array-buffer.slice.js');
|
|
8
|
+
require('core-js/modules/es.array-buffer.detached.js');
|
|
9
|
+
require('core-js/modules/es.array-buffer.transfer.js');
|
|
10
|
+
require('core-js/modules/es.array-buffer.transfer-to-fixed-length.js');
|
|
11
|
+
require('core-js/modules/es.json.stringify.js');
|
|
12
|
+
require('core-js/modules/es.object.assign.js');
|
|
6
13
|
require('core-js/modules/es.object.from-entries.js');
|
|
14
|
+
require('core-js/modules/es.parse-int.js');
|
|
15
|
+
require('core-js/modules/es.promise.js');
|
|
7
16
|
require('core-js/modules/es.regexp.exec.js');
|
|
8
|
-
require('core-js/modules/es.
|
|
17
|
+
require('core-js/modules/es.regexp.test.js');
|
|
18
|
+
require('core-js/modules/es.regexp.to-string.js');
|
|
9
19
|
require('core-js/modules/es.typed-array.uint8-array.js');
|
|
20
|
+
require('core-js/modules/es.typed-array.at.js');
|
|
10
21
|
require('core-js/modules/es.typed-array.fill.js');
|
|
22
|
+
require('core-js/modules/es.typed-array.find-last.js');
|
|
23
|
+
require('core-js/modules/es.typed-array.find-last-index.js');
|
|
11
24
|
require('core-js/modules/es.typed-array.set.js');
|
|
12
25
|
require('core-js/modules/es.typed-array.sort.js');
|
|
13
26
|
require('core-js/modules/es.typed-array.to-locale-string.js');
|
|
27
|
+
require('core-js/modules/es.typed-array.to-reversed.js');
|
|
28
|
+
require('core-js/modules/es.typed-array.to-sorted.js');
|
|
29
|
+
require('core-js/modules/es.typed-array.with.js');
|
|
30
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
31
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
32
|
+
require('core-js/modules/esnext.iterator.map.js');
|
|
33
|
+
require('core-js/modules/esnext.uint8-array.to-base64.js');
|
|
34
|
+
require('core-js/modules/esnext.uint8-array.to-hex.js');
|
|
14
35
|
require('core-js/modules/web.dom-collections.iterator.js');
|
|
15
36
|
require('core-js/modules/web.url.js');
|
|
37
|
+
require('core-js/modules/web.url.to-json.js');
|
|
16
38
|
require('core-js/modules/web.url-search-params.js');
|
|
17
|
-
require('core-js/modules/
|
|
18
|
-
require('core-js/modules/
|
|
19
|
-
require('core-js/modules/
|
|
20
|
-
require('core-js/modules/es.regexp.to-string.js');
|
|
21
|
-
require('core-js/modules/es.array.sort.js');
|
|
39
|
+
require('core-js/modules/web.url-search-params.delete.js');
|
|
40
|
+
require('core-js/modules/web.url-search-params.has.js');
|
|
41
|
+
require('core-js/modules/web.url-search-params.size.js');
|
|
22
42
|
var core = require('@authme/core');
|
|
23
43
|
var util = require('@authme/util');
|
|
24
44
|
var rxjs = require('rxjs');
|
|
25
|
-
require('core-js/modules/es.symbol.description.js');
|
|
26
|
-
|
|
27
|
-
/******************************************************************************
|
|
28
|
-
Copyright (c) Microsoft Corporation.
|
|
29
|
-
|
|
30
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
31
|
-
purpose with or without fee is hereby granted.
|
|
32
|
-
|
|
33
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
34
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
35
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
36
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
37
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
38
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
39
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
40
|
-
***************************************************************************** */
|
|
41
|
-
|
|
42
|
-
function __awaiter(thisArg, _arguments, P, generator) {
|
|
43
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
44
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
45
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
46
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
47
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
48
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
53
|
-
var e = new Error(message);
|
|
54
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
55
|
-
};
|
|
56
45
|
|
|
57
46
|
exports.EngineModule = void 0;
|
|
58
47
|
(function (EngineModule) {
|
|
@@ -71,8 +60,8 @@ exports.EAuthMeEngineReturnCode = void 0;
|
|
|
71
60
|
})(exports.EAuthMeEngineReturnCode || (exports.EAuthMeEngineReturnCode = {}));
|
|
72
61
|
|
|
73
62
|
var authEnumModule = /*#__PURE__*/Object.freeze({
|
|
74
|
-
|
|
75
|
-
|
|
63
|
+
__proto__: null,
|
|
64
|
+
get EAuthMeEngineReturnCode () { return exports.EAuthMeEngineReturnCode; }
|
|
76
65
|
});
|
|
77
66
|
|
|
78
67
|
exports.EAuthMeCardClass = void 0;
|
|
@@ -80,7 +69,7 @@ exports.EAuthMeCardClass = void 0;
|
|
|
80
69
|
EAuthMeCardClass["Invalid"] = "EAuthMeCardClass_Invalid";
|
|
81
70
|
EAuthMeCardClass["Unknown"] = "EAuthMeCardClass_UnknownCard";
|
|
82
71
|
EAuthMeCardClass["Passport"] = "EAuthMeCardClass_Passport";
|
|
83
|
-
EAuthMeCardClass["ALL_PASSPORT_CONTENT"] = "
|
|
72
|
+
EAuthMeCardClass["ALL_PASSPORT_CONTENT"] = "EAuthMeCardClass_ALL_PASSPORT_CONTENT";
|
|
84
73
|
EAuthMeCardClass["TWN_IDCard_Front"] = "EAuthMeCardClass_TWN_IDCard_Front";
|
|
85
74
|
EAuthMeCardClass["TWN_IDCard_Back"] = "EAuthMeCardClass_TWN_IDCard_Back";
|
|
86
75
|
EAuthMeCardClass["TWN_DriverLicense_Front"] = "EAuthMeCardClass_TWN_DriverLicense_Front";
|
|
@@ -170,15 +159,15 @@ exports.EAuthMeIDCardAntiFraudStage = void 0;
|
|
|
170
159
|
})(exports.EAuthMeIDCardAntiFraudStage || (exports.EAuthMeIDCardAntiFraudStage = {}));
|
|
171
160
|
|
|
172
161
|
var idRecognitionEnumModule = /*#__PURE__*/Object.freeze({
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
162
|
+
__proto__: null,
|
|
163
|
+
get EAuthMeCardClass () { return exports.EAuthMeCardClass; },
|
|
164
|
+
get EAuthMeCardMatchStatus () { return exports.EAuthMeCardMatchStatus; },
|
|
165
|
+
get EAuthMeCardOCRStatus () { return exports.EAuthMeCardOCRStatus; },
|
|
166
|
+
get EAuthMeIDCardAntiFraudStage () { return exports.EAuthMeIDCardAntiFraudStage; },
|
|
167
|
+
get EAuthMeIDCardAntiFraudStatus () { return exports.EAuthMeIDCardAntiFraudStatus; },
|
|
168
|
+
get EAuthMeIDCardMetalTagStatus () { return exports.EAuthMeIDCardMetalTagStatus; },
|
|
169
|
+
get EAuthMeMRZRecogStatus () { return exports.EAuthMeMRZRecogStatus; },
|
|
170
|
+
get EAuthMeMRZServiceStatus () { return exports.EAuthMeMRZServiceStatus; }
|
|
182
171
|
});
|
|
183
172
|
|
|
184
173
|
exports.EAuthMeFASServiceStatus = void 0;
|
|
@@ -238,13 +227,13 @@ exports.EAuthMeFaceAntiSpoofingStatus = void 0;
|
|
|
238
227
|
})(exports.EAuthMeFaceAntiSpoofingStatus || (exports.EAuthMeFaceAntiSpoofingStatus = {}));
|
|
239
228
|
|
|
240
229
|
var fasRecognitionEnumModule = /*#__PURE__*/Object.freeze({
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
230
|
+
__proto__: null,
|
|
231
|
+
get EAuthMeEyeStatus () { return exports.EAuthMeEyeStatus; },
|
|
232
|
+
get EAuthMeFASServiceStage () { return exports.EAuthMeFASServiceStage; },
|
|
233
|
+
get EAuthMeFASServiceStatus () { return exports.EAuthMeFASServiceStatus; },
|
|
234
|
+
get EAuthMeFaceAntiSpoofingStatus () { return exports.EAuthMeFaceAntiSpoofingStatus; },
|
|
235
|
+
get EAuthMeFacePose () { return exports.EAuthMeFacePose; },
|
|
236
|
+
get EAuthMeMouthStatus () { return exports.EAuthMeMouthStatus; }
|
|
248
237
|
});
|
|
249
238
|
|
|
250
239
|
const defaultMlEngineConfig = {
|
|
@@ -257,18 +246,14 @@ const defaultMlEngineConfig = {
|
|
|
257
246
|
};
|
|
258
247
|
|
|
259
248
|
var name = "authme/sdk";
|
|
260
|
-
var version$1 = "2.8.
|
|
261
|
-
var date = "2026-02-03T09:36:05+0000";
|
|
249
|
+
var version$1 = "2.8.44";
|
|
262
250
|
var sdkInfo = {
|
|
263
251
|
name: name,
|
|
264
|
-
version: version$1
|
|
265
|
-
date: date
|
|
266
|
-
};
|
|
252
|
+
version: version$1};
|
|
267
253
|
|
|
268
|
-
var
|
|
269
|
-
var _b, _c;
|
|
254
|
+
var _window, _Symbol$for, _window$_Symbol$for;
|
|
270
255
|
const version = sdkInfo.version;
|
|
271
|
-
(
|
|
256
|
+
(_window$_Symbol$for = (_window = window)[_Symbol$for = Symbol.for('authme-sdk')]) != null ? _window$_Symbol$for : _window[_Symbol$for] = {};
|
|
272
257
|
window[Symbol.for('authme-sdk')][sdkInfo.name] = version;
|
|
273
258
|
|
|
274
259
|
function logCollect(message, stackTrace) {
|
|
@@ -285,17 +270,36 @@ function logCollect(message, stackTrace) {
|
|
|
285
270
|
});
|
|
286
271
|
}
|
|
287
272
|
|
|
273
|
+
var _MlEngine, _AuthmeEngineModuleBase;
|
|
288
274
|
const getDownloadOrder = function () {
|
|
289
275
|
// model 越大,在後續 worker service 載入與解密的時間越長,
|
|
290
276
|
// 所以盡可能讓越大的檔案排在越前面下載,以便讓耗費時間長的任務先排在背景執行。
|
|
291
277
|
//
|
|
292
278
|
// 但由於 api server 目前沒有提供檔案大小的相關資訊,
|
|
293
279
|
// 所以將順序相關的資訊寫死在 sdk 裡。
|
|
294
|
-
const DOWNLOAD_ORDER = Object.fromEntries(['FACE_03',
|
|
280
|
+
const DOWNLOAD_ORDER = Object.fromEntries(['FACE_03',
|
|
281
|
+
// 3.7m
|
|
282
|
+
'FACE_00',
|
|
283
|
+
// 1.6m
|
|
284
|
+
'IDCardAntiFraud_00',
|
|
285
|
+
//1.5m
|
|
286
|
+
'FACE_01',
|
|
287
|
+
// 1.4m
|
|
288
|
+
'OCR_00',
|
|
289
|
+
// 1.4m
|
|
290
|
+
'FACE_02',
|
|
291
|
+
// 1.3m
|
|
292
|
+
'OCR_02',
|
|
293
|
+
// 548k
|
|
294
|
+
'MRZ_00',
|
|
295
|
+
// 548k
|
|
296
|
+
'OCR_01',
|
|
297
|
+
// 375k
|
|
298
|
+
'MRZ_01' // 375k
|
|
295
299
|
].map((key, index) => [key, index]));
|
|
296
300
|
return function getDownloadOrder(key) {
|
|
297
|
-
var
|
|
298
|
-
return (
|
|
301
|
+
var _DOWNLOAD_ORDER$key;
|
|
302
|
+
return (_DOWNLOAD_ORDER$key = DOWNLOAD_ORDER[key]) != null ? _DOWNLOAD_ORDER$key : Number.MAX_VALUE;
|
|
299
303
|
};
|
|
300
304
|
}();
|
|
301
305
|
function isSimdSupported() {
|
|
@@ -327,54 +331,46 @@ function getJsContentAsync(url) {
|
|
|
327
331
|
sdkInfo: null
|
|
328
332
|
});
|
|
329
333
|
}
|
|
330
|
-
function createWorkerWithObjectUrlAsync(url) {
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
return worker;
|
|
339
|
-
});
|
|
334
|
+
async function createWorkerWithObjectUrlAsync(url) {
|
|
335
|
+
const scriptContent = await getJsContentAsync(url);
|
|
336
|
+
const objectUrl = URL.createObjectURL(new Blob([scriptContent], {
|
|
337
|
+
type: 'text/javascript'
|
|
338
|
+
}));
|
|
339
|
+
const worker = new Worker(objectUrl);
|
|
340
|
+
URL.revokeObjectURL(objectUrl);
|
|
341
|
+
return worker;
|
|
340
342
|
}
|
|
341
343
|
function convertToModelQueryString(modelVersion) {
|
|
342
344
|
return `models=${modelVersion.name}[${modelVersion.version}]`;
|
|
343
345
|
}
|
|
344
|
-
function fetchModelCodesAsync(modelVersions) {
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
return response.models;
|
|
349
|
-
});
|
|
346
|
+
async function fetchModelCodesAsync(modelVersions) {
|
|
347
|
+
const queryString = modelVersions.map(convertToModelQueryString).join('&');
|
|
348
|
+
const response = await core.sendRequest('/api/model-management/v1/model?' + queryString);
|
|
349
|
+
return response.models;
|
|
350
350
|
}
|
|
351
351
|
function base64ToBufferAsync(base64) {
|
|
352
352
|
const dataUrl = 'data:application/octet-binary;base64,' + base64;
|
|
353
353
|
return fetch(dataUrl).then(res => res.arrayBuffer());
|
|
354
354
|
}
|
|
355
|
-
function fetchModelContentAsync(code, dataTransferMethod) {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
});
|
|
355
|
+
async function fetchModelContentAsync(code, dataTransferMethod) {
|
|
356
|
+
const payload = await core.sendRequest(`/api/model-management/v1/model/${code}${dataTransferMethod === 'binary' ? '/file' : ''}`);
|
|
357
|
+
if (dataTransferMethod === 'binary') {
|
|
358
|
+
return payload;
|
|
359
|
+
} else {
|
|
360
|
+
return await base64ToBufferAsync(payload.data);
|
|
361
|
+
}
|
|
364
362
|
}
|
|
365
363
|
function fetchModelContents(modelVersions, dataTransferMethod) {
|
|
366
364
|
return rxjs.of(modelVersions).pipe(rxjs.concatMap(modelVersions => rxjs.defer(() => fetchModelCodesAsync(modelVersions))), rxjs.concatAll(), rxjs.mergeMap(({
|
|
367
365
|
name,
|
|
368
366
|
version,
|
|
369
367
|
code
|
|
370
|
-
}) => rxjs.defer(() =>
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
modelArrayBuffer: yield fetchModelContentAsync(code, dataTransferMethod)
|
|
377
|
-
};
|
|
368
|
+
}) => rxjs.defer(async () => ({
|
|
369
|
+
modelVersion: {
|
|
370
|
+
name,
|
|
371
|
+
version: `${parseInt(version)}`
|
|
372
|
+
},
|
|
373
|
+
modelArrayBuffer: await fetchModelContentAsync(code, dataTransferMethod)
|
|
378
374
|
})), 1
|
|
379
375
|
// 下載 model 過程會分為 wait time & download time,
|
|
380
376
|
// concurrent 設定越高,只能起到降低 wait time 的作用,但會拉長單一檔案完成下載的時間,
|
|
@@ -383,16 +379,13 @@ function fetchModelContents(modelVersions, dataTransferMethod) {
|
|
|
383
379
|
// 所以 concurrent 建議設定為 1 或 2,盡量讓已下載好的 model 儘早進行載入與解密。
|
|
384
380
|
));
|
|
385
381
|
}
|
|
386
|
-
|
|
387
382
|
class AuthmeFunctionModule {
|
|
388
|
-
init(config) {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
util.Storage.setItem(key, config[key]);
|
|
393
|
-
}
|
|
383
|
+
async init(config) {
|
|
384
|
+
for (const key in config) {
|
|
385
|
+
if (Object.prototype.hasOwnProperty.call(config, key)) {
|
|
386
|
+
util.Storage.setItem(key, config[key]);
|
|
394
387
|
}
|
|
395
|
-
}
|
|
388
|
+
}
|
|
396
389
|
}
|
|
397
390
|
static getVersion() {
|
|
398
391
|
return version;
|
|
@@ -403,7 +396,7 @@ class MlEngine {
|
|
|
403
396
|
this.workerAndStreamPromise = undefined;
|
|
404
397
|
this.preloadPromise = undefined;
|
|
405
398
|
this.debugTools = util.debugTools();
|
|
406
|
-
this.config = Object.assign(
|
|
399
|
+
this.config = Object.assign({}, defaultMlEngineConfig, config, {
|
|
407
400
|
isMobile: util.isMobile()
|
|
408
401
|
});
|
|
409
402
|
}
|
|
@@ -420,102 +413,88 @@ class MlEngine {
|
|
|
420
413
|
durationTimeWorker.end();
|
|
421
414
|
})));
|
|
422
415
|
}
|
|
423
|
-
_makeWorkerAndStreamAsync() {
|
|
424
|
-
var
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
}
|
|
437
|
-
return x.data;
|
|
438
|
-
}), rxjs.shareReplay(1));
|
|
439
|
-
yield this._run(worker, workerMessage$, exports.EngineModule.Core, 'setConfig', this.config);
|
|
440
|
-
return [worker, workerMessage$];
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
_backgroundPreloadAsync() {
|
|
444
|
-
var _a;
|
|
445
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
446
|
-
const [worker, workerMessage$] = yield (_a = this.workerAndStreamPromise) !== null && _a !== void 0 ? _a : this.workerAndStreamPromise = this._makeWorkerAndStreamAsync();
|
|
447
|
-
yield this._loadEngineAsync(worker, workerMessage$);
|
|
448
|
-
yield this._checkEnumConsistencyAsync(worker, workerMessage$);
|
|
449
|
-
return [worker, workerMessage$];
|
|
450
|
-
});
|
|
451
|
-
}
|
|
452
|
-
terminateWorkerAsync() {
|
|
453
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
454
|
-
if (this.workerAndStreamPromise || this.preloadPromise) {
|
|
455
|
-
const [worker, _] = yield this._backgroundPreloadAsync();
|
|
456
|
-
this.workerAndStreamPromise = undefined;
|
|
457
|
-
this.preloadPromise = undefined;
|
|
458
|
-
worker.terminate();
|
|
416
|
+
async _makeWorkerAndStreamAsync() {
|
|
417
|
+
var _this$config$scriptPa;
|
|
418
|
+
// use blobUrl to fix cross-domain problem on worker creating.
|
|
419
|
+
// ref:
|
|
420
|
+
// * https://stackoverflow.com/questions/25458104/can-should-html5-web-workers-use-cors-for-cross-origin
|
|
421
|
+
// * https://web.dev/workers-basics/
|
|
422
|
+
const worker = await createWorkerWithObjectUrlAsync(`${(_this$config$scriptPa = this.config.scriptPath) != null ? _this$config$scriptPa : ''}engine-worker.js?t=${Date.now()}`);
|
|
423
|
+
const workerMessage$ = rxjs.fromEvent(worker, 'message').pipe(rxjs.map(x => {
|
|
424
|
+
var _x$data;
|
|
425
|
+
if ((_x$data = x.data) != null && (_x$data = _x$data.value) != null && _x$data.error) {
|
|
426
|
+
var _x$data2;
|
|
427
|
+
logCollect('workerMessage error', JSON.stringify((_x$data2 = x.data) == null || (_x$data2 = _x$data2.value) == null ? void 0 : _x$data2.error));
|
|
428
|
+
throw new core.AuthmeError(core.ErrorCode.SDK_INTERNAL_ERROR, 'unexpected worker error');
|
|
459
429
|
}
|
|
460
|
-
|
|
430
|
+
return x.data;
|
|
431
|
+
}), rxjs.shareReplay(1));
|
|
432
|
+
await this._run(worker, workerMessage$, exports.EngineModule.Core, 'setConfig', this.config);
|
|
433
|
+
return [worker, workerMessage$];
|
|
434
|
+
}
|
|
435
|
+
async _backgroundPreloadAsync() {
|
|
436
|
+
var _this$workerAndStream;
|
|
437
|
+
const [worker, workerMessage$] = await ((_this$workerAndStream = this.workerAndStreamPromise) != null ? _this$workerAndStream : this.workerAndStreamPromise = this._makeWorkerAndStreamAsync());
|
|
438
|
+
await this._loadEngineAsync(worker, workerMessage$);
|
|
439
|
+
await this._checkEnumConsistencyAsync(worker, workerMessage$);
|
|
440
|
+
return [worker, workerMessage$];
|
|
441
|
+
}
|
|
442
|
+
async terminateWorkerAsync() {
|
|
443
|
+
if (this.workerAndStreamPromise || this.preloadPromise) {
|
|
444
|
+
const [worker, _] = await this._backgroundPreloadAsync();
|
|
445
|
+
this.workerAndStreamPromise = undefined;
|
|
446
|
+
this.preloadPromise = undefined;
|
|
447
|
+
worker.terminate();
|
|
448
|
+
}
|
|
461
449
|
}
|
|
462
450
|
_preloadAndWaitReadyAsync() {
|
|
463
|
-
var
|
|
464
|
-
return (
|
|
465
|
-
}
|
|
466
|
-
_checkEnumConsistencyAsync(worker, workerMessage$) {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
}
|
|
475
|
-
});
|
|
451
|
+
var _this$preloadPromise;
|
|
452
|
+
return (_this$preloadPromise = this.preloadPromise) != null ? _this$preloadPromise : this.preloadPromise = this._backgroundPreloadAsync();
|
|
453
|
+
}
|
|
454
|
+
async _checkEnumConsistencyAsync(worker, workerMessage$) {
|
|
455
|
+
const problem = await this._run(worker, workerMessage$, 'Core', 'checkEnumConsistency', Object.assign({}, authEnumModule, idRecognitionEnumModule, fasRecognitionEnumModule));
|
|
456
|
+
if (problem.length > 0) {
|
|
457
|
+
logCollect('enum consistency problem', JSON.stringify(problem));
|
|
458
|
+
throw new core.AuthmeError(core.ErrorCode.SDK_INTERNAL_ERROR, {
|
|
459
|
+
problem
|
|
460
|
+
});
|
|
461
|
+
}
|
|
476
462
|
}
|
|
477
|
-
run(module, command, value = {}) {
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
return yield this._run(worker, workerMessage$, module, command, value);
|
|
481
|
-
});
|
|
463
|
+
async run(module, command, value = {}) {
|
|
464
|
+
const [worker, workerMessage$] = await this._preloadAndWaitReadyAsync();
|
|
465
|
+
return await this._run(worker, workerMessage$, module, command, value);
|
|
482
466
|
}
|
|
483
467
|
getConfig() {
|
|
484
468
|
return this.config;
|
|
485
469
|
}
|
|
486
|
-
setConfig(config) {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
}
|
|
493
|
-
});
|
|
470
|
+
async setConfig(config) {
|
|
471
|
+
this.config = Object.assign({}, this.config, config);
|
|
472
|
+
if (this.workerAndStreamPromise) {
|
|
473
|
+
const [worker, workerMessage$] = await this._preloadAndWaitReadyAsync();
|
|
474
|
+
await this._run(worker, workerMessage$, exports.EngineModule.Core, 'setConfig', this.config);
|
|
475
|
+
}
|
|
494
476
|
}
|
|
495
|
-
setPublicKeyForJson(pubKey) {
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
return yield this._run(worker, workerMessage$, exports.EngineModule.Core, 'loadEngine', {
|
|
512
|
-
engineJsContent,
|
|
513
|
-
engineWasmContent
|
|
514
|
-
});
|
|
477
|
+
async setPublicKeyForJson(pubKey) {
|
|
478
|
+
const [worker, workerMessage$] = await this._preloadAndWaitReadyAsync();
|
|
479
|
+
await this._run(worker, workerMessage$, exports.EngineModule.Fas, 'setPublicKeyForJson', pubKey);
|
|
480
|
+
}
|
|
481
|
+
async _loadEngineAsync(worker, workerMessage$) {
|
|
482
|
+
var _this$config$scriptPa2, _this$config$scriptPa3, _this$config$scriptPa4, _this$config$scriptPa5, _MlEngine$_ENGINE_CAC;
|
|
483
|
+
// load js/wasm outside the worker.
|
|
484
|
+
const simdSupported = isSimdSupported();
|
|
485
|
+
const jsUrl = simdSupported ? `${(_this$config$scriptPa2 = this.config.scriptPath) != null ? _this$config$scriptPa2 : ''}ml_engine_web.simd.js` : `${(_this$config$scriptPa3 = this.config.scriptPath) != null ? _this$config$scriptPa3 : ''}ml_engine_web.js`;
|
|
486
|
+
const wasmUrl = simdSupported ? `${(_this$config$scriptPa4 = this.config.scriptPath) != null ? _this$config$scriptPa4 : ''}ml_engine_web.simd.wasm` : `${(_this$config$scriptPa5 = this.config.scriptPath) != null ? _this$config$scriptPa5 : ''}ml_engine_web.wasm`;
|
|
487
|
+
const durationTimeNetworkEngine = this.debugTools.setTimeDuration('loadEngine_network');
|
|
488
|
+
const [engineJsContent, engineWasmContent] = await ((_MlEngine$_ENGINE_CAC = MlEngine._ENGINE_CACHE) != null ? _MlEngine$_ENGINE_CAC : MlEngine._ENGINE_CACHE = Promise.all([getJsContentAsync(`${jsUrl}?t=${Date.now()}`), getWasmContentAsync(`${wasmUrl}?t=${Date.now()}`)]));
|
|
489
|
+
durationTimeNetworkEngine.end();
|
|
490
|
+
return await this._run(worker, workerMessage$, exports.EngineModule.Core, 'loadEngine', {
|
|
491
|
+
engineJsContent,
|
|
492
|
+
engineWasmContent
|
|
515
493
|
});
|
|
516
494
|
}
|
|
517
495
|
}
|
|
518
|
-
|
|
496
|
+
_MlEngine = MlEngine;
|
|
497
|
+
_MlEngine._ENGINE_CACHE = undefined;
|
|
519
498
|
class AuthmeEngineModuleBase {
|
|
520
499
|
constructor(engine) {
|
|
521
500
|
this._initPromise = undefined;
|
|
@@ -528,59 +507,57 @@ class AuthmeEngineModuleBase {
|
|
|
528
507
|
_engineRunAsync(command, value) {
|
|
529
508
|
return this.engine.run(this.moduleName, command, value);
|
|
530
509
|
}
|
|
531
|
-
_init() {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
}) => modelVersion.name === name && modelVersion.version === version));
|
|
555
|
-
}
|
|
556
|
-
const loadSessions$ = rxjs.from(noLoadedModelVersions).pipe(rxjs.map(({
|
|
557
|
-
name,
|
|
558
|
-
version
|
|
559
|
-
}) => AuthmeEngineModuleBase._MODEL_CACHE[`${name}-${version}`]), rxjs.mergeAll(), rxjs.concatMap(({
|
|
560
|
-
modelVersion,
|
|
561
|
-
modelArrayBuffer
|
|
562
|
-
}) => rxjs.of(this._engineRunAsync('loadSession', {
|
|
563
|
-
modelVersion,
|
|
564
|
-
modelArrayBuffer
|
|
565
|
-
}))), rxjs.reduce((promises, item) => {
|
|
566
|
-
promises.push(item);
|
|
567
|
-
return promises;
|
|
568
|
-
}, []), rxjs.concatMap(promises => rxjs.defer(() => Promise.all(promises))));
|
|
569
|
-
yield rxjs.firstValueFrom(loadSessions$);
|
|
570
|
-
const result = yield this._engineRunAsync('init');
|
|
571
|
-
this.initialized = true;
|
|
572
|
-
return result;
|
|
573
|
-
} catch (error) {
|
|
574
|
-
logCollect('engine init error', JSON.stringify(error));
|
|
575
|
-
throw new core.AuthmeError(core.ErrorCode.ENGINE_MODULE_INIT_ERROR, error);
|
|
576
|
-
} finally {
|
|
577
|
-
this.initializing = false;
|
|
510
|
+
async _init() {
|
|
511
|
+
if (this.initialized) {
|
|
512
|
+
return true;
|
|
513
|
+
}
|
|
514
|
+
if (this.initializing) {
|
|
515
|
+
throw new core.AuthmeError(core.ErrorCode.ENGINE_MODULE_IS_INITIALIZING);
|
|
516
|
+
}
|
|
517
|
+
this.initializing = true;
|
|
518
|
+
try {
|
|
519
|
+
var _this$engine$getConfi;
|
|
520
|
+
const noLoadedModelVersions = await this._engineRunAsync('getNoLoadedModelVersions');
|
|
521
|
+
const noCachedModelVersions = noLoadedModelVersions.filter(({
|
|
522
|
+
name,
|
|
523
|
+
version
|
|
524
|
+
}) => !AuthmeEngineModuleBase._MODEL_CACHE[`${name}-${version}`]);
|
|
525
|
+
const newCachedValues = fetchModelContents(noCachedModelVersions.sort((a, b) => getDownloadOrder(a.name) - getDownloadOrder(b.name)), (_this$engine$getConfi = this.engine.getConfig().dataTransferMethod) != null ? _this$engine$getConfi : 'binary').pipe(rxjs.shareReplay());
|
|
526
|
+
for (const {
|
|
527
|
+
name,
|
|
528
|
+
version
|
|
529
|
+
} of noCachedModelVersions) {
|
|
530
|
+
AuthmeEngineModuleBase._MODEL_CACHE[`${name}-${version}`] = newCachedValues.pipe(rxjs.filter(({
|
|
531
|
+
modelVersion
|
|
532
|
+
}) => modelVersion.name === name && modelVersion.version === version));
|
|
578
533
|
}
|
|
579
|
-
|
|
534
|
+
const loadSessions$ = rxjs.from(noLoadedModelVersions).pipe(rxjs.map(({
|
|
535
|
+
name,
|
|
536
|
+
version
|
|
537
|
+
}) => AuthmeEngineModuleBase._MODEL_CACHE[`${name}-${version}`]), rxjs.mergeAll(), rxjs.concatMap(({
|
|
538
|
+
modelVersion,
|
|
539
|
+
modelArrayBuffer
|
|
540
|
+
}) => rxjs.of(this._engineRunAsync('loadSession', {
|
|
541
|
+
modelVersion,
|
|
542
|
+
modelArrayBuffer
|
|
543
|
+
}))), rxjs.reduce((promises, item) => {
|
|
544
|
+
promises.push(item);
|
|
545
|
+
return promises;
|
|
546
|
+
}, []), rxjs.concatMap(promises => rxjs.defer(() => Promise.all(promises))));
|
|
547
|
+
await rxjs.firstValueFrom(loadSessions$);
|
|
548
|
+
const result = await this._engineRunAsync('init');
|
|
549
|
+
this.initialized = true;
|
|
550
|
+
return result;
|
|
551
|
+
} catch (error) {
|
|
552
|
+
logCollect('engine init error', JSON.stringify(error));
|
|
553
|
+
throw new core.AuthmeError(core.ErrorCode.ENGINE_MODULE_INIT_ERROR, error);
|
|
554
|
+
} finally {
|
|
555
|
+
this.initializing = false;
|
|
556
|
+
}
|
|
580
557
|
}
|
|
581
558
|
init() {
|
|
582
|
-
var
|
|
583
|
-
return (
|
|
559
|
+
var _this$_initPromise;
|
|
560
|
+
return (_this$_initPromise = this._initPromise) != null ? _this$_initPromise : this._initPromise = this._init();
|
|
584
561
|
}
|
|
585
562
|
preloadAsync() {
|
|
586
563
|
return this.init();
|
|
@@ -598,66 +575,60 @@ class AuthmeEngineModuleBase {
|
|
|
598
575
|
setOption(params) {
|
|
599
576
|
return this._engineRunAsync('setOption', params);
|
|
600
577
|
}
|
|
601
|
-
recognition(data) {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
debugInfo: {
|
|
617
|
-
inferenceTime: performance.now() - start
|
|
618
|
-
}
|
|
619
|
-
});
|
|
620
|
-
} catch (error) {
|
|
621
|
-
this.received = true;
|
|
622
|
-
logCollect('recognition error', JSON.stringify(error));
|
|
623
|
-
throw new core.AuthmeError(core.ErrorCode.RECOGNITION_ERROR, error);
|
|
624
|
-
}
|
|
625
|
-
});
|
|
626
|
-
}
|
|
627
|
-
getDebugImageData(data) {
|
|
628
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
629
|
-
// status control
|
|
630
|
-
if (!this.received || !this.initialized || !this.setSized) {
|
|
631
|
-
logCollect('getDebugImageData recognition not available', JSON.stringify(core.ErrorCode.RECOGNITION_NOT_AVAILABLE));
|
|
632
|
-
throw new core.AuthmeError(core.ErrorCode.RECOGNITION_NOT_AVAILABLE);
|
|
633
|
-
}
|
|
634
|
-
try {
|
|
635
|
-
this.received = false;
|
|
636
|
-
const start = performance.now();
|
|
637
|
-
const return$ = yield this._engineRunAsync('getDebugImage', {
|
|
638
|
-
data
|
|
639
|
-
});
|
|
640
|
-
this.received = true;
|
|
641
|
-
return$.debugInfo = {
|
|
578
|
+
async recognition(data) {
|
|
579
|
+
// status control
|
|
580
|
+
if (!this.received || !this.initialized || !this.setSized) {
|
|
581
|
+
logCollect('recognition not available', JSON.stringify(core.ErrorCode.RECOGNITION_NOT_AVAILABLE));
|
|
582
|
+
throw new core.AuthmeError(core.ErrorCode.RECOGNITION_NOT_AVAILABLE);
|
|
583
|
+
}
|
|
584
|
+
try {
|
|
585
|
+
this.received = false;
|
|
586
|
+
const start = performance.now();
|
|
587
|
+
const return$ = await this._engineRunAsync('recognition', {
|
|
588
|
+
data
|
|
589
|
+
});
|
|
590
|
+
this.received = true;
|
|
591
|
+
return Object.assign({}, return$, {
|
|
592
|
+
debugInfo: {
|
|
642
593
|
inferenceTime: performance.now() - start
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
});
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
} catch (error) {
|
|
597
|
+
this.received = true;
|
|
598
|
+
logCollect('recognition error', JSON.stringify(error));
|
|
599
|
+
throw new core.AuthmeError(core.ErrorCode.RECOGNITION_ERROR, error);
|
|
600
|
+
}
|
|
651
601
|
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
602
|
+
async getDebugImageData(data) {
|
|
603
|
+
// status control
|
|
604
|
+
if (!this.received || !this.initialized || !this.setSized) {
|
|
605
|
+
logCollect('getDebugImageData recognition not available', JSON.stringify(core.ErrorCode.RECOGNITION_NOT_AVAILABLE));
|
|
606
|
+
throw new core.AuthmeError(core.ErrorCode.RECOGNITION_NOT_AVAILABLE);
|
|
607
|
+
}
|
|
608
|
+
try {
|
|
609
|
+
this.received = false;
|
|
610
|
+
const start = performance.now();
|
|
611
|
+
const return$ = await this._engineRunAsync('getDebugImage', {
|
|
612
|
+
data
|
|
657
613
|
});
|
|
658
|
-
this.
|
|
659
|
-
return
|
|
614
|
+
this.received = true;
|
|
615
|
+
return$.debugInfo = {
|
|
616
|
+
inferenceTime: performance.now() - start
|
|
617
|
+
};
|
|
618
|
+
return return$;
|
|
619
|
+
} catch (error) {
|
|
620
|
+
this.received = true;
|
|
621
|
+
logCollect('getDebugImageData recognition error', JSON.stringify(error));
|
|
622
|
+
throw new core.AuthmeError(core.ErrorCode.RECOGNITION_ERROR, error);
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
async setFrameSize(width, height) {
|
|
626
|
+
const result = await this._engineRunAsync('setFrameSize', {
|
|
627
|
+
width,
|
|
628
|
+
height
|
|
660
629
|
});
|
|
630
|
+
this.setSized = true;
|
|
631
|
+
return result;
|
|
661
632
|
}
|
|
662
633
|
getParams() {
|
|
663
634
|
return this._engineRunAsync('getParams');
|
|
@@ -672,38 +643,30 @@ class AuthmeEngineModuleBase {
|
|
|
672
643
|
positions
|
|
673
644
|
});
|
|
674
645
|
}
|
|
675
|
-
encryptString(str, key) {
|
|
676
|
-
return
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
key
|
|
680
|
-
});
|
|
646
|
+
async encryptString(str, key) {
|
|
647
|
+
return await this._engineRunAsync('encryptString', {
|
|
648
|
+
string: str,
|
|
649
|
+
key
|
|
681
650
|
});
|
|
682
651
|
}
|
|
683
|
-
encryptBlob(uint8Array, key) {
|
|
684
|
-
return
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
key
|
|
688
|
-
});
|
|
652
|
+
async encryptBlob(uint8Array, key) {
|
|
653
|
+
return await this._engineRunAsync('encryptBlob', {
|
|
654
|
+
uint8Array: uint8Array,
|
|
655
|
+
key
|
|
689
656
|
});
|
|
690
657
|
}
|
|
691
658
|
// 測試圖片上傳加密用,未來實作後請刪除。
|
|
692
|
-
_decryptString(str, key) {
|
|
693
|
-
return
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
key
|
|
697
|
-
});
|
|
659
|
+
async _decryptString(str, key) {
|
|
660
|
+
return await this._engineRunAsync('_decryptString', {
|
|
661
|
+
string: str,
|
|
662
|
+
key
|
|
698
663
|
});
|
|
699
664
|
}
|
|
700
|
-
destroy() {
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
return true;
|
|
706
|
-
});
|
|
665
|
+
async destroy() {
|
|
666
|
+
await this._engineRunAsync('destroy');
|
|
667
|
+
this.initialized = false;
|
|
668
|
+
this._initPromise = undefined;
|
|
669
|
+
return true;
|
|
707
670
|
}
|
|
708
671
|
getUIParams() {
|
|
709
672
|
return this.engine.run(this.moduleName, 'getUIParams');
|
|
@@ -715,7 +678,8 @@ class AuthmeEngineModuleBase {
|
|
|
715
678
|
this._MODEL_CACHE = {};
|
|
716
679
|
}
|
|
717
680
|
}
|
|
718
|
-
|
|
681
|
+
_AuthmeEngineModuleBase = AuthmeEngineModuleBase;
|
|
682
|
+
_AuthmeEngineModuleBase._MODEL_CACHE = {};
|
|
719
683
|
|
|
720
684
|
exports.AuthmeEngineModuleBase = AuthmeEngineModuleBase;
|
|
721
685
|
exports.AuthmeFunctionModule = AuthmeFunctionModule;
|