@verii/server-credentialagent 1.0.0-pre.1752076816

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 (395) hide show
  1. package/.localdev.e2e.env +40 -0
  2. package/.localdev.env +41 -0
  3. package/.standalone.env +5 -0
  4. package/LICENSE +202 -0
  5. package/NOTICE +1 -0
  6. package/README.md +19 -0
  7. package/docker/compose.yml +33 -0
  8. package/e2e/README.md +12 -0
  9. package/e2e/org-registration-and-issuing.e2e.test.js +624 -0
  10. package/jest.config.js +20 -0
  11. package/migrate-mongo.config.js +36 -0
  12. package/migrations/20210317133137-add-index-to-offers-repo.js +57 -0
  13. package/migrations/20210416145639-add-index-to-revocation-list.js +27 -0
  14. package/migrations/20210719120225-add_unique_did_index_to_tenant.js +45 -0
  15. package/migrations/20230524053029-add-vendorUserIdMappings-index.js +32 -0
  16. package/migrations/20230616111907-add-configuration-type-index.js +32 -0
  17. package/package.json +108 -0
  18. package/src/assets/public/favicon.ico +0 -0
  19. package/src/assets/public/logo192.png +0 -0
  20. package/src/assets/public/logo512.png +0 -0
  21. package/src/assets/public/manifest.json +28 -0
  22. package/src/assets/templates/app-redirect.hbs +16 -0
  23. package/src/config/config.js +44 -0
  24. package/src/config/core-config.js +143 -0
  25. package/src/config/holder-config.js +104 -0
  26. package/src/config/index.js +22 -0
  27. package/src/config/operator-config.js +64 -0
  28. package/src/controllers/autoload-holder-api-controllers.js +30 -0
  29. package/src/controllers/autoload-operator-api-controllers.js +31 -0
  30. package/src/controllers/autoload-root-api-controller.js +30 -0
  31. package/src/controllers/autoload-saasoperator-api-controllers.js +31 -0
  32. package/src/controllers/holder/autohooks.js +55 -0
  33. package/src/controllers/holder/get-exchange-progress/autohooks.js +27 -0
  34. package/src/controllers/holder/get-exchange-progress/controller.js +50 -0
  35. package/src/controllers/holder/inspect/autohooks.js +35 -0
  36. package/src/controllers/holder/inspect/get-presentation-request/controller.js +100 -0
  37. package/src/controllers/holder/inspect/schemas/holder-disclosure.schema.json +73 -0
  38. package/src/controllers/holder/inspect/schemas/index.js +33 -0
  39. package/src/controllers/holder/inspect/schemas/presentation-definition.v1.schema.json +461 -0
  40. package/src/controllers/holder/inspect/schemas/presentation-request.schema.json +279 -0
  41. package/src/controllers/holder/inspect/schemas/presentation-submission.schema.json +41 -0
  42. package/src/controllers/holder/inspect/schemas/siop-presentation-submission.schema.json +74 -0
  43. package/src/controllers/holder/inspect/schemas/velocity-presentation-submission.response.200.schema.json +36 -0
  44. package/src/controllers/holder/inspect/schemas/velocity-presentation-submission.schema.json +34 -0
  45. package/src/controllers/holder/inspect/submit-presentation/controller.js +89 -0
  46. package/src/controllers/holder/issue/autohooks.js +23 -0
  47. package/src/controllers/holder/issue/get-credential-manifest/controller.js +193 -0
  48. package/src/controllers/holder/issue/offers/autohooks.js +35 -0
  49. package/src/controllers/holder/issue/offers/controller.js +164 -0
  50. package/src/controllers/holder/issue/offers/credential-offers/controller.js +460 -0
  51. package/src/controllers/holder/issue/submit-identification/autohooks.js +37 -0
  52. package/src/controllers/holder/issue/submit-identification/controller.js +63 -0
  53. package/src/controllers/holder/oauth/autohooks.js +19 -0
  54. package/src/controllers/holder/oauth/controller.js +140 -0
  55. package/src/controllers/index.js +22 -0
  56. package/src/controllers/operator/tenants/_tenantId/autohooks.js +40 -0
  57. package/src/controllers/operator/tenants/_tenantId/check-credentials/autohooks.js +24 -0
  58. package/src/controllers/operator/tenants/_tenantId/check-credentials/controller-v0.8.js +200 -0
  59. package/src/controllers/operator/tenants/_tenantId/check-credentials/schemas/index.js +19 -0
  60. package/src/controllers/operator/tenants/_tenantId/check-credentials/schemas/vendor-credential.schema.json +244 -0
  61. package/src/controllers/operator/tenants/_tenantId/controller-v0.8.js +221 -0
  62. package/src/controllers/operator/tenants/_tenantId/disclosures/_id/autohooks.js +30 -0
  63. package/src/controllers/operator/tenants/_tenantId/disclosures/_id/controller-v0.8.js +271 -0
  64. package/src/controllers/operator/tenants/_tenantId/disclosures/_id/feeds/autohooks.js +45 -0
  65. package/src/controllers/operator/tenants/_tenantId/disclosures/_id/feeds/controller-v0.8.js +199 -0
  66. package/src/controllers/operator/tenants/_tenantId/disclosures/_id/feeds/schemas/add-feed.schema.js +14 -0
  67. package/src/controllers/operator/tenants/_tenantId/disclosures/_id/feeds/schemas/feed.schema.json +27 -0
  68. package/src/controllers/operator/tenants/_tenantId/disclosures/_id/feeds/schemas/index.js +25 -0
  69. package/src/controllers/operator/tenants/_tenantId/disclosures/_id/feeds/schemas/modify-feed-update-body.schema.js +18 -0
  70. package/src/controllers/operator/tenants/_tenantId/disclosures/_id/feeds/schemas/modify-feed.schema.json +19 -0
  71. package/src/controllers/operator/tenants/_tenantId/disclosures/autohooks.js +34 -0
  72. package/src/controllers/operator/tenants/_tenantId/disclosures/controller-v0.8.js +100 -0
  73. package/src/controllers/operator/tenants/_tenantId/disclosures/schemas/agent-disclosure-presentation-definition.schema.json +404 -0
  74. package/src/controllers/operator/tenants/_tenantId/disclosures/schemas/agent-disclosure.schema.js +24 -0
  75. package/src/controllers/operator/tenants/_tenantId/disclosures/schemas/index.js +29 -0
  76. package/src/controllers/operator/tenants/_tenantId/disclosures/schemas/new-agent-disclosure.schema.json +166 -0
  77. package/src/controllers/operator/tenants/_tenantId/disclosures/schemas/update-agent-disclosure.schema.js +20 -0
  78. package/src/controllers/operator/tenants/_tenantId/exchanges/_exchangeId/autohooks.js +30 -0
  79. package/src/controllers/operator/tenants/_tenantId/exchanges/_exchangeId/controller-v0.8.js +73 -0
  80. package/src/controllers/operator/tenants/_tenantId/exchanges/autohooks.js +19 -0
  81. package/src/controllers/operator/tenants/_tenantId/exchanges/controller-v0.8.js +150 -0
  82. package/src/controllers/operator/tenants/_tenantId/exchanges/schemas/get-exchange.response.body.json +147 -0
  83. package/src/controllers/operator/tenants/_tenantId/exchanges/schemas/index.js +21 -0
  84. package/src/controllers/operator/tenants/_tenantId/issued-credentials/autohooks.js +27 -0
  85. package/src/controllers/operator/tenants/_tenantId/issued-credentials/controller-v0.8.js +303 -0
  86. package/src/controllers/operator/tenants/_tenantId/issued-credentials/schemas/index.js +23 -0
  87. package/src/controllers/operator/tenants/_tenantId/issued-credentials/schemas/issued-credential.schema.json +115 -0
  88. package/src/controllers/operator/tenants/_tenantId/issued-credentials/schemas/revoke-credentials.schema.json +18 -0
  89. package/src/controllers/operator/tenants/_tenantId/keys/controller-v0.8.js +168 -0
  90. package/src/controllers/operator/tenants/_tenantId/offer-data/controller-v0.8.js +78 -0
  91. package/src/controllers/operator/tenants/_tenantId/offers/autohooks.js +34 -0
  92. package/src/controllers/operator/tenants/_tenantId/offers/controller-v0.8.js +253 -0
  93. package/src/controllers/operator/tenants/_tenantId/offers/schemas/index.js +23 -0
  94. package/src/controllers/operator/tenants/_tenantId/offers/schemas/new-vendor-offer.schema.js +47 -0
  95. package/src/controllers/operator/tenants/_tenantId/offers/schemas/vendor-offer.schema.json +56 -0
  96. package/src/controllers/operator/tenants/_tenantId/users/autohooks.js +24 -0
  97. package/src/controllers/operator/tenants/_tenantId/users/controller-v0.8.js +92 -0
  98. package/src/controllers/operator/tenants/_tenantId/users/schemas/index.js +23 -0
  99. package/src/controllers/operator/tenants/_tenantId/users/schemas/new-user.schema.json +13 -0
  100. package/src/controllers/operator/tenants/_tenantId/users/schemas/user.schema.json +16 -0
  101. package/src/controllers/operator/tenants/_tenantId/vc-api/credentials/autohooks.js +34 -0
  102. package/src/controllers/operator/tenants/_tenantId/vc-api/credentials/controller-v0.8.js +110 -0
  103. package/src/controllers/operator/tenants/_tenantId/vc-api/credentials/schemas/Credential.schema.js +18 -0
  104. package/src/controllers/operator/tenants/_tenantId/vc-api/credentials/schemas/IssueCredentialOptions.schema.json +42 -0
  105. package/src/controllers/operator/tenants/_tenantId/vc-api/credentials/schemas/IssueCredentialRequest.schema.json +13 -0
  106. package/src/controllers/operator/tenants/_tenantId/vc-api/credentials/schemas/IssueCredentialResponse.schema.json +19 -0
  107. package/src/controllers/operator/tenants/_tenantId/vc-api/credentials/schemas/LinkedDataProof.schema.json +43 -0
  108. package/src/controllers/operator/tenants/_tenantId/vc-api/credentials/schemas/VerifiableCredential.schema.js +16 -0
  109. package/src/controllers/operator/tenants/_tenantId/vc-api/credentials/schemas/index.js +31 -0
  110. package/src/controllers/operator/tenants/autohooks.js +65 -0
  111. package/src/controllers/operator/tenants/controller-v0.8.js +167 -0
  112. package/src/controllers/operator/tenants/schemas/index.js +41 -0
  113. package/src/controllers/operator/tenants/schemas/modify-secret.schema.json +11 -0
  114. package/src/controllers/operator/tenants/schemas/modify-tenant-v0.8.schema.json +44 -0
  115. package/src/controllers/operator/tenants/schemas/new-tenant-v0.8.schema.json +19 -0
  116. package/src/controllers/operator/tenants/schemas/new-tenant.response.200.schema.json +7 -0
  117. package/src/controllers/operator/tenants/schemas/secret-key-metadata.schema.json +31 -0
  118. package/src/controllers/operator/tenants/schemas/secret-key.schema.json +29 -0
  119. package/src/controllers/operator/tenants/schemas/secret-kid.schema.json +13 -0
  120. package/src/controllers/operator/tenants/schemas/secret-new-tenant-v0.8.schema.json +28 -0
  121. package/src/controllers/operator/tenants/schemas/secret-tenant-key-v0.8.schema.json +13 -0
  122. package/src/controllers/operator/tenants/schemas/tenant-key-v0.8.schema.json +14 -0
  123. package/src/controllers/operator/tenants/schemas/tenant-v0.8.schema.json +62 -0
  124. package/src/controllers/root/autohooks.js +23 -0
  125. package/src/controllers/root/controller.js +173 -0
  126. package/src/controllers/saasoperator/groups/_id/autohooks.js +9 -0
  127. package/src/controllers/saasoperator/groups/_id/controller.js +121 -0
  128. package/src/controllers/saasoperator/groups/autohooks.js +19 -0
  129. package/src/controllers/saasoperator/groups/controller.js +65 -0
  130. package/src/controllers/saasoperator/groups/schemas/group.schema.js +17 -0
  131. package/src/controllers/saasoperator/groups/schemas/index.js +4 -0
  132. package/src/controllers/saasoperator/groups/schemas/new-group.schema.js +13 -0
  133. package/src/entities/common/domains/get-json-at-path.js +28 -0
  134. package/src/entities/common/domains/index.js +17 -0
  135. package/src/entities/common/index.js +17 -0
  136. package/src/entities/credentials/domains/credential-format.js +22 -0
  137. package/src/entities/credentials/domains/index.js +19 -0
  138. package/src/entities/credentials/index.js +17 -0
  139. package/src/entities/deep-links/domains/extract-did.js +11 -0
  140. package/src/entities/deep-links/domains/index.js +20 -0
  141. package/src/entities/deep-links/domains/velocity-protocol-uri-to-http-uri.js +32 -0
  142. package/src/entities/deep-links/index.js +19 -0
  143. package/src/entities/disclosures/domains/assert-disclosure-active.js +21 -0
  144. package/src/entities/disclosures/domains/compute-disclosure-configuration-type.js +29 -0
  145. package/src/entities/disclosures/domains/constants.js +61 -0
  146. package/src/entities/disclosures/domains/errors.js +34 -0
  147. package/src/entities/disclosures/domains/get-disclosure-configuration-type.js +60 -0
  148. package/src/entities/disclosures/domains/index.js +32 -0
  149. package/src/entities/disclosures/domains/is-issuing-disclosure.js +23 -0
  150. package/src/entities/disclosures/domains/parse-body-to-disclosure.js +17 -0
  151. package/src/entities/disclosures/domains/validate-by-identification-method.js +69 -0
  152. package/src/entities/disclosures/domains/validate-commercial-entity.js +26 -0
  153. package/src/entities/disclosures/domains/validate-disclosure-by-configuration-type.js +47 -0
  154. package/src/entities/disclosures/domains/validate-disclosure-default-issuing.js +77 -0
  155. package/src/entities/disclosures/domains/validate-disclosure.js +37 -0
  156. package/src/entities/disclosures/domains/validate-feed.js +16 -0
  157. package/src/entities/disclosures/domains/validate-presentation-definition.js +54 -0
  158. package/src/entities/disclosures/domains/validate-vendor-endpoint.js +22 -0
  159. package/src/entities/disclosures/domains/validate-vendor-webhook.js +18 -0
  160. package/src/entities/disclosures/factories/disclosure-factory.js +94 -0
  161. package/src/entities/disclosures/factories/index.js +19 -0
  162. package/src/entities/disclosures/index.js +22 -0
  163. package/src/entities/disclosures/orchestrators/get-disclosure.js +18 -0
  164. package/src/entities/disclosures/orchestrators/index.js +20 -0
  165. package/src/entities/disclosures/orchestrators/update-disclosure-configuration-type.js +32 -0
  166. package/src/entities/disclosures/repos/index.js +20 -0
  167. package/src/entities/disclosures/repos/repo.js +118 -0
  168. package/src/entities/disclosures/repos/set-configuration-type.js +33 -0
  169. package/src/entities/exchanges/adapters/index.js +17 -0
  170. package/src/entities/exchanges/adapters/sign-exchange-response.js +45 -0
  171. package/src/entities/exchanges/domains/build-exchange-progress.js +56 -0
  172. package/src/entities/exchanges/domains/constants.js +24 -0
  173. package/src/entities/exchanges/domains/ensure-exchange-state-valid.js +35 -0
  174. package/src/entities/exchanges/domains/errors.js +33 -0
  175. package/src/entities/exchanges/domains/index.js +25 -0
  176. package/src/entities/exchanges/domains/states.js +43 -0
  177. package/src/entities/exchanges/domains/types.js +31 -0
  178. package/src/entities/exchanges/factories/disclosure-exchange-factory.js +46 -0
  179. package/src/entities/exchanges/factories/index.js +20 -0
  180. package/src/entities/exchanges/factories/offer-exchange-factory.js +48 -0
  181. package/src/entities/exchanges/index.js +23 -0
  182. package/src/entities/exchanges/orchestrators/build-exchange-request-deep-link.js +50 -0
  183. package/src/entities/exchanges/orchestrators/index.js +19 -0
  184. package/src/entities/exchanges/repos/exchange-repo-projections.js +45 -0
  185. package/src/entities/exchanges/repos/exchange-state-repo-extension.js +76 -0
  186. package/src/entities/exchanges/repos/index.js +20 -0
  187. package/src/entities/exchanges/repos/repo.js +44 -0
  188. package/src/entities/feeds/factories/feed-factory.js +47 -0
  189. package/src/entities/feeds/factories/index.js +19 -0
  190. package/src/entities/feeds/index.js +20 -0
  191. package/src/entities/feeds/repos/index.js +19 -0
  192. package/src/entities/feeds/repos/repo.js +95 -0
  193. package/src/entities/groups/domains/format-group.js +11 -0
  194. package/src/entities/groups/domains/index.js +3 -0
  195. package/src/entities/groups/factories/group-factory.js +40 -0
  196. package/src/entities/groups/factories/index.js +19 -0
  197. package/src/entities/groups/index.js +22 -0
  198. package/src/entities/groups/orchestrators/find-group-or-error.js +16 -0
  199. package/src/entities/groups/orchestrators/index.js +6 -0
  200. package/src/entities/groups/orchestrators/validate-did.js +24 -0
  201. package/src/entities/groups/orchestrators/validate-group-by-user.js +16 -0
  202. package/src/entities/groups/orchestrators/validate-group.js +39 -0
  203. package/src/entities/groups/repos/delete-tenant-extension.js +13 -0
  204. package/src/entities/groups/repos/index.js +19 -0
  205. package/src/entities/groups/repos/repo.js +38 -0
  206. package/src/entities/groups/repos/update-or-error-extension.js +46 -0
  207. package/src/entities/index.js +37 -0
  208. package/src/entities/keys/domains/constants.js +37 -0
  209. package/src/entities/keys/domains/index.js +21 -0
  210. package/src/entities/keys/domains/is-matching-private-key-kid.js +41 -0
  211. package/src/entities/keys/domains/validate-key.js +62 -0
  212. package/src/entities/keys/factories/index.js +19 -0
  213. package/src/entities/keys/factories/key-factory.js +56 -0
  214. package/src/entities/keys/index.js +22 -0
  215. package/src/entities/keys/orchestrators/index.js +3 -0
  216. package/src/entities/keys/orchestrators/validate-did-doc-keys.js +69 -0
  217. package/src/entities/metadata-list-allocations/index.js +19 -0
  218. package/src/entities/metadata-list-allocations/repos/index.js +19 -0
  219. package/src/entities/metadata-list-allocations/repos/repo.js +40 -0
  220. package/src/entities/notifications/domains/index.js +19 -0
  221. package/src/entities/notifications/domains/notification-types.js +25 -0
  222. package/src/entities/notifications/index.js +19 -0
  223. package/src/entities/offers/domains/build-clean-pii-filter.js +35 -0
  224. package/src/entities/offers/domains/build-deeplink-url.js +120 -0
  225. package/src/entities/offers/domains/build-offer.js +88 -0
  226. package/src/entities/offers/domains/build-qr-code-url.js +37 -0
  227. package/src/entities/offers/domains/constants.js +32 -0
  228. package/src/entities/offers/domains/filter-object-ids.js +34 -0
  229. package/src/entities/offers/domains/generate-issuing-challenge.js +26 -0
  230. package/src/entities/offers/domains/generate-link-code.js +35 -0
  231. package/src/entities/offers/domains/index.js +31 -0
  232. package/src/entities/offers/domains/post-validation-offers-handler.js +31 -0
  233. package/src/entities/offers/domains/prepare-linked-credentials-for-holder.js +36 -0
  234. package/src/entities/offers/domains/resolve-subject.js +142 -0
  235. package/src/entities/offers/domains/validate-offer-commercial-entity.js +24 -0
  236. package/src/entities/offers/domains/validate-offer.js +90 -0
  237. package/src/entities/offers/factories/index.js +19 -0
  238. package/src/entities/offers/factories/offer-factory.js +119 -0
  239. package/src/entities/offers/index.js +22 -0
  240. package/src/entities/offers/orchestrators/create-verifiable-credentials.js +131 -0
  241. package/src/entities/offers/orchestrators/finalize-exchange.js +44 -0
  242. package/src/entities/offers/orchestrators/index.js +23 -0
  243. package/src/entities/offers/orchestrators/load-credential-refs.js +57 -0
  244. package/src/entities/offers/orchestrators/load-credential-types-map.js +44 -0
  245. package/src/entities/offers/orchestrators/prepare-offers.js +35 -0
  246. package/src/entities/offers/orchestrators/trigger-issued-credentials-webhook.js +63 -0
  247. package/src/entities/offers/repos/clean-pii-extension.js +85 -0
  248. package/src/entities/offers/repos/index.js +20 -0
  249. package/src/entities/offers/repos/issued-credential-projection.js +44 -0
  250. package/src/entities/offers/repos/repo.js +177 -0
  251. package/src/entities/presentations/domains/build-identity-doc.js +120 -0
  252. package/src/entities/presentations/domains/build-request-response-schema.js +46 -0
  253. package/src/entities/presentations/domains/build-vendor-data.js +31 -0
  254. package/src/entities/presentations/domains/check-payment-requirement.js +30 -0
  255. package/src/entities/presentations/domains/errors.js +28 -0
  256. package/src/entities/presentations/domains/extract-fields-from-id-credential.js +35 -0
  257. package/src/entities/presentations/domains/index.js +26 -0
  258. package/src/entities/presentations/domains/merge-credential-check-results.js +24 -0
  259. package/src/entities/presentations/domains/validate-presentation.js +128 -0
  260. package/src/entities/presentations/index.js +20 -0
  261. package/src/entities/presentations/orchestrators/create-presentation-request.js +148 -0
  262. package/src/entities/presentations/orchestrators/deduplicate-disclosure-exchange.js +52 -0
  263. package/src/entities/presentations/orchestrators/handle-presentation-submission.js +47 -0
  264. package/src/entities/presentations/orchestrators/index.js +20 -0
  265. package/src/entities/presentations/orchestrators/match-identity-on-exchange.js +114 -0
  266. package/src/entities/presentations/orchestrators/share-identification-credentials.js +110 -0
  267. package/src/entities/presentations/orchestrators/share-presentation.js +234 -0
  268. package/src/entities/push-delegate/get-push-delegate.js +37 -0
  269. package/src/entities/push-delegate/index.js +17 -0
  270. package/src/entities/redirect/index.js +3 -0
  271. package/src/entities/redirect/orchestrators/index.js +3 -0
  272. package/src/entities/redirect/orchestrators/load-org-info.js +40 -0
  273. package/src/entities/revocation-list-allocations/index.js +19 -0
  274. package/src/entities/revocation-list-allocations/repos/index.js +19 -0
  275. package/src/entities/revocation-list-allocations/repos/repo.js +40 -0
  276. package/src/entities/schemas/index.js +19 -0
  277. package/src/entities/schemas/orchestrators/index.js +19 -0
  278. package/src/entities/schemas/orchestrators/load-schema-validation.js +73 -0
  279. package/src/entities/tenants/domains/build-service-ids.js +27 -0
  280. package/src/entities/tenants/domains/extract-service.js +27 -0
  281. package/src/entities/tenants/domains/index.js +21 -0
  282. package/src/entities/tenants/domains/validate-service-ids.js +35 -0
  283. package/src/entities/tenants/factories/index.js +19 -0
  284. package/src/entities/tenants/factories/tenant-factory.js +37 -0
  285. package/src/entities/tenants/index.js +22 -0
  286. package/src/entities/tenants/orchestrators/add-primary-address-to-tenant.js +47 -0
  287. package/src/entities/tenants/orchestrators/create-tenant.js +91 -0
  288. package/src/entities/tenants/orchestrators/index.js +22 -0
  289. package/src/entities/tenants/orchestrators/refresh-tenant-dids.js +146 -0
  290. package/src/entities/tenants/orchestrators/set-tenant-default-issuing-disclosure.js +31 -0
  291. package/src/entities/tenants/repos/index.js +20 -0
  292. package/src/entities/tenants/repos/insert-tenant-extension.js +33 -0
  293. package/src/entities/tenants/repos/repo.js +52 -0
  294. package/src/entities/tenants/repos/tenant-default-projection.js +33 -0
  295. package/src/entities/tokens/adapters/access-token.js +49 -0
  296. package/src/entities/tokens/adapters/index.js +19 -0
  297. package/src/entities/tokens/index.js +19 -0
  298. package/src/entities/users/factories/index.js +19 -0
  299. package/src/entities/users/factories/user-factory.js +36 -0
  300. package/src/entities/users/index.js +20 -0
  301. package/src/entities/users/repos/add-anonymous-user-repo-extension.js +23 -0
  302. package/src/entities/users/repos/find-or-insert-vendor-user-repo-extension.js +30 -0
  303. package/src/entities/users/repos/index.js +19 -0
  304. package/src/entities/users/repos/repo.js +50 -0
  305. package/src/fetchers/index.js +20 -0
  306. package/src/fetchers/operator/identify-fetcher.js +36 -0
  307. package/src/fetchers/operator/index.js +21 -0
  308. package/src/fetchers/operator/inspection-fetcher.js +35 -0
  309. package/src/fetchers/operator/issuing-fetcher.js +50 -0
  310. package/src/fetchers/operator/webhook-auth-header.js +45 -0
  311. package/src/fetchers/push-gateway/generate-push-gateway-token.js +40 -0
  312. package/src/fetchers/push-gateway/index.js +19 -0
  313. package/src/fetchers/push-gateway/push-fetcher.js +39 -0
  314. package/src/index.js +19 -0
  315. package/src/init-holder-server.js +108 -0
  316. package/src/init-operator-server.js +101 -0
  317. package/src/init-server.js +120 -0
  318. package/src/main-holder.js +18 -0
  319. package/src/main-operator.js +19 -0
  320. package/src/main.js +18 -0
  321. package/src/plugins/autoload-repos.js +28 -0
  322. package/src/plugins/disclosure-loader-plugin.js +56 -0
  323. package/src/plugins/ensure-disclosure-active-plugin.js +30 -0
  324. package/src/plugins/ensure-disclosure-configuration-type-plugin.js +29 -0
  325. package/src/plugins/ensure-tenant-default-issuing-disclosure-id-plugin.js +60 -0
  326. package/src/plugins/ensure-tenant-primary-address-plugin.js +44 -0
  327. package/src/plugins/exchange-error-handler-plugin.js +51 -0
  328. package/src/plugins/exchange-loader-plugin.js +50 -0
  329. package/src/plugins/group-loader-plugin.js +51 -0
  330. package/src/plugins/index.js +32 -0
  331. package/src/plugins/kms-plugin.js +57 -0
  332. package/src/plugins/tenant-loader-plugin.js +91 -0
  333. package/src/plugins/validate-cao-plugin.js +81 -0
  334. package/src/plugins/vendor-routes-auth-plugin.js +24 -0
  335. package/src/plugins/verify-access-token-plugin.js +88 -0
  336. package/src/standalone.js +24 -0
  337. package/src/start-app-server.js +38 -0
  338. package/test/combined/app-redirect.test.js +199 -0
  339. package/test/combined/helpers/credentialagent-build-fastify.js +29 -0
  340. package/test/combined/helpers/index.js +22 -0
  341. package/test/combined/helpers/nock-registrar-app-schema-name.js +50 -0
  342. package/test/combined/helpers/nock-registrar-get-organization-diddoc.js +26 -0
  343. package/test/combined/helpers/nock-registrar-get-organization-verified-profile.js +33 -0
  344. package/test/combined/manifest.json.test.js +55 -0
  345. package/test/combined/root-controller.test.js +42 -0
  346. package/test/combined/schemas/education-degree.schema.json +166 -0
  347. package/test/combined/schemas/employment-current-v1.1.schema.json +253 -0
  348. package/test/combined/schemas/open-badge-credential.schema.json +1285 -0
  349. package/test/combined/schemas/past-employment-position-with-uri-id.schema.js +22 -0
  350. package/test/combined/schemas/past-employment-position.schema.json +148 -0
  351. package/test/combined/schemas/will-always-validate.json +10 -0
  352. package/test/combined/validate-cao-plugin.test.js +155 -0
  353. package/test/get-push-delegate.test.js +54 -0
  354. package/test/helpers/jwt-vc-expectation.js +109 -0
  355. package/test/holder/build-request-response-schema.test.js +55 -0
  356. package/test/holder/credential-manifest-controller.test.js +3192 -0
  357. package/test/holder/e2e-issuing-controller.test.js +425 -0
  358. package/test/holder/get-exchange-progress-controller.test.js +521 -0
  359. package/test/holder/get-presentation-request.test.js +906 -0
  360. package/test/holder/helpers/credential-type-metadata.js +98 -0
  361. package/test/holder/helpers/credentialagent-holder-build-fastify.js +32 -0
  362. package/test/holder/helpers/generate-presentation.js +441 -0
  363. package/test/holder/helpers/generate-test-access-token.js +54 -0
  364. package/test/holder/helpers/jwt-access-token-expectation.js +32 -0
  365. package/test/holder/helpers/jwt-vc-expectation.js +115 -0
  366. package/test/holder/issuing-controller.test.js +7076 -0
  367. package/test/holder/oauth-token-controller.test.js +412 -0
  368. package/test/holder/presentation-submission.test.js +2365 -0
  369. package/test/holder/submit-identification.test.js +4815 -0
  370. package/test/operator/check-credentials-controller-v0.8.test.js +832 -0
  371. package/test/operator/credentials-revoke.test.js +536 -0
  372. package/test/operator/disclosures-controller-v0.8.test.js +4157 -0
  373. package/test/operator/exchanges-controller-v0.8.test.js +414 -0
  374. package/test/operator/exchanges-id-controller-v0.8.test.js +162 -0
  375. package/test/operator/feeds-controller-v0.8.test.js +659 -0
  376. package/test/operator/generate-push-gateway-token.test.js +116 -0
  377. package/test/operator/groups-controller.test.js +145 -0
  378. package/test/operator/groups-id-controller.test.js +287 -0
  379. package/test/operator/helpers/create-test-org-doc.js +60 -0
  380. package/test/operator/helpers/credentialagent-operator-build-fastify.js +32 -0
  381. package/test/operator/helpers/find-kms-key.js +31 -0
  382. package/test/operator/helpers/generate-primary-and-add-operator-to-primary.js +63 -0
  383. package/test/operator/helpers/init-agent-kms.js +22 -0
  384. package/test/operator/issued-credentials-controller-v0.8.test.js +398 -0
  385. package/test/operator/keys-controller-v0.8.test.js +1130 -0
  386. package/test/operator/offer-data-controller-v0.8.test.js +253 -0
  387. package/test/operator/offers-controller-v0.8.test.js +3026 -0
  388. package/test/operator/set-configuration-type-modifier.test.js +75 -0
  389. package/test/operator/swagger.test.js +37 -0
  390. package/test/operator/tenant-controller-v0.8.test.js +730 -0
  391. package/test/operator/tenant-loader-plugin.test.js +96 -0
  392. package/test/operator/tenants-controller-v0.8.test.js +2093 -0
  393. package/test/operator/users-controller-v0.8.test.js +137 -0
  394. package/test/operator/vc-api-credentials.test.js +963 -0
  395. package/verification.env +28 -0
