@privateid/ultrapass-web-sdk 1.7.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/dist/application/index.js +6 -1
  2. package/dist/application/index.js.map +1 -1
  3. package/dist/application/modules/core/document/DocumentService.d.ts +1 -0
  4. package/dist/application/modules/core/document/DocumentService.js +55 -36
  5. package/dist/application/modules/core/document/DocumentService.js.map +1 -1
  6. package/dist/application/modules/core/document/document.types.d.ts +151 -0
  7. package/dist/application/modules/core/document/document.utils.d.ts +23 -1
  8. package/dist/application/modules/core/document/document.utils.js +123 -20
  9. package/dist/application/modules/core/document/document.utils.js.map +1 -1
  10. package/dist/application/modules/core/face/FaceService.d.ts +2 -2
  11. package/dist/application/modules/core/face/FaceService.js +50 -25
  12. package/dist/application/modules/core/face/FaceService.js.map +1 -1
  13. package/dist/application/modules/core/face/face.types.d.ts +105 -2
  14. package/dist/application/modules/core/face/face.types.js.map +1 -1
  15. package/dist/application/modules/core/face/face.utils.d.ts +14 -0
  16. package/dist/application/modules/core/face/face.utils.js +86 -2
  17. package/dist/application/modules/core/face/face.utils.js.map +1 -1
  18. package/dist/application/modules/internal/feature-flag/LDFeatureFlagService.js +0 -1
  19. package/dist/application/modules/internal/feature-flag/LDFeatureFlagService.js.map +1 -1
  20. package/dist/application/modules/internal/shared/index.d.ts +1 -0
  21. package/dist/application/modules/internal/shared/index.js +1 -0
  22. package/dist/application/modules/internal/shared/index.js.map +1 -1
  23. package/dist/application/modules/internal/shared/shared.types.d.ts +21 -0
  24. package/dist/application/modules/internal/shared/shared.types.js +2 -0
  25. package/dist/application/modules/internal/shared/shared.types.js.map +1 -0
  26. package/dist/application/modules/internal/shared/shared.utils.d.ts +7 -0
  27. package/dist/application/modules/internal/shared/shared.utils.js +38 -5
  28. package/dist/application/modules/internal/shared/shared.utils.js.map +1 -1
  29. package/dist/application/modules/internal/wasm-orchestrator/WasmOrchestratorService.d.ts +1 -2
  30. package/dist/application/modules/internal/wasm-orchestrator/WasmOrchestratorService.js +88 -209
  31. package/dist/application/modules/internal/wasm-orchestrator/WasmOrchestratorService.js.map +1 -1
  32. package/dist/application/modules/internal/wasm-orchestrator/index.d.ts +1 -2
  33. package/dist/application/modules/internal/wasm-orchestrator/index.js +0 -2
  34. package/dist/application/modules/internal/wasm-orchestrator/index.js.map +1 -1
  35. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.types.d.ts +7 -19
  36. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.utils.d.ts +18 -0
  37. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.utils.js +73 -10
  38. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.utils.js.map +1 -1
  39. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.utils.test.d.ts +1 -0
  40. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.utils.test.js +218 -0
  41. package/dist/application/modules/internal/wasm-orchestrator/wasm-orchestrator.utils.test.js.map +1 -0
  42. package/dist/application/modules/support/camera/CameraServiceFactory.js +0 -1
  43. package/dist/application/modules/support/camera/CameraServiceFactory.js.map +1 -1
  44. package/dist/application/modules/support/camera/camera.domain.d.ts +2 -1
  45. package/dist/application/modules/support/camera/camera.types.d.ts +18 -3
  46. package/dist/application/modules/support/camera/camera.types.js +9 -5
  47. package/dist/application/modules/support/camera/camera.types.js.map +1 -1
  48. package/dist/application/modules/support/camera/camera.utils.d.ts +1 -2
  49. package/dist/application/modules/support/camera/camera.utils.js +1 -11
  50. package/dist/application/modules/support/camera/camera.utils.js.map +1 -1
  51. package/dist/application/modules/support/camera/index.d.ts +3 -1
  52. package/dist/application/modules/support/camera/index.js +3 -0
  53. package/dist/application/modules/support/camera/index.js.map +1 -1
  54. package/dist/application/modules/support/camera/services/BaseCameraService.d.ts +5 -5
  55. package/dist/application/modules/support/camera/services/BaseCameraService.js +15 -16
  56. package/dist/application/modules/support/camera/services/BaseCameraService.js.map +1 -1
  57. package/dist/application/modules/support/camera/services/DesktopCameraService.js +0 -1
  58. package/dist/application/modules/support/camera/services/DesktopCameraService.js.map +1 -1
  59. package/dist/application/modules/support/camera/services/FirefoxCameraService.js +0 -1
  60. package/dist/application/modules/support/camera/services/FirefoxCameraService.js.map +1 -1
  61. package/dist/application/modules/support/camera/services/MacSafariCameraService.js +0 -1
  62. package/dist/application/modules/support/camera/services/MacSafariCameraService.js.map +1 -1
  63. package/dist/application/modules/support/camera/services/MobileCameraService.js +1 -3
  64. package/dist/application/modules/support/camera/services/MobileCameraService.js.map +1 -1
  65. package/dist/application/modules/support/camera/services/VideoIntegrityMonitor.d.ts +51 -0
  66. package/dist/application/modules/support/camera/services/VideoIntegrityMonitor.js +246 -0
  67. package/dist/application/modules/support/camera/services/VideoIntegrityMonitor.js.map +1 -0
  68. package/dist/application/modules/support/engine/EngineService.js +5 -6
  69. package/dist/application/modules/support/engine/EngineService.js.map +1 -1
  70. package/dist/application/modules/support/engine/engine.constants.d.ts +1 -0
  71. package/dist/application/modules/support/engine/engine.constants.js +1 -0
  72. package/dist/application/modules/support/engine/engine.constants.js.map +1 -1
  73. package/dist/application/modules/support/engine/engine.types.d.ts +2 -21
  74. package/dist/application/modules/support/engine/engine.utils.js +14 -5
  75. package/dist/application/modules/support/engine/engine.utils.js.map +1 -1
  76. package/dist/application/modules/support/engine/index.d.ts +1 -1
  77. package/dist/application/modules/support/permissions/PermissionsService.js +0 -2
  78. package/dist/application/modules/support/permissions/PermissionsService.js.map +1 -1
  79. package/dist/application/modules/support/permissions/index.js +0 -1
  80. package/dist/application/modules/support/permissions/index.js.map +1 -1
  81. package/dist/application/workers/wasm/WasmWorkerService.d.ts +16 -5
  82. package/dist/application/workers/wasm/WasmWorkerService.js +284 -212
  83. package/dist/application/workers/wasm/WasmWorkerService.js.map +1 -1
  84. package/dist/application/workers/wasm/wasm-worker.domain.d.ts +2 -2
  85. package/dist/application/workers/wasm/wasm-worker.types.d.ts +19 -1
  86. package/dist/application/workers/wasm/wasm-worker.utils.d.ts +28 -1
  87. package/dist/application/workers/wasm/wasm-worker.utils.js +137 -23
  88. package/dist/application/workers/wasm/wasm-worker.utils.js.map +1 -1
  89. package/dist/application/workers/wasm/wasm-worker.utils.test.d.ts +1 -0
  90. package/dist/application/workers/wasm/wasm-worker.utils.test.js +123 -0
  91. package/dist/application/workers/wasm/wasm-worker.utils.test.js.map +1 -0
  92. package/dist/index.d.ts +47 -35
  93. package/dist/index.js +108 -77
  94. package/dist/index.js.map +1 -1
  95. package/package.json +19 -11
  96. package/wasm/ultra/manifest.json +15 -15
  97. package/wasm/ultra/nosimd/26.03.17-71cdf0e-prod/privid_fhe_ultra.js +18 -0
  98. package/wasm/{ultra-dev/nosimd/26.02.13-24c4552-dev → ultra/nosimd/26.03.17-71cdf0e-prod}/privid_fhe_ultra.wasm +0 -0
  99. package/wasm/ultra/nosimd/version.json +1 -1
  100. package/wasm/ultra/simd/26.03.17-71cdf0e-prod/privid_fhe_ultra.js +18 -0
  101. package/wasm/{ultra-dev/simd/26.02.13-24c4552-dev → ultra/simd/26.03.17-71cdf0e-prod}/privid_fhe_ultra.wasm +0 -0
  102. package/wasm/ultra/simd/version.json +1 -1
  103. package/wasm/ultra-dev/nosimd/26.03.17-71cdf0e-dev/privid_fhe_ultra.js +18 -0
  104. package/wasm/{ultra/nosimd/26.02.13-24c4552-prod → ultra-dev/nosimd/26.03.17-71cdf0e-dev}/privid_fhe_ultra.wasm +0 -0
  105. package/wasm/ultra-dev/nosimd/version.json +1 -1
  106. package/wasm/ultra-dev/simd/26.03.17-71cdf0e-dev/privid_fhe_ultra.js +18 -0
  107. package/wasm/{ultra/simd/26.02.13-24c4552-prod → ultra-dev/simd/26.03.17-71cdf0e-dev}/privid_fhe_ultra.wasm +0 -0
  108. package/wasm/ultra-dev/simd/version.json +1 -1
  109. package/workers/wasm-new.worker.js +1 -1
  110. package/workers/wasm-new.worker.js.map +3 -3
  111. package/dist/apiUtils.d.ts +0 -46
  112. package/dist/apiUtils.js +0 -923
  113. package/dist/apiUtils.js.map +0 -1
  114. package/dist/cameraUtils.d.ts +0 -77
  115. package/dist/cameraUtils.js +0 -362
  116. package/dist/cameraUtils.js.map +0 -1
  117. package/dist/constants.d.ts +0 -9
  118. package/dist/constants.js +0 -14
  119. package/dist/constants.js.map +0 -1
  120. package/dist/createCallback.d.ts +0 -57
  121. package/dist/createCallback.js +0 -336
  122. package/dist/createCallback.js.map +0 -1
  123. package/dist/dbUtils.d.ts +0 -14
  124. package/dist/dbUtils.js +0 -149
  125. package/dist/dbUtils.js.map +0 -1
  126. package/dist/envUtils.d.ts +0 -4
  127. package/dist/envUtils.js +0 -17
  128. package/dist/envUtils.js.map +0 -1
  129. package/dist/faceModule.d.ts +0 -233
  130. package/dist/faceModule.js +0 -1021
  131. package/dist/faceModule.js.map +0 -1
  132. package/dist/main.d.ts +0 -48
  133. package/dist/main.js +0 -111
  134. package/dist/main.js.map +0 -1
  135. package/dist/types.d.ts +0 -139
  136. package/dist/types.js +0 -78
  137. package/dist/types.js.map +0 -1
  138. package/dist/utils.d.ts +0 -90
  139. package/dist/utils.js +0 -587
  140. package/dist/utils.js.map +0 -1
  141. package/wasm/ultra/nosimd/26.02.13-24c4552-prod/privid_fhe_ultra.js +0 -18
  142. package/wasm/ultra/simd/26.02.13-24c4552-prod/privid_fhe_ultra.js +0 -18
  143. package/wasm/ultra-dev/nosimd/26.02.13-24c4552-dev/privid_fhe_ultra.js +0 -18
  144. package/wasm/ultra-dev/simd/26.02.13-24c4552-dev/privid_fhe_ultra.js +0 -18
