@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,28 @@
|
|
|
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
|
+
const ExchangeErrors = {
|
|
18
|
+
REFERENCED_EXCHANGE_NOT_FOUND: 'referenced_exchange_not_found',
|
|
19
|
+
REFERENCED_SERVICE_NOT_FOUND: 'referenced_service_not_found',
|
|
20
|
+
REFERENCED_DEPOT_NOT_FOUND: 'referenced_depot_not_found',
|
|
21
|
+
MESSAGING_SETTINGS_INVALID: 'messaging_settings_invalid',
|
|
22
|
+
CREDENTIAL_OFFER_REQUEST_INVALID: 'credential_offer_request_invalid',
|
|
23
|
+
UNAUTHORIZED: 'unauthorized',
|
|
24
|
+
PRESENTATION_SUBMISSION_INVALID: 'presentation_submission_invalid',
|
|
25
|
+
AUTHENTICATION_METHOD_UNSUPPORTED: 'authentication_method_unsupported',
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
module.exports = { ExchangeErrors };
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
|
|
18
|
+
const ExchangeProtocols = {
|
|
19
|
+
// The VCALM protocol (experimental implementation): https://w3c-ccg.github.io/vc-api/
|
|
20
|
+
W3C_VCALM: 'vcalm',
|
|
21
|
+
// The Velocity Network protocols. Issuing: https://hackmd.io/GdvzWGFBT16HcfijoowqUw & Inspection: https://hackmd.io/lk40OgPuSeCLbx2MegbVfA
|
|
22
|
+
VN_API: 'vn_api',
|
|
23
|
+
// The openid 4 vci protocol
|
|
24
|
+
OPENID4VCI: 'openid4vci',
|
|
25
|
+
// The openid 4 vp protocol
|
|
26
|
+
OPENID4VP: 'openid4vp',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
module.exports = { ExchangeProtocols };
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
/**
|
|
18
|
+
* Copyright 2023 Velocity Team
|
|
19
|
+
*
|
|
20
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
21
|
+
* you may not use this file except in compliance with the License.
|
|
22
|
+
* You may obtain a copy of the License at
|
|
23
|
+
*
|
|
24
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
25
|
+
*
|
|
26
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
27
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
28
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
29
|
+
* See the License for the specific language governing permissions and
|
|
30
|
+
* limitations under the License.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
const ExchangeStates = {
|
|
34
|
+
NEW: 'NEW',
|
|
35
|
+
PRESENTATION_REQUEST_REQUESTED: 'PRESENTATION_REQUEST_REQUESTED',
|
|
36
|
+
PRESENTATION_SUBMISSION_RECEIVED: 'PRESENTATION_SUBMISSION_RECEIVED',
|
|
37
|
+
PRESENTATION_VERIFIED: 'PRESENTATION_VERIFIED',
|
|
38
|
+
PRESENTATION_VERIFICATION_SKIPPED: 'PRESENTATION_VERIFICATION_SKIPPED',
|
|
39
|
+
CREDENTIAL_MANIFEST_REQUESTED: 'CREDENTIAL_MANIFEST_REQUESTED',
|
|
40
|
+
AUTHENTICATION_REQUEST: 'AUTHENTICATION_REQUEST',
|
|
41
|
+
AUTHENTICATION_SUCCESS: 'AUTHENTICATION_SUCCESS',
|
|
42
|
+
AUTHENTICATION_FAILURE: 'AUTHENTICATION_FAILURE',
|
|
43
|
+
UNAUTHORIZED: 'UNAUTHORIZED',
|
|
44
|
+
OFFERS_REQUESTED: 'OFFERS_REQUESTED',
|
|
45
|
+
OFFERS_SENT: 'OFFERS_SENT',
|
|
46
|
+
CLAIMING_IN_PROGRESS: 'CLAIMING_IN_PROGRESS',
|
|
47
|
+
CREDENTIALS_SIGNED: 'CREDENTIALS_SIGNED',
|
|
48
|
+
CLIENT_ERROR: 'CLIENT_ERROR',
|
|
49
|
+
COMPLETE: 'COMPLETE',
|
|
50
|
+
UNEXPECTED_ERROR: 'UNEXPECTED_ERROR',
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
module.exports = { ExchangeStates };
|
|
@@ -0,0 +1,22 @@
|
|
|
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
|
+
const ExchangeTypes = {
|
|
18
|
+
ISSUER: 'issuer',
|
|
19
|
+
RELYING_PARTY: 'relying_party',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
module.exports = { ExchangeTypes };
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
|
|
18
|
+
const { addMilliseconds, getUnixTime } = require('date-fns');
|
|
19
|
+
const { nanoid } = require('nanoid');
|
|
20
|
+
const { CihKeyPurposes } = require('../../keys');
|
|
21
|
+
|
|
22
|
+
const generateIssuingChallenge = async (
|
|
23
|
+
exchangeId,
|
|
24
|
+
{ kms, tenant, config: { challengesExpireIn: challengesExpireInMs } },
|
|
25
|
+
) => {
|
|
26
|
+
const challengeIssuedAt = new Date();
|
|
27
|
+
const challengeIssuedAtUnix = getUnixTime(challengeIssuedAt);
|
|
28
|
+
const challengeExpiresAtUnix = getUnixTime(
|
|
29
|
+
addMilliseconds(challengeIssuedAt, challengesExpireInMs),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
challenge: await kms.signJwt(
|
|
34
|
+
{ exchangeId: exchangeId.toString() },
|
|
35
|
+
tenant.keysByPurpose[CihKeyPurposes.HOLDER_ACCESS_TOKENS]._id,
|
|
36
|
+
{
|
|
37
|
+
alg: 'HS256',
|
|
38
|
+
audience: tenant.hostUrl,
|
|
39
|
+
exp: challengeExpiresAtUnix,
|
|
40
|
+
iat: challengeIssuedAtUnix,
|
|
41
|
+
issuer: tenant.hostUrl,
|
|
42
|
+
jti: nanoid(),
|
|
43
|
+
},
|
|
44
|
+
),
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
module.exports = { generateIssuingChallenge };
|
|
@@ -0,0 +1,32 @@
|
|
|
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('./authorize-exchange'),
|
|
19
|
+
...require('./build-presentation-request'),
|
|
20
|
+
...require('./build-exchange-event'),
|
|
21
|
+
...require('./exchange-errors'),
|
|
22
|
+
...require('./exchange-protocols'),
|
|
23
|
+
...require('./exchange-states'),
|
|
24
|
+
...require('./exchange-types'),
|
|
25
|
+
...require('./generate-issuing-challenge'),
|
|
26
|
+
...require('./validate-message-settings'),
|
|
27
|
+
...require('./validate-new-exchange'),
|
|
28
|
+
...require('./validate-preauth'),
|
|
29
|
+
...require('./validate-referenced-service'),
|
|
30
|
+
...require('./verify-issuing-challenge'),
|
|
31
|
+
...require('./verify-proof-of-key-possession'),
|
|
32
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
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 { isEmpty } = require('lodash/fp');
|
|
19
|
+
const { ExchangeErrors } = require('./exchange-errors');
|
|
20
|
+
|
|
21
|
+
const validateMessagingSettings = (messagingSettings) => {
|
|
22
|
+
if (
|
|
23
|
+
messagingSettings != null &&
|
|
24
|
+
(isEmpty(messagingSettings.webhookUrl) ||
|
|
25
|
+
isEmpty(messagingSettings.authToken))
|
|
26
|
+
) {
|
|
27
|
+
throw newError(400, ExchangeErrors.MESSAGING_SETTINGS_INVALID, {
|
|
28
|
+
errorCode: ExchangeErrors.MESSAGING_SETTINGS_INVALID,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
module.exports = { validateMessagingSettings };
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
const { validateReferencedService } = require('./validate-referenced-service');
|
|
18
|
+
const { validateMessagingSettings } = require('./validate-message-settings');
|
|
19
|
+
|
|
20
|
+
const validateNewExchange = (newExchange, service) => {
|
|
21
|
+
validateReferencedService(service);
|
|
22
|
+
validateMessagingSettings(newExchange.messagingSettings);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
module.exports = { validateNewExchange };
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
const { isEmpty } = require('lodash/fp');
|
|
18
|
+
const newError = require('http-errors');
|
|
19
|
+
const { calcSha384 } = require('@verii/crypto');
|
|
20
|
+
const { ExchangeErrors } = require('./exchange-errors');
|
|
21
|
+
const { ExchangeStates } = require('./exchange-states');
|
|
22
|
+
|
|
23
|
+
const validatePreauth = (preauthCode, depot, { log }) => {
|
|
24
|
+
if (
|
|
25
|
+
depot == null ||
|
|
26
|
+
isEmpty(preauthCode) ||
|
|
27
|
+
calcSha384(preauthCode) !== depot.preauthCodeHash
|
|
28
|
+
) {
|
|
29
|
+
log.error(
|
|
30
|
+
{
|
|
31
|
+
depot,
|
|
32
|
+
preauthCode,
|
|
33
|
+
preauthCodeHash:
|
|
34
|
+
preauthCode != null ? calcSha384(preauthCode) : undefined,
|
|
35
|
+
},
|
|
36
|
+
'Preauth failed',
|
|
37
|
+
);
|
|
38
|
+
throw newError(401, ExchangeErrors.UNAUTHORIZED, {
|
|
39
|
+
exchangeErrorState: ExchangeStates.AUTHENTICATION_FAILURE,
|
|
40
|
+
errorCode: ExchangeErrors.UNAUTHORIZED,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
module.exports = { validatePreauth };
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
const newError = require('http-errors');
|
|
18
|
+
const { isBefore } = require('date-fns/fp');
|
|
19
|
+
const { ExchangeErrors } = require('./exchange-errors');
|
|
20
|
+
|
|
21
|
+
const validateReferencedService = (service) => {
|
|
22
|
+
if (
|
|
23
|
+
service == null ||
|
|
24
|
+
(service.deactivationDate != null &&
|
|
25
|
+
isBefore(new Date(), service.deactivationDate))
|
|
26
|
+
) {
|
|
27
|
+
throw newError(400, ExchangeErrors.REFERENCED_SERVICE_NOT_FOUND, {
|
|
28
|
+
errorCode: ExchangeErrors.REFERENCED_SERVICE_NOT_FOUND,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
module.exports = { validateReferencedService };
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
|
|
18
|
+
const { CihKeyPurposes } = require('../../keys');
|
|
19
|
+
|
|
20
|
+
const verifyIssuingChallenge = async (
|
|
21
|
+
challenge,
|
|
22
|
+
exchangeId,
|
|
23
|
+
{ kms, tenant },
|
|
24
|
+
) => {
|
|
25
|
+
const { payload } = await kms.verifyJwt(
|
|
26
|
+
challenge,
|
|
27
|
+
tenant.keysByPurpose[CihKeyPurposes.HOLDER_ACCESS_TOKENS]._id,
|
|
28
|
+
{
|
|
29
|
+
alg: 'HS256',
|
|
30
|
+
audience: tenant.hostUrl,
|
|
31
|
+
issuer: tenant.hostUrl,
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
if (payload.exchangeId !== exchangeId.toString()) {
|
|
36
|
+
throw new Error('challenge_exchange_mismatch');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return payload;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
module.exports = { verifyIssuingChallenge };
|
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
|
|
18
|
+
const { startsWith } = require('lodash/fp');
|
|
19
|
+
const newError = require('http-errors');
|
|
20
|
+
const { resolveKid } = require('@verii/common-fetchers');
|
|
21
|
+
const { getJwkFromDidUri } = require('@verii/did-doc');
|
|
22
|
+
const { jwtVerify, jwtDecode } = require('@verii/jwt');
|
|
23
|
+
const { verifyIssuingChallenge } = require('./verify-issuing-challenge');
|
|
24
|
+
|
|
25
|
+
const verifyProofOfKeyPossession = async (proof, exchange, context) => {
|
|
26
|
+
verifyProofStructure(proof);
|
|
27
|
+
const jwk = await resolveDidAndJwk(proof.jwt, context);
|
|
28
|
+
const { header, payload } = await doJwtVerify(proof.jwt, jwk);
|
|
29
|
+
|
|
30
|
+
await validateContent(payload, header, exchange, context);
|
|
31
|
+
|
|
32
|
+
return payload.iss;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const doJwtVerify = (jwt, jwk) =>
|
|
36
|
+
jwtVerify(jwt, jwk).catch(() => {
|
|
37
|
+
throw newError(400, 'proof_verify_failed', {
|
|
38
|
+
errorCode: 'proof_verify_failed',
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const verifyProofStructure = (proof) => {
|
|
43
|
+
if (proof == null) {
|
|
44
|
+
throw newError(400, 'proof_required', {
|
|
45
|
+
errorCode: 'proof_required',
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const resolveDidAndJwk = async (jwt, context) => {
|
|
51
|
+
const { header } = jwtDecode(jwt);
|
|
52
|
+
|
|
53
|
+
if (header.kid == null) {
|
|
54
|
+
throw newError(400, 'proof.jwt is missing a kid', {
|
|
55
|
+
errorCode: 'proof_kid_required',
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
if (startsWith('did:jwk', header.kid)) {
|
|
61
|
+
return getJwkFromDidUri(header.kid);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const verificationMethod = await resolveKid(header, context);
|
|
65
|
+
return verificationMethod.publicKeyJwk;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
context.log.error(error);
|
|
68
|
+
throw newError(400, 'proof_kid_invalid', {
|
|
69
|
+
errorCode: 'proof_kid_invalid',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const validateContent = async (payload, { kid }, exchange, context) => {
|
|
75
|
+
const {
|
|
76
|
+
tenant: { hostUrl },
|
|
77
|
+
} = context;
|
|
78
|
+
|
|
79
|
+
if (payload.iss == null) {
|
|
80
|
+
throw newError(400, 'proof_iss_required', {
|
|
81
|
+
errorCode: 'proof_iss_required',
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (!startsWith('did', payload.iss) || !startsWith(payload.iss, kid)) {
|
|
86
|
+
throw newError(400, 'proof_iss_invalid', {
|
|
87
|
+
errorCode: 'proof_iss_invalid',
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (!startsWith(hostUrl, payload.aud)) {
|
|
92
|
+
throw newError(400, 'proof_aud_invalid', {
|
|
93
|
+
errorCode: 'proof_aud_invalid',
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
await verifyChallenge(payload.nonce, exchange, context);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const throwExpiredChallengeError = () => {
|
|
101
|
+
throw newError(400, 'proof_challenge_expired', {
|
|
102
|
+
errorCode: 'proof_challenge_expired',
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const throwChallengeMismatchError = () => {
|
|
107
|
+
throw newError(400, 'proof_challenge_mismatch', {
|
|
108
|
+
errorCode: 'proof_challenge_mismatch',
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const throwChallengeVerificationError = (error) => {
|
|
113
|
+
if (error?.code === 'ERR_JWT_EXPIRED' || error?.name === 'JWTExpired') {
|
|
114
|
+
throwExpiredChallengeError();
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
throwChallengeMismatchError();
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const verifyChallenge = async (nonce, { _id }, context) => {
|
|
121
|
+
try {
|
|
122
|
+
await verifyIssuingChallenge(nonce, _id, context);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
throwChallengeVerificationError(error);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
module.exports = { verifyProofOfKeyPossession };
|
|
@@ -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('./init-exchange-factory'),
|
|
19
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
|
|
18
|
+
const { register } = require('@spencejs/spence-factories');
|
|
19
|
+
const { ObjectId } = require('mongodb');
|
|
20
|
+
const { initTenantFactory } = require('../../tenants');
|
|
21
|
+
const { exchangesRepoPlugin } = require('../repo');
|
|
22
|
+
const { ExchangeStates, ExchangeTypes } = require('../domain');
|
|
23
|
+
const {
|
|
24
|
+
initIssuerServiceFactory,
|
|
25
|
+
} = require('../../issuer-services/factories/issuer-service-factory');
|
|
26
|
+
const {
|
|
27
|
+
initRelyingPartyServiceFactory,
|
|
28
|
+
} = require('../../relying-party-services/factories/relying-party-service-factory');
|
|
29
|
+
|
|
30
|
+
const initExchangeFactory = (
|
|
31
|
+
app,
|
|
32
|
+
defaultExchangeType = ExchangeTypes.ISSUER,
|
|
33
|
+
) => {
|
|
34
|
+
const initRepo = exchangesRepoPlugin(app);
|
|
35
|
+
return register('exchange', async (overrides, { getOrBuild }) => {
|
|
36
|
+
const service = await getOrBuild(
|
|
37
|
+
'service',
|
|
38
|
+
defaultExchangeType === ExchangeTypes.ISSUER
|
|
39
|
+
? initIssuerServiceFactory(app)
|
|
40
|
+
: initRelyingPartyServiceFactory(app),
|
|
41
|
+
);
|
|
42
|
+
const tenant = await getOrBuild('tenant', initTenantFactory(app));
|
|
43
|
+
const offerExchange = {
|
|
44
|
+
type: defaultExchangeType,
|
|
45
|
+
events: [{ state: ExchangeStates.NEW, timestamp: new Date() }],
|
|
46
|
+
tenantId: new ObjectId(tenant._id),
|
|
47
|
+
serviceId: new ObjectId(service._id),
|
|
48
|
+
...overrides(),
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
item: offerExchange,
|
|
53
|
+
repo: initRepo({ tenant: { ...tenant, _id: new ObjectId(tenant._id) } }),
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
module.exports = { initExchangeFactory };
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
const { ExchangeStates } = require('../domain');
|
|
18
|
+
|
|
19
|
+
const exchangeErrorHook = (exchangeId, error, { repos }) =>
|
|
20
|
+
repos.exchanges.addState(
|
|
21
|
+
exchangeId,
|
|
22
|
+
error.statusCode === 401
|
|
23
|
+
? ExchangeStates.AUTHENTICATION_FAILURE
|
|
24
|
+
: ExchangeStates.UNEXPECTED_ERROR,
|
|
25
|
+
{
|
|
26
|
+
err: error.message,
|
|
27
|
+
},
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
module.exports = { exchangeErrorHook };
|
|
@@ -0,0 +1,17 @@
|
|
|
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 = { ...require('./exchange-error-hook') };
|
|
@@ -0,0 +1,24 @@
|
|
|
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('./adapters'),
|
|
19
|
+
...require('./domain'),
|
|
20
|
+
...require('./factories'),
|
|
21
|
+
...require('./hooks'),
|
|
22
|
+
...require('./orchestrators'),
|
|
23
|
+
...require('./repo'),
|
|
24
|
+
};
|