Skip to content

Commit

Permalink
Merge pull request #124 from velocitycareerlabs/VL-8115-fxes
Browse files Browse the repository at this point in the history
fixes
  • Loading branch information
michaelavoyan authored Jul 14, 2024
2 parents c468967 + dd2cbc1 commit c0da720
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import fetcher from "../network/Fetcher";
import { Dictionary } from "../Types";

export const getCredentialManifestByDeepLink = async (
deepLink: Dictionary<any>
deepLink: Dictionary<any>,
didJwk: Dictionary<any>
): Promise<Dictionary<any>> => {
const config = {
url: Urls.getCredentialManifest,
method: 'POST',
data: deepLink,
data: { deepLink, didJwk }
};
return await fetcher(config);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import fetcher from "../network/Fetcher";
import Urls from "../network/Urls";

export const getPresentationRequest = async (
deepLink: Dictionary<any>
deepLink: Dictionary<any>,
didJwk: Dictionary<any>
): Promise<Dictionary<any>> => {
const config = {
url: Urls.getPresentationRequest,
method: 'POST',
data: deepLink,
data: { deepLink, didJwk }
};
return await fetcher(config);
}
10 changes: 7 additions & 3 deletions packages/sample-app/src/screens/MeinScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -92,7 +95,8 @@ const onSubmitPresentation = (presentationRequest: Dictionary<any>) => {

const onGetCredentialManifestByDeepLink = () => {
getCredentialManifestByDeepLink(
{ value: Constants.CredentialManifestDeepLinkStrDev }
{ value: Constants.CredentialManifestDeepLinkStrDev },
didJwk
).then((credentialManifest) => {
console.log('credential manifest: ', credentialManifest);
onGenerateOffers(credentialManifest);
Expand Down
24 changes: 7 additions & 17 deletions packages/sample-server/src/plugins/VclSdkPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import fastifyPlugin from "fastify-plugin";
import {
VCLCryptoServicesDescriptor, VCLDidJwkDescriptor,
VCLCryptoServicesDescriptor,
VCLInitializationDescriptor,
VCLProvider
} from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src";
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/sample-server/src/routes/Inspection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);
}
);
Expand Down
20 changes: 11 additions & 9 deletions packages/sample-server/src/utils/Converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -58,8 +59,9 @@ export const didJwkFrom = (json: Dictionary<any>): VCLDidJwk => {
return VCLDidJwk.fromJSON(json);
}

export const presentationRequestDescriptorFrom = (json: Dictionary<any>, didJwk: VCLDidJwk): VCLPresentationRequestDescriptor => {
const deepLink = deepLinkFrom(json)
export const presentationRequestDescriptorFrom = (json: Dictionary<any>): VCLPresentationRequestDescriptor => {
const deepLink = deepLinkFrom(json.deepLink);
const didJwk = didJwkFrom(json.didJwk);
return new VCLPresentationRequestDescriptor(
deepLink,
null,
Expand Down Expand Up @@ -134,7 +136,7 @@ const credentialManifestDescriptorRefreshFrom = (json: Dictionary<any>): VCLCred
export const credentialManifestDescriptorFrom = (json: Dictionary<any>): VCLCredentialManifestDescriptor => {
return json.credentialIds ? credentialManifestDescriptorRefreshFrom(json) : (
json.service ? credentialManifestDescriptorByServiceFrom(json) : credentialManifestDescriptorByDeepLinkFrom(json)
)
);
}

export const credentialManifestFrom = (json: Dictionary<any>): VCLCredentialManifest => {
Expand Down

0 comments on commit c0da720

Please sign in to comment.