@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.
- package/.localdev.env +47 -0
- package/.standalone.env +13 -0
- package/LICENSE +248 -0
- package/jest.config.js +20 -0
- package/migrate-mongo.config.js +25 -0
- package/migrations/20211017180227-create-personas.js +478 -0
- package/migrations/20211026185916-create-vanessa.js +79 -0
- package/migrations/20211026185917-update-personas.js +30 -0
- package/migrations/20211108124410-remove-surplus-personas.js +33 -0
- package/migrations/20211108132353-fix-vanessa-and-sheila.js +25 -0
- package/migrations/20220222123110-add-career-wallet-app-config.js +6 -0
- package/migrations/20220411104157-add-min-app-versions.js +15 -0
- package/migrations/20220419131726-create-nicole-flores-persona.js +63 -0
- package/migrations/20220515114034-update-persona-id-credentials.js +628 -0
- package/migrations/20220608093743-disable-mainnet-holderapp-id-verification.js +21 -0
- package/migrations/20220609063708-enable-mainnet-holderapp-id-verification.js +21 -0
- package/migrations/20220623091507-add-push-url.js +43 -0
- package/migrations/20220624133205-set-min-app-versions-to-11.js +16 -0
- package/migrations/20220710125326-set-min-app-version-to-0.10.7.js +16 -0
- package/migrations/20220811103500-add-verification-service-disclosure-deeplink.js +45 -0
- package/migrations/20220811123751-add-holderapp-dids-to-config.js +74 -0
- package/migrations/20220818072306-add-holderapp-endpoints-to-config.js +21 -0
- package/migrations/20220825090656-update-deeplink.js +46 -0
- package/migrations/20221003151823-app-config-add-public-verification-api.js +18 -0
- package/migrations/20221116085242-add-holderapp-sdk-to-config.js +15 -0
- package/migrations/20221121091030-update-holderapp-deeplink.js +19 -0
- package/migrations/20221128103425-update-holderapp-presentation-template.js +19 -0
- package/migrations/20221221091436-app-config-add-oauth.js +13 -0
- package/migrations/20221226205900-app-config-add-presentation-extension-api.js +18 -0
- package/migrations/20230120113141-update-holderapp-cashSiquence.js +15 -0
- package/migrations/20230123084103-update-holderapp-cacheSequence.js +15 -0
- package/migrations/20230214083430-update-holderapp-cache-Sequence.js +15 -0
- package/migrations/20230225173335-set-min-app-version-1.5.1.js +30 -0
- package/migrations/20230323120629-add-sunil-singh-persona.js +87 -0
- package/migrations/20230329081529-add-personas-by-env.js +294 -0
- package/migrations/20230329103219-remove-unused-personas.js +14 -0
- package/migrations/20230504090208-disable-yoti-migration.js +21 -0
- package/migrations/20230504123425-set-min-app-version-1.8.1.js +38 -0
- package/migrations/20230504185047-enable-yoti-migration.js +21 -0
- package/migrations/20230524053203-add-devices-index.js +16 -0
- package/migrations/20230704000002-add-common-holder-endpoints-to-config.js +16 -0
- package/migrations/20230704000003-add-linkedin-holder-endpoints-to-config.js +18 -0
- package/migrations/20230704104055-update-push-url-and-yoti-url.js +18 -0
- package/migrations/20230705000001-add-liburl-to-holderapp-config.js +20 -0
- package/migrations/20230814113134-app-config-add-oauth-client-id.js +18 -0
- package/migrations/20230821154136-yoti-new-session-url-fix.js +19 -0
- package/migrations/20230907134442-update-holderapp-cache-Sequence.js +15 -0
- package/migrations/20230919180000-set-holderapp-min-app-versions-1.15.0.js +16 -0
- package/migrations/20231011083137-update-holderapp-cache-sequence-6.js +15 -0
- package/migrations/20231102083252-set-holderapp-min-app-versions-1.14.0.js +16 -0
- package/migrations/20231108202229-set-holderapp-min-app-versions-1.15.0.js +16 -0
- package/migrations/20231115143332-holderapp-isDirectIssuerCheckOn-true.js +16 -0
- package/migrations/20231120100020-insert-didKeyMetadatum-for-old-accounts.js +59 -0
- package/migrations/20231207142742-remove-devices-from-accounts.js +46 -0
- package/migrations/20231226090805-app-config-set-direct-issuer-check.js +13 -0
- package/migrations/202312271524-set-holderapp-app-version-1.15.1.js +16 -0
- package/migrations/20232211171700-app-config-update-base-urls.js +18 -0
- package/migrations/20240102093506-holderapp-revert-version-1.15.0.js +16 -0
- package/migrations/202401041618111-holderapp-isDebugOn-false.js +17 -0
- package/migrations/20240131095122-test-personas-add-did.js +102 -0
- package/migrations/202402051547000-update-sdk.js +18 -0
- package/migrations/20240206101448-update-personas-vc-to-v2.js +137 -0
- package/migrations/202402061233000-set-xVnfProtocolVersion-2.js +13 -0
- package/migrations/202402081240000-set-xVnfProtocolVersion-1.js +13 -0
- package/migrations/202402131319-set-holderapp-min-versions-1.17.js +16 -0
- package/migrations/202402141152-set-holderapp-min-version-1.16.js +16 -0
- package/migrations/20240221123501-transform-account-keys-to-stringified-jwk.js +81 -0
- package/migrations/202402290955-update-holderapp-to-verifyMyCreds.js +36 -0
- package/migrations/20240311134223-update-keyid-persona.js +66 -0
- package/migrations/20240312141618-vl-7409-persona-update-maria-williams.js +82 -0
- package/migrations/202403181733000-remove-devices-from-all-accounts.js +27 -0
- package/migrations/20240401091041-set-holderapp-min-version-1.18.1.js +16 -0
- package/migrations/202404071847-app-config-update-yoti-url.js +19 -0
- package/migrations/20240724063405-vl-3827-new-yoti-session-url.js +19 -0
- package/migrations/20240731112302-vl-8160-add-persona-keys.js +101 -0
- package/migrations/20240911115206-vanessa-lin-id-credentials.js +57 -0
- package/migrations/202409201219-add-isWalletAvailable-field.js +13 -0
- package/migrations/202409221012-set-isWalletAvailable-true.js +13 -0
- package/migrations/20240922114643-holderapp-isWalletAvailable-refactor.js +36 -0
- package/migrations/20240923132213-update-android-ios-app-config.js +36 -0
- package/migrations/20240926061732-inc-cacheSequence-to-7.js +15 -0
- package/migrations/20240926073339-inc-cacheSequence-to-7-fix.js +18 -0
- package/migrations/202410081217-adam-smith-id-credntials.js +57 -0
- package/migrations/202410101243-adam_smith-id-credential.js +57 -0
- package/migrations/20241015124307-persona-key-id-type-fix.js +26 -0
- package/migrations/202501291027000-set-holderapp-did-web.js +37 -0
- package/migrations/environments/dev.env +34 -0
- package/migrations/environments/localdev.env +22 -0
- package/migrations/environments/prod.env +18 -0
- package/migrations/environments/qa.env +54 -0
- package/migrations/environments/staging.env +31 -0
- package/migrations/environments/test.env +18 -0
- package/package.json +84 -0
- package/src/assets/category-icons/assessment.png +0 -0
- package/src/assets/category-icons/badge.png +0 -0
- package/src/assets/category-icons/certification.png +0 -0
- package/src/assets/category-icons/education.png +0 -0
- package/src/assets/category-icons/employment.png +0 -0
- package/src/assets/category-icons/gig.png +0 -0
- package/src/assets/category-icons/identity.png +0 -0
- package/src/assets/category-icons/pharmacy.png +0 -0
- package/src/assets/category-icons/training.png +0 -0
- package/src/assets/credentialCategories.json +119 -0
- package/src/config/config.js +156 -0
- package/src/controllers/api/v0.6/accounts/autohooks.js +36 -0
- package/src/controllers/api/v0.6/accounts/controller.js +288 -0
- package/src/controllers/api/v0.6/accounts/schemas/careerwallet-accounts-didkeymetadatum-response.schema.js +41 -0
- package/src/controllers/api/v0.6/accounts/schemas/careerwallet-accounts-request.schema.js +49 -0
- package/src/controllers/api/v0.6/accounts/schemas/careerwallet-accounts-response.schema.js +74 -0
- package/src/controllers/api/v0.6/accounts/schemas/careerwallet-get-account-response.schema.js +72 -0
- package/src/controllers/api/v0.6/accounts/schemas/index.js +6 -0
- package/src/controllers/api/v0.6/careerwallet/appconfig/controller.js +25 -0
- package/src/controllers/api/v0.6/careerwallet/appconfig/repo.js +40 -0
- package/src/controllers/api/v0.6/careerwallet/autohooks.js +5 -0
- package/src/controllers/api/v0.6/careerwallet/consents/controller.js +66 -0
- package/src/controllers/api/v0.6/careerwallet/consents/latest/autohooks.js +7 -0
- package/src/controllers/api/v0.6/careerwallet/consents/latest/controller.js +76 -0
- package/src/controllers/api/v0.6/careerwallet/consents/repo.js +24 -0
- package/src/controllers/api/v0.6/careerwallet/consents/schemas/careerwallet-consent-response.schema.js +23 -0
- package/src/controllers/api/v0.6/careerwallet/consents/schemas/index.js +3 -0
- package/src/controllers/api/v0.6/create_did_key/autohooks.js +10 -0
- package/src/controllers/api/v0.6/create_did_key/controller.js +84 -0
- package/src/controllers/api/v0.6/create_did_key/schemas/index.js +4 -0
- package/src/controllers/api/v0.6/create_did_key/schemas/jwk-did-request.schema.js +20 -0
- package/src/controllers/api/v0.6/create_did_key/schemas/jwk-did-response.schema.js +41 -0
- package/src/controllers/api/v0.6/create_jwk/autohooks.js +10 -0
- package/src/controllers/api/v0.6/create_jwk/controller.js +46 -0
- package/src/controllers/api/v0.6/create_jwk/schemas/index.js +3 -0
- package/src/controllers/api/v0.6/create_jwk/schemas/jwk-response.schema.js +33 -0
- package/src/controllers/api/v0.6/credential-categories/controller.js +35 -0
- package/src/controllers/api/v0.6/devices/autohooks.js +11 -0
- package/src/controllers/api/v0.6/devices/controller.js +323 -0
- package/src/controllers/api/v0.6/devices/repo.js +27 -0
- package/src/controllers/api/v0.6/devices/schemas/device.schema.json +43 -0
- package/src/controllers/api/v0.6/devices/schemas/index.js +3 -0
- package/src/controllers/api/v0.6/feedback/controller.js +24 -0
- package/src/controllers/api/v0.6/feedback/schemas/index.js +3 -0
- package/src/controllers/api/v0.6/feedback/schemas/new-feedback.schema.js +47 -0
- package/src/controllers/api/v0.6/jwt/autohooks.js +10 -0
- package/src/controllers/api/v0.6/jwt/controller.js +44 -0
- package/src/controllers/api/v0.6/jwt/schemas/index.js +4 -0
- package/src/controllers/api/v0.6/jwt/schemas/jwt-request.schema.js +40 -0
- package/src/controllers/api/v0.6/jwt/schemas/jwt-response.schema.js +14 -0
- package/src/controllers/api/v0.6/oauth/controller.js +131 -0
- package/src/controllers/api/v0.6/push/controller.js +296 -0
- package/src/controllers/api/v0.6/push/firebase-initializer.js +21 -0
- package/src/controllers/api/v0.6/push/notification-types.js +37 -0
- package/src/controllers/api/v0.6/push/push-gateway-auth.js +123 -0
- package/src/controllers/api/v0.6/push/repo.js +24 -0
- package/src/controllers/api/v0.6/verification-offers/repo.js +25 -0
- package/src/controllers/api/v0.6/verify/autohooks.js +15 -0
- package/src/controllers/api/v0.6/verify/controller.js +348 -0
- package/src/controllers/api/v0.6/verify/repo.js +23 -0
- package/src/controllers/api/v0.6/verify/verification-credential-types.js +6 -0
- package/src/controllers/jwt/autohooks.js +10 -0
- package/src/controllers/jwt/controller.js +106 -0
- package/src/controllers/jwt/schemas/index.js +31 -0
- package/src/controllers/jwt/schemas/jwt-decode.response.200.schema.json +20 -0
- package/src/controllers/jwt/schemas/jwt-decode.schema.json +15 -0
- package/src/controllers/jwt/schemas/jwt-sign.response.200.schema.json +14 -0
- package/src/controllers/jwt/schemas/jwt-sign.schema.json +40 -0
- package/src/controllers/jwt/schemas/jwt-verify.response.200.schema.json +17 -0
- package/src/controllers/jwt/schemas/jwt-verify.schema.json +19 -0
- package/src/controllers/reference/autohooks.js +5 -0
- package/src/controllers/reference/countries/controller.js +81 -0
- package/src/controllers/reference/personas/controller.js +91 -0
- package/src/controllers/reference/personas/repo.js +29 -0
- package/src/controllers/reference/personas/schemas/index.js +3 -0
- package/src/controllers/reference/personas/schemas/persona.schema.json +108 -0
- package/src/controllers/root/controller.js +27 -0
- package/src/entities/accounts/constants.js +18 -0
- package/src/entities/accounts/domain/index.js +3 -0
- package/src/entities/accounts/domain/merge-scopes.js +9 -0
- package/src/entities/accounts/index.js +5 -0
- package/src/entities/accounts/repos/accounts.repo.js +64 -0
- package/src/entities/accounts/repos/id-token-claims-extension.js +31 -0
- package/src/entities/accounts/repos/index.js +3 -0
- package/src/entities/devices/constants.js +7 -0
- package/src/entities/devices/index.js +3 -0
- package/src/entities/feedback/domain/generate-feedback-email.js +23 -0
- package/src/entities/feedback/domain/index.js +3 -0
- package/src/entities/feedback/index.js +3 -0
- package/src/entities/index.js +9 -0
- package/src/entities/key-pairs/index.js +4 -0
- package/src/entities/key-pairs/orchestrators/generate-jwk.js +28 -0
- package/src/entities/key-pairs/orchestrators/get-key-pair.js +58 -0
- package/src/entities/key-pairs/orchestrators/index.js +4 -0
- package/src/entities/key-pairs/repos/index.js +3 -0
- package/src/entities/key-pairs/repos/key-pairs.repo.js +23 -0
- package/src/entities/oauth/constants.js +13 -0
- package/src/entities/oauth/domain/build-access-token.js +14 -0
- package/src/entities/oauth/domain/index.js +10 -0
- package/src/entities/oauth/domain/validate-audience.js +13 -0
- package/src/entities/oauth/domain/validate-client-id.js +13 -0
- package/src/entities/oauth/domain/validate-credential.js +16 -0
- package/src/entities/oauth/domain/validate-presentation.js +17 -0
- package/src/entities/oauth/domain/validate-refresh-token.js +17 -0
- package/src/entities/oauth/domain/validate-scope.js +30 -0
- package/src/entities/oauth/domain/verify-presentation.js +24 -0
- package/src/entities/oauth/index.js +4 -0
- package/src/entities/pushes/domains/errors.js +11 -0
- package/src/entities/pushes/domains/index.js +3 -0
- package/src/entities/pushes/index.js +3 -0
- package/src/entities/verification-code-attempts/index.js +3 -0
- package/src/entities/verification-code-attempts/orchestrators/index.js +3 -0
- package/src/entities/verification-code-attempts/orchestrators/validate-verification-code-attempts.js +79 -0
- package/src/entities/verification-code-attempts/repo.js +99 -0
- package/src/entities/verifications/constants.js +8 -0
- package/src/entities/verifications/index.js +3 -0
- package/src/helpers/caching-constants.js +6 -0
- package/src/helpers/index.js +3 -0
- package/src/index.js +15 -0
- package/src/init-server.js +88 -0
- package/src/plugins/index.js +4 -0
- package/src/plugins/vcl-verification-version-plugin.js +10 -0
- package/src/plugins/verify-access-token-plugin.js +116 -0
- package/src/standalone.js +8 -0
- package/test/accounts-controller.test.js +893 -0
- package/test/accounts-repo.test.js +92 -0
- package/test/careerwallet-config-controller.test.js +142 -0
- package/test/careerwallet-consents-controller.test.js +409 -0
- package/test/create_did_key-controller.test.js +397 -0
- package/test/create_jwk-controller.test.js +188 -0
- package/test/credential-categories-controller.test.js +29 -0
- package/test/credential-icons-controller.test.js +36 -0
- package/test/devices-controller.test.js +1025 -0
- package/test/factories/accounts-factory.js +15 -0
- package/test/factories/career-wallet-config-factory.js +60 -0
- package/test/factories/consents-career-wallet-factory.js +21 -0
- package/test/factories/devices-factory.js +16 -0
- package/test/factories/key-pairs-factory.js +18 -0
- package/test/factories/notifications-factory.js +16 -0
- package/test/factories/persona-factory.js +17 -0
- package/test/factories/refresh-tokens-factory.js +14 -0
- package/test/factories/verification-code-attempts-factory.js +17 -0
- package/test/factories/verification-factory.js +15 -0
- package/test/factories/verification-offer-factory.js +20 -0
- package/test/feedback-controller.test.js +225 -0
- package/test/helpers/.env.test +39 -0
- package/test/helpers/access-token.js +59 -0
- package/test/helpers/careerwallet-build-fastify.js +20 -0
- package/test/helpers/yoti.js +96 -0
- package/test/id-verification-controller.test.js +27 -0
- package/test/jwt-controller.test.js +1519 -0
- package/test/oauth-controller.test.js +639 -0
- package/test/push-controller.test.js +733 -0
- package/test/push-gateway-auth.test.js +208 -0
- package/test/reference-countries-controller.test.js +45 -0
- package/test/reference-personas-controller.test.js +179 -0
- package/test/root.test.js +21 -0
- package/test/swagger.test.js +21 -0
- package/test/verification-controller.test.js +1372 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const newError = require('http-errors');
|
|
2
|
+
const { isEmpty } = require('lodash/fp');
|
|
3
|
+
|
|
4
|
+
const { careerWalletConsentResponseSchema } = require('../schemas');
|
|
5
|
+
|
|
6
|
+
const controller = async (fastify) => {
|
|
7
|
+
fastify.get(
|
|
8
|
+
'/',
|
|
9
|
+
{
|
|
10
|
+
onRequest: fastify.verifyCareerWalletAccessToken(),
|
|
11
|
+
schema: fastify.autoSchema({
|
|
12
|
+
query: {
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {
|
|
15
|
+
accountId: { type: 'string' },
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
response: {
|
|
19
|
+
200: {
|
|
20
|
+
type: 'object',
|
|
21
|
+
properties: {
|
|
22
|
+
consent: careerWalletConsentResponseSchema,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
async (req) => {
|
|
29
|
+
const { repos, user, query } = req;
|
|
30
|
+
|
|
31
|
+
validateRequestParams(req);
|
|
32
|
+
|
|
33
|
+
const accountId = query.accountId || user.sub;
|
|
34
|
+
|
|
35
|
+
const consent = await repos.consentsCareerWallet.findOne({
|
|
36
|
+
filter: { accountId },
|
|
37
|
+
sort: { createdAt: -1 },
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (isEmpty(consent)) {
|
|
41
|
+
throw newError(400, 'Consents not found');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
consent: mapConsent(consent),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const validateRequestParams = (req) => {
|
|
52
|
+
const hasAdminScopes = req.isServerUser;
|
|
53
|
+
if (hasAdminScopes) {
|
|
54
|
+
if (isEmpty(req.query?.accountId)) {
|
|
55
|
+
throw new newError.BadRequest('AccountId query param is missed');
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (
|
|
61
|
+
req.query?.accountId &&
|
|
62
|
+
req.user?.sub &&
|
|
63
|
+
req.query.accountId !== req.user.sub
|
|
64
|
+
) {
|
|
65
|
+
throw new newError.BadRequest('Param accountId and sub mismatch');
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const mapConsent = ({ createdAt, version, accountId, ...consent }) => ({
|
|
70
|
+
createdAt,
|
|
71
|
+
accountId,
|
|
72
|
+
version,
|
|
73
|
+
id: consent._id.toString(),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
module.exports = controller;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
const {
|
|
2
|
+
repoFactory,
|
|
3
|
+
autoboxIdsExtension,
|
|
4
|
+
} = require('@spencejs/spence-mongo-repos');
|
|
5
|
+
|
|
6
|
+
module.exports = (app, options, next = () => {}) => {
|
|
7
|
+
next();
|
|
8
|
+
return repoFactory(
|
|
9
|
+
{
|
|
10
|
+
name: 'consentsCareerWallet',
|
|
11
|
+
entityName: 'consentsCareerWallet',
|
|
12
|
+
defaultProjection: {
|
|
13
|
+
_id: 1,
|
|
14
|
+
accountId: 1,
|
|
15
|
+
version: 1,
|
|
16
|
+
consentId: 1,
|
|
17
|
+
createdAt: 1,
|
|
18
|
+
},
|
|
19
|
+
timestampKeys: { createdAt: 'createdAt' },
|
|
20
|
+
extensions: [autoboxIdsExtension],
|
|
21
|
+
},
|
|
22
|
+
app
|
|
23
|
+
);
|
|
24
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const careerWalletConsentResponseSchema = {
|
|
2
|
+
$id: 'https://velocitycareerlabs.io/carrerwallet-consent-response.schema.json',
|
|
3
|
+
title: 'career-wallet-consent-response',
|
|
4
|
+
description: 'the body of response for career wallet consent',
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
accountId: {
|
|
8
|
+
type: 'string',
|
|
9
|
+
},
|
|
10
|
+
version: {
|
|
11
|
+
type: 'string',
|
|
12
|
+
},
|
|
13
|
+
createdAt: {
|
|
14
|
+
type: 'string',
|
|
15
|
+
},
|
|
16
|
+
id: {
|
|
17
|
+
type: 'string',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
required: ['accountId', 'version', 'createdAt', 'id'],
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
module.exports = { careerWalletConsentResponseSchema };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const { verifyAccessTokenPlugin } = require('../../../../plugins');
|
|
2
|
+
const { accountScopes } = require('../../../../entities');
|
|
3
|
+
|
|
4
|
+
const autohooks = async (fastify) => {
|
|
5
|
+
fastify.register(verifyAccessTokenPlugin).autoSchemaPreset({
|
|
6
|
+
security: [{ bearerAuth: [accountScopes.keyCreate] }],
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
module.exports = autohooks;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const newError = require('http-errors');
|
|
2
|
+
const { isEmpty, uniqBy, find } = require('lodash/fp');
|
|
3
|
+
const { initKmsClient } = require('@velocitycareerlabs/aws-clients');
|
|
4
|
+
const { getDidUriFromJwk } = require('@velocitycareerlabs/did-doc');
|
|
5
|
+
const { jwkDidResponse, jwkDidRequest } = require('./schemas');
|
|
6
|
+
const {
|
|
7
|
+
mergeScopes,
|
|
8
|
+
generateJwk,
|
|
9
|
+
accountScopes,
|
|
10
|
+
} = require('../../../../entities');
|
|
11
|
+
|
|
12
|
+
const newScopes = [
|
|
13
|
+
accountScopes.jwt,
|
|
14
|
+
accountScopes.keyCreate,
|
|
15
|
+
accountScopes.inbox,
|
|
16
|
+
accountScopes.account,
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const сontroller = async (fastify) => {
|
|
20
|
+
const awsKmsClient = initKmsClient(fastify.config);
|
|
21
|
+
|
|
22
|
+
fastify.post(
|
|
23
|
+
'/',
|
|
24
|
+
{
|
|
25
|
+
onRequest: [
|
|
26
|
+
fastify.verifyCareerWalletAccessToken([accountScopes.keyCreate]),
|
|
27
|
+
],
|
|
28
|
+
schema: fastify.autoSchema({
|
|
29
|
+
tags: ['careerwallet'],
|
|
30
|
+
body: jwkDidRequest,
|
|
31
|
+
response: {
|
|
32
|
+
200: jwkDidResponse,
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
35
|
+
},
|
|
36
|
+
async (req) => {
|
|
37
|
+
const {
|
|
38
|
+
body,
|
|
39
|
+
user: { sub },
|
|
40
|
+
repos,
|
|
41
|
+
} = req;
|
|
42
|
+
const { crv } = body;
|
|
43
|
+
const account = await repos.accounts.findOne({ filter: { _id: sub } });
|
|
44
|
+
|
|
45
|
+
const didKeyMetadatum = account.didKeyMetadatum ?? [];
|
|
46
|
+
const didKeyMetadatumByCrv = find(
|
|
47
|
+
({ publicJwk }) => publicJwk.crv === crv,
|
|
48
|
+
didKeyMetadatum
|
|
49
|
+
);
|
|
50
|
+
if (!isEmpty(didKeyMetadatumByCrv)) {
|
|
51
|
+
throw newError(400, 'DID key with crv already exists', {
|
|
52
|
+
errorCode: 'account_did_exist',
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const { publicKey, keyId } = await generateJwk(crv, {
|
|
57
|
+
...req,
|
|
58
|
+
awsKmsClient,
|
|
59
|
+
});
|
|
60
|
+
const didJwk = getDidUriFromJwk(publicKey);
|
|
61
|
+
await repos.accounts.update(account._id, {
|
|
62
|
+
didKeyMetadatum: uniqBy('keyId', [
|
|
63
|
+
...didKeyMetadatum,
|
|
64
|
+
{
|
|
65
|
+
publicJwk: publicKey,
|
|
66
|
+
keyId,
|
|
67
|
+
kid: `${didJwk}#0`,
|
|
68
|
+
did: didJwk,
|
|
69
|
+
},
|
|
70
|
+
]),
|
|
71
|
+
keyId,
|
|
72
|
+
scope: mergeScopes(account.scope, newScopes),
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
publicJwk: publicKey,
|
|
76
|
+
keyId,
|
|
77
|
+
kid: `${didJwk}#0`,
|
|
78
|
+
did: didJwk,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
module.exports = сontroller;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const jwkDidRequest = {
|
|
2
|
+
title: 'jwk-did-request',
|
|
3
|
+
$id: 'https://velocitycareerlabs.io/jwk-did-request.schema.json',
|
|
4
|
+
description: 'jwk did request schema',
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
crv: {
|
|
8
|
+
type: 'string',
|
|
9
|
+
enum: ['secp256k1', 'P-256'],
|
|
10
|
+
},
|
|
11
|
+
didMethod: {
|
|
12
|
+
type: 'string',
|
|
13
|
+
enum: ['did:jwk'],
|
|
14
|
+
default: 'did:jwk',
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
required: ['crv'],
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
module.exports = { jwkDidRequest };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
const jwkDidResponse = {
|
|
2
|
+
title: 'jwk-did-response',
|
|
3
|
+
$id: 'https://velocitycareerlabs.io/jwk-did-response.schema.json',
|
|
4
|
+
description: 'jwk did response schema',
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
did: {
|
|
8
|
+
type: 'string',
|
|
9
|
+
},
|
|
10
|
+
kid: {
|
|
11
|
+
type: 'string',
|
|
12
|
+
},
|
|
13
|
+
keyId: {
|
|
14
|
+
type: 'string',
|
|
15
|
+
},
|
|
16
|
+
publicJwk: {
|
|
17
|
+
type: 'object',
|
|
18
|
+
required: ['kty'],
|
|
19
|
+
properties: {
|
|
20
|
+
kty: { type: 'string' },
|
|
21
|
+
use: { type: 'string' },
|
|
22
|
+
key_ops: { type: 'string' },
|
|
23
|
+
x5u: { type: 'string' },
|
|
24
|
+
x5c: { type: 'string' },
|
|
25
|
+
x5t: { type: 'string' },
|
|
26
|
+
'x5t#S256': { type: 'string' },
|
|
27
|
+
alg: { type: 'string' },
|
|
28
|
+
kid: { type: 'string' },
|
|
29
|
+
exp: { type: 'string' },
|
|
30
|
+
crv: { type: 'string' },
|
|
31
|
+
y: { type: 'string' },
|
|
32
|
+
x: { type: 'string' },
|
|
33
|
+
n: { type: 'string' },
|
|
34
|
+
e: { type: 'string' },
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
required: ['did', 'publicJwk'],
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
module.exports = { jwkDidResponse };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const { verifyAccessTokenPlugin } = require('../../../../plugins');
|
|
2
|
+
const { accountScopes } = require('../../../../entities');
|
|
3
|
+
|
|
4
|
+
const autohooks = async (fastify) => {
|
|
5
|
+
fastify.register(verifyAccessTokenPlugin).autoSchemaPreset({
|
|
6
|
+
security: [{ bearerAuth: [accountScopes.keyCreate] }],
|
|
7
|
+
});
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
module.exports = autohooks;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const { initKmsClient } = require('@velocitycareerlabs/aws-clients');
|
|
2
|
+
const { jwkResponse } = require('./schemas');
|
|
3
|
+
const { generateJwk, accountScopes } = require('../../../../entities');
|
|
4
|
+
|
|
5
|
+
const controller = async (fastify) => {
|
|
6
|
+
const awsKmsClient = initKmsClient(fastify.config);
|
|
7
|
+
|
|
8
|
+
fastify.post(
|
|
9
|
+
'/',
|
|
10
|
+
{
|
|
11
|
+
onRequest: [
|
|
12
|
+
fastify.verifyCareerWalletAccessToken([accountScopes.keyCreate]),
|
|
13
|
+
],
|
|
14
|
+
schema: fastify.autoSchema({
|
|
15
|
+
tags: ['careerwallet'],
|
|
16
|
+
body: {
|
|
17
|
+
type: 'object',
|
|
18
|
+
properties: {
|
|
19
|
+
crv: {
|
|
20
|
+
type: 'string',
|
|
21
|
+
enum: ['secp256k1', 'P-256'],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
required: ['crv'],
|
|
25
|
+
},
|
|
26
|
+
response: {
|
|
27
|
+
200: jwkResponse,
|
|
28
|
+
},
|
|
29
|
+
}),
|
|
30
|
+
},
|
|
31
|
+
async (req) => {
|
|
32
|
+
const { body } = req;
|
|
33
|
+
const { crv } = body;
|
|
34
|
+
const { publicKey, keyId } = await generateJwk(crv, {
|
|
35
|
+
...req,
|
|
36
|
+
awsKmsClient,
|
|
37
|
+
});
|
|
38
|
+
return {
|
|
39
|
+
jwk: publicKey,
|
|
40
|
+
keyId,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
module.exports = controller;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const jwkResponse = {
|
|
2
|
+
title: 'jwk-response',
|
|
3
|
+
$id: 'https://velocitycareerlabs.io/jwk-response.schema.json',
|
|
4
|
+
description: 'jwk response schema',
|
|
5
|
+
type: 'object',
|
|
6
|
+
properties: {
|
|
7
|
+
jwk: {
|
|
8
|
+
type: 'object',
|
|
9
|
+
required: ['kty'],
|
|
10
|
+
properties: {
|
|
11
|
+
kty: { type: 'string' },
|
|
12
|
+
use: { type: 'string' },
|
|
13
|
+
key_ops: { type: 'string' },
|
|
14
|
+
x5u: { type: 'string' },
|
|
15
|
+
x5c: { type: 'string' },
|
|
16
|
+
x5t: { type: 'string' },
|
|
17
|
+
'x5t#S256': { type: 'string' },
|
|
18
|
+
alg: { type: 'string' },
|
|
19
|
+
kid: { type: 'string' },
|
|
20
|
+
exp: { type: 'string' },
|
|
21
|
+
crv: { type: 'string' },
|
|
22
|
+
y: { type: 'string' },
|
|
23
|
+
x: { type: 'string' },
|
|
24
|
+
n: { type: 'string' },
|
|
25
|
+
e: { type: 'string' },
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
keyId: { type: 'string' },
|
|
29
|
+
},
|
|
30
|
+
required: ['jwk', 'keyId'],
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
module.exports = { jwkResponse };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const fileName = 'credentialCategories.json';
|
|
2
|
+
|
|
3
|
+
const сontroller = async (fastify) => {
|
|
4
|
+
fastify.get(
|
|
5
|
+
'/',
|
|
6
|
+
{
|
|
7
|
+
schema: fastify.autoSchema({
|
|
8
|
+
tags: ['careerwallet'],
|
|
9
|
+
response: {
|
|
10
|
+
200: {
|
|
11
|
+
type: 'array',
|
|
12
|
+
items: {
|
|
13
|
+
type: 'object',
|
|
14
|
+
properties: {
|
|
15
|
+
title: { type: 'string' },
|
|
16
|
+
icon: { type: 'string' },
|
|
17
|
+
color: { type: 'string' },
|
|
18
|
+
types: { type: 'array', items: { type: 'string' } },
|
|
19
|
+
iconSize: { type: 'integer' },
|
|
20
|
+
isIdentity: { type: 'boolean' },
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
},
|
|
27
|
+
async (req, reply) => {
|
|
28
|
+
return reply
|
|
29
|
+
.type('application/json; charset=utf-8')
|
|
30
|
+
.sendFile(fileName, { cacheControl: false });
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
module.exports = сontroller;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const { verifyAccessTokenPlugin } = require('../../../../plugins');
|
|
2
|
+
const { deviceSchema } = require('./schemas');
|
|
3
|
+
|
|
4
|
+
const autohooks = async (fastify) => {
|
|
5
|
+
fastify
|
|
6
|
+
.addSchema(deviceSchema)
|
|
7
|
+
.autoSchemaPreset({ tags: ['careerwallet'] })
|
|
8
|
+
.register(verifyAccessTokenPlugin);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
module.exports = autohooks;
|