@velocitycareerlabs/server-careerwallet 1.25.0-dev-build.12642c864

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (252) hide show
  1. package/.localdev.env +47 -0
  2. package/.standalone.env +13 -0
  3. package/LICENSE +248 -0
  4. package/jest.config.js +20 -0
  5. package/migrate-mongo.config.js +25 -0
  6. package/migrations/20211017180227-create-personas.js +478 -0
  7. package/migrations/20211026185916-create-vanessa.js +79 -0
  8. package/migrations/20211026185917-update-personas.js +30 -0
  9. package/migrations/20211108124410-remove-surplus-personas.js +33 -0
  10. package/migrations/20211108132353-fix-vanessa-and-sheila.js +25 -0
  11. package/migrations/20220222123110-add-career-wallet-app-config.js +6 -0
  12. package/migrations/20220411104157-add-min-app-versions.js +15 -0
  13. package/migrations/20220419131726-create-nicole-flores-persona.js +63 -0
  14. package/migrations/20220515114034-update-persona-id-credentials.js +628 -0
  15. package/migrations/20220608093743-disable-mainnet-holderapp-id-verification.js +21 -0
  16. package/migrations/20220609063708-enable-mainnet-holderapp-id-verification.js +21 -0
  17. package/migrations/20220623091507-add-push-url.js +43 -0
  18. package/migrations/20220624133205-set-min-app-versions-to-11.js +16 -0
  19. package/migrations/20220710125326-set-min-app-version-to-0.10.7.js +16 -0
  20. package/migrations/20220811103500-add-verification-service-disclosure-deeplink.js +45 -0
  21. package/migrations/20220811123751-add-holderapp-dids-to-config.js +74 -0
  22. package/migrations/20220818072306-add-holderapp-endpoints-to-config.js +21 -0
  23. package/migrations/20220825090656-update-deeplink.js +46 -0
  24. package/migrations/20221003151823-app-config-add-public-verification-api.js +18 -0
  25. package/migrations/20221116085242-add-holderapp-sdk-to-config.js +15 -0
  26. package/migrations/20221121091030-update-holderapp-deeplink.js +19 -0
  27. package/migrations/20221128103425-update-holderapp-presentation-template.js +19 -0
  28. package/migrations/20221221091436-app-config-add-oauth.js +13 -0
  29. package/migrations/20221226205900-app-config-add-presentation-extension-api.js +18 -0
  30. package/migrations/20230120113141-update-holderapp-cashSiquence.js +15 -0
  31. package/migrations/20230123084103-update-holderapp-cacheSequence.js +15 -0
  32. package/migrations/20230214083430-update-holderapp-cache-Sequence.js +15 -0
  33. package/migrations/20230225173335-set-min-app-version-1.5.1.js +30 -0
  34. package/migrations/20230323120629-add-sunil-singh-persona.js +87 -0
  35. package/migrations/20230329081529-add-personas-by-env.js +294 -0
  36. package/migrations/20230329103219-remove-unused-personas.js +14 -0
  37. package/migrations/20230504090208-disable-yoti-migration.js +21 -0
  38. package/migrations/20230504123425-set-min-app-version-1.8.1.js +38 -0
  39. package/migrations/20230504185047-enable-yoti-migration.js +21 -0
  40. package/migrations/20230524053203-add-devices-index.js +16 -0
  41. package/migrations/20230704000002-add-common-holder-endpoints-to-config.js +16 -0
  42. package/migrations/20230704000003-add-linkedin-holder-endpoints-to-config.js +18 -0
  43. package/migrations/20230704104055-update-push-url-and-yoti-url.js +18 -0
  44. package/migrations/20230705000001-add-liburl-to-holderapp-config.js +20 -0
  45. package/migrations/20230814113134-app-config-add-oauth-client-id.js +18 -0
  46. package/migrations/20230821154136-yoti-new-session-url-fix.js +19 -0
  47. package/migrations/20230907134442-update-holderapp-cache-Sequence.js +15 -0
  48. package/migrations/20230919180000-set-holderapp-min-app-versions-1.15.0.js +16 -0
  49. package/migrations/20231011083137-update-holderapp-cache-sequence-6.js +15 -0
  50. package/migrations/20231102083252-set-holderapp-min-app-versions-1.14.0.js +16 -0
  51. package/migrations/20231108202229-set-holderapp-min-app-versions-1.15.0.js +16 -0
  52. package/migrations/20231115143332-holderapp-isDirectIssuerCheckOn-true.js +16 -0
  53. package/migrations/20231120100020-insert-didKeyMetadatum-for-old-accounts.js +59 -0
  54. package/migrations/20231207142742-remove-devices-from-accounts.js +46 -0
  55. package/migrations/20231226090805-app-config-set-direct-issuer-check.js +13 -0
  56. package/migrations/202312271524-set-holderapp-app-version-1.15.1.js +16 -0
  57. package/migrations/20232211171700-app-config-update-base-urls.js +18 -0
  58. package/migrations/20240102093506-holderapp-revert-version-1.15.0.js +16 -0
  59. package/migrations/202401041618111-holderapp-isDebugOn-false.js +17 -0
  60. package/migrations/20240131095122-test-personas-add-did.js +102 -0
  61. package/migrations/202402051547000-update-sdk.js +18 -0
  62. package/migrations/20240206101448-update-personas-vc-to-v2.js +137 -0
  63. package/migrations/202402061233000-set-xVnfProtocolVersion-2.js +13 -0
  64. package/migrations/202402081240000-set-xVnfProtocolVersion-1.js +13 -0
  65. package/migrations/202402131319-set-holderapp-min-versions-1.17.js +16 -0
  66. package/migrations/202402141152-set-holderapp-min-version-1.16.js +16 -0
  67. package/migrations/20240221123501-transform-account-keys-to-stringified-jwk.js +81 -0
  68. package/migrations/202402290955-update-holderapp-to-verifyMyCreds.js +36 -0
  69. package/migrations/20240311134223-update-keyid-persona.js +66 -0
  70. package/migrations/20240312141618-vl-7409-persona-update-maria-williams.js +82 -0
  71. package/migrations/202403181733000-remove-devices-from-all-accounts.js +27 -0
  72. package/migrations/20240401091041-set-holderapp-min-version-1.18.1.js +16 -0
  73. package/migrations/202404071847-app-config-update-yoti-url.js +19 -0
  74. package/migrations/20240724063405-vl-3827-new-yoti-session-url.js +19 -0
  75. package/migrations/20240731112302-vl-8160-add-persona-keys.js +101 -0
  76. package/migrations/20240911115206-vanessa-lin-id-credentials.js +57 -0
  77. package/migrations/202409201219-add-isWalletAvailable-field.js +13 -0
  78. package/migrations/202409221012-set-isWalletAvailable-true.js +13 -0
  79. package/migrations/20240922114643-holderapp-isWalletAvailable-refactor.js +36 -0
  80. package/migrations/20240923132213-update-android-ios-app-config.js +36 -0
  81. package/migrations/20240926061732-inc-cacheSequence-to-7.js +15 -0
  82. package/migrations/20240926073339-inc-cacheSequence-to-7-fix.js +18 -0
  83. package/migrations/202410081217-adam-smith-id-credntials.js +57 -0
  84. package/migrations/202410101243-adam_smith-id-credential.js +57 -0
  85. package/migrations/20241015124307-persona-key-id-type-fix.js +26 -0
  86. package/migrations/202501291027000-set-holderapp-did-web.js +37 -0
  87. package/migrations/environments/dev.env +34 -0
  88. package/migrations/environments/localdev.env +22 -0
  89. package/migrations/environments/prod.env +18 -0
  90. package/migrations/environments/qa.env +54 -0
  91. package/migrations/environments/staging.env +31 -0
  92. package/migrations/environments/test.env +18 -0
  93. package/package.json +84 -0
  94. package/src/assets/category-icons/assessment.png +0 -0
  95. package/src/assets/category-icons/badge.png +0 -0
  96. package/src/assets/category-icons/certification.png +0 -0
  97. package/src/assets/category-icons/education.png +0 -0
  98. package/src/assets/category-icons/employment.png +0 -0
  99. package/src/assets/category-icons/gig.png +0 -0
  100. package/src/assets/category-icons/identity.png +0 -0
  101. package/src/assets/category-icons/pharmacy.png +0 -0
  102. package/src/assets/category-icons/training.png +0 -0
  103. package/src/assets/credentialCategories.json +119 -0
  104. package/src/config/config.js +156 -0
  105. package/src/controllers/api/v0.6/accounts/autohooks.js +36 -0
  106. package/src/controllers/api/v0.6/accounts/controller.js +288 -0
  107. package/src/controllers/api/v0.6/accounts/schemas/careerwallet-accounts-didkeymetadatum-response.schema.js +41 -0
  108. package/src/controllers/api/v0.6/accounts/schemas/careerwallet-accounts-request.schema.js +49 -0
  109. package/src/controllers/api/v0.6/accounts/schemas/careerwallet-accounts-response.schema.js +74 -0
  110. package/src/controllers/api/v0.6/accounts/schemas/careerwallet-get-account-response.schema.js +72 -0
  111. package/src/controllers/api/v0.6/accounts/schemas/index.js +6 -0
  112. package/src/controllers/api/v0.6/careerwallet/appconfig/controller.js +25 -0
  113. package/src/controllers/api/v0.6/careerwallet/appconfig/repo.js +40 -0
  114. package/src/controllers/api/v0.6/careerwallet/autohooks.js +5 -0
  115. package/src/controllers/api/v0.6/careerwallet/consents/controller.js +66 -0
  116. package/src/controllers/api/v0.6/careerwallet/consents/latest/autohooks.js +7 -0
  117. package/src/controllers/api/v0.6/careerwallet/consents/latest/controller.js +76 -0
  118. package/src/controllers/api/v0.6/careerwallet/consents/repo.js +24 -0
  119. package/src/controllers/api/v0.6/careerwallet/consents/schemas/careerwallet-consent-response.schema.js +23 -0
  120. package/src/controllers/api/v0.6/careerwallet/consents/schemas/index.js +3 -0
  121. package/src/controllers/api/v0.6/create_did_key/autohooks.js +10 -0
  122. package/src/controllers/api/v0.6/create_did_key/controller.js +84 -0
  123. package/src/controllers/api/v0.6/create_did_key/schemas/index.js +4 -0
  124. package/src/controllers/api/v0.6/create_did_key/schemas/jwk-did-request.schema.js +20 -0
  125. package/src/controllers/api/v0.6/create_did_key/schemas/jwk-did-response.schema.js +41 -0
  126. package/src/controllers/api/v0.6/create_jwk/autohooks.js +10 -0
  127. package/src/controllers/api/v0.6/create_jwk/controller.js +46 -0
  128. package/src/controllers/api/v0.6/create_jwk/schemas/index.js +3 -0
  129. package/src/controllers/api/v0.6/create_jwk/schemas/jwk-response.schema.js +33 -0
  130. package/src/controllers/api/v0.6/credential-categories/controller.js +35 -0
  131. package/src/controllers/api/v0.6/devices/autohooks.js +11 -0
  132. package/src/controllers/api/v0.6/devices/controller.js +323 -0
  133. package/src/controllers/api/v0.6/devices/repo.js +27 -0
  134. package/src/controllers/api/v0.6/devices/schemas/device.schema.json +43 -0
  135. package/src/controllers/api/v0.6/devices/schemas/index.js +3 -0
  136. package/src/controllers/api/v0.6/feedback/controller.js +24 -0
  137. package/src/controllers/api/v0.6/feedback/schemas/index.js +3 -0
  138. package/src/controllers/api/v0.6/feedback/schemas/new-feedback.schema.js +47 -0
  139. package/src/controllers/api/v0.6/jwt/autohooks.js +10 -0
  140. package/src/controllers/api/v0.6/jwt/controller.js +44 -0
  141. package/src/controllers/api/v0.6/jwt/schemas/index.js +4 -0
  142. package/src/controllers/api/v0.6/jwt/schemas/jwt-request.schema.js +40 -0
  143. package/src/controllers/api/v0.6/jwt/schemas/jwt-response.schema.js +14 -0
  144. package/src/controllers/api/v0.6/oauth/controller.js +131 -0
  145. package/src/controllers/api/v0.6/push/controller.js +296 -0
  146. package/src/controllers/api/v0.6/push/firebase-initializer.js +21 -0
  147. package/src/controllers/api/v0.6/push/notification-types.js +37 -0
  148. package/src/controllers/api/v0.6/push/push-gateway-auth.js +123 -0
  149. package/src/controllers/api/v0.6/push/repo.js +24 -0
  150. package/src/controllers/api/v0.6/verification-offers/repo.js +25 -0
  151. package/src/controllers/api/v0.6/verify/autohooks.js +15 -0
  152. package/src/controllers/api/v0.6/verify/controller.js +348 -0
  153. package/src/controllers/api/v0.6/verify/repo.js +23 -0
  154. package/src/controllers/api/v0.6/verify/verification-credential-types.js +6 -0
  155. package/src/controllers/jwt/autohooks.js +10 -0
  156. package/src/controllers/jwt/controller.js +106 -0
  157. package/src/controllers/jwt/schemas/index.js +31 -0
  158. package/src/controllers/jwt/schemas/jwt-decode.response.200.schema.json +20 -0
  159. package/src/controllers/jwt/schemas/jwt-decode.schema.json +15 -0
  160. package/src/controllers/jwt/schemas/jwt-sign.response.200.schema.json +14 -0
  161. package/src/controllers/jwt/schemas/jwt-sign.schema.json +40 -0
  162. package/src/controllers/jwt/schemas/jwt-verify.response.200.schema.json +17 -0
  163. package/src/controllers/jwt/schemas/jwt-verify.schema.json +19 -0
  164. package/src/controllers/reference/autohooks.js +5 -0
  165. package/src/controllers/reference/countries/controller.js +81 -0
  166. package/src/controllers/reference/personas/controller.js +91 -0
  167. package/src/controllers/reference/personas/repo.js +29 -0
  168. package/src/controllers/reference/personas/schemas/index.js +3 -0
  169. package/src/controllers/reference/personas/schemas/persona.schema.json +108 -0
  170. package/src/controllers/root/controller.js +27 -0
  171. package/src/entities/accounts/constants.js +18 -0
  172. package/src/entities/accounts/domain/index.js +3 -0
  173. package/src/entities/accounts/domain/merge-scopes.js +9 -0
  174. package/src/entities/accounts/index.js +5 -0
  175. package/src/entities/accounts/repos/accounts.repo.js +64 -0
  176. package/src/entities/accounts/repos/id-token-claims-extension.js +31 -0
  177. package/src/entities/accounts/repos/index.js +3 -0
  178. package/src/entities/devices/constants.js +7 -0
  179. package/src/entities/devices/index.js +3 -0
  180. package/src/entities/feedback/domain/generate-feedback-email.js +23 -0
  181. package/src/entities/feedback/domain/index.js +3 -0
  182. package/src/entities/feedback/index.js +3 -0
  183. package/src/entities/index.js +9 -0
  184. package/src/entities/key-pairs/index.js +4 -0
  185. package/src/entities/key-pairs/orchestrators/generate-jwk.js +28 -0
  186. package/src/entities/key-pairs/orchestrators/get-key-pair.js +58 -0
  187. package/src/entities/key-pairs/orchestrators/index.js +4 -0
  188. package/src/entities/key-pairs/repos/index.js +3 -0
  189. package/src/entities/key-pairs/repos/key-pairs.repo.js +23 -0
  190. package/src/entities/oauth/constants.js +13 -0
  191. package/src/entities/oauth/domain/build-access-token.js +14 -0
  192. package/src/entities/oauth/domain/index.js +10 -0
  193. package/src/entities/oauth/domain/validate-audience.js +13 -0
  194. package/src/entities/oauth/domain/validate-client-id.js +13 -0
  195. package/src/entities/oauth/domain/validate-credential.js +16 -0
  196. package/src/entities/oauth/domain/validate-presentation.js +17 -0
  197. package/src/entities/oauth/domain/validate-refresh-token.js +17 -0
  198. package/src/entities/oauth/domain/validate-scope.js +30 -0
  199. package/src/entities/oauth/domain/verify-presentation.js +24 -0
  200. package/src/entities/oauth/index.js +4 -0
  201. package/src/entities/pushes/domains/errors.js +11 -0
  202. package/src/entities/pushes/domains/index.js +3 -0
  203. package/src/entities/pushes/index.js +3 -0
  204. package/src/entities/verification-code-attempts/index.js +3 -0
  205. package/src/entities/verification-code-attempts/orchestrators/index.js +3 -0
  206. package/src/entities/verification-code-attempts/orchestrators/validate-verification-code-attempts.js +79 -0
  207. package/src/entities/verification-code-attempts/repo.js +99 -0
  208. package/src/entities/verifications/constants.js +8 -0
  209. package/src/entities/verifications/index.js +3 -0
  210. package/src/helpers/caching-constants.js +6 -0
  211. package/src/helpers/index.js +3 -0
  212. package/src/index.js +15 -0
  213. package/src/init-server.js +88 -0
  214. package/src/plugins/index.js +4 -0
  215. package/src/plugins/vcl-verification-version-plugin.js +10 -0
  216. package/src/plugins/verify-access-token-plugin.js +116 -0
  217. package/src/standalone.js +8 -0
  218. package/test/accounts-controller.test.js +893 -0
  219. package/test/accounts-repo.test.js +92 -0
  220. package/test/careerwallet-config-controller.test.js +142 -0
  221. package/test/careerwallet-consents-controller.test.js +409 -0
  222. package/test/create_did_key-controller.test.js +397 -0
  223. package/test/create_jwk-controller.test.js +188 -0
  224. package/test/credential-categories-controller.test.js +29 -0
  225. package/test/credential-icons-controller.test.js +36 -0
  226. package/test/devices-controller.test.js +1025 -0
  227. package/test/factories/accounts-factory.js +15 -0
  228. package/test/factories/career-wallet-config-factory.js +60 -0
  229. package/test/factories/consents-career-wallet-factory.js +21 -0
  230. package/test/factories/devices-factory.js +16 -0
  231. package/test/factories/key-pairs-factory.js +18 -0
  232. package/test/factories/notifications-factory.js +16 -0
  233. package/test/factories/persona-factory.js +17 -0
  234. package/test/factories/refresh-tokens-factory.js +14 -0
  235. package/test/factories/verification-code-attempts-factory.js +17 -0
  236. package/test/factories/verification-factory.js +15 -0
  237. package/test/factories/verification-offer-factory.js +20 -0
  238. package/test/feedback-controller.test.js +225 -0
  239. package/test/helpers/.env.test +39 -0
  240. package/test/helpers/access-token.js +59 -0
  241. package/test/helpers/careerwallet-build-fastify.js +20 -0
  242. package/test/helpers/yoti.js +96 -0
  243. package/test/id-verification-controller.test.js +27 -0
  244. package/test/jwt-controller.test.js +1519 -0
  245. package/test/oauth-controller.test.js +639 -0
  246. package/test/push-controller.test.js +733 -0
  247. package/test/push-gateway-auth.test.js +208 -0
  248. package/test/reference-countries-controller.test.js +45 -0
  249. package/test/reference-personas-controller.test.js +179 -0
  250. package/test/root.test.js +21 -0
  251. package/test/swagger.test.js +21 -0
  252. package/test/verification-controller.test.js +1372 -0
