Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Refactor #121

Merged
merged 4 commits into from
Aug 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 48 additions & 7 deletions wallet/wallet-app/utils/httpRequests.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
/* eslint-disable no-alert */
const host = '192.168.137.191';

const issuerUrl = `http://${host}:8083/`;
const verifierUrl = `http://${host}:8080/api/`;
const issuerUrl = `http://${host}:8083/api`;
const verifierUrl = `http://${host}:8080/api`;
const vdrUrl = `http://${host}:8083/vdr`;

/**
* Fetches a verifiable credential from an issuer using HTTP GET.
*
* @param {string} vcType The type of credential to request
* @param {string} baseVC JWT-encoded base VC (root identity)
* @param {string} issuer The issuer to request from (should be removed when issuers are separated)
* @returns {string} A verifiable credential JWT string
*/
export async function httpGetCredential(vcType, baseVC, issuer) {
const url = `${issuerUrl}api/getVC/`;
const url = `${issuerUrl}/getVC/`;
const response = await fetch(`${url}?type=${vcType}&baseVC=${baseVC}&issuer=${issuer}`);
const payload = await response.text();

return payload;
}

/**
* Sends a verifiable presentation to a verifier using HTTP POST.
*
* @param {string} token A JWT-encoded verifiable presentation
* @returns {boolean} True if the request was succesful, false if not
*/
export async function httpSendPresentation(token) {
const url = `${verifierUrl}sendVP`;
const url = `${verifierUrl}/sendVP`;

try {
const response = await fetch(url, {
Expand All @@ -31,22 +44,41 @@ export async function httpSendPresentation(token) {
}
}

/**
* Fetches the available VC types for a given issuer
*
* @param {string} issuer The issuer to get available types for
* @returns {string[]} The VC types the selected issuer is offering
*/
export async function httpGetTypesFromIssuer(issuer) {
const url = `${vdrUrl}/getTypes/${issuer}`;
const response = await fetch(url);
const payload = await response.text();
return payload;
}

/**
* Fetches all the issuers available in the VDR
*
* @returns {string[]} List of available issuers
*/

export async function httpGetAllIssuers() {
const url = `${vdrUrl}/getAllIssuers`;
const response = await fetch(url);
const payload = await response.text();
return payload;
}

/**
* Publishes the wallet's public key to the VDR, using HTTP POST
*
* @param {string} id The id of the wallet
* @param {string} key A PEM-encoded public key
* @returns True if the key is successfully posted, false if not
*/
export async function httpPostPublicKey(id, key) {
const url = `${issuerUrl}vdr/postKey`;
const url = `${vdrUrl}/postKey`;

try {
const response = await fetch(`${url}?userID=${id}`, {
Expand All @@ -64,16 +96,25 @@ export async function httpPostPublicKey(id, key) {
}
}

/**
* Fetches an issuer's public key (RS256)
* The format of the key is not yet standardized (e.g. PEM)
*
* @param {string} id The id of the issuer
* @returns {string} The public key as base64
*/
export async function httpGetIssuerKey(id) {
const url = `${issuerUrl}vdr/key/`;
const url = `${vdrUrl}/key/`;
const response = await fetch(`${url}${id}`);
const payload = await response.text();
return payload;
}

/** Example VC JWT for development purposes */
export const exampleCredentialToken =
'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiIwODA4OTQwODA4NCIsImlzcyI6IlV0c2VkZXJBdkJldmlzLm5vZWQ4M2JlNDctYjJmNy00ZmIyLTkzNDEtOWE3MTBjOWM3ZWFkIiwiZXhwIjoxNjI3OTg5NDU5LCJpYXQiOjE2MjY3Nzk4NTksInZjIjp7ImNyZWRlbnRpYWxTdWJqZWN0Ijp7ImFnZSI6eyJuYW1lIjoiT3ZlciAxOCIsInR5cGUiOiJvdmVyLTE4In19LCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiQWdlQ3JlZGVudGlhbCJdLCJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSJdfSwianRpIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgzL2NyZWRlbnRpYWxzLzEifQ.AGa0bo7lTdRqHfAx6bbS34sW4DwNhMMHsqd_riorZ2Yf3zEafMXV-_QmBIHxamuVy_8Neq7qz7vnAe6o5Ej8Vs6K98Z_H5IxeZ64bfN-qTq2WBadsk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