@velocitycareerlabs/yoti-integration-plugin 1.25.0-dev-build.12642c864
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/LICENSE +202 -0
- package/NOTICE +1 -0
- package/README.md +4 -0
- package/index.js +10 -0
- package/package.json +51 -0
- package/src/config/config.js +21 -0
- package/src/controllers/id-verify/controller.js +341 -0
- package/src/controllers/id-verify/repo.js +26 -0
- package/src/diagrams/README.md +14 -0
- package/src/diagrams/diagram-markdown-part-1.md +1 -0
- package/src/diagrams/diagram-markdown-part-2.md +1 -0
- package/src/diagrams/diagram-source-part-1.md +12 -0
- package/src/diagrams/diagram-source-part-2.md +22 -0
- package/src/fetchers.js +23 -0
- package/src/id-credential-types.js +9 -0
- package/src/init-plugin.js +13 -0
- package/src/yoti.js +273 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Copyright 2023 Velocity Team Authors
|
package/README.md
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* eslint-disable global-require */
|
|
2
|
+
const fetchers = require('./src/fetchers');
|
|
3
|
+
|
|
4
|
+
module.exports = {
|
|
5
|
+
...require('./src/yoti'),
|
|
6
|
+
...require('./src/id-credential-types'),
|
|
7
|
+
...require('./src/config/config'),
|
|
8
|
+
...require('./src/init-plugin'),
|
|
9
|
+
fetchers,
|
|
10
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@velocitycareerlabs/yoti-integration-plugin",
|
|
3
|
+
"version": "1.25.0-dev-build.12642c864",
|
|
4
|
+
"description": "Library supporting integration with Yoti services",
|
|
5
|
+
"repository": "https://github.com/velocitycareerlabs/packages",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"license": "Apache-2.0",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"scripts": {
|
|
12
|
+
"test": "jest --config ./jest.config.js --runInBand --coverage",
|
|
13
|
+
"lint": "eslint . --format json >> eslint.json",
|
|
14
|
+
"lint:fix": "eslint --fix --ext .js ."
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@getyoti/sdk-sandbox": "1.7.0",
|
|
18
|
+
"@spencejs/spence-mongo-repos": "^0.10.2",
|
|
19
|
+
"@velocitycareerlabs/common-schemas": "1.25.0-dev-build.12642c864",
|
|
20
|
+
"@velocitycareerlabs/config": "1.25.0-dev-build.12642c864",
|
|
21
|
+
"@velocitycareerlabs/country-data": "1.25.0-dev-build.12642c864",
|
|
22
|
+
"@velocitycareerlabs/crypto": "1.25.0-dev-build.12642c864",
|
|
23
|
+
"@velocitycareerlabs/jwt": "1.25.0-dev-build.12642c864",
|
|
24
|
+
"@velocitycareerlabs/request": "1.25.0-dev-build.12642c864",
|
|
25
|
+
"env-var": "^7.0.0",
|
|
26
|
+
"http-errors": "2.0.0",
|
|
27
|
+
"lodash": "^4.17.21",
|
|
28
|
+
"mongodb": "~6.14.0",
|
|
29
|
+
"nanoid": "~3.3.1",
|
|
30
|
+
"uuid": "11.0.5",
|
|
31
|
+
"yoti": "4.10.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@spencejs/spence-factories": "0.10.2",
|
|
35
|
+
"@velocitycareerlabs/server-provider": "1.25.0-dev-build.12642c864",
|
|
36
|
+
"@velocitycareerlabs/tests-helpers": "1.25.0-dev-build.12642c864",
|
|
37
|
+
"eslint": "8.57.1",
|
|
38
|
+
"eslint-config-airbnb-base": "14.2.1",
|
|
39
|
+
"eslint-config-prettier": "8.10.0",
|
|
40
|
+
"eslint-plugin-autofix": "1.1.0",
|
|
41
|
+
"eslint-plugin-better-mutation": "1.6.0",
|
|
42
|
+
"eslint-plugin-import": "2.31.0",
|
|
43
|
+
"eslint-plugin-prefer-arrow-functions": "3.6.2",
|
|
44
|
+
"eslint-plugin-prettier": "4.2.1",
|
|
45
|
+
"eslint-watch": "7.0.0",
|
|
46
|
+
"jest": "29.7.0",
|
|
47
|
+
"nock": "13.5.6",
|
|
48
|
+
"prettier": "2.8.8"
|
|
49
|
+
},
|
|
50
|
+
"gitHead": "ca5028aa212670198151cabf1147bacf59f10851"
|
|
51
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const env = require('env-var');
|
|
2
|
+
const { genericConfig } = require('@velocitycareerlabs/config');
|
|
3
|
+
|
|
4
|
+
const { isTest } = genericConfig;
|
|
5
|
+
|
|
6
|
+
const yotiConfig = {
|
|
7
|
+
bearerToken: env.get('BEARER_TOKEN').asString(),
|
|
8
|
+
yotiClientSdkId: env.get('YOTI_CLIENT_SDK_ID').required(!isTest).asString(),
|
|
9
|
+
yotiSecret: env.get('YOTI_SECRET').required().asString(),
|
|
10
|
+
idVerificationTenantId: env
|
|
11
|
+
.get('ID_VERIFICATION_TENANT_ID')
|
|
12
|
+
.required()
|
|
13
|
+
.asString(),
|
|
14
|
+
yotiNotificationsWebhookRelativePath: '/yoti-integration/notifications',
|
|
15
|
+
yotiSessionTtl: 2629800, // seconds
|
|
16
|
+
yotiResourceRetentionTtl: 5259600, // 315576000 for creating long lived session for CI
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
module.exports = {
|
|
20
|
+
yotiConfig,
|
|
21
|
+
};
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
const { nanoid } = require('nanoid');
|
|
2
|
+
const { generateCredentialJwt } = require('@velocitycareerlabs/jwt');
|
|
3
|
+
const { generateKeyPair } = require('@velocitycareerlabs/crypto');
|
|
4
|
+
const {
|
|
5
|
+
flow,
|
|
6
|
+
map,
|
|
7
|
+
filter,
|
|
8
|
+
defaultTo,
|
|
9
|
+
isEmpty,
|
|
10
|
+
split,
|
|
11
|
+
last,
|
|
12
|
+
} = require('lodash/fp');
|
|
13
|
+
const newError = require('http-errors');
|
|
14
|
+
const { IDVClient } = require('yoti');
|
|
15
|
+
|
|
16
|
+
const {
|
|
17
|
+
identifyWebhookRequestBodySchema,
|
|
18
|
+
verificationIdentifyResponse200Schema,
|
|
19
|
+
} = require('@velocitycareerlabs/common-schemas');
|
|
20
|
+
const {
|
|
21
|
+
createSessionSpec,
|
|
22
|
+
isCountryCodeValid,
|
|
23
|
+
getIdDocument,
|
|
24
|
+
yotiCheckTointernalYotiCheck,
|
|
25
|
+
} = require('../../yoti');
|
|
26
|
+
const {
|
|
27
|
+
submitCompleteOfferExchange,
|
|
28
|
+
submitAddOfferToExchange,
|
|
29
|
+
} = require('../../fetchers');
|
|
30
|
+
|
|
31
|
+
const idVerificationController = async (fastify) => {
|
|
32
|
+
const { config } = fastify;
|
|
33
|
+
|
|
34
|
+
const idvClient = new IDVClient(config.yotiClientSdkId, config.yotiSecret);
|
|
35
|
+
|
|
36
|
+
fastify.addSchema(identifyWebhookRequestBodySchema);
|
|
37
|
+
fastify.addSchema(verificationIdentifyResponse200Schema);
|
|
38
|
+
|
|
39
|
+
fastify.post(
|
|
40
|
+
'/start-session',
|
|
41
|
+
{
|
|
42
|
+
schema: fastify.autoSchema({
|
|
43
|
+
body: {
|
|
44
|
+
type: 'object',
|
|
45
|
+
properties: {
|
|
46
|
+
defaultCountryCode: { type: 'string' },
|
|
47
|
+
},
|
|
48
|
+
required: ['defaultCountryCode'],
|
|
49
|
+
additionalProperties: false,
|
|
50
|
+
},
|
|
51
|
+
response: {
|
|
52
|
+
200: {
|
|
53
|
+
type: 'object',
|
|
54
|
+
properties: {
|
|
55
|
+
sessionId: { type: 'string' },
|
|
56
|
+
sessionToken: { type: 'string' },
|
|
57
|
+
verifierAuthToken: { type: 'string' },
|
|
58
|
+
verificationIdentifier: { type: 'string' },
|
|
59
|
+
},
|
|
60
|
+
required: [
|
|
61
|
+
'sessionId',
|
|
62
|
+
'sessionToken',
|
|
63
|
+
'verifierAuthToken',
|
|
64
|
+
'verificationIdentifier',
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
}),
|
|
69
|
+
},
|
|
70
|
+
async (req) => {
|
|
71
|
+
const { repos, body } = req;
|
|
72
|
+
const { defaultCountryCode: countryCode } = body;
|
|
73
|
+
|
|
74
|
+
if (!(await isCountryCodeValid(countryCode))) {
|
|
75
|
+
return newError(400, 'Unsupported Country');
|
|
76
|
+
}
|
|
77
|
+
const verifierAuthToken = nanoid();
|
|
78
|
+
const sessionSpec = createSessionSpec(
|
|
79
|
+
{ verifierAuthToken, countryCode },
|
|
80
|
+
req
|
|
81
|
+
);
|
|
82
|
+
const session = await idvClient.createSession(sessionSpec);
|
|
83
|
+
const sessionId = session.getSessionId();
|
|
84
|
+
const sessionToken = session.getClientSessionToken();
|
|
85
|
+
const verificationIdentifier = nanoid();
|
|
86
|
+
|
|
87
|
+
const { privateKey } = generateKeyPair();
|
|
88
|
+
|
|
89
|
+
const verificationIdentifierContent = await generateCredentialJwt(
|
|
90
|
+
{
|
|
91
|
+
id: verificationIdentifier,
|
|
92
|
+
type: ['VerificationIdentifier'],
|
|
93
|
+
issuer: fastify.config.rootDid,
|
|
94
|
+
credentialSubject: {
|
|
95
|
+
id: sessionId,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
privateKey
|
|
99
|
+
);
|
|
100
|
+
await repos.verificationSessions.insert({
|
|
101
|
+
sessionId,
|
|
102
|
+
verifierAuthToken,
|
|
103
|
+
countryCode,
|
|
104
|
+
verificationIdentifierContent,
|
|
105
|
+
});
|
|
106
|
+
return {
|
|
107
|
+
sessionId,
|
|
108
|
+
sessionToken,
|
|
109
|
+
verifierAuthToken,
|
|
110
|
+
verificationIdentifier: verificationIdentifierContent,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
fastify.post(
|
|
116
|
+
config.yotiNotificationsWebhookRelativePath,
|
|
117
|
+
{
|
|
118
|
+
schema: fastify.autoSchema({
|
|
119
|
+
headers: {
|
|
120
|
+
type: 'object',
|
|
121
|
+
properties: {
|
|
122
|
+
authorization: { type: 'string' },
|
|
123
|
+
},
|
|
124
|
+
required: ['authorization'],
|
|
125
|
+
},
|
|
126
|
+
body: {
|
|
127
|
+
type: 'object',
|
|
128
|
+
properties: {
|
|
129
|
+
session_id: {
|
|
130
|
+
type: 'string',
|
|
131
|
+
},
|
|
132
|
+
topic: {
|
|
133
|
+
type: 'string',
|
|
134
|
+
const: 'session_completion',
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
required: ['session_id', 'topic'],
|
|
138
|
+
additionalProperties: true,
|
|
139
|
+
},
|
|
140
|
+
response: {
|
|
141
|
+
200: {
|
|
142
|
+
type: 'object',
|
|
143
|
+
},
|
|
144
|
+
...fastify.NotFoundResponse,
|
|
145
|
+
...fastify.UnauthorizedResponse,
|
|
146
|
+
},
|
|
147
|
+
}),
|
|
148
|
+
},
|
|
149
|
+
async (req) => {
|
|
150
|
+
const { repos, body, headers } = req;
|
|
151
|
+
const { session_id: sessionId } = body;
|
|
152
|
+
const { authorization } = headers;
|
|
153
|
+
|
|
154
|
+
const verificationSession = await repos.verificationSessions.findOne({
|
|
155
|
+
filter: { sessionId },
|
|
156
|
+
});
|
|
157
|
+
if (!verificationSession) {
|
|
158
|
+
return newError(404, `Session Id: ${sessionId} not found`);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const isAuthenticated =
|
|
162
|
+
flow(split(' '), last)(authorization) ===
|
|
163
|
+
verificationSession.verifierAuthToken;
|
|
164
|
+
|
|
165
|
+
if (!isAuthenticated) {
|
|
166
|
+
return newError(
|
|
167
|
+
401,
|
|
168
|
+
`Auth token: ${verificationSession.verifierAuthToken} invalid for session`
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
const offer = await getOffer({ verificationSession, sessionId }, req);
|
|
172
|
+
if (offer) {
|
|
173
|
+
try {
|
|
174
|
+
await submitAddOfferToExchange(
|
|
175
|
+
{
|
|
176
|
+
offer,
|
|
177
|
+
exchangeId: verificationSession.exchangeId,
|
|
178
|
+
},
|
|
179
|
+
req
|
|
180
|
+
);
|
|
181
|
+
} catch (e) {
|
|
182
|
+
req.log.warn({
|
|
183
|
+
err: e,
|
|
184
|
+
fn: 'submitAddOfferToExchange',
|
|
185
|
+
exchangeId: verificationSession.exchangeId,
|
|
186
|
+
});
|
|
187
|
+
throw e;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
await submitCompleteOfferExchange(
|
|
192
|
+
{
|
|
193
|
+
exchangeId: verificationSession.exchangeId,
|
|
194
|
+
},
|
|
195
|
+
req
|
|
196
|
+
);
|
|
197
|
+
} catch (e) {
|
|
198
|
+
req.log.warn({
|
|
199
|
+
err: e,
|
|
200
|
+
fn: 'submitCompleteOfferExchange',
|
|
201
|
+
exchangeId: verificationSession.exchangeId,
|
|
202
|
+
});
|
|
203
|
+
throw e;
|
|
204
|
+
}
|
|
205
|
+
return {};
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
fastify.post(
|
|
210
|
+
'/issuing/identify',
|
|
211
|
+
{
|
|
212
|
+
schema: fastify.autoSchema({
|
|
213
|
+
body: identifyWebhookRequestBodySchema,
|
|
214
|
+
response: {
|
|
215
|
+
200: verificationIdentifyResponse200Schema,
|
|
216
|
+
...fastify.NotFoundResponse,
|
|
217
|
+
},
|
|
218
|
+
}),
|
|
219
|
+
},
|
|
220
|
+
async ({ body, repos }) => {
|
|
221
|
+
const { exchangeId } = body;
|
|
222
|
+
const id = getSessionId(body);
|
|
223
|
+
|
|
224
|
+
const updatedVerificationSessionDocuments =
|
|
225
|
+
await repos.verificationSessions.updateUsingFilter(
|
|
226
|
+
{
|
|
227
|
+
filter: { sessionId: id },
|
|
228
|
+
},
|
|
229
|
+
{ exchangeId }
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
if (isEmpty(updatedVerificationSessionDocuments)) {
|
|
233
|
+
return newError.NotFound('Session not found');
|
|
234
|
+
}
|
|
235
|
+
const session = updatedVerificationSessionDocuments[0];
|
|
236
|
+
|
|
237
|
+
return { vendorUserId: session._id };
|
|
238
|
+
}
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
fastify.post(
|
|
242
|
+
'/issuing/generate-offers',
|
|
243
|
+
{
|
|
244
|
+
schema: fastify.autoSchema({
|
|
245
|
+
body: { type: 'object' },
|
|
246
|
+
response: { 202: { type: 'string' } },
|
|
247
|
+
}),
|
|
248
|
+
},
|
|
249
|
+
async (req, reply) => {
|
|
250
|
+
return reply.code(202).send('');
|
|
251
|
+
}
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
const getOffer = async ({ verificationSession, sessionId }, ctx) => {
|
|
255
|
+
try {
|
|
256
|
+
const session = await idvClient.getSession(sessionId);
|
|
257
|
+
const failedChecks = await getFailedChecksOfSession(session);
|
|
258
|
+
|
|
259
|
+
if (!isEmpty(failedChecks)) {
|
|
260
|
+
await addFailedChecksToVerificationSession(
|
|
261
|
+
verificationSession,
|
|
262
|
+
failedChecks,
|
|
263
|
+
ctx
|
|
264
|
+
);
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const { credential: idDocument, credentialType } = await getIdDocument(
|
|
269
|
+
session,
|
|
270
|
+
idvClient
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
const credentialSubject = {
|
|
274
|
+
...idDocument,
|
|
275
|
+
vendorUserId: verificationSession._id,
|
|
276
|
+
};
|
|
277
|
+
const idDocumentOffer = {
|
|
278
|
+
offerId: nanoid(),
|
|
279
|
+
type: [credentialType],
|
|
280
|
+
credentialSubject,
|
|
281
|
+
claimed: false,
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
ctx.log.info(idDocumentOffer);
|
|
285
|
+
return idDocumentOffer;
|
|
286
|
+
} catch (e) {
|
|
287
|
+
await addErrorToVerificationSession(verificationSession, e, ctx);
|
|
288
|
+
}
|
|
289
|
+
return undefined;
|
|
290
|
+
};
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const getFailedChecksOfSession = async (session) => {
|
|
294
|
+
const checks = session.getChecks();
|
|
295
|
+
return flow([
|
|
296
|
+
filter((check) => check.getType() !== 'LIVENESS'),
|
|
297
|
+
filter((check) => {
|
|
298
|
+
const recommendation = check.getReport().getRecommendation();
|
|
299
|
+
return recommendation.value !== 'APPROVE';
|
|
300
|
+
}),
|
|
301
|
+
map((check) => {
|
|
302
|
+
const { value, reason } = check.getReport().getRecommendation();
|
|
303
|
+
const lastUpdated = check.getLastUpdated();
|
|
304
|
+
const id = check.getId();
|
|
305
|
+
return { id, value, reason: defaultTo('', reason), lastUpdated };
|
|
306
|
+
}),
|
|
307
|
+
])(checks);
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
const addFailedChecksToVerificationSession = async (
|
|
311
|
+
verificationSession,
|
|
312
|
+
failedChecks,
|
|
313
|
+
{ repos }
|
|
314
|
+
) => {
|
|
315
|
+
const internalFailedChecks = map(yotiCheckTointernalYotiCheck, failedChecks);
|
|
316
|
+
await repos.verificationSessions.update(verificationSession._id, {
|
|
317
|
+
failedChecks: internalFailedChecks,
|
|
318
|
+
});
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
const getSessionId = ({ idDocumentCredentials, vendorOriginContext }) => {
|
|
322
|
+
if (vendorOriginContext) {
|
|
323
|
+
return vendorOriginContext;
|
|
324
|
+
}
|
|
325
|
+
const idDocumentCredential = idDocumentCredentials[0];
|
|
326
|
+
return idDocumentCredential.credentialSubject
|
|
327
|
+
? idDocumentCredential.credentialSubject.id
|
|
328
|
+
: idDocumentCredential.id; // Deprecated
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
const addErrorToVerificationSession = async (
|
|
332
|
+
verificationSession,
|
|
333
|
+
err,
|
|
334
|
+
{ repos }
|
|
335
|
+
) => {
|
|
336
|
+
await repos.verificationSessions.update(verificationSession._id, {
|
|
337
|
+
err,
|
|
338
|
+
});
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
module.exports = idVerificationController;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const {
|
|
2
|
+
repoFactory,
|
|
3
|
+
autoboxIdsExtension,
|
|
4
|
+
} = require('@spencejs/spence-mongo-repos');
|
|
5
|
+
|
|
6
|
+
module.exports = (app, options, next = () => {}) => {
|
|
7
|
+
next();
|
|
8
|
+
return repoFactory(
|
|
9
|
+
{
|
|
10
|
+
name: 'verificationSessions',
|
|
11
|
+
entityName: 'verificationSession',
|
|
12
|
+
defaultProjection: {
|
|
13
|
+
_id: 1,
|
|
14
|
+
sessionId: 1,
|
|
15
|
+
exchangeId: 1,
|
|
16
|
+
verifierAuthToken: 1,
|
|
17
|
+
countryCode: 1,
|
|
18
|
+
verificationIdentifierContent: 1,
|
|
19
|
+
createdAt: 1,
|
|
20
|
+
updatedAt: 1,
|
|
21
|
+
},
|
|
22
|
+
extensions: [autoboxIdsExtension],
|
|
23
|
+
},
|
|
24
|
+
app
|
|
25
|
+
);
|
|
26
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Yoti integration steps flow charts.
|
|
2
|
+
Tool used: https://mermaid-js.github.io/
|
|
3
|
+
Result Markdown can be used in documentation directly (renders automatically)
|
|
4
|
+
|
|
5
|
+
Part 1:
|
|
6
|
+
Source: [diagram-source-part-1.md](diagram-source-part-1.md ':include')
|
|
7
|
+
Result Markdown: [diagram-markdown-part-1.md](diagram-markdown-part-1.md ':include')
|
|
8
|
+
|
|
9
|
+
Part 2:
|
|
10
|
+
Source: [diagram-source-part-2.md](diagram-source-part-2.md ':include')
|
|
11
|
+
Result Markdown: [diagram-markdown-part-2.md](diagram-markdown-part-1.md ':include')
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
NB: Charts are used in [Wiki](https://velocitycareerlabs.visualstudio.com/velocity/_wiki/wikis/velocity.wiki/197/KYC-Integration), in case charts are modified, - Wiki page have to be updated as well
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[](https://mermaid-js.github.io/mermaid-live-editor/edit/##eyJjb2RlIjoic2VxdWVuY2VEaWFncmFtXG5hdXRvbnVtYmVyXG5Ob3RlIGxlZnQgb2YgT3JnYW5pemF0aW9uIFNldHVwOiBQYXJ0IDE6IDxicj4gb3JnYW5pemF0aW9uIHJlZ2lzdHJhdGlvbjxicj4gYW5kIDxicj4gaXNzdWluZyB3ZWJob29rc1xuT3JnYW5pemF0aW9uIFNldHVwLT4-VmVsb2NpdHkgUmVnaXN0YXI6IFJlZ2lzdGVyIE9yZ2FuaXphdGlvblxuT3JnYW5pemF0aW9uIFNldHVwLT4-Q3JlZGVudGlhbCBBZ2VudDogQWRkIGEgVGVuYW50ICh0aGF0IGNvcnJlc3BvbmRzIHRvIHRoYXQgT3JnYW5pemF0aW9uKVxuTm90ZSBsZWZ0IG9mIFlvdGkgSW50ZWdyYXRpb24gU2VydmVyOiBJbXBsZW1lbnQgdGhlIDxicj4yIGlzc3Vpbmcgd2ViaG9va3MgXG5Zb3RpIEludGVncmF0aW9uIFNlcnZlci0tPj5Zb3RpIEludGVncmF0aW9uIFNlcnZlcjogV2ViaG9vayA8YnI-Wy9pc3N1aW5nL2lkZW50aWZ5XVxuWW90aSBJbnRlZ3JhdGlvbiBTZXJ2ZXItLT4-WW90aSBJbnRlZ3JhdGlvbiBTZXJ2ZXI6IFdlYmhvb2sgPGJyPlsvaXNzdWluZy9nZW5lcmF0ZS1vZmZlcnNdXG5cblxuIiwibWVybWFpZCI6IntcbiAgX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
6
|
+
autonumber
|
|
7
|
+
Note left of Organization Setup: Part 1: <br> organization registration<br> and <br> issuing webhooks
|
|
8
|
+
Organization Setup->>Velocity Registar: Register Organization
|
|
9
|
+
Organization Setup->>Credential Agent: Add a Tenant (that corresponds to that Organization)
|
|
10
|
+
Note left of Yoti Integration Server: Implement the <br>2 issuing webhooks
|
|
11
|
+
Yoti Integration Server-->>Yoti Integration Server: Webhook <br>[/issuing/identify]
|
|
12
|
+
Yoti Integration Server-->>Yoti Integration Server: Webhook <br>[/issuing/generate-offers]
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Online editor:
|
|
2
|
+
https://mermaid-js.github.io/mermaid-live-editor/beta/edit/#eyJjb2RlIjoic2VxdWVuY2VEaWFncmFtXG5hdXRvbnVtYmVyXG5wYXJ0aWNpcGFudCBIb2xkZXIgQXBwXG5wYXJ0aWNpcGFudCBDcmVkZW50aWFsIEFnZW50XG5Ob3RlIGxlZnQgb2YgSG9sZGVyIEFwcDogUGFydCAyOiA8YnI-IEhvbGRlciBBcHAgPGJyPiBZb3RpIEtZQyBpc3N1aW5nIGZsb3dcbkhvbGRlciBBcHAgLS0-PiBIb2xkZXIgQXBwIDogVXNlciBzdGFydHMgdGhlPGJyPiBZb3RpIEtZQyBwcm9jZXNzXG5Ib2xkZXIgQXBwIC0-PiBZb3RpIEludGVncmF0aW9uIFNlcnZlciA6IGNhbGwgZW5kcG9pbnQ6IFsvc3RhcnQtc2Vzc2lvbl1cbllvdGkgSW50ZWdyYXRpb24gU2VydmVyIC0-PiBZb3RpJ3MgU2VydmljZXMgOiBbL3N0YXJ0LXNlc3Npb25dXG5Ib2xkZXIgQXBwIC0-PiBDcmVkZW50aWFsIEFnZW50OiBjYWxsIGlkZW50aWZ5IGVuZHBvaW50OiA8YnI-IFsvYXBpL2hvbGRlci92MC42L29yZy97e2RpZH19L2V4Y2hhbmdlXSA8YnI-IGNyZWF0ZXMgYW4gZXhjaGFuZ2UgZG9jdW1lbnQgPGJyPiB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maWVzIHRoZSBhcHBcbkhvbGRlciBBcHAgLS0-PiBIb2xkZXIgQXBwOiBwcm9jZXNzIGNvbXBsZXRlZFxuXG5cbiIsIm1lcm1haWQiOiJ7XG4gIFwidGhlbWVcIjogXCJkZWZhdWx0XCJcbn0iLCJ1cGRhdGVFZGl0b3IiOmZhbHNlLCJhdXRvU3luYyI6dHJ1ZSwidXBkYXRlRGlhZ3JhbSI6ZmFsc2V9
|
|
3
|
+
|
|
4
|
+
Chart source:
|
|
5
|
+
sequenceDiagram
|
|
6
|
+
autonumber
|
|
7
|
+
participant Holder App
|
|
8
|
+
participant Credential Agent
|
|
9
|
+
Note left of Holder App: Part 2: <br> Holder App <br> Yoti KYC issuing flow
|
|
10
|
+
Holder App -->> Holder App : User starts the<br> Yoti KYC process
|
|
11
|
+
Holder App ->> Yoti Integration Server : call endpoint: [/start-session]
|
|
12
|
+
Yoti Integration Server ->> Yoti's Services : [/start-session]
|
|
13
|
+
Holder App ->> Credential Agent: call identify endpoint: <br> [/api/holder/v0.6/org/{{did}}/exchange] <br> creates an exchange document <br> in mongo DB
|
|
14
|
+
Holder App ->> Yoti Integration Server: call endpoint: [/issuing/identify] <br> associates the Yoti session <br> with the exchange
|
|
15
|
+
Holder App ->> Yoti Integration Server: call endpoint: [/issuing/generate-offers]
|
|
16
|
+
Credential Agent -->> Holder App: responds with a code: 202 <br> meaning - request accepted, <br> exchange will be completed at <br> a later point in time via a push;
|
|
17
|
+
Holder App -->> Holder App : User completes the<br> Yoti KYC process
|
|
18
|
+
Yoti's Services -->> Yoti Integration Server: call back about<br> process complete
|
|
19
|
+
Yoti Integration Server ->> Credential Agent: adds an offer <br> to the exchange
|
|
20
|
+
Yoti Integration Server ->> Credential Agent: informs that the exchange <br>should be marked as complete
|
|
21
|
+
Credential Agent ->> Holder App: push notifies the app
|
|
22
|
+
Holder App -->> Holder App: process completed
|
package/src/fetchers.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const submitAddOfferToExchange = (
|
|
2
|
+
{ offer, exchangeId },
|
|
3
|
+
{ agentFetch, config }
|
|
4
|
+
) =>
|
|
5
|
+
agentFetch
|
|
6
|
+
.post(
|
|
7
|
+
`operator-api/v0.8/tenants/${config.idVerificationTenantId}/exchanges/${exchangeId}/offers`,
|
|
8
|
+
{ json: offer }
|
|
9
|
+
)
|
|
10
|
+
.json();
|
|
11
|
+
|
|
12
|
+
const submitCompleteOfferExchange = ({ exchangeId }, { agentFetch, config }) =>
|
|
13
|
+
agentFetch
|
|
14
|
+
.post(
|
|
15
|
+
`operator-api/v0.8/tenants/${config.idVerificationTenantId}/exchanges/${exchangeId}/offers/complete`,
|
|
16
|
+
{ json: { exchangeId } }
|
|
17
|
+
)
|
|
18
|
+
.json();
|
|
19
|
+
|
|
20
|
+
module.exports = {
|
|
21
|
+
submitAddOfferToExchange,
|
|
22
|
+
submitCompleteOfferExchange,
|
|
23
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const IdCredentialTypes = Object.freeze({
|
|
2
|
+
DocumentVerification: 'IdDocument',
|
|
3
|
+
IdDocumentV1v0: 'IdDocumentV1.0',
|
|
4
|
+
DriversLicenseV1v0: 'DriversLicenseV1.0',
|
|
5
|
+
NationalIdV1v0: 'NationalIdCardV1.0',
|
|
6
|
+
PassportV1v0: 'PassportV1.0',
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
module.exports = { IdCredentialTypes };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const idVerifyController = require('./controllers/id-verify/controller');
|
|
2
|
+
const initVerificationSessionsRepo = require('./controllers/id-verify/repo');
|
|
3
|
+
|
|
4
|
+
const yotiIntegrationPlugin = (server) => {
|
|
5
|
+
initVerificationSessionsRepo(server);
|
|
6
|
+
return server
|
|
7
|
+
.autoSchemaPreset({ tags: ['credential_issuer_id'] })
|
|
8
|
+
.register(idVerifyController, {
|
|
9
|
+
prefix: '/id-verify',
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
module.exports = { yotiIntegrationPlugin };
|
package/src/yoti.js
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
const { omit, first, last, size } = require('lodash/fp');
|
|
2
|
+
const { alpha3ToAlpha2 } = require('@velocitycareerlabs/country-data');
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
NotificationConfigBuilder,
|
|
6
|
+
SessionSpecificationBuilder,
|
|
7
|
+
RequestedDocumentAuthenticityCheckBuilder,
|
|
8
|
+
RequestedLivenessCheckBuilder,
|
|
9
|
+
RequestedTextExtractionTaskBuilder,
|
|
10
|
+
RequestedFaceMatchCheckBuilder,
|
|
11
|
+
SdkConfigBuilder,
|
|
12
|
+
} = require('yoti');
|
|
13
|
+
|
|
14
|
+
const { IdCredentialTypes } = require('./id-credential-types');
|
|
15
|
+
|
|
16
|
+
const validCountryCodes = {
|
|
17
|
+
USA: true, // US
|
|
18
|
+
GBR: true, // UK
|
|
19
|
+
ISR: true, // Israel
|
|
20
|
+
AUT: true, // Austria
|
|
21
|
+
BEL: true, // Belgium
|
|
22
|
+
BGR: true, // Bulgaria
|
|
23
|
+
HRV: true, // Croatia
|
|
24
|
+
CYP: true, // Cyprus
|
|
25
|
+
CZE: true, // Czechia
|
|
26
|
+
DNK: true, // Denmark
|
|
27
|
+
EST: true, // Estonia
|
|
28
|
+
FIN: true, // Finland
|
|
29
|
+
FRA: true, // France
|
|
30
|
+
DEU: true, // Germany
|
|
31
|
+
GRC: true, // Greece
|
|
32
|
+
HUN: true, // Hungary
|
|
33
|
+
IRL: true, // Ireland
|
|
34
|
+
ITA: true, // Italy
|
|
35
|
+
LVA: true, // Latvia
|
|
36
|
+
LTU: true, // Lithuania
|
|
37
|
+
LUX: true, // Luxembourg
|
|
38
|
+
MLT: true, // Malta
|
|
39
|
+
NLD: true, // Netherlands
|
|
40
|
+
POL: true, // Poland
|
|
41
|
+
PRT: true, // Portugal
|
|
42
|
+
ROU: true, // Romania
|
|
43
|
+
SVK: true, // Slovakia
|
|
44
|
+
SVN: true, // Slovenia
|
|
45
|
+
ESP: true, // Spain
|
|
46
|
+
SWE: true, // Sweden
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const YotiDocumentTypes = {
|
|
50
|
+
PASSPORT: 'PASSPORT',
|
|
51
|
+
DRIVING_LICENSE: 'DRIVING_LICENCE',
|
|
52
|
+
NATIONAL_ID: 'NATIONAL_ID',
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const isCountryCodeValid = async (countryCode) => {
|
|
56
|
+
// const supportedCountries = await idvClient.getSupportedCountries();
|
|
57
|
+
return !!validCountryCodes[countryCode];
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const fullNameToNameComponents = (fullNameStr) => {
|
|
61
|
+
const middleNames = [];
|
|
62
|
+
const nameParts = fullNameStr.split(' ');
|
|
63
|
+
const givenName = nameParts.slice(0, -1).join(' ');
|
|
64
|
+
const len = size(nameParts);
|
|
65
|
+
const firstName = len ? first(nameParts) : '';
|
|
66
|
+
const lastName = len ? last(nameParts) : '';
|
|
67
|
+
return { firstName, lastName, middleNames, givenName };
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const buildYotiNotificationEndpoint = ({ config }) => {
|
|
71
|
+
const { hostUrl, yotiNotificationsWebhookRelativePath, isTest } = config;
|
|
72
|
+
const idVerifyPrefix = '/id-verify';
|
|
73
|
+
const urlObj = new URL(
|
|
74
|
+
`${hostUrl}${idVerifyPrefix}${yotiNotificationsWebhookRelativePath}`
|
|
75
|
+
);
|
|
76
|
+
if (isTest) {
|
|
77
|
+
// eslint-disable-next-line better-mutation/no-mutation
|
|
78
|
+
urlObj.protocol = 'https';
|
|
79
|
+
}
|
|
80
|
+
return urlObj.href;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const yotiCheckTointernalYotiCheck = (check) => {
|
|
84
|
+
return { ...omit(['id'], check), yotiId: check.id };
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
const getIdDocument = async (session, idvClient) => {
|
|
88
|
+
const resources = session.getResources();
|
|
89
|
+
const yotiDocuments = resources.getIdDocuments();
|
|
90
|
+
return yotiDocumentToIdDocument(session, first(yotiDocuments), idvClient);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const yotiDocumentToIdDocument = async (session, yotiDocument, idvClient) => {
|
|
94
|
+
const documentType = yotiDocument.getDocumentType();
|
|
95
|
+
// const issuingCountry = yotiDocument.getIssuingCountry();
|
|
96
|
+
const documentFields = yotiDocument.getDocumentFields();
|
|
97
|
+
let documentFieldsMediaId = null;
|
|
98
|
+
if (documentFields) {
|
|
99
|
+
documentFieldsMediaId = documentFields.getMedia().getId();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const media = await idvClient.getMediaContent(
|
|
103
|
+
session.getSessionId(),
|
|
104
|
+
`${documentFieldsMediaId}`
|
|
105
|
+
);
|
|
106
|
+
const buffer = media.getContent();
|
|
107
|
+
return buildCredential(documentType, JSON.parse(buffer));
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const buildPassportAuthority = (baseCredential) => {
|
|
111
|
+
if (baseCredential.authority == null) {
|
|
112
|
+
return {
|
|
113
|
+
authority: {
|
|
114
|
+
name: 'Passport',
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
if (baseCredential.authority.name === '-') {
|
|
119
|
+
return {
|
|
120
|
+
authority: {
|
|
121
|
+
...baseCredential.authority,
|
|
122
|
+
name: 'Passport',
|
|
123
|
+
},
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
authority: baseCredential.authority,
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
const buildCredential = (documentType, data) => {
|
|
131
|
+
const baseCredential = buildBaseCredential(data);
|
|
132
|
+
switch (documentType) {
|
|
133
|
+
case YotiDocumentTypes.PASSPORT:
|
|
134
|
+
return {
|
|
135
|
+
credential: {
|
|
136
|
+
documentCode: 'P',
|
|
137
|
+
...baseCredential,
|
|
138
|
+
...buildPassportAuthority(baseCredential),
|
|
139
|
+
},
|
|
140
|
+
credentialType: IdCredentialTypes.PassportV1v0,
|
|
141
|
+
};
|
|
142
|
+
case YotiDocumentTypes.NATIONAL_ID:
|
|
143
|
+
return {
|
|
144
|
+
credential: baseCredential,
|
|
145
|
+
credentialType: IdCredentialTypes.NationalIdV1v0,
|
|
146
|
+
};
|
|
147
|
+
case YotiDocumentTypes.DRIVING_LICENSE:
|
|
148
|
+
return {
|
|
149
|
+
credential: {
|
|
150
|
+
name: data.organisation,
|
|
151
|
+
...baseCredential,
|
|
152
|
+
},
|
|
153
|
+
credentialType: IdCredentialTypes.DriversLicenseV1v0,
|
|
154
|
+
};
|
|
155
|
+
default:
|
|
156
|
+
return {
|
|
157
|
+
credential: {
|
|
158
|
+
documentType,
|
|
159
|
+
...baseCredential,
|
|
160
|
+
},
|
|
161
|
+
credentialType: IdCredentialTypes.IdDocumentV1v0,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const valueOrFallBack = (value, fallback = '-') => value ?? fallback;
|
|
167
|
+
const buildAuthority = (issuingAuthority, issuingCountry) => {
|
|
168
|
+
if (!issuingAuthority && !issuingCountry) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
if (issuingAuthority && !issuingCountry) {
|
|
172
|
+
return {
|
|
173
|
+
name: valueOrFallBack(issuingAuthority),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
const twoLetterIssuingCountry = alpha3ToAlpha2(issuingCountry);
|
|
177
|
+
return {
|
|
178
|
+
name: valueOrFallBack(issuingAuthority),
|
|
179
|
+
place: {
|
|
180
|
+
addressCountry: valueOrFallBack(twoLetterIssuingCountry),
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
const buildBaseCredential = (data) => {
|
|
185
|
+
const {
|
|
186
|
+
full_name: fullName,
|
|
187
|
+
first_name: firstName,
|
|
188
|
+
middle_name: middleName,
|
|
189
|
+
family_name: familyName,
|
|
190
|
+
date_of_birth: dateOfBirth,
|
|
191
|
+
document_number: documentNumber,
|
|
192
|
+
issuing_country: issuingCountry,
|
|
193
|
+
issuing_authority: issuingAuthority,
|
|
194
|
+
date_of_issue: dateOfIssue,
|
|
195
|
+
expiration_date: expirationDate,
|
|
196
|
+
} = data;
|
|
197
|
+
const nameComponents = fullNameToNameComponents(fullName);
|
|
198
|
+
return {
|
|
199
|
+
identifier: documentNumber,
|
|
200
|
+
person: {
|
|
201
|
+
givenName: firstName || nameComponents.firstName,
|
|
202
|
+
middleName: middleName || nameComponents.middleName,
|
|
203
|
+
familyName: familyName || nameComponents.lastName,
|
|
204
|
+
birthDate: dateOfBirth,
|
|
205
|
+
},
|
|
206
|
+
validity: {
|
|
207
|
+
firstValidFrom: dateOfIssue,
|
|
208
|
+
validUntil: expirationDate,
|
|
209
|
+
},
|
|
210
|
+
authority: buildAuthority(issuingAuthority, issuingCountry),
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const convertFromBasicAuth = (str) =>
|
|
215
|
+
Buffer.from(str, 'base64').toString('binary');
|
|
216
|
+
|
|
217
|
+
const createSessionSpec = ({ verifierAuthToken, countryCode }, { config }) => {
|
|
218
|
+
// Document Authenticity Check
|
|
219
|
+
const documentAuthenticityCheck =
|
|
220
|
+
new RequestedDocumentAuthenticityCheckBuilder().build();
|
|
221
|
+
|
|
222
|
+
const livenessCheck = new RequestedLivenessCheckBuilder()
|
|
223
|
+
.forStaticLiveness()
|
|
224
|
+
.build();
|
|
225
|
+
|
|
226
|
+
const faceMatchCheck = new RequestedFaceMatchCheckBuilder()
|
|
227
|
+
.withManualCheckFallback()
|
|
228
|
+
.build();
|
|
229
|
+
|
|
230
|
+
const textExtractionTask = new RequestedTextExtractionTaskBuilder()
|
|
231
|
+
.withManualCheckFallback()
|
|
232
|
+
.build();
|
|
233
|
+
|
|
234
|
+
const sdkConfig = new SdkConfigBuilder()
|
|
235
|
+
.withAllowsCameraAndUpload()
|
|
236
|
+
.withPresetIssuingCountry(countryCode)
|
|
237
|
+
.build();
|
|
238
|
+
|
|
239
|
+
const notificationEndpoint = buildYotiNotificationEndpoint({ config });
|
|
240
|
+
const notificationConfig = new NotificationConfigBuilder()
|
|
241
|
+
.withEndpoint(notificationEndpoint)
|
|
242
|
+
.withAuthToken(verifierAuthToken)
|
|
243
|
+
.withAuthTypeBearer() // .forResourceUpdate()
|
|
244
|
+
// .forTaskCompletion()
|
|
245
|
+
// .forCheckCompletion()
|
|
246
|
+
.forSessionCompletion()
|
|
247
|
+
.build();
|
|
248
|
+
|
|
249
|
+
return (
|
|
250
|
+
new SessionSpecificationBuilder()
|
|
251
|
+
.withClientSessionTokenTtl(config.yotiSessionTtl)
|
|
252
|
+
.withResourcesTtl(config.yotiResourceRetentionTtl)
|
|
253
|
+
// .withUserTrackingId('some-user-tracking-id')
|
|
254
|
+
.withRequestedCheck(documentAuthenticityCheck)
|
|
255
|
+
.withRequestedCheck(livenessCheck)
|
|
256
|
+
.withRequestedCheck(faceMatchCheck)
|
|
257
|
+
.withRequestedTask(textExtractionTask)
|
|
258
|
+
.withSdkConfig(sdkConfig)
|
|
259
|
+
.withNotifications(notificationConfig)
|
|
260
|
+
.build()
|
|
261
|
+
);
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
module.exports = {
|
|
265
|
+
buildYotiNotificationEndpoint,
|
|
266
|
+
convertFromBasicAuth,
|
|
267
|
+
createSessionSpec,
|
|
268
|
+
fullNameToNameComponents,
|
|
269
|
+
getIdDocument,
|
|
270
|
+
isCountryCodeValid,
|
|
271
|
+
yotiCheckTointernalYotiCheck,
|
|
272
|
+
buildCredential,
|
|
273
|
+
};
|