@@ -1,1021 +0,0 @@
1
- /* eslint-disable */
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- /**
12
- * @module Face module
13
- */
14
- import { proxy } from 'comlink';
15
- import { detect } from 'detect-browser';
16
- import { getCameraList, getVideoConstraints, isFaceTimeCamera, isMobileBackCameraPortrait } from './cameraUtils';
17
- import { facingMode } from './constants';
18
- import { callbackTypeEnum, createCallback } from './createCallback';
19
- import { CameraFaceMode, ImageType } from './types';
20
- import { checkIfModelsLoaded, createImages, getDebugType, getDefaultCameraDeviceId, getIsSIMD, iOS, isMobileFunc, pkiEncrypt, printLogs, setDefaultCameraDeviceId, ultraAgeEstimate, ultraCompareEmbeddings, ultraEnroll, ultraPredict, ultraScanBackDocument, ultraScanFrontDocument, ultraDocumentOcr, freeMemory, } from './utils';
21
- let videoElement = null;
22
- let faceMode = CameraFaceMode.front;
23
- let mediaDevice = null;
24
- let mediaDevices = null;
25
- let mediaStream = null;
26
- let isSimd = false;
27
- const debugType = getDebugType();
28
- const isDebugWithImages = ['900', '901', '902', '903'].includes(debugType);
29
- const cameraHeight = 1440;
30
- const cameraWidth = 2560;
31
- const cameraLowResHeight = 1080;
32
- const cameraLowResWidth = 1920;
33
- getIsSIMD().then((simd) => (isSimd = simd));
34
- let privid_wasm_result = (operation, id, response_str) => { };
35
- const isVirtualCamera = (deviceLabel) => {
36
- const virtualCameraKeywords = ['virtual', 'obs', 'software', 'manycam'];
37
- return virtualCameraKeywords.some((keyword) => deviceLabel.toLowerCase().includes(keyword));
38
- };
39
- const callbackWithImageCreation = (callback, imageData, isEnrollFlow) => {
40
- return (result) => {
41
- if (isDebugWithImages) {
42
- createImages([imageData], `${ImageType.original}_${result === null || result === void 0 ? void 0 : result.face_validation_status}_${result === null || result === void 0 ? void 0 : result.antispoof_status}`, isEnrollFlow);
43
- }
44
- callback(result);
45
- };
46
- };
47
- const preparePrivdWasmResult = (callback, callbackType, image, config) => {
48
- const callbackForImageCreation = callbackWithImageCreation(callback, image, false);
49
- privid_wasm_result = createCallback({
50
- type: callbackType,
51
- callbackFunction: callbackForImageCreation,
52
- imageData: (config === null || config === void 0 ? void 0 : config.sendImageToJS) ? image : undefined,
53
- });
54
- };
55
- const prepareCameraResult = (stream, devices, faceMode, videoElement) => __awaiter(void 0, void 0, void 0, function* () {
56
- const track = stream.getVideoTracks()[0];
57
- const capabilities = track.getCapabilities ? track.getCapabilities() : null;
58
- const settings = track.getSettings();
59
- printLogs('settings: ', settings);
60
- if (capabilities) {
61
- printLogs('capabilities: ', capabilities);
62
- }
63
- yield startVideo(videoElement, stream);
64
- mediaStream = stream;
65
- mediaDevices = devices;
66
- return {
67
- status: true,
68
- stream,
69
- devices,
70
- faceMode,
71
- settings,
72
- capabilities,
73
- errorMessage: null,
74
- };
75
- });
76
- const openCameraMobile = (domElement, requestFaceMode = null, canvasResolution, requireHD = false, isDocumentScan) => __awaiter(void 0, void 0, void 0, function* () {
77
- try {
78
- if (mediaStream) {
79
- mediaStream.getTracks().forEach((track) => track.stop());
80
- mediaStream = null;
81
- }
82
- let inCatchBlock = false;
83
- videoElement = domElement;
84
- printLogs('Opening Camera on Mobile', '');
85
- let devices = yield navigator.mediaDevices.enumerateDevices();
86
- devices = devices.filter((d) => d.kind === 'videoinput');
87
- devices = getDevicesWithCapabilities(devices);
88
- let stream;
89
- let hasError = true;
90
- while (hasError) {
91
- try {
92
- // @ts-ignore
93
- const videoConstraint = getVideoConstraints(yield getCameraList(faceMode === 'back'),
94
- // @ts-ignore
95
- facingMode[faceMode], requireHD, isDocumentScan, canvasResolution, inCatchBlock);
96
- printLogs(`videoConstraint: `, videoConstraint);
97
- stream = yield navigator.mediaDevices.getUserMedia(
98
- // @ts-ignore
99
- videoConstraint);
100
- hasError = false;
101
- }
102
- catch (e) {
103
- printLogs(`openCameraMobile:' `, e, 'ERROR');
104
- inCatchBlock = true;
105
- // hasError = false;
106
- }
107
- }
108
- return prepareCameraResult(stream, devices, faceMode, domElement);
109
- }
110
- catch (e) {
111
- printLogs(`Error: `, e, 'ERROR');
112
- return null;
113
- }
114
- });
115
- /**
116
- * @ignore
117
- */
118
- const openCameraMacSafari = (domElement, deviceId = null, canvasResolution = { width: cameraWidth, height: cameraHeight }, requireHD = false) => __awaiter(void 0, void 0, void 0, function* () {
119
- var _a, _b, _c, _d;
120
- try {
121
- videoElement = domElement;
122
- printLogs('Opening Camera on Mac Safari', '');
123
- let devices = yield navigator.mediaDevices.enumerateDevices();
124
- devices = devices.filter((d) => d.kind === 'videoinput' && !isVirtualCamera(d.label));
125
- const defaultDeviceId = getDefaultCameraDeviceId();
126
- const externalDeviceId = devices.length > 1 ? devices.find((device) => !device.label.includes('FaceTime')) : devices[0];
127
- const isDefaultDeviceAvailable = devices.find((device) => defaultDeviceId === device.deviceId);
128
- mediaDevice = deviceId || (isDefaultDeviceAvailable ? defaultDeviceId : externalDeviceId.deviceId);
129
- setDefaultCameraDeviceId(mediaDevice);
130
- const deviceCapabilites = getDefaultDevice(devices, mediaDevice);
131
- const resolution = requireHD
132
- ? (canvasResolution === null || canvasResolution === void 0 ? void 0 : canvasResolution.width) || Math.min(((_b = (_a = deviceCapabilites[0]) === null || _a === void 0 ? void 0 : _a.width) === null || _b === void 0 ? void 0 : _b.max) || cameraWidth, cameraWidth)
133
- : (canvasResolution === null || canvasResolution === void 0 ? void 0 : canvasResolution.width) || Math.min(((_d = (_c = deviceCapabilites[0]) === null || _c === void 0 ? void 0 : _c.width) === null || _d === void 0 ? void 0 : _d.max) || cameraLowResWidth, cameraLowResWidth);
134
- const constraints = {
135
- audio: false,
136
- video: {
137
- deviceId: deviceCapabilites[0].deviceId,
138
- width: { ideal: resolution },
139
- height: (canvasResolution === null || canvasResolution === void 0 ? void 0 : canvasResolution.height) ? { ideal: canvasResolution === null || canvasResolution === void 0 ? void 0 : canvasResolution.height } : undefined,
140
- // advance: [{ width: { ideal: 2560 }, height: { ideal: 1440 } }],
141
- },
142
- };
143
- const stream = yield navigator.mediaDevices.getUserMedia(constraints);
144
- return prepareCameraResult(stream, devices, faceMode, domElement);
145
- }
146
- catch (e) {
147
- printLogs(`Error while getAccessToCamera: `, e, 'ERROR');
148
- return null;
149
- }
150
- });
151
- const openCameraFirefox = (domElement, canvasResolution = { width: cameraWidth, height: cameraHeight }, requireHD = false) => __awaiter(void 0, void 0, void 0, function* () {
152
- printLogs('Open Camera Firefox!', '');
153
- videoElement = domElement;
154
- yield navigator.mediaDevices.getUserMedia({ audio: false, video: true });
155
- try {
156
- let devices = [];
157
- devices = yield navigator.mediaDevices.enumerateDevices();
158
- printLogs(`devices: `, devices);
159
- devices = devices.filter((d) => d.kind === 'videoinput' && !isVirtualCamera(d.label));
160
- if (devices.length === 0) {
161
- printLogs('NO_CAMERA', '', 'ERROR');
162
- throw new Error('NO_CAMERA');
163
- }
164
- const constraints = {
165
- audio: false,
166
- video: {
167
- width: { ideal: (canvasResolution === null || canvasResolution === void 0 ? void 0 : canvasResolution.width) || requireHD ? cameraWidth : cameraLowResWidth },
168
- height: (canvasResolution === null || canvasResolution === void 0 ? void 0 : canvasResolution.height) || 1080,
169
- },
170
- aspectRatio: 1.7777777778,
171
- focusMode: 'continuous',
172
- facingMode: facingMode[faceMode] || 'user',
173
- };
174
- const stream = yield navigator.mediaDevices.getUserMedia(constraints);
175
- return prepareCameraResult(stream, devices, faceMode, domElement);
176
- }
177
- catch (e) {
178
- if (parseInt(debugType, 10) >= 2) {
179
- printLogs(`Error while getAccessToCamera `, e, 'ERROR');
180
- }
181
- return null;
182
- }
183
- });
184
- export const openCamera = ({ videoElementId, deviceId, requestFaceMode, canvasResolution, isDocumentScan, }) => __awaiter(void 0, void 0, void 0, function* () {
185
- var _e;
186
- videoElement = videoElementId;
187
- faceMode = requestFaceMode;
188
- const { name: browserName, os } = detect();
189
- yield navigator.mediaDevices.getUserMedia({ video: true, audio: false }).then((mediaStream) => {
190
- const stream = mediaStream;
191
- const tracks = stream.getTracks();
192
- tracks.forEach((track) => track.stop());
193
- });
194
- // Firefox
195
- if (browserName === 'firefox') {
196
- return openCameraFirefox(videoElementId, canvasResolution);
197
- }
198
- // Mobile
199
- if (iOS() || ['iOS', 'android', 'Android OS'].includes(os)) {
200
- return openCameraMobile(videoElementId, requestFaceMode, canvasResolution, null, isDocumentScan);
201
- }
202
- // Mac Safari Browser
203
- if (os === 'Mac OS' && browserName === 'safari') {
204
- return openCameraMacSafari(videoElementId, deviceId, canvasResolution, null);
205
- }
206
- try {
207
- let devices = [];
208
- devices = yield navigator.mediaDevices.enumerateDevices();
209
- devices = devices.filter((d) => d.kind === 'videoinput' && !isVirtualCamera(d.label));
210
- printLogs(`Devices: `, devices);
211
- if (devices.length === 0) {
212
- printLogs('NO_CAMERA', '', 'ERROR');
213
- throw new Error('NO_CAMERA');
214
- }
215
- let defaultDeviceId = getDefaultCameraDeviceId();
216
- if (deviceId) {
217
- defaultDeviceId = deviceId;
218
- }
219
- if (!mediaDevice) {
220
- if (deviceId) {
221
- mediaDevice = deviceId;
222
- }
223
- else {
224
- if (defaultDeviceId) {
225
- const isDefaultDeviceAvailable = devices.find((device) => defaultDeviceId === device.deviceId);
226
- mediaDevice = isDefaultDeviceAvailable ? defaultDeviceId : devices[0].deviceId;
227
- }
228
- else {
229
- mediaDevice = devices[0].deviceId;
230
- }
231
- }
232
- }
233
- const isWindowsDevice = () => {
234
- if (['windows', 'win16', 'win32', 'wince'].includes(navigator.platform.toUpperCase())) {
235
- return true;
236
- }
237
- else {
238
- return false;
239
- }
240
- };
241
- const deviceCapabilites = getDefaultDevice(devices, mediaDevice);
242
- const isMacFaceTimeCamera = isFaceTimeCamera((_e = deviceCapabilites[0]) === null || _e === void 0 ? void 0 : _e.label, isDocumentScan);
243
- const getBestResolution = () => __awaiter(void 0, void 0, void 0, function* () {
244
- var _f, _g;
245
- let resolution = (canvasResolution === null || canvasResolution === void 0 ? void 0 : canvasResolution.width) || Math.min(((_g = (_f = deviceCapabilites[0]) === null || _f === void 0 ? void 0 : _f.width) === null || _g === void 0 ? void 0 : _g.max) || cameraWidth, cameraWidth);
246
- let hasError = true;
247
- let constraints = {
248
- audio: false,
249
- video: {
250
- deviceId: deviceCapabilites[0].deviceId,
251
- width: { ideal: resolution },
252
- height: (canvasResolution === null || canvasResolution === void 0 ? void 0 : canvasResolution.height) ? { ideal: canvasResolution === null || canvasResolution === void 0 ? void 0 : canvasResolution.height } : { ideal: cameraHeight },
253
- aspectRatio: isMacFaceTimeCamera ? 1 : 1.777777778,
254
- resizeMode: 'none',
255
- facingMode: isWindowsDevice() ? 'user' : undefined,
256
- },
257
- };
258
- let stream;
259
- while (hasError) {
260
- try {
261
- stream = yield navigator.mediaDevices.getUserMedia(constraints);
262
- if (stream)
263
- hasError = false;
264
- }
265
- catch (e) {
266
- resolution = getTheNextResolutionAvailable(resolution);
267
- constraints = Object.assign(Object.assign({}, constraints), { video: Object.assign(Object.assign({}, constraints.video), { width: { ideal: resolution } }) });
268
- }
269
- }
270
- return stream;
271
- });
272
- let stream;
273
- stream = yield getBestResolution();
274
- return prepareCameraResult(stream, devices, faceMode, videoElementId);
275
- }
276
- catch (e) {
277
- printLogs(`Error while getAccessToCamera: `, e, 'ERROR');
278
- return null;
279
- }
280
- });
281
- function startVideo(videoElement, stream) {
282
- return __awaiter(this, void 0, void 0, function* () {
283
- const element = document.getElementById(videoElement);
284
- element.srcObject = stream;
285
- element.play();
286
- yield new Promise((resolve) => (element.onplaying = resolve));
287
- enableMutationObserver(element, stream);
288
- });
289
- }
290
- let videoMutationObserver = null;
291
- function enableMutationObserver(videoElement, stream) {
292
- videoMutationObserver = new MutationObserver(() => {
293
- if (videoElement.srcObject !== stream) {
294
- printLogs('Unauthorized video source change detected! Resetting to correct camera.', '', 'WARN');
295
- videoElement.srcObject = stream;
296
- }
297
- });
298
- videoMutationObserver.observe(videoElement, { attributes: true, attributeFilter: ['srcObject'] });
299
- }
300
- /**
301
- * This function close camera, and clear all memories related to the camera.
302
- * @category Face
303
- * @param domElement id of the video tag
304
- * @deprecated This function is being replaced with cameraClose.
305
- */
306
- export const closeCamera = (element) => __awaiter(void 0, void 0, void 0, function* () {
307
- try {
308
- const video = element || videoElement;
309
- const videoEl = document.getElementById(video);
310
- // Para o stream associado ao elemento, se ainda existir
311
- const streamFromElement = videoEl === null || videoEl === void 0 ? void 0 : videoEl.srcObject;
312
- if (streamFromElement) {
313
- streamFromElement.getTracks().forEach((track) => track.stop());
314
- videoEl.srcObject = null;
315
- }
316
- // If mediaStream is still active independent of stop all tracks, i'm forcing the stop again
317
- if (mediaStream) {
318
- mediaStream.getTracks().forEach((track) => track.stop());
319
- mediaStream = null;
320
- }
321
- // Clear the video element source and variable memories
322
- videoElement = null;
323
- mediaDevice = null;
324
- mediaDevices = null;
325
- // if observer is active, disconnect it
326
- if (videoMutationObserver) {
327
- videoMutationObserver.disconnect();
328
- videoMutationObserver = null;
329
- }
330
- }
331
- catch (err) {
332
- printLogs(`Close Camera: `, err, 'ERROR');
333
- }
334
- });
335
- /**
336
- * This function open camera, and returns the stream, current faceMode and the list of available media devices
337
- * @category Face
338
- * @param domElement id of the video tag
339
- */
340
- const getTheNextResolutionAvailable = (currentResolution) => {
341
- printLogs(`getTheNextResolutionAvailable `, currentResolution);
342
- const resolutions = [2560, 1920, 1600, 1552, 1440, 1280, 1024, 960, 800, 720, 704, 640].sort((a, b) => b - a);
343
- return resolutions.find((e) => e < currentResolution) || 640;
344
- };
345
- /**
346
- * This function switch camera from front to back on mobile, and to another device on desktop
347
- * @category Face
348
- * @param selectedCamera Selected camera either front or back
349
- * @param device Selected camera ID
350
- * @param canvasResolution
351
- * @deprecated This function is being replaced with cameraSwitch.
352
- */
353
- export const switchCamera = (selectedCamera, device, canvasResolution) => __awaiter(void 0, void 0, void 0, function* () {
354
- if (!videoElement)
355
- return;
356
- let devices = [];
357
- if (mediaStream) {
358
- mediaStream.getTracks().forEach((track) => track.stop());
359
- }
360
- devices = yield navigator.mediaDevices.enumerateDevices();
361
- devices = devices.filter((d) => d.kind === 'videoinput');
362
- devices = getDevicesWithCapabilities(devices);
363
- const deviceCapabilites = getDefaultDevice(devices, device);
364
- if (selectedCamera)
365
- faceMode = selectedCamera;
366
- const getBestResolution = () => __awaiter(void 0, void 0, void 0, function* () {
367
- var _h, _j, _k, _l;
368
- let resolution = (canvasResolution === null || canvasResolution === void 0 ? void 0 : canvasResolution.width) || Math.min(((_j = (_h = deviceCapabilites[0]) === null || _h === void 0 ? void 0 : _h.width) === null || _j === void 0 ? void 0 : _j.max) || cameraWidth, cameraWidth);
369
- const isPortraitMobileCamera = isMobileBackCameraPortrait(deviceCapabilites[0]);
370
- let hasError = true;
371
- const videoConstraints = {
372
- deviceId: deviceCapabilites[0].deviceId,
373
- width: { ideal: calculateWidth() },
374
- height: { ideal: calculateHeight() },
375
- facingMode: ((_l = (_k = deviceCapabilites[0]) === null || _k === void 0 ? void 0 : _k.facingMode) === null || _l === void 0 ? void 0 : _l[0]) || undefined,
376
- focusMode: 'continuous',
377
- aspectRatio: calculateAspectRatio(),
378
- resizeMode: 'none',
379
- };
380
- const constraints = {
381
- audio: false,
382
- video: videoConstraints, // Apply video constraints
383
- };
384
- function calculateWidth() {
385
- if (canvasResolution === null || canvasResolution === void 0 ? void 0 : canvasResolution.width) {
386
- return resolution; // Use the specified resolution if canvas width is available
387
- }
388
- if (isPortraitMobileCamera) {
389
- return cameraHeight; // Use camera height for portrait mobile camera
390
- }
391
- return resolution; // Use the specified resolution for other cases
392
- }
393
- function calculateHeight() {
394
- if (canvasResolution === null || canvasResolution === void 0 ? void 0 : canvasResolution.height) {
395
- return canvasResolution.height; // Use the specified canvas height
396
- }
397
- return cameraHeight; // Use camera height if canvas height is not available
398
- }
399
- function calculateAspectRatio() {
400
- if (canvasResolution === null || canvasResolution === void 0 ? void 0 : canvasResolution.width) {
401
- return 1.7777777778; // 16:9 aspect ratio if canvas width is available
402
- }
403
- if (isPortraitMobileCamera) {
404
- return 1; // 1:1 aspect ratio for portrait mobile camera
405
- }
406
- return 1.7777777778; // 16:9 aspect ratio for other cases
407
- }
408
- let stream;
409
- while (hasError) {
410
- try {
411
- stream = yield navigator.mediaDevices.getUserMedia(constraints);
412
- hasError = false;
413
- }
414
- catch (e) {
415
- resolution = getTheNextResolutionAvailable(resolution);
416
- constraints.video = Object.assign(Object.assign({}, constraints.video), { width: { ideal: resolution } });
417
- }
418
- }
419
- printLogs(`bestconstraints: `, constraints);
420
- return stream;
421
- });
422
- if (device) {
423
- mediaDevice = device;
424
- setDefaultCameraDeviceId(device);
425
- }
426
- if (selectedCamera && !device) {
427
- if (selectedCamera) {
428
- const regex = selectedCamera === CameraFaceMode.back ? /back/gi : /front/gi;
429
- devices = devices.filter((d) => regex.test(d.label));
430
- }
431
- const getBestResolutionWithFacingMode = () => __awaiter(void 0, void 0, void 0, function* () {
432
- var _m, _o;
433
- const deviceCapabilites = getDefaultDevice(devices, devices[0].deviceId);
434
- const { name: browserName, os } = detect();
435
- const resolutionWidth = (canvasResolution === null || canvasResolution === void 0 ? void 0 : canvasResolution.width) || (iOS() || ['iOS'].includes(os) ? cameraLowResWidth : cameraWidth);
436
- const resolutionHeight = (canvasResolution === null || canvasResolution === void 0 ? void 0 : canvasResolution.height) || (iOS() || ['iOS'].includes(os) ? cameraLowResHeight : cameraHeight);
437
- let hasError = true;
438
- const constraints = {
439
- audio: false,
440
- video: {
441
- // deviceId: deviceCapabilites[0].deviceId,
442
- width: { ideal: resolutionWidth },
443
- facingMode: faceMode ? facingMode[faceMode] : 'user',
444
- height: { ideal: resolutionHeight },
445
- resizeMode: 'none',
446
- },
447
- advance: [
448
- {
449
- focusMode: 'continuous',
450
- resizeMode: 'none',
451
- // @ts-ignore
452
- focusDistance: Math.min(((_o = (_m = deviceCapabilites[0]) === null || _m === void 0 ? void 0 : _m.focusDistance) === null || _o === void 0 ? void 0 : _o.max) || 100, 100),
453
- aspectRatio: 1.7777777778,
454
- },
455
- ],
456
- };
457
- let stream;
458
- while (hasError) {
459
- try {
460
- stream = yield navigator.mediaDevices.getUserMedia(constraints);
461
- hasError = false;
462
- }
463
- catch (e) {
464
- //
465
- }
466
- }
467
- printLogs(`bestconstraints: `, constraints);
468
- return stream;
469
- });
470
- try {
471
- // eslint-disable-next-line no-nested-ternary
472
- const stream = yield getBestResolutionWithFacingMode();
473
- const element = document.getElementById(videoElement);
474
- element.srcObject = stream;
475
- mediaStream = stream;
476
- const track = stream.getVideoTracks()[0];
477
- const capabilities = (track === null || track === void 0 ? void 0 : track.getCapabilities) ? track.getCapabilities() : null;
478
- const settings = track.getSettings();
479
- printLogs(`switch camera capabilities: `, capabilities);
480
- printLogs(`switch camera settings: `, settings);
481
- // eslint-disable-next-line consistent-return
482
- return { capabilities, settings };
483
- }
484
- catch (e) {
485
- printLogs(`Error while getAccessToCamera : `, e, 'ERROR');
486
- yield switchCamera(null, devices[0].deviceId, canvasResolution);
487
- }
488
- }
489
- else {
490
- try {
491
- if (videoMutationObserver) {
492
- videoMutationObserver.disconnect();
493
- }
494
- // eslint-disable-next-line no-nested-ternary
495
- const stream = yield getBestResolution();
496
- const element = document.getElementById(videoElement);
497
- element.srcObject = stream;
498
- mediaStream = stream;
499
- const track = stream.getVideoTracks()[0];
500
- const capabilities = (track === null || track === void 0 ? void 0 : track.getCapabilities) ? track.getCapabilities() : null;
501
- const settings = track.getSettings();
502
- printLogs(`switch camera capabilities: `, capabilities);
503
- printLogs(`switch camera settings: `, settings);
504
- enableMutationObserver(element, stream);
505
- // eslint-disable-next-line consistent-return
506
- return { capabilities, settings };
507
- }
508
- catch (e) {
509
- printLogs(`Error while getAccessToCamera : `, e, 'ERROR');
510
- yield switchCamera(null, devices[0].deviceId, canvasResolution);
511
- }
512
- }
513
- });
514
- export const getBaseConfigEnroll = () => ({
515
- input_image_format: 'rgba',
516
- angle_rotation_left_threshold: 20.0,
517
- angle_rotation_right_threshold: 20.0,
518
- threshold_high_vertical_enroll: 0.9,
519
- threshold_down_vertical_enroll: 2.2,
520
- anti_spoofing_threshold: 0.8,
521
- threshold_profile_enroll: 0.66,
522
- blur_threshold_enroll_pred: 40,
523
- threshold_user_too_close: 0.52,
524
- threshold_user_too_far: 0.165,
525
- allow_only_one_face: true,
526
- threshold_user_up: 0.15,
527
- threshold_user_down: 0.9,
528
- threshold_user_left: 0.8,
529
- threshold_user_right: 0.2,
530
- });
531
- // eslint-disable-next-line consistent-return
532
- /**
533
- * @deprecated This function is being replaced with faceEnroll.
534
- */
535
- export function enroll({ callback, config, element, returnPortrait = false }) {
536
- return __awaiter(this, void 0, void 0, function* () {
537
- printLogs('ENROLL_ONE_FA', '');
538
- // eslint-disable-next-line consistent-return
539
- let configJSON = getBaseConfigEnroll();
540
- const { os } = detect();
541
- if (['iOS', 'android', 'Android OS'].includes(os)) {
542
- configJSON = Object.assign(Object.assign({}, configJSON), { threshold_user_right: 0.2, threshold_user_left: 0.8, threshold_profile_enroll: 0.66 });
543
- }
544
- if (config) {
545
- configJSON = Object.assign(Object.assign({}, configJSON), config);
546
- }
547
- if (element) {
548
- videoElement = element;
549
- }
550
- // eslint-disable-next-line consistent-return
551
- const videoEl = document.getElementById(videoElement);
552
- const height = (videoEl === null || videoEl === void 0 ? void 0 : videoEl.videoHeight) || 0;
553
- const width = (videoEl === null || videoEl === void 0 ? void 0 : videoEl.videoWidth) || 0;
554
- // eslint-disable-next-line consistent-return
555
- if (width === 0)
556
- return { result: 'error' };
557
- printLogs(`isValid: `, { height, width });
558
- const canvas = document.createElement('canvas');
559
- canvas.setAttribute('id', 'test-canvas');
560
- canvas.setAttribute('height', `${height}`);
561
- canvas.setAttribute('width', `${width}`);
562
- const context = canvas.getContext('2d', { willReadFrequently: true });
563
- if (faceMode === CameraFaceMode.front) {
564
- context.translate(width, 0);
565
- context.scale(-1, 1);
566
- }
567
- context.drawImage(videoEl, 0, 0);
568
- const imageData = context.getImageData(0, 0, width, height);
569
- const callbackForImageCreation = callbackWithImageCreation(callback, imageData, true);
570
- privid_wasm_result = createCallback({ type: callbackTypeEnum.enroll, callbackFunction: callbackForImageCreation });
571
- const bestImage = yield ultraEnroll(imageData, isSimd, JSON.stringify(configJSON), proxy(privid_wasm_result));
572
- // eslint-disable-next-line consistent-return
573
- if (returnPortrait) {
574
- return imageData;
575
- }
576
- return bestImage;
577
- });
578
- }
579
- // Base configuration object with common settings
580
- const getBaseConfigPredict = () => ({
581
- input_image_format: 'rgba',
582
- angle_rotation_left_threshold: 20.0,
583
- angle_rotation_right_threshold: 20.0,
584
- anti_spoofing_threshold: 0.8,
585
- threshold_profile_predict: 0.66,
586
- blur_threshold_enroll_pred: 40,
587
- threshold_user_too_close: 0.52,
588
- threshold_user_too_far: 0.165,
589
- threshold_user_up: 0.15,
590
- threshold_user_down: 0.9,
591
- threshold_user_left: 0.8,
592
- threshold_user_right: 0.2,
593
- threshold_high_vertical_predict: 0.9,
594
- threshold_down_vertical_predict: 2.2,
595
- url_name_override: '',
596
- disallowed_results: [20],
597
- disable_predict_mf: false,
598
- mf_count_override: 5,
599
- });
600
- const faceLoginCanvas = document.createElement('canvas');
601
- // Helper function to prepare canvas and get image data
602
- const prepareCanvasAndGetImageData = (elementId, useExistingCanvas = false) => {
603
- const videoEl = document.getElementById(elementId);
604
- const height = (videoEl === null || videoEl === void 0 ? void 0 : videoEl.videoHeight) || 0;
605
- const width = (videoEl === null || videoEl === void 0 ? void 0 : videoEl.videoWidth) || 0;
606
- if (width === 0)
607
- return { result: 'error' };
608
- printLogs(`isValid:`, { height, width });
609
- let canvas;
610
- if (useExistingCanvas) {
611
- canvas = faceLoginCanvas;
612
- }
613
- else {
614
- canvas = document.createElement('canvas');
615
- }
616
- canvas.setAttribute('id', 'test-canvas');
617
- canvas.setAttribute('height', `${height}`);
618
- canvas.setAttribute('width', `${width}`);
619
- const context = canvas.getContext('2d', { willReadFrequently: true });
620
- if (faceMode === CameraFaceMode.front) {
621
- context.translate(width, 0);
622
- context.scale(-1, 1);
623
- }
624
- context.drawImage(videoEl, 0, 0);
625
- const imageData = context.getImageData(0, 0, width, height);
626
- return { imageData, canvas, width, height };
627
- };
628
- /**
629
- *
630
- */
631
- const performPredict = (options) => {
632
- return runUltraProcess(ultraPredict, Object.assign(Object.assign({}, options), { callbackType: callbackTypeEnum.predict, logMessage: options.logMessage || '---------------------PREDICT_ONE_FA----------------------' }));
633
- };
634
- /**
635
- * @deprecated This function is being replaced with faceAgeEstimation.
636
- */
637
- export const estimateAge = (options) => {
638
- return runUltraProcess(ultraAgeEstimate, Object.assign(Object.assign({}, options), { callbackType: callbackTypeEnum.ageEstimation, logMessage: options.logMessage || '---------------------AGE_ESTIMATION----------------------', config: Object.assign({ anti_spoofing_threshold: 0.8, mf_count_override: 5, disable_estimate_age_mf: false, threshold_user_too_close: 0.8, threshold_profile_enroll: 0.6, threshold_user_too_far: 0.2, allow_only_one_face: false }, options.config) }));
639
- };
640
- const runUltraProcess = (fn, options) => __awaiter(void 0, void 0, void 0, function* () {
641
- const { callback, image, config = {}, element, returnPortrait = false, useExistingCanvas = false, logMessage = '---------------------ULTRA_PROCESS----------------------', callbackType, } = options;
642
- printLogs(`${logMessage}`, '');
643
- let configJSON = getBaseConfigPredict();
644
- // const { os } = detect();
645
- // if (['iOS', 'android', 'Android OS'].includes(os)) {
646
- // configJSON = {
647
- // ...configJSON,
648
- // threshold_user_too_far: 0.31,
649
- // threshold_user_too_close: 0.55,
650
- // threshold_user_right: 0.1,
651
- // threshold_user_left: 0.9,
652
- // };
653
- // }
654
- if (config) {
655
- configJSON = Object.assign(Object.assign({}, configJSON), config);
656
- }
657
- if (image) {
658
- preparePrivdWasmResult(callback, callbackType, image, config);
659
- return yield fn([image], isSimd, JSON.stringify(configJSON), proxy(privid_wasm_result));
660
- }
661
- if (element) {
662
- videoElement = element;
663
- }
664
- const result = prepareCanvasAndGetImageData(videoElement, useExistingCanvas);
665
- if ('result' in result)
666
- return result;
667
- const { imageData, canvas } = result;
668
- preparePrivdWasmResult(callback, callbackType, imageData, config);
669
- printLogs(`Config JSON: `, configJSON);
670
- yield fn([imageData], isSimd, JSON.stringify(configJSON), proxy(privid_wasm_result));
671
- if (returnPortrait) {
672
- return imageData;
673
- }
674
- releaseCanvas(canvas);
675
- });
676
- /**
677
- * @deprecated This function is being replaced with facePredict.
678
- */
679
- export const faceLogin = (props) => __awaiter(void 0, void 0, void 0, function* () {
680
- return performPredict(Object.assign(Object.assign({}, props), { useExistingCanvas: true, logMessage: '---------------------FACE_LOGIN----------------------' }));
681
- });
682
- /**
683
- * @deprecated This function is being replaced with facePredict({ type: 'VERIFY' }).
684
- * This function performs predict, the camera should already be open. the functions performs the identification return the result then restart again.
685
- * @category Face
686
- * @param callback Callbacks triggered on the predict operation
687
- * @param config Configuration recommeded default: { input_image_format: "rgba" }
688
- * @param element Element id of video tag. (Optional) By default it uses the element id used when opening the camera using openCamera()
689
- * @param image ImageData, If there is an image passed, it will be predicting the image instead of the video feed.
690
- */
691
- export const predictVerify = (props) => __awaiter(void 0, void 0, void 0, function* () {
692
- return performPredict(Object.assign({}, props));
693
- });
694
- /**
695
- * @deprecated This function is being replaced with facePredict({ type: 'PREDICT' }).
696
- */
697
- export const predict = (props) => __awaiter(void 0, void 0, void 0, function* () {
698
- return performPredict(Object.assign(Object.assign({}, props), { config: Object.assign({ url_name_override: 'predict' }, props.config) }));
699
- });
700
- /**
701
- * @deprecated This function is being replaced with facePredict({ type: 'PREDICT_STATUS' }).
702
- */
703
- export const predictWithStatus = (props) => __awaiter(void 0, void 0, void 0, function* () {
704
- return performPredict(Object.assign(Object.assign({}, props), { config: Object.assign({ url_name_override: 'predict-status' }, props.config) }));
705
- });
706
- /**
707
- * @deprecated This function is being replaced with facePredict({ type: 'CONFIRM_USER' }).
708
- */
709
- export const predictConfirmUser = (props) => __awaiter(void 0, void 0, void 0, function* () {
710
- return performPredict(Object.assign(Object.assign({}, props), { config: Object.assign({ url_name_override: 'confirm-user' }, props.config) }));
711
- });
712
- /**
713
- * @deprecated This function is being replaced with facePredict({ type: 'ULTRA_VERIFY' }).
714
- */
715
- export const ultraVerify = (props) => __awaiter(void 0, void 0, void 0, function* () {
716
- return performPredict(Object.assign(Object.assign({}, props), { config: Object.assign({ url_name_override: 'verify-ultra' }, props.config) }));
717
- });
718
- /**
719
- * @deprecated This function is being replaced with facePredict({ type: 'DELETE' }).
720
- */
721
- export const predictDeleteUser = (props) => __awaiter(void 0, void 0, void 0, function* () {
722
- return performPredict(Object.assign(Object.assign({}, props), { config: Object.assign({ url_name_override: 'predict/delete' }, props.config) }));
723
- });
724
- const getDefaultDevice = (devices, device) => devices.reduce((acc, val) => {
725
- if (val.deviceId === device) {
726
- // @ts-ignore
727
- if (val === null || val === void 0 ? void 0 : val.getCapabilities) {
728
- // @ts-ignore
729
- acc.push(Object.assign(Object.assign({}, val.getCapabilities()), { label: val.label }));
730
- }
731
- else {
732
- acc.push(val);
733
- }
734
- }
735
- return acc;
736
- }, []);
737
- const getDevicesWithCapabilities = (devices) => devices.map((device) => {
738
- // Check if 'getCapabilities' exists on 'device'
739
- // @ts-ignore
740
- if (device.getCapabilities) {
741
- // Use 'device.getCapabilities()' directly without optional chaining
742
- // @ts-ignore
743
- const capabilities = device.getCapabilities();
744
- // Return a new object with capabilities and label
745
- return Object.assign(Object.assign({}, capabilities), { label: device.label });
746
- }
747
- return device;
748
- });
749
- function releaseCanvas(canvas) {
750
- try {
751
- printLogs('STARTING TO RELEASE CANVAS', '');
752
- // eslint-disable-next-line no-param-reassign
753
- canvas.width = 1;
754
- // eslint-disable-next-line no-param-reassign
755
- canvas.height = 1;
756
- const ctx = canvas.getContext('2d', { willReadFrequently: true });
757
- // eslint-disable-next-line no-unused-expressions
758
- ctx && ctx.clearRect(0, 0, 1, 1);
759
- // eslint-disable-next-line no-param-reassign
760
- canvas = null;
761
- printLogs('CANVAS RELEASED', '');
762
- }
763
- catch (e) {
764
- printLogs(`CLEARING CANVAS: `, e, 'ERROR');
765
- }
766
- }
767
- /**
768
- *
769
- * @deprecated This function is being replaced with engineEncryptData.
770
- */
771
- export const pkiEncryptData = (payload) => __awaiter(void 0, void 0, void 0, function* () {
772
- var _p;
773
- const stringPayload = JSON.stringify(payload);
774
- const encryptedData = yield pkiEncrypt(stringPayload);
775
- return (_p = encryptedData === null || encryptedData === void 0 ? void 0 : encryptedData.operation_result) === null || _p === void 0 ? void 0 : _p.request;
776
- });
777
- /**
778
- * @deprecated This function is being replaced with engineCheckModelsAreLoaded.
779
- */
780
- export const checkIfModelsAreLoaded = (isEnroll) => __awaiter(void 0, void 0, void 0, function* () {
781
- const result = yield checkIfModelsLoaded(isEnroll);
782
- return result;
783
- });
784
- const frontScanCanvas = document.createElement('canvas');
785
- /**
786
- * @deprecated This function is being replaced with documentScanGovernmentPhotoId.
787
- */
788
- export const scanFrontDocument = ({ callback, config }) => __awaiter(void 0, void 0, void 0, function* () {
789
- printLogs('________________ FRONT DOCUMENT SCAN ______________', '');
790
- const videoEl = document.getElementById(videoElement);
791
- let configuration = {
792
- input_image_format: 'rgba',
793
- fingers_over_document_threshold: 0.2,
794
- };
795
- if (config) {
796
- configuration = Object.assign(Object.assign({}, configuration), config);
797
- }
798
- if (!videoElement || !videoEl) {
799
- printLogs(`Capture need the video element id`, '', 'ERROR');
800
- return { result: 'error' };
801
- }
802
- let height = videoEl.videoHeight;
803
- let width = videoEl.videoWidth;
804
- if (isMobileFunc()) {
805
- height = videoEl.videoHeight;
806
- width = videoEl.videoWidth;
807
- }
808
- frontScanCanvas.setAttribute('id', 'test-canvas');
809
- frontScanCanvas.setAttribute('height', `${height}`);
810
- frontScanCanvas.setAttribute('width', `${width}`);
811
- const context = frontScanCanvas.getContext('2d', { willReadFrequently: true });
812
- context.drawImage(videoEl, 0, 0);
813
- let imageData = context.getImageData(0, 0, width, height);
814
- privid_wasm_result = createCallback({
815
- type: callbackTypeEnum.frontScan,
816
- callbackFunction: callback,
817
- // imageData: doOcr ? imageData : undefined,
818
- });
819
- const cb = proxy(privid_wasm_result);
820
- if (['900', '901', '902', '903'].includes(debugType)) {
821
- yield createImages([imageData], `${ImageType.original}_front_document_scan`, true);
822
- }
823
- try {
824
- configuration = JSON.stringify(configuration);
825
- yield ultraScanFrontDocument(imageData, isSimd, configuration, cb);
826
- imageData = null;
827
- return;
828
- }
829
- catch (e) {
830
- printLogs(`isValidPhotoID error: `, e, 'ERROR');
831
- return {
832
- result: -1,
833
- };
834
- }
835
- });
836
- /**
837
- * @deprecated This function is being replaced with documentScanPassport.
838
- */
839
- export const scanPassport = ({ callback, config }) => __awaiter(void 0, void 0, void 0, function* () {
840
- printLogs('________________ PASSPORT SCAN ______________', '');
841
- const videoEl = document.getElementById(videoElement);
842
- let configuration = {
843
- input_image_format: 'rgba',
844
- };
845
- if (config) {
846
- configuration = Object.assign(Object.assign({}, configuration), config);
847
- }
848
- privid_wasm_result = createCallback({ type: callbackTypeEnum.passportScan, callbackFunction: callback });
849
- if (!videoElement || !videoEl) {
850
- printLogs(`Capture need the video element id`, '', 'ERROR');
851
- return { result: 'error' };
852
- }
853
- let height = videoEl.videoHeight;
854
- let width = videoEl.videoWidth;
855
- if (isMobileFunc()) {
856
- height = videoEl.videoHeight;
857
- width = videoEl.videoWidth;
858
- }
859
- frontScanCanvas.setAttribute('id', 'test-canvas');
860
- frontScanCanvas.setAttribute('height', `${height}`);
861
- frontScanCanvas.setAttribute('width', `${width}`);
862
- const context = frontScanCanvas.getContext('2d', { willReadFrequently: true });
863
- context.drawImage(videoEl, 0, 0);
864
- let imageData = context.getImageData(0, 0, width, height);
865
- const cb = proxy(privid_wasm_result);
866
- if (['900', '901', '902', '903'].includes(debugType)) {
867
- yield createImages([imageData], `${ImageType.original}_passport_scan`, true);
868
- }
869
- try {
870
- configuration = JSON.stringify(configuration);
871
- yield ultraScanFrontDocument(imageData, isSimd, configuration, cb);
872
- imageData = null;
873
- return;
874
- }
875
- catch (e) {
876
- printLogs(`isValidPhotoID error: `, e, 'ERROR');
877
- return {
878
- result: -1,
879
- };
880
- }
881
- });
882
- const backScanCanvas = document.createElement('canvas');
883
- /**
884
- * @deprecated This function is being replaced with documentScanBackGovernmentPhotoId.
885
- */
886
- export const scanBackDocument = ({ callback, image, config }) => __awaiter(void 0, void 0, void 0, function* () {
887
- printLogs('________________ DOCUMENT SCAN ______________', '');
888
- const videoEl = document.getElementById(videoElement);
889
- let configuration = {
890
- input_image_format: 'rgba',
891
- };
892
- if (config) {
893
- configuration = Object.assign(Object.assign({}, configuration), config);
894
- }
895
- const { os } = detect();
896
- if (iOS() || ['iOS', 'android', 'Android OS'].includes(os)) {
897
- privid_wasm_result = createCallback({
898
- type: callbackTypeEnum.backScan,
899
- callbackFunction: callback,
900
- isMobile: true, // barcodeScanEnable
901
- });
902
- }
903
- else if (configuration === null || configuration === void 0 ? void 0 : configuration.document_scan_barcode_only) {
904
- privid_wasm_result = createCallback({
905
- type: callbackTypeEnum.backScan,
906
- callbackFunction: callback,
907
- isMobile: true,
908
- });
909
- }
910
- else if (configuration === null || configuration === void 0 ? void 0 : configuration.detect_barcode_without_parsing) {
911
- privid_wasm_result = createCallback({
912
- type: callbackTypeEnum.backScan,
913
- callbackFunction: callback,
914
- });
915
- }
916
- else {
917
- configuration = Object.assign(Object.assign({}, configuration), { detect_document_only: true });
918
- privid_wasm_result = createCallback({ type: callbackTypeEnum.backScan, callbackFunction: callback });
919
- }
920
- configuration = JSON.stringify(configuration);
921
- if (!videoElement || !videoEl) {
922
- printLogs(`Capture need the video element id`, '', 'ERROR');
923
- return { result: 'error' };
924
- }
925
- let height = videoEl.videoHeight;
926
- let width = videoEl.videoWidth;
927
- // if (isMobileFunc()) {
928
- // height = videoEl.videoHeight;
929
- // width = videoEl.videoWidth;
930
- // }
931
- backScanCanvas.setAttribute('id', 'test-canvas');
932
- backScanCanvas.setAttribute('height', `${height}`);
933
- backScanCanvas.setAttribute('width', `${width}`);
934
- const context = backScanCanvas.getContext('2d', { willReadFrequently: true });
935
- context.drawImage(videoEl, 0, 0);
936
- if ((image === null || image === void 0 ? void 0 : image.width) === 0 || width === 0 || height === 0)
937
- return { result: 'error' };
938
- let imageData = context.getImageData(0, 0, width, height);
939
- let result = null;
940
- if (['900', '901', '902', '903'].includes(debugType)) {
941
- yield createImages([imageData], ImageType.original, true);
942
- }
943
- try {
944
- printLogs(`Configuration: back scan: `, configuration);
945
- // if(isMobileDevice()){
946
- result = yield ultraScanBackDocument(imageData, isSimd, configuration, proxy(privid_wasm_result));
947
- // }
948
- // else{
949
- // privid_wasm_result = createCallback({ type: callbackTypeEnum.backScan, callbackFunction: callback });
950
- // result = await scanDocumentNoFace(imageData, isSimd, proxy(privid_wasm_result), configuration, '3');
951
- // }
952
- imageData = null;
953
- releaseCanvas(backScanCanvas);
954
- return Object.assign({}, result);
955
- }
956
- catch (e) {
957
- printLogs(`isValidPhotoID error: `, e, 'ERROR');
958
- return {
959
- result: -1,
960
- };
961
- }
962
- });
963
- /**
964
- * @deprecated This function is being replaced with compareImageEmbeddings.
965
- */
966
- export const compareEmbeddings = (embeddingsA, embeddingsB, config = {}, callback, encryptData = false) => __awaiter(void 0, void 0, void 0, function* () {
967
- if (encryptData) {
968
- config = Object.assign(Object.assign({}, config), { encrypt_compare_result: true });
969
- }
970
- printLogs(`ULTRA COMPARE: `, {
971
- embeddingsA,
972
- embeddingsB,
973
- config: JSON.stringify(config),
974
- ex: proxy(createCallback({ type: callbackTypeEnum.compareEmbeddings, callbackFunction: callback })),
975
- });
976
- const result = yield ultraCompareEmbeddings(embeddingsA, embeddingsB, JSON.stringify(config), proxy(createCallback({ type: callbackTypeEnum.compareEmbeddings, callbackFunction: callback })));
977
- return result;
978
- });
979
- /**
980
- * @deprecated This function is being replaced with documentExtractOCR.
981
- */
982
- export const documentOcr = ({ inputImage, callback, config }) => __awaiter(void 0, void 0, void 0, function* () {
983
- printLogs('________________ DOCUMENT OCR ______________', '');
984
- const videoEl = document.getElementById(videoElement);
985
- let configuration = {
986
- input_image_format: 'rgba',
987
- calculate_age_from_ocr_text: true,
988
- threshold_doc_x: 0.0,
989
- threshold_doc_y: 0.0,
990
- threshold_doc_too_close: 0.99,
991
- threshold_doc_too_far: 0.1,
992
- };
993
- if (config) {
994
- configuration = Object.assign(Object.assign({}, configuration), config);
995
- }
996
- privid_wasm_result = createCallback({ type: callbackTypeEnum.documentOcr, callbackFunction: callback });
997
- const cb = proxy(privid_wasm_result);
998
- if (['900', '901', '902', '903'].includes(debugType)) {
999
- yield createImages([inputImage], `${ImageType.original}_document_ocr`, true);
1000
- }
1001
- try {
1002
- configuration = JSON.stringify(configuration);
1003
- yield ultraDocumentOcr(inputImage, configuration, cb);
1004
- return;
1005
- }
1006
- catch (e) {
1007
- printLogs(`isValidPhotoID error: `, e, 'ERROR');
1008
- return {
1009
- result: -1,
1010
- };
1011
- }
1012
- });
1013
- /**
1014
- *
1015
- * @deprecated This function is being replaced with engineFreeMemory.
1016
- */
1017
- export const freeFrontScanMemory = () => __awaiter(void 0, void 0, void 0, function* () {
1018
- const result = yield freeMemory();
1019
- return result;
1020
- });
1021
- //# sourceMappingURL=faceModule.js.map