@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,66 @@
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
+
18
+ const cors = require('@fastify/cors');
19
+ const { KeyPurposes } = require('@verii/crypto');
20
+ const { toDidUrl } = require('@verii/did-doc');
21
+ const {
22
+ getCredentialIssuerMetadata,
23
+ getAuthorizationServerMetadata,
24
+ } = require('../../entities/openid4vci');
25
+
26
+ const APPLICATION_JWT_MEDIA_TYPE = 'application/jwt';
27
+ const openid4vcMetadataController = async (fastify) => {
28
+ fastify
29
+ .register(cors, { origin: true })
30
+ .get(
31
+ '/.well-known/openid-credential-issuer/r/:tenantId',
32
+ async (req, reply) => {
33
+ const credentialIssuerMetadata = await getCredentialIssuerMetadata(req);
34
+ if (req.headers.accept?.includes(APPLICATION_JWT_MEDIA_TYPE)) {
35
+ reply.type(APPLICATION_JWT_MEDIA_TYPE);
36
+ const exchangesKey = req.tenant.keysByPurpose[KeyPurposes.EXCHANGES];
37
+ return req.kms.signJwt(credentialIssuerMetadata, exchangesKey._id, {
38
+ issuer: req.tenant.did,
39
+ subject: req.tenant.did,
40
+ kid: toDidUrl(req.tenant.did, exchangesKey.kidFragment),
41
+ expiresIn: '1w',
42
+ });
43
+ }
44
+ return credentialIssuerMetadata;
45
+ },
46
+ )
47
+ .get('/.well-known/oauth-authorization-server/r/:tenantId', async (req) => {
48
+ const authorizationServerMetadata =
49
+ await getAuthorizationServerMetadata(req);
50
+ const exchangesKey = req.tenant.keysByPurpose[KeyPurposes.EXCHANGES];
51
+ return {
52
+ signed_metadata: await req.kms.signJwt(
53
+ authorizationServerMetadata,
54
+ exchangesKey._id,
55
+ {
56
+ issuer: req.tenant.did,
57
+ subject: req.tenant.did,
58
+ kid: toDidUrl(req.tenant.did, exchangesKey.kidFragment),
59
+ expiresIn: '1w',
60
+ },
61
+ ),
62
+ };
63
+ });
64
+ };
65
+
66
+ module.exports = openid4vcMetadataController;
@@ -0,0 +1,125 @@
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
+
18
+ const { Oauth2ErrorCodes } = require('@openid4vc/oauth2');
19
+ const {
20
+ createCredential,
21
+ handleNotification,
22
+ Oidc4vciErrors,
23
+ } = require('../../entities/openid4vci');
24
+ const { oauthErrorResponseSchema } = require('../../schemas');
25
+
26
+ const openid4vciController = async (fastify) => {
27
+ fastify
28
+ .post(
29
+ '/r/:tenantId/openid4vc/nonce',
30
+ {
31
+ schema: fastify.autoSchema({
32
+ params: {
33
+ type: 'object',
34
+ properties: {
35
+ tenantId: { type: 'string' },
36
+ },
37
+ },
38
+ }),
39
+ },
40
+ async (req, reply) => {
41
+ reply.header('Cache-Control', 'no-store');
42
+ const openid4vcIssuer = await req.getOpenId4VciIssuer();
43
+ return openid4vcIssuer.createNonce();
44
+ },
45
+ )
46
+ .post(
47
+ '/r/:tenantId/openid4vc/credential',
48
+ {
49
+ errorHandler: (e, request, reply) => {
50
+ const error = fastify.openid4vcErrorHandler(e, request, reply);
51
+ if (error.error === Oauth2ErrorCodes.InvalidRequest) {
52
+ // eslint-disable-next-line better-mutation/no-mutation
53
+ error.error = Oauth2ErrorCodes.InvalidCredentialRequest;
54
+ }
55
+ return error;
56
+ },
57
+ preHandler: (req, reply) => fastify.openid4vcBearerAuth(req, reply),
58
+ schema: fastify.autoSchema({
59
+ params: {
60
+ type: 'object',
61
+ properties: {
62
+ tenantId: { type: 'string' },
63
+ },
64
+ },
65
+ response: {
66
+ 400: oauthErrorResponseSchema,
67
+ 401: oauthErrorResponseSchema,
68
+ 500: oauthErrorResponseSchema,
69
+ },
70
+ }),
71
+ },
72
+ async (req) => createCredential(req.body, req),
73
+ )
74
+ .post(
75
+ '/r/:tenantId/openid4vc/notification',
76
+ {
77
+ errorHandler: (e, request, reply) => {
78
+ const error = fastify.openid4vcErrorHandler(e, request, reply);
79
+ if (error.error === Oauth2ErrorCodes.InvalidRequest) {
80
+ // eslint-disable-next-line better-mutation/no-mutation
81
+ error.error = Oidc4vciErrors.INVALID_NOTIFICATION_REQUEST;
82
+ }
83
+ return error;
84
+ },
85
+ preHandler: (req, reply) => fastify.openid4vcBearerAuth(req, reply),
86
+ schema: fastify.autoSchema({
87
+ params: {
88
+ type: 'object',
89
+ properties: {
90
+ tenantId: { type: 'string' },
91
+ },
92
+ },
93
+ body: {
94
+ type: 'object',
95
+ properties: {
96
+ notification_id: { type: 'string' },
97
+ event: {
98
+ type: 'string',
99
+ enum: [
100
+ 'credential_accepted',
101
+ 'credential_deleted',
102
+ 'credential_failure',
103
+ ],
104
+ },
105
+ event_description: { type: 'string' },
106
+ },
107
+ required: ['notification_id', 'event'],
108
+ },
109
+
110
+ response: {
111
+ 400: oauthErrorResponseSchema,
112
+ 401: oauthErrorResponseSchema,
113
+ 500: oauthErrorResponseSchema,
114
+ },
115
+ }),
116
+ },
117
+ async (req, reply) => {
118
+ await handleNotification(req.body, req);
119
+ reply.status(204);
120
+ return {};
121
+ },
122
+ );
123
+ };
124
+
125
+ module.exports = openid4vciController;
@@ -0,0 +1,22 @@
1
+ /*
2
+ * Copyright 2026 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 { tenantLoaderPlugin } = require('../../entities/tenants');
18
+ const { kmsPlugin } = require('../../entities/keys');
19
+
20
+ module.exports = async (fastify) => {
21
+ fastify.register(tenantLoaderPlugin).register(kmsPlugin);
22
+ };
@@ -0,0 +1,177 @@
1
+ /*
2
+ * Copyright 2026 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 fastifyFormBody = require('@fastify/formbody');
19
+ const {
20
+ createAuthorizationRequest,
21
+ postAuthorizationResponse,
22
+ } = require('../../entities/openid4vp');
23
+ const { oauthErrorResponseSchema } = require('../../schemas');
24
+ const {
25
+ presentationSubmissionSchema,
26
+ velocityPresentationSubmissionSchema,
27
+ } = require('../vn-api/schemas');
28
+
29
+ const openid4vpController = async (fastify) => {
30
+ fastify.register(fastifyFormBody);
31
+ fastify
32
+ .addSchema(presentationSubmissionSchema)
33
+ .addSchema(velocityPresentationSubmissionSchema);
34
+
35
+ fastify
36
+ .post(
37
+ '/r/:tenantId/openid4vp/authorization-request/:requestId',
38
+ {
39
+ errorHandler: (error, request, reply) =>
40
+ fastify.openid4vpErrorHandler(error, request, reply),
41
+ schema: fastify.autoSchema({
42
+ params: {
43
+ type: 'object',
44
+ properties: {
45
+ tenantId: { type: 'string' },
46
+ requestId: { type: 'string' },
47
+ },
48
+ required: ['tenantId', 'requestId'],
49
+ },
50
+ headers: {
51
+ type: 'object',
52
+ properties: {
53
+ 'content-type': {
54
+ type: 'string',
55
+ pattern: '^application/x-www-form-urlencoded(?:\\s*;.*)?$',
56
+ },
57
+ accept: {
58
+ type: 'string',
59
+ pattern: 'application/oauth-authz-req\\+jwt',
60
+ },
61
+ },
62
+ required: ['content-type', 'accept'],
63
+ },
64
+ body: {
65
+ type: 'object',
66
+ properties: {
67
+ wallet_metadata: { type: 'string' },
68
+ wallet_nonce: { type: 'string', minLength: 11 },
69
+ },
70
+ required: ['wallet_metadata', 'wallet_nonce'],
71
+ },
72
+ response: {
73
+ 200: {
74
+ description: 'OpenID4VP authorization request JWT',
75
+ content: {
76
+ 'application/oauth-authz-req+jwt': {
77
+ schema: { type: 'string' },
78
+ },
79
+ },
80
+ },
81
+ 400: oauthErrorResponseSchema,
82
+ 404: oauthErrorResponseSchema,
83
+ 500: oauthErrorResponseSchema,
84
+ },
85
+ }),
86
+ },
87
+ async (req, reply) => {
88
+ const authorizationRequestJwt = await createAuthorizationRequest(
89
+ req.params.requestId,
90
+ {
91
+ walletMetadata: req.body.wallet_metadata,
92
+ walletNonce: req.body.wallet_nonce,
93
+ },
94
+ req,
95
+ );
96
+
97
+ reply.type('application/oauth-authz-req+jwt');
98
+ return authorizationRequestJwt;
99
+ },
100
+ )
101
+ .post(
102
+ '/r/:tenantId/openid4vp/direct-post',
103
+ {
104
+ errorHandler: (error, request, reply) =>
105
+ fastify.openid4vpErrorHandler(error, request, reply),
106
+ schema: fastify.autoSchema({
107
+ params: {
108
+ type: 'object',
109
+ properties: {
110
+ tenantId: { type: 'string' },
111
+ },
112
+ required: ['tenantId'],
113
+ },
114
+ headers: {
115
+ type: 'object',
116
+ properties: {
117
+ 'content-type': {
118
+ type: 'string',
119
+ pattern: '^application/x-www-form-urlencoded(?:\\s*;.*)?$',
120
+ },
121
+ },
122
+ required: ['content-type'],
123
+ },
124
+ body: {
125
+ oneOf: [
126
+ {
127
+ type: 'object',
128
+ properties: {
129
+ state: {
130
+ type: 'string',
131
+ minLength: 1,
132
+ pattern: '^[0-9a-fA-F]{24}$',
133
+ },
134
+ vp_token: {
135
+ type: 'string',
136
+ minLength: 1,
137
+ pattern: '^(?!\\s*\\[\\s*\\]\\s*$).+',
138
+ },
139
+ presentation_submission: { type: 'string', minLength: 1 },
140
+ },
141
+ required: ['state', 'vp_token', 'presentation_submission'],
142
+ },
143
+ {
144
+ type: 'object',
145
+ properties: {
146
+ state: {
147
+ type: 'string',
148
+ minLength: 1,
149
+ pattern: '^[0-9a-fA-F]{24}$',
150
+ },
151
+ error: { type: 'string', minLength: 1 },
152
+ error_description: { type: 'string', minLength: 1 },
153
+ },
154
+ required: ['state', 'error'],
155
+ },
156
+ ],
157
+ },
158
+ response: {
159
+ 200: {
160
+ type: 'object',
161
+ additionalProperties: false,
162
+ properties: {},
163
+ },
164
+ 400: oauthErrorResponseSchema,
165
+ 404: oauthErrorResponseSchema,
166
+ 500: oauthErrorResponseSchema,
167
+ },
168
+ }),
169
+ },
170
+ async (req) => {
171
+ await postAuthorizationResponse(req.body, req);
172
+ return {};
173
+ },
174
+ );
175
+ };
176
+
177
+ module.exports = openid4vpController;
@@ -0,0 +1,31 @@
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 { responseRequestIdPlugin } = require('@verii/fastify-plugins');
18
+ const fastifyBearerAuth = require('@fastify/bearer-auth');
19
+ const { kmsPlugin } = require('../../entities/keys');
20
+
21
+ module.exports = async (fastify) => {
22
+ if (!fastify.config.isTest) {
23
+ fastify.register(fastifyBearerAuth, {
24
+ keys: new Set([fastify.config.operatorApiToken]),
25
+ });
26
+ }
27
+ fastify
28
+ .register(kmsPlugin)
29
+ .register(responseRequestIdPlugin)
30
+ .autoSchemaPreset({ security: [{ bearerAuth: [] }] });
31
+ };
@@ -0,0 +1,212 @@
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 {
19
+ newOfferRelatedResourceSchema,
20
+ w3cVcSchema,
21
+ } = require('@verii/common-schemas');
22
+ const { validationPlugin } = require('@verii/validation');
23
+ const { tenantLoaderPlugin } = require('../../../entities/tenants');
24
+ const { createCredentials } = require('../../../entities/credentials');
25
+ const { newCredentialSchema, credentialSchema } = require('./schemas');
26
+
27
+ const credentialsController = async (fastify) => {
28
+ fastify
29
+ .addSchema(newOfferRelatedResourceSchema)
30
+ .addSchema(w3cVcSchema)
31
+ .addSchema(newCredentialSchema)
32
+ .addSchema(credentialSchema)
33
+ .register(tenantLoaderPlugin, { notFoundStatusCode: 400 })
34
+ .register(validationPlugin, {
35
+ ajv: { useDefaults: true, strictTypes: false },
36
+ decorateRequest: ['addDocSchema', 'getDocValidator'],
37
+ })
38
+ .post(
39
+ '/create',
40
+ {
41
+ schema: fastify.autoSchema({
42
+ body: {
43
+ type: 'object',
44
+ properties: {
45
+ tenantId: {
46
+ type: 'string',
47
+ },
48
+ depotId: { type: 'string' },
49
+ credential: {
50
+ $ref: 'new-credential',
51
+ },
52
+ },
53
+ required: ['tenantId', 'depotId', 'credential'],
54
+ },
55
+ response: {
56
+ 200: {
57
+ type: 'object',
58
+ properties: {
59
+ credential: {
60
+ $ref: 'Credential',
61
+ },
62
+ requestId: {
63
+ type: 'string',
64
+ },
65
+ },
66
+ },
67
+ },
68
+ }),
69
+ },
70
+ async (req) => {
71
+ const { body } = req;
72
+ const [credential] = await createCredentials([body], req);
73
+ return { credential };
74
+ },
75
+ )
76
+ .post(
77
+ '/create-many',
78
+ {
79
+ schema: fastify.autoSchema({
80
+ body: {
81
+ type: 'object',
82
+ properties: {
83
+ tenantId: {
84
+ type: 'string',
85
+ },
86
+ items: {
87
+ type: 'array',
88
+ items: {
89
+ type: 'object',
90
+ properties: {
91
+ depotId: { type: 'string' },
92
+ credential: {
93
+ $ref: 'new-credential',
94
+ },
95
+ },
96
+ required: ['depotId', 'credential'],
97
+ },
98
+ minItems: 1,
99
+ },
100
+ },
101
+ required: ['tenantId', 'items'],
102
+ },
103
+ response: {
104
+ 200: {
105
+ type: 'object',
106
+ properties: {
107
+ credentials: {
108
+ type: 'array',
109
+ items: {
110
+ $ref: 'Credential',
111
+ },
112
+ },
113
+ requestId: {
114
+ type: 'string',
115
+ },
116
+ },
117
+ },
118
+ },
119
+ }),
120
+ },
121
+ async (req) => {
122
+ const { body } = req;
123
+ const credentials = await createCredentials(body.items, req);
124
+ return { credentials };
125
+ },
126
+ )
127
+ .get(
128
+ '/get',
129
+ {
130
+ schema: fastify.autoSchema({
131
+ query: {
132
+ type: 'object',
133
+ properties: {
134
+ tenantId: {
135
+ type: 'string',
136
+ },
137
+ credentialId: {
138
+ type: 'string',
139
+ },
140
+ },
141
+ required: ['tenantId'],
142
+ },
143
+ response: {
144
+ 200: {
145
+ type: 'object',
146
+ properties: {
147
+ credentials: {
148
+ type: 'array',
149
+ items: {
150
+ $ref: 'Credential',
151
+ },
152
+ },
153
+ requestId: {
154
+ type: 'string',
155
+ },
156
+ },
157
+ },
158
+ },
159
+ }),
160
+ },
161
+ async (req) => {
162
+ const {
163
+ query: { credentialId },
164
+ repos,
165
+ } = req;
166
+ const credentials = await repos.credentials.search({
167
+ credentialIds: credentialId ? [credentialId] : [],
168
+ });
169
+
170
+ return { credentials };
171
+ },
172
+ )
173
+ .post(
174
+ '/delete',
175
+ {
176
+ schema: fastify.autoSchema({
177
+ body: {
178
+ type: 'object',
179
+ properties: {
180
+ tenantId: {
181
+ type: 'string',
182
+ },
183
+ credentialIds: {
184
+ type: 'array',
185
+ items: {
186
+ type: 'string',
187
+ },
188
+ minItems: 1,
189
+ },
190
+ },
191
+ required: ['tenantId', 'credentialIds'],
192
+ },
193
+ response: {
194
+ 200: {
195
+ type: 'object',
196
+ properties: {
197
+ requestId: {
198
+ type: 'string',
199
+ },
200
+ },
201
+ },
202
+ },
203
+ }),
204
+ },
205
+ async (req) =>
206
+ req.repos.credentials.delUsingFilter({
207
+ filter: { _id: { $in: req.body.credentialIds } },
208
+ }),
209
+ );
210
+ };
211
+
212
+ module.exports = credentialsController;
@@ -0,0 +1,46 @@
1
+ const { mutableEntitySchema } = require('@verii/common-schemas');
2
+ const newCredentialSchema = require('./new-credential.schema.json');
3
+
4
+ const credentialSchema = {
5
+ $id: 'Credential',
6
+ type: 'object',
7
+ properties: {
8
+ ...mutableEntitySchema.properties,
9
+ ...newCredentialSchema.properties,
10
+ depotId: {
11
+ type: 'string',
12
+ description: 'the depot that contains this credential',
13
+ },
14
+ contentHash: {
15
+ type: 'string',
16
+ description: 'the credential content hash',
17
+ },
18
+ acceptedAt: {
19
+ type: 'string',
20
+ description: 'when the credential was accepted',
21
+ format: 'date-time',
22
+ },
23
+ jwtVc: {
24
+ type: 'string',
25
+ description: 'the issued credential',
26
+ },
27
+ rejectedAt: {
28
+ type: 'string',
29
+ description: 'when the credential was rejected',
30
+ format: 'date-time',
31
+ },
32
+ rejectedReason: {
33
+ type: 'string',
34
+ description: 'an optional reason that was captured during rejection',
35
+ },
36
+ },
37
+ required: [
38
+ ...mutableEntitySchema.required,
39
+ ...newCredentialSchema.required,
40
+ 'depotId',
41
+ 'contentHash',
42
+ ],
43
+ $defs: newCredentialSchema.$defs,
44
+ };
45
+
46
+ module.exports = credentialSchema;
@@ -0,0 +1,7 @@
1
+ const newCredentialSchema = require('./new-credential.schema.json');
2
+ const credentialSchema = require('./credential.schema');
3
+
4
+ module.exports = {
5
+ credentialSchema,
6
+ newCredentialSchema,
7
+ };