@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,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const Oidc4vciErrors = {
|
|
19
|
+
PRE_AUTHORIZATION_CODE_NOT_MATCHED: 'pre_authorization_code_not_matched',
|
|
20
|
+
UNKNOWN_CREDENTIAL_IDENTIFIER: 'unknown_credential_identifier',
|
|
21
|
+
INVALID_NOTIFICATION_ID: 'invalid_notification_id',
|
|
22
|
+
INVALID_NOTIFICATION_REQUEST: 'invalid_notification_request',
|
|
23
|
+
};
|
|
24
|
+
module.exports = { Oidc4vciErrors };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
const toCredentialConfigurationId = (credentialType) =>
|
|
19
|
+
`foundation.velocitynetwork.${credentialType}`;
|
|
20
|
+
|
|
21
|
+
module.exports = { toCredentialConfigurationId };
|
|
@@ -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('./orchestrators'),
|
|
20
|
+
...require('./plugins'),
|
|
21
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
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 { filter, flow, isEmpty, map } = require('lodash/fp');
|
|
18
|
+
const { calcSha384 } = require('@verii/crypto');
|
|
19
|
+
const { toCredentialConfigurationId } = require('../domain');
|
|
20
|
+
|
|
21
|
+
const createAccessToken = async (accessTokenParameters, context) => {
|
|
22
|
+
const openid4VciIssuer = await context.getOpenId4VciIssuer();
|
|
23
|
+
await openid4VciIssuer.validateAccessTokenParams(
|
|
24
|
+
accessTokenParameters,
|
|
25
|
+
context,
|
|
26
|
+
);
|
|
27
|
+
const depot = await context.repos.depots.findDepotByPreauthCode(
|
|
28
|
+
accessTokenParameters['pre-authorized_code'],
|
|
29
|
+
);
|
|
30
|
+
await openid4VciIssuer.verifyPreauthCode(
|
|
31
|
+
calcSha384(accessTokenParameters['pre-authorized_code']),
|
|
32
|
+
depot?.preauthCodeHash,
|
|
33
|
+
accessTokenParameters,
|
|
34
|
+
context,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const [credentials, issuerService] = await Promise.all([
|
|
38
|
+
context.repos.credentials.findByDepotId({
|
|
39
|
+
depotId: depot._id,
|
|
40
|
+
claimable: true,
|
|
41
|
+
}),
|
|
42
|
+
context.repos.issuerServices.findById(depot.serviceId),
|
|
43
|
+
]);
|
|
44
|
+
|
|
45
|
+
const accessTokenResponse = await openid4VciIssuer.generateAccessToken(
|
|
46
|
+
accessTokenParameters,
|
|
47
|
+
buildAuthorizationDetails(
|
|
48
|
+
credentials,
|
|
49
|
+
accessTokenParameters.authorization_details,
|
|
50
|
+
),
|
|
51
|
+
issuerService.authTokensExpireIn,
|
|
52
|
+
);
|
|
53
|
+
return accessTokenResponse;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const buildAuthorizationDetails = (
|
|
57
|
+
credentials,
|
|
58
|
+
requestedAuthorizationDetails,
|
|
59
|
+
) => {
|
|
60
|
+
const pipeline = [
|
|
61
|
+
map((credential) => ({
|
|
62
|
+
type: 'openid_credential',
|
|
63
|
+
credential_configuration_id: toCredentialConfigurationId(
|
|
64
|
+
credential.typeMetadata.credentialType,
|
|
65
|
+
),
|
|
66
|
+
credential_identifiers: [`${credential._id}`],
|
|
67
|
+
})),
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
if (!isEmpty(requestedAuthorizationDetails)) {
|
|
71
|
+
const requestedCredentialConfigurationIds = map(
|
|
72
|
+
'credential_configuration_id',
|
|
73
|
+
requestedAuthorizationDetails,
|
|
74
|
+
);
|
|
75
|
+
pipeline.push(
|
|
76
|
+
filter(({ credential_configuration_id: credentialConfigurationId }) =>
|
|
77
|
+
requestedCredentialConfigurationIds.includes(credentialConfigurationId),
|
|
78
|
+
),
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return flow(pipeline)(credentials);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
module.exports = { createAccessToken };
|
|
@@ -0,0 +1,108 @@
|
|
|
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 { Oauth2ServerErrorResponseError } = require('@openid4vc/oauth2');
|
|
18
|
+
const { jwtDecode } = require('@verii/jwt');
|
|
19
|
+
const { nanoid } = require('nanoid');
|
|
20
|
+
const { Oidc4vciErrors } = require('../domain');
|
|
21
|
+
const {
|
|
22
|
+
buildExchangeEvent,
|
|
23
|
+
ExchangeProtocols,
|
|
24
|
+
ExchangeStates,
|
|
25
|
+
ExchangeTypes,
|
|
26
|
+
} = require('../../exchanges');
|
|
27
|
+
const { signVeriiCredentialsFacade } = require('../../credentials');
|
|
28
|
+
|
|
29
|
+
const createCredential = async (credentialRequestParameters, context) => {
|
|
30
|
+
const { repos } = context;
|
|
31
|
+
const openid4VciIssuer = await context.getOpenId4VciIssuer();
|
|
32
|
+
const credentialRequest = await openid4VciIssuer.getCredentialRequest(
|
|
33
|
+
credentialRequestParameters,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const credential = await repos.credentials.findOne({
|
|
37
|
+
filter: { _id: credentialRequest.credentialIdentifier },
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (credential == null) {
|
|
41
|
+
throw new Oauth2ServerErrorResponseError({
|
|
42
|
+
error: Oidc4vciErrors.UNKNOWN_CREDENTIAL_IDENTIFIER,
|
|
43
|
+
error_description: `Error identifying credential ${credentialRequest.credentialIdentifier}`,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const depot = await repos.depots.findById(credential.depotId);
|
|
48
|
+
const service = await repos.issuerServices.findById(depot.serviceId);
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
const { payload } = jwtDecode(credentialRequest.proofs.jwt[0]);
|
|
52
|
+
const credentialSubjectId = payload.iss;
|
|
53
|
+
|
|
54
|
+
const { vcJwt, credentialMetadata } = await signVeriiCredentialsFacade(
|
|
55
|
+
[credential.content],
|
|
56
|
+
credentialSubjectId,
|
|
57
|
+
[credential.typeMetadata],
|
|
58
|
+
service,
|
|
59
|
+
context,
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const newExchange = buildExchange(
|
|
63
|
+
service,
|
|
64
|
+
ExchangeStates.CREDENTIALS_SIGNED,
|
|
65
|
+
{ credentialMetadata },
|
|
66
|
+
);
|
|
67
|
+
await repos.credentials.updateIssuedCredential(
|
|
68
|
+
credential._id,
|
|
69
|
+
jwtDecode(vcJwt).payload.vc.id,
|
|
70
|
+
vcJwt,
|
|
71
|
+
credentialSubjectId,
|
|
72
|
+
false,
|
|
73
|
+
newExchange,
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
credentials: [{ credential: vcJwt }],
|
|
78
|
+
notification_id: newExchange.id,
|
|
79
|
+
};
|
|
80
|
+
} catch (error) {
|
|
81
|
+
context.log.error(error);
|
|
82
|
+
await repos.credentials.update(credential._id, {
|
|
83
|
+
exchange: buildExchange(service, ExchangeStates.UNEXPECTED_ERROR, {
|
|
84
|
+
err: error.message,
|
|
85
|
+
errorCode: error.errorCode,
|
|
86
|
+
errorDescription: error.error_description,
|
|
87
|
+
}),
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
throw new Oauth2ServerErrorResponseError({
|
|
91
|
+
error: 'server_error',
|
|
92
|
+
error_description: error.message,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const buildExchange = (service, state, overrides) => ({
|
|
98
|
+
id: nanoid(12),
|
|
99
|
+
type: ExchangeTypes.ISSUER,
|
|
100
|
+
serviceId: service._id,
|
|
101
|
+
protocolMetadata: {
|
|
102
|
+
protocol: ExchangeProtocols.OPENID4VCI,
|
|
103
|
+
},
|
|
104
|
+
events: [buildExchangeEvent(ExchangeStates.NEW), buildExchangeEvent(state)],
|
|
105
|
+
...overrides,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
module.exports = { createCredential };
|
|
@@ -0,0 +1,22 @@
|
|
|
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 getAuthorizationServerMetadata = async (context) => {
|
|
18
|
+
const issuer = await context.getOpenId4VciIssuer();
|
|
19
|
+
return issuer.getAuthorizationServerMetadata({ includeSignedMetadata: true });
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
module.exports = { getAuthorizationServerMetadata };
|
|
@@ -0,0 +1,22 @@
|
|
|
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 getCredentialIssuerMetadata = async (context) => {
|
|
18
|
+
const issuer = await context.getOpenId4VciIssuer();
|
|
19
|
+
return issuer.getCredentialIssuerMetadata();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
module.exports = { getCredentialIssuerMetadata };
|
|
@@ -0,0 +1,94 @@
|
|
|
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 { Oauth2ServerErrorResponseError } = require('@openid4vc/oauth2');
|
|
18
|
+
const { omitBy, isNil } = require('lodash/fp');
|
|
19
|
+
const { Oidc4vciErrors } = require('../domain');
|
|
20
|
+
const { ExchangeStates } = require('../../exchanges');
|
|
21
|
+
const { anchorVeriiCredentialsFacade } = require('../../credentials');
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line complexity
|
|
24
|
+
const handleNotification = async (notificationRequest, context) => {
|
|
25
|
+
const { repos } = context;
|
|
26
|
+
const credential = await repos.credentials.findOne(
|
|
27
|
+
{ filter: { 'exchange.id': notificationRequest.notification_id } },
|
|
28
|
+
{ exchange: 1 },
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
if (credential?.exchange == null) {
|
|
32
|
+
throw new Oauth2ServerErrorResponseError({
|
|
33
|
+
error: Oidc4vciErrors.INVALID_NOTIFICATION_ID,
|
|
34
|
+
error_description: `Error identifying notification ${notificationRequest.notification_id}`,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
switch (notificationRequest.event) {
|
|
40
|
+
case 'credential_accepted': {
|
|
41
|
+
await anchorVeriiCredentialsFacade(
|
|
42
|
+
[credential?.exchange.credentialMetadata],
|
|
43
|
+
context,
|
|
44
|
+
);
|
|
45
|
+
await repos.credentials.addExchangeState(
|
|
46
|
+
credential._id,
|
|
47
|
+
ExchangeStates.COMPLETE,
|
|
48
|
+
{ acceptedAt: new Date() },
|
|
49
|
+
);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case 'credential_deleted':
|
|
53
|
+
await repos.credentials.addExchangeState(
|
|
54
|
+
credential._id,
|
|
55
|
+
ExchangeStates.COMPLETE,
|
|
56
|
+
{ deletedAt: new Date() },
|
|
57
|
+
);
|
|
58
|
+
break;
|
|
59
|
+
case 'credential_failure':
|
|
60
|
+
await repos.credentials.addExchangeState(
|
|
61
|
+
credential._id,
|
|
62
|
+
ExchangeStates.CLIENT_ERROR,
|
|
63
|
+
{
|
|
64
|
+
'exchange.err': 'client_credential_failure',
|
|
65
|
+
'exchange.errorDescription': notificationRequest.event_description,
|
|
66
|
+
failedAt: new Date(),
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
throw new Oauth2ServerErrorResponseError({
|
|
72
|
+
error: Oidc4vciErrors.INVALID_NOTIFICATION_REQUEST,
|
|
73
|
+
error_description: 'event not supported',
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
} catch (error) {
|
|
77
|
+
context.log.error(error);
|
|
78
|
+
await repos.credentials.addExchangeState(
|
|
79
|
+
credential._id,
|
|
80
|
+
ExchangeStates.UNEXPECTED_ERROR,
|
|
81
|
+
omitBy(isNil, {
|
|
82
|
+
'exchange.err': error.message,
|
|
83
|
+
'exchange.errorCode': error.errorCode,
|
|
84
|
+
'exchange.errorDescription': error.error_description,
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
87
|
+
throw new Oauth2ServerErrorResponseError({
|
|
88
|
+
error: 'server_error',
|
|
89
|
+
error_description: error.message,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
module.exports = { handleNotification };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2025 Velocity Team
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
module.exports = {
|
|
19
|
+
...require('./create-access-token'),
|
|
20
|
+
...require('./get-authorization-server-metadata'),
|
|
21
|
+
...require('./get-credential-issuer-metadata'),
|
|
22
|
+
...require('./create-credential'),
|
|
23
|
+
...require('./handle-notification'),
|
|
24
|
+
};
|
|
@@ -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('./openid4vci-plugin'),
|
|
19
|
+
};
|