From f8c71054320671613c04c77f96c5f740f2635a03 Mon Sep 17 00:00:00 2001 From: Michael Avoyan Date: Sun, 14 Jul 2024 10:38:43 +0300 Subject: [PATCH] split routes --- .../sample-app/src/{screens => }/Constants.ts | 0 .../sample-app/src/screens/MeinScreen.tsx | 2 +- .../src/routes/CryptoServices.ts | 49 +++++ .../src/routes/Initialization.ts | 27 +++ .../sample-server/src/routes/Inspection.ts | 43 +++++ packages/sample-server/src/routes/Issuing.ts | 55 ++++++ packages/sample-server/src/routes/Other.ts | 29 +++ packages/sample-server/src/routes/Routes.ts | 170 ------------------ .../sample-server/src/routes/SelfReport.ts | 18 ++ packages/sample-server/src/routes/index.ts | 23 +++ 10 files changed, 245 insertions(+), 171 deletions(-) rename packages/sample-app/src/{screens => }/Constants.ts (100%) create mode 100644 packages/sample-server/src/routes/CryptoServices.ts create mode 100644 packages/sample-server/src/routes/Initialization.ts create mode 100644 packages/sample-server/src/routes/Inspection.ts create mode 100644 packages/sample-server/src/routes/Issuing.ts create mode 100644 packages/sample-server/src/routes/Other.ts delete mode 100644 packages/sample-server/src/routes/Routes.ts create mode 100644 packages/sample-server/src/routes/SelfReport.ts create mode 100644 packages/sample-server/src/routes/index.ts diff --git a/packages/sample-app/src/screens/Constants.ts b/packages/sample-app/src/Constants.ts similarity index 100% rename from packages/sample-app/src/screens/Constants.ts rename to packages/sample-app/src/Constants.ts diff --git a/packages/sample-app/src/screens/MeinScreen.tsx b/packages/sample-app/src/screens/MeinScreen.tsx index f4a1f1e..28797ff 100644 --- a/packages/sample-app/src/screens/MeinScreen.tsx +++ b/packages/sample-app/src/screens/MeinScreen.tsx @@ -25,7 +25,7 @@ import { verifyJwt, generateSignedJwt } from "../repositories"; -import { Constants } from "./Constants"; +import { Constants } from "../Constants"; import { Dictionary } from "../Types"; import { getApprovedRejectedOfferIdsMock } from "../utils/Utils"; diff --git a/packages/sample-server/src/routes/CryptoServices.ts b/packages/sample-server/src/routes/CryptoServices.ts new file mode 100644 index 0000000..c9c10c8 --- /dev/null +++ b/packages/sample-server/src/routes/CryptoServices.ts @@ -0,0 +1,49 @@ +/** + * Created by Michael Avoyan on 14/07/2024. + * + * Copyright 2022 Velocity Career Labs inc. + * SPDX-License-Identifier: Apache-2.0 + */ +import { + didJwkDescriptorFrom, + didJwkFrom, + jwtDescriptorFrom, + jwtFromJson, + publicJwkFrom, + tokenFrom +} from "../utils/Converter"; + +export default async function cryptoServicesRoutes(fastify) { + fastify.post( + "/verifyJwt", + async (req, reply) => { + reply.send( + await req.vclSdk.verifyJwt( + jwtFromJson(req.body.jwt), + publicJwkFrom(req.body.publicJwk), + tokenFrom(req.body.remoteCryptoServicesToken) + ) + ); + } + ); + fastify.post( + "/generateSignedJwt", + async (req, reply) => { + reply.send( + await req.vclSdk.generateSignedJwt( + jwtDescriptorFrom(req.body.jwtDescriptor), + didJwkFrom(req.body.didJwk), + tokenFrom(req.body.remoteCryptoServicesToken) + ) + ); + } + ); + fastify.post( + "/generateDidJwk", + async (req, reply) => { + reply.send( + await req.vclSdk.generateDidJwk(didJwkDescriptorFrom(req.body)) + ); + } + ); +} \ No newline at end of file diff --git a/packages/sample-server/src/routes/Initialization.ts b/packages/sample-server/src/routes/Initialization.ts new file mode 100644 index 0000000..0e9d84b --- /dev/null +++ b/packages/sample-server/src/routes/Initialization.ts @@ -0,0 +1,27 @@ +/** + * Created by Michael Avoyan on 14/07/2024. + * + * Copyright 2022 Velocity Career Labs inc. + * SPDX-License-Identifier: Apache-2.0 + */ + +export default async function initializationRoutes(fastify) { + fastify.get( + "/getCountries", + (req, reply) => { + reply.send(req.vclSdk.countries); + } + ); + fastify.get( + "/getCredentialTypes", + (req, reply) => { + reply.send(req.vclSdk.credentialTypes); + } + ); + fastify.get( + "/getCredentialTypeSchemas", + (req, reply) => { + reply.send(req.vclSdk.credentialTypeSchemas); + } + ); +} \ No newline at end of file diff --git a/packages/sample-server/src/routes/Inspection.ts b/packages/sample-server/src/routes/Inspection.ts new file mode 100644 index 0000000..02b2e68 --- /dev/null +++ b/packages/sample-server/src/routes/Inspection.ts @@ -0,0 +1,43 @@ +/** + * Created by Michael Avoyan on 14/07/2024. + * + * Copyright 2022 Velocity Career Labs inc. + * SPDX-License-Identifier: Apache-2.0 + */ +import { + presentationRequestDescriptorFrom, + presentationSubmissionFrom, + submissionResultFrom +} from "../utils/Converter"; +import { VCLExchangeDescriptor } from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src"; + +export default async function inspectionRoutes(fastify) { + fastify.post( + "/getPresentationRequest", + async (req, reply) => { + reply.send( + await req.vclSdk.getPresentationRequest(presentationRequestDescriptorFrom(req.body, req.didJwk)) + ); + } + ); + fastify.post( + "/submitPresentation", + async (req, reply) => { + reply.send( + await req.vclSdk.submitPresentation(presentationSubmissionFrom(req.body)) + ); + } + ); + fastify.post( + "/getExchangeProgress", + async (req, reply) => { + reply.send( + await req.vclSdk.getExchangeProgress( + new VCLExchangeDescriptor( + presentationSubmissionFrom(req.body.presentationSubmission), + submissionResultFrom(req.body.submissionResult) + ) + )); + } + ); +} \ No newline at end of file diff --git a/packages/sample-server/src/routes/Issuing.ts b/packages/sample-server/src/routes/Issuing.ts new file mode 100644 index 0000000..9646714 --- /dev/null +++ b/packages/sample-server/src/routes/Issuing.ts @@ -0,0 +1,55 @@ +/** + * Created by Michael Avoyan on 14/07/2024. + * + * Copyright 2022 Velocity Career Labs inc. + * SPDX-License-Identifier: Apache-2.0 + */ +import { + credentialManifestDescriptorFrom, + finalizeOffersDescriptorFrom, + generateOffersDescriptorFrom, + tokenFrom +} from "../utils/Converter"; + +export default async function issuingRoutes(fastify) { + fastify.post( + "/getCredentialManifest", + async (req, reply) => { + reply.send( + await req.vclSdk.getCredentialManifest( + credentialManifestDescriptorFrom(req.body) + ) + ) + } + ); + fastify.post( + "/generateOffers", + async (req, reply) => { + reply.send( + await req.vclSdk.generateOffers(generateOffersDescriptorFrom(req.body)) + ); + } + ); + fastify.post( + "/checkOffers", + async (req, reply) => { + reply.send( + await req.vclSdk.checkForOffers( + generateOffersDescriptorFrom(req.body), + tokenFrom(req.body.sessionToken) + ) + ); + } + ); + fastify.post( + "/finalizeOffers", + async (req, reply) => { + reply.send( + await req.vclSdk.finalizeOffers( + finalizeOffersDescriptorFrom(req.body.finalizeOffersDescriptor), + tokenFrom(req.body.sessionToken) + ) + ); + } + ); +} \ No newline at end of file diff --git a/packages/sample-server/src/routes/Other.ts b/packages/sample-server/src/routes/Other.ts new file mode 100644 index 0000000..dab1df9 --- /dev/null +++ b/packages/sample-server/src/routes/Other.ts @@ -0,0 +1,29 @@ +/** + * Created by Michael Avoyan on 14/07/2024. + * + * Copyright 2022 Velocity Career Labs inc. + * SPDX-License-Identifier: Apache-2.0 + */ +import { + organizationsSearchDescriptorFrom, + verifiedProfileDescriptorFrom +} from "../utils/Converter"; + +export default async function otherRoutes(fastify) { + fastify.post( + "/searchForOrganizations", + async (req, reply) => { + reply.send( + await req.vclSdk.searchForOrganizations(organizationsSearchDescriptorFrom(req.body)) + ); + } + ); + fastify.post( + "/getVerifiedProfile", + async (req, reply) => { + reply.send( + await req.vclSdk.getVerifiedProfile(verifiedProfileDescriptorFrom(req.body)) + ); + } + ); +} \ No newline at end of file diff --git a/packages/sample-server/src/routes/Routes.ts b/packages/sample-server/src/routes/Routes.ts deleted file mode 100644 index b547e19..0000000 --- a/packages/sample-server/src/routes/Routes.ts +++ /dev/null @@ -1,170 +0,0 @@ -/** - * Created by Michael Avoyan on 27/06/2024. - * - * Copyright 2022 Velocity Career Labs inc. - * SPDX-License-Identifier: Apache-2.0 - */ - -import { - credentialManifestDescriptorFrom, - credentialTypesUIFormSchemaDescriptorFrom, - didJwkDescriptorFrom, - didJwkFrom, - finalizeOffersDescriptorFrom, - generateOffersDescriptorFrom, - jwtDescriptorFrom, - jwtFromJson, - organizationsSearchDescriptorFrom, - presentationRequestDescriptorFrom, - presentationSubmissionFrom, - publicJwkFrom, - submissionResultFrom, - tokenFrom, - verifiedProfileDescriptorFrom -} from "../utils/Converter"; -import { VCLExchangeDescriptor } from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src"; - -export default async function routes(fastify) { - fastify.get( - "/getCountries", - (req, reply) => { - reply.send(req.vclSdk.countries); - } - ); - fastify.get( - "/getCredentialTypes", - (req, reply) => { - reply.send(req.vclSdk.credentialTypes); - } - ); - fastify.get( - "/getCredentialTypeSchemas", - (req, reply) => { - reply.send(req.vclSdk.credentialTypeSchemas); - } - ); - fastify.post( - "/getPresentationRequest", - async (req, reply) => { - reply.send( - await req.vclSdk.getPresentationRequest(presentationRequestDescriptorFrom(req.body, req.didJwk)) - ); - } - ); - fastify.post( - "/submitPresentation", - async (req, reply) => { - reply.send( - await req.vclSdk.submitPresentation(presentationSubmissionFrom(req.body)) - ); - } - ); - fastify.post( - "/getExchangeProgress", - async (req, reply) => { - reply.send( - await req.vclSdk.getExchangeProgress( - new VCLExchangeDescriptor( - presentationSubmissionFrom(req.body.presentationSubmission), - submissionResultFrom(req.body.submissionResult) - ) - )); - } - ); - fastify.post( - "/searchForOrganizations", - async (req, reply) => { - reply.send( - await req.vclSdk.searchForOrganizations(organizationsSearchDescriptorFrom(req.body)) - ); - } - ); - fastify.post( - "/getCredentialManifest", - async (req, reply) => { - reply.send( - await req.vclSdk.getCredentialManifest( - credentialManifestDescriptorFrom(req.body) - ) - ) - } - ); - fastify.post( - "/generateOffers", - async (req, reply) => { - reply.send( - await req.vclSdk.generateOffers(generateOffersDescriptorFrom(req.body)) - ); - } - ); - fastify.post( - "/checkOffers", - async (req, reply) => { - reply.send( - await req.vclSdk.checkForOffers( - generateOffersDescriptorFrom(req.body), - tokenFrom(req.body.sessionToken) - ) - ); - } - ); - fastify.post( - "/finalizeOffers", - async (req, reply) => { - reply.send( - await req.vclSdk.finalizeOffers( - finalizeOffersDescriptorFrom(req.body.finalizeOffersDescriptor), - tokenFrom(req.body.sessionToken) - ) - ); - } - ); - fastify.post( - "/getCredentialTypesUIFormSchema", - async (req, reply) => { - reply.send( - await req.vclSdk.getCredentialTypesUIFormSchema(credentialTypesUIFormSchemaDescriptorFrom(req.body)) - ); - } - ); - fastify.post( - "/getVerifiedProfile", - async (req, reply) => { - reply.send( - await req.vclSdk.getVerifiedProfile(verifiedProfileDescriptorFrom(req.body)) - ); - } - ); - fastify.post( - "/verifyJwt", - async (req, reply) => { - reply.send( - await req.vclSdk.verifyJwt( - jwtFromJson(req.body.jwt), - publicJwkFrom(req.body.publicJwk), - tokenFrom(req.body.remoteCryptoServicesToken) - ) - ); - } - ); - fastify.post( - "/generateSignedJwt", - async (req, reply) => { - reply.send( - await req.vclSdk.generateSignedJwt( - jwtDescriptorFrom(req.body.jwtDescriptor), - didJwkFrom(req.body.didJwk), - tokenFrom(req.body.remoteCryptoServicesToken) - ) - ); - } - ); - fastify.post( - "/generateDidJwk", - async (req, reply) => { - reply.send( - await req.vclSdk.generateDidJwk(didJwkDescriptorFrom(req.body)) - ); - } - ); -} \ No newline at end of file diff --git a/packages/sample-server/src/routes/SelfReport.ts b/packages/sample-server/src/routes/SelfReport.ts new file mode 100644 index 0000000..a208bd9 --- /dev/null +++ b/packages/sample-server/src/routes/SelfReport.ts @@ -0,0 +1,18 @@ +/** + * Created by Michael Avoyan on 14/07/2024. + * + * Copyright 2022 Velocity Career Labs inc. + * SPDX-License-Identifier: Apache-2.0 + */ +import { credentialTypesUIFormSchemaDescriptorFrom } from "../utils/Converter"; + +export default async function selfReportRoutes(fastify) { + fastify.post( + "/getCredentialTypesUIFormSchema", + async (req, reply) => { + reply.send( + await req.vclSdk.getCredentialTypesUIFormSchema(credentialTypesUIFormSchemaDescriptorFrom(req.body)) + ); + } + ); +} \ No newline at end of file diff --git a/packages/sample-server/src/routes/index.ts b/packages/sample-server/src/routes/index.ts new file mode 100644 index 0000000..2c29356 --- /dev/null +++ b/packages/sample-server/src/routes/index.ts @@ -0,0 +1,23 @@ +/** + * Created by Michael Avoyan on 27/06/2024. + * + * Copyright 2022 Velocity Career Labs inc. + * SPDX-License-Identifier: Apache-2.0 + */ + +import initializationRoutes from "./Initialization"; +import inspectionRoutes from "./Inspection"; +import issuingRoutes from "./Issuing"; +import cryptoServicesRoutes from "./CryptoServices"; +import selfReportRoutes from "./SelfReport"; +import otherRoutes from "./Other"; + +export default async function routes(fastify) { + initializationRoutes(fastify); + inspectionRoutes(fastify); + issuingRoutes(fastify); + cryptoServicesRoutes(fastify); + selfReportRoutes(fastify); + otherRoutes(fastify); +} +