@verii/verii-verification 1.0.0-pre.1754543687
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 +119 -0
- package/index.js +23 -0
- package/package.json +55 -0
- package/src/build-failed-check-result-error.js +93 -0
- package/src/constants.js +38 -0
- package/src/get-issuer-info.js +21 -0
- package/src/validate-presentation-context.js +40 -0
- package/src/verify-credentials.js +404 -0
- package/src/verify-presentation-jwt.js +41 -0
- package/src/verify-verii-credentials.js +47 -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
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# Verii Verification Library
|
|
2
|
+
|
|
3
|
+
The Verii Verification Library provides utility functions for verifying Verifiable Credentials (VCs) and Verifiable Presentations (VPs) according to the Verii and Velocity Network specifications. It includes logic for cryptographic validation, protocol version support, and key resolution via DIDs.
|
|
4
|
+
|
|
5
|
+
## 📦 Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @velocitycareerlabs/verii-verification
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## 🚀 Main Entry Points
|
|
12
|
+
|
|
13
|
+
### 1. `verifyCredentials`
|
|
14
|
+
|
|
15
|
+
Verifies one or more Verifiable Credentials (VCs) in JWT format.
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { verifyCredentials } from '@velocitycareerlabs/verii-verification';
|
|
19
|
+
|
|
20
|
+
const credentials = [
|
|
21
|
+
"eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9...", // JWT-encoded Verifiable Credential
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
// The KMS abstraction requires a exportKeyOrSecret function
|
|
25
|
+
const kms = {
|
|
26
|
+
exportKeyOrSecret(keyId) {
|
|
27
|
+
// ... exports the private key from the kms
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
async function authenticator () {
|
|
32
|
+
const token = authenticate()// Fetch an access token from an OAuth provider using the client_credential grant type
|
|
33
|
+
return token
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const config = {
|
|
37
|
+
rootPublicKey: "0x899ef1cc48d17ee2701b25b14203d45e15bb01d07767450e9191ea71760d558a", // TRUST Root Private key
|
|
38
|
+
revocationContractAddress: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e", // DLT address for revocation address
|
|
39
|
+
metadataRegistryContractAddress: "0x3f5CE5FBFe3E9af3971dD833D26BA9b5C936f0bE", // DLT address for VC metadata
|
|
40
|
+
rpcProvider: initProvider("http://localhost:8545", authenticator),
|
|
41
|
+
registrarUrl: "https://registrar.velocitynetwork.foundation",
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const context = {
|
|
45
|
+
kms,
|
|
46
|
+
log, // a logger that exposes a pino logger
|
|
47
|
+
config,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const verified = await verifyVeriiCredentials(
|
|
51
|
+
{
|
|
52
|
+
credentials,
|
|
53
|
+
expectedHolderDid: "did:jwk:eyJrdHkiOiJFQyIsInVzZSI6InNpZyIsImNydiI6I...",
|
|
54
|
+
relyingParty: { did: "did:web:example.com", dltOperatorKMSKeyId: "df9c4f12-3d79-4ab6-88ef-91b4eae45eaf" },
|
|
55
|
+
},
|
|
56
|
+
context
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
console.log(verified);
|
|
60
|
+
// [
|
|
61
|
+
// {
|
|
62
|
+
// credential:
|
|
63
|
+
// {
|
|
64
|
+
// ... // The jwt's `payload.vc` value (ie. the unsigned jsonld representation of the VC)
|
|
65
|
+
// },
|
|
66
|
+
// credentialChecks: {
|
|
67
|
+
// UNTAMPERED: 'PASS',
|
|
68
|
+
// TRUSTED_ISSUER: 'PASS',
|
|
69
|
+
// TRUSTED_HOLDER: 'PASS',
|
|
70
|
+
// UNEXPIRED: 'PASS',
|
|
71
|
+
// UNREVOKED: 'PASS'
|
|
72
|
+
// }
|
|
73
|
+
// },
|
|
74
|
+
// ...
|
|
75
|
+
// ]
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 2. `verifyVerifiablePresentationJwt`
|
|
79
|
+
|
|
80
|
+
Verifies a Verifiable Presentation (VP) in JWT format, optionally using protocol-aware key resolution. Returns the
|
|
81
|
+
unsigned VP.
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { verifyVerifiablePresentationJwt } from '@velocitycareerlabs/verii-verification';
|
|
85
|
+
|
|
86
|
+
const vpJwt = "eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9...";
|
|
87
|
+
|
|
88
|
+
const result = await verifyVerifiablePresentationJwt(vpJwt, {
|
|
89
|
+
vnfProtocolVersion: 2
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
console.log(result);
|
|
93
|
+
// {
|
|
94
|
+
// ... // returns the JWT's payload.vp claim (ie. the unsigned jsonld representation of the VP)
|
|
95
|
+
// }
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## 🛠 Dependencies
|
|
99
|
+
|
|
100
|
+
- DID resolution via `@verii/did-doc`
|
|
101
|
+
- JWT operations via `@verii/jwt`
|
|
102
|
+
- Verii protocol version constants from `@verii/vc-checks`
|
|
103
|
+
|
|
104
|
+
### Peer Dependencies
|
|
105
|
+
- Pino logger from https://github.com/pinojs/pino
|
|
106
|
+
|
|
107
|
+
## 🧪 Error Handling
|
|
108
|
+
|
|
109
|
+
Malformed or unverifiable inputs will throw `http-errors` with structured metadata:
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
throw createError(400, "Malformed jwt_vp property", {
|
|
113
|
+
errorCode: 'presentation_malformed',
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## 📘 License
|
|
118
|
+
|
|
119
|
+
Licensed under the Apache 2.0 License. See [LICENSE](./LICENSE) for details.
|
package/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
...require('./src/verify-credentials'),
|
|
19
|
+
...require('./src/build-failed-check-result-error'),
|
|
20
|
+
...require('./src/constants'),
|
|
21
|
+
...require('./src/verify-presentation-jwt'),
|
|
22
|
+
...require('./src/validate-presentation-context'),
|
|
23
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@verii/verii-verification",
|
|
3
|
+
"version": "1.0.0-pre.1754543687",
|
|
4
|
+
"description": "Verii VC and VP Verification library ",
|
|
5
|
+
"repository": "https://github.com/LFDT-Verii/core",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "jest --config ./jest.config.js --runInBand --coverage",
|
|
12
|
+
"lint": "eslint . --format json >> eslint.json",
|
|
13
|
+
"lint:fix": "eslint --fix --ext .js ."
|
|
14
|
+
},
|
|
15
|
+
"author": "Yauheni Pozdnyakov",
|
|
16
|
+
"license": "Apache-2.0",
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"@verii/common-fetchers": "1.0.0-pre.1754543687",
|
|
19
|
+
"@verii/common-functions": "1.0.0-pre.1754543687",
|
|
20
|
+
"@verii/did-doc": "1.0.0-pre.1754543687",
|
|
21
|
+
"@verii/http-client": "1.0.0-pre.1754543687",
|
|
22
|
+
"@verii/jwt": "1.0.0-pre.1754543687",
|
|
23
|
+
"@verii/metadata-registration": "1.0.0-pre.1754543687",
|
|
24
|
+
"@verii/vc-checks": "1.0.0-pre.1754543687",
|
|
25
|
+
"http-errors": "^2.0.0",
|
|
26
|
+
"lodash": "^4.17.21"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@verii/crypto": "1.0.0-pre.1754543687",
|
|
30
|
+
"@verii/sample-data": "1.0.0-pre.1754543687",
|
|
31
|
+
"@verii/test-regexes": "1.0.0-pre.1754543687",
|
|
32
|
+
"@verii/tests-helpers": "1.0.0-pre.1754543687",
|
|
33
|
+
"date-fns": "3.6.0",
|
|
34
|
+
"eslint": "8.57.1",
|
|
35
|
+
"eslint-config-airbnb-base": "14.2.1",
|
|
36
|
+
"eslint-config-prettier": "8.10.2",
|
|
37
|
+
"eslint-plugin-autofix": "1.1.0",
|
|
38
|
+
"eslint-plugin-better-mutation": "1.7.0",
|
|
39
|
+
"eslint-plugin-import": "2.32.0",
|
|
40
|
+
"eslint-plugin-prefer-arrow-functions": "3.6.2",
|
|
41
|
+
"eslint-plugin-prettier": "4.2.5",
|
|
42
|
+
"eslint-watch": "7.0.0",
|
|
43
|
+
"jest": "29.7.0",
|
|
44
|
+
"nanoid": "3.3.11",
|
|
45
|
+
"nock": "15.0.0-beta.5",
|
|
46
|
+
"prettier": "2.8.8",
|
|
47
|
+
"undici": "^7.0.0"
|
|
48
|
+
},
|
|
49
|
+
"nx": {
|
|
50
|
+
"tags": [
|
|
51
|
+
"lib"
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
"gitHead": "8e7d25a089f4398a2d754426613e56100dc2d29c"
|
|
55
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const newError = require('http-errors');
|
|
19
|
+
const { CredentialCheckResultValue } = require('./constants');
|
|
20
|
+
|
|
21
|
+
const checkFailedMessage = (reason, id, value) =>
|
|
22
|
+
`${reason} credential check failed for credential ${id}. Was '${value}', expected 'PASS'`;
|
|
23
|
+
|
|
24
|
+
const buildFailedCheckResultError = (
|
|
25
|
+
{ credential, credentialChecks },
|
|
26
|
+
{ log }
|
|
27
|
+
) => {
|
|
28
|
+
if (credentialChecks.UNTAMPERED !== CredentialCheckResultValue.PASS) {
|
|
29
|
+
log.error(
|
|
30
|
+
checkFailedMessage('tampered', credential.id, credentialChecks.UNTAMPERED)
|
|
31
|
+
);
|
|
32
|
+
return newError(401, 'presentation_credential_tampered', {
|
|
33
|
+
errorCode: 'presentation_credential_failed_tampered',
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (credentialChecks.TRUSTED_ISSUER !== CredentialCheckResultValue.PASS) {
|
|
37
|
+
log.error(
|
|
38
|
+
checkFailedMessage(
|
|
39
|
+
'trusted_issuer',
|
|
40
|
+
credential.id,
|
|
41
|
+
credentialChecks.TRUSTED_ISSUER
|
|
42
|
+
)
|
|
43
|
+
);
|
|
44
|
+
return newError(401, 'presentation_credential_bad_issuer', {
|
|
45
|
+
errorCode: 'presentation_credential_bad_issuer',
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (credentialChecks.UNREVOKED !== CredentialCheckResultValue.PASS) {
|
|
49
|
+
log.error(
|
|
50
|
+
checkFailedMessage('revoked', credential.id, credentialChecks.UNREVOKED)
|
|
51
|
+
);
|
|
52
|
+
return newError(401, 'presentation_credential_revoked', {
|
|
53
|
+
errorCode: 'presentation_credential_revoked',
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
if (
|
|
57
|
+
![
|
|
58
|
+
CredentialCheckResultValue.PASS,
|
|
59
|
+
CredentialCheckResultValue.NOT_APPLICABLE,
|
|
60
|
+
].includes(credentialChecks.UNEXPIRED)
|
|
61
|
+
) {
|
|
62
|
+
log.error(
|
|
63
|
+
checkFailedMessage('expired', credential.id, credentialChecks.UNEXPIRED, [
|
|
64
|
+
CredentialCheckResultValue.NOT_APPLICABLE,
|
|
65
|
+
])
|
|
66
|
+
);
|
|
67
|
+
return newError(401, 'presentation_credential_expired', {
|
|
68
|
+
errorCode: 'presentation_credential_expired',
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (
|
|
72
|
+
![
|
|
73
|
+
CredentialCheckResultValue.PASS,
|
|
74
|
+
CredentialCheckResultValue.NOT_APPLICABLE,
|
|
75
|
+
].includes(credentialChecks.TRUSTED_HOLDER)
|
|
76
|
+
) {
|
|
77
|
+
log.error(
|
|
78
|
+
checkFailedMessage(
|
|
79
|
+
'trusted_holder',
|
|
80
|
+
credential.id,
|
|
81
|
+
credentialChecks.TRUSTED_HOLDER,
|
|
82
|
+
[CredentialCheckResultValue.NOT_APPLICABLE]
|
|
83
|
+
)
|
|
84
|
+
);
|
|
85
|
+
return newError(401, 'presentation_credential_bad_holder', {
|
|
86
|
+
errorCode: 'presentation_credential_bad_holder',
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return undefined;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
module.exports = { buildFailedCheckResultError };
|
package/src/constants.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const VerifiableCredentialTypes = {
|
|
18
|
+
BASIC_PROFILE_V1_0: 'OrganizationBasicProfile-v1.0',
|
|
19
|
+
VERIFIABLE_CREDENTIAL: 'VerifiableCredential',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const VerifiableCredentialFormats = {
|
|
23
|
+
JWT_VC: 'jwt_vc',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const CredentialCheckResultValue = {
|
|
27
|
+
PASS: 'PASS',
|
|
28
|
+
FAIL: 'FAIL',
|
|
29
|
+
NOT_CHECKED: 'NOT_CHECKED',
|
|
30
|
+
SELF_SIGNED: 'SELF_SIGNED',
|
|
31
|
+
NOT_APPLICABLE: 'NOT_APPLICABLE',
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
module.exports = {
|
|
35
|
+
VerifiableCredentialTypes,
|
|
36
|
+
VerifiableCredentialFormats,
|
|
37
|
+
CredentialCheckResultValue,
|
|
38
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const { jwtDecode } = require('@verii/jwt');
|
|
2
|
+
|
|
3
|
+
const getIssuerInfo = async (
|
|
4
|
+
issuerVc,
|
|
5
|
+
{ resolveKid, getOrganizationVerifiedProfile },
|
|
6
|
+
context
|
|
7
|
+
) => {
|
|
8
|
+
const { header, payload } = jwtDecode(issuerVc);
|
|
9
|
+
const issuerPublicKey = await resolveKid({ kid: header.kid }, context);
|
|
10
|
+
const organizationVerifiedProfile = await getOrganizationVerifiedProfile(
|
|
11
|
+
payload.iss,
|
|
12
|
+
context
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
return {
|
|
16
|
+
issuerPublicKey,
|
|
17
|
+
organizationVerifiedProfile,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
module.exports = { getIssuerInfo };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const { castArray, includes } = require('lodash/fp');
|
|
18
|
+
const newError = require('http-errors');
|
|
19
|
+
|
|
20
|
+
const validatePresentationContext = (
|
|
21
|
+
presentation,
|
|
22
|
+
{
|
|
23
|
+
config: {
|
|
24
|
+
enablePresentationContextValidation,
|
|
25
|
+
presentationContextValue: expectedValue,
|
|
26
|
+
},
|
|
27
|
+
}
|
|
28
|
+
) => {
|
|
29
|
+
if (!enablePresentationContextValidation) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!includes(expectedValue, castArray(presentation?.['@context']))) {
|
|
34
|
+
throw newError(400, 'presentation @context is not set correctly', {
|
|
35
|
+
errorCode: 'presentation_invalid',
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
module.exports = { validatePresentationContext };
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
const {
|
|
17
|
+
filter,
|
|
18
|
+
find,
|
|
19
|
+
first,
|
|
20
|
+
flow,
|
|
21
|
+
isArray,
|
|
22
|
+
isEmpty,
|
|
23
|
+
join,
|
|
24
|
+
keyBy,
|
|
25
|
+
map,
|
|
26
|
+
partition,
|
|
27
|
+
reduce,
|
|
28
|
+
size,
|
|
29
|
+
some,
|
|
30
|
+
startsWith,
|
|
31
|
+
toLower,
|
|
32
|
+
uniq,
|
|
33
|
+
} = require('lodash/fp');
|
|
34
|
+
const { buildDecodedCredential, jwtDecode, hexFromJwk } = require('@verii/jwt');
|
|
35
|
+
const {
|
|
36
|
+
initMetadataRegistry,
|
|
37
|
+
initVerificationCoupon,
|
|
38
|
+
initRevocationRegistry,
|
|
39
|
+
} = require('@verii/metadata-registration');
|
|
40
|
+
const {
|
|
41
|
+
CheckResults,
|
|
42
|
+
CredentialStatus,
|
|
43
|
+
checkExpiration,
|
|
44
|
+
checkJwtVCTampering,
|
|
45
|
+
checkCredentialStatus,
|
|
46
|
+
checkIssuerTrust,
|
|
47
|
+
checkHolder,
|
|
48
|
+
extractCredentialType,
|
|
49
|
+
VelocityRevocationListType,
|
|
50
|
+
} = require('@verii/vc-checks');
|
|
51
|
+
const { mapWithIndex } = require('@verii/common-functions');
|
|
52
|
+
const { resolveDidJwkDocument, toDidUrl } = require('@verii/did-doc');
|
|
53
|
+
|
|
54
|
+
const verifyCredentials = async (
|
|
55
|
+
{ credentials: jwtVcs, expectedHolderDid, relyingParty },
|
|
56
|
+
fetchers,
|
|
57
|
+
context
|
|
58
|
+
) => {
|
|
59
|
+
const credentialDataList = mapWithIndex(buildCredentialDataFromJwtVc, jwtVcs);
|
|
60
|
+
|
|
61
|
+
const [keyRefs, issuerRefs, credentialStatusRefs] = await Promise.all([
|
|
62
|
+
resolveKeyRefs(credentialDataList, relyingParty, context),
|
|
63
|
+
resolveIssuerMetadata(credentialDataList, fetchers, context),
|
|
64
|
+
resolveCredentialStatuses(credentialDataList, context),
|
|
65
|
+
]);
|
|
66
|
+
|
|
67
|
+
return Promise.all(
|
|
68
|
+
map(async (data) => {
|
|
69
|
+
const tamperingCheck = await runTamperingCheck(data, keyRefs, context);
|
|
70
|
+
if (tamperingCheck !== CheckResults.PASS) {
|
|
71
|
+
return {
|
|
72
|
+
credentialChecks: tamperErrorCheckResults(tamperingCheck),
|
|
73
|
+
credential: data.credential,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const credentialChecks = {
|
|
78
|
+
UNTAMPERED: CheckResults.PASS,
|
|
79
|
+
TRUSTED_ISSUER: await runIssuerTrustCheck(
|
|
80
|
+
data,
|
|
81
|
+
{
|
|
82
|
+
boundIssuerVcsMap: keyRefs.boundIssuerVcsMap,
|
|
83
|
+
...issuerRefs,
|
|
84
|
+
},
|
|
85
|
+
context
|
|
86
|
+
),
|
|
87
|
+
TRUSTED_HOLDER: checkHolder(
|
|
88
|
+
data.credential,
|
|
89
|
+
expectedHolderDid,
|
|
90
|
+
context
|
|
91
|
+
),
|
|
92
|
+
UNREVOKED: runCredentialStatusCheck(data, credentialStatusRefs),
|
|
93
|
+
UNEXPIRED: checkExpiration(data.credential),
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
return { credentialChecks, credential: data.credential };
|
|
97
|
+
}, credentialDataList)
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const buildCredentialDataFromJwtVc = (jwtVc, index) => {
|
|
102
|
+
const { header, payload } = jwtDecode(jwtVc);
|
|
103
|
+
return {
|
|
104
|
+
id: payload.jti,
|
|
105
|
+
index,
|
|
106
|
+
credentialType: extractCredentialType(payload.vc),
|
|
107
|
+
contentHash: payload.vc.contentHash?.value,
|
|
108
|
+
issuerId: payload.iss,
|
|
109
|
+
keyMetadata: header,
|
|
110
|
+
jwtVc,
|
|
111
|
+
credential: buildDecodedCredential(payload),
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const isIssuerTheSubject = (header) => !isDidVelocityCredential(header);
|
|
116
|
+
const isDidVelocityCredential = ({ kid }) => startsWith('did:velocity:', kid);
|
|
117
|
+
|
|
118
|
+
const resolveKeyRefs = async (credentialDataList, relyingParty, context) => {
|
|
119
|
+
const [velocityCredentialDataList, otherCredentialDataList] = flow(
|
|
120
|
+
filter(({ keyMetadata }) => keyMetadata.kid != null),
|
|
121
|
+
partition(({ keyMetadata }) => isDidVelocityCredential(keyMetadata))
|
|
122
|
+
)(credentialDataList);
|
|
123
|
+
|
|
124
|
+
const resolutions = await Promise.all([
|
|
125
|
+
resolveVelocityDidDocument(
|
|
126
|
+
velocityCredentialDataList,
|
|
127
|
+
relyingParty,
|
|
128
|
+
context
|
|
129
|
+
),
|
|
130
|
+
...map(
|
|
131
|
+
(credentialData) => resolveOtherDidDocument(credentialData, context),
|
|
132
|
+
otherCredentialDataList
|
|
133
|
+
),
|
|
134
|
+
]);
|
|
135
|
+
|
|
136
|
+
const keyMap = reduce(
|
|
137
|
+
(acc, { didDocument }) => {
|
|
138
|
+
const keys =
|
|
139
|
+
didDocument?.verificationMethod ?? didDocument?.publicKey ?? [];
|
|
140
|
+
for (const key of keys) {
|
|
141
|
+
acc[toLower(toDidUrl(didDocument.id, key.id))] = key;
|
|
142
|
+
}
|
|
143
|
+
return acc;
|
|
144
|
+
},
|
|
145
|
+
{},
|
|
146
|
+
resolutions
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
const boundIssuerVcsMap = keyBy(
|
|
150
|
+
({ id }) => toLower(id),
|
|
151
|
+
first(resolutions)?.didDocumentMetadata?.boundIssuerVcs
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
keyMap,
|
|
156
|
+
boundIssuerVcsMap,
|
|
157
|
+
errors: flow(map('errors'), find(size))(resolutions),
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const resolveVelocityDidDocument = async (
|
|
162
|
+
credentialData,
|
|
163
|
+
relyingParty,
|
|
164
|
+
context
|
|
165
|
+
) => {
|
|
166
|
+
if (isEmpty(credentialData)) {
|
|
167
|
+
return {};
|
|
168
|
+
}
|
|
169
|
+
const { config, kms, rpcProvider, log } = context;
|
|
170
|
+
|
|
171
|
+
// eslint-disable-next-line prefer-destructuring
|
|
172
|
+
let dltPrivateKey = relyingParty.dltPrivateKey;
|
|
173
|
+
if (dltPrivateKey == null) {
|
|
174
|
+
const { privateJwk: dltJwk } = await kms.exportKeyOrSecret(
|
|
175
|
+
relyingParty.dltOperatorKMSKeyId
|
|
176
|
+
);
|
|
177
|
+
dltPrivateKey = hexFromJwk(dltJwk);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const metadataRegistry = await initMetadataRegistry(
|
|
181
|
+
{
|
|
182
|
+
contractAddress: config.metadataRegistryContractAddress,
|
|
183
|
+
privateKey: dltPrivateKey,
|
|
184
|
+
rpcProvider,
|
|
185
|
+
},
|
|
186
|
+
context
|
|
187
|
+
);
|
|
188
|
+
const verificationCoupon = await initVerificationCoupon(
|
|
189
|
+
{
|
|
190
|
+
contractAddress: config.couponContractAddress,
|
|
191
|
+
privateKey: dltPrivateKey,
|
|
192
|
+
rpcProvider,
|
|
193
|
+
},
|
|
194
|
+
context
|
|
195
|
+
);
|
|
196
|
+
try {
|
|
197
|
+
const multiDid = `did:velocity:v2:multi:${flow(
|
|
198
|
+
map(({ id }) => id.split(':v2:')[1]),
|
|
199
|
+
join(';')
|
|
200
|
+
)(credentialData)}`;
|
|
201
|
+
|
|
202
|
+
const { didDocument, didDocumentMetadata, didResolutionMetadata } =
|
|
203
|
+
await metadataRegistry.resolveDidDocument({
|
|
204
|
+
did: multiDid,
|
|
205
|
+
verificationCoupon,
|
|
206
|
+
credentials: credentialData,
|
|
207
|
+
burnerDid: context.tenant.did,
|
|
208
|
+
caoDid: context.caoDid,
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
log.info(
|
|
212
|
+
{ didDocument, didDocumentMetadata, didResolutionMetadata },
|
|
213
|
+
'did:velocity doc resolved'
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
return { didDocument, didDocumentMetadata };
|
|
217
|
+
} catch (err) {
|
|
218
|
+
if (err.reason === 'No available tokens') {
|
|
219
|
+
log.warn({ err });
|
|
220
|
+
return { errors: { vouchersExhausted: true } };
|
|
221
|
+
}
|
|
222
|
+
log.error({ err });
|
|
223
|
+
return { errors: { keyResolutionError: true } };
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const resolveOtherDidDocument = async ({ keyMetadata }, { log }) => {
|
|
228
|
+
try {
|
|
229
|
+
const didDocument = await resolveDidJwkDocument(keyMetadata.kid);
|
|
230
|
+
return { didDocument };
|
|
231
|
+
} catch (err) {
|
|
232
|
+
log.error({ keyMetadata }, 'did method not supported');
|
|
233
|
+
return { errors: { keyResolutionError: true } };
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const resolveIssuerMetadata = async (credentialData, fetchers, context) => {
|
|
238
|
+
try {
|
|
239
|
+
const issuerIds = flow(map('issuerId'), uniq)(credentialData);
|
|
240
|
+
const credentialTypes = flow(map('credentialType'), uniq)(credentialData);
|
|
241
|
+
|
|
242
|
+
const [accreditationVCs, issuerDidDocuments, credentialTypeMetadatas] =
|
|
243
|
+
await Promise.all([
|
|
244
|
+
Promise.all(
|
|
245
|
+
map(
|
|
246
|
+
(issuerId) =>
|
|
247
|
+
fetchers
|
|
248
|
+
.getOrganizationVerifiedProfile(issuerId, context)
|
|
249
|
+
.catch(() => {}),
|
|
250
|
+
issuerIds
|
|
251
|
+
)
|
|
252
|
+
),
|
|
253
|
+
Promise.all(
|
|
254
|
+
map(
|
|
255
|
+
(issuerId) =>
|
|
256
|
+
fetchers.resolveDid(issuerId, context).catch(() => {}),
|
|
257
|
+
issuerIds
|
|
258
|
+
)
|
|
259
|
+
),
|
|
260
|
+
fetchers.getCredentialTypeMetadata(credentialTypes, context),
|
|
261
|
+
]);
|
|
262
|
+
|
|
263
|
+
return {
|
|
264
|
+
accreditationVCMap: keyBy('credentialSubject.id', accreditationVCs),
|
|
265
|
+
issuerDidDocumentMap: keyBy('id', issuerDidDocuments),
|
|
266
|
+
credentialTypeMetadatasMap: keyBy(
|
|
267
|
+
'credentialType',
|
|
268
|
+
credentialTypeMetadatas
|
|
269
|
+
),
|
|
270
|
+
};
|
|
271
|
+
} catch (error) {
|
|
272
|
+
context.log.error(error);
|
|
273
|
+
return { errors: { metadataRetrievalError: true } };
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const resolveCredentialStatuses = async (credentialData, context) => {
|
|
278
|
+
try {
|
|
279
|
+
const resolveCredentialStatus = await initResolveCredentialStatus(context);
|
|
280
|
+
const credentialStatuses = await Promise.all(
|
|
281
|
+
map(
|
|
282
|
+
({ credential }) =>
|
|
283
|
+
resolveCredentialStatus(credential.credentialStatus),
|
|
284
|
+
credentialData
|
|
285
|
+
)
|
|
286
|
+
);
|
|
287
|
+
return { credentialStatuses };
|
|
288
|
+
} catch {
|
|
289
|
+
return { errors: { credentialStatusRetrievalError: true } };
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const initResolveCredentialStatus = async (context) => {
|
|
294
|
+
const {
|
|
295
|
+
config: { revocationContractAddress },
|
|
296
|
+
rpcProvider,
|
|
297
|
+
log,
|
|
298
|
+
} = context;
|
|
299
|
+
|
|
300
|
+
const { getRevokedStatus } = await initRevocationRegistry(
|
|
301
|
+
{ contractAddress: revocationContractAddress, rpcProvider },
|
|
302
|
+
context
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
return async (credentialStatusEntries) => {
|
|
306
|
+
const status = getVelocityCredentialStatus(credentialStatusEntries);
|
|
307
|
+
if (status?.id == null) {
|
|
308
|
+
return CredentialStatus.NOT_SUPPORTED;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
try {
|
|
312
|
+
const revokedStatus = await getRevokedStatus(status.id);
|
|
313
|
+
return revokedStatus
|
|
314
|
+
? CredentialStatus.REVOKED
|
|
315
|
+
: CredentialStatus.UNREVOKED;
|
|
316
|
+
} catch (err) {
|
|
317
|
+
log.error(err);
|
|
318
|
+
return CredentialStatus.DEPENDENCY_RESOLUTION_ERROR;
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const runTamperingCheck = (
|
|
324
|
+
{ jwtVc, keyMetadata },
|
|
325
|
+
{ keyMap, errors },
|
|
326
|
+
context
|
|
327
|
+
) => {
|
|
328
|
+
if (errors?.vouchersExhausted) {
|
|
329
|
+
return CheckResults.VOUCHER_RESERVE_EXHAUSTED;
|
|
330
|
+
}
|
|
331
|
+
if (errors?.keyResolutionError) {
|
|
332
|
+
return CheckResults.DEPENDENCY_RESOLUTION_ERROR;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
let key = keyMap[toLower(keyMetadata.kid)]?.publicKeyJwk;
|
|
336
|
+
if (key == null && isIssuerTheSubject(keyMetadata)) {
|
|
337
|
+
key = keyMetadata.jwk;
|
|
338
|
+
}
|
|
339
|
+
return checkJwtVCTampering(jwtVc, key, context);
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const runIssuerTrustCheck = (
|
|
343
|
+
{ id, keyMetadata, issuerId, credentialType, credential },
|
|
344
|
+
{
|
|
345
|
+
boundIssuerVcsMap,
|
|
346
|
+
accreditationVCMap,
|
|
347
|
+
issuerDidDocumentMap,
|
|
348
|
+
credentialTypeMetadatasMap,
|
|
349
|
+
errors,
|
|
350
|
+
},
|
|
351
|
+
context
|
|
352
|
+
) => {
|
|
353
|
+
const { log } = context;
|
|
354
|
+
if (errors?.metadataRetrievalError) {
|
|
355
|
+
return Promise.resolve(CheckResults.DEPENDENCY_RESOLUTION_ERROR);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (isIssuerTheSubject(keyMetadata)) {
|
|
359
|
+
return Promise.resolve(CheckResults.SELF_SIGNED);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const resolvedDeps = {
|
|
363
|
+
boundIssuerVc: boundIssuerVcsMap[toLower(id)]?.vc,
|
|
364
|
+
issuerAccreditation: accreditationVCMap[issuerId]?.credentialSubject,
|
|
365
|
+
issuerDidDocument: issuerDidDocumentMap[issuerId],
|
|
366
|
+
credentialTypeMetadata: credentialTypeMetadatasMap[credentialType],
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
if (some(isEmpty, Object.values(resolvedDeps))) {
|
|
370
|
+
log.error(
|
|
371
|
+
{ id, credential, issuerId, credentialType, resolvedDeps },
|
|
372
|
+
'runIssuerTrustCheck: resolvedDeps failed'
|
|
373
|
+
);
|
|
374
|
+
return Promise.resolve(CheckResults.FAIL);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
return checkIssuerTrust(credential, issuerId, resolvedDeps, context);
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
const runCredentialStatusCheck = ({ index }, { credentialStatuses, errors }) =>
|
|
381
|
+
errors?.credentialStatusRetrievalError
|
|
382
|
+
? CheckResults.DEPENDENCY_RESOLUTION_ERROR
|
|
383
|
+
: checkCredentialStatus(credentialStatuses[index]);
|
|
384
|
+
|
|
385
|
+
const getVelocityCredentialStatus = (credentialStatus) => {
|
|
386
|
+
if (isArray(credentialStatus)) {
|
|
387
|
+
return find({ type: VelocityRevocationListType }, credentialStatus);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (credentialStatus?.type !== VelocityRevocationListType) {
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
return credentialStatus;
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
const tamperErrorCheckResults = (checkStatus) => ({
|
|
397
|
+
UNTAMPERED: checkStatus,
|
|
398
|
+
TRUSTED_ISSUER: CheckResults.NOT_CHECKED,
|
|
399
|
+
TRUSTED_HOLDER: CheckResults.NOT_CHECKED,
|
|
400
|
+
UNREVOKED: CheckResults.NOT_CHECKED,
|
|
401
|
+
UNEXPIRED: CheckResults.NOT_CHECKED,
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
module.exports = { verifyCredentials };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2023 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const { jwtDecode, verifyPresentationJwt } = require('@verii/jwt');
|
|
18
|
+
const { VeriiProtocolVersions } = require('@verii/vc-checks');
|
|
19
|
+
const { getJwkFromDidUri } = require('@verii/did-doc');
|
|
20
|
+
const newError = require('http-errors');
|
|
21
|
+
|
|
22
|
+
const verifyVerifiablePresentationJwt = async (
|
|
23
|
+
presentationJwt,
|
|
24
|
+
{ vnfProtocolVersion }
|
|
25
|
+
) => {
|
|
26
|
+
try {
|
|
27
|
+
if (vnfProtocolVersion < VeriiProtocolVersions.PROTOCOL_VERSION_2) {
|
|
28
|
+
return await verifyPresentationJwt(presentationJwt);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const { header } = jwtDecode(presentationJwt);
|
|
32
|
+
const jwk = await getJwkFromDidUri(header.kid);
|
|
33
|
+
return await verifyPresentationJwt(presentationJwt, jwk);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
throw newError(400, `Malformed jwt_vp property: ${error.message}`, {
|
|
36
|
+
errorCode: 'presentation_malformed',
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
module.exports = { verifyVerifiablePresentationJwt };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
const { initHttpClient } = require('@verii/http-client');
|
|
18
|
+
const fetchers = require('@verii/common-fetchers');
|
|
19
|
+
const { verifyCredentials } = require('./verify-credentials');
|
|
20
|
+
|
|
21
|
+
const verifyVeriiCredentials = async (
|
|
22
|
+
{ credentials, expectedHolderDid, relyingParty },
|
|
23
|
+
context
|
|
24
|
+
) => {
|
|
25
|
+
const httpClient = initHttpClient({
|
|
26
|
+
nodeEnv: context.config.nodeEnv,
|
|
27
|
+
requestTimeout: context.config.requestTimeout,
|
|
28
|
+
traceIdHeader: context.config.traceIdHeader,
|
|
29
|
+
prefixUrls: [context.config.registrarUrl],
|
|
30
|
+
agent: context.agent,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// eslint-disable-next-line better-mutation/no-mutation
|
|
34
|
+
context.registrarFetch = httpClient(context.config.registrarUrl, context);
|
|
35
|
+
if (context?.tenant?.id == null) {
|
|
36
|
+
// eslint-disable-next-line better-mutation/no-mutation
|
|
37
|
+
context.tenant = { did: relyingParty.did };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return verifyCredentials(
|
|
41
|
+
{ credentials, expectedHolderDid, relyingParty },
|
|
42
|
+
fetchers,
|
|
43
|
+
context
|
|
44
|
+
);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
module.exports = { verifyVeriiCredentials };
|