Skip to content

Commit

Permalink
Merge pull request #115 from velocitycareerlabs/VL-8115-nodejs-sample…
Browse files Browse the repository at this point in the history
…-app-15

cont
  • Loading branch information
michaelavoyan authored Jul 10, 2024
2 parents f53624b + 1f48d2a commit d9996ed
Show file tree
Hide file tree
Showing 16 changed files with 287 additions and 34 deletions.
21 changes: 21 additions & 0 deletions packages/sample-app/src/repositories/CheckForOffersRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Created by Michael Avoyan on 10/07/2024.
*
* Copyright 2022 Velocity Career Labs inc.
* SPDX-License-Identifier: Apache-2.0
*/
import { Dictionary } from "../Types";
import Urls from "../network/Urls";
import fetcher from "../network/Fetcher";

export const checkOffers = async (
generateOffersDescriptor: Dictionary<any>,
sessionToken: Dictionary<any>,
): Promise<Dictionary<any>> => {
const config = {
url: Urls.checkOffers,
method: 'POST',
data: { generateOffersDescriptor, sessionToken }
};
return await fetcher(config);
}
21 changes: 21 additions & 0 deletions packages/sample-app/src/repositories/FinalizeOffersRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Created by Michael Avoyan on 10/07/2024.
*
* Copyright 2022 Velocity Career Labs inc.
* SPDX-License-Identifier: Apache-2.0
*/
import { Dictionary } from "../Types";
import Urls from "../network/Urls";
import fetcher from "../network/Fetcher";

export const finalizeOffers = async (
finalizeOffersDescriptor: Dictionary<any>,
sessionToken: Dictionary<any>,
): Promise<Dictionary<any>> => {
const config = {
url: Urls.finalizeOffers,
method: 'POST',
data: { finalizeOffersDescriptor, sessionToken },
};
return await fetcher(config);
}
18 changes: 18 additions & 0 deletions packages/sample-app/src/repositories/GenerateDidJwkRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Created by Michael Avoyan on 10/07/2024.
*
* Copyright 2022 Velocity Career Labs inc.
* SPDX-License-Identifier: Apache-2.0
*/
import Urls from "../network/Urls";
import { Dictionary } from "../Types";
import fetcher from "../network/Fetcher";

export const generateDidJwk = async (generateDidJwkDescriptor: Dictionary<any>): Promise<Dictionary<any>> => {
const config = {
url: Urls.generateDidJwk,
method: 'POST',
data: generateDidJwkDescriptor,
};
return await fetcher(config);
}
20 changes: 20 additions & 0 deletions packages/sample-app/src/repositories/GenerateOffersRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Created by Michael Avoyan on 09/07/2024.
*
* Copyright 2022 Velocity Career Labs inc.
* SPDX-License-Identifier: Apache-2.0
*/
import { Dictionary } from "../Types";
import Urls from "../network/Urls";
import fetcher from "../network/Fetcher";

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