@@ -0,0 +1,832 @@
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 mockSendPush = jest.fn().mockResolvedValue(undefined);
18
+ const mockVerifyCredentials = jest.fn().mockResolvedValue(undefined);
19
+ // eslint-disable-next-line import/order
20
+ const buildFastify = require('./helpers/credentialagent-operator-build-fastify');
21
+ const { ObjectId } = require('mongodb');
22
+ const { map } = require('lodash/fp');
23
+ const nock = require('nock');
24
+ const { mongoDb } = require('@spencejs/spence-mongo-repos');
25
+ const { KeyPurposes, generateKeyPair } = require('@verii/crypto');
26
+ const { errorResponseMatcher } = require('@verii/tests-helpers');
27
+ const { credentialUnexpired } = require('@verii/sample-data');
28
+ const metadataRegistration = require('@verii/metadata-registration');
29
+ const { CheckResults } = require('@verii/vc-checks');
30
+ const {
31
+ initTenantFactory,
32
+ initKeysFactory,
33
+ initOfferExchangeFactory,
34
+ initDisclosureFactory,
35
+ } = require('../../src/entities');
36
+
37
+ const buildCheckCredentialsUrl = ({ _id }) =>
38
+ `/operator-api/v0.8/tenants/${_id}/check-credentials`;
39
+
40
+ jest.mock('@verii/metadata-registration');
41
+ jest.mock('@verii/verifiable-credentials', () => ({
42
+ verifyCredentials: mockVerifyCredentials,
43
+ }));
44
+ jest.mock('../../src/fetchers', () => ({
45
+ sendPush: mockSendPush,
46
+ }));
47
+
48
+ describe('Credentials checking tests', () => {
49
+ let fastify;
50
+ let persistTenant;
51
+ let persistKey;
52
+ let persistOfferExchange;
53
+ let tenant;
54
+ let persistDisclosure;
55
+
56
+ const checkResult = {
57
+ credential: {
58
+ ...credentialUnexpired,
59
+ issuer: {
60
+ id: '0000',
61
+ name: 'Velocity',
62
+ image: 'https://velocity.com/image.png',
63
+ },
64
+ },
65
+ credentialChecks: {
66
+ TRUSTED_HOLDER: 'NOT_CHECKED',
67
+ TRUSTED_ISSUER: 'NOT_CHECKED',
68
+ UNEXPIRED: 'NOT_CHECKED',
69
+ UNTAMPERED: 'NOT_CHECKED',
70
+ UNREVOKED: 'NOT_CHECKED',
71
+ },
72
+ };
73
+
74
+ beforeAll(async () => {
75
+ fastify = buildFastify();
76
+ await fastify.ready();
77
+ ({ persistTenant } = initTenantFactory(fastify));
78
+ ({ persistKey } = initKeysFactory(fastify));
79
+ ({ persistOfferExchange } = initOfferExchangeFactory(fastify));
80
+ ({ persistDisclosure } = initDisclosureFactory(fastify));
81
+ });
82
+
83
+ beforeEach(async () => {
84
+ nock.cleanAll();
85
+ jest.resetAllMocks();
86
+ await mongoDb().collection('tenants').deleteMany({});
87
+ await mongoDb().collection('keys').deleteMany({});
88
+ await mongoDb().collection('disclosures').deleteMany({});
89
+ await mongoDb().collection('exchanges').deleteMany({});
90
+
91
+ tenant = await persistTenant();
92
+
93
+ nock('http://oracle.localhost.test')
94
+ .get('/api/v0.6/credential-types', () => {
95
+ return true;
96
+ })
97
+ .reply(200, [
98
+ {
99
+ credentialType: 'Passport',
100
+ issuerCategory: 'ContactIssuer',
101
+ },
102
+ ]);
103
+ mockVerifyCredentials.mockImplementationOnce(async ({ credentials }) => {
104
+ switch (credentials[0]) {
105
+ case '0000':
106
+ return Promise.reject(new Error('BAD JWT!'));
107
+ case '0001':
108
+ return Promise.resolve([
109
+ {
110
+ credential: {
111
+ ...credentialUnexpired,
112
+ issuer: {
113
+ id: '0000',
114
+ name: 'Velocity',
115
+ image: 'https://velocity.com/image.png',
116
+ },
117
+ },
118
+ credentialChecks: {
119
+ TRUSTED_HOLDER: CheckResults.FAIL,
120
+ TRUSTED_ISSUER: CheckResults.PASS,
121
+ UNEXPIRED: CheckResults.PASS,
122
+ UNREVOKED: CheckResults.PASS,
123
+ UNTAMPERED: CheckResults.VOUCHER_RESERVE_EXHAUSTED,
124
+ },
125
+ },
126
+ ]);
127
+ default:
128
+ return Promise.resolve([checkResult]);
129
+ }
130
+ });
131
+ metadataRegistration.initRevocationRegistry.mockImplementation(() => ({
132
+ getRevokedStatus: () => Promise.resolve(true),
133
+ }));
134
+ });
135
+
136
+ afterAll(async () => {
137
+ await fastify.close();
138
+ nock.cleanAll();
139
+ nock.restore();
140
+ });
141
+
142
+ it('Should return 400 when request is malformed', async () => {
143
+ const response = await fastify.injectJson({
144
+ method: 'POST',
145
+ url: buildCheckCredentialsUrl(tenant),
146
+ payload: {},
147
+ });
148
+
149
+ expect(response.statusCode).toEqual(400);
150
+ });
151
+
152
+ it("Should return 400 when pushData doesn't not have sendPush", async () => {
153
+ const payload = {
154
+ rawCredentials: [
155
+ {
156
+ id: 'did:velocity:0x0000',
157
+ rawCredential: 'RAW-CREDENTIAL',
158
+ },
159
+ ],
160
+ pushData: {},
161
+ };
162
+ const response = await fastify.injectJson({
163
+ method: 'POST',
164
+ url: buildCheckCredentialsUrl(tenant),
165
+ payload,
166
+ });
167
+
168
+ expect(response.statusCode).toEqual(400);
169
+ expect(response.json.message).toEqual(
170
+ "body/pushData must have required property 'sendPush'"
171
+ );
172
+ });
173
+
174
+ it("Should return 400 when pushData doesn't not have exchangeId", async () => {
175
+ const payload = {
176
+ rawCredentials: [
177
+ {
178
+ id: 'did:velocity:0x0000',
179
+ rawCredential: 'RAW-CREDENTIAL',
180
+ },
181
+ ],
182
+ pushData: {
183
+ sendPush: false,
184
+ },
185
+ };
186
+ const response = await fastify.injectJson({
187
+ method: 'POST',
188
+ url: buildCheckCredentialsUrl(tenant),
189
+ payload,
190
+ });
191
+
192
+ expect(response.statusCode).toEqual(400);
193
+ expect(response.json.message).toEqual(
194
+ "body/pushData must have required property 'exchangeId'"
195
+ );
196
+ });
197
+
198
+ it("Should return 400 when pushData doesn't not have pushUrl", async () => {
199
+ const payload = {
200
+ rawCredentials: [
201
+ {
202
+ id: 'did:velocity:0x0000',
203
+ rawCredential: 'RAW-CREDENTIAL',
204
+ },
205
+ ],
206
+ pushData: {
207
+ sendPush: false,
208
+ exchangeId: '123132',
209
+ pushDelegate: {},
210
+ },
211
+ };
212
+ const response = await fastify.injectJson({
213
+ method: 'POST',
214
+ url: buildCheckCredentialsUrl(tenant),
215
+ payload,
216
+ });
217
+
218
+ expect(response.statusCode).toEqual(400);
219
+ expect(response.json.message).toEqual(
220
+ "body/pushData/pushDelegate must have required property 'pushUrl'"
221
+ );
222
+ });
223
+
224
+ it("Should return 400 when pushData doesn't not have pushToken", async () => {
225
+ const payload = {
226
+ rawCredentials: [
227
+ {
228
+ id: 'did:velocity:0x0000',
229
+ rawCredential: 'RAW-CREDENTIAL',
230
+ },
231
+ ],
232
+ pushData: {
233
+ sendPush: false,
234
+ exchangeId: '123132',
235
+ pushDelegate: {
236
+ pushUrl: 'token',
237
+ },
238
+ },
239
+ };
240
+ const response = await fastify.injectJson({
241
+ method: 'POST',
242
+ url: buildCheckCredentialsUrl(tenant),
243
+ payload,
244
+ });
245
+
246
+ expect(response.statusCode).toEqual(400);
247
+ expect(response.json.message).toEqual(
248
+ "body/pushData/pushDelegate must have required property 'pushToken'"
249
+ );
250
+ });
251
+
252
+ it('Should return 500 when credential is not a valid JWT', async () => {
253
+ const keyPair = generateKeyPair({ format: 'jwk' });
254
+
255
+ await persistKey({
256
+ tenant,
257
+ kidFragment: '#ID1',
258
+ keyPair,
259
+ purposes: [KeyPurposes.DLT_TRANSACTIONS],
260
+ });
261
+
262
+ const payload = {
263
+ rawCredentials: [
264
+ {
265
+ id: 'did:velocity:0x0000',
266
+ rawCredential: '0000',
267
+ },
268
+ ],
269
+ };
270
+
271
+ const response = await fastify.injectJson({
272
+ method: 'POST',
273
+ url: buildCheckCredentialsUrl(tenant),
274
+ payload,
275
+ });
276
+
277
+ expect(mockSendPush).toBeCalledTimes(0);
278
+ expect(response.statusCode).toEqual(500);
279
+ });
280
+
281
+ it('Should return credential checks results when credential JWT is valid', async () => {
282
+ const keyPair = generateKeyPair({ format: 'jwk' });
283
+
284
+ const key = await persistKey({
285
+ tenant,
286
+ kidFragment: '#ID1',
287
+ keyPair,
288
+ purposes: [KeyPurposes.DLT_TRANSACTIONS],
289
+ });
290
+
291
+ const payload = {
292
+ rawCredentials: [
293
+ {
294
+ id: 'did:velocity:0x0000',
295
+ rawCredential: 'RAW-CREDENTIAL',
296
+ },
297
+ ],
298
+ };
299
+
300
+ const response = await fastify.injectJson({
301
+ method: 'POST',
302
+ url: buildCheckCredentialsUrl(tenant),
303
+ payload,
304
+ });
305
+
306
+ expect(mockSendPush).toBeCalledTimes(0);
307
+ expect(mockVerifyCredentials.mock.calls).toEqual([
308
+ [
309
+ {
310
+ credentials: map('rawCredential', payload.rawCredentials),
311
+ relyingParty: { dltOperatorKMSKeyId: new ObjectId(key._id) },
312
+ },
313
+ {
314
+ resolveDid: expect.any(Function),
315
+ getOrganizationVerifiedProfile: expect.any(Function),
316
+ getCredentialTypeMetadata: expect.any(Function),
317
+ },
318
+ expect.any(Object),
319
+ ],
320
+ ]);
321
+
322
+ expect(response.statusCode).toEqual(200);
323
+ expect(response.json.credentials[0].credentialChecks).toEqual(
324
+ checkResult.credentialChecks
325
+ );
326
+ });
327
+
328
+ it('Should return credential checks and not send pushNotification if pushData is present (sendPush is false)', async () => {
329
+ const keyPair = generateKeyPair({ format: 'jwk' });
330
+
331
+ await persistKey({
332
+ tenant,
333
+ kidFragment: '#ID1',
334
+ keyPair,
335
+ purposes: [KeyPurposes.DLT_TRANSACTIONS],
336
+ });
337
+
338
+ const pushDelegate = {
339
+ pushUrl: 'urls',
340
+ pushToken: 'token',
341
+ };
342
+
343
+ const payload = {
344
+ rawCredentials: [
345
+ {
346
+ id: 'did:velocity:0x0000',
347
+ rawCredential: 'RAW-CREDENTIAL',
348
+ },
349
+ ],
350
+ pushData: {
351
+ sendPush: false,
352
+ exchangeId: '123123',
353
+ pushDelegate,
354
+ },
355
+ };
356
+
357
+ const response = await fastify.injectJson({
358
+ method: 'POST',
359
+ url: buildCheckCredentialsUrl(tenant),
360
+ payload,
361
+ });
362
+
363
+ expect(mockSendPush).toBeCalledTimes(0);
364
+
365
+ expect(response.statusCode).toEqual(200);
366
+ expect(response.json.credentials[0].credentialChecks).toEqual(
367
+ checkResult.credentialChecks
368
+ );
369
+ });
370
+ it('Should return credential checks and send pushNotification if pushData is present (sendPush is true)', async () => {
371
+ const keyPair = generateKeyPair({ format: 'jwk' });
372
+ const { did } = tenant;
373
+
374
+ await persistKey({
375
+ tenant,
376
+ kidFragment: '#ID1',
377
+ keyPair,
378
+ purposes: [KeyPurposes.DLT_TRANSACTIONS],
379
+ });
380
+
381
+ const pushDelegate = {
382
+ pushUrl: 'urls',
383
+ pushToken: 'token',
384
+ };
385
+
386
+ const payload = {
387
+ rawCredentials: [
388
+ {
389
+ id: 'did:velocity:0x0000',
390
+ rawCredential: 'RAW-CREDENTIAL',
391
+ },
392
+ ],
393
+ pushData: {
394
+ sendPush: true,
395
+ exchangeId: '123123',
396
+ pushDelegate,
397
+ },
398
+ };
399
+
400
+ const response = await fastify.injectJson({
401
+ method: 'POST',
402
+ url: buildCheckCredentialsUrl(tenant),
403
+ payload,
404
+ });
405
+
406
+ expect(mockSendPush).toBeCalledTimes(1);
407
+ expect(mockSendPush).toBeCalledWith(
408
+ {
409
+ data: {
410
+ exchangeId: '123123',
411
+ issuer: did,
412
+ notificationType: 'PresentationVerified',
413
+ serviceEndpoint: 'urls',
414
+ },
415
+ id: expect.any(String),
416
+ pushToken: 'token',
417
+ },
418
+ pushDelegate,
419
+ expect.any(Object)
420
+ );
421
+
422
+ expect(response.statusCode).toEqual(200);
423
+ expect(response.json.credentials[0].credentialChecks).toEqual(
424
+ checkResult.credentialChecks
425
+ );
426
+ });
427
+ it('Should send pushNotification if pushData is true but disclosure is true', async () => {
428
+ const keyPair = generateKeyPair({ format: 'jwk' });
429
+
430
+ const pushDelegate = {
431
+ pushUrl: 'urls',
432
+ pushToken: 'token',
433
+ };
434
+
435
+ const disclosure = await persistDisclosure({
436
+ tenant,
437
+ sendPushOnVerification: false,
438
+ });
439
+ const exchange = await persistOfferExchange({
440
+ tenant,
441
+ disclosure,
442
+ pushDelegate,
443
+ });
444
+
445
+ await persistKey({
446
+ tenant,
447
+ kidFragment: '#ID1',
448
+ keyPair,
449
+ purposes: [KeyPurposes.DLT_TRANSACTIONS],
450
+ });
451
+
452
+ const payload = {
453
+ rawCredentials: [
454
+ {
455
+ id: 'did:velocity:0x0000',
456
+ rawCredential: 'RAW-CREDENTIAL',
457
+ },
458
+ ],
459
+ pushData: {
460
+ sendPush: true,
461
+ exchangeId: exchange._id,
462
+ pushDelegate,
463
+ },
464
+ };
465
+
466
+ const response = await fastify.injectJson({
467
+ method: 'POST',
468
+ url: buildCheckCredentialsUrl(tenant),
469
+ payload,
470
+ });
471
+
472
+ expect(mockSendPush).toBeCalledTimes(0);
473
+
474
+ expect(response.statusCode).toEqual(200);
475
+ expect(response.json.credentials[0].credentialChecks).toEqual(
476
+ checkResult.credentialChecks
477
+ );
478
+ });
479
+ it('Should send pushNotification if pushData is false but disclosure is true', async () => {
480
+ const keyPair = generateKeyPair({ format: 'jwk' });
481
+ const { did } = tenant;
482
+
483
+ const pushDelegate = {
484
+ pushUrl: 'urls',
485
+ pushToken: 'token',
486
+ };
487
+
488
+ const disclosure = await persistDisclosure({
489
+ tenant,
490
+ sendPushOnVerification: true,
491
+ });
492
+ const exchange = await persistOfferExchange({
493
+ tenant,
494
+ disclosure,
495
+ pushDelegate,
496
+ });
497
+
498
+ await persistKey({
499
+ tenant,
500
+ kidFragment: '#ID1',
501
+ keyPair,
502
+ purposes: [KeyPurposes.DLT_TRANSACTIONS],
503
+ });
504
+
505
+ const payload = {
506
+ rawCredentials: [
507
+ {
508
+ id: 'did:velocity:0x0000',
509
+ rawCredential: 'RAW-CREDENTIAL',
510
+ },
511
+ ],
512
+ pushData: {
513
+ sendPush: true,
514
+ exchangeId: exchange._id,
515
+ pushDelegate,
516
+ },
517
+ };
518
+
519
+ const response = await fastify.injectJson({
520
+ method: 'POST',
521
+ url: buildCheckCredentialsUrl(tenant),
522
+ payload,
523
+ });
524
+
525
+ expect(mockSendPush).toBeCalledTimes(1);
526
+ expect(mockSendPush).toBeCalledWith(
527
+ {
528
+ data: {
529
+ exchangeId: exchange._id,
530
+ issuer: did,
531
+ notificationType: 'PresentationVerified',
532
+ serviceEndpoint: 'urls',
533
+ },
534
+ id: expect.any(String),
535
+ pushToken: 'token',
536
+ },
537
+ pushDelegate,
538
+ expect.any(Object)
539
+ );
540
+
541
+ expect(response.statusCode).toEqual(200);
542
+ expect(response.json.credentials[0].credentialChecks).toEqual(
543
+ checkResult.credentialChecks
544
+ );
545
+ });
546
+ it('Should send pushNotification if pushData is false but disclosure is true and disclosure does not have', async () => {
547
+ const keyPair = generateKeyPair({ format: 'jwk' });
548
+ const { did } = tenant;
549
+
550
+ const pushDelegate = {
551
+ pushUrl: 'urls',
552
+ pushToken: 'token',
553
+ };
554
+
555
+ const disclosure = await persistDisclosure({
556
+ tenant,
557
+ sendPushOnVerification: true,
558
+ });
559
+ const exchange = await persistOfferExchange({
560
+ tenant,
561
+ disclosure,
562
+ pushDelegate,
563
+ });
564
+
565
+ await persistKey({
566
+ tenant,
567
+ kidFragment: '#ID1',
568
+ keyPair,
569
+ purposes: [KeyPurposes.DLT_TRANSACTIONS],
570
+ });
571
+
572
+ const payload = {
573
+ rawCredentials: [
574
+ {
575
+ id: 'did:velocity:0x0000',
576
+ rawCredential: 'RAW-CREDENTIAL',
577
+ },
578
+ ],
579
+ pushData: {
580
+ sendPush: true,
581
+ exchangeId: exchange._id,
582
+ pushDelegate,
583
+ },
584
+ };
585
+
586
+ const response = await fastify.injectJson({
587
+ method: 'POST',
588
+ url: buildCheckCredentialsUrl(tenant),
589
+ payload,
590
+ });
591
+
592
+ expect(mockSendPush).toBeCalledTimes(1);
593
+ expect(mockSendPush).toBeCalledWith(
594
+ {
595
+ data: {
596
+ exchangeId: exchange._id,
597
+ issuer: did,
598
+ notificationType: 'PresentationVerified',
599
+ serviceEndpoint: 'urls',
600
+ },
601
+ id: expect.any(String),
602
+ pushToken: 'token',
603
+ },
604
+ pushDelegate,
605
+ expect.any(Object)
606
+ );
607
+
608
+ expect(response.statusCode).toEqual(200);
609
+ expect(response.json.credentials[0].credentialChecks).toEqual(
610
+ checkResult.credentialChecks
611
+ );
612
+ });
613
+ it('Should not send pushNotification if pushData is true and sendPushOnVerification is not present', async () => {
614
+ const keyPair = generateKeyPair({ format: 'jwk' });
615
+ const { did } = tenant;
616
+
617
+ const pushDelegate = {
618
+ pushUrl: 'urls',
619
+ pushToken: 'token',
620
+ };
621
+
622
+ const disclosure = await persistDisclosure({ tenant });
623
+ const exchange = await persistOfferExchange({
624
+ tenant,
625
+ disclosure,
626
+ pushDelegate,
627
+ });
628
+
629
+ await mongoDb()
630
+ .collection('disclosures')
631
+ .updateOne(
632
+ { _id: new ObjectId(disclosure._id) },
633
+ { $unset: { sendPushOnVerification: '' } }
634
+ );
635
+
636
+ await persistKey({
637
+ tenant,
638
+ kidFragment: '#ID1',
639
+ keyPair,
640
+ purposes: [KeyPurposes.DLT_TRANSACTIONS],
641
+ });
642
+
643
+ const payload = {
644
+ rawCredentials: [
645
+ {
646
+ id: 'did:velocity:0x0000',
647
+ rawCredential: 'RAW-CREDENTIAL',
648
+ },
649
+ ],
650
+ pushData: {
651
+ sendPush: true,
652
+ exchangeId: exchange._id,
653
+ pushDelegate,
654
+ },
655
+ };
656
+
657
+ const response = await fastify.injectJson({
658
+ method: 'POST',
659
+ url: buildCheckCredentialsUrl(tenant),
660
+ payload,
661
+ });
662
+
663
+ expect(mockSendPush).toBeCalledTimes(1);
664
+ expect(mockSendPush).toBeCalledWith(
665
+ {
666
+ data: {
667
+ exchangeId: exchange._id,
668
+ issuer: did,
669
+ notificationType: 'PresentationVerified',
670
+ serviceEndpoint: 'urls',
671
+ },
672
+ id: expect.any(String),
673
+ pushToken: 'token',
674
+ },
675
+ pushDelegate,
676
+ expect.any(Object)
677
+ );
678
+
679
+ expect(response.statusCode).toEqual(200);
680
+ expect(response.json.credentials[0].credentialChecks).toEqual(
681
+ checkResult.credentialChecks
682
+ );
683
+ });
684
+ it('Should not send pushNotification sendPushOnVerification is true and has corrupted pushDelegate', async () => {
685
+ const keyPair = generateKeyPair({ format: 'jwk' });
686
+
687
+ const pushDelegate = {
688
+ pushUrl: 'urls',
689
+ pushToken: 'token',
690
+ };
691
+
692
+ const disclosure = await persistDisclosure({
693
+ tenant,
694
+ sendPushOnVerification: true,
695
+ });
696
+ const exchange = await persistOfferExchange({
697
+ tenant,
698
+ disclosure,
699
+ pushDelegate: {
700
+ pushUrl: 'urla',
701
+ },
702
+ });
703
+
704
+ await persistKey({
705
+ tenant,
706
+ kidFragment: '#ID1',
707
+ keyPair,
708
+ purposes: [KeyPurposes.DLT_TRANSACTIONS],
709
+ });
710
+
711
+ const payload = {
712
+ rawCredentials: [
713
+ {
714
+ id: 'did:velocity:0x0000',
715
+ rawCredential: 'RAW-CREDENTIAL',
716
+ },
717
+ ],
718
+ pushData: {
719
+ sendPush: false,
720
+ exchangeId: exchange._id,
721
+ pushDelegate,
722
+ },
723
+ };
724
+
725
+ const response = await fastify.injectJson({
726
+ method: 'POST',
727
+ url: buildCheckCredentialsUrl(tenant),
728
+ payload,
729
+ });
730
+
731
+ expect(mockSendPush).toBeCalledTimes(0);
732
+
733
+ expect(response.statusCode).toEqual(200);
734
+ expect(response.json.credentials[0].credentialChecks).toEqual(
735
+ checkResult.credentialChecks
736
+ );
737
+ });
738
+ it('Should send pushNotification sendPushOnVerification is true and has corrupted pushDelegate and pushData is correct', async () => {
739
+ const keyPair = generateKeyPair({ format: 'jwk' });
740
+
741
+ const pushDelegate = {
742
+ pushUrl: 'urls',
743
+ pushToken: 'token',
744
+ };
745
+
746
+ const disclosure = await persistDisclosure({
747
+ tenant,
748
+ sendPushOnVerification: true,
749
+ });
750
+ const exchange = await persistOfferExchange({
751
+ tenant,
752
+ disclosure,
753
+ pushDelegate: {
754
+ pushUrl: 'urla',
755
+ },
756
+ });
757
+
758
+ await persistKey({
759
+ tenant,
760
+ kidFragment: '#ID1',
761
+ keyPair,
762
+ purposes: [KeyPurposes.DLT_TRANSACTIONS],
763
+ });
764
+
765
+ const payload = {
766
+ rawCredentials: [
767
+ {
768
+ id: 'did:velocity:0x0000',
769
+ rawCredential: 'RAW-CREDENTIAL',
770
+ },
771
+ ],
772
+ pushData: {
773
+ sendPush: true,
774
+ exchangeId: exchange._id,
775
+ pushDelegate,
776
+ },
777
+ };
778
+
779
+ const response = await fastify.injectJson({
780
+ method: 'POST',
781
+ url: buildCheckCredentialsUrl(tenant),
782
+ payload,
783
+ });
784
+
785
+ expect(mockSendPush).toBeCalledTimes(1);
786
+
787
+ expect(response.statusCode).toEqual(200);
788
+ expect(response.json.credentials[0].issuer).toEqual({
789
+ id: '0000',
790
+ name: 'Velocity',
791
+ image: 'https://velocity.com/image.png',
792
+ });
793
+ expect(response.json.credentials[0].credentialChecks).toEqual(
794
+ checkResult.credentialChecks
795
+ );
796
+ });
797
+
798
+ it('Should return 402 when a coupon was not provided', async () => {
799
+ const keyPair = generateKeyPair({ format: 'jwk' });
800
+
801
+ await persistKey({
802
+ tenant,
803
+ kidFragment: '#ID1',
804
+ keyPair,
805
+ purposes: [KeyPurposes.DLT_TRANSACTIONS],
806
+ });
807
+
808
+ const payload = {
809
+ rawCredentials: [
810
+ {
811
+ id: 'did:velocity:0x0000',
812
+ rawCredential: '0001',
813
+ },
814
+ ],
815
+ };
816
+
817
+ const response = await fastify.injectJson({
818
+ method: 'POST',
819
+ url: buildCheckCredentialsUrl(tenant),
820
+ payload,
821
+ });
822
+
823
+ expect(response.json).toEqual(
824
+ errorResponseMatcher({
825
+ error: 'Bad Request',
826
+ errorCode: 'payment_required',
827
+ message: 'No voucher was provided to process the request',
828
+ statusCode: 400,
829
+ })
830
+ );
831
+ });
832
+ });