Skip to content

Commit

Permalink
refactor cont
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelavoyan committed Jul 11, 2024
1 parent 60d86fd commit 9b6f2cb
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const checkOffers = async (
const config = {
url: Urls.checkOffers,
method: 'POST',
data: { generateOffersDescriptor, sessionToken }
data: { ...generateOffersDescriptor, sessionToken }
};
return await fetcher(config);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const generateOffers = async (
const config = {
url: Urls.generateOffers,
method: 'POST',
data: { generateOffersDescriptor },
data: generateOffersDescriptor
};
return await fetcher(config);
}
61 changes: 33 additions & 28 deletions packages/sample-server/src/routes/Routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
*/

import {
credentialManifestDescriptorFromJson,
credentialTypesUIFormSchemaDescriptorFromJson, didJwkDescriptorFromJson, didJwkFromJson,
finalizeOffersDescriptorFromJson,
generateOffersDescriptorFromJson, jwtDescriptorFromJson, jwtFromJson,
organizationsSearchDescriptorFromJson,
presentationRequestDescriptorFromJson,
presentationSubmissionFromJson, publicJwkFromJson,
submissionResultFromJson,
tokenFromString, verifiedProfileDescriptorFromJson
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";

Expand All @@ -41,15 +46,15 @@ export default async function routes(fastify) {
"/getPresentationRequest",
async (req, reply) => {
reply.send(
await req.vclSdk.getPresentationRequest(presentationRequestDescriptorFromJson(req.body, req.didJwk))
await req.vclSdk.getPresentationRequest(presentationRequestDescriptorFrom(req.body, req.didJwk))
);
}
);
fastify.post(
"/submitPresentation",
async (req, reply) => {
reply.send(
await req.vclSdk.submitPresentation(presentationSubmissionFromJson(req.body))
await req.vclSdk.submitPresentation(presentationSubmissionFrom(req.body))
);
}
);
Expand All @@ -59,8 +64,8 @@ export default async function routes(fastify) {
reply.send(
await req.vclSdk.getExchangeProgress(
new VCLExchangeDescriptor(
presentationSubmissionFromJson(req.body.presentationSubmission),
submissionResultFromJson(req.body.submissionResult)
presentationSubmissionFrom(req.body.presentationSubmission),
submissionResultFrom(req.body.submissionResult)
)
));
}
Expand All @@ -69,7 +74,7 @@ export default async function routes(fastify) {
"/searchForOrganizations",
async (req, reply) => {
reply.send(
await req.vclSdk.searchForOrganizations(organizationsSearchDescriptorFromJson(req.body))
await req.vclSdk.searchForOrganizations(organizationsSearchDescriptorFrom(req.body))
);
}
);
Expand All @@ -78,7 +83,7 @@ export default async function routes(fastify) {
async (req, reply) => {
reply.send(
await req.vclSdk.getCredentialManifest(
credentialManifestDescriptorFromJson(req.body, req.didJwk)
credentialManifestDescriptorFrom(req.body, req.didJwk)
)
)
}
Expand All @@ -87,7 +92,7 @@ export default async function routes(fastify) {
"/generateOffers",
async (req, reply) => {
reply.send(
await req.vclSdk.generateOffers(generateOffersDescriptorFromJson(req.body))
await req.vclSdk.generateOffers(generateOffersDescriptorFrom(req.body))
);
}
);
Expand All @@ -96,8 +101,8 @@ export default async function routes(fastify) {
async (req, reply) => {
reply.send(
await req.vclSdk.checkForOffers(
generateOffersDescriptorFromJson(req.body),
tokenFromString(req.body.sessionToken.value)
generateOffersDescriptorFrom(req.body),
tokenFrom(req.body.sessionToken)
)
);
}
Expand All @@ -107,8 +112,8 @@ export default async function routes(fastify) {
async (req, reply) => {
reply.send(
await req.vclSdk.finalizeOffers(
finalizeOffersDescriptorFromJson(req.body),
tokenFromString(req.body.sessionToken.value)
finalizeOffersDescriptorFrom(req.body.finalizeOffersDescriptor),
tokenFrom(req.body.sessionToken)
)
);
}
Expand All @@ -117,15 +122,15 @@ export default async function routes(fastify) {
"/getCredentialTypesUIFormSchema",
async (req, reply) => {
reply.send(
await req.vclSdk.getCredentialTypesUIFormSchema(credentialTypesUIFormSchemaDescriptorFromJson(req.body))
await req.vclSdk.getCredentialTypesUIFormSchema(credentialTypesUIFormSchemaDescriptorFrom(req.body))
);
}
);
fastify.post(
"/getVerifiedProfile",
async (req, reply) => {
reply.send(
await req.vclSdk.getVerifiedProfile(verifiedProfileDescriptorFromJson(req.body))
await req.vclSdk.getVerifiedProfile(verifiedProfileDescriptorFrom(req.body))
);
}
);
Expand All @@ -135,8 +140,8 @@ export default async function routes(fastify) {
reply.send(
await req.vclSdk.verifyJwt(
jwtFromJson(req.body.jwt),
publicJwkFromJson(req.body.publicJwk),
tokenFromString(req.body.remoteCryptoServicesToken)
publicJwkFrom(req.body.publicJwk),
tokenFrom(req.body.remoteCryptoServicesToken)
)
);
}
Expand All @@ -146,9 +151,9 @@ export default async function routes(fastify) {
async (req, reply) => {
reply.send(
await req.vclSdk.generateSignedJwt(
jwtDescriptorFromJson(req.body.jwtDescriptor),
didJwkFromJson(req.body.didJwk),
tokenFromString(req.body.remoteCryptoServicesToken)
jwtDescriptorFrom(req.body.jwtDescriptor),
didJwkFrom(req.body.didJwk),
tokenFrom(req.body.remoteCryptoServicesToken)
)
);
}
Expand All @@ -157,7 +162,7 @@ export default async function routes(fastify) {
"/generateDidJwk",
async (req, reply) => {
reply.send(
await req.vclSdk.generateDidJwk(didJwkDescriptorFromJson(req.body))
await req.vclSdk.generateDidJwk(didJwkDescriptorFrom(req.body))
);
}
);
Expand Down
58 changes: 29 additions & 29 deletions packages/sample-server/src/utils/Converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,28 @@ import {
VCLDidJwkDescriptor
} from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src";

export const deepLinkFromString = (str: string): VCLDeepLink => {
return new VCLDeepLink(str);
export const deepLinkFrom = (deepLink: any): VCLDeepLink => {
return new VCLDeepLink(deepLink.value ?? deepLink);
}

export const tokenFromString = (str: string): VCLToken => {
return new VCLToken(str);
export const tokenFrom = (token: any): VCLToken => {
return new VCLToken(token.value ?? token);
}

export const jwtFromJson = (json: Dictionary<any>): VCLJwt => {
return VCLJwt.fromEncodedJwt(json.encodedJwt);
}

export const publicJwkFromJson = (json: Dictionary<any>): VCLPublicJwk => {
export const publicJwkFrom = (json: Dictionary<any>): VCLPublicJwk => {
return VCLPublicJwk.fromJSON(json);
}

export const didJwkFromJson = (json: Dictionary<any>): VCLDidJwk => {
export const didJwkFrom = (json: Dictionary<any>): VCLDidJwk => {
return VCLDidJwk.fromJSON(json);
}

export const presentationRequestDescriptorFromJson = (json: Dictionary<any>, didJwk: VCLDidJwk): VCLPresentationRequestDescriptor => {
const deepLink = deepLinkFromString(json.value)
export const presentationRequestDescriptorFrom = (json: Dictionary<any>, didJwk: VCLDidJwk): VCLPresentationRequestDescriptor => {
const deepLink = deepLinkFrom(json)
return new VCLPresentationRequestDescriptor(
deepLink,
null,
Expand All @@ -66,15 +66,15 @@ export const presentationRequestDescriptorFromJson = (json: Dictionary<any>, did
)
}

export const presentationSubmissionFromJson = (json: Dictionary<any>): VCLPresentationSubmission => {
export const presentationSubmissionFrom = (json: Dictionary<any>): VCLPresentationSubmission => {
const presentationRequestJson = json.presentationRequest;
const verifiableCredentials = json.verifiableCredentials
const presentationRequest = new VCLPresentationRequest(
jwtFromJson(presentationRequestJson.jwt),
new VCLVerifiedProfile(presentationRequestJson.verifiedProfile.payload),
new VCLDeepLink(presentationRequestJson.deepLink.value),
null,
didJwkFromJson(presentationRequestJson.didJwk),
didJwkFrom(presentationRequestJson.didJwk),
json.remoteCryptoServicesToken ? new VCLToken(json.remoteCryptoServicesToken) : null
)
return new VCLPresentationSubmission(
Expand All @@ -83,35 +83,35 @@ export const presentationSubmissionFromJson = (json: Dictionary<any>): VCLPresen
);
}

export const submissionResultFromJson = (json: Dictionary<any>): VCLSubmissionResult => {
export const submissionResultFrom = (json: Dictionary<any>): VCLSubmissionResult => {
const submissionResultJson = json;
return new VCLSubmissionResult(
tokenFromString(submissionResultJson.sessionToken.value),
tokenFrom(submissionResultJson.sessionToken.value),
new VCLExchange(submissionResultJson.exchange),
submissionResultJson.jti,
submissionResultJson.submissionId
);
}

export const organizationsSearchDescriptorFromJson = (json: Dictionary<any>): VCLOrganizationsSearchDescriptor => {
export const organizationsSearchDescriptorFrom = (json: Dictionary<any>): VCLOrganizationsSearchDescriptor => {
return new VCLOrganizationsSearchDescriptor(
new VCLFilter(json.filter.did, null, null),
);
}

const credentialManifestDescriptorByDeepLinkFromJson = (
const credentialManifestDescriptorByDeepLinkFrom = (
json: Dictionary<any>,
didJwk: VCLDidJwk
): VCLCredentialManifestDescriptorByDeepLink => {
return new VCLCredentialManifestDescriptorByDeepLink(
deepLinkFromString(json.value),
deepLinkFrom(json),
VCLIssuingType.Career,
null,
didJwk,
);
}

const credentialManifestDescriptorByServiceFromJson = (
const credentialManifestDescriptorByServiceFrom = (
json: Dictionary<any>,
didJwk: VCLDidJwk
): VCLCredentialManifestDescriptorByService => {
Expand All @@ -125,29 +125,29 @@ const credentialManifestDescriptorByServiceFromJson = (
);
}

export const credentialManifestDescriptorFromJson = (
export const credentialManifestDescriptorFrom = (
json: Dictionary<any>,
didJwk: VCLDidJwk
): VCLCredentialManifestDescriptor => {
return json.value ? // deep link
credentialManifestDescriptorByDeepLinkFromJson(json, didJwk) :
credentialManifestDescriptorByServiceFromJson(json, didJwk)
credentialManifestDescriptorByDeepLinkFrom(json, didJwk) :
credentialManifestDescriptorByServiceFrom(json, didJwk)
}

export const credentialManifestFromJson = (json: Dictionary<any>): VCLCredentialManifest => {
export const credentialManifestFrom = (json: Dictionary<any>): VCLCredentialManifest => {
return new VCLCredentialManifest(
jwtFromJson(json.jwt),
json.vendorOriginContext,
new VCLVerifiedProfile(json.verifiedProfile.payload),
json.deepLink ? new VCLDeepLink(json.deepLink.value) : null,
didJwkFromJson(json.didJwk),
didJwkFrom(json.didJwk),
json.remoteCryptoServicesToken ? new VCLToken(json.remoteCryptoServicesToken) : null

);
}

export const generateOffersDescriptorFromJson = (json: Dictionary<any>): VCLGenerateOffersDescriptor => {
const credentialManifest = credentialManifestFromJson(json.credentialManifest)
export const generateOffersDescriptorFrom = (json: Dictionary<any>): VCLGenerateOffersDescriptor => {
const credentialManifest = credentialManifestFrom(json.credentialManifest)
const identificationVerifiableCredentials =
json.identificationVerifiableCredentials.map((vc: Dictionary<any>) => VCLVerifiableCredential.fromJSON(vc))
return new VCLGenerateOffersDescriptor(
Expand All @@ -158,8 +158,8 @@ export const generateOffersDescriptorFromJson = (json: Dictionary<any>): VCLGene
);
}

export const finalizeOffersDescriptorFromJson = (json: Dictionary<any>): VCLFinalizeOffersDescriptor => {
const credentialManifest = credentialManifestFromJson(json.credentialManifest)
export const finalizeOffersDescriptorFrom = (json: Dictionary<any>): VCLFinalizeOffersDescriptor => {
const credentialManifest = credentialManifestFrom(json.credentialManifest)
return new VCLFinalizeOffersDescriptor(
credentialManifest,
json.challenge,
Expand All @@ -168,21 +168,21 @@ export const finalizeOffersDescriptorFromJson = (json: Dictionary<any>): VCLFina
);
}

export const credentialTypesUIFormSchemaDescriptorFromJson = (json: Dictionary<any>): VCLCredentialTypesUIFormSchemaDescriptor => {
export const credentialTypesUIFormSchemaDescriptorFrom = (json: Dictionary<any>): VCLCredentialTypesUIFormSchemaDescriptor => {
return new VCLCredentialTypesUIFormSchemaDescriptor(
json.credentialType,
json.countryCode
);
}

export function verifiedProfileDescriptorFromJson(json: Dictionary<any>): VCLVerifiedProfileDescriptor {
export const verifiedProfileDescriptorFrom = (json: Dictionary<any>): VCLVerifiedProfileDescriptor => {
return new VCLVerifiedProfileDescriptor(json.did)
}

export const jwtDescriptorFromJson = (json: Dictionary<any>): VCLJwtDescriptor => {
export const jwtDescriptorFrom = (json: Dictionary<any>): VCLJwtDescriptor => {
return new VCLJwtDescriptor(json.payload, json.jti, json.iss, json.aud);
}

export const didJwkDescriptorFromJson = (json: Dictionary<any>): VCLDidJwkDescriptor => {
export const didJwkDescriptorFrom = (json: Dictionary<any>): VCLDidJwkDescriptor => {
return new VCLDidJwkDescriptor(json.signatureAlgorithm, null);
}

0 comments on commit 9b6f2cb

Please sign in to comment.