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.
@@ -0,0 +1,493 @@
1
+ # Verifying user
2
+
3
+ If your PowerAuthSDK instance was activated with the `WDOActivationService`, it will be in the state that needs additional verification. Without such verification, it won't be able to properly sign requests.
4
+
5
+ Additional verification means that the user will need to scan his face and documents like ID and/or passport.
6
+
7
+ ## When is the verification needed?
8
+
9
+ Verification is needed if the `activationFlags` in the `PowerAuthActivationStatus` contains `VERIFICATION_PENDING` or `VERIFICATION_IN_PROGRESS` value.
10
+
11
+ To simplify this check, you can use the `WDOVerificationService.isVerificationRequired` method that returns a boolean indicating whether verification is required.
12
+
13
+ Example:
14
+
15
+ ```typescript
16
+ const powerAuth: PowerAuth // configured and activated PowerAuth instance
17
+
18
+ try {
19
+ const status = await powerAuth.fetchActivationStatus()
20
+ if (WDOVerificationService.isVerificationRequired(status)) {
21
+ // navigate to the verification flow
22
+ // and call `WDOVerificationService.status`
23
+ } else {
24
+ // handle PA status
25
+ }
26
+ } catch (error) {
27
+ // handle error
28
+ }
29
+ ```
30
+
31
+ ## Example app flow
32
+
33
+ <p align="center"><img src="images/verification-mockup.png" alt="Example verification flow" width="100%" /></p>
34
+
35
+ <!-- begin box info -->
36
+ This mockup shows a __happy user flow__ of an example setup. Your usage may vary.
37
+ The final flow (which screens come after another) is controlled by the backend.
38
+ <!-- end -->
39
+
40
+ ## Server driven flow
41
+
42
+ - The screen that should be displayed is driven by the state on the server "session".
43
+ - At the beginning of the verification process, you will call the status which will tell you what to display to the user and which function to call next.
44
+ - Each API call returns a result and a next screen to display.
45
+ - This repeats until the process is finished or an "endstate state" is presented which terminates the process.
46
+
47
+ ## Possible state values
48
+
49
+ State is defined by the `WDOVerificationStateType` enum with the following possibilities:
50
+
51
+ ```typescript
52
+ /** Types of the verification state */
53
+ declare enum WDOVerificationStateType {
54
+ /**
55
+ * Show the verification introduction screen where the user can start the activation.
56
+ *
57
+ * The next step should be calling the `consentGet()`.
58
+ */
59
+ intro = "intro",
60
+ /**
61
+ * Show document selection to the user. Which documents are available and how many
62
+ * can the user select is up to your backend configuration.
63
+ *
64
+ * The next step should be calling the `documentsSetSelectedTypes`.
65
+ */
66
+ documentsToScanSelect = "documentsToScanSelect",
67
+ /**
68
+ * User should scan documents - display UI for the user to scan all necessary documents.
69
+ *
70
+ * The next step should be calling the `documentsSubmit`.
71
+ */
72
+ scanDocument = "scanDocument",
73
+ /**
74
+ * The system is processing data - show loading with text hint from provided `WDOStatusCheckReason`.
75
+ *
76
+ * The next step should be calling the `status`.
77
+ */
78
+ processing = "processing",
79
+ /**
80
+ * The user should be presented with a presence check.
81
+ * Presence check is handled by third-party SDK based on the project setup.
82
+ *
83
+ * The next step should be calling the `presenceCheckInit` to start the check and `presenceCheckSubmit` to
84
+ * 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.
85
+ */
86
+ presenceCheck = "presenceCheck",
87
+ /**
88
+ * Show enter OTP screen with resend button.
89
+ *
90
+ * The next step should be calling the `verifyOTP` with user-entered OTP.
91
+ * The OTP is usually SMS or email.
92
+ */
93
+ otp = "otp",
94
+ /**
95
+ * Verification failed and can be restarted
96
+ *
97
+ * The next step should be calling the `restartVerification` or `cancelWholeProcess` based on
98
+ * the user's decision if he wants to try it again or cancel the process.
99
+ */
100
+ failed = "failed",
101
+ /**
102
+ * Verification is canceled and the user needs to start again with a new PowerAuth activation.
103
+ *
104
+ * The next step should be calling the `PowerAuth.removeActivationLocal()` and starting activation from scratch.
105
+ */
106
+ endState = "endState",
107
+ /**
108
+ * Verification was successfully ended. Continue into your app flow.
109
+ */
110
+ success = "success"
111
+ }
112
+ ```
113
+
114
+ Based on the type value, additional data is provided in the union type `WDOVerificationState`.
115
+
116
+ Available data per state type:
117
+
118
+ ```typescript
119
+ export type WDOVerificationState =
120
+ | WDOIntroState
121
+ | WDODocumentsToScanSelectState
122
+ | WDOScanDocumentState
123
+ | WDOProcessingState
124
+ | WDOPresenceCheckState
125
+ | WDOOtpState
126
+ | WDOFailedState
127
+ | WDOEndStateState
128
+ | WDOSuccessState
129
+
130
+ /**
131
+ * Show the verification introduction screen where the user can start the activation.
132
+ *
133
+ * The next step should be calling the `start`.
134
+ */
135
+ export interface WDOIntroState {
136
+ type: WDOVerificationStateType.intro,
137
+ /** Indicates whether the user consent is required to proceed */
138
+ consentRequired: boolean
139
+ }
140
+
141
+ /**
142
+ * Show document selection to the user. Which documents are available and how many
143
+ * can the user select is up to your backend configuration.
144
+ *
145
+ * The next step should be calling the `documentsSetSelectedTypes`.
146
+ */
147
+ export interface WDODocumentsToScanSelectState {
148
+ type: WDOVerificationStateType.documentsToScanSelect
149
+ }
150
+
151
+ /**
152
+ * User should scan documents - display UI for the user to scan all necessary documents.
153
+ *
154
+ * The next step should be calling the `documentsSubmit`.
155
+ */
156
+ export interface WDOScanDocumentState {
157
+ type: WDOVerificationStateType.scanDocument
158
+ /** Scanning process that helps with the document scanning */
159
+ process: WDOVerificationScanProcess
160
+ }
161
+
162
+ /**
163
+ * The system is processing data - show loading with text hint from provided `WDOStatusCheckReason`.
164
+ *
165
+ * The next step should be calling the `status`.
166
+ */
167
+ export interface WDOProcessingState {
168
+ type: WDOVerificationStateType.processing
169
+ /** Reason for the current processing state */
170
+ item: WDOStatusCheckReason
171
+ }
172
+
173
+ /**
174
+ * The user should be presented with a presence check.
175
+ * Presence check is handled by third-party SDK based on the project setup.
176
+ *
177
+ * The next step should be calling the `presenceCheckInit` to start the check and `presenceCheckSubmit` to
178
+ * 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.
179
+ */
180
+ export interface WDOPresenceCheckState {
181
+ type: WDOVerificationStateType.presenceCheck
182
+ }
183
+
184
+ /**
185
+ * Show enter OTP screen with resend button.
186
+ *
187
+ * The next step should be calling the `verifyOTP` with user-entered OTP.
188
+ * The OTP is usually SMS or email.
189
+ */
190
+ export interface WDOOtpState {
191
+ type: WDOVerificationStateType.otp
192
+ /** Number of remaining attempts to enter the correct OTP */
193
+ remainingAttempts?: number
194
+ }
195
+
196
+ /**
197
+ * Verification failed and can be restarted
198
+ *
199
+ * The next step should be calling the `restartVerification` or `cancelWholeProcess` based on
200
+ * the user's decision if he wants to try it again or cancel the process.
201
+ */
202
+ export interface WDOFailedState {
203
+ type: WDOVerificationStateType.failed
204
+ }
205
+
206
+ /**
207
+ * Verification is canceled and the user needs to start again with a new PowerAuth activation.
208
+ *
209
+ * The next step should be calling the `PowerAuth.removeActivationLocal()` and starting activation from scratch.
210
+ */
211
+ export interface WDOEndStateState {
212
+ type: WDOVerificationStateType.endState
213
+ /** Reason for the end state */
214
+ reason: WDOEndStateReason
215
+ }
216
+
217
+ /**
218
+ * Verification was successfully ended. Continue into your app flow.
219
+ */
220
+ export interface WDOSuccessState {
221
+ type: WDOVerificationStateType.success
222
+ }
223
+ ```
224
+
225
+ ## Creating an instance
226
+
227
+ To create an instance you will need a `PowerAuth` instance that is __already activated__.
228
+
229
+ <!-- begin box info -->
230
+ [Documentation for `PowerAuth`](https://github.com/wultra/react-native-powerauth-mobile-sdk).
231
+ <!-- end -->
232
+
233
+
234
+ Example:
235
+ ```typescript
236
+ const powerAuth = new PowerAuth("my-pa-instance")
237
+ powerAuth.configure({
238
+ configuration: "ARCB+...jg==", // base64 PowerAuth configuration
239
+ baseEndpointUrl: "https://my-server-deployment.com/enrollment-server/"
240
+ })
241
+ const verification = new WDOVerificationService(
242
+ powerAuth,
243
+ "https://my-server-deployment.com/enrollment-server-onboarding/"
244
+ )
245
+ ```
246
+
247
+ ## Getting the verification status
248
+
249
+ When entering the verification flow for the first time (for example fresh app start), you need to retrieve the state of the verification.
250
+
251
+ The same needs to be done after some operation fails and it's not sure what is the next step in the verification process.
252
+
253
+ Most verification functions return the result and also the state for your convenience of "what next".
254
+
255
+ Getting the state directly:
256
+
257
+ ```typescript
258
+ const verification: WDOVerificationService // configured instance
259
+ try {
260
+ const vfStatus = await verification.status()
261
+ // handle `WDOVerificationState` state and navigate to the expected screen
262
+ if (vfStatus.type === WDOVerificationStateType.intro) {
263
+ // display intro screen
264
+ const consentRequired = vfStatus.consentRequired // accessible based on union type 'intro'
265
+ // show consent info if needed
266
+ verification.start(WDOConsentResponse.approved) // example of starting the process
267
+
268
+ } else if (vfStatus.type === WDOVerificationStateType.documentsToScanSelect) {
269
+ // display document selector
270
+ }
271
+ // ... other states
272
+ } catch (error) {
273
+ if (error.verificationState) {
274
+ // show expected screen based on the state
275
+ } else {
276
+ // navigate to error screen
277
+ }
278
+ }
279
+ ```
280
+
281
+ ## Starting the identity verification
282
+
283
+ When the state is `intro`, the first step in the flow is to start the verification process by calling `start` function.
284
+
285
+ ```typescript
286
+ const state: WDOVerificationState // we're assuming that the state is `intro` here (WDOIntroState)
287
+ const verification: WDOVerificationService // configured instance
288
+ try {
289
+ let consentResult: WDOConsentResponse
290
+ const introState = state as WDOIntroState
291
+ if (introState.consentRequired) {
292
+ const consentTextResponse = await verification.consentGet()
293
+ // show consent screen to the user and get his approval
294
+ // assuming user approved the consent here
295
+ consentResult = WDOConsentResponse.approved
296
+ } else {
297
+ consentResult = WDOConsentResponse.notRequired
298
+ }
299
+ const startResult = await verification.start(consentResult)
300
+ // process the returned state, should be `documentsToScanSelect` now
301
+ } catch (error) {
302
+ if (error.verificationState) {
303
+ // show expected screen based on the state
304
+ } else {
305
+ // navigate to error screen
306
+ }
307
+ }
308
+ ```
309
+
310
+ ## Set document types to scan
311
+
312
+ After the user approves the consent, present a document selector for documents which will be scanned. The number and types of documents (or other rules like 1 type required) are completely dependent on your backend system integration. You can retrieve the list of available document types from the [configuration service](Process-Configuration.md).
313
+
314
+ For example, your system might require a national ID and one additional document like a driver's license, passport, or any other government-issued personal document.
315
+
316
+ ```typescript
317
+ const verification: WDOVerificationService // configured instance
318
+ try {
319
+ const docTypesResult = await verification.documentsSetSelectedTypes([
320
+ WDODocumentType.idCard,
321
+ WDODocumentType.driversLicense
322
+ ])
323
+ // state will be in the `scanDocument` case here - display the document scanner
324
+ } catch (error) {
325
+ if (error.verificationState) {
326
+ // show expected screen based on the state
327
+ } else {
328
+ // navigate to error screen
329
+ }
330
+ }
331
+ ```
332
+
333
+ ## Configuring the "Document Scan SDK"
334
+
335
+ <!-- begin box info -->
336
+ This step does not move the state of the process but is a "stand-alone" API call.
337
+ <!-- end -->
338
+
339
+ Since the document scanning itself is not provided by this library but by a 3rd party library, some of them need a server-side initialization.
340
+
341
+ If your chosen scanning SDK requires such a step, use this function to retrieve necessary data from the server.
342
+
343
+ Example:
344
+
345
+ ```typescript
346
+ const verification: WDOVerificationService // configured instance
347
+ const challengeFromSDK = "..." // optional challenge from the scanning SDK
348
+ const initResult = await verification.documentsInitSDK(challengeFromSDK)
349
+ // use the `initResult` to initialize the scanning SDK
350
+ ```
351
+
352
+ ## Scanning a document
353
+
354
+ When the state of the process is `scanDocument` with the `WDOVerificationScanProcess` parameter, you need to present a document scan UI to the user. This UI needs
355
+ to guide through the scanning process - scanning one document after another and both sides (if the document requires so).
356
+
357
+ The whole UI and document scanning process is up to you and the 3rd party library you choose to use.
358
+
359
+ <!-- begin box warning -->
360
+ This step is the most complicated in the process as you need to integrate this SDK, another document-scanning SDK, and integrate your server-side expected logic. To
361
+ make sure everything goes as smoothly as possible, ask your project management to provide you with a detailed description/document of the required scenarios and expected documents
362
+ for your implementation.
363
+ <!-- end -->
364
+
365
+ ## Uploading a document
366
+
367
+ When a document is scanned (both sides when required), it needs to be uploaded to the server.
368
+
369
+ <!-- begin box warning -->
370
+ __Images of the document should not be bigger than 1MB. Files that are too big will take longer time to upload and process on the server.__
371
+ <!-- end -->
372
+
373
+ To upload a document, use `documentsSubmit` function. Each side of a document is a single `WDODocumentFile` instance.
374
+
375
+ Example:
376
+
377
+ ```typescript
378
+ const verification: WDOVerificationService // configured instance
379
+
380
+ const passportToUpload = WDODocumentFile(
381
+ "BASE64_ENCODED_IMAGE_DATA", // raw image data from the document scanning library/photo camera
382
+ WDODocumentType.passport,
383
+ WDODocumentSide.front, // passport has only front side
384
+ undefined, // use only when re-uploading the file (for example when first upload was rejected because of a blur)
385
+ undefined // optional, use when provided by the document scanning library
386
+ )
387
+ try {
388
+ const result = await verification.documentsSubmit([passportToUpload])
389
+ // state will be in the `processing` case here - display the processing screen
390
+ } catch (error) {
391
+ if (error.verificationState) {
392
+ // show expected screen based on the state
393
+ } else {
394
+ // navigate to error screen
395
+ }
396
+ }
397
+ ```
398
+
399
+ ### `WDODocumentFile`
400
+
401
+ ```typescript
402
+ /** Image of a document that can be sent to the backend for Identity Verification. */
403
+ declare class WDODocumentFile {
404
+ /** Raw data to upload. Make sure that the data aren't too big, hundreds of kbs should be enough. */
405
+ data: Base64EncodedJPEG;
406
+ /**
407
+ * Image signature.
408
+ *
409
+ * Optional, use only when the scan SDK supports this.
410
+ */
411
+ dataSignature: string | undefined;
412
+ /** Type of the document. */
413
+ type: WDODocumentType;
414
+ /** Side of the document (`front` if the document is one-sided or only one side is expected). */
415
+ side: WDODocumentSide;
416
+ /**
417
+ * For image reuploading when the previous file of the same document was rejected.
418
+ *
419
+ * Without specifying this value, the document side won't be overwritten.
420
+ */
421
+ originalDocumentId: string | undefined;
422
+ /**
423
+ * Create the document file from an image that can be sent to the backend for Identity Verification.
424
+ *
425
+ * @param scannedDocument Document to upload.
426
+ * @param side The side of the document that the image captures.
427
+ * @param data Raw image data. Make sure that the data aren't too big, hundreds of kbs should be enough.
428
+ * @param dataSignature Signature of the image data. Optional, use only when the scan SDK supports this. `undefined` by default.
429
+ * @returns Document file to upload.
430
+ */
431
+ static fromScannedDocument(scannedDocument: WDOScannedDocument, side: WDODocumentSide, data: Base64EncodedJPEG, dataSignature?: string): WDODocumentFile;
432
+ /**
433
+ * Image of a document that can be sent to the backend for Identity Verification.
434
+ *
435
+ * @param data Raw image data. Make sure that the data aren't too big, hundreds of kbs should be enough.
436
+ * @param type Type of the document.
437
+ * @param side The side of the document that the image captures.
438
+ * @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.
439
+ * @param dataSignature Signature of the image data. Optional, use only when the scan SDK supports this. `undefined` by default.
440
+ */
441
+ constructor(data: Base64EncodedJPEG, type: WDODocumentType, side: WDODocumentSide, originalDocumentId?: string, dataSignature?: string);
442
+ }
443
+ ```
444
+
445
+ <!-- begin box info -->
446
+ To create an instance of the `WDODocumentFile`, you can use `WDODocumentFile.fromScannedDocument`. The `WDOScannedDocument` is returned in the process status as a "next document to scan".
447
+ <!-- end -->
448
+
449
+ ## Presence check
450
+
451
+ To verify that the user is present in front of the phone, a presence check is required. This is suggested by the `presenceCheck` state.
452
+
453
+ When this state is obtained, the following steps need to be done:
454
+
455
+ 1. Call `presenceCheckInit` to initialize the presence check on the server. This call returns a dictionary of necessary data for the presence-check library to initialize.
456
+ 2. Make the presence check by the third-party library
457
+ 3. After the presence check is finished, call `presenceCheckSubmit` to tell the server you finished the process on the device.
458
+
459
+ ## Verify OTP (optional step)
460
+
461
+ After the presence check is finished, the user will receive an SMS/email OTP and the `otp` state will be reported. When this state is received, prompt the user for the OTP and verify it via `verifyOTP` method.
462
+
463
+ The `otp` state also contains the number of possible OTP attempts. When attempts are depleted, the error state is returned.
464
+
465
+ Example:
466
+
467
+ ```typescript
468
+ const verification: WDOVerificationService // configured instance
469
+ try {
470
+ const otpStatus = await verificationService.verifyOTP("123456")
471
+ // React to a new state returned in the result
472
+ } catch (error) {
473
+ // handle error
474
+ }
475
+ ```
476
+
477
+ ## Success state
478
+
479
+ When a whole verification is finished, you will receive the `success` state. Show a success screen and navigate the user to a common activated flow.
480
+
481
+ At the same time, the verification flags from the PowerAuth status are removed.
482
+
483
+ ## Failed state
484
+
485
+ When the process fails, a `failed` state is returned. This means that the current verification process has failed and the user can restart it (by calling the `restartVerification` function) and start again (by showing the intro).
486
+
487
+ ## Endstate state
488
+
489
+ When the activation is no longer able to be verified (for example did several failed attempts or took too long to finish), the `endstate` state is returned. In this state there's nothing the user can do to continue. `cancelWholeProcess` shall be called and `removeActivationLocal` should be called on the PowerAuth object. After that, user should be put inti the "fresh install state".
490
+
491
+ ## Read next
492
+
493
+ - [Language Configuration](Language-Configuration.md)
@@ -0,0 +1,12 @@
1
+ **Tutorials**
2
+
3
+ - [SDK Integration](SDK-Integration.md)
4
+ - [Process Configuration](Process-Configuration.md)
5
+ - [Device Activation (With Weak Credentials)](Device-Activation.md)
6
+ - [Verifying User With Document Scan And Genuine Presence Check](Verifying-User.md)
7
+ - [Language Configuration](Language-Configuration.md)
8
+ - [Logging](Logging.md)
9
+
10
+ **Other**
11
+
12
+ - [Changelog](./Changelog.md)
Binary file