export const getCredentialManifest = async (deepLink: string): Promise<Dictionary<any>> => {
export const getCredentialManifestByDeepLink = async (
deepLink: Dictionary<any>
): Promise<Dictionary<any>> => {
const config = {
url: Urls.getCredentialManifest,
method: 'POST',
data: { "value": deepLink },
data: deepLink,
};
return await fetcher(config);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Created by Michael Avoyan on 10/07/2024.
*
* Copyright 2022 Velocity Career Labs inc.
* SPDX-License-Identifier: Apache-2.0
*/
import { Dictionary } from "../Types";
import Urls from "../network/Urls";
import fetcher from "../network/Fetcher";

export const getCredentialManifestByService = async (
credentialManifestDescriptorByService: Dictionary<any>
): Promise<Dictionary<any>> => {
const config = {
url: Urls.getCredentialManifest,
method: 'POST',
data: credentialManifestDescriptorByService,
};
return await fetcher(config);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { Dictionary } from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src";
import fetcher from "../network/Fetcher";
import Urls from "../network/Urls";

export const getPresentationRequest = async (deepLink: string): Promise<Dictionary<any>> => {
export const getPresentationRequest = async (
deepLink: Dictionary<any>
): Promise<Dictionary<any>> => {
const config = {
url: Urls.getPresentationRequest,
method: 'POST',
data: { "value": deepLink },
data: deepLink,
};
return await fetcher(config);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Created by Michael Avoyan on 09/07/2024.
*
* Copyright 2022 Velocity Career Labs inc.
* SPDX-License-Identifier: Apache-2.0
*/
import { Dictionary } from "../Types";
import Urls from "../network/Urls";
import fetcher from "../network/Fetcher";

export const searchForOrganizations = async (
organizationDescriptor: Dictionary<any>
): Promise<any> => {
const config = {
url: Urls.searchForOrganizations,
method: 'POST',
data: organizationDescriptor,
};
return await fetcher(config);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { Dictionary } from "@velocitycareerlabs/vnf-nodejs-wallet-sdk/src";
import Urls from "../network/Urls";
import fetcher from "../network/Fetcher";

export const submitPresentation = async (presentationSubmission: Dictionary<any>): Promise<Dictionary<any>> => {
export const submitPresentation = async (
presentationSubmission: Dictionary<any>
): Promise<Dictionary<any>> => {
const config = {
url: Urls.submitPresentation,
method: 'POST',
Expand Down
16 changes: 14 additions & 2 deletions packages/sample-app/src/repositories/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,25 @@ import { getCredentialTypes } from "./CredentialTypesRepository";
import { getCredentialTypeSchemas } from "./CredentialTypeSchemasRepository";
import { getPresentationRequest } from "./PresentationRequestRepository";
import { submitPresentation } from "./SubmitPresentationRepository";
import { getCredentialManifest } from "./GetCredentialManifestByDeepLinkRepository";
import { getCredentialManifestByDeepLink } from "./GetCredentialManifestByDeepLinkRepository";
import { getCredentialManifestByService } from "./GetCredentialManifestByServiceRepository";
import { generateOffers } from "./GenerateOffersRepository";
import { checkOffers } from "./CheckForOffersRepository";
import { finalizeOffers } from "./FinalizeOffersRepository";
import { searchForOrganizations } from "./SearchForOrganizationsRepository";
import { generateDidJwk } from "./GenerateDidJwkRepository";

export {
getCountries,
getCredentialTypes,
getCredentialTypeSchemas,
getPresentationRequest,
submitPresentation,
getCredentialManifest
getCredentialManifestByDeepLink,
getCredentialManifestByService,
generateOffers,
finalizeOffers,
checkOffers,
searchForOrganizations,
generateDidJwk
};
124 changes: 102 additions & 22 deletions packages/sample-app/src/screens/MeinScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,59 @@ import {
getCredentialTypeSchemas,
getCredentialTypes,
getPresentationRequest,
submitPresentation, getCredentialManifest
submitPresentation,
getCredentialManifestByDeepLink,
getCredentialManifestByService,
generateOffers,
searchForOrganizations,
generateDidJwk, finalizeOffers, checkOffers
} from "../repositories";
import { Constants } from "./Constants";
import { Dictionary } from "../Types";
import { getApprovedRejectedOfferIdsMock } from "../utils/Utils";

let didJwk: Dictionary<any>;
const initialization = async () => {
if (!didJwk) {
didJwk = await generateDidJwk({
signatureAlgorithm: "P-256",
remoteCryptoServicesToken: null
});
}
console.log('didJwk: ', didJwk);
};

// @ts-ignore
await initialization();

const onGetCountries = () => {
getCountries().then((response) => {
console.log(response);
getCountries().then((countries) => {
console.log('countries: ', countries);
}).catch((error) => {
console.log(error);
});
};

const onGetCredentialTypes = () => {
getCredentialTypes().then((response) => {
console.log(response);
getCredentialTypes().then((credentialTypes) => {
console.log('credential types: ', credentialTypes);
}).catch((error) => {
console.log(error);
});
};

const onGetCredentialTypeSchemas = () => {
getCredentialTypeSchemas().then((response) => {
console.log(response);
getCredentialTypeSchemas().then((credentialTypeSchemas) => {
console.log('credential typeSchemas: ', credentialTypeSchemas);
}).catch((error) => {
console.log(error);
});
};

const onGetPresentationRequest = () => {
getPresentationRequest(Constants.PresentationRequestDeepLinkStrDev)
getPresentationRequest({value: Constants.PresentationRequestDeepLinkStrDev} )
.then((presentationRequest) => {
console.log("Presentation Request received: ", presentationRequest);
console.log('presentation request: ', presentationRequest);
onSubmitPresentation(presentationRequest);
})
.catch((error) => {
Expand All @@ -50,30 +73,87 @@ const onGetPresentationRequest = () => {

const onSubmitPresentation = (presentationRequest: Dictionary<any>) => {
submitPresentation({
'verifiableCredentials': Constants.PresentationSelectionsList,
'presentationRequest': presentationRequest
verifiableCredentials: Constants.PresentationSelectionsList,
presentationRequest: presentationRequest
}
).then((response) => {
console.log(response);
).then((submissionResult) => {
console.log('submission result: ', submissionResult);
}).catch((error) => {
console.log(error);
});
}
};

const onGetCredentialManifestByDeepLink = () => {
getCredentialManifest(Constants.CredentialManifestDeepLinkStrDev).then((credentialManifest) => {
console.log(credentialManifest);
getCredentialManifestByDeepLink(
{ value: Constants.CredentialManifestDeepLinkStrDev }
).then((credentialManifest) => {
console.log('credential manifest: ', credentialManifest);
onGenerateOffers(credentialManifest);
}).catch((error) => {
console.log(error);
});
}

const gonGetCredentialManifestByDeepLink = () => {
onGetCredentialManifestByDeepLink()
};

const onGetOrganizationsThenCredentialManifestByService = () => {
alert(`You clicked on getOrganizationsThenCredentialManifestByService`);
searchForOrganizations({
filter: { 'did': Constants.DidDev }
}).then((organizations) => {
console.log('organizations: ', organizations);
const serviceCredentialAgentIssuer = organizations.all[0].payload.service[0];
getCredentialManifestByService({
service: serviceCredentialAgentIssuer,
issuingType: 'Career',
credentialTypes: [serviceCredentialAgentIssuer.type], // Can come from any where
didJwk: didJwk
}).then((credentialManifest) => {
console.log('credential manifest: ', credentialManifest);
onGenerateOffers(credentialManifest);
}).catch((error) => {
console.log(error);
});
}).catch((error) => {
console.log(error);
});
}

const onGenerateOffers = (credentialManifest: Dictionary<any>) => {
const generateOffersDescriptor = {
credentialManifest: credentialManifest,
types: Constants.CredentialTypes,
identificationVerifiableCredentials: Constants.IdentificationList
}
generateOffers(generateOffersDescriptor).then((offers) => {
console.log('generate offers: ', offers);
onCheckOffers(generateOffersDescriptor, offers.sessionToken)
}).catch((error) => {
console.log(error);
})
};

const onCheckOffers = (generateOffersDescriptor: Dictionary<any>, sessionToken: Dictionary<any>) => {
checkOffers(generateOffersDescriptor, sessionToken).then((offers) => {
console.log('check offers: ', offers);
onFinalizeOffers(generateOffersDescriptor.credentialManifest, offers);
}).catch((error) => {
console.log(error);
});
}

const onFinalizeOffers = (credentialManifest: Dictionary<any>, offers: Dictionary<any>) => {
const approvedRejectedOfferIds = getApprovedRejectedOfferIdsMock(offers)
const finalizeOffersDescriptor = {
credentialManifest: credentialManifest,
challenge: offers.challenge,
approvedOfferIds: approvedRejectedOfferIds[0],
rejectedOfferIds: approvedRejectedOfferIds[1]
}
finalizeOffers(finalizeOffersDescriptor, offers.sessionToken).then((credentials) => {
console.log('credentials: ', credentials);
}).catch((error) => {
console.log(error);
});
}

const onGetCredentialTypesUIFormSchema = () => {
alert(`You clicked on getCredentialTypesUIFormSchema`);
};
Expand All @@ -99,7 +179,7 @@ const MeinScreen: React.FC = () => {
'Get Credential Types': onGetCredentialTypes,
'Get Credential Type Schemas': onGetCredentialTypeSchemas,
'Disclosing Credentials (aka Inspection)': onGetPresentationRequest,
'Receiving Credentials (aka Issuing) By Deeplink': gonGetCredentialManifestByDeepLink,
'Receiving Credentials (aka Issuing) By Deeplink': onGetCredentialManifestByDeepLink,
'Receiving Credentials (aka Issuing) By Services': onGetOrganizationsThenCredentialManifestByService,
'Self Reporting Credentials (aka Self Attested)': onGetCredentialTypesUIFormSchema,
'Refresh Credentials': onRefreshCredentials,
Expand Down
Loading

0 comments on commit d9996ed

Please sign in to comment.