@@ -0,0 +1,14 @@
1
+ const { generateDocJwt } = require('@velocitycareerlabs/jwt');
2
+ const { nanoid } = require('nanoid');
3
+
4
+ const initBuildAccessToken =
5
+ (signingKey, issuer, expiresIn) => async (scope, accountId) =>
6
+ generateDocJwt({ scope, nonce: nanoid(8) }, signingKey, {
7
+ issuer,
8
+ expiresIn,
9
+ subject: accountId,
10
+ });
11
+
12
+ module.exports = {
13
+ initBuildAccessToken,
14
+ };
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ ...require('./build-access-token'),
3
+ ...require('./validate-scope'),
4
+ ...require('./validate-client-id'),
5
+ ...require('./validate-audience'),
6
+ ...require('./validate-refresh-token'),
7
+ ...require('./validate-presentation'),
8
+ ...require('./validate-credential'),
9
+ ...require('./verify-presentation'),
10
+ };
@@ -0,0 +1,13 @@
1
+ const newError = require('http-errors');
2
+
3
+ const initValidateAudience = (_audience) => {
4
+ return (audience) => {
5
+ if (audience !== _audience) {
6
+ throw newError.Unauthorized(`Unknown audience: ${audience}`);
7
+ }
8
+ };
9
+ };
10
+
11
+ module.exports = {
12
+ initValidateAudience,
13
+ };
@@ -0,0 +1,13 @@
1
+ const newError = require('http-errors');
2
+
3
+ const initValidateClientId = (_clientId) => {
4
+ return (clientId) => {
5
+ if (clientId !== _clientId) {
6
+ throw newError.Unauthorized(`Unknown client id: ${clientId}`);
7
+ }
8
+ };
9
+ };
10
+
11
+ module.exports = {
12
+ initValidateClientId,
13
+ };
@@ -0,0 +1,16 @@
1
+ const { includes } = require('lodash/fp');
2
+ const newError = require('http-errors');
3
+
4
+ const validateCredential = (credential) => {
5
+ const { payload } = credential;
6
+ const { vc } = payload;
7
+ const { type } = vc;
8
+ const includesCorrectCredential = includes('PhoneV1.0', type);
9
+ if (!includesCorrectCredential) {
10
+ throw newError.Unauthorized('Credential is not of type PhoneV1.0');
11
+ }
12
+ };
13
+
14
+ module.exports = {
15
+ validateCredential,
16
+ };
@@ -0,0 +1,17 @@
1
+ const newError = require('http-errors');
2
+ const { GrantTypes } = require('../constants');
3
+
4
+ const validatePresentation = (grantType, presentation) => {
5
+ if (grantType !== GrantTypes.VNF_PRESENTATION) {
6
+ return;
7
+ }
8
+ if (!presentation) {
9
+ throw newError.BadRequest(
10
+ `Presentation required with grant type "${GrantTypes.VNF_PRESENTATION}"`
11
+ );
12
+ }
13
+ };
14
+
15
+ module.exports = {
16
+ validatePresentation,
17
+ };
@@ -0,0 +1,17 @@
1
+ const newError = require('http-errors');
2
+ const { GrantTypes } = require('../constants');
3
+
4
+ const validateRefreshToken = (grantType, refreshToken) => {
5
+ if (grantType !== GrantTypes.REFRESH_TOKEN) {
6
+ return;
7
+ }
8
+ if (!refreshToken) {
9
+ throw newError.BadRequest(
10
+ `Refresh token required with grant type "${GrantTypes.REFRESH_TOKEN}"`
11
+ );
12
+ }
13
+ };
14
+
15
+ module.exports = {
16
+ validateRefreshToken,
17
+ };
@@ -0,0 +1,30 @@
1
+ const { reduce, split, partition, isEmpty } = require('lodash/fp');
2
+ const newError = require('http-errors');
3
+
4
+ const validateScope = (scopes) =>
5
+ reduce(
6
+ (accumulator, current) => ({ ...accumulator, [current]: true }),
7
+ {},
8
+ split(' ', scopes)
9
+ );
10
+
11
+ const initValidateScopes = (scopes) => {
12
+ const scopesMap = validateScope(scopes);
13
+ return (scopeStr) => {
14
+ const scopeArr = split(' ', scopeStr);
15
+ const [recognizedScopes, unrecognizedScopes] = partition(
16
+ (scope) => scopesMap[scope],
17
+ scopeArr
18
+ );
19
+ if (!isEmpty(unrecognizedScopes)) {
20
+ throw newError.Unauthorized(
21
+ `Unrecognized scopes: ${JSON.stringify(unrecognizedScopes)}`
22
+ );
23
+ }
24
+ return recognizedScopes;
25
+ };
26
+ };
27
+
28
+ module.exports = {
29
+ initValidateScopes,
30
+ };
@@ -0,0 +1,24 @@
1
+ const { verifyPresentationJwt, jwtVerify } = require('@velocitycareerlabs/jwt');
2
+ const { reject, isNil, first } = require('lodash/fp');
3
+ const newError = require('http-errors');
4
+
5
+ const initVerifyPresentation = (jwk) => async (presentation) => {
6
+ const decodedAndVerifiedPresentation = await verifyPresentationJwt(
7
+ presentation
8
+ );
9
+ const vcJwts = reject(
10
+ isNil,
11
+ decodedAndVerifiedPresentation.verifiableCredential
12
+ );
13
+ const vc = first(vcJwts);
14
+ try {
15
+ const decodedJwt = await jwtVerify(vc, jwk);
16
+ return decodedJwt;
17
+ } catch (e) {
18
+ throw newError.Unauthorized('Credential verification failed');
19
+ }
20
+ };
21
+
22
+ module.exports = {
23
+ initVerifyPresentation,
24
+ };
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ ...require('./domain'),
3
+ ...require('./constants'),
4
+ };
@@ -0,0 +1,11 @@
1
+ const ErrorsUnauthorizedPushes = {
2
+ INVALID_ISSUING_TIME: 'Invalid issue time',
3
+ INVALID_AUDIENCE: 'Invalid audience',
4
+ INVALID_HASH: 'Invalid hash',
5
+ MISSED_CLAIMS: 'Missed claims in a token',
6
+ INVALID_ORG_ERROR_TEMPLATE: ({ reason }) =>
7
+ `Invalid organization profile due to ${reason}`,
8
+ };
9
+ module.exports = {
10
+ ErrorsUnauthorizedPushes,
11
+ };
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ ...require('./errors'),
3
+ };
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ ...require('./domains'),
3
+ };
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ ...require('./orchestrators'),
3
+ };
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ ...require('./validate-verification-code-attempts'),
3
+ };
@@ -0,0 +1,79 @@
1
+ const { subMinutes, addHours } = require('date-fns/fp');
2
+ const { size, map, filter, partition, startsWith, some } = require('lodash/fp');
3
+ const createError = require('http-errors');
4
+ const { mapWithIndex } = require('@velocitycareerlabs/common-functions');
5
+
6
+ const validateVerificationCodeAttempts = async (key, ctx) => {
7
+ const { repos } = ctx;
8
+ const timestamp = new Date();
9
+ await repos.verificationCodeAttempts.insertAttempt(key, timestamp);
10
+ await applyRules({ key, timestamp }, ctx);
11
+ };
12
+
13
+ const applyRules = async ({ key, timestamp }, ctx) => {
14
+ const { repos } = ctx;
15
+ validateIsPrefixAllowed(key, ctx);
16
+ const loadedAttempts =
17
+ await repos.verificationCodeAttempts.loadPreviousAttempts(
18
+ key,
19
+ timestamp,
20
+ subMinutes(60, timestamp)
21
+ );
22
+
23
+ if (size(loadedAttempts) >= 10) {
24
+ const idsWithReleaseAt = map(
25
+ (attempt) => ({
26
+ id: attempt._id,
27
+ releaseAt: addHours(480, timestamp),
28
+ }),
29
+ loadedAttempts
30
+ );
31
+ await repos.verificationCodeAttempts.setReleaseAtById(idsWithReleaseAt);
32
+ throwAttemptBlockedError();
33
+ }
34
+
35
+ const [futureReleases, previousAttempts] = partition(
36
+ (attempt) => !!attempt.releaseAt,
37
+ loadedAttempts
38
+ );
39
+
40
+ const previousAttempts60Min = filter(
41
+ (attempt) => attempt.attemptedAt >= subMinutes(60, timestamp),
42
+ previousAttempts
43
+ );
44
+
45
+ const futureReleasesAnd60Min = [...futureReleases, ...previousAttempts60Min];
46
+ if (size(futureReleasesAnd60Min) >= 3) {
47
+ const idsWithReleaseAt = mapWithIndex(
48
+ (attempt, idx) => ({
49
+ id: attempt._id,
50
+ releaseAt: addHours(idx + 1, timestamp),
51
+ }),
52
+ futureReleasesAnd60Min
53
+ );
54
+ await repos.verificationCodeAttempts.setReleaseAtById(idsWithReleaseAt);
55
+ throwAttemptBlockedError();
56
+ }
57
+ };
58
+
59
+ const validateIsPrefixAllowed = (phoneNumber, ctx) => {
60
+ const {
61
+ config: { phonePrefixesToBlock },
62
+ } = ctx;
63
+ const isPrefixBlocked = some((phonePrefix) => {
64
+ return startsWith(phonePrefix, phoneNumber);
65
+ }, phonePrefixesToBlock);
66
+ if (isPrefixBlocked) {
67
+ throwAttemptBlockedError();
68
+ }
69
+ };
70
+
71
+ const throwAttemptBlockedError = () => {
72
+ throw createError(400, 'Attempt Blocked', {
73
+ errorCode: 'attempt_blocked',
74
+ });
75
+ };
76
+
77
+ module.exports = {
78
+ validateVerificationCodeAttempts,
79
+ };
@@ -0,0 +1,99 @@
1
+ const {
2
+ repoFactory,
3
+ autoboxIdsExtension,
4
+ } = require('@spencejs/spence-mongo-repos');
5
+ const { map } = require('lodash/fp');
6
+ const { hashAndEncodeHex } = require('@velocitycareerlabs/crypto');
7
+
8
+ module.exports = (app, options, next = () => {}) => {
9
+ next();
10
+ return repoFactory(
11
+ {
12
+ name: 'verificationCodeAttempts',
13
+ entityName: 'verificationCodeAttempt',
14
+ defaultProjection: {
15
+ _id: 1,
16
+ attemptedAt: 1,
17
+ releaseAt: 1,
18
+ },
19
+ extensions: [
20
+ autoboxIdsExtension,
21
+ hashKeyModificationExtension,
22
+ hashKeyFilterExtension,
23
+ insertAttemptExtension,
24
+ loadPreviousAttemptsExtension,
25
+ setReleaseAtByIdExtension,
26
+ ],
27
+ },
28
+ app
29
+ );
30
+ };
31
+
32
+ const hashKeyModificationExtension = (parent) => {
33
+ return {
34
+ prepModification: (val, ...args) => {
35
+ return parent.prepModification(
36
+ { ...val, key: val.key && hashAndEncodeHex(val.key) },
37
+ ...args
38
+ );
39
+ },
40
+ extensions: parent.extensions.concat(['hashKeyModificationExtension']),
41
+ };
42
+ };
43
+ const hashKeyFilterExtension = (parent) => {
44
+ return {
45
+ prepFilter: (filter) => {
46
+ return parent.prepFilter({
47
+ ...filter,
48
+ key: filter.key && hashAndEncodeHex(filter.key),
49
+ });
50
+ },
51
+ extensions: parent.extensions.concat(['hashKeyFilterExtension']),
52
+ };
53
+ };
54
+
55
+ const insertAttemptExtension = (parent) => ({
56
+ insertAttempt: async (key, timestamp) => {
57
+ return parent.insert({
58
+ key,
59
+ attemptedAt: timestamp,
60
+ });
61
+ },
62
+ extensions: parent.extensions.concat(['insertAttempt']),
63
+ });
64
+
65
+ const loadPreviousAttemptsExtension = (parent) => ({
66
+ loadPreviousAttempts: async (key, timestamp, offsetTimestamp) => {
67
+ return parent.find({
68
+ filter: {
69
+ $or: [
70
+ { releaseAt: { $gt: timestamp } },
71
+ { attemptedAt: { $gte: offsetTimestamp } },
72
+ ],
73
+ key,
74
+ },
75
+ sort: {
76
+ attemptedAt: 1,
77
+ },
78
+ });
79
+ },
80
+ extensions: parent.extensions.concat(['loadPreviousAttempts']),
81
+ });
82
+
83
+ const setReleaseAtByIdExtension = (parent) => ({
84
+ setReleaseAtById: async (idsWithReleaseAt) => {
85
+ const operations = map(
86
+ ({ id, releaseAt }) => ({
87
+ updateOne: {
88
+ filter: { _id: id },
89
+ update: {
90
+ $set: { releaseAt },
91
+ },
92
+ },
93
+ }),
94
+ idsWithReleaseAt
95
+ );
96
+ return parent.collection().bulkWrite(operations);
97
+ },
98
+ extensions: parent.extensions.concat(['setReleaseAtById']),
99
+ });
@@ -0,0 +1,8 @@
1
+ const VerificationValueTypes = Object.freeze({
2
+ Phone: 'phone',
3
+ Email: 'email',
4
+ });
5
+
6
+ module.exports = {
7
+ VerificationValueTypes,
8
+ };
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ ...require('./constants'),
3
+ };
@@ -0,0 +1,6 @@
1
+ const CachingConstants = {
2
+ CACHE_CONTROL_HEADER: 'Cache-control',
3
+ MAX_AGE_CACHE_CONTROL: 'public,max-age=31536000,immutable',
4
+ };
5
+
6
+ module.exports = { CachingConstants };
@@ -0,0 +1,3 @@
1
+ module.exports = {
2
+ ...require('./caching-constants'),
3
+ };
package/src/index.js ADDED
@@ -0,0 +1,15 @@
1
+ const {
2
+ createServer,
3
+ listenServer,
4
+ } = require('@velocitycareerlabs/server-provider');
5
+ const { flow } = require('lodash/fp');
6
+ const config = require('./config/config');
7
+ const { initServer } = require('./init-server');
8
+
9
+ /* istanbul ignore next */
10
+ process.on('unhandledRejection', (error) => {
11
+ console.error(error);
12
+ process.exit(1);
13
+ });
14
+
15
+ flow(createServer, initServer, listenServer)(config);
@@ -0,0 +1,88 @@
1
+ const { corsPlugin } = require('@velocitycareerlabs/fastify-plugins');
2
+ const {
3
+ sendEmailPlugin,
4
+ sendSmsPlugin,
5
+ } = require('@velocitycareerlabs/aws-clients');
6
+ const initRequest = require('@velocitycareerlabs/request');
7
+ const Static = require('@fastify/static');
8
+ const AutoLoad = require('@fastify/autoload');
9
+ const path = require('path');
10
+ const {
11
+ yotiIntegrationPlugin,
12
+ } = require('@velocitycareerlabs/yoti-integration-plugin');
13
+ const { pick } = require('lodash/fp');
14
+ const { vclVerificationVersionPlugin } = require('./plugins');
15
+
16
+ const initServer = (server) => {
17
+ return server
18
+ .register(corsPlugin)
19
+ .register(sendSmsPlugin)
20
+ .register(sendEmailPlugin)
21
+ .register(vclVerificationVersionPlugin)
22
+ .register(yotiIntegrationPlugin)
23
+ .register(AutoLoad, {
24
+ dir: path.join(__dirname, 'controllers'),
25
+ indexPattern: /.*repo(\.ts|\.js|\.cjs|\.mjs)$/,
26
+ scriptPattern: /.*repo(\.ts|\.js|\.cjs|\.mjs)$/,
27
+ })
28
+ .register(AutoLoad, {
29
+ dir: path.join(__dirname, 'entities'),
30
+ indexPattern: /.*repo(\.ts|\.js|\.cjs|\.mjs)$/,
31
+ scriptPattern: /.*repo(\.ts|\.js|\.cjs|\.mjs)$/,
32
+ })
33
+ .register(AutoLoad, {
34
+ dir: path.join(__dirname, 'controllers'),
35
+ indexPattern: /^.*controller(\.ts|\.js|\.cjs|\.mjs)$/,
36
+ scriptPattern: /.*controller(\.ts|\.js|\.cjs|\.mjs)$/,
37
+ routeParams: true,
38
+ autoHooks: true,
39
+ cascadeHooks: true,
40
+ })
41
+ .decorate(
42
+ 'baseAgentFetch',
43
+ initRequest({
44
+ ...server.config,
45
+ prefixUrl: server.config.agentUrl,
46
+ })
47
+ )
48
+ .decorateRequest('agentFetch', null)
49
+ .addHook('preValidation', async (req) => {
50
+ req.agentFetch = server.baseAgentFetch(req);
51
+ })
52
+ .decorate(
53
+ 'baseRegistrarFetch',
54
+ initRequest({
55
+ ...server.config,
56
+ prefixUrl: server.config.registrarUrl,
57
+ })
58
+ )
59
+ .decorateRequest('registrarFetch', null)
60
+ .addHook('preValidation', async (req) => {
61
+ req.registrarFetch = server.baseRegistrarFetch(req);
62
+ })
63
+ .decorate(
64
+ 'baseLibFetch',
65
+ initRequest({
66
+ ...pick(['nodeEnv', 'requestTimeout', 'traceIdHeader'], server.config),
67
+ prefixUrl: server.config.libUrl,
68
+ })
69
+ )
70
+ .decorateRequest('libFetch', null)
71
+ .addHook('preValidation', async (req) => {
72
+ req.libFetch = server.baseLibFetch(req);
73
+ })
74
+ .register(Static, {
75
+ root: path.join(__dirname, 'assets'),
76
+ wildcard: false,
77
+ })
78
+ .register(Static, {
79
+ root: path.join(__dirname, 'assets/category-icons'),
80
+ prefix: '/category-icons',
81
+ setHeaders: (res) => {
82
+ res.setHeader('contentType', 'image/png');
83
+ },
84
+ decorateReply: false,
85
+ });
86
+ };
87
+
88
+ module.exports = { initServer };
@@ -0,0 +1,4 @@
1
+ module.exports = {
2
+ ...require('./vcl-verification-version-plugin'),
3
+ ...require('./verify-access-token-plugin'),
4
+ };
@@ -0,0 +1,10 @@
1
+ const {
2
+ fastifyVersionPluginFactory,
3
+ } = require('@velocitycareerlabs/fastify-plugins');
4
+
5
+ const vclVerificationVersionPlugin = fastifyVersionPluginFactory(
6
+ 'x-vcl-verif-version',
7
+ 'vclVerificationVersion'
8
+ );
9
+
10
+ module.exports = { vclVerificationVersionPlugin };
@@ -0,0 +1,116 @@
1
+ const fp = require('fastify-plugin');
2
+ const { isEmpty, some, trim, values } = require('lodash/fp');
3
+ const newError = require('http-errors');
4
+ const bearerAuthPlugin = require('@fastify/bearer-auth');
5
+
6
+ const { jwtVerify } = require('@velocitycareerlabs/jwt');
7
+ const { promisify } = require('@velocitycareerlabs/common-functions');
8
+ const { adminScopes } = require('../entities');
9
+
10
+ const initAuth = (context) => async (jwt, request) => {
11
+ const { config, log } = context;
12
+ const { holderAppServerAccessTokenPublicKey } = config;
13
+ try {
14
+ const { header, payload } = await jwtVerify(
15
+ jwt,
16
+ holderAppServerAccessTokenPublicKey
17
+ );
18
+
19
+ const hasAdminScope = initHasMatchingScope(values(adminScopes));
20
+
21
+ log.info(
22
+ `velocity-access-token-plugin: ${JSON.stringify({
23
+ payload,
24
+ header,
25
+ })}`
26
+ );
27
+
28
+ if (isEmpty(payload.sub)) {
29
+ throw new newError.Unauthorized();
30
+ }
31
+
32
+ if (hasAdminScope(payload)) {
33
+ // eslint-disable-next-line better-mutation/no-mutation
34
+ request.isServerUser = true;
35
+ }
36
+ // eslint-disable-next-line better-mutation/no-mutation
37
+ request.user = payload;
38
+
39
+ return true;
40
+ } catch (error) {
41
+ log.info(
42
+ `velocity-access-token-plugin-error: ${JSON.stringify({
43
+ error,
44
+ })}`
45
+ );
46
+ return false;
47
+ }
48
+ };
49
+
50
+ const initHasMatchingScope = (targetScopes) => (user) => {
51
+ const { scope = '' } = user;
52
+ const userScopes = scope.split(' ');
53
+ return some(
54
+ (userScope) => targetScopes.includes(trim(userScope)),
55
+ userScopes
56
+ );
57
+ };
58
+
59
+ const initVerifyAccessToken =
60
+ (fastify) =>
61
+ (requiredScopes = []) => {
62
+ const hasMatchingScope = initHasMatchingScope(requiredScopes);
63
+
64
+ return async (req, reply) => {
65
+ if (isDisabledApiEndpoint(req)) {
66
+ return;
67
+ }
68
+
69
+ await promisify(fastify.verifyBearerAuth)(req, reply);
70
+
71
+ if (isEmpty(requiredScopes)) {
72
+ return;
73
+ }
74
+
75
+ if (!hasMatchingScope(req.user)) {
76
+ throw new newError.Forbidden(
77
+ `User must have one of the following scopes: ${JSON.stringify(
78
+ requiredScopes
79
+ )}`
80
+ );
81
+ }
82
+ };
83
+ };
84
+
85
+ const isDisabledApiEndpoint = (req) => {
86
+ const {
87
+ routeOptions: { url, method },
88
+ } = req;
89
+
90
+ return (
91
+ !isEmpty(req.config.oauthVerificationDisabledEndpoints) &&
92
+ req.config.oauthVerificationDisabledEndpoints.includes(`${method}:${url}`)
93
+ );
94
+ };
95
+
96
+ const verifyAccessTokenPlugin = (fastify, options, next) => {
97
+ fastify
98
+ .register(bearerAuthPlugin, {
99
+ auth: initAuth(fastify),
100
+ addHook: false,
101
+ })
102
+ .decorate('verifyCareerWalletAccessToken', initVerifyAccessToken(fastify))
103
+ .decorateRequest(
104
+ 'verifyUserAdminScope',
105
+ initHasMatchingScope(values(adminScopes))
106
+ );
107
+
108
+ next();
109
+ };
110
+
111
+ module.exports = {
112
+ verifyAccessTokenPlugin: fp(verifyAccessTokenPlugin, {
113
+ fastify: '>=2.0.0',
114
+ name: 'velocity-access-token-plugin',
115
+ }),
116
+ };
@@ -0,0 +1,8 @@
1
+ /* istanbul ignore file */
2
+ // eslint-disable-next-line import/no-extraneous-dependencies
3
+ const dotenv = require('dotenv');
4
+
5
+ dotenv.config({ path: '.standalone.env' });
6
+ dotenv.config({ path: '.localdev.env' });
7
+
8
+ require('./index');