From dd2cbc13755262e947f261e22dbb25f170d4349b Mon Sep 17 00:00:00 2001 From: Michael Avoyan Date: Sun, 14 Jul 2024 17:48:27 +0300 Subject: [PATCH] fixes --- ...tCredentialManifestByDeepLinkRepository.ts | 5 ++-- .../PresentationRequestRepository.ts | 5 ++-- .../sample-app/src/screens/MeinScreen.tsx | 10 +++++--- .../sample-server/src/plugins/VclSdkPlugin.ts | 24 ++++++------------- .../sample-server/src/routes/Inspection.ts | 2 +- packages/sample-server/src/utils/Converter.ts | 20 +++++++++------- 6 files changed, 32 insertions(+), 34 deletions(-) diff --git a/packages/sample-app/src/repositories/GetCredentialManifestByDeepLinkRepository.ts b/packages/sample-app/src/repositories/GetCredentialManifestByDeepLinkRepository.ts index 72aea97..8e479a5 100644 --- a/packages/sample-app/src/repositories/GetCredentialManifestByDeepLinkRepository.ts +++ b/packages/sample-app/src/repositories/GetCredentialManifestByDeepLinkRepository.ts @@ -9,12 +9,13 @@ import fetcher from "../network/Fetcher"; import { Dictionary } from "../Types"; export const getCredentialManifestByDeepLink = async ( - deepLink: Dictionary + deepLink: Dictionary, + didJwk: Dictionary ): Promise> => { const config = { url: Urls.getCredentialManifest, method: 'POST', - data: deepLink, + data: { deepLink, didJwk } }; return await fetcher(config); } \ No newline at end of file diff --git a/packages/sample-app/src/repositories/PresentationRequestRepository.ts b/packages/sample-app/src/repositories/PresentationRequestRepository.ts index 7f74d10..d30968d 100644 --- a/packages/sample-app/src/repositories/PresentationRequestRepository.ts +++ b/packages/sample-app/src/repositories/PresentationRequestRepository.ts @@ -9,12 +9,13 @@ import fetcher from "../network/Fetcher"; import Urls from "../network/Urls"; export const getPresentationRequest = async ( - deepLink: Dictionary + deepLink: Dictionary, + didJwk: Dictionary ): Promise> => { const config = { url: Urls.getPresentationRequest, method: 'POST', - data: deepLink, + data: { deepLink, didJwk } }; return await fetcher(config); } \ No newline at end of file diff --git a/packages/sample-app/src/screens/MeinScreen.tsx b/packages/sample-app/src/screens/MeinScreen.tsx index 28797ff..f6b9a7e 100644 --- a/packages/sample-app/src/screens/MeinScreen.tsx +++ b/packages/sample-app/src/screens/MeinScreen.tsx @@ -37,7 +37,7 @@ const initialization = async () => { remoteCryptoServicesToken: null }); } - console.log('didJwk: ', didJwk); + console.log('didJwk: ', didJwk); // Should be managed by the consumer }; // @ts-ignore @@ -68,7 +68,10 @@ const onGetCredentialTypeSchemas = () => { }; const onGetPresentationRequest = () => { - getPresentationRequest({value: Constants.PresentationRequestDeepLinkStrDev} ) + getPresentationRequest( + {value: Constants.PresentationRequestDeepLinkStrDev}, + didJwk + ) .then((presentationRequest) => { console.log('presentation request: ', presentationRequest); onSubmitPresentation(presentationRequest); @@ -92,7 +95,8 @@ const onSubmitPresentation = (presentationRequest: Dictionary) => { const onGetCredentialManifestByDeepLink = () => { getCredentialManifestByDeepLink( - { value: Constants.CredentialManifestDeepLinkStrDev } + { value: Constants.CredentialManifestDeepLinkStrDev }, + didJwk ).then((credentialManifest) => { console.log('credential manifest: ', credentialManifest); onGenerateOffers(credentialManifest); diff --git a/packages/sample-server/src/plugins/VclSdkPlugin.ts b/packages/sample-server/src/plugins/VclSdkPlugin.ts index 083ddff..5bb1087 100644 --- a/packages/sample-server/src/plugins/VclSdkPlugin.ts +++ b/packages/sample-server/src/plugins/VclSdkPlugin.ts @@ -6,7 +6,7 @@ */ import fastifyPlugin from "fastify-plugin"; import { - VCLCryptoServicesDescriptor, VCLDidJwkDescriptor, + VCLCryptoServicesDescriptor, VCLInitializationDescriptor, VCLProvider } from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src"; @@ -29,22 +29,12 @@ const vclSdkPlugin = async (fastify) => { try { await vclSdk.initialize(initializationDescriptor) console.log('VCL SDK initialized successfully'); - try { - const didJwk = await vclSdk.generateDidJwk(new VCLDidJwkDescriptor()) - console.log(`DID JWK generated successfully: ${JSON.stringify(didJwk)}`); - fastify.decorate('vclSdk', vclSdk); - fastify.decorate('didJwk', didJwk); - const addHooks = async (req, reply) => { - req.vclSdk = vclSdk; - req.didJwk = didJwk; - reply.vclSdk = vclSdk; - reply.didJwk = didJwk; - }; - fastify.addHook('preHandler', addHooks); - } catch (e) { - console.error('Failed to generate DID JWK', e); - throw e; - } + fastify.decorate('vclSdk', vclSdk); + const addHooks = async (req, reply) => { + req.vclSdk = vclSdk; + reply.vclSdk = vclSdk; + }; + fastify.addHook('preHandler', addHooks); } catch (e) { console.error('Failed to initialize VCL SDK', e); throw e; diff --git a/packages/sample-server/src/routes/Inspection.ts b/packages/sample-server/src/routes/Inspection.ts index 02b2e68..47a8afe 100644 --- a/packages/sample-server/src/routes/Inspection.ts +++ b/packages/sample-server/src/routes/Inspection.ts @@ -16,7 +16,7 @@ export default async function inspectionRoutes(fastify) { "/getPresentationRequest", async (req, reply) => { reply.send( - await req.vclSdk.getPresentationRequest(presentationRequestDescriptorFrom(req.body, req.didJwk)) + await req.vclSdk.getPresentationRequest(presentationRequestDescriptorFrom(req.body)) ); } ); diff --git a/packages/sample-server/src/utils/Converter.ts b/packages/sample-server/src/utils/Converter.ts index 3d5c319..cd6cd03 100644 --- a/packages/sample-server/src/utils/Converter.ts +++ b/packages/sample-server/src/utils/Converter.ts @@ -8,33 +8,34 @@ import { Dictionary, issuingTypeFromString, + Nullish, VCLCredentialManifest, VCLCredentialManifestDescriptor, VCLCredentialManifestDescriptorByDeepLink, VCLCredentialManifestDescriptorByService, VCLCredentialManifestDescriptorRefresh, + VCLCredentialTypesUIFormSchemaDescriptor, VCLDeepLink, VCLDidJwk, + VCLDidJwkDescriptor, VCLExchange, VCLFilter, + VCLFinalizeOffersDescriptor, VCLGenerateOffersDescriptor, VCLIssuingType, VCLJwt, + VCLJwtDescriptor, VCLOrganizationsSearchDescriptor, VCLPresentationRequest, VCLPresentationRequestDescriptor, VCLPresentationSubmission, + VCLPublicJwk, VCLServiceCredentialAgentIssuer, VCLSubmissionResult, VCLToken, VCLVerifiableCredential, VCLVerifiedProfile, - VCLFinalizeOffersDescriptor, - VCLCredentialTypesUIFormSchemaDescriptor, - VCLVerifiedProfileDescriptor, - VCLPublicJwk, - VCLJwtDescriptor, - VCLDidJwkDescriptor, Nullish + VCLVerifiedProfileDescriptor } from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src"; export const deepLinkFrom = (deepLink: any): VCLDeepLink => { @@ -58,8 +59,9 @@ export const didJwkFrom = (json: Dictionary): VCLDidJwk => { return VCLDidJwk.fromJSON(json); } -export const presentationRequestDescriptorFrom = (json: Dictionary, didJwk: VCLDidJwk): VCLPresentationRequestDescriptor => { - const deepLink = deepLinkFrom(json) +export const presentationRequestDescriptorFrom = (json: Dictionary): VCLPresentationRequestDescriptor => { + const deepLink = deepLinkFrom(json.deepLink); + const didJwk = didJwkFrom(json.didJwk); return new VCLPresentationRequestDescriptor( deepLink, null, @@ -134,7 +136,7 @@ const credentialManifestDescriptorRefreshFrom = (json: Dictionary): VCLCred export const credentialManifestDescriptorFrom = (json: Dictionary): VCLCredentialManifestDescriptor => { return json.credentialIds ? credentialManifestDescriptorRefreshFrom(json) : ( json.service ? credentialManifestDescriptorByServiceFrom(json) : credentialManifestDescriptorByDeepLinkFrom(json) - ) + ); } export const credentialManifestFrom = (json: Dictionary): VCLCredentialManifest => {