@verii/server-credentialing-hub 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +13 -0
  3. package/package.json +87 -0
  4. package/src/assets/templates/app-redirect.hbs +22 -0
  5. package/src/config/config.js +118 -0
  6. package/src/config/index.js +19 -0
  7. package/src/controllers/app-redirect/controller.js +85 -0
  8. package/src/controllers/openid4vc/autohooks.js +22 -0
  9. package/src/controllers/openid4vc/oauth-controller.js +96 -0
  10. package/src/controllers/openid4vc/openid4vc-metadata-controller.js +66 -0
  11. package/src/controllers/openid4vc/openid4vci-controller.js +125 -0
  12. package/src/controllers/openid4vp/autohooks.js +22 -0
  13. package/src/controllers/openid4vp/openid4vp-controller.js +177 -0
  14. package/src/controllers/operator/autohooks.js +31 -0
  15. package/src/controllers/operator/credentials/credentials-controller.js +212 -0
  16. package/src/controllers/operator/credentials/schemas/credential.schema.js +46 -0
  17. package/src/controllers/operator/credentials/schemas/index.js +7 -0
  18. package/src/controllers/operator/credentials/schemas/new-credential.schema.json +23 -0
  19. package/src/controllers/operator/depots/depots-controller.js +154 -0
  20. package/src/controllers/operator/depots/schemas/depot.schema.js +34 -0
  21. package/src/controllers/operator/depots/schemas/index.js +24 -0
  22. package/src/controllers/operator/depots/schemas/new-depot.schema.json +30 -0
  23. package/src/controllers/operator/issue-links/issue-links-controller.js +74 -0
  24. package/src/controllers/operator/issuer-services/issuer-services-controller.js +200 -0
  25. package/src/controllers/operator/issuer-services/schemas/index.js +7 -0
  26. package/src/controllers/operator/issuer-services/schemas/issuer-service.schema.js +26 -0
  27. package/src/controllers/operator/issuer-services/schemas/new-issuer-service.schema.js +137 -0
  28. package/src/controllers/operator/presentation-links/presentation-links-controller.js +76 -0
  29. package/src/controllers/operator/presentations/presentations-controller.js +174 -0
  30. package/src/controllers/operator/presentations/schemas/base-presentation.schema.js +39 -0
  31. package/src/controllers/operator/presentations/schemas/credential-verification.schema.js +83 -0
  32. package/src/controllers/operator/presentations/schemas/index.js +23 -0
  33. package/src/controllers/operator/presentations/schemas/presentation-verification.schema.js +42 -0
  34. package/src/controllers/operator/presentations/schemas/presentation.schema.js +53 -0
  35. package/src/controllers/operator/presentations/schemas/w3c-presentation.js +52 -0
  36. package/src/controllers/operator/relying-party-services/relying-party-services-controller.js +202 -0
  37. package/src/controllers/operator/relying-party-services/schemas/index.js +7 -0
  38. package/src/controllers/operator/relying-party-services/schemas/new-relying-party-service.schema.js +91 -0
  39. package/src/controllers/operator/relying-party-services/schemas/relying-party-service.schema.js +26 -0
  40. package/src/controllers/operator/tenants/schemas/index.js +33 -0
  41. package/src/controllers/operator/tenants/schemas/jwk.schema.json +56 -0
  42. package/src/controllers/operator/tenants/schemas/key-metadata.schema.json +12 -0
  43. package/src/controllers/operator/tenants/schemas/new-key-metadata.schema.json +42 -0
  44. package/src/controllers/operator/tenants/schemas/new-key.schema.json +12 -0
  45. package/src/controllers/operator/tenants/schemas/new-tenant.schema.json +33 -0
  46. package/src/controllers/operator/tenants/schemas/secret-key.schema.json +33 -0
  47. package/src/controllers/operator/tenants/schemas/tenant.schema.json +44 -0
  48. package/src/controllers/operator/tenants/tenants-controller.js +165 -0
  49. package/src/controllers/root-controller.js +43 -0
  50. package/src/controllers/vn-api/schemas/index.js +25 -0
  51. package/src/controllers/vn-api/schemas/presentation-submission.schema.json +41 -0
  52. package/src/controllers/vn-api/schemas/velocity-presentation-submission.response.200.schema.json +36 -0
  53. package/src/controllers/vn-api/schemas/velocity-presentation-submission.schema.json +31 -0
  54. package/src/controllers/vn-api/vn-api-presentation-controller.js +158 -0
  55. package/src/controllers/vn-api/vn-issuing-controller.js +295 -0
  56. package/src/entities/credential-types/fetchers/fetch-credential-type-descriptors.js +36 -0
  57. package/src/entities/credential-types/fetchers/index.js +19 -0
  58. package/src/entities/credential-types/index.js +19 -0
  59. package/src/entities/credentials/domain/canonicalize-credentials.js +70 -0
  60. package/src/entities/credentials/domain/credential-errors.js +25 -0
  61. package/src/entities/credentials/domain/credential-format.js +21 -0
  62. package/src/entities/credentials/domain/index.js +22 -0
  63. package/src/entities/credentials/domain/validate-credential.js +74 -0
  64. package/src/entities/credentials/facades/anchor-verii-credentials-facade.js +45 -0
  65. package/src/entities/credentials/facades/build-verii-issuer.js +44 -0
  66. package/src/entities/credentials/facades/index.js +22 -0
  67. package/src/entities/credentials/facades/issue-verii-credentials-facade.js +62 -0
  68. package/src/entities/credentials/facades/sign-verii-credentials-facade.js +56 -0
  69. package/src/entities/credentials/factories/credential-factory.js +53 -0
  70. package/src/entities/credentials/factories/index.js +19 -0
  71. package/src/entities/credentials/index.js +23 -0
  72. package/src/entities/credentials/orchestrators/create-credentials.js +118 -0
  73. package/src/entities/credentials/orchestrators/index.js +19 -0
  74. package/src/entities/credentials/repo/finders-extension.js +94 -0
  75. package/src/entities/credentials/repo/index.js +19 -0
  76. package/src/entities/credentials/repo/repo.js +62 -0
  77. package/src/entities/credentials/repo/update-issued-credential.js +60 -0
  78. package/src/entities/depots/domain/depot-errors.js +23 -0
  79. package/src/entities/depots/domain/index.js +20 -0
  80. package/src/entities/depots/domain/validate-depot.js +38 -0
  81. package/src/entities/depots/factories/depot-factory.js +50 -0
  82. package/src/entities/depots/factories/index.js +19 -0
  83. package/src/entities/depots/index.js +22 -0
  84. package/src/entities/depots/orchestrators/create-depot.js +31 -0
  85. package/src/entities/depots/orchestrators/delete-depot.js +43 -0
  86. package/src/entities/depots/orchestrators/index.js +20 -0
  87. package/src/entities/depots/repo/find-depot-by-preauth-code.js +30 -0
  88. package/src/entities/depots/repo/find-depots-extension.js +34 -0
  89. package/src/entities/depots/repo/index.js +19 -0
  90. package/src/entities/depots/repo/refresh-preauth-code.js +30 -0
  91. package/src/entities/depots/repo/repo.js +61 -0
  92. package/src/entities/exchanges/adapters/index.js +17 -0
  93. package/src/entities/exchanges/adapters/sign-exchange-response.js +37 -0
  94. package/src/entities/exchanges/domain/authorize-exchange.js +29 -0
  95. package/src/entities/exchanges/domain/build-exchange-event.js +19 -0
  96. package/src/entities/exchanges/domain/build-presentation-request.js +174 -0
  97. package/src/entities/exchanges/domain/exchange-errors.js +28 -0
  98. package/src/entities/exchanges/domain/exchange-protocols.js +29 -0
  99. package/src/entities/exchanges/domain/exchange-states.js +53 -0
  100. package/src/entities/exchanges/domain/exchange-types.js +22 -0
  101. package/src/entities/exchanges/domain/generate-issuing-challenge.js +48 -0
  102. package/src/entities/exchanges/domain/index.js +32 -0
  103. package/src/entities/exchanges/domain/validate-message-settings.js +33 -0
  104. package/src/entities/exchanges/domain/validate-new-exchange.js +25 -0
  105. package/src/entities/exchanges/domain/validate-preauth.js +45 -0
  106. package/src/entities/exchanges/domain/validate-referenced-service.js +33 -0
  107. package/src/entities/exchanges/domain/verify-issuing-challenge.js +42 -0
  108. package/src/entities/exchanges/domain/verify-proof-of-key-possession.js +128 -0
  109. package/src/entities/exchanges/factories/index.js +19 -0
  110. package/src/entities/exchanges/factories/init-exchange-factory.js +58 -0
  111. package/src/entities/exchanges/hooks/exchange-error-hook.js +30 -0
  112. package/src/entities/exchanges/hooks/index.js +17 -0
  113. package/src/entities/exchanges/index.js +24 -0
  114. package/src/entities/exchanges/orchestrators/authenticate.js +67 -0
  115. package/src/entities/exchanges/orchestrators/credential-offer-request.js +70 -0
  116. package/src/entities/exchanges/orchestrators/get-credential-manifest.js +84 -0
  117. package/src/entities/exchanges/orchestrators/get-presentation-request.js +114 -0
  118. package/src/entities/exchanges/orchestrators/index.js +24 -0
  119. package/src/entities/exchanges/orchestrators/issue-credentials.js +132 -0
  120. package/src/entities/exchanges/orchestrators/post-presentation.js +58 -0
  121. package/src/entities/exchanges/repo/exchange-state-repo-extension.js +78 -0
  122. package/src/entities/exchanges/repo/index.js +19 -0
  123. package/src/entities/exchanges/repo/repo.js +52 -0
  124. package/src/entities/issuer-services/domain/index.js +20 -0
  125. package/src/entities/issuer-services/domain/issuer-services-errors.js +23 -0
  126. package/src/entities/issuer-services/domain/validate-issuer-service.js +23 -0
  127. package/src/entities/issuer-services/factories/index.js +19 -0
  128. package/src/entities/issuer-services/factories/issuer-service-factory.js +44 -0
  129. package/src/entities/issuer-services/index.js +21 -0
  130. package/src/entities/issuer-services/repo/find-issuer-services-extension.js +30 -0
  131. package/src/entities/issuer-services/repo/index.js +19 -0
  132. package/src/entities/issuer-services/repo/repo.js +59 -0
  133. package/src/entities/keys/adapters/index.js +19 -0
  134. package/src/entities/keys/adapters/load-primary-account.js +39 -0
  135. package/src/entities/keys/domain/cih-key-purposes.js +23 -0
  136. package/src/entities/keys/domain/get-key-with-purpose.js +22 -0
  137. package/src/entities/keys/domain/index.js +22 -0
  138. package/src/entities/keys/domain/key-errors.js +25 -0
  139. package/src/entities/keys/domain/normalize-tenant-key.js +33 -0
  140. package/src/entities/keys/domain/validate-tenant-keys.js +78 -0
  141. package/src/entities/keys/factories/index.js +19 -0
  142. package/src/entities/keys/factories/key-factory.js +61 -0
  143. package/src/entities/keys/index.js +22 -0
  144. package/src/entities/keys/plugins/index.js +17 -0
  145. package/src/entities/keys/plugins/kms-plugin.js +61 -0
  146. package/src/entities/links/domain/build-deep-link-url.js +58 -0
  147. package/src/entities/links/domain/build-openid4vci-credential-offer-link.js +31 -0
  148. package/src/entities/links/domain/build-openid4vp-authorization-request-link.js +36 -0
  149. package/src/entities/links/domain/build-redirect-url.js +29 -0
  150. package/src/entities/links/domain/build-vn-api-issuing-link.js +54 -0
  151. package/src/entities/links/domain/build-vn-api-presentation-link.js +49 -0
  152. package/src/entities/links/domain/index.js +28 -0
  153. package/src/entities/links/domain/is-preauth-code-auth.js +19 -0
  154. package/src/entities/links/domain/link-errors.js +23 -0
  155. package/src/entities/links/domain/validate-issue-link.js +39 -0
  156. package/src/entities/links/domain/validate-presentation-link.js +39 -0
  157. package/src/entities/links/index.js +20 -0
  158. package/src/entities/links/orchestrators/index.js +17 -0
  159. package/src/entities/links/orchestrators/refresh-links.js +139 -0
  160. package/src/entities/openid4vci/domain/index.js +20 -0
  161. package/src/entities/openid4vci/domain/openid4vci-errors.js +24 -0
  162. package/src/entities/openid4vci/domain/to-credential-configuration-id.js +21 -0
  163. package/src/entities/openid4vci/index.js +21 -0
  164. package/src/entities/openid4vci/orchestrators/create-access-token.js +85 -0
  165. package/src/entities/openid4vci/orchestrators/create-credential.js +108 -0
  166. package/src/entities/openid4vci/orchestrators/get-authorization-server-metadata.js +22 -0
  167. package/src/entities/openid4vci/orchestrators/get-credential-issuer-metadata.js +22 -0
  168. package/src/entities/openid4vci/orchestrators/handle-notification.js +94 -0
  169. package/src/entities/openid4vci/orchestrators/index.js +24 -0
  170. package/src/entities/openid4vci/plugins/index.js +19 -0
  171. package/src/entities/openid4vci/plugins/openid4vci-plugin.js +427 -0
  172. package/src/entities/openid4vp/domain/index.js +21 -0
  173. package/src/entities/openid4vp/domain/openid4vp-request-id.js +47 -0
  174. package/src/entities/openid4vp/domain/presentation-request-expiry.js +37 -0
  175. package/src/entities/openid4vp/domain/wallet-metadata.js +30 -0
  176. package/src/entities/openid4vp/index.js +21 -0
  177. package/src/entities/openid4vp/orchestrators/create-authorization-request.js +183 -0
  178. package/src/entities/openid4vp/orchestrators/index.js +20 -0
  179. package/src/entities/openid4vp/orchestrators/post-authorization-response.js +353 -0
  180. package/src/entities/openid4vp/plugins/index.js +19 -0
  181. package/src/entities/openid4vp/plugins/openid4vp-plugin.js +174 -0
  182. package/src/entities/presentations/domain/index.js +20 -0
  183. package/src/entities/presentations/domain/presentation-format.js +20 -0
  184. package/src/entities/presentations/domain/validate-presentation.js +178 -0
  185. package/src/entities/presentations/factories/index.js +19 -0
  186. package/src/entities/presentations/factories/presentation-factory.js +96 -0
  187. package/src/entities/presentations/index.js +21 -0
  188. package/src/entities/presentations/orchestrators/index.js +19 -0
  189. package/src/entities/presentations/orchestrators/verify-presentation.js +131 -0
  190. package/src/entities/presentations/repo/add-verification.js +31 -0
  191. package/src/entities/presentations/repo/finders-extension.js +50 -0
  192. package/src/entities/presentations/repo/index.js +19 -0
  193. package/src/entities/presentations/repo/repo.js +58 -0
  194. package/src/entities/relying-party-services/factories/index.js +19 -0
  195. package/src/entities/relying-party-services/factories/relying-party-service-factory.js +43 -0
  196. package/src/entities/relying-party-services/index.js +20 -0
  197. package/src/entities/relying-party-services/repo/find-relying-party-services-extension.js +30 -0
  198. package/src/entities/relying-party-services/repo/index.js +19 -0
  199. package/src/entities/relying-party-services/repo/repo.js +55 -0
  200. package/src/entities/service-configurations/domain/canonicalize-service-configuration.js +12 -0
  201. package/src/entities/service-configurations/domain/index.js +22 -0
  202. package/src/entities/service-configurations/domain/service-configuration-errors.js +24 -0
  203. package/src/entities/service-configurations/domain/validate-service-configuration.js +31 -0
  204. package/src/entities/service-configurations/domain/validate-update-service-configuration.js +19 -0
  205. package/src/entities/service-configurations/index.js +20 -0
  206. package/src/entities/service-configurations/orchestrators/create-service-configuration.js +34 -0
  207. package/src/entities/service-configurations/orchestrators/delete-service-configuration.js +41 -0
  208. package/src/entities/service-configurations/orchestrators/index.js +21 -0
  209. package/src/entities/service-configurations/orchestrators/update-service-configuration.js +40 -0
  210. package/src/entities/tenants/adapters/index.js +20 -0
  211. package/src/entities/tenants/adapters/load-tenant-did-doc.js +47 -0
  212. package/src/entities/tenants/adapters/load-tenant-profile.js +40 -0
  213. package/src/entities/tenants/domain/index.js +20 -0
  214. package/src/entities/tenants/domain/tenant-errors.js +29 -0
  215. package/src/entities/tenants/domain/validate-new-tenant.js +49 -0
  216. package/src/entities/tenants/factories/index.js +19 -0
  217. package/src/entities/tenants/factories/tenant-factory.js +41 -0
  218. package/src/entities/tenants/index.js +24 -0
  219. package/src/entities/tenants/orchestrators/create-tenant.js +116 -0
  220. package/src/entities/tenants/orchestrators/delete-tenant.js +45 -0
  221. package/src/entities/tenants/orchestrators/find-tenants.js +22 -0
  222. package/src/entities/tenants/orchestrators/index.js +21 -0
  223. package/src/entities/tenants/plugins/index.js +3 -0
  224. package/src/entities/tenants/plugins/tenant-loader-plugin.js +64 -0
  225. package/src/entities/tenants/repo/index.js +19 -0
  226. package/src/entities/tenants/repo/insert-tenant-extension.js +36 -0
  227. package/src/entities/tenants/repo/repo.js +51 -0
  228. package/src/entities/tokens/domains/access-token.js +74 -0
  229. package/src/entities/tokens/domains/index.js +19 -0
  230. package/src/entities/tokens/index.js +19 -0
  231. package/src/index.js +3 -0
  232. package/src/init-server.js +88 -0
  233. package/src/main.js +25 -0
  234. package/src/schemas/index.js +20 -0
  235. package/src/schemas/oauth-error-response.schema.js +27 -0
  236. package/src/standalone.js +8 -0
  237. package/src/start-app-server.js +27 -0
@@ -0,0 +1,295 @@
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 bearerAuthPlugin = require('@fastify/bearer-auth');
19
+ const { coerceArray } = require('@verii/common-functions');
20
+ const {
21
+ verifyVerifiablePresentationJwt,
22
+ } = require('@verii/verii-verification');
23
+ const newError = require('http-errors');
24
+ const {
25
+ holderOfferSchema,
26
+ newOfferRelatedResourceSchema,
27
+ } = require('@verii/common-schemas');
28
+ const {
29
+ authenticate,
30
+ getCredentialManifest,
31
+ signExchangeResponse,
32
+ exchangeErrorHook,
33
+ credentialOfferRequest,
34
+ issueCredentials,
35
+ } = require('../../entities/exchanges');
36
+ const {
37
+ generateAccessToken,
38
+ verifyAccessToken,
39
+ } = require('../../entities/tokens');
40
+ const { ExchangeErrors, ExchangeStates } = require('../../entities/exchanges');
41
+ const { tenantLoaderPlugin } = require('../../entities/tenants');
42
+ const { kmsPlugin } = require('../../entities/keys');
43
+ const {
44
+ presentationSubmissionSchema,
45
+ velocityPresentationSubmissionSchema,
46
+ velocityPresentationSubmissionResponseSchema,
47
+ } = require('./schemas');
48
+
49
+ const vnfIssuingController = async (fastify) => {
50
+ fastify
51
+ .register(tenantLoaderPlugin, { useDID: true })
52
+ .register(kmsPlugin)
53
+ .addSchema(presentationSubmissionSchema)
54
+ .addSchema(velocityPresentationSubmissionSchema)
55
+ .addSchema(velocityPresentationSubmissionResponseSchema)
56
+ .addSchema(newOfferRelatedResourceSchema)
57
+ .addSchema(holderOfferSchema)
58
+ .register(bearerAuthPlugin, {
59
+ auth: verifyAccessTokenAuth,
60
+ addHook: false,
61
+ })
62
+ .get(
63
+ '/r/:tenantId/get-credential-manifest',
64
+ {
65
+ schema: fastify.autoSchema({
66
+ params: {
67
+ type: 'object',
68
+ properties: {
69
+ tenantId: { type: 'string' },
70
+ },
71
+ },
72
+ query: {
73
+ type: 'object',
74
+ properties: {
75
+ id: { type: 'string' },
76
+ credential_types: {
77
+ anyOf: [
78
+ { type: 'string' },
79
+ {
80
+ type: 'array',
81
+ items: { type: 'string', minLength: 1 },
82
+ },
83
+ ],
84
+ },
85
+ 'push_delegate.push_token': { type: 'string' },
86
+ 'push_delegate.push_url': { type: 'string' },
87
+ locale: { type: 'string', default: 'en' },
88
+ format: { type: 'string', enum: ['json', 'jwt'], default: 'jwt' },
89
+ },
90
+ required: ['id'],
91
+ },
92
+ response: {
93
+ 200: {
94
+ oneOf: [
95
+ {
96
+ issuing_request: { type: 'object' },
97
+ },
98
+ {
99
+ issuing_request: { type: 'string' },
100
+ },
101
+ ],
102
+ },
103
+ },
104
+ }),
105
+ },
106
+ async (req) => {
107
+ const { query } = req;
108
+
109
+ const messagingSettings =
110
+ query.push_delegate != null
111
+ ? {
112
+ webhookUrl: query.push_delegate.push_url,
113
+ authToken: query.push_delegate.push_token,
114
+ }
115
+ : undefined;
116
+
117
+ const credentialManifest = await getCredentialManifest(
118
+ query.id,
119
+ coerceArray(query.credential_types),
120
+ query.locale,
121
+ messagingSettings,
122
+ req,
123
+ );
124
+
125
+ /* eslint-disable camelcase */
126
+ const issuing_request =
127
+ query.format !== 'json'
128
+ ? await signExchangeResponse(credentialManifest, {}, req)
129
+ : credentialManifest;
130
+
131
+ return { issuing_request };
132
+ /* eslint-enable */
133
+ },
134
+ )
135
+ .post(
136
+ '/r/:tenantId/authenticate',
137
+ {
138
+ schema: fastify.autoSchema({
139
+ body: {
140
+ type: 'object',
141
+ properties: {
142
+ exchange_id: { type: 'string', description: 'exchange id value' },
143
+ jwt_vp: {
144
+ type: 'string',
145
+ description: 'vp encoded as a jwt signed by the holder',
146
+ },
147
+ },
148
+ required: ['exchange_id', 'jwt_vp'],
149
+ },
150
+ response: {
151
+ 200: {
152
+ $ref: 'https://velocitycareerlabs.io/velocity-presentation-submission-response.schema.json#',
153
+ },
154
+ ...fastify.UnauthorizedResponse,
155
+ },
156
+ }),
157
+ onError: async (req, reply, err) =>
158
+ exchangeErrorHook(req.body.exchange_id, err, req),
159
+ },
160
+ async (req) => {
161
+ const vp = await verifyVerifiablePresentationJwt(req.body.jwt_vp, {
162
+ vnfProtocolVersion: 2,
163
+ });
164
+ req.validateInput(vp, {
165
+ $ref: 'https://velocitycareerlabs.io/velocity-presentation-submission.schema.json#',
166
+ });
167
+
168
+ const [issuerService, exchange] = await authenticate(
169
+ req.body.exchange_id,
170
+ vp,
171
+ req,
172
+ );
173
+
174
+ const token = await generateAccessToken(issuerService, exchange, req);
175
+
176
+ return {
177
+ token,
178
+ exchange: {
179
+ id: exchange._id,
180
+ type: exchange.type,
181
+ disclosureComplete: true,
182
+ exchangeComplete: false,
183
+ },
184
+ };
185
+ },
186
+ )
187
+ .post(
188
+ '/r/:tenantId/credential-offers',
189
+ {
190
+ schema: fastify.autoSchema({
191
+ body: {
192
+ type: 'object',
193
+ properties: {
194
+ offerHashes: {
195
+ type: 'array',
196
+ items: {
197
+ type: 'string',
198
+ },
199
+ },
200
+ },
201
+ },
202
+ response: {
203
+ 200: {
204
+ type: 'object',
205
+ properties: {
206
+ offers: {
207
+ type: 'array',
208
+ items: {
209
+ $ref: 'https://velocitycareerlabs.io/holder-offer.schema.json#',
210
+ },
211
+ },
212
+ challenge: {
213
+ type: 'string',
214
+ },
215
+ },
216
+ required: ['offers'],
217
+ },
218
+ 502: {
219
+ $ref: 'error#',
220
+ },
221
+ },
222
+ }),
223
+ preHandler: (...args) => fastify.verifyBearerAuth(...args),
224
+ onError: async (req, reply, err) =>
225
+ exchangeErrorHook(req.body.exchange_id, err, req),
226
+ },
227
+ async (req) =>
228
+ credentialOfferRequest(req.token, req.body.offerHashes, req),
229
+ )
230
+ .post(
231
+ '/r/:tenantId/issue-credentials',
232
+ {
233
+ schema: fastify.autoSchema({
234
+ body: {
235
+ type: 'object',
236
+ properties: {
237
+ approvedOfferIds: {
238
+ type: 'array',
239
+ items: { type: 'string' },
240
+ },
241
+ rejectedOfferIds: {
242
+ type: 'array',
243
+ items: { type: 'string' },
244
+ },
245
+ proof: {
246
+ type: 'object',
247
+ properties: {
248
+ proof_type: { type: 'string', enum: ['jwt'] },
249
+ jwt: { type: 'string' },
250
+ },
251
+ required: ['proof_type', 'jwt'],
252
+ },
253
+ },
254
+ },
255
+ response: {
256
+ 200: {
257
+ type: 'array',
258
+ items: {
259
+ type: 'string',
260
+ },
261
+ },
262
+ },
263
+ }),
264
+ preHandler: (...args) => fastify.verifyBearerAuth(...args),
265
+ onError: async (req, reply, err) =>
266
+ exchangeErrorHook(req.body.exchange_id, err, req),
267
+ },
268
+ async (req) =>
269
+ issueCredentials(
270
+ req.token,
271
+ req.body.approvedOfferIds,
272
+ req.body.rejectedOfferIds,
273
+ req.body.proof,
274
+ req,
275
+ ),
276
+ );
277
+ };
278
+
279
+ const verifyAccessTokenAuth = async (bearerToken, req) => {
280
+ try {
281
+ const verifiedJwt = await verifyAccessToken(bearerToken, req);
282
+
283
+ // eslint-disable-next-line better-mutation/no-mutation
284
+ req.token = verifiedJwt.payload;
285
+ return true;
286
+ } catch (error) {
287
+ req.log.error(error);
288
+ throw newError(401, ExchangeErrors.UNAUTHORIZED, {
289
+ exchangeErrorState: ExchangeStates.UNAUTHORIZED,
290
+ errorCode: ExchangeErrors.UNAUTHORIZED,
291
+ });
292
+ }
293
+ };
294
+
295
+ module.exports = vnfIssuingController;
@@ -0,0 +1,36 @@
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 { map } = require('lodash/fp');
18
+ const { getCredentialTypeDescriptor } = require('@verii/common-fetchers');
19
+
20
+ const fetchCredentialTypeDescriptors = (
21
+ types,
22
+ includeDisplay,
23
+ locale,
24
+ context,
25
+ ) =>
26
+ Promise.all(
27
+ map(
28
+ (type) =>
29
+ getCredentialTypeDescriptor({ type, locale, includeDisplay }, context),
30
+ types,
31
+ ),
32
+ );
33
+
34
+ module.exports = {
35
+ fetchCredentialTypeDescriptors,
36
+ };
@@ -0,0 +1,19 @@
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
+ module.exports = {
18
+ ...require('./fetch-credential-type-descriptors'),
19
+ };
@@ -0,0 +1,19 @@
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
+ module.exports = {
18
+ ...require('./fetchers'),
19
+ };
@@ -0,0 +1,70 @@
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
+ const { ObjectId } = require('mongodb');
18
+ const { hashOffer } = require('@verii/verii-issuing');
19
+ const { isEmpty, map, keyBy } = require('lodash/fp');
20
+
21
+ const initCanonicalizeCredentials = (
22
+ relatedCredentials,
23
+ credentialTypeMetadatas,
24
+ ) => {
25
+ const defaultCredentialContent =
26
+ initDefaultCredentialContent(relatedCredentials);
27
+ return ({ credential, depotId, metadataIdx }) => ({
28
+ ...credential,
29
+ depotId: new ObjectId(depotId),
30
+ content: defaultCredentialContent(credential.content),
31
+ contentHash: hashOffer(credential.content),
32
+ typeMetadata: credentialTypeMetadatas[metadataIdx],
33
+ });
34
+ };
35
+
36
+ const initDefaultCredentialContent = (relatedCredentials) => {
37
+ const defaultRelatedResource = initDefaultRelatedResource(relatedCredentials);
38
+ return (content) => {
39
+ if (!isEmpty(content.relatedResource)) {
40
+ // eslint-disable-next-line better-mutation/no-mutation
41
+ content.relatedResource = map(
42
+ defaultRelatedResource,
43
+ content.relatedResource,
44
+ );
45
+ }
46
+
47
+ if (!isEmpty(content.replaces)) {
48
+ // eslint-disable-next-line better-mutation/no-mutation
49
+ content.replaces = map(defaultRelatedResource, content.replaces);
50
+ }
51
+ return content;
52
+ };
53
+ };
54
+
55
+ const initDefaultRelatedResource = (relatedCredentials) => {
56
+ const credentialRefsMap = keyBy('did', relatedCredentials);
57
+ return (resource) => {
58
+ const credentialRef = credentialRefsMap[resource.id];
59
+ if (!isEmpty(credentialRef)) {
60
+ // eslint-disable-next-line better-mutation/no-mutation
61
+ resource.digestSRI = resource.digestSRI ?? credentialRef.digestSRI;
62
+ // eslint-disable-next-line better-mutation/no-mutation
63
+ resource.hint = resource.hint ?? credentialRef.content.type;
64
+ }
65
+
66
+ return resource;
67
+ };
68
+ };
69
+
70
+ module.exports = { initCanonicalizeCredentials };
@@ -0,0 +1,25 @@
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
+ const CredentialErrors = {
18
+ REFERENCED_DEPOT_NOT_FOUND: 'referenced_depot_not_found',
19
+ CREDENTIAL_TYPE_NOT_FOUND: 'credential_type_not_found',
20
+ CREDENTIAL_TYPES_METADATA_UPSTREAM_ERROR:
21
+ 'credential_types_metadata_upstream_error',
22
+ SCHEMA_UPSTREAM_ERROR: 'schema_upstream_error',
23
+ };
24
+
25
+ module.exports = { CredentialErrors };
@@ -0,0 +1,21 @@
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 CredentialFormat = {
18
+ JWT_VC: 'JWT_VC',
19
+ };
20
+
21
+ module.exports = { CredentialFormat };
@@ -0,0 +1,22 @@
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
+ module.exports = {
18
+ ...require('./canonicalize-credentials'),
19
+ ...require('./credential-errors'),
20
+ ...require('./credential-format'),
21
+ ...require('./validate-credential'),
22
+ };
@@ -0,0 +1,74 @@
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
+ const { wrapValidationError } = require('@verii/validation');
18
+ const newError = require('http-errors');
19
+ const { keyBy, map, forEach } = require('lodash/fp');
20
+ const { CredentialErrors } = require('./credential-errors');
21
+
22
+ const initValidateCredential = (
23
+ depots,
24
+ credentialTypeMetadatas,
25
+ schemas,
26
+ context,
27
+ ) => {
28
+ const depotsById = keyBy('_id', depots);
29
+
30
+ forEach((schema) => {
31
+ context.addDocSchema(schema, true);
32
+ }, schemas);
33
+
34
+ const credentialSubjectValidators = map(
35
+ (schema) => context.getDocValidator(schema.$id),
36
+ schemas,
37
+ );
38
+
39
+ return ({ credential, depotId, metadataIdx }) => {
40
+ validateCredential(
41
+ credential,
42
+ depotsById[depotId],
43
+ credentialTypeMetadatas[metadataIdx],
44
+ credentialSubjectValidators[metadataIdx],
45
+ );
46
+ };
47
+ };
48
+ const validateCredential = (
49
+ credential,
50
+ depot,
51
+ credentialTypeMetadata,
52
+ validateCredentialSubject,
53
+ ) => {
54
+ if (depot == null) {
55
+ throw newError(400, CredentialErrors.REFERENCED_DEPOT_NOT_FOUND, {
56
+ errorCode: CredentialErrors.REFERENCED_DEPOT_NOT_FOUND,
57
+ });
58
+ }
59
+ if (credentialTypeMetadata == null) {
60
+ throw newError(400, CredentialErrors.CREDENTIAL_TYPE_NOT_FOUND, {
61
+ errorCode: CredentialErrors.CREDENTIAL_TYPE_NOT_FOUND,
62
+ });
63
+ }
64
+
65
+ validateCredentialSubject(credential.content.credentialSubject);
66
+ if (validateCredentialSubject.errors !== null) {
67
+ throw wrapValidationError(
68
+ validateCredentialSubject.errors,
69
+ 'credential.content.credentialSubject',
70
+ );
71
+ }
72
+ };
73
+
74
+ module.exports = { initValidateCredential };
@@ -0,0 +1,45 @@
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 { anchorVeriiCredentials } = require('@verii/verii-issuing');
18
+ const newError = require('http-errors');
19
+ const { buildVeriiIssuer } = require('./build-verii-issuer');
20
+
21
+ const anchorVeriiCredentialsFacade = (credentialMetadatas, context) => {
22
+ const issuer = buildVeriiIssuer(context.tenant);
23
+ // eslint-disable-next-line better-mutation/no-mutation
24
+ context.caoDid = context.tenant.caoDid;
25
+ return anchorVeriiCredentials(credentialMetadatas, issuer, context).catch(
26
+ (e) => {
27
+ context.log.error({
28
+ err: e,
29
+ fn: 'anchorVeriiCredentials',
30
+ args: { credentialMetadatas },
31
+ });
32
+
33
+ switch (e.errorCode) {
34
+ case 'career_issuing_not_permitted':
35
+ case 'identity_issuing_not_permitted':
36
+ case 'contact_issuing_not_permitted':
37
+ throw newError(502, e);
38
+ default:
39
+ throw e;
40
+ }
41
+ },
42
+ );
43
+ };
44
+
45
+ module.exports = { anchorVeriiCredentialsFacade };
@@ -0,0 +1,44 @@
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 { toDidUrl } = require('@verii/did-doc');
18
+ const { toEthereumAddress } = require('@verii/blockchain-functions');
19
+ const { KeyPurposes } = require('@verii/crypto');
20
+
21
+ const buildVeriiIssuer = (tenant, issuerService) => {
22
+ const veriiIssuer = {
23
+ id: tenant._id,
24
+ did: tenant.did,
25
+ issuingServiceKMSKeyId:
26
+ tenant.keysByPurpose[KeyPurposes.ISSUING_METADATA]._id,
27
+ issuingServiceDIDKeyId: toDidUrl(
28
+ tenant.did,
29
+ tenant.keysByPurpose[KeyPurposes.ISSUING_METADATA].kidFragment,
30
+ ),
31
+ dltOperatorAddress: toEthereumAddress(
32
+ tenant.keysByPurpose[KeyPurposes.DLT_TRANSACTIONS].publicJwk,
33
+ ),
34
+ dltOperatorKMSKeyId: tenant.keysByPurpose[KeyPurposes.DLT_TRANSACTIONS]._id,
35
+ dltPrimaryAddress: tenant.primaryAccount,
36
+ };
37
+ if (issuerService != null) {
38
+ veriiIssuer.issuingRefreshServiceId =
39
+ issuerService.velocityNetworkServiceId;
40
+ }
41
+ return veriiIssuer;
42
+ };
43
+
44
+ module.exports = { buildVeriiIssuer };