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