@verii/server-credentialing-hub 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +13 -0
- package/package.json +87 -0
- package/src/assets/templates/app-redirect.hbs +22 -0
- package/src/config/config.js +118 -0
- package/src/config/index.js +19 -0
- package/src/controllers/app-redirect/controller.js +85 -0
- package/src/controllers/openid4vc/autohooks.js +22 -0
- package/src/controllers/openid4vc/oauth-controller.js +96 -0
- package/src/controllers/openid4vc/openid4vc-metadata-controller.js +66 -0
- package/src/controllers/openid4vc/openid4vci-controller.js +125 -0
- package/src/controllers/openid4vp/autohooks.js +22 -0
- package/src/controllers/openid4vp/openid4vp-controller.js +177 -0
- package/src/controllers/operator/autohooks.js +31 -0
- package/src/controllers/operator/credentials/credentials-controller.js +212 -0
- package/src/controllers/operator/credentials/schemas/credential.schema.js +46 -0
- package/src/controllers/operator/credentials/schemas/index.js +7 -0
- package/src/controllers/operator/credentials/schemas/new-credential.schema.json +23 -0
- package/src/controllers/operator/depots/depots-controller.js +154 -0
- package/src/controllers/operator/depots/schemas/depot.schema.js +34 -0
- package/src/controllers/operator/depots/schemas/index.js +24 -0
- package/src/controllers/operator/depots/schemas/new-depot.schema.json +30 -0
- package/src/controllers/operator/issue-links/issue-links-controller.js +74 -0
- package/src/controllers/operator/issuer-services/issuer-services-controller.js +200 -0
- package/src/controllers/operator/issuer-services/schemas/index.js +7 -0
- package/src/controllers/operator/issuer-services/schemas/issuer-service.schema.js +26 -0
- package/src/controllers/operator/issuer-services/schemas/new-issuer-service.schema.js +137 -0
- package/src/controllers/operator/presentation-links/presentation-links-controller.js +76 -0
- package/src/controllers/operator/presentations/presentations-controller.js +174 -0
- package/src/controllers/operator/presentations/schemas/base-presentation.schema.js +39 -0
- package/src/controllers/operator/presentations/schemas/credential-verification.schema.js +83 -0
- package/src/controllers/operator/presentations/schemas/index.js +23 -0
- package/src/controllers/operator/presentations/schemas/presentation-verification.schema.js +42 -0
- package/src/controllers/operator/presentations/schemas/presentation.schema.js +53 -0
- package/src/controllers/operator/presentations/schemas/w3c-presentation.js +52 -0
- package/src/controllers/operator/relying-party-services/relying-party-services-controller.js +202 -0
- package/src/controllers/operator/relying-party-services/schemas/index.js +7 -0
- package/src/controllers/operator/relying-party-services/schemas/new-relying-party-service.schema.js +91 -0
- package/src/controllers/operator/relying-party-services/schemas/relying-party-service.schema.js +26 -0
- package/src/controllers/operator/tenants/schemas/index.js +33 -0
- package/src/controllers/operator/tenants/schemas/jwk.schema.json +56 -0
- package/src/controllers/operator/tenants/schemas/key-metadata.schema.json +12 -0
- package/src/controllers/operator/tenants/schemas/new-key-metadata.schema.json +42 -0
- package/src/controllers/operator/tenants/schemas/new-key.schema.json +12 -0
- package/src/controllers/operator/tenants/schemas/new-tenant.schema.json +33 -0
- package/src/controllers/operator/tenants/schemas/secret-key.schema.json +33 -0
- package/src/controllers/operator/tenants/schemas/tenant.schema.json +44 -0
- package/src/controllers/operator/tenants/tenants-controller.js +165 -0
- package/src/controllers/root-controller.js +43 -0
- package/src/controllers/vn-api/schemas/index.js +25 -0
- package/src/controllers/vn-api/schemas/presentation-submission.schema.json +41 -0
- package/src/controllers/vn-api/schemas/velocity-presentation-submission.response.200.schema.json +36 -0
- package/src/controllers/vn-api/schemas/velocity-presentation-submission.schema.json +31 -0
- package/src/controllers/vn-api/vn-api-presentation-controller.js +158 -0
- package/src/controllers/vn-api/vn-issuing-controller.js +295 -0
- package/src/entities/credential-types/fetchers/fetch-credential-type-descriptors.js +36 -0
- package/src/entities/credential-types/fetchers/index.js +19 -0
- package/src/entities/credential-types/index.js +19 -0
- package/src/entities/credentials/domain/canonicalize-credentials.js +70 -0
- package/src/entities/credentials/domain/credential-errors.js +25 -0
- package/src/entities/credentials/domain/credential-format.js +21 -0
- package/src/entities/credentials/domain/index.js +22 -0
- package/src/entities/credentials/domain/validate-credential.js +74 -0
- package/src/entities/credentials/facades/anchor-verii-credentials-facade.js +45 -0
- package/src/entities/credentials/facades/build-verii-issuer.js +44 -0
- package/src/entities/credentials/facades/index.js +22 -0
- package/src/entities/credentials/facades/issue-verii-credentials-facade.js +62 -0
- package/src/entities/credentials/facades/sign-verii-credentials-facade.js +56 -0
- package/src/entities/credentials/factories/credential-factory.js +53 -0
- package/src/entities/credentials/factories/index.js +19 -0
- package/src/entities/credentials/index.js +23 -0
- package/src/entities/credentials/orchestrators/create-credentials.js +118 -0
- package/src/entities/credentials/orchestrators/index.js +19 -0
- package/src/entities/credentials/repo/finders-extension.js +94 -0
- package/src/entities/credentials/repo/index.js +19 -0
- package/src/entities/credentials/repo/repo.js +62 -0
- package/src/entities/credentials/repo/update-issued-credential.js +60 -0
- package/src/entities/depots/domain/depot-errors.js +23 -0
- package/src/entities/depots/domain/index.js +20 -0
- package/src/entities/depots/domain/validate-depot.js +38 -0
- package/src/entities/depots/factories/depot-factory.js +50 -0
- package/src/entities/depots/factories/index.js +19 -0
- package/src/entities/depots/index.js +22 -0
- package/src/entities/depots/orchestrators/create-depot.js +31 -0
- package/src/entities/depots/orchestrators/delete-depot.js +43 -0
- package/src/entities/depots/orchestrators/index.js +20 -0
- package/src/entities/depots/repo/find-depot-by-preauth-code.js +30 -0
- package/src/entities/depots/repo/find-depots-extension.js +34 -0
- package/src/entities/depots/repo/index.js +19 -0
- package/src/entities/depots/repo/refresh-preauth-code.js +30 -0
- package/src/entities/depots/repo/repo.js +61 -0
- package/src/entities/exchanges/adapters/index.js +17 -0
- package/src/entities/exchanges/adapters/sign-exchange-response.js +37 -0
- package/src/entities/exchanges/domain/authorize-exchange.js +29 -0
- package/src/entities/exchanges/domain/build-exchange-event.js +19 -0
- package/src/entities/exchanges/domain/build-presentation-request.js +174 -0
- package/src/entities/exchanges/domain/exchange-errors.js +28 -0
- package/src/entities/exchanges/domain/exchange-protocols.js +29 -0
- package/src/entities/exchanges/domain/exchange-states.js +53 -0
- package/src/entities/exchanges/domain/exchange-types.js +22 -0
- package/src/entities/exchanges/domain/generate-issuing-challenge.js +48 -0
- package/src/entities/exchanges/domain/index.js +32 -0
- package/src/entities/exchanges/domain/validate-message-settings.js +33 -0
- package/src/entities/exchanges/domain/validate-new-exchange.js +25 -0
- package/src/entities/exchanges/domain/validate-preauth.js +45 -0
- package/src/entities/exchanges/domain/validate-referenced-service.js +33 -0
- package/src/entities/exchanges/domain/verify-issuing-challenge.js +42 -0
- package/src/entities/exchanges/domain/verify-proof-of-key-possession.js +128 -0
- package/src/entities/exchanges/factories/index.js +19 -0
- package/src/entities/exchanges/factories/init-exchange-factory.js +58 -0
- package/src/entities/exchanges/hooks/exchange-error-hook.js +30 -0
- package/src/entities/exchanges/hooks/index.js +17 -0
- package/src/entities/exchanges/index.js +24 -0
- package/src/entities/exchanges/orchestrators/authenticate.js +67 -0
- package/src/entities/exchanges/orchestrators/credential-offer-request.js +70 -0
- package/src/entities/exchanges/orchestrators/get-credential-manifest.js +84 -0
- package/src/entities/exchanges/orchestrators/get-presentation-request.js +114 -0
- package/src/entities/exchanges/orchestrators/index.js +24 -0
- package/src/entities/exchanges/orchestrators/issue-credentials.js +132 -0
- package/src/entities/exchanges/orchestrators/post-presentation.js +58 -0
- package/src/entities/exchanges/repo/exchange-state-repo-extension.js +78 -0
- package/src/entities/exchanges/repo/index.js +19 -0
- package/src/entities/exchanges/repo/repo.js +52 -0
- package/src/entities/issuer-services/domain/index.js +20 -0
- package/src/entities/issuer-services/domain/issuer-services-errors.js +23 -0
- package/src/entities/issuer-services/domain/validate-issuer-service.js +23 -0
- package/src/entities/issuer-services/factories/index.js +19 -0
- package/src/entities/issuer-services/factories/issuer-service-factory.js +44 -0
- package/src/entities/issuer-services/index.js +21 -0
- package/src/entities/issuer-services/repo/find-issuer-services-extension.js +30 -0
- package/src/entities/issuer-services/repo/index.js +19 -0
- package/src/entities/issuer-services/repo/repo.js +59 -0
- package/src/entities/keys/adapters/index.js +19 -0
- package/src/entities/keys/adapters/load-primary-account.js +39 -0
- package/src/entities/keys/domain/cih-key-purposes.js +23 -0
- package/src/entities/keys/domain/get-key-with-purpose.js +22 -0
- package/src/entities/keys/domain/index.js +22 -0
- package/src/entities/keys/domain/key-errors.js +25 -0
- package/src/entities/keys/domain/normalize-tenant-key.js +33 -0
- package/src/entities/keys/domain/validate-tenant-keys.js +78 -0
- package/src/entities/keys/factories/index.js +19 -0
- package/src/entities/keys/factories/key-factory.js +61 -0
- package/src/entities/keys/index.js +22 -0
- package/src/entities/keys/plugins/index.js +17 -0
- package/src/entities/keys/plugins/kms-plugin.js +61 -0
- package/src/entities/links/domain/build-deep-link-url.js +58 -0
- package/src/entities/links/domain/build-openid4vci-credential-offer-link.js +31 -0
- package/src/entities/links/domain/build-openid4vp-authorization-request-link.js +36 -0
- package/src/entities/links/domain/build-redirect-url.js +29 -0
- package/src/entities/links/domain/build-vn-api-issuing-link.js +54 -0
- package/src/entities/links/domain/build-vn-api-presentation-link.js +49 -0
- package/src/entities/links/domain/index.js +28 -0
- package/src/entities/links/domain/is-preauth-code-auth.js +19 -0
- package/src/entities/links/domain/link-errors.js +23 -0
- package/src/entities/links/domain/validate-issue-link.js +39 -0
- package/src/entities/links/domain/validate-presentation-link.js +39 -0
- package/src/entities/links/index.js +20 -0
- package/src/entities/links/orchestrators/index.js +17 -0
- package/src/entities/links/orchestrators/refresh-links.js +139 -0
- package/src/entities/openid4vci/domain/index.js +20 -0
- package/src/entities/openid4vci/domain/openid4vci-errors.js +24 -0
- package/src/entities/openid4vci/domain/to-credential-configuration-id.js +21 -0
- package/src/entities/openid4vci/index.js +21 -0
- package/src/entities/openid4vci/orchestrators/create-access-token.js +85 -0
- package/src/entities/openid4vci/orchestrators/create-credential.js +108 -0
- package/src/entities/openid4vci/orchestrators/get-authorization-server-metadata.js +22 -0
- package/src/entities/openid4vci/orchestrators/get-credential-issuer-metadata.js +22 -0
- package/src/entities/openid4vci/orchestrators/handle-notification.js +94 -0
- package/src/entities/openid4vci/orchestrators/index.js +24 -0
- package/src/entities/openid4vci/plugins/index.js +19 -0
- package/src/entities/openid4vci/plugins/openid4vci-plugin.js +427 -0
- package/src/entities/openid4vp/domain/index.js +21 -0
- package/src/entities/openid4vp/domain/openid4vp-request-id.js +47 -0
- package/src/entities/openid4vp/domain/presentation-request-expiry.js +37 -0
- package/src/entities/openid4vp/domain/wallet-metadata.js +30 -0
- package/src/entities/openid4vp/index.js +21 -0
- package/src/entities/openid4vp/orchestrators/create-authorization-request.js +183 -0
- package/src/entities/openid4vp/orchestrators/index.js +20 -0
- package/src/entities/openid4vp/orchestrators/post-authorization-response.js +353 -0
- package/src/entities/openid4vp/plugins/index.js +19 -0
- package/src/entities/openid4vp/plugins/openid4vp-plugin.js +174 -0
- package/src/entities/presentations/domain/index.js +20 -0
- package/src/entities/presentations/domain/presentation-format.js +20 -0
- package/src/entities/presentations/domain/validate-presentation.js +178 -0
- package/src/entities/presentations/factories/index.js +19 -0
- package/src/entities/presentations/factories/presentation-factory.js +96 -0
- package/src/entities/presentations/index.js +21 -0
- package/src/entities/presentations/orchestrators/index.js +19 -0
- package/src/entities/presentations/orchestrators/verify-presentation.js +131 -0
- package/src/entities/presentations/repo/add-verification.js +31 -0
- package/src/entities/presentations/repo/finders-extension.js +50 -0
- package/src/entities/presentations/repo/index.js +19 -0
- package/src/entities/presentations/repo/repo.js +58 -0
- package/src/entities/relying-party-services/factories/index.js +19 -0
- package/src/entities/relying-party-services/factories/relying-party-service-factory.js +43 -0
- package/src/entities/relying-party-services/index.js +20 -0
- package/src/entities/relying-party-services/repo/find-relying-party-services-extension.js +30 -0
- package/src/entities/relying-party-services/repo/index.js +19 -0
- package/src/entities/relying-party-services/repo/repo.js +55 -0
- package/src/entities/service-configurations/domain/canonicalize-service-configuration.js +12 -0
- package/src/entities/service-configurations/domain/index.js +22 -0
- package/src/entities/service-configurations/domain/service-configuration-errors.js +24 -0
- package/src/entities/service-configurations/domain/validate-service-configuration.js +31 -0
- package/src/entities/service-configurations/domain/validate-update-service-configuration.js +19 -0
- package/src/entities/service-configurations/index.js +20 -0
- package/src/entities/service-configurations/orchestrators/create-service-configuration.js +34 -0
- package/src/entities/service-configurations/orchestrators/delete-service-configuration.js +41 -0
- package/src/entities/service-configurations/orchestrators/index.js +21 -0
- package/src/entities/service-configurations/orchestrators/update-service-configuration.js +40 -0
- package/src/entities/tenants/adapters/index.js +20 -0
- package/src/entities/tenants/adapters/load-tenant-did-doc.js +47 -0
- package/src/entities/tenants/adapters/load-tenant-profile.js +40 -0
- package/src/entities/tenants/domain/index.js +20 -0
- package/src/entities/tenants/domain/tenant-errors.js +29 -0
- package/src/entities/tenants/domain/validate-new-tenant.js +49 -0
- package/src/entities/tenants/factories/index.js +19 -0
- package/src/entities/tenants/factories/tenant-factory.js +41 -0
- package/src/entities/tenants/index.js +24 -0
- package/src/entities/tenants/orchestrators/create-tenant.js +116 -0
- package/src/entities/tenants/orchestrators/delete-tenant.js +45 -0
- package/src/entities/tenants/orchestrators/find-tenants.js +22 -0
- package/src/entities/tenants/orchestrators/index.js +21 -0
- package/src/entities/tenants/plugins/index.js +3 -0
- package/src/entities/tenants/plugins/tenant-loader-plugin.js +64 -0
- package/src/entities/tenants/repo/index.js +19 -0
- package/src/entities/tenants/repo/insert-tenant-extension.js +36 -0
- package/src/entities/tenants/repo/repo.js +51 -0
- package/src/entities/tokens/domains/access-token.js +74 -0
- package/src/entities/tokens/domains/index.js +19 -0
- package/src/entities/tokens/index.js +19 -0
- package/src/index.js +3 -0
- package/src/init-server.js +88 -0
- package/src/main.js +25 -0
- package/src/schemas/index.js +20 -0
- package/src/schemas/oauth-error-response.schema.js +27 -0
- package/src/standalone.js +8 -0
- package/src/start-app-server.js +27 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const fp = require('fastify-plugin');
|
|
19
|
+
const { Openid4vpVerifier } = require('@openid4vc/openid4vp');
|
|
20
|
+
const {
|
|
21
|
+
Oauth2Error,
|
|
22
|
+
Oauth2ErrorCodes,
|
|
23
|
+
Oauth2ServerErrorResponseError,
|
|
24
|
+
} = require('@openid4vc/oauth2');
|
|
25
|
+
const { KeyPurposes } = require('@verii/crypto');
|
|
26
|
+
const { toDidUrl } = require('@verii/did-doc');
|
|
27
|
+
|
|
28
|
+
const openid4vpPlugin = async (fastify) => {
|
|
29
|
+
fastify.decorateRequest(
|
|
30
|
+
'getOpenId4VpVerifier',
|
|
31
|
+
async function getOpenId4VpVerifier() {
|
|
32
|
+
return buildVerifier(this);
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
fastify.decorate('openid4vpErrorHandler', (error, request, reply) => {
|
|
36
|
+
if (error.code === 'FST_ERR_VALIDATION') {
|
|
37
|
+
reply.status(error.statusCode);
|
|
38
|
+
return {
|
|
39
|
+
error: Oauth2ErrorCodes.InvalidRequest,
|
|
40
|
+
error_description: getOpenid4vpValidationErrorDescription(error),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (error.errorResponse == null) {
|
|
44
|
+
const statusCode = error.statusCode ?? 500;
|
|
45
|
+
reply.status(statusCode);
|
|
46
|
+
if (statusCode >= 500) {
|
|
47
|
+
request.log.error(error);
|
|
48
|
+
return {
|
|
49
|
+
error: Oauth2ErrorCodes.ServerError,
|
|
50
|
+
error_description: 'Unexpected server error',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
error: Oauth2ErrorCodes.InvalidRequest,
|
|
55
|
+
error_description: error.message,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
reply.status(error.status);
|
|
59
|
+
return error.errorResponse;
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const getOpenid4vpValidationErrorDescription = (error) => {
|
|
64
|
+
if (
|
|
65
|
+
error.validation?.some(
|
|
66
|
+
({ instancePath, keyword }) =>
|
|
67
|
+
instancePath === '/vp_token' && keyword === 'pattern',
|
|
68
|
+
)
|
|
69
|
+
) {
|
|
70
|
+
return 'OpenID4VP VP token is missing';
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (error.validation == null || error.validation.length === 0) {
|
|
74
|
+
return error.message;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return `${error.validationContext}${error.validation[0].instancePath} ${error.validation[0].message}`;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const buildVerifier = (context) => {
|
|
81
|
+
const { tenant } = context;
|
|
82
|
+
const exchangesKey = tenant.keysByPurpose[KeyPurposes.EXCHANGES];
|
|
83
|
+
const signer = {
|
|
84
|
+
method: 'did',
|
|
85
|
+
didUrl: toDidUrl(tenant.did, exchangesKey.kidFragment),
|
|
86
|
+
alg: 'ES256K',
|
|
87
|
+
kid: toDidUrl(tenant.did, exchangesKey.kidFragment),
|
|
88
|
+
};
|
|
89
|
+
const verifier = new Openid4vpVerifier({
|
|
90
|
+
callbacks: {
|
|
91
|
+
signJwt: (jwtSigner, jwt) => signJwt(jwtSigner, jwt, context),
|
|
92
|
+
encryptJwe: () => {
|
|
93
|
+
throw new Error('OpenID4VP encrypted responses are not supported');
|
|
94
|
+
},
|
|
95
|
+
verifyJwt: () => {
|
|
96
|
+
throw new Error('OpenID4VP response verification is not implemented');
|
|
97
|
+
},
|
|
98
|
+
decryptJwe: () => {
|
|
99
|
+
throw new Error('OpenID4VP encrypted responses are not supported');
|
|
100
|
+
},
|
|
101
|
+
hash: () => {
|
|
102
|
+
throw new Error('OpenID4VP transaction data is not implemented');
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const createAuthorizationRequestJwt = async ({
|
|
108
|
+
requestId,
|
|
109
|
+
authorizationRequestPayload,
|
|
110
|
+
requestUri,
|
|
111
|
+
expiresInSeconds,
|
|
112
|
+
walletNonce,
|
|
113
|
+
}) => {
|
|
114
|
+
const { jar } = await verifier.createOpenId4vpAuthorizationRequest({
|
|
115
|
+
authorizationRequestPayload,
|
|
116
|
+
wallet: { expectedNonce: walletNonce },
|
|
117
|
+
jar: {
|
|
118
|
+
requestUri,
|
|
119
|
+
jwtSigner: signer,
|
|
120
|
+
expiresInSeconds,
|
|
121
|
+
additionalJwtPayload: {
|
|
122
|
+
iss: authorizationRequestPayload.client_id,
|
|
123
|
+
jti: requestId,
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
return jar.authorizationRequestJwt;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const parseAuthorizationResponse = async (options) => {
|
|
132
|
+
try {
|
|
133
|
+
return await verifier.parseOpenid4vpAuthorizationResponse(options);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
if (error instanceof Oauth2ServerErrorResponseError) {
|
|
136
|
+
throw error;
|
|
137
|
+
}
|
|
138
|
+
if (error instanceof Oauth2Error) {
|
|
139
|
+
throw new Oauth2ServerErrorResponseError(
|
|
140
|
+
{
|
|
141
|
+
error: Oauth2ErrorCodes.InvalidRequest,
|
|
142
|
+
error_description: error.message,
|
|
143
|
+
},
|
|
144
|
+
{ status: 400 },
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
return { createAuthorizationRequestJwt, parseAuthorizationResponse };
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const signJwt = async (jwtSigner, { header, payload }, context) => {
|
|
155
|
+
const { kms, tenant } = context;
|
|
156
|
+
const exchangesKey = tenant.keysByPurpose[KeyPurposes.EXCHANGES];
|
|
157
|
+
const jwt = await kms.signJwt(payload, exchangesKey._id, {
|
|
158
|
+
alg: jwtSigner.alg,
|
|
159
|
+
kid: header.kid,
|
|
160
|
+
typ: header.typ,
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
jwt,
|
|
165
|
+
signerJwk: exchangesKey.publicJwk,
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
module.exports = {
|
|
170
|
+
openid4vpPlugin: fp(openid4vpPlugin, {
|
|
171
|
+
name: 'openid4vp-plugin',
|
|
172
|
+
dependencies: [],
|
|
173
|
+
}),
|
|
174
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
module.exports = {
|
|
18
|
+
...require('./presentation-format'),
|
|
19
|
+
...require('./validate-presentation'),
|
|
20
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
const PresentationFormat = {
|
|
18
|
+
JWT_VP: 'JWT_VP',
|
|
19
|
+
};
|
|
20
|
+
module.exports = { PresentationFormat };
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
const newError = require('http-errors');
|
|
18
|
+
const { first, includes, isEmpty, castArray, omit } = require('lodash/fp');
|
|
19
|
+
const { JSONPath } = require('jsonpath-plus');
|
|
20
|
+
|
|
21
|
+
const VALID_PRESENTATION_CONTEXTS = [
|
|
22
|
+
'https://www.w3.org/2018/credentials/v1',
|
|
23
|
+
'https://www.w3.org/ns/credentials/v2',
|
|
24
|
+
];
|
|
25
|
+
const SUPPORTED_DESCRIPTOR_FORMATS = ['jwt_vc', 'jwt_vp'];
|
|
26
|
+
const SUPPORTED_NESTED_VP_TOKEN_PATHS = ['$', '$[0]'];
|
|
27
|
+
const presentationSchema = {
|
|
28
|
+
$ref: 'https://velocitycareerlabs.io/velocity-presentation-submission.schema.json#',
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const validatePresentation = (
|
|
32
|
+
presentation,
|
|
33
|
+
exchange,
|
|
34
|
+
context,
|
|
35
|
+
presentationSubmission = presentation.presentation_submission,
|
|
36
|
+
) => {
|
|
37
|
+
const submittedPresentation = {
|
|
38
|
+
...presentation,
|
|
39
|
+
presentation_submission: presentationSubmission,
|
|
40
|
+
};
|
|
41
|
+
const validateSchema = context.compileValidationSchema(presentationSchema);
|
|
42
|
+
if (!validateSchema(submittedPresentation)) {
|
|
43
|
+
throw newError(
|
|
44
|
+
400,
|
|
45
|
+
`${validateSchema.errors[0].instancePath.substring(1)} ${
|
|
46
|
+
validateSchema.errors[0].message
|
|
47
|
+
}`,
|
|
48
|
+
{
|
|
49
|
+
errorCode: 'request_validation_failed',
|
|
50
|
+
},
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
validatePresentationContext(presentation, context);
|
|
54
|
+
verifyPresentationSubmissionAgainstDefinition(
|
|
55
|
+
presentationSubmission,
|
|
56
|
+
presentation,
|
|
57
|
+
);
|
|
58
|
+
verifyPresentationAgainstExchange(presentationSubmission, exchange);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const validatePresentationContext = (presentation) => {
|
|
62
|
+
if (
|
|
63
|
+
!includes(
|
|
64
|
+
first(castArray(presentation?.['@context'])),
|
|
65
|
+
VALID_PRESENTATION_CONTEXTS,
|
|
66
|
+
)
|
|
67
|
+
) {
|
|
68
|
+
throw newError(400, 'presentation @context is invalid', {
|
|
69
|
+
errorCode: 'presentation_invalid',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const verifyPresentationAgainstExchange = (
|
|
75
|
+
presentationSubmission,
|
|
76
|
+
exchange,
|
|
77
|
+
) => {
|
|
78
|
+
if (presentationSubmission.definition_id == null) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const [exchangeId, disclosureId] =
|
|
83
|
+
presentationSubmission.definition_id.split('.');
|
|
84
|
+
|
|
85
|
+
if (exchange?._id.toString() !== exchangeId) {
|
|
86
|
+
throw newError(400, 'Mismatched Exchange Ids', {
|
|
87
|
+
exchange,
|
|
88
|
+
presentationSubmission,
|
|
89
|
+
errorCode: 'presentation_mismatch_exchange',
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (exchange?.serviceId.toString() !== disclosureId) {
|
|
93
|
+
throw newError(400, 'Mismatched Service Ids', {
|
|
94
|
+
exchange,
|
|
95
|
+
presentationSubmission,
|
|
96
|
+
errorCode: 'presentation_mismatch_service',
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const verifyPresentationSubmissionAgainstDefinition = (
|
|
102
|
+
presentationSubmission,
|
|
103
|
+
presentation,
|
|
104
|
+
) => {
|
|
105
|
+
const presentationContent = omit(['presentation_submission'], presentation);
|
|
106
|
+
for (const descriptor of presentationSubmission.descriptor_map) {
|
|
107
|
+
validateDescriptorFormat(descriptor);
|
|
108
|
+
validateDescriptorPath(descriptor);
|
|
109
|
+
const result = getJsonAtPath(
|
|
110
|
+
getDescriptorPath(descriptor),
|
|
111
|
+
presentationContent,
|
|
112
|
+
);
|
|
113
|
+
if (isEmpty(result)) {
|
|
114
|
+
throw newError(
|
|
115
|
+
400,
|
|
116
|
+
'Presentation path descriptor does not reference any valid data: JSONPath expression returned no results',
|
|
117
|
+
{
|
|
118
|
+
descriptor,
|
|
119
|
+
json: presentationContent,
|
|
120
|
+
errorCode: 'presentation_jsonpath_empty',
|
|
121
|
+
},
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const validateDescriptorFormat = (descriptor) => {
|
|
128
|
+
if (!SUPPORTED_DESCRIPTOR_FORMATS.includes(descriptor.format)) {
|
|
129
|
+
throw newError(
|
|
130
|
+
400,
|
|
131
|
+
"Velocity Presentation Submission only supports 'jwt_vc' or 'jwt_vp' inputs",
|
|
132
|
+
{ errorCode: 'presentation_missing_jwtvc_or_jwtvp' },
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const validateDescriptorPath = (descriptor) => {
|
|
138
|
+
if (descriptor.path_nested != null) {
|
|
139
|
+
if (descriptor.path_nested.path_nested != null) {
|
|
140
|
+
throw newError(
|
|
141
|
+
400,
|
|
142
|
+
'Presentation path descriptor uses unsupported recursive nested paths',
|
|
143
|
+
{
|
|
144
|
+
descriptor,
|
|
145
|
+
errorCode: 'presentation_jsonpath_unsupported',
|
|
146
|
+
},
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
validateDescriptorFormat(descriptor.path_nested);
|
|
150
|
+
}
|
|
151
|
+
if (
|
|
152
|
+
descriptor.path_nested != null &&
|
|
153
|
+
!SUPPORTED_NESTED_VP_TOKEN_PATHS.includes(descriptor.path)
|
|
154
|
+
) {
|
|
155
|
+
throw newError(
|
|
156
|
+
400,
|
|
157
|
+
'Presentation path descriptor uses an unsupported nested VP-token path',
|
|
158
|
+
{
|
|
159
|
+
descriptor,
|
|
160
|
+
errorCode: 'presentation_jsonpath_unsupported',
|
|
161
|
+
},
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const getDescriptorPath = (descriptor) =>
|
|
167
|
+
descriptor.path_nested?.path ?? descriptor.path;
|
|
168
|
+
|
|
169
|
+
const getJsonAtPath = (path, json) =>
|
|
170
|
+
JSONPath({
|
|
171
|
+
path,
|
|
172
|
+
json,
|
|
173
|
+
preventEval: true,
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
module.exports = {
|
|
177
|
+
validatePresentation,
|
|
178
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
module.exports = {
|
|
18
|
+
...require('./presentation-factory'),
|
|
19
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const { register } = require('@spencejs/spence-factories');
|
|
18
|
+
const { ObjectId } = require('mongodb');
|
|
19
|
+
const {
|
|
20
|
+
generatePresentationJwt,
|
|
21
|
+
generateCredentialJwt,
|
|
22
|
+
} = require('@verii/jwt');
|
|
23
|
+
const { generateKeyPair } = require('@verii/crypto');
|
|
24
|
+
const { getDidUriFromJwk } = require('@verii/did-doc/src/did-jwk');
|
|
25
|
+
const { hashOffer } = require('@verii/verii-issuing');
|
|
26
|
+
const { initTenantFactory } = require('../../tenants/factories');
|
|
27
|
+
const { initDepotFactory } = require('../../depots/factories');
|
|
28
|
+
const { initExchangeFactory } = require('../../exchanges/factories');
|
|
29
|
+
const { PresentationFormat } = require('../domain/presentation-format');
|
|
30
|
+
const { presentationsRepoPlugin } = require('../repo');
|
|
31
|
+
|
|
32
|
+
const initPresentationFactory = (app) =>
|
|
33
|
+
register(
|
|
34
|
+
'presentation',
|
|
35
|
+
presentationsRepoPlugin(app)({ config: app.config }),
|
|
36
|
+
async (overrides, { getOrBuild }) => {
|
|
37
|
+
const tenant = await getOrBuild('tenant', initTenantFactory(app));
|
|
38
|
+
const depot = await getOrBuild('depot', initDepotFactory(app));
|
|
39
|
+
const exchange = await getOrBuild('exchange', initExchangeFactory(app));
|
|
40
|
+
const holderKeyPair = await getOrBuild('holderKey', defaultKeyPair);
|
|
41
|
+
|
|
42
|
+
const vcContent = await getOrBuild('vcContent', defaultVcContent);
|
|
43
|
+
const credentialDid = await getOrBuild(
|
|
44
|
+
'credentialDid',
|
|
45
|
+
defaultCredentialDid(vcContent),
|
|
46
|
+
);
|
|
47
|
+
const vcKeyPair = await getOrBuild('vcKeyPair', defaultKeyPair);
|
|
48
|
+
|
|
49
|
+
const holderDid = getDidUriFromJwk(holderKeyPair.publicKey);
|
|
50
|
+
const vc = await generateCredentialJwt(
|
|
51
|
+
createVcPayload(tenant, credentialDid, holderDid, vcContent),
|
|
52
|
+
vcKeyPair.privateKey,
|
|
53
|
+
`${credentialDid}#key-1`,
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const presentation = await generatePresentationJwt(
|
|
57
|
+
{ verifiableCredential: [vc], issuer: holderDid },
|
|
58
|
+
holderKeyPair.privateKey,
|
|
59
|
+
`${holderDid}#key`,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
format: PresentationFormat.JWT_VP,
|
|
64
|
+
exchangeId: new ObjectId(exchange._id),
|
|
65
|
+
depotId: new ObjectId(depot._id),
|
|
66
|
+
tenantId: new ObjectId(tenant._id),
|
|
67
|
+
presentation,
|
|
68
|
+
...overrides(),
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const defaultCredentialDid = (vcContent) => () =>
|
|
74
|
+
`did:velocity:v2:A:1:i:${hashOffer(vcContent)}`;
|
|
75
|
+
|
|
76
|
+
const createVcPayload = (tenant, credentialDid, holderDid, content) => ({
|
|
77
|
+
...content,
|
|
78
|
+
id: credentialDid,
|
|
79
|
+
issuer: { id: tenant.did },
|
|
80
|
+
credentialSubject: {
|
|
81
|
+
id: holderDid,
|
|
82
|
+
...content.credentialSubject,
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const defaultVcContent = () => ({
|
|
87
|
+
type: ['Employment'],
|
|
88
|
+
credentialSubject: {
|
|
89
|
+
legalEmployer: { name: 'ExampleEmployer', identifier: 'did:example.com' },
|
|
90
|
+
roleName: 'CEO',
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const defaultKeyPair = () => generateKeyPair({ format: 'jwk' });
|
|
95
|
+
|
|
96
|
+
module.exports = { initPresentationFactory, defaultVcContent };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
module.exports = {
|
|
18
|
+
...require('./domain'),
|
|
19
|
+
...require('./factories'),
|
|
20
|
+
...require('./orchestrators'),
|
|
21
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2024 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
module.exports = {
|
|
18
|
+
...require('./verify-presentation'),
|
|
19
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
const { jwtDecode, verifyPresentationJwt } = require('@verii/jwt');
|
|
18
|
+
const { getJwkFromDidUri } = require('@verii/did-doc');
|
|
19
|
+
const { CheckResults } = require('@verii/vc-checks');
|
|
20
|
+
const { verifyCredentials } = require('@verii/verii-verification');
|
|
21
|
+
const { KeyPurposes } = require('@verii/crypto');
|
|
22
|
+
const {
|
|
23
|
+
resolveDid,
|
|
24
|
+
getOrganizationVerifiedProfile,
|
|
25
|
+
getCredentialTypeMetadata,
|
|
26
|
+
} = require('@verii/common-fetchers');
|
|
27
|
+
const { flow, every, includes, map } = require('lodash/fp');
|
|
28
|
+
const { mapWithIndex } = require('@verii/common-functions');
|
|
29
|
+
const newError = require('http-errors');
|
|
30
|
+
const { PresentationFormat } = require('../domain/presentation-format');
|
|
31
|
+
const {
|
|
32
|
+
CredentialFormat,
|
|
33
|
+
} = require('../../credentials/domain/credential-format');
|
|
34
|
+
|
|
35
|
+
const verifyPresentation = async (presentation, context) => {
|
|
36
|
+
const { tenant } = context;
|
|
37
|
+
const { header, payload } = jwtDecode(presentation);
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const jwk = header.jwk ?? getJwkFromDidUri(header.kid);
|
|
41
|
+
await verifyPresentationJwt(presentation, jwk);
|
|
42
|
+
} catch {
|
|
43
|
+
return {
|
|
44
|
+
format: PresentationFormat.JWT_VP,
|
|
45
|
+
presentation,
|
|
46
|
+
w3cPresentation: payload.vp,
|
|
47
|
+
verification: {
|
|
48
|
+
verified: false,
|
|
49
|
+
tamperCheck: CheckResults.FAIL,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// eslint-disable-next-line better-mutation/no-mutation
|
|
55
|
+
context.caoDid = tenant.caoDid;
|
|
56
|
+
|
|
57
|
+
const credentialCheckResults = await verifyCredentials(
|
|
58
|
+
{
|
|
59
|
+
credentials: payload.vp.verifiableCredential,
|
|
60
|
+
expectedHolderDid: payload.iss,
|
|
61
|
+
relyingParty: {
|
|
62
|
+
dltOperatorKMSKeyId:
|
|
63
|
+
tenant.keysByPurpose[KeyPurposes.DLT_TRANSACTIONS]._id,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
resolveDid,
|
|
68
|
+
getOrganizationVerifiedProfile,
|
|
69
|
+
getCredentialTypeMetadata,
|
|
70
|
+
},
|
|
71
|
+
context,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const credentials = mapWithIndex((credentialCheckResult, index) => {
|
|
75
|
+
const conclusion = calcCredentialConclusion(
|
|
76
|
+
Object.values(credentialCheckResult.credentialChecks),
|
|
77
|
+
);
|
|
78
|
+
return {
|
|
79
|
+
format: CredentialFormat.JWT_VC,
|
|
80
|
+
credential: payload.vp.verifiableCredential[index],
|
|
81
|
+
w3cCredential: credentialCheckResult.credential,
|
|
82
|
+
conclusion,
|
|
83
|
+
verified: conclusion === CheckResults.PASS,
|
|
84
|
+
tamperCheck: credentialCheckResult.credentialChecks.UNTAMPERED,
|
|
85
|
+
trustedIssuerCheck: credentialCheckResult.credentialChecks.TRUSTED_ISSUER,
|
|
86
|
+
trustedHolderCheck: credentialCheckResult.credentialChecks.TRUSTED_HOLDER,
|
|
87
|
+
revocationCheck: credentialCheckResult.credentialChecks.UNREVOKED,
|
|
88
|
+
expiryCheck: credentialCheckResult.credentialChecks.UNEXPIRED,
|
|
89
|
+
};
|
|
90
|
+
}, credentialCheckResults);
|
|
91
|
+
|
|
92
|
+
if (
|
|
93
|
+
flow(
|
|
94
|
+
map('conclusion'),
|
|
95
|
+
includes(CheckResults.VOUCHER_RESERVE_EXHAUSTED),
|
|
96
|
+
)(credentials)
|
|
97
|
+
) {
|
|
98
|
+
throw newError(402, 'Verification vouchers exhausted', {
|
|
99
|
+
errorCode: 'verification_payment_required',
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
format: PresentationFormat.JWT_VP,
|
|
105
|
+
presentation,
|
|
106
|
+
w3cPresentation: payload.vp,
|
|
107
|
+
verification: {
|
|
108
|
+
verified: every(({ verified }) => verified, credentials),
|
|
109
|
+
tamperCheck: CheckResults.PASS,
|
|
110
|
+
credentials,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const calcCredentialConclusion = (vals) => {
|
|
116
|
+
for (const val of vals) {
|
|
117
|
+
if (val === CheckResults.VOUCHER_RESERVE_EXHAUSTED) {
|
|
118
|
+
return CheckResults.VOUCHER_RESERVE_EXHAUSTED;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (![CheckResults.PASS, CheckResults.NOT_APPLICABLE].includes(val)) {
|
|
122
|
+
return CheckResults.FAIL;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return CheckResults.PASS;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
module.exports = {
|
|
130
|
+
verifyPresentation,
|
|
131
|
+
};
|