cordova-digital-onboarding 1.0.0 → 1.0.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/lib/index.js ADDED
@@ -0,0 +1,2001 @@
1
+ 'use strict';
2
+
3
+ /******************************************************************************
4
+ Copyright (c) Microsoft Corporation.
5
+
6
+ Permission to use, copy, modify, and/or distribute this software for any
7
+ purpose with or without fee is hereby granted.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
16
+ ***************************************************************************** */
17
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
18
+
19
+ var extendStatics = function(d, b) {
20
+ extendStatics = Object.setPrototypeOf ||
21
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
22
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
23
+ return extendStatics(d, b);
24
+ };
25
+
26
+ function __extends(d, b) {
27
+ if (typeof b !== "function" && b !== null)
28
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
29
+ extendStatics(d, b);
30
+ function __() { this.constructor = d; }
31
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
32
+ }
33
+
34
+ function __awaiter(thisArg, _arguments, P, generator) {
35
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
36
+ return new (P || (P = Promise))(function (resolve, reject) {
37
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
38
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
39
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
40
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
41
+ });
42
+ }
43
+
44
+ function __generator(thisArg, body) {
45
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
46
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
47
+ function verb(n) { return function (v) { return step([n, v]); }; }
48
+ function step(op) {
49
+ if (f) throw new TypeError("Generator is already executing.");
50
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
51
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
52
+ if (y = 0, t) op = [op[0] & 2, t.value];
53
+ switch (op[0]) {
54
+ case 0: case 1: t = op; break;
55
+ case 4: _.label++; return { value: op[1], done: false };
56
+ case 5: _.label++; y = op[1]; op = [0]; continue;
57
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
58
+ default:
59
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
60
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
61
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
62
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
63
+ if (t[2]) _.ops.pop();
64
+ _.trys.pop(); continue;
65
+ }
66
+ op = body.call(thisArg, _);
67
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
68
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
69
+ }
70
+ }
71
+
72
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
73
+ var e = new Error(message);
74
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
75
+ };
76
+
77
+ /**
78
+ * Copyright Wultra s.r.o.
79
+ *
80
+ * This source code is licensed under the Apache License, Version 2.0 license
81
+ * found in the LICENSE file in the root directory of this source tree.
82
+ *
83
+ * SPDX-License-Identifier: Apache-2.0
84
+ */
85
+ /** Log levels for Wultra Digital Onboarding. */
86
+ exports.WDOLogLevel = void 0;
87
+ (function (WDOLogLevel) {
88
+ WDOLogLevel[WDOLogLevel["NONE"] = 0] = "NONE";
89
+ WDOLogLevel[WDOLogLevel["ERROR"] = 1] = "ERROR";
90
+ WDOLogLevel[WDOLogLevel["WARN"] = 2] = "WARN";
91
+ WDOLogLevel[WDOLogLevel["INFO"] = 3] = "INFO";
92
+ WDOLogLevel[WDOLogLevel["DEBUG"] = 4] = "DEBUG";
93
+ })(exports.WDOLogLevel || (exports.WDOLogLevel = {}));
94
+ /** Simple logger utility for Wultra Digital Onboarding SDK. */
95
+ var WDOLogger = /** @class */ (function () {
96
+ function WDOLogger() {
97
+ }
98
+ /* @internal */
99
+ WDOLogger.debug = function (message) {
100
+ this.log(exports.WDOLogLevel.DEBUG, message);
101
+ };
102
+ /* @internal */
103
+ WDOLogger.info = function (message) {
104
+ this.log(exports.WDOLogLevel.INFO, message);
105
+ };
106
+ /* @internal */
107
+ WDOLogger.warn = function (message) {
108
+ this.log(exports.WDOLogLevel.WARN, message);
109
+ };
110
+ /* @internal */
111
+ WDOLogger.error = function (message) {
112
+ this.log(exports.WDOLogLevel.ERROR, message);
113
+ };
114
+ /* @internal */
115
+ WDOLogger.log = function (level, message) {
116
+ if (level <= this.logLevel) {
117
+ console.log("[WDO][".concat(exports.WDOLogLevel[level], "] ").concat(message));
118
+ }
119
+ if (this.listener) {
120
+ this.listener.log(level, message);
121
+ }
122
+ };
123
+ /** Current log level. Messages with a level higher than this will not be logged. */
124
+ WDOLogger.logLevel = exports.WDOLogLevel.INFO;
125
+ /** Listener for custom logging implementation */
126
+ WDOLogger.listener = null;
127
+ return WDOLogger;
128
+ }());
129
+
130
+ /**
131
+ * Copyright Wultra s.r.o.
132
+ *
133
+ * This source code is licensed under the Apache License, Version 2.0 license
134
+ * found in the LICENSE file in the root directory of this source tree.
135
+ *
136
+ * SPDX-License-Identifier: Apache-2.0
137
+ */
138
+ // TODO: add ERROR codes
139
+ var WDOError = /** @class */ (function () {
140
+ function WDOError(message, additionalInfo) {
141
+ this.message = message;
142
+ this.additionalInfo = additionalInfo;
143
+ }
144
+ return WDOError;
145
+ }());
146
+
147
+ /**
148
+ * Copyright Wultra s.r.o.
149
+ *
150
+ * This source code is licensed under the Apache License, Version 2.0 license
151
+ * found in the LICENSE file in the root directory of this source tree.
152
+ *
153
+ * SPDX-License-Identifier: Apache-2.0
154
+ */
155
+ /**
156
+ * Service that can activate PowerAuth instance by user weak credentials (like his email, phone number or client ID) + optional SMS OTP.
157
+ *
158
+ * When the PowerAuth is activated with this service, `WDOVerificationService.isVerificationRequired` will be `true`
159
+ * and you will need to verify the PowerAuth instance via `WDOVerificationService`.
160
+ *
161
+ * This service operates against Wultra Onboarding server (usually ending with `/enrollment-onboarding-server`) and you need to configure networking service with the right URL.
162
+ */
163
+ var WDOBaseActivationService = /** @class */ (function () {
164
+ function WDOBaseActivationService() {
165
+ }
166
+ Object.defineProperty(WDOBaseActivationService.prototype, "hasActiveProcess", {
167
+ /**
168
+ * If the activation process is in progress.
169
+ *
170
+ * Note that even if this property is `true` it can be already discontinued on the server.
171
+ * Calling `status()` for example after the app is launched in this case is recommended.
172
+ */
173
+ get: function () { return !!this.processData; },
174
+ enumerable: false,
175
+ configurable: true
176
+ });
177
+ /**
178
+ * Accept language for the outgoing requests headers.
179
+ * Default value is "en".
180
+ *
181
+ * Standard RFC "Accept-Language" https://tools.ietf.org/html/rfc7231#section-5.3.5
182
+ * Response texts are based on this setting. For example when "de" is set, server
183
+ * will return error texts and other in german (if available).
184
+ */
185
+ WDOBaseActivationService.prototype.changeAcceptLanguage = function (language) {
186
+ this.changeAcceptLanguageImpl(language);
187
+ };
188
+ Object.defineProperty(WDOBaseActivationService.prototype, "processId", {
189
+ /* @internal */
190
+ get: function () { var _a; return (_a = this.processData) === null || _a === void 0 ? void 0 : _a.processId; },
191
+ enumerable: false,
192
+ configurable: true
193
+ });
194
+ // PUBLIC API
195
+ /**
196
+ * Retrieves status of the onboarding activation.
197
+ *
198
+ * @return Promise resolved with onboarding status.
199
+ */
200
+ WDOBaseActivationService.prototype.status = function () {
201
+ return __awaiter(this, void 0, void 0, function () {
202
+ var pid, result;
203
+ return __generator(this, function (_a) {
204
+ switch (_a.label) {
205
+ case 0:
206
+ WDOLogger.debug("Getting activation status for processId=".concat(this.processId));
207
+ return [4 /*yield*/, this.verifyCanStartProcess()];
208
+ case 1:
209
+ _a.sent();
210
+ pid = this.verifyHasActiveProcess();
211
+ return [4 /*yield*/, this.api.activationGetStatus(pid)];
212
+ case 2:
213
+ result = _a.sent();
214
+ return [2 /*return*/, result.onboardingStatus];
215
+ }
216
+ });
217
+ });
218
+ };
219
+ /**
220
+ * Start onboarding activation with user credentials.
221
+ *
222
+ * For example, when you require email and birth date, your object would look like this:
223
+ * ```
224
+ * {
225
+ * email: "<user_email>",
226
+ * birthdate: "<user_birth_date>"
227
+ * }
228
+ * ```
229
+ * @param credentials Object with credentials. Which credentials are needed should be provided by a system/backend provider.
230
+ * @param processType The process type identification. If not specified, the default process type will be used.
231
+ */
232
+ WDOBaseActivationService.prototype.start = function (credentials, processType) {
233
+ return __awaiter(this, void 0, void 0, function () {
234
+ var result;
235
+ return __generator(this, function (_a) {
236
+ switch (_a.label) {
237
+ case 0:
238
+ WDOLogger.debug("Starting activation with credentials: ".concat(JSON.stringify(credentials)));
239
+ if (this.processId) {
240
+ throw new WDOError("Cannot start the process - processId already obtained, cancel first.");
241
+ }
242
+ return [4 /*yield*/, this.verifyCanStartProcess()];
243
+ case 1:
244
+ _a.sent();
245
+ return [4 /*yield*/, this.api.activationStart(credentials, processType)];
246
+ case 2:
247
+ result = _a.sent();
248
+ WDOLogger.info("WDOActivationService.start success");
249
+ WDOLogger.debug(" - processId: ".concat(result.processId));
250
+ this.processData = { processId: result.processId, activationCode: result.activationCode };
251
+ return [2 /*return*/];
252
+ }
253
+ });
254
+ });
255
+ };
256
+ /**
257
+ * Cancel the activation process (issues a cancel request to the backend and clears the local process ID).
258
+ *
259
+ * @param forceCancel When true, the process will be canceled in the SDK even when fails on backend. `true` by default.
260
+ */
261
+ WDOBaseActivationService.prototype.cancel = function () {
262
+ return __awaiter(this, arguments, void 0, function (forceCancel) {
263
+ var pid, error_1;
264
+ if (forceCancel === void 0) { forceCancel = true; }
265
+ return __generator(this, function (_a) {
266
+ switch (_a.label) {
267
+ case 0:
268
+ WDOLogger.debug("Canceling activation for processId=".concat(this.processId, ", forceCancel=").concat(forceCancel));
269
+ pid = this.verifyHasActiveProcess();
270
+ _a.label = 1;
271
+ case 1:
272
+ _a.trys.push([1, 3, , 4]);
273
+ return [4 /*yield*/, this.api.activationCancel(pid)];
274
+ case 2:
275
+ _a.sent();
276
+ this.processData = undefined;
277
+ WDOLogger.info("WDOActivationService.cancel success");
278
+ return [3 /*break*/, 4];
279
+ case 3:
280
+ error_1 = _a.sent();
281
+ if (forceCancel) {
282
+ // pretend it was successful and just log the error
283
+ WDOLogger.debug("Process canceled (but the request failed) - ".concat(error_1, "."));
284
+ this.processData = undefined;
285
+ }
286
+ else {
287
+ throw error_1; // rethrow
288
+ }
289
+ return [3 /*break*/, 4];
290
+ case 4: return [2 /*return*/];
291
+ }
292
+ });
293
+ });
294
+ };
295
+ /** Clear the stored data (without networking call). */
296
+ WDOBaseActivationService.prototype.clear = function () {
297
+ this.processData = undefined;
298
+ };
299
+ /**
300
+ * OTP resend request.
301
+ *
302
+ * This is intended to be displayed for the user to use in case of the OTP is not received.
303
+ * For example, when the user does not receive SMS after some time, there should be a button to "send again".
304
+ */
305
+ WDOBaseActivationService.prototype.resendOTP = function () {
306
+ return __awaiter(this, void 0, void 0, function () {
307
+ var pid;
308
+ return __generator(this, function (_a) {
309
+ switch (_a.label) {
310
+ case 0:
311
+ WDOLogger.debug("Activation: resending OTP");
312
+ pid = this.verifyHasActiveProcess();
313
+ return [4 /*yield*/, this.verifyCanStartProcess()];
314
+ case 1:
315
+ _a.sent();
316
+ return [4 /*yield*/, this.api.activationResendOTP(pid)];
317
+ case 2:
318
+ _a.sent();
319
+ return [2 /*return*/];
320
+ }
321
+ });
322
+ });
323
+ };
324
+ /**
325
+ * @internal
326
+ * Demo endpoint available only in Wultra Demo systems.
327
+ *
328
+ * If the app is running against our demo server, you can retrieve the OTP without needing to send SMS or emails.
329
+ */
330
+ WDOBaseActivationService.prototype.getOTP = function () {
331
+ return __awaiter(this, void 0, void 0, function () {
332
+ var pid;
333
+ return __generator(this, function (_a) {
334
+ switch (_a.label) {
335
+ case 0:
336
+ WDOLogger.debug("Activation: getting OTP from server (only for testing purposes)");
337
+ pid = this.verifyHasActiveProcess();
338
+ return [4 /*yield*/, this.api.activationGetOTP(pid, "ACTIVATION")];
339
+ case 1: return [2 /*return*/, (_a.sent()).otpCode];
340
+ }
341
+ });
342
+ });
343
+ };
344
+ /**
345
+ * Activate the PowerAuth instance that was passed in the initializer.
346
+ *
347
+ * @param activationName Name of the activation. Device name by default (usually something like John's iPhone or similar).
348
+ * @param otp OTP code received by the user (via SMS or email). Optional when not required.
349
+ * @return Promise resolved with activation result.
350
+ */
351
+ WDOBaseActivationService.prototype.activate = function (activationName, otp) {
352
+ return __awaiter(this, void 0, void 0, function () {
353
+ var pid, code, result, identityAttributes;
354
+ var _a;
355
+ return __generator(this, function (_b) {
356
+ switch (_b.label) {
357
+ case 0:
358
+ WDOLogger.debug("Activating the PowerAuth with activation name '".concat(activationName, "'"));
359
+ return [4 /*yield*/, this.verifyCanStartProcess()];
360
+ case 1:
361
+ _b.sent();
362
+ pid = this.verifyHasActiveProcess();
363
+ code = (_a = this.processData) === null || _a === void 0 ? void 0 : _a.activationCode;
364
+ if (!code) return [3 /*break*/, 3];
365
+ WDOLogger.info("Activating PowerAuth using activation code from the onboarding process");
366
+ return [4 /*yield*/, this.activatePowerAuthWithCode(code, otp, activationName)];
367
+ case 2:
368
+ result = _b.sent();
369
+ return [3 /*break*/, 5];
370
+ case 3:
371
+ WDOLogger.info("Activating PowerAuth using identity attributes from the onboarding process");
372
+ identityAttributes = { processId: pid, otpCode: otp, credentialsType: "ONBOARDING" };
373
+ return [4 /*yield*/, this.activatePowerAuth(identityAttributes, activationName)];
374
+ case 4:
375
+ result = _b.sent();
376
+ _b.label = 5;
377
+ case 5:
378
+ // Clear process ID after activation attempt
379
+ this.processData = undefined;
380
+ return [2 /*return*/, result];
381
+ }
382
+ });
383
+ });
384
+ };
385
+ // PRIVATE METHODS
386
+ /* @internal */
387
+ WDOBaseActivationService.prototype.verifyCanStartProcess = function () {
388
+ return __awaiter(this, void 0, void 0, function () {
389
+ return __generator(this, function (_a) {
390
+ switch (_a.label) {
391
+ case 0: return [4 /*yield*/, this.api.canStartActivation()];
392
+ case 1:
393
+ if (!(_a.sent())) {
394
+ WDOLogger.error("PowerAuth is already activated - Activation cannot be started/processed.");
395
+ this.processData = undefined;
396
+ throw new WDOError("PowerAuth is already activated");
397
+ }
398
+ return [2 /*return*/];
399
+ }
400
+ });
401
+ });
402
+ };
403
+ /* @internal */
404
+ WDOBaseActivationService.prototype.verifyHasActiveProcess = function () {
405
+ var pid = this.processId;
406
+ if (!pid) {
407
+ WDOLogger.warn("Cannot proceed (processId not available).");
408
+ throw new WDOError("No active activation process");
409
+ }
410
+ return pid;
411
+ };
412
+ return WDOBaseActivationService;
413
+ }());
414
+
415
+ /**
416
+ * Copyright Wultra s.r.o.
417
+ *
418
+ * This source code is licensed under the Apache License, Version 2.0 license
419
+ * found in the LICENSE file in the root directory of this source tree.
420
+ *
421
+ * SPDX-License-Identifier: Apache-2.0
422
+ */
423
+ var WDOActivationEndpoints = /** @class */ (function () {
424
+ function WDOActivationEndpoints() {
425
+ }
426
+ WDOActivationEndpoints.start = {
427
+ path: "/api/onboarding/start",
428
+ e2eeScope: "APPLICATION",
429
+ returnsData: true
430
+ };
431
+ WDOActivationEndpoints.cancel = {
432
+ path: "/api/onboarding/cleanup",
433
+ e2eeScope: "APPLICATION",
434
+ returnsData: false
435
+ };
436
+ WDOActivationEndpoints.resendOTP = {
437
+ path: "/api/onboarding/otp/resend",
438
+ e2eeScope: "APPLICATION",
439
+ returnsData: false
440
+ };
441
+ WDOActivationEndpoints.getStatus = {
442
+ path: "/api/onboarding/status",
443
+ e2eeScope: "APPLICATION",
444
+ returnsData: true
445
+ };
446
+ return WDOActivationEndpoints;
447
+ }());
448
+ var WDOVerificationEndpoints = /** @class */ (function () {
449
+ function WDOVerificationEndpoints() {
450
+ }
451
+ WDOVerificationEndpoints.getStatus = {
452
+ path: "/api/identity/status",
453
+ e2eeScope: "NONE",
454
+ tokenName: "possession_universal",
455
+ returnsData: true
456
+ };
457
+ WDOVerificationEndpoints.init = {
458
+ path: "/api/identity/init",
459
+ uriId: "/api/identity/init",
460
+ e2eeScope: "NONE",
461
+ returnsData: false
462
+ };
463
+ WDOVerificationEndpoints.cancel = {
464
+ path: "/api/identity/cleanup",
465
+ uriId: "/api/identity/cleanup",
466
+ e2eeScope: "NONE",
467
+ returnsData: false
468
+ };
469
+ WDOVerificationEndpoints.consentText = {
470
+ path: "/api/identity/consent/text",
471
+ tokenName: "possession_universal",
472
+ e2eeScope: "NONE",
473
+ returnsData: true
474
+ };
475
+ WDOVerificationEndpoints.consentApprove = {
476
+ path: "/api/identity/consent/approve",
477
+ uriId: "/api/identity/consent/approve",
478
+ e2eeScope: "NONE",
479
+ returnsData: false
480
+ };
481
+ WDOVerificationEndpoints.documentScanSdkInit = {
482
+ path: "/api/identity/document/init-sdk",
483
+ uriId: "/api/identity/document/init-sdk",
484
+ e2eeScope: "ACTIVATION",
485
+ returnsData: true
486
+ };
487
+ // Legacy endpoint that required zip file upload
488
+ WDOVerificationEndpoints.submitDocuments = {
489
+ path: "/api/identity/document/submit",
490
+ tokenName: "possession_universal",
491
+ e2eeScope: "ACTIVATION",
492
+ returnsData: false
493
+ };
494
+ WDOVerificationEndpoints.v2submitDocuments = {
495
+ path: "/api/v2/identity/document/submit",
496
+ tokenName: "possession_universal",
497
+ e2eeScope: "ACTIVATION",
498
+ returnsData: false
499
+ };
500
+ WDOVerificationEndpoints.documentsStatus = {
501
+ path: "/api/identity/document/status",
502
+ tokenName: "possession_universal",
503
+ e2eeScope: "NONE",
504
+ returnsData: true
505
+ };
506
+ WDOVerificationEndpoints.presenceCheckInit = {
507
+ path: "/api/identity/presence-check/init",
508
+ uriId: "/api/identity/presence-check/init",
509
+ e2eeScope: "ACTIVATION",
510
+ returnsData: true
511
+ };
512
+ WDOVerificationEndpoints.presenceCheckSubmit = {
513
+ path: "/api/identity/presence-check/submit",
514
+ uriId: "/api/identity/presence-check/submit",
515
+ e2eeScope: "NONE",
516
+ returnsData: false
517
+ };
518
+ WDOVerificationEndpoints.resendOTP = {
519
+ path: "/api/identity/otp/resend",
520
+ uriId: "/api/identity/otp/resend",
521
+ e2eeScope: "NONE",
522
+ returnsData: false
523
+ };
524
+ WDOVerificationEndpoints.verifyOTP = {
525
+ path: "/api/identity/otp/verify",
526
+ e2eeScope: "ACTIVATION",
527
+ returnsData: true
528
+ };
529
+ return WDOVerificationEndpoints;
530
+ }());
531
+
532
+ /**
533
+ * Copyright Wultra s.r.o.
534
+ *
535
+ * This source code is licensed under the Apache License, Version 2.0 license
536
+ * found in the LICENSE file in the root directory of this source tree.
537
+ *
538
+ * SPDX-License-Identifier: Apache-2.0
539
+ */
540
+ var WDOBaseApi = /** @class */ (function () {
541
+ function WDOBaseApi() {
542
+ }
543
+ // Configuration endpoints
544
+ WDOBaseApi.prototype.getConfiguration = function (processType) {
545
+ var requestObject = { processType: processType };
546
+ return this.callApi(requestObject, { path: "/api/configuration", e2eeScope: "APPLICATION", returnsData: true });
547
+ };
548
+ // Activation endpoints
549
+ WDOBaseApi.prototype.activationStart = function (credentials, processType) {
550
+ var requestObject = { identification: credentials, processType: processType };
551
+ return this.callApi(requestObject, WDOActivationEndpoints.start);
552
+ };
553
+ WDOBaseApi.prototype.activationCancel = function (processId) {
554
+ var requestObject = { processId: processId };
555
+ return this.callApi(requestObject, WDOActivationEndpoints.cancel);
556
+ };
557
+ WDOBaseApi.prototype.activationGetStatus = function (processId) {
558
+ var requestObject = { processId: processId };
559
+ return this.callApi(requestObject, WDOActivationEndpoints.getStatus);
560
+ };
561
+ WDOBaseApi.prototype.activationResendOTP = function (processId) {
562
+ var requestObject = { processId: processId };
563
+ return this.callApi(requestObject, WDOActivationEndpoints.resendOTP);
564
+ };
565
+ WDOBaseApi.prototype.activationGetOTP = function (processId, otpType) {
566
+ var requestObject = { processId: processId, otpType: otpType };
567
+ return this.callApi(requestObject, { path: "/api/onboarding/otp/detail", e2eeScope: "APPLICATION", returnsData: true });
568
+ };
569
+ // Verification endpoints
570
+ WDOBaseApi.prototype.verificationStatus = function () {
571
+ var requestObject = {};
572
+ return this.callApi(requestObject, WDOVerificationEndpoints.getStatus);
573
+ };
574
+ WDOBaseApi.prototype.verificationStart = function (processId) {
575
+ var requestObject = { processId: processId };
576
+ return this.callApi(requestObject, WDOVerificationEndpoints.init);
577
+ };
578
+ WDOBaseApi.prototype.verificationCleanup = function (processId) {
579
+ var requestObject = { processId: processId };
580
+ return this.callApi(requestObject, WDOVerificationEndpoints.cancel);
581
+ };
582
+ WDOBaseApi.prototype.verificationGetConsentText = function (processId) {
583
+ var requestObject = { processId: processId, consentType: "GDPR" }; // TODO: hardcoded type
584
+ return this.callApi(requestObject, WDOVerificationEndpoints.consentText);
585
+ };
586
+ WDOBaseApi.prototype.verificationResolveConsent = function (processId, approved) {
587
+ var requestObject = { processId: processId, approved: approved, consentType: "GDPR" }; // TODO: hardcoded type
588
+ return this.callApi(requestObject, WDOVerificationEndpoints.consentApprove);
589
+ };
590
+ WDOBaseApi.prototype.verificationInitScanSDK = function (processId, challenge) {
591
+ var requestObject = { processId: processId, attributes: { 'sdk-init-token': challenge } };
592
+ return this.callApi(requestObject, WDOVerificationEndpoints.documentScanSdkInit);
593
+ };
594
+ WDOBaseApi.prototype.verificationSubmitDocumentsV2 = function (processId, resubmit, documents) {
595
+ var requestObject = {
596
+ processId: processId,
597
+ resubmit: resubmit,
598
+ documents: documents
599
+ };
600
+ // TODO: there should be longer timeout!
601
+ return this.callApi(requestObject, WDOVerificationEndpoints.v2submitDocuments);
602
+ };
603
+ WDOBaseApi.prototype.verificationSubmitDocuments = function (processId, data, resubmit, documents) {
604
+ var requestObject = { processId: processId, data: data, resubmit: resubmit, documents: documents };
605
+ // TODO: there should be longer timeout!
606
+ return this.callApi(requestObject, WDOVerificationEndpoints.submitDocuments);
607
+ };
608
+ WDOBaseApi.prototype.verificationDocumentsStatus = function (processId) {
609
+ var requestObject = { processId: processId };
610
+ // TODO: longer timeout?
611
+ return this.callApi(requestObject, WDOVerificationEndpoints.documentsStatus);
612
+ };
613
+ WDOBaseApi.prototype.verificationPresenceCheckInit = function (processId) {
614
+ var requestObject = { processId: processId };
615
+ return this.callApi(requestObject, WDOVerificationEndpoints.presenceCheckInit);
616
+ };
617
+ WDOBaseApi.prototype.verificationPresenceCheckSubmit = function (processId) {
618
+ var requestObject = { processId: processId };
619
+ return this.callApi(requestObject, WDOVerificationEndpoints.presenceCheckSubmit);
620
+ };
621
+ WDOBaseApi.prototype.verificationResendOTP = function (processId) {
622
+ var requestObject = { processId: processId };
623
+ return this.callApi(requestObject, WDOVerificationEndpoints.resendOTP);
624
+ };
625
+ WDOBaseApi.prototype.verifyOTP = function (processId, otp) {
626
+ var requestObject = { processId: processId, otpCode: otp };
627
+ return this.callApi(requestObject, WDOVerificationEndpoints.verifyOTP);
628
+ };
629
+ return WDOBaseApi;
630
+ }());
631
+
632
+ /**
633
+ * Copyright Wultra s.r.o.
634
+ *
635
+ * This source code is licensed under the Apache License, Version 2.0 license
636
+ * found in the LICENSE file in the root directory of this source tree.
637
+ *
638
+ * SPDX-License-Identifier: Apache-2.0
639
+ */
640
+
641
+
642
+ var WDOApi = /** @class */ (function (_super) {
643
+ __extends(WDOApi, _super);
644
+ function WDOApi(powerauth, baseUrl) {
645
+ var _this = _super.call(this) || this;
646
+ // TODO: additional configuration?
647
+ _this.networking = new WPNNetworking(powerauth, baseUrl);
648
+ _this.powerauth = powerauth;
649
+ return _this;
650
+ }
651
+ WDOApi.prototype.callApi = function (requestObject, endpoint) {
652
+ return this.networking.call(
653
+ // construct
654
+ this.constructEndpoint(endpoint), { requestObject: requestObject }, endpoint.tokenName || endpoint.uriId ? PowerAuthAuthentication.possession() : undefined // if signed, use possession auth
655
+ ).then(function (result) {
656
+ if (result.responseObject) {
657
+ return result.responseObject;
658
+ }
659
+ else if (result.responseError) {
660
+ throw new WDOError("Server API error: ".concat(result.responseError.code, ", ").concat(result.responseError.message), result.responseError);
661
+ }
662
+ else if (!endpoint.returnsData) {
663
+ // for void responses
664
+ return {};
665
+ }
666
+ else {
667
+ throw new WDOError("Failed to retrieve activation data");
668
+ }
669
+ });
670
+ };
671
+ WDOApi.prototype.canStartActivation = function () {
672
+ return this.powerauth.canStartActivation();
673
+ };
674
+ WDOApi.prototype.constructEndpoint = function (endpoint) {
675
+ var scope;
676
+ if (endpoint.e2eeScope === "ACTIVATION") {
677
+ scope = WPNE2EEConfiguration.ACTIVATION_SCOPE;
678
+ }
679
+ else if (endpoint.e2eeScope === "APPLICATION") {
680
+ scope = WPNE2EEConfiguration.APPLICATION_SCOPE;
681
+ }
682
+ else {
683
+ scope = WPNE2EEConfiguration.NOT_ENCRYPTED;
684
+ }
685
+ if (endpoint.uriId) {
686
+ return WPNEndpoint.signed(endpoint.path, endpoint.uriId, undefined, scope);
687
+ }
688
+ else if (endpoint.tokenName) {
689
+ return WPNEndpoint.signedWithToken(endpoint.path, endpoint.tokenName, undefined, scope);
690
+ }
691
+ else {
692
+ return WPNEndpoint.unsigned(endpoint.path, undefined, scope);
693
+ }
694
+ };
695
+ return WDOApi;
696
+ }(WDOBaseApi));
697
+
698
+ /**
699
+ * Copyright Wultra s.r.o.
700
+ *
701
+ * This source code is licensed under the Apache License, Version 2.0 license
702
+ * found in the LICENSE file in the root directory of this source tree.
703
+ *
704
+ * SPDX-License-Identifier: Apache-2.0
705
+ */
706
+
707
+ /**
708
+ * Service that can activate PowerAuth instance by user weak credentials (like his email, phone number or client ID) + optional SMS OTP.
709
+ *
710
+ * When the PowerAuth is activated with this service, `WDOVerificationService.isVerificationRequired` will be `true`
711
+ * and you will need to verify the PowerAuth instance via `WDOVerificationService`.
712
+ *
713
+ * This service operates against Wultra Onboarding server (usually ending with `/enrollment-onboarding-server`) and you need to configure networking service with the right URL.
714
+ */
715
+ var WDOActivationService = /** @class */ (function (_super) {
716
+ __extends(WDOActivationService, _super);
717
+ /**
718
+ * Creates service instance
719
+ *
720
+ * @param powerauth Configured PowerAuth instance. This instance needs to be without valid activation.
721
+ * @param baseUrl Base URL of the Wultra Digital Onboarding server. Usually ending with `/enrollment-onboarding-server`.
722
+ */
723
+ function WDOActivationService(powerauth, baseUrl) {
724
+ var _this = _super.call(this) || this;
725
+ _this.api = new WDOApi(powerauth, baseUrl);
726
+ _this.powerauth = powerauth;
727
+ return _this;
728
+ }
729
+ /* @internal */
730
+ WDOActivationService.prototype.activatePowerAuth = function (identityAttributes, activationName) {
731
+ var activation = PowerAuthActivation.createWithIdentityAttributes(identityAttributes, activationName);
732
+ return this.powerauth.createActivation(activation);
733
+ };
734
+ /* @internal */
735
+ WDOActivationService.prototype.activatePowerAuthWithCode = function (activationCode, otp, activationName) {
736
+ var activation = PowerAuthActivation.createWithActivationCode(activationCode, activationName);
737
+ if (otp) {
738
+ activation.additionalActivationOtp = otp;
739
+ }
740
+ return this.powerauth.createActivation(activation);
741
+ };
742
+ /* @internal */
743
+ WDOActivationService.prototype.changeAcceptLanguageImpl = function (language) {
744
+ this.api.networking.acceptLanguage = language;
745
+ };
746
+ return WDOActivationService;
747
+ }(WDOBaseActivationService));
748
+
749
+ /**
750
+ * Copyright Wultra s.r.o.
751
+ *
752
+ * This source code is licensed under the Apache License, Version 2.0 license
753
+ * found in the LICENSE file in the root directory of this source tree.
754
+ *
755
+ * SPDX-License-Identifier: Apache-2.0
756
+ */
757
+ /**
758
+ * The `WDOPowerAuthActivationState` enum defines all possible states of activation.
759
+ * The state is a part of information received together with the rest
760
+ * of the `WDOPowerAuthActivationStatus` object.
761
+ */
762
+ var WDOPowerAuthActivationState;
763
+ (function (WDOPowerAuthActivationState) {
764
+ /**
765
+ * The activation is just created.
766
+ */
767
+ WDOPowerAuthActivationState["CREATED"] = "CREATED";
768
+ /**
769
+ * The activation is not completed yet on the server.
770
+ */
771
+ WDOPowerAuthActivationState["PENDING_COMMIT"] = "PENDING_COMMIT";
772
+ /**
773
+ * The shared secure context is valid and active.
774
+ */
775
+ WDOPowerAuthActivationState["ACTIVE"] = "ACTIVE";
776
+ /**
777
+ * The activation is blocked.
778
+ */
779
+ WDOPowerAuthActivationState["BLOCKED"] = "BLOCKED";
780
+ /**
781
+ * The activation doesn't exist anymore.
782
+ */
783
+ WDOPowerAuthActivationState["REMOVED"] = "REMOVED";
784
+ /**
785
+ * The activation is technically blocked. You cannot use it anymore
786
+ * for the signature calculations.
787
+ */
788
+ WDOPowerAuthActivationState["DEADLOCK"] = "DEADLOCK";
789
+ })(WDOPowerAuthActivationState || (WDOPowerAuthActivationState = {}));
790
+
791
+ /**
792
+ * Copyright Wultra s.r.o.
793
+ *
794
+ * This source code is licensed under the Apache License, Version 2.0 license
795
+ * found in the LICENSE file in the root directory of this source tree.
796
+ *
797
+ * SPDX-License-Identifier: Apache-2.0
798
+ */
799
+ /** Image of a document that can be sent to the backend for Identity Verification. */
800
+ var WDODocumentFile = /** @class */ (function () {
801
+ /**
802
+ * Image of a document that can be sent to the backend for Identity Verification.
803
+ *
804
+ * @param data Raw image data. Make sure that the data aren't too big, hundreds of kbs should be enough.
805
+ * @param type Type of the document.
806
+ * @param side The side of the document that the image captures.
807
+ * @param originalDocumentId Original document ID In case of a reupload. If you've previously uploaded this type and side and won't specify the previous ID, the image won't be overwritten.
808
+ * @param dataSignature Signature of the image data. Optional, use only when the scan SDK supports this. `undefined` by default.
809
+ */
810
+ function WDODocumentFile(data, type, side, originalDocumentId, dataSignature) {
811
+ this.data = data;
812
+ this.dataSignature = dataSignature;
813
+ this.type = type;
814
+ this.side = side;
815
+ this.originalDocumentId = originalDocumentId;
816
+ }
817
+ /**
818
+ * Create the document file from an image that can be sent to the backend for Identity Verification.
819
+ *
820
+ * @param scannedDocument Document to upload.
821
+ * @param side The side of the document that the image captures.
822
+ * @param data Raw image data. Make sure that the data aren't too big, hundreds of kbs should be enough.
823
+ * @param dataSignature Signature of the image data. Optional, use only when the scan SDK supports this. `undefined` by default.
824
+ * @returns Document file to upload.
825
+ */
826
+ WDODocumentFile.fromScannedDocument = function (scannedDocument, side, data, dataSignature) {
827
+ var _a;
828
+ var originalDocumentId = (_a = scannedDocument.sides.find(function (s) { return s.type === side; })) === null || _a === void 0 ? void 0 : _a.serverId;
829
+ return new WDODocumentFile(data, scannedDocument.type, side, originalDocumentId, dataSignature);
830
+ };
831
+ return WDODocumentFile;
832
+ }());
833
+ /** Type of the document. */
834
+ exports.WDODocumentType = void 0;
835
+ (function (WDODocumentType) {
836
+ /** National ID card */
837
+ WDODocumentType["idCard"] = "idCard";
838
+ /** Passport */
839
+ WDODocumentType["passport"] = "passport";
840
+ /** Drivers license */
841
+ WDODocumentType["driversLicense"] = "driversLicense";
842
+ })(exports.WDODocumentType || (exports.WDODocumentType = {}));
843
+ /**
844
+ * Available sides of the document
845
+ *
846
+ * Front and back for ID card.
847
+ * For passport and drivers license front only.
848
+ */
849
+ function WDODocumentTypeSides(type) {
850
+ switch (type) {
851
+ case exports.WDODocumentType.idCard:
852
+ return [exports.WDODocumentSide.front, exports.WDODocumentSide.back];
853
+ case exports.WDODocumentType.passport:
854
+ return [exports.WDODocumentSide.front];
855
+ case exports.WDODocumentType.driversLicense:
856
+ return [exports.WDODocumentSide.front];
857
+ }
858
+ }
859
+ /** Side of the document */
860
+ exports.WDODocumentSide = void 0;
861
+ (function (WDODocumentSide) {
862
+ /** Front side of a document. Usually the one with the picture.
863
+ *
864
+ * When a document has more than one side but only one side is used (for example passport), then such side is considered to be front.
865
+ */
866
+ WDODocumentSide["front"] = "front";
867
+ /** Back side of a document */
868
+ WDODocumentSide["back"] = "back";
869
+ })(exports.WDODocumentSide || (exports.WDODocumentSide = {}));
870
+
871
+ /**
872
+ * Copyright Wultra s.r.o.
873
+ *
874
+ * This source code is licensed under the Apache License, Version 2.0 license
875
+ * found in the LICENSE file in the root directory of this source tree.
876
+ *
877
+ * SPDX-License-Identifier: Apache-2.0
878
+ */
879
+ /** Status of the onboarding */
880
+ var WDOOnboardingStatus;
881
+ (function (WDOOnboardingStatus) {
882
+ /** Activation part of the process is in progress */
883
+ WDOOnboardingStatus["activationInProgress"] = "ACTIVATION_IN_PROGRESS";
884
+ /** Verification part of the process is in progress */
885
+ WDOOnboardingStatus["verificationInProgress"] = "VERIFICATION_IN_PROGRESS";
886
+ /** Onboarding process has failed */
887
+ WDOOnboardingStatus["failed"] = "FAILED";
888
+ /** Onboarding process is completed */
889
+ WDOOnboardingStatus["finished"] = "FINISHED";
890
+ })(WDOOnboardingStatus || (WDOOnboardingStatus = {}));
891
+ /** Status of the current identity verification */
892
+ var WDOIdentityVerificationStatus;
893
+ (function (WDOIdentityVerificationStatus) {
894
+ /** Identity verification is waiting for initialization */
895
+ WDOIdentityVerificationStatus["notInitialized"] = "NOT_INITIALIZED";
896
+ /** All submitted documents are waiting for verification */
897
+ WDOIdentityVerificationStatus["verificationPending"] = "VERIFICATION_PENDING";
898
+ /** Identity verification is in progress */
899
+ WDOIdentityVerificationStatus["inProgress"] = "IN_PROGRESS";
900
+ /** Identity verification was successfully completed */
901
+ WDOIdentityVerificationStatus["accepted"] = "ACCEPTED";
902
+ /** Identity verification has failed, an error occurred */
903
+ WDOIdentityVerificationStatus["failed"] = "FAILED";
904
+ /** Identity verification was rejected */
905
+ WDOIdentityVerificationStatus["rejected"] = "REJECTED";
906
+ })(WDOIdentityVerificationStatus || (WDOIdentityVerificationStatus = {}));
907
+ /** Phase of the current identity verification */
908
+ var WDOIdentityVerificationPhase;
909
+ (function (WDOIdentityVerificationPhase) {
910
+ /** Document upload is in progress */
911
+ WDOIdentityVerificationPhase["documentUpload"] = "DOCUMENT_UPLOAD";
912
+ /** Presence check is in progress */
913
+ WDOIdentityVerificationPhase["presenceCheck"] = "PRESENCE_CHECK";
914
+ /** Backend is verifying documents */
915
+ WDOIdentityVerificationPhase["clientEvaluation"] = "CLIENT_EVALUATION";
916
+ /** Document verification is in progress */
917
+ WDOIdentityVerificationPhase["documentVerification"] = "DOCUMENT_VERIFICATION";
918
+ /** Cross check on documents is in progress */
919
+ WDOIdentityVerificationPhase["documentVerificationFinal"] = "DOCUMENT_VERIFICATION_FINAL";
920
+ /** OTP verification needed */
921
+ WDOIdentityVerificationPhase["otp"] = "OTP_VERIFICATION";
922
+ /** Completed */
923
+ WDOIdentityVerificationPhase["completed"] = "COMPLETED";
924
+ })(WDOIdentityVerificationPhase || (WDOIdentityVerificationPhase = {}));
925
+ /** Types of available documents */
926
+ var WDODocumentSubmitFileType;
927
+ (function (WDODocumentSubmitFileType) {
928
+ /** National ID card */
929
+ WDODocumentSubmitFileType["idCard"] = "ID_CARD";
930
+ /** Passport */
931
+ WDODocumentSubmitFileType["passport"] = "PASSPORT";
932
+ /** Driving license */
933
+ WDODocumentSubmitFileType["driversLicense"] = "DRIVING_LICENSE";
934
+ /** Selfie photo */
935
+ WDODocumentSubmitFileType["selfiePhoto"] = "SELFIE_PHOTO";
936
+ })(WDODocumentSubmitFileType || (WDODocumentSubmitFileType = {}));
937
+ /** Side of the file */
938
+ var WDODocumentSubmitFileSide;
939
+ (function (WDODocumentSubmitFileSide) {
940
+ /** Front side of an document. Usually the one with the picture */
941
+ WDODocumentSubmitFileSide["front"] = "FRONT";
942
+ /** Back side of an document */
943
+ WDODocumentSubmitFileSide["back"] = "BACK";
944
+ })(WDODocumentSubmitFileSide || (WDODocumentSubmitFileSide = {}));
945
+ /** Status of the document */
946
+ var WDODocumentStatus;
947
+ (function (WDODocumentStatus) {
948
+ /** Document was accepted */
949
+ WDODocumentStatus["accepted"] = "ACCEPTED";
950
+ /** Document is being uploaded to the verification system by the backend */
951
+ WDODocumentStatus["uploadInProgress"] = "UPLOAD_IN_PROGRESS";
952
+ /** Document are being processed */
953
+ WDODocumentStatus["inProgress"] = "IN_PROGRESS";
954
+ /** Document is pending verification */
955
+ WDODocumentStatus["verificationPending"] = "VERIFICATION_PENDING";
956
+ /** Document is being verified */
957
+ WDODocumentStatus["verificationInProgress"] = "VERIFICATION_IN_PROGRESS";
958
+ /** Document was rejected */
959
+ WDODocumentStatus["rejected"] = "REJECTED";
960
+ /** Verification of the document failed */
961
+ WDODocumentStatus["failed"] = "FAILED";
962
+ })(WDODocumentStatus || (WDODocumentStatus = {}));
963
+ /** Converts WDODocumentType to DocumentSubmitFileType */
964
+ function WDOCreateDocumentSubmitFileType(type) {
965
+ switch (type) {
966
+ case exports.WDODocumentType.idCard:
967
+ return WDODocumentSubmitFileType.idCard;
968
+ case exports.WDODocumentType.passport:
969
+ return WDODocumentSubmitFileType.passport;
970
+ case exports.WDODocumentType.driversLicense:
971
+ return WDODocumentSubmitFileType.driversLicense;
972
+ }
973
+ }
974
+ /** Converts WDODocumentSide to DocumentSubmitFileSide */
975
+ function WDOCreateDocumentSubmitFileSide(side) {
976
+ switch (side) {
977
+ case exports.WDODocumentSide.front:
978
+ return WDODocumentSubmitFileSide.front;
979
+ case exports.WDODocumentSide.back:
980
+ return WDODocumentSubmitFileSide.back;
981
+ }
982
+ }
983
+
984
+ /**
985
+ * Copyright Wultra s.r.o.
986
+ *
987
+ * This source code is licensed under the Apache License, Version 2.0 license
988
+ * found in the LICENSE file in the root directory of this source tree.
989
+ *
990
+ * SPDX-License-Identifier: Apache-2.0
991
+ */
992
+ /** Types of the verification state */
993
+ exports.WDOVerificationStateType = void 0;
994
+ (function (WDOVerificationStateType) {
995
+ /**
996
+ * Show the verification introduction screen where the user can start the activation.
997
+ *
998
+ * The next step should be calling the `consentGet()`.
999
+ */
1000
+ WDOVerificationStateType["intro"] = "intro";
1001
+ /**
1002
+ * Show approve/cancel user consent.
1003
+ *
1004
+ * The content of the text depends on the server configuration and might be plain text or HTML.
1005
+ *
1006
+ * The next step should be calling the `consentApprove`.
1007
+ */
1008
+ WDOVerificationStateType["consent"] = "consent";
1009
+ /**
1010
+ * Show document selection to the user. Which documents are available and how many
1011
+ * can the user select is up to your backend configuration.
1012
+ *
1013
+ * The next step should be calling the `documentsSetSelectedTypes`.
1014
+ */
1015
+ WDOVerificationStateType["documentsToScanSelect"] = "documentsToScanSelect";
1016
+ /**
1017
+ * User should scan documents - display UI for the user to scan all necessary documents.
1018
+ *
1019
+ * The next step should be calling the `documentsSubmit`.
1020
+ */
1021
+ WDOVerificationStateType["scanDocument"] = "scanDocument";
1022
+ /**
1023
+ * The system is processing data - show loading with text hint from provided `WDOStatusCheckReason`.
1024
+ *
1025
+ * The next step should be calling the `status`.
1026
+ */
1027
+ WDOVerificationStateType["processing"] = "processing";
1028
+ /**
1029
+ * The user should be presented with a presence check.
1030
+ * Presence check is handled by third-party SDK based on the project setup.
1031
+ *
1032
+ * The next step should be calling the `presenceCheckInit` to start the check and `presenceCheckSubmit` to
1033
+ * mark it finished. Note that these methods won't change the status and it's up to the app to handle the process of the presence check.
1034
+ */
1035
+ WDOVerificationStateType["presenceCheck"] = "presenceCheck";
1036
+ /**
1037
+ * Show enter OTP screen with resend button.
1038
+ *
1039
+ * The next step should be calling the `verifyOTP` with user-entered OTP.
1040
+ * The OTP is usually SMS or email.
1041
+ */
1042
+ WDOVerificationStateType["otp"] = "otp";
1043
+ /**
1044
+ * Verification failed and can be restarted
1045
+ *
1046
+ * The next step should be calling the `restartVerification` or `cancelWholeProcess` based on
1047
+ * the user's decision if he wants to try it again or cancel the process.
1048
+ */
1049
+ WDOVerificationStateType["failed"] = "failed";
1050
+ /**
1051
+ * Verification is canceled and the user needs to start again with a new PowerAuth activation.
1052
+ *
1053
+ * The next step should be calling the `PowerAuth.removeActivationLocal()` and starting activation from scratch.
1054
+ */
1055
+ WDOVerificationStateType["endState"] = "endState";
1056
+ /**
1057
+ * Verification was successfully ended. Continue into your app flow.
1058
+ */
1059
+ WDOVerificationStateType["success"] = "success";
1060
+ })(exports.WDOVerificationStateType || (exports.WDOVerificationStateType = {}));
1061
+ /** The reason why the process ended in a non-recoverable state. */
1062
+ exports.WDOEndStateReason = void 0;
1063
+ (function (WDOEndStateReason) {
1064
+ /**
1065
+ * The verification was rejected by the system
1066
+ *
1067
+ * eg: Fake information, fraud detection, or user is trying repeatedly in a short time.
1068
+ * The real reason is not presented to the user and is only audited on the server.
1069
+ */
1070
+ WDOEndStateReason["rejected"] = "rejected";
1071
+ /**
1072
+ * The limit of repeat tries was reached. There is a fixed number of tries that the user can reach
1073
+ * before the system stops the process.
1074
+ */
1075
+ WDOEndStateReason["limitReached"] = "limitReached";
1076
+ /** An unknown reason. */
1077
+ WDOEndStateReason["other"] = "other";
1078
+ })(exports.WDOEndStateReason || (exports.WDOEndStateReason = {}));
1079
+ /**
1080
+ * The reason for what we are waiting for. For example, we can wait for documents to be OCRed and matched against the database.
1081
+ * Use these values for better loading texts to tell the user what is happening - some tasks may take some time
1082
+ * and it would be frustrating to just show a generic loading indicator.
1083
+ */
1084
+ exports.WDOStatusCheckReason = void 0;
1085
+ (function (WDOStatusCheckReason) {
1086
+ WDOStatusCheckReason["unknown"] = "unknown";
1087
+ WDOStatusCheckReason["documentUpload"] = "documentUpload";
1088
+ WDOStatusCheckReason["documentVerification"] = "documentVerification";
1089
+ WDOStatusCheckReason["documentAccepted"] = "documentAccepted";
1090
+ WDOStatusCheckReason["documentsCrossVerification"] = "documentsCrossVerification";
1091
+ WDOStatusCheckReason["clientVerification"] = "clientVerification";
1092
+ WDOStatusCheckReason["clientAccepted"] = "clientAccepted";
1093
+ WDOStatusCheckReason["verifyingPresence"] = "verifyingPresence";
1094
+ })(exports.WDOStatusCheckReason || (exports.WDOStatusCheckReason = {}));
1095
+
1096
+ /**
1097
+ * Copyright Wultra s.r.o.
1098
+ *
1099
+ * This source code is licensed under the Apache License, Version 2.0 license
1100
+ * found in the LICENSE file in the root directory of this source tree.
1101
+ *
1102
+ * SPDX-License-Identifier: Apache-2.0
1103
+ */
1104
+ /** Describes the state of documents that need to be uploaded to the server. */
1105
+ var WDOVerificationScanProcess = /** @class */ (function () {
1106
+ /* @internal */
1107
+ function WDOVerificationScanProcess(types) {
1108
+ this.documents = types.map(function (t) { return new WDOScannedDocument(t); });
1109
+ }
1110
+ Object.defineProperty(WDOVerificationScanProcess.prototype, "nextDocumentToScan", {
1111
+ /** Which document should be scanned next. `undefined` when all documents are uploaded and accepted. */
1112
+ get: function () { return this.documents.find(function (d) { return d.uploadState !== exports.UploadState.accepted; }); },
1113
+ enumerable: false,
1114
+ configurable: true
1115
+ });
1116
+ /* @internal */
1117
+ WDOVerificationScanProcess.prototype.feedServerData = function (documents) {
1118
+ var _this = this;
1119
+ var groups = documents.reduce(function (map, doc) {
1120
+ var _a;
1121
+ var key = doc.type;
1122
+ var group = (_a = map.get(key)) !== null && _a !== void 0 ? _a : [];
1123
+ group.push(doc);
1124
+ map.set(key, group);
1125
+ return map;
1126
+ }, new Map());
1127
+ groups.forEach(function (docs, type) {
1128
+ var _a;
1129
+ // TODO: type mismatch?
1130
+ (_a = _this.documents.find(function (d) { return d.type === type; })) === null || _a === void 0 ? void 0 : _a.processServerData(docs);
1131
+ });
1132
+ };
1133
+ return WDOVerificationScanProcess;
1134
+ }());
1135
+ /** Document that needs to be scanned during process. */
1136
+ var WDOScannedDocument = /** @class */ (function () {
1137
+ /* @internal */
1138
+ function WDOScannedDocument(type) {
1139
+ /* @internal */
1140
+ this._sides = new Array();
1141
+ this.type = type;
1142
+ }
1143
+ Object.defineProperty(WDOScannedDocument.prototype, "uploadState", {
1144
+ /** Upload state. */
1145
+ get: function () {
1146
+ // if there are no sides, consider the document not uploaded
1147
+ if (this.sides.length === 0) {
1148
+ return exports.UploadState.notUploaded;
1149
+ }
1150
+ // if any side is rejected, consider whole document rejected
1151
+ for (var _i = 0, _a = this.sides; _i < _a.length; _i++) {
1152
+ var side = _a[_i];
1153
+ if (side.uploadState === exports.UploadState.rejected) {
1154
+ return exports.UploadState.rejected;
1155
+ }
1156
+ }
1157
+ return exports.UploadState.accepted;
1158
+ },
1159
+ enumerable: false,
1160
+ configurable: true
1161
+ });
1162
+ Object.defineProperty(WDOScannedDocument.prototype, "sides", {
1163
+ /** Sides of the document that were uploaded on the server. */
1164
+ get: function () { return this._sides; },
1165
+ enumerable: false,
1166
+ configurable: true
1167
+ });
1168
+ /* @internal */
1169
+ WDOScannedDocument.prototype.processServerData = function (documents) {
1170
+ this._sides = documents.map(function (doc) { var _a, _b; return new Side(doc.side == WDODocumentSubmitFileSide.front ? exports.WDODocumentSide.front : exports.WDODocumentSide.back, doc.id, ((_b = (_a = doc.errors) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0 ? exports.UploadState.rejected : exports.UploadState.accepted); });
1171
+ };
1172
+ return WDOScannedDocument;
1173
+ }());
1174
+ /** State of the document on the server. */
1175
+ exports.UploadState = void 0;
1176
+ (function (UploadState) {
1177
+ /** The document was not uploaded yet. */
1178
+ UploadState[UploadState["notUploaded"] = 0] = "notUploaded";
1179
+ /** The document was accepted by the server. */
1180
+ UploadState[UploadState["accepted"] = 1] = "accepted";
1181
+ /** The document was rejected and needs to be re-uploaded. */
1182
+ UploadState[UploadState["rejected"] = 2] = "rejected";
1183
+ })(exports.UploadState || (exports.UploadState = {}));
1184
+ /** Side of the uploaded document. */
1185
+ var Side = /** @class */ (function () {
1186
+ /* @internal */
1187
+ function Side(type, serverId, uploadState) {
1188
+ this.type = type;
1189
+ this.serverId = serverId;
1190
+ this.uploadState = uploadState;
1191
+ }
1192
+ return Side;
1193
+ }());
1194
+
1195
+ /**
1196
+ * Copyright Wultra s.r.o.
1197
+ *
1198
+ * This source code is licensed under the Apache License, Version 2.0 license
1199
+ * found in the LICENSE file in the root directory of this source tree.
1200
+ *
1201
+ * SPDX-License-Identifier: Apache-2.0
1202
+ */
1203
+ /**
1204
+ * Service that can verify previously activated PowerAuth instance.
1205
+ *
1206
+ * When PowerAuth instance was activated with weak credentials via `WDOActivationService`, user needs to verify his genuine presence.
1207
+ * This can be confirmed in the `WDOVerificationService.isVerificationRequired` which will be `true`.
1208
+ *
1209
+ * This service operates against Wultra Onboarding server (usually ending with `/enrollment-onboarding-server`) and you need to configure networking service with the right URL.
1210
+ */
1211
+ var WDOBaseVerificationService = /** @class */ (function () {
1212
+ function WDOBaseVerificationService() {
1213
+ /* @internal */
1214
+ this.lastStatus = undefined;
1215
+ /* @internal */
1216
+ this.cachedProcess = undefined; // TODO: persistence?
1217
+ }
1218
+ // PUBLIC API
1219
+ /**
1220
+ * Accept language for the outgoing requests headers.
1221
+ * Default value is "en".
1222
+ *
1223
+ * Standard RFC "Accept-Language" https://tools.ietf.org/html/rfc7231#section-5.3.5
1224
+ * Response texts are based on this setting. For example when "de" is set, server
1225
+ * will return error texts and other in german (if available).
1226
+ */
1227
+ WDOBaseVerificationService.prototype.changeAcceptLanguage = function (language) {
1228
+ this.changeAcceptLanguageImpl(language);
1229
+ };
1230
+ Object.defineProperty(WDOBaseVerificationService.prototype, "otpResendPeriodSeconds", {
1231
+ /** Time in seconds that user needs to wait between OTP resend calls */
1232
+ get: function () {
1233
+ var _a, _b;
1234
+ return (_b = (_a = this.lastStatus) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.otpResendPeriodSeconds;
1235
+ },
1236
+ enumerable: false,
1237
+ configurable: true
1238
+ });
1239
+ /**
1240
+ * Status of the verification.
1241
+ */
1242
+ WDOBaseVerificationService.prototype.status = function () {
1243
+ return __awaiter(this, void 0, void 0, function () {
1244
+ var response, vf, _a, docsResponse, documents, cachedProcess, error_1;
1245
+ var _b;
1246
+ return __generator(this, function (_c) {
1247
+ switch (_c.label) {
1248
+ case 0:
1249
+ _c.trys.push([0, 12, , 13]);
1250
+ return [4 /*yield*/, this.api.verificationStatus()];
1251
+ case 1:
1252
+ response = _c.sent();
1253
+ WDOLogger.info("Verification status successfully retrieved.");
1254
+ WDOLogger.debug("Verification status: ".concat(JSON.stringify(response)));
1255
+ switch (response.identityVerificationStatus) {
1256
+ case WDOIdentityVerificationStatus.failed:
1257
+ case WDOIdentityVerificationStatus.rejected:
1258
+ case WDOIdentityVerificationStatus.notInitialized:
1259
+ case WDOIdentityVerificationStatus.accepted:
1260
+ WDOLogger.debug("Status ".concat(response.identityVerificationStatus, " - clearing cache"));
1261
+ this.cachedProcess = undefined;
1262
+ break;
1263
+ }
1264
+ this.lastStatus = response;
1265
+ vf = new WDOVerificationStatus(response);
1266
+ WDOLogger.info("Verification next step: ".concat(vf.description()));
1267
+ _a = vf.nextStep;
1268
+ switch (_a) {
1269
+ case WDONextStep.intro: return [3 /*break*/, 2];
1270
+ case WDONextStep.documentScan: return [3 /*break*/, 3];
1271
+ case WDONextStep.presenceCheck: return [3 /*break*/, 5];
1272
+ case WDONextStep.otp: return [3 /*break*/, 6];
1273
+ case WDONextStep.statusCheck: return [3 /*break*/, 7];
1274
+ case WDONextStep.failed: return [3 /*break*/, 8];
1275
+ case WDONextStep.rejected: return [3 /*break*/, 9];
1276
+ case WDONextStep.success: return [3 /*break*/, 10];
1277
+ }
1278
+ return [3 /*break*/, 11];
1279
+ case 2: return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.intro })];
1280
+ case 3:
1281
+ WDOLogger.debug("Verifying documents status");
1282
+ return [4 /*yield*/, this.api.verificationDocumentsStatus(response.processId)];
1283
+ case 4:
1284
+ docsResponse = _c.sent();
1285
+ WDOLogger.debug("Documents status: ".concat(JSON.stringify(docsResponse)));
1286
+ documents = docsResponse.documents;
1287
+ cachedProcess = this.cachedProcess;
1288
+ if (cachedProcess) {
1289
+ cachedProcess.feedServerData(docsResponse.documents);
1290
+ if (documents.some(function (d) { return documentAction(d) === "error"; }) || documents.some(function (d) { return d.errors != undefined && d.errors.length > 0; })) {
1291
+ WDOLogger.debug("At least one document in error state: ".concat(documents.some(function (d) { return documentAction(d) === "error"; }), ", ").concat(documents.some(function (d) { return d.errors != undefined && d.errors.length > 0; })));
1292
+ return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.scanDocument, process: cachedProcess })];
1293
+ }
1294
+ else if (documents.every(function (d) { return documentAction(d) === "proceed"; })) {
1295
+ WDOLogger.debug("All documents accepted, proceeding");
1296
+ return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.scanDocument, process: cachedProcess })];
1297
+ }
1298
+ else if (documents.some(function (d) { return documentAction(d) === "wait"; })) {
1299
+ WDOLogger.debug("At least one document still in progress, moving to processing");
1300
+ return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.processing, item: exports.WDOStatusCheckReason.documentVerification })];
1301
+ }
1302
+ else if (documents.length == 0) {
1303
+ WDOLogger.debug("No documents scanned, scan documents...");
1304
+ return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.scanDocument, process: cachedProcess })];
1305
+ }
1306
+ else {
1307
+ return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.failed })];
1308
+ }
1309
+ }
1310
+ else {
1311
+ if (documents.length == 0) {
1312
+ return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.documentsToScanSelect })];
1313
+ }
1314
+ else {
1315
+ return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.failed })];
1316
+ }
1317
+ }
1318
+ case 5: return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.presenceCheck })];
1319
+ case 6: return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.otp })];
1320
+ case 7: return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.processing, item: (_b = vf.statusCheckReason) !== null && _b !== void 0 ? _b : exports.WDOStatusCheckReason.unknown })];
1321
+ case 8: return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.failed })];
1322
+ case 9: return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.endState, reason: exports.WDOEndStateReason.rejected })];
1323
+ case 10: return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.success })];
1324
+ case 11: return [3 /*break*/, 13];
1325
+ case 12:
1326
+ error_1 = _c.sent();
1327
+ WDOLogger.error("Error fetching verification status: ".concat(JSON.stringify(error_1)));
1328
+ this.lastStatus = undefined;
1329
+ throw this.processError(error_1);
1330
+ case 13: return [2 /*return*/];
1331
+ }
1332
+ });
1333
+ });
1334
+ };
1335
+ /**
1336
+ * Returns consent text for user to approve. The content of the text depends on the server configuration and might be plain text or HTML.
1337
+ *
1338
+ * Consent text explains how the service will handle his document photos or selfie scans.
1339
+ */
1340
+ WDOBaseVerificationService.prototype.consentGet = function () {
1341
+ return __awaiter(this, void 0, void 0, function () {
1342
+ var pid, response;
1343
+ return __generator(this, function (_a) {
1344
+ switch (_a.label) {
1345
+ case 0:
1346
+ pid = this.verifyHasActiveProcess();
1347
+ return [4 /*yield*/, this.handleError(this.api.verificationGetConsentText(pid))];
1348
+ case 1:
1349
+ response = _a.sent();
1350
+ return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.consent, body: response.consentText })];
1351
+ }
1352
+ });
1353
+ });
1354
+ };
1355
+ /**
1356
+ * Approves the consent for this process and starts the activation.
1357
+ */
1358
+ WDOBaseVerificationService.prototype.consentApprove = function () {
1359
+ return __awaiter(this, void 0, void 0, function () {
1360
+ var pid;
1361
+ return __generator(this, function (_a) {
1362
+ switch (_a.label) {
1363
+ case 0:
1364
+ pid = this.verifyHasActiveProcess();
1365
+ return [4 /*yield*/, this.handleError(this.api.verificationResolveConsent(pid, true))];
1366
+ case 1:
1367
+ _a.sent();
1368
+ return [4 /*yield*/, this.handleError(this.api.verificationStart(pid))];
1369
+ case 2:
1370
+ _a.sent();
1371
+ return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.documentsToScanSelect })];
1372
+ }
1373
+ });
1374
+ });
1375
+ };
1376
+ /**
1377
+ * Get the token for the document scanning SDK, when required.
1378
+ *
1379
+ * This is needed for example for ZenID or BlinkID provider.
1380
+ *
1381
+ * @param challenge Optional challenge provided by the scanning SDK.
1382
+ */
1383
+ WDOBaseVerificationService.prototype.documentsInitSDK = function (challenge) {
1384
+ return __awaiter(this, void 0, void 0, function () {
1385
+ var pid, response;
1386
+ return __generator(this, function (_a) {
1387
+ switch (_a.label) {
1388
+ case 0:
1389
+ pid = this.verifyHasActiveProcess();
1390
+ return [4 /*yield*/, this.handleError(this.api.verificationInitScanSDK(pid, challenge !== null && challenge !== void 0 ? challenge : "-"))]; // TODO: is "-" acceptable?
1391
+ case 1:
1392
+ response = _a.sent() // TODO: is "-" acceptable?
1393
+ ;
1394
+ return [2 /*return*/, response];
1395
+ }
1396
+ });
1397
+ });
1398
+ };
1399
+ /**
1400
+ * Set which documents will be scanned.
1401
+ *
1402
+ * Note that this needs to be in sync what server expects based on the configuration.
1403
+ *
1404
+ * @param types Types of documents to scan.
1405
+ */
1406
+ WDOBaseVerificationService.prototype.documentsSetSelectedTypes = function (types) {
1407
+ return __awaiter(this, void 0, void 0, function () {
1408
+ var process;
1409
+ return __generator(this, function (_a) {
1410
+ WDOLogger.debug("Submitting selected document types: ".concat(types));
1411
+ process = new WDOVerificationScanProcess(types);
1412
+ this.cachedProcess = process;
1413
+ return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.scanDocument, process: process })];
1414
+ });
1415
+ });
1416
+ };
1417
+ /**
1418
+ * Upload document files to the server. The order of the documents is up to you.
1419
+ * Make sure that uploaded document are reasonable size so you're not uploading large files.
1420
+ *
1421
+ * If you're uploading the same document file again, you need to include the `originalDocumentId` otherwise it will be rejected by the server.
1422
+ *
1423
+ * @param files Document files to upload.
1424
+ */
1425
+ WDOBaseVerificationService.prototype.documentsSubmit = function (files) {
1426
+ return __awaiter(this, void 0, void 0, function () {
1427
+ var pid, resubmit, submitFiles;
1428
+ return __generator(this, function (_a) {
1429
+ switch (_a.label) {
1430
+ case 0:
1431
+ pid = this.verifyHasActiveProcess();
1432
+ resubmit = files.some(function (f) { return f.originalDocumentId != undefined; });
1433
+ submitFiles = files.map(function (f) {
1434
+ return {
1435
+ filename: "".concat(f.type.toLowerCase(), "_").concat(f.side.toLowerCase(), ".jpg"), // TODO: OK?
1436
+ type: WDOCreateDocumentSubmitFileType(f.type),
1437
+ side: WDOCreateDocumentSubmitFileSide(f.side),
1438
+ originalDocumentId: f.originalDocumentId,
1439
+ data: f.data
1440
+ };
1441
+ });
1442
+ return [4 /*yield*/, this.handleError(this.api.verificationSubmitDocumentsV2(pid, resubmit, submitFiles))];
1443
+ case 1:
1444
+ _a.sent();
1445
+ return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.processing, item: exports.WDOStatusCheckReason.documentUpload })];
1446
+ }
1447
+ });
1448
+ });
1449
+ };
1450
+ /**
1451
+ * @internal
1452
+ * Upload document files to the server. The order of the documents is up to you.
1453
+ * Make sure that uploaded document are reasonable size so you're not uploading large files.
1454
+ *
1455
+ * If you're uploading the same document file again, you need to include the `originalDocumentId` otherwise it will be rejected by the server.
1456
+ *
1457
+ * @param files Document files to upload.
1458
+ */
1459
+ WDOBaseVerificationService.prototype.documentsSubmitDemo = function (files, zipFolderNameDemo, base64zipDemo) {
1460
+ return __awaiter(this, void 0, void 0, function () {
1461
+ var pid, resubmit, submitFiles;
1462
+ return __generator(this, function (_a) {
1463
+ switch (_a.label) {
1464
+ case 0:
1465
+ pid = this.verifyHasActiveProcess();
1466
+ resubmit = files.some(function (f) { return f.originalDocumentId != undefined; });
1467
+ submitFiles = files.map(function (f) {
1468
+ return {
1469
+ filename: "".concat(zipFolderNameDemo, "/").concat(f.type.toLowerCase(), "_").concat(f.side.toLowerCase(), ".jpg"),
1470
+ type: WDOCreateDocumentSubmitFileType(f.type),
1471
+ side: WDOCreateDocumentSubmitFileSide(f.side),
1472
+ originalDocumentId: f.originalDocumentId
1473
+ };
1474
+ });
1475
+ return [4 /*yield*/, this.handleError(this.api.verificationSubmitDocuments(pid, base64zipDemo, resubmit, submitFiles))];
1476
+ case 1:
1477
+ _a.sent();
1478
+ return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.processing, item: exports.WDOStatusCheckReason.documentUpload })];
1479
+ }
1480
+ });
1481
+ });
1482
+ };
1483
+ /**
1484
+ * Initiates the presence check. This returns attributes that are needed to start the 3rd party SDK (if needed).
1485
+ */
1486
+ WDOBaseVerificationService.prototype.presenceCheckInit = function () {
1487
+ return __awaiter(this, void 0, void 0, function () {
1488
+ var pid, response;
1489
+ return __generator(this, function (_a) {
1490
+ switch (_a.label) {
1491
+ case 0:
1492
+ pid = this.verifyHasActiveProcess();
1493
+ return [4 /*yield*/, this.handleError(this.api.verificationPresenceCheckInit(pid))];
1494
+ case 1:
1495
+ response = _a.sent();
1496
+ return [2 /*return*/, this.processSuccess(response.sessionAttributes)];
1497
+ }
1498
+ });
1499
+ });
1500
+ };
1501
+ /**
1502
+ * Call when presence check was finished in the 3rd party SDK.
1503
+ */
1504
+ WDOBaseVerificationService.prototype.presenceCheckSubmit = function () {
1505
+ return __awaiter(this, void 0, void 0, function () {
1506
+ var pid;
1507
+ return __generator(this, function (_a) {
1508
+ switch (_a.label) {
1509
+ case 0:
1510
+ pid = this.verifyHasActiveProcess();
1511
+ return [4 /*yield*/, this.handleError(this.api.verificationPresenceCheckSubmit(pid))];
1512
+ case 1:
1513
+ _a.sent();
1514
+ return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.processing, item: exports.WDOStatusCheckReason.verifyingPresence })];
1515
+ }
1516
+ });
1517
+ });
1518
+ };
1519
+ /**
1520
+ * Verification restart. When sucessfully called, intro screen should be presented.
1521
+ */
1522
+ WDOBaseVerificationService.prototype.restartVerification = function () {
1523
+ return __awaiter(this, void 0, void 0, function () {
1524
+ var pid;
1525
+ return __generator(this, function (_a) {
1526
+ switch (_a.label) {
1527
+ case 0:
1528
+ pid = this.verifyHasActiveProcess();
1529
+ return [4 /*yield*/, this.handleError(this.api.verificationCleanup(pid))];
1530
+ case 1:
1531
+ _a.sent();
1532
+ this.cachedProcess = undefined;
1533
+ WDOLogger.info("Verification process restarted.");
1534
+ return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.intro })];
1535
+ }
1536
+ });
1537
+ });
1538
+ };
1539
+ /**
1540
+ * Cancel the whole activation/verification. After this it's no longer possible to call
1541
+ * any API of this library and PowerAuth activation should be removed and activation started again.
1542
+ */
1543
+ WDOBaseVerificationService.prototype.cancelWholeProcess = function () {
1544
+ return __awaiter(this, void 0, void 0, function () {
1545
+ var pid;
1546
+ return __generator(this, function (_a) {
1547
+ switch (_a.label) {
1548
+ case 0:
1549
+ pid = this.verifyHasActiveProcess();
1550
+ return [4 /*yield*/, this.handleError(this.api.verificationCleanup(pid))];
1551
+ case 1:
1552
+ _a.sent();
1553
+ this.cachedProcess = undefined;
1554
+ WDOLogger.info("Verification process canceled.");
1555
+ return [2 /*return*/];
1556
+ }
1557
+ });
1558
+ });
1559
+ };
1560
+ /**
1561
+ * Verify OTP that user entered as a last step of the verification.
1562
+ *
1563
+ * @param otp OTP that user obtained via other channel (usually SMS or email).
1564
+ */
1565
+ WDOBaseVerificationService.prototype.verifyOTP = function (otp) {
1566
+ return __awaiter(this, void 0, void 0, function () {
1567
+ var pid, response;
1568
+ return __generator(this, function (_a) {
1569
+ switch (_a.label) {
1570
+ case 0:
1571
+ pid = this.verifyHasActiveProcess();
1572
+ return [4 /*yield*/, this.handleError(this.api.verifyOTP(pid, otp))];
1573
+ case 1:
1574
+ response = _a.sent();
1575
+ if (response.verified) {
1576
+ WDOLogger.info("OTP verified successfully.");
1577
+ return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.processing, item: exports.WDOStatusCheckReason.unknown })];
1578
+ }
1579
+ else {
1580
+ if (response.remainingAttempts > 0 && response.expired == false) {
1581
+ WDOLogger.error("OTP verification failed, remaining attempts: ".concat(response.remainingAttempts));
1582
+ return [2 /*return*/, this.processSuccess({ type: exports.WDOVerificationStateType.otp, remainingAttempts: response.remainingAttempts })];
1583
+ }
1584
+ else {
1585
+ WDOLogger.error("OTP verification failed, no remaining attempts or OTP expired");
1586
+ throw this.processError(new WDOError("OTP verification failed, no remaining attempts or OTP expired"));
1587
+ }
1588
+ }
1589
+ }
1590
+ });
1591
+ });
1592
+ };
1593
+ /**
1594
+ * Request OTP resend.
1595
+ *
1596
+ * Since SMS or emails can fail to deliver, use this to send the OTP again.
1597
+ */
1598
+ WDOBaseVerificationService.prototype.resendOTP = function () {
1599
+ return __awaiter(this, void 0, void 0, function () {
1600
+ var pid;
1601
+ return __generator(this, function (_a) {
1602
+ switch (_a.label) {
1603
+ case 0:
1604
+ pid = this.verifyHasActiveProcess();
1605
+ return [4 /*yield*/, this.handleError(this.api.verificationResendOTP(pid))];
1606
+ case 1:
1607
+ _a.sent();
1608
+ return [2 /*return*/];
1609
+ }
1610
+ });
1611
+ });
1612
+ };
1613
+ /**
1614
+ * @internal
1615
+ * Demo endpoint available only in Wultra Demo systems.
1616
+ *
1617
+ * If the app is running against our demo server, you can retrieve the OTP without needing to send SMS or emails.
1618
+ */
1619
+ WDOBaseVerificationService.prototype.getOTP = function () {
1620
+ return __awaiter(this, void 0, void 0, function () {
1621
+ var pid;
1622
+ return __generator(this, function (_a) {
1623
+ switch (_a.label) {
1624
+ case 0:
1625
+ WDOLogger.debug("Activation: getting OTP from server (only for testing purposes)");
1626
+ pid = this.verifyHasActiveProcess();
1627
+ return [4 /*yield*/, this.api.activationGetOTP(pid, "USER_VERIFICATION")];
1628
+ case 1: return [2 /*return*/, (_a.sent()).otpCode];
1629
+ }
1630
+ });
1631
+ });
1632
+ };
1633
+ // PRIVATE METHODS
1634
+ /* @internal */
1635
+ WDOBaseVerificationService.prototype.verifyHasActiveProcess = function () {
1636
+ var _a;
1637
+ var pid = (_a = this.lastStatus) === null || _a === void 0 ? void 0 : _a.processId;
1638
+ if (!pid) {
1639
+ WDOLogger.error("Process id not available - did you start the verification process and fetched the status?");
1640
+ throw new WDOError("Process id not available - did you start the verification process and fetched the status?");
1641
+ }
1642
+ return pid;
1643
+ };
1644
+ /* @internal */
1645
+ WDOBaseVerificationService.prototype.processSuccess = function (result) {
1646
+ var _a;
1647
+ if (result.type !== undefined) {
1648
+ (_a = this.listener) === null || _a === void 0 ? void 0 : _a.verificationStatusChanged(this, result);
1649
+ }
1650
+ return result;
1651
+ };
1652
+ /* @internal */
1653
+ WDOBaseVerificationService.prototype.handleError = function (promise) {
1654
+ var _this = this;
1655
+ return promise.catch(function (error) {
1656
+ throw _this.processError(error);
1657
+ });
1658
+ };
1659
+ /* @internal */
1660
+ WDOBaseVerificationService.prototype.processError = function (error) {
1661
+ return __awaiter(this, void 0, void 0, function () {
1662
+ var status_1;
1663
+ var _b;
1664
+ return __generator(this, function (_c) {
1665
+ switch (_c.label) {
1666
+ case 0:
1667
+ if (!(error.code === "AUTHENTICATION_ERROR")) return [3 /*break*/, 4];
1668
+ _c.label = 1;
1669
+ case 1:
1670
+ _c.trys.push([1, 3, , 4]);
1671
+ return [4 /*yield*/, this.fetchActivationStatus()];
1672
+ case 2:
1673
+ status_1 = _c.sent();
1674
+ if (status_1.state !== WDOPowerAuthActivationState.ACTIVE) {
1675
+ WDOLogger.error("PowerAuth status is not active (status".concat(status_1.state, ") - notifying the delegate and returning and error."));
1676
+ (_b = this.listener) === null || _b === void 0 ? void 0 : _b.powerAuthActivationStatusChanged(this, status_1);
1677
+ return [2 /*return*/, new WDOError("PowerAuth activation is not active anymore")];
1678
+ }
1679
+ return [3 /*break*/, 4];
1680
+ case 3:
1681
+ _c.sent();
1682
+ return [3 /*break*/, 4];
1683
+ case 4: return [2 /*return*/, error];
1684
+ }
1685
+ });
1686
+ });
1687
+ };
1688
+ return WDOBaseVerificationService;
1689
+ }());
1690
+ // INTERNAL CLASSES
1691
+ /**
1692
+ @internal
1693
+ Internal status that works as a translation layer between server API and SDK API
1694
+ */
1695
+ var WDOVerificationStatus = /** @class */ (function () {
1696
+ /** Translation from server status to phone status. */
1697
+ function WDOVerificationStatus(serverResponse) {
1698
+ var phase = serverResponse.identityVerificationPhase;
1699
+ var status = serverResponse.identityVerificationStatus;
1700
+ var nextStep = undefined;
1701
+ var statusCheckReason = undefined;
1702
+ // UNDEFINED PHASE
1703
+ if (phase == undefined) {
1704
+ switch (status) {
1705
+ case WDOIdentityVerificationStatus.notInitialized:
1706
+ nextStep = WDONextStep.intro;
1707
+ break;
1708
+ case WDOIdentityVerificationStatus.failed:
1709
+ nextStep = WDONextStep.failed;
1710
+ break;
1711
+ }
1712
+ }
1713
+ // DOCUMENT UPLOAD PHASE
1714
+ else if (phase === WDOIdentityVerificationPhase.documentUpload) {
1715
+ switch (status) {
1716
+ case WDOIdentityVerificationStatus.inProgress:
1717
+ nextStep = WDONextStep.documentScan;
1718
+ break;
1719
+ case WDOIdentityVerificationStatus.verificationPending:
1720
+ nextStep = WDONextStep.statusCheck;
1721
+ statusCheckReason = exports.WDOStatusCheckReason.documentVerification;
1722
+ break;
1723
+ case WDOIdentityVerificationStatus.failed:
1724
+ nextStep = WDONextStep.failed;
1725
+ break;
1726
+ }
1727
+ }
1728
+ // DOCUMENT VERIFICATION PHASE
1729
+ else if (phase === WDOIdentityVerificationPhase.documentVerification) {
1730
+ switch (status) {
1731
+ case WDOIdentityVerificationStatus.accepted:
1732
+ nextStep = WDONextStep.statusCheck;
1733
+ statusCheckReason = exports.WDOStatusCheckReason.documentAccepted;
1734
+ break;
1735
+ case WDOIdentityVerificationStatus.inProgress:
1736
+ nextStep = WDONextStep.statusCheck;
1737
+ statusCheckReason = exports.WDOStatusCheckReason.documentVerification;
1738
+ break;
1739
+ case WDOIdentityVerificationStatus.failed:
1740
+ nextStep = WDONextStep.failed;
1741
+ break;
1742
+ case WDOIdentityVerificationStatus.rejected:
1743
+ nextStep = WDONextStep.rejected;
1744
+ break;
1745
+ }
1746
+ }
1747
+ // DOCUMENT VERIFICATION FINAL PHASE
1748
+ else if (phase === WDOIdentityVerificationPhase.documentVerificationFinal) {
1749
+ switch (status) {
1750
+ case WDOIdentityVerificationStatus.accepted:
1751
+ nextStep = WDONextStep.statusCheck;
1752
+ statusCheckReason = exports.WDOStatusCheckReason.documentsCrossVerification;
1753
+ break;
1754
+ case WDOIdentityVerificationStatus.inProgress:
1755
+ nextStep = WDONextStep.statusCheck;
1756
+ statusCheckReason = exports.WDOStatusCheckReason.documentsCrossVerification;
1757
+ break;
1758
+ case WDOIdentityVerificationStatus.failed:
1759
+ nextStep = WDONextStep.failed;
1760
+ break;
1761
+ case WDOIdentityVerificationStatus.rejected:
1762
+ nextStep = WDONextStep.rejected;
1763
+ break;
1764
+ }
1765
+ }
1766
+ // CLIENT EVALUATION PHASE
1767
+ else if (phase === WDOIdentityVerificationPhase.clientEvaluation) {
1768
+ switch (status) {
1769
+ case WDOIdentityVerificationStatus.inProgress:
1770
+ nextStep = WDONextStep.statusCheck;
1771
+ statusCheckReason = exports.WDOStatusCheckReason.clientVerification;
1772
+ break;
1773
+ case WDOIdentityVerificationStatus.accepted:
1774
+ nextStep = WDONextStep.statusCheck;
1775
+ statusCheckReason = exports.WDOStatusCheckReason.clientAccepted;
1776
+ break;
1777
+ case WDOIdentityVerificationStatus.rejected:
1778
+ nextStep = WDONextStep.rejected;
1779
+ break;
1780
+ case WDOIdentityVerificationStatus.failed:
1781
+ nextStep = WDONextStep.failed;
1782
+ break;
1783
+ }
1784
+ }
1785
+ // PRESENCE CHECK PHASE
1786
+ else if (phase === WDOIdentityVerificationPhase.presenceCheck) {
1787
+ switch (status) {
1788
+ case WDOIdentityVerificationStatus.notInitialized:
1789
+ case WDOIdentityVerificationStatus.inProgress:
1790
+ nextStep = WDONextStep.presenceCheck;
1791
+ break;
1792
+ case WDOIdentityVerificationStatus.verificationPending:
1793
+ nextStep = WDONextStep.statusCheck;
1794
+ statusCheckReason = exports.WDOStatusCheckReason.verifyingPresence;
1795
+ break;
1796
+ case WDOIdentityVerificationStatus.failed:
1797
+ nextStep = WDONextStep.failed;
1798
+ break;
1799
+ case WDOIdentityVerificationStatus.rejected:
1800
+ nextStep = WDONextStep.rejected;
1801
+ break;
1802
+ }
1803
+ }
1804
+ // OTP PHASE
1805
+ else if (phase === WDOIdentityVerificationPhase.otp) {
1806
+ switch (status) {
1807
+ case WDOIdentityVerificationStatus.verificationPending:
1808
+ nextStep = WDONextStep.otp;
1809
+ break;
1810
+ }
1811
+ }
1812
+ // COMPLETED PHASE
1813
+ else if (phase === WDOIdentityVerificationPhase.completed) {
1814
+ switch (status) {
1815
+ case WDOIdentityVerificationStatus.accepted:
1816
+ nextStep = WDONextStep.success;
1817
+ break;
1818
+ case WDOIdentityVerificationStatus.failed:
1819
+ nextStep = WDONextStep.failed;
1820
+ break;
1821
+ case WDOIdentityVerificationStatus.rejected:
1822
+ nextStep = WDONextStep.rejected;
1823
+ break;
1824
+ }
1825
+ }
1826
+ if (nextStep == undefined) {
1827
+ WDOLogger.error("Unknown phase/status combo: ".concat(phase !== null && phase !== void 0 ? phase : "nil", ", ").concat(status));
1828
+ nextStep = WDONextStep.failed;
1829
+ }
1830
+ this.nextStep = nextStep;
1831
+ this.statusCheckReason = statusCheckReason;
1832
+ }
1833
+ WDOVerificationStatus.prototype.description = function () {
1834
+ var result = this.nextStep.toString();
1835
+ if (this.statusCheckReason) {
1836
+ result += "(".concat(this.statusCheckReason, ")");
1837
+ }
1838
+ return result;
1839
+ };
1840
+ return WDOVerificationStatus;
1841
+ }());
1842
+ /* @internal */
1843
+ var WDONextStep;
1844
+ (function (WDONextStep) {
1845
+ WDONextStep["intro"] = "intro";
1846
+ WDONextStep["documentScan"] = "documentScan";
1847
+ WDONextStep["statusCheck"] = "statusCheck";
1848
+ WDONextStep["presenceCheck"] = "presenceCheck";
1849
+ WDONextStep["otp"] = "otp";
1850
+ WDONextStep["failed"] = "failed";
1851
+ WDONextStep["rejected"] = "rejected";
1852
+ WDONextStep["success"] = "success";
1853
+ })(WDONextStep || (WDONextStep = {}));
1854
+ function documentAction(document) {
1855
+ switch (document.status) {
1856
+ case WDODocumentStatus.accepted:
1857
+ return "proceed";
1858
+ case WDODocumentStatus.uploadInProgress:
1859
+ case WDODocumentStatus.inProgress:
1860
+ case WDODocumentStatus.verificationPending:
1861
+ case WDODocumentStatus.verificationInProgress:
1862
+ return "wait";
1863
+ case WDODocumentStatus.rejected:
1864
+ case WDODocumentStatus.failed:
1865
+ return "error";
1866
+ }
1867
+ WDOLogger.debug("Unknown document status: ".concat(document.status, " for document ID: ").concat(document.id));
1868
+ return "error"; // fallback
1869
+ }
1870
+
1871
+ /**
1872
+ * Copyright Wultra s.r.o.
1873
+ *
1874
+ * This source code is licensed under the Apache License, Version 2.0 license
1875
+ * found in the LICENSE file in the root directory of this source tree.
1876
+ *
1877
+ * SPDX-License-Identifier: Apache-2.0
1878
+ */
1879
+
1880
+ /**
1881
+ * Service that can verify previously activated PowerAuth instance.
1882
+ *
1883
+ * When PowerAuth instance was activated with weak credentials via `WDOActivationService`, user needs to verify his genuine presence.
1884
+ *
1885
+ * This service operates against Wultra Onboarding server (usually ending with `/enrollment-onboarding-server`) and you need to configure networking service with the right URL.
1886
+ */
1887
+ var WDOVerificationService = /** @class */ (function (_super) {
1888
+ __extends(WDOVerificationService, _super);
1889
+ /**
1890
+ * Creates service instance
1891
+ *
1892
+ * @param powerauth Configured PowerAuth instance. This instance needs to be without valid activation.
1893
+ * @param baseUrl Base URL of the Wultra Digital Onboarding server. Usually ending with `/enrollment-onboarding-server`.
1894
+ */
1895
+ function WDOVerificationService(powerauth, baseUrl) {
1896
+ var _this = _super.call(this) || this;
1897
+ _this.api = new WDOApi(powerauth, baseUrl);
1898
+ _this.powerauth = powerauth;
1899
+ return _this;
1900
+ }
1901
+ /** Checks if verification is required based on PowerAuth activation status */
1902
+ WDOVerificationService.isVerificationRequired = function (paStatus) {
1903
+ var _a;
1904
+ var flags = (_a = paStatus.customObject) === null || _a === void 0 ? void 0 : _a.activationFlags;
1905
+ return !!flags && flags.some(function (f) { return f === "VERIFICATION_PENDING" || f === "VERIFICATION_IN_PROGRESS"; });
1906
+ };
1907
+ /* @internal */
1908
+ WDOVerificationService.prototype.fetchActivationStatus = function () {
1909
+ return __awaiter(this, void 0, void 0, function () {
1910
+ var result;
1911
+ return __generator(this, function (_a) {
1912
+ switch (_a.label) {
1913
+ case 0: return [4 /*yield*/, this.powerauth.fetchActivationStatus()];
1914
+ case 1:
1915
+ result = _a.sent();
1916
+ return [2 /*return*/, {
1917
+ state: WDOPowerAuthActivationState[result.state],
1918
+ failCount: result.failCount,
1919
+ maxFailCount: result.maxFailCount,
1920
+ remainingAttempts: result.remainingAttempts,
1921
+ customObject: result.customObject
1922
+ }];
1923
+ }
1924
+ });
1925
+ });
1926
+ };
1927
+ /* @internal */
1928
+ WDOVerificationService.prototype.changeAcceptLanguageImpl = function (language) {
1929
+ this.api.networking.acceptLanguage = language;
1930
+ };
1931
+ return WDOVerificationService;
1932
+ }(WDOBaseVerificationService));
1933
+
1934
+ /**
1935
+ * Copyright Wultra s.r.o.
1936
+ *
1937
+ * This source code is licensed under the Apache License, Version 2.0 license
1938
+ * found in the LICENSE file in the root directory of this source tree.
1939
+ *
1940
+ * SPDX-License-Identifier: Apache-2.0
1941
+ */
1942
+ /** Service that provides configuration for the Wultra Digital Onboarding SDK. */
1943
+ var WDOBaseConfigurationService = /** @class */ (function () {
1944
+ function WDOBaseConfigurationService() {
1945
+ }
1946
+ /**
1947
+ * Fetches configuration for the given process type from the server.
1948
+ *
1949
+ * @param processType Type of the process for which to fetch configuration.
1950
+ * @returns Configuration response from the server.
1951
+ */
1952
+ WDOBaseConfigurationService.prototype.getConfiguration = function (processType) {
1953
+ return __awaiter(this, void 0, void 0, function () {
1954
+ return __generator(this, function (_a) {
1955
+ switch (_a.label) {
1956
+ case 0: return [4 /*yield*/, this.api.getConfiguration(processType)];
1957
+ case 1: return [2 /*return*/, _a.sent()];
1958
+ }
1959
+ });
1960
+ });
1961
+ };
1962
+ return WDOBaseConfigurationService;
1963
+ }());
1964
+
1965
+ /**
1966
+ * Copyright Wultra s.r.o.
1967
+ *
1968
+ * This source code is licensed under the Apache License, Version 2.0 license
1969
+ * found in the LICENSE file in the root directory of this source tree.
1970
+ *
1971
+ * SPDX-License-Identifier: Apache-2.0
1972
+ */
1973
+
1974
+ /** Service that provides configuration for the Wultra Digital Onboarding SDK. */
1975
+ var WDOConfigurationService = /** @class */ (function (_super) {
1976
+ __extends(WDOConfigurationService, _super);
1977
+ /**
1978
+ * Creates service instance
1979
+ *
1980
+ * @param powerauth Configured PowerAuth instance.
1981
+ * @param baseUrl Base URL of the Wultra Digital Onboarding server. Usually ending with `/enrollment-onboarding-server`.
1982
+ */
1983
+ function WDOConfigurationService(powerauth, baseUrl) {
1984
+ var _this = _super.call(this) || this;
1985
+ _this.api = new WDOApi(powerauth, baseUrl);
1986
+ _this.powerauth = powerauth;
1987
+ return _this;
1988
+ }
1989
+ return WDOConfigurationService;
1990
+ }(WDOBaseConfigurationService));
1991
+
1992
+ exports.Side = Side;
1993
+ exports.WDOActivationService = WDOActivationService;
1994
+ exports.WDOConfigurationService = WDOConfigurationService;
1995
+ exports.WDODocumentFile = WDODocumentFile;
1996
+ exports.WDODocumentTypeSides = WDODocumentTypeSides;
1997
+ exports.WDOLogger = WDOLogger;
1998
+ exports.WDOScannedDocument = WDOScannedDocument;
1999
+ exports.WDOVerificationScanProcess = WDOVerificationScanProcess;
2000
+ exports.WDOVerificationService = WDOVerificationService;
2001
+ //# sourceMappingURL=index.js.map