From 58d9bcd598036a14b35d107761eddba388587783 Mon Sep 17 00:00:00 2001 From: Sam Hellawell Date: Wed, 25 Sep 2024 04:20:16 +0100 Subject: [PATCH 1/2] Add individual API proxy routes instead of bundled into one, cleanup some unused code --- README.md | 2 - _credentials/equinet.js | 3 - _credentials/forsur.js | 2 - _credentials/quotient.js | 2 - hooks/useRevoke.js | 6 -- pages/api/create-proof-request.js | 30 ++++++ ...ndle-credentials.js => create-registry.js} | 12 +-- pages/api/find-registry.js | 29 ++++++ pages/api/{handle-get.js => get-job.js} | 7 +- pages/api/issue-biometric.js | 39 ++++++++ pages/api/issue-credential.js | 26 +++++ pages/api/revoke-action.js | 29 ++++++ pages/api/verify-credential.js | 26 +++++ pages/test.js | 96 ------------------- utils/dock-credentials.js | 40 +------- utils/dock-jobs.js | 7 +- utils/dock-registries.js | 38 ++++---- utils/generate-qr.js | 15 +-- utils/request.js | 16 +--- 19 files changed, 220 insertions(+), 205 deletions(-) create mode 100644 pages/api/create-proof-request.js rename pages/api/{handle-credentials.js => create-registry.js} (75%) create mode 100644 pages/api/find-registry.js rename pages/api/{handle-get.js => get-job.js} (82%) create mode 100644 pages/api/issue-biometric.js create mode 100644 pages/api/issue-credential.js create mode 100644 pages/api/revoke-action.js create mode 100644 pages/api/verify-credential.js delete mode 100644 pages/test.js diff --git a/README.md b/README.md index f3029e3..3bcceae 100644 --- a/README.md +++ b/README.md @@ -156,8 +156,6 @@ Under folder `/utils` are the files that handle all the communication with Dock `createCredential(registryId, credential)` -> Create new credential from registryId & credential schema. -`distributeCredential(credential)` -> Send a signed credential to a Did or email. - `issueRevokableCredential = async (credential, setRevokableCredential)` -> Entire process that carrie all previews functions. revokeCredential = async (registryId, credentialId) -> Revoke credit score credential with a given registry and credential ids. diff --git a/_credentials/equinet.js b/_credentials/equinet.js index ded5622..3e329d0 100644 --- a/_credentials/equinet.js +++ b/_credentials/equinet.js @@ -1,12 +1,9 @@ -import { v4 as uuidv4 } from 'uuid'; -import { dockUrl } from 'utils/constants'; import { validateEmail } from 'utils/validation'; export function createCreditScoreCredential({ receiverDid, recipientEmail, creditScore }) { console.log('Creating EquiNet - Credit Score Credential for:', receiverDid); const credentialPayload = { - url: `${dockUrl}/credentials`, body: { anchor: false, distribute: true, diff --git a/_credentials/forsur.js b/_credentials/forsur.js index 3af2f4b..1a6a4ad 100644 --- a/_credentials/forsur.js +++ b/_credentials/forsur.js @@ -1,5 +1,4 @@ import { v4 as uuidv4 } from 'uuid'; -import { dockUrl } from 'utils/constants'; import { validateEmail } from 'utils/validation'; export function createBiometricsCredential({ @@ -10,7 +9,6 @@ export function createBiometricsCredential({ console.log('Creating ForSur - Biometric Enrollment Credential for:', receiverDid); const credentialPayload = { - url: `${dockUrl}/credentials`, body: { anchor: false, algorithm: 'bbdt16', diff --git a/_credentials/quotient.js b/_credentials/quotient.js index 02a95b2..3312b41 100644 --- a/_credentials/quotient.js +++ b/_credentials/quotient.js @@ -1,5 +1,4 @@ import { v4 as uuidv4 } from 'uuid'; -import { dockUrl } from 'utils/constants'; import { validateEmail } from 'utils/validation'; export function createBankIdCredential({ @@ -12,7 +11,6 @@ export function createBankIdCredential({ console.log('Creating Quotient Bank Identity Credential for:', receiverDid); const credentialPayload = { - url: `${dockUrl}/credentials`, body: { anchor: false, algorithm: 'bbdt16', diff --git a/hooks/useRevoke.js b/hooks/useRevoke.js index 198e22a..257e59f 100644 --- a/hooks/useRevoke.js +++ b/hooks/useRevoke.js @@ -61,14 +61,8 @@ export const useRevoke = () => { } } - async function handleGetRegistry() { - const registry = await getRegistry(revokableCredential.registryId); - console.log('registry', registry); - } - return { loadingRevokation, - handleGetRegistry, handleRevoke, issueNewCredential } diff --git a/pages/api/create-proof-request.js b/pages/api/create-proof-request.js new file mode 100644 index 0000000..65cd129 --- /dev/null +++ b/pages/api/create-proof-request.js @@ -0,0 +1,30 @@ +import { generateNonce } from '../../utils/generate-nonce'; +import { dockUrl } from '../../utils/constants'; + +export default async (req, res) => { + if (req.method !== 'POST') { + console.log('Only post request allowed'); + res.status(400).json({}); + return; + } + + const result = await fetch(`${dockUrl}/proof-templates/${req.body.proofTemplateID}/request`, { + method: 'POST', + headers: { + 'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, + 'content-type': 'application/json', + }, + body: JSON.stringify({ + nonce: `${generateNonce()}`, + domain: 'dock.io', + }), + }); + + const response = await result.json(); + if (!result.ok) { + const errorText = await result.text(); + throw new Error(`API Error: ${result.status} - ${errorText}`); + } + + res.status(202).send(response); +}; diff --git a/pages/api/handle-credentials.js b/pages/api/create-registry.js similarity index 75% rename from pages/api/handle-credentials.js rename to pages/api/create-registry.js index 561bd9d..6739c8b 100644 --- a/pages/api/handle-credentials.js +++ b/pages/api/create-registry.js @@ -1,3 +1,5 @@ +import { dockUrl } from '../../utils/constants'; + export default async (req, res) => { if (req.method !== 'POST') { console.log('Only post request allowed'); @@ -5,22 +7,16 @@ export default async (req, res) => { return; } - const body = req.body; - - console.log('body::', body); - - const result = await fetch(body.url, { + const result = await fetch(`${dockUrl}/registries`, { method: 'POST', headers: { 'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, 'content-type': 'application/json', }, - body: JSON.stringify(body), + body: JSON.stringify(req.body), }); const response = await result.json(); - console.log('response:', result); - if (!result.ok) { const errorText = await result.text(); throw new Error(`API Error: ${result.status} - ${errorText}`); diff --git a/pages/api/find-registry.js b/pages/api/find-registry.js new file mode 100644 index 0000000..03b9649 --- /dev/null +++ b/pages/api/find-registry.js @@ -0,0 +1,29 @@ +import { dockUrl } from '../../utils/constants'; + +export default async (req, res) => { + if (req.method !== 'GET') { + console.log('Only GET request allowed'); + res.status(400).json({}); + return; + } + + const result = await fetch( + `${dockUrl}/registries?did=${encodeURIComponent(req.query.did)}&type=${encodeURIComponent(req.query.searchType)}`, + { + method: 'GET', + headers: { + 'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, + 'content-type': 'application/json', + }, + } + ); + + const response = await result.json(); + + if (!result.ok) { + const errorText = await result.text(); + throw new Error(`API get Error: ${result.status} - ${errorText}`); + } + + res.status(202).send(response); +}; diff --git a/pages/api/handle-get.js b/pages/api/get-job.js similarity index 82% rename from pages/api/handle-get.js rename to pages/api/get-job.js index 146603b..773378f 100644 --- a/pages/api/handle-get.js +++ b/pages/api/get-job.js @@ -1,3 +1,5 @@ +import { dockUrl } from '../../utils/constants'; + export default async (req, res) => { if (req.method !== 'GET') { console.log('Only GET request allowed'); @@ -5,9 +7,7 @@ export default async (req, res) => { return; } - const url = req.query.url; - - const result = await fetch(url, { + const result = await fetch(`${dockUrl}/jobs/${req.query.id}`, { method: 'GET', headers: { 'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, @@ -16,7 +16,6 @@ export default async (req, res) => { }); const response = await result.json(); - console.log('response:', result); if (!result.ok) { const errorText = await result.text(); diff --git a/pages/api/issue-biometric.js b/pages/api/issue-biometric.js new file mode 100644 index 0000000..babed96 --- /dev/null +++ b/pages/api/issue-biometric.js @@ -0,0 +1,39 @@ +import { dockUrl } from '../../utils/constants'; + +export default async (req, res) => { + if (req.method !== 'POST') { + console.log('Only post request allowed'); + res.status(400).json({}); + return; + } + + const { issuer, type, subject, expirationDate } = req.body; + + const result = await fetch(`${dockUrl}/credentials`, { + method: 'POST', + headers: { + 'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, + 'content-type': 'application/json', + }, + body: JSON.stringify({ + anchor: false, + persist: false, + credential: { + name: type, + type: ['VerifiableCredential', type], + issuer, + expirationDate, + subject, + }, + algorithm: 'dockbbs+', + }), + }); + + const response = await result.json(); + if (!result.ok) { + const errorText = await result.text(); + throw new Error(`API Error: ${result.status} - ${errorText}`); + } + + res.status(202).send(response); +}; diff --git a/pages/api/issue-credential.js b/pages/api/issue-credential.js new file mode 100644 index 0000000..b56d6a1 --- /dev/null +++ b/pages/api/issue-credential.js @@ -0,0 +1,26 @@ +import { dockUrl } from '../../utils/constants'; + +export default async (req, res) => { + if (req.method !== 'POST') { + console.log('Only post request allowed'); + res.status(400).json({}); + return; + } + + const result = await fetch(`${dockUrl}/credentials`, { + method: 'POST', + headers: { + 'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, + 'content-type': 'application/json', + }, + body: JSON.stringify(req.body), + }); + + const response = await result.json(); + if (!result.ok) { + const errorText = await result.text(); + throw new Error(`API Error: ${result.status} - ${errorText}`); + } + + res.status(202).send(response); +}; diff --git a/pages/api/revoke-action.js b/pages/api/revoke-action.js new file mode 100644 index 0000000..290ac83 --- /dev/null +++ b/pages/api/revoke-action.js @@ -0,0 +1,29 @@ +import { dockUrl } from '../../utils/constants'; + +export default async (req, res) => { + if (req.method !== 'POST') { + console.log('Only post request allowed'); + res.status(400).json({}); + return; + } + + const result = await fetch(`${dockUrl}/registries/${req.body.registryId}`, { + method: 'POST', + headers: { + 'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, + 'content-type': 'application/json', + }, + body: JSON.stringify({ + ...req.body, + registryId: undefined, + }), + }); + + const response = await result.json(); + if (!result.ok) { + const errorText = await result.text(); + throw new Error(`API Error: ${result.status} - ${errorText}`); + } + + res.status(202).send(response); +}; diff --git a/pages/api/verify-credential.js b/pages/api/verify-credential.js new file mode 100644 index 0000000..d464897 --- /dev/null +++ b/pages/api/verify-credential.js @@ -0,0 +1,26 @@ +import { dockUrl } from '../../utils/constants'; + +export default async (req, res) => { + if (req.method !== 'POST') { + console.log('Only post request allowed'); + res.status(400).json({}); + return; + } + + const result = await fetch(`${dockUrl}/verify`, { + method: 'POST', + headers: { + 'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, + 'content-type': 'application/json', + }, + body: JSON.stringify(req.body), + }); + + const response = await result.json(); + if (!result.ok) { + const errorText = await result.text(); + throw new Error(`API Error: ${result.status} - ${errorText}`); + } + + res.status(202).send(response); +}; diff --git a/pages/test.js b/pages/test.js deleted file mode 100644 index fd17303..0000000 --- a/pages/test.js +++ /dev/null @@ -1,96 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import { Button } from 'components/ui/button'; -import { useLocalStorage } from 'hooks/hooks'; -import { issueRevokableCredential } from 'utils/issue-crendentials'; -import { createCreditScoreCredential } from '_credentials/equinet'; -import { getRandomNumber } from 'utils'; -import { getRegistry, revokeCredential } from 'utils/dock-registries'; -import { toast } from 'sonner'; -import userStore from 'store/appStore'; - -export default function Test() { - const [revokableCredential, setRevokableCredential] = useLocalStorage('revokableCredential', ''); - const recipientEmail = userStore((state) => state.userEmail); - const [loadingRevokation, setLoadingRevokation] = useState(false); - - const credentialPayload = { - receiverDid: revokableCredential.userDid, - recipientEmail, - creditScore: getRandomNumber(700, 800), - }; - - async function handleRevoke() { - if (!revokableCredential.registryId || !revokableCredential.credentialId) { - toast.warning('There is no credential to revoke.'); - return; - } - - setLoadingRevokation(true); - try { - const revokation = await revokeCredential( - revokableCredential.registryId, - revokableCredential.credentialId - ); - if (revokation.status === 202) { - toast.success('Credential revoked successfully', { duration: 10000 }); - setTimeout(async () => { - await issueNewCredential(); - }, 3000); - } else { - setLoadingRevokation(false); - throw new Error('Revocation error, try again'); - } - } catch (error) { - setLoadingRevokation(false); - toast.error('Error revokating credential, try again.'); - } - } - - const createCredential = async (credential, payload, isRevocable) => { - const credentialObj = credential(payload); - await issueRevokableCredential(credentialObj.body, setRevokableCredential, isRevocable); - }; - - async function issueNewCredential() { - toast.info('Issuing new credential', { duration: 10000 }); - try { - await createCredential(createCreditScoreCredential, credentialPayload, true); - toast.success('Credentials issued successfully.'); - setLoadingRevokation(false); - } catch (error) { - console.log('Issuing error:', error); - toast.warning('Error issuing credentials, try again.'); - setLoadingRevokation(false); - } - } - - async function handleGetRegistry() { - const registry = await getRegistry(revokableCredential.registryId); - console.log('registry', registry); - } - - return ( -
-
-

Helper functions

-
-
- - - - - -
-
- ); -} diff --git a/utils/dock-credentials.js b/utils/dock-credentials.js index e66a996..80c14b0 100644 --- a/utils/dock-credentials.js +++ b/utils/dock-credentials.js @@ -1,5 +1,4 @@ -import { postRequest } from "./request"; -import { dockUrl } from "./constants"; +import { postRequestLocal } from "./request"; /** * Creates a credential with the provided credential data and issuer. * Sets the credential issuer ID to the provided issuer DID. @@ -13,10 +12,7 @@ export async function createCredential(registryId, credential) { } console.log("issuing credential", credential); - return await postRequest( - `${dockUrl}/credentials/`, - credential, - ); + return postRequestLocal('issue-credential', credential); } /** @@ -27,38 +23,10 @@ export async function createCredential(registryId, credential) { * @returns A Promise that resolves to the verification result. */ export async function verifyCredential({ credential }) { - - return await postRequest( - `${dockUrl}/verify/`, - credential, - ); + console.log("verifying credential", credential); + return postRequestLocal('verify-credential', credential); } -/** - * Distributes a credential by encrypting it and sending it via API. - * - * @param credential - The credential to be distributed. - * @returns A Promise that resolves to the result of the API call. - */ -export async function distributeCredential(credential) { - - console.log('distributeCredential:', credential); - const encryptionPayload = { - senderDid: credential.issuer.id, - recipientDids: [credential.credentialSubject.id], - type: "issue", - payload: { - domain: "api.dock.io", - credentials: [credential.subject], - } - }; - - return await postRequest( - `${dockUrl}/messaging/encrypt`, - encryptionPayload - ); -}; - // export async function requestClaims(credential) { // const body = { diff --git a/utils/dock-jobs.js b/utils/dock-jobs.js index 16a2d2d..86167e1 100644 --- a/utils/dock-jobs.js +++ b/utils/dock-jobs.js @@ -1,5 +1,4 @@ -import { apiGet } from "./request"; -import { dockUrl } from "./constants"; +import { apiGetLocal } from "./request"; /** * Gets a job by ID. @@ -7,8 +6,8 @@ import { dockUrl } from "./constants"; * @returns {Promise} The job data. */ export async function getJob(id) { - const result = await apiGet( - `${dockUrl}/jobs/${id}` + const result = await apiGetLocal( + `get-job?id=${id}` ); return result.data; } diff --git a/utils/dock-registries.js b/utils/dock-registries.js index 386f561..ea757ff 100644 --- a/utils/dock-registries.js +++ b/utils/dock-registries.js @@ -1,6 +1,6 @@ import { toast } from 'sonner'; -import { postRequest, apiGet } from './request'; -import { dockUrl } from './constants'; +import { apiGetLocal, postRequestLocal } from './request'; + /** * Creates a new registry by calling the Registries API endpoint. * @@ -16,8 +16,8 @@ export async function createRegistry(policyDid, type) { }; try { - const response = await postRequest( - `${dockUrl}/registries`, + const response = await postRequestLocal( + 'create-registry', data, ); @@ -33,14 +33,6 @@ export async function createRegistry(policyDid, type) { return undefined; } -export async function getRegistry(registryId) { - try { - return apiGet(`${dockUrl}/registries/${registryId}`); - } catch (error) { - toast.error('Invalid crendential registry.'); - } -} - /** * Revokes a credential from the registry with the given ID. * @@ -58,9 +50,12 @@ export const revokeCredential = async (registryId, credentialId) => { }; try { - return await postRequest( - `${dockUrl}/registries/${registryId}`, - payload, + return await postRequestLocal( + 'revoke-action', + { + ...payload, + registryId, + }, ); } catch (error) { toast.warning('Error revoking this credential'); @@ -85,10 +80,13 @@ export async function unrevoke(registryId, credential) { }; try { - const response = await postRequest({ - url, - body: data, - }); + const response = await postRequestLocal( + 'revoke-action', + { + ...data, + registryId, + }, + ); return response; } catch (error) { @@ -99,7 +97,7 @@ export async function unrevoke(registryId, credential) { } export async function getExistingRegistry(did, searchType) { - const registriesResponse = await apiGet(encodeURIComponent(`${dockUrl}/registries?did=${encodeURIComponent(did)}&type=${searchType}&limit=1`)); + const registriesResponse = await apiGetLocal(`find-registry?did=${encodeURIComponent(did)}&type=${searchType}`); if (!registriesResponse || !registriesResponse.data || registriesResponse.data.length === 0) { return null; diff --git a/utils/generate-qr.js b/utils/generate-qr.js index 2b1fd0f..0e71cee 100644 --- a/utils/generate-qr.js +++ b/utils/generate-qr.js @@ -1,20 +1,15 @@ import { toast } from 'sonner'; -import { generateNonce } from './generate-nonce'; -import { dockUrl } from './constants'; -import { postRequest } from './request'; +import { postRequestLocal } from './request'; export const generateQR = async ( proofTemplateID ) => { - const proofBody = { - nonce: `${generateNonce()}`, - domain: 'dock.io' - }; - try { - const response = await postRequest(`${dockUrl}/proof-templates/${proofTemplateID}/request`, proofBody); + const response = await postRequestLocal('create-proof-request', { + proofTemplateID, + }); if (response.status === 202) return response.data; - return undefined + return undefined; } catch (err) { toast.error('Error generating proof request QR code:'); throw new Error(err); diff --git a/utils/request.js b/utils/request.js index 7e5dea3..8f1d467 100644 --- a/utils/request.js +++ b/utils/request.js @@ -1,16 +1,8 @@ import axios from 'axios'; -/** - * Sends a POST request to the specified URL with the given body. - * @param {string} url - The URL to send the POST request to. - * @param {object} body - The body of the POST request. - * @returns {Promise} A Promise that resolves with the response data if successful. - * @throws {Error} If an error occurs during the request. - */ -export async function postRequest(url, body) { +export async function postRequestLocal(url, requestBody) { try { - const requestBody = { ...body, url }; - const response = await axios.post(`/api/handle-credentials`, requestBody); + const response = await axios.post(`/api/${url}`, requestBody); console.log('post response:', response); return response; } catch (error) { @@ -20,10 +12,10 @@ export async function postRequest(url, body) { } } -export async function apiGet(url) { +export async function apiGetLocal(url) { try { return await axios.get( - `/api/handle-get?url=${url}`, + `/api/${url}`, ); } catch (error) { console.error(error); From d5bc904e8bed3bfaa6d6255d2129f11289790ae2 Mon Sep 17 00:00:00 2001 From: Sam Hellawell Date: Wed, 25 Sep 2024 04:43:28 +0100 Subject: [PATCH 2/2] Fix mdl/openid examples --- pages/api/create-credential-offer.js | 44 ++++++++++++++++++++++++ pages/api/create-proof-request-object.js | 26 ++++++++++++++ pages/api/get-oid4vp-url.js | 29 ++++++++++++++++ pages/mdl.js | 16 ++++----- pages/openid.js | 29 +++++----------- 5 files changed, 115 insertions(+), 29 deletions(-) create mode 100644 pages/api/create-credential-offer.js create mode 100644 pages/api/create-proof-request-object.js create mode 100644 pages/api/get-oid4vp-url.js diff --git a/pages/api/create-credential-offer.js b/pages/api/create-credential-offer.js new file mode 100644 index 0000000..1938b08 --- /dev/null +++ b/pages/api/create-credential-offer.js @@ -0,0 +1,44 @@ +import { dockUrl } from '../../utils/constants'; + +export default async (req, res) => { + if (req.method !== 'POST') { + console.log('Only post request allowed'); + res.status(400).json({}); + return; + } + + let result; + result = await fetch(`${dockUrl}/openid/issuers`, { + method: 'POST', + headers: { + 'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, + 'content-type': 'application/json', + }, + body: JSON.stringify(req.body), + }); + + const response = await result.json(); + if (!result.ok) { + const errorText = await result.text(); + throw new Error(`API Error: ${result.status} - ${errorText}`); + } + + result = await fetch(`${dockUrl}/openid/credential-offers`, { + method: 'POST', + headers: { + 'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, + 'content-type': 'application/json', + }, + body: JSON.stringify({ + id: response.id, + }), + }); + + const offerResponse = await result.json(); + if (!result.ok) { + const errorText = await result.text(); + throw new Error(`API Error: ${result.status} - ${errorText}`); + } + + res.status(202).send(offerResponse); +}; diff --git a/pages/api/create-proof-request-object.js b/pages/api/create-proof-request-object.js new file mode 100644 index 0000000..74e8331 --- /dev/null +++ b/pages/api/create-proof-request-object.js @@ -0,0 +1,26 @@ +import { dockUrl } from '../../utils/constants'; + +export default async (req, res) => { + if (req.method !== 'POST') { + console.log('Only post request allowed'); + res.status(400).json({}); + return; + } + + const result = await fetch(`${dockUrl}/proof-requests`, { + method: 'POST', + headers: { + 'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, + 'content-type': 'application/json', + }, + body: JSON.stringify(req.body), + }); + + const response = await result.json(); + if (!result.ok) { + const errorText = await result.text(); + throw new Error(`API Error: ${result.status} - ${errorText}`); + } + + res.status(202).send(response); +}; diff --git a/pages/api/get-oid4vp-url.js b/pages/api/get-oid4vp-url.js new file mode 100644 index 0000000..034f55e --- /dev/null +++ b/pages/api/get-oid4vp-url.js @@ -0,0 +1,29 @@ +import { dockUrl } from '../../utils/constants'; + +export default async (req, res) => { + if (req.method !== 'POST') { + console.log('Only post request allowed'); + res.status(400).json({}); + return; + } + + const result = await fetch(`${dockUrl}/openid/vp/${req.body.proofRequestId}/request-url`, { + method: 'POST', + headers: { + 'DOCK-API-TOKEN': `${process.env.DOCK_API_TOKEN}`, + 'content-type': 'application/json', + }, + body: JSON.stringify({ + ...req.body, + proofRequestId: undefined, + }), + }); + + const response = await result.json(); + if (!result.ok) { + const errorText = await result.text(); + throw new Error(`API Error: ${result.status} - ${errorText}`); + } + + res.status(202).send(response); +}; diff --git a/pages/mdl.js b/pages/mdl.js index d5fad50..d5418ff 100644 --- a/pages/mdl.js +++ b/pages/mdl.js @@ -6,7 +6,7 @@ import axios from 'axios'; import { Separator } from 'components/ui/separator'; import { Button } from 'components/ui/button'; import { QRCodeGenerator } from 'components/qrcode/qr-generator'; -import { apiGet, postRequest } from 'utils/request'; +import { apiGetLocal, postRequestLocal } from 'utils/request'; import { dockUrl } from 'utils/constants'; const baseUrl = process.env.NEXT_PUBLIC_DOCK_API_URL; @@ -80,17 +80,15 @@ function OID4VPProofRequest({ title, desc, proofRequestSetupObject, onPres, setE const [isVerified, setIsVerified] = useState(false); async function createProofRequest() { - const { data: proofRequest } = await postRequest(`${dockUrl}/proof-requests`, { + const { data: proofRequest } = await postRequestLocal('create-proof-request-object', { did: process.env.NEXT_PUBLIC_QUOTIENT_ISSUER_ID, ...proofRequestSetupObject, }); - const { data: qrUrlData } = await postRequest( - `${dockUrl}/openid/vp/${proofRequest.id}/request-url`, - { - withRequestURI: true, - } - ); + const { data: qrUrlData } = await postRequestLocal('get-oid4vp-url', { + withRequestURI: true, + proofRequestId: proofRequest.id, + }); setProofRequest({ ...proofRequest, @@ -99,7 +97,7 @@ function OID4VPProofRequest({ title, desc, proofRequestSetupObject, onPres, setE const int = setInterval(async () => { try { - const { data: res } = await apiGet(`${dockUrl}/proof-requests/${proofRequest.id}`); + const { data: res } = await apiGetLocal(`handle-proof?proofID=${proofRequest.id}`); if (res.verified) { setProofRequest(res); setIsVerified(true); diff --git a/pages/openid.js b/pages/openid.js index 0a53c0f..b82c736 100644 --- a/pages/openid.js +++ b/pages/openid.js @@ -1,13 +1,8 @@ -import OrganizationCard from 'components/org/organizationCard'; -import organizations from 'data/organizations'; import Image from 'next/image'; import React, { useEffect, useState } from 'react'; -import Link from 'next/link'; import { Separator } from 'components/ui/separator'; -import DemoFlow from 'components/demo-flow'; -import { Button } from 'components/ui/button'; import { QRCodeGenerator } from 'components/qrcode/qr-generator'; -import { apiGet, postRequest } from 'utils/request'; +import { apiGetLocal, postRequestLocal } from 'utils/request'; import { dockUrl } from 'utils/constants'; const credential = { @@ -154,17 +149,15 @@ function OID4VPProofRequest({ title, desc, proofRequestSetupObject }) { const [isVerified, setIsVerified] = useState(false); async function createProofRequest() { - const { data: proofRequest } = await postRequest(`${dockUrl}/proof-requests`, { + const { data: proofRequest } = await postRequestLocal('create-proof-request-object', { did: process.env.NEXT_PUBLIC_QUOTIENT_ISSUER_ID, ...proofRequestSetupObject, }); - const { data: qrUrlData } = await postRequest( - `${dockUrl}/openid/vp/${proofRequest.id}/request-url`, - { - withRequestURI: true, - } - ); + const { data: qrUrlData } = await postRequestLocal('get-oid4vp-url', { + withRequestURI: true, + proofRequestId: proofRequest.id, + }); setProofRequest({ ...proofRequest, @@ -173,7 +166,7 @@ function OID4VPProofRequest({ title, desc, proofRequestSetupObject }) { const int = setInterval(async () => { try { - const { data: res } = await apiGet(`${dockUrl}/proof-requests/${proofRequest.id}`); + const { data: res } = await apiGetLocal(`handle-proof?proofID=${proofRequest.id}`); if (res.verified) { setProofRequest(res); setIsVerified(true); @@ -245,7 +238,7 @@ export default function Home() { const [credentialOffer, setCredentialOffer] = useState(); async function createCredentialOffer() { - const { data: oidcIssuer } = await postRequest(`${dockUrl}/openid/issuers`, { + const { data: credentialOffer } = await postRequestLocal('create-credential-offer', { claimMap, credentialOptions: { credential: { @@ -257,15 +250,11 @@ export default function Home() { authProvider, }); - const { data: credentialOffer } = await postRequest(`${dockUrl}/openid/credential-offers`, { - id: oidcIssuer.id, - }); - setCredentialOffer(credentialOffer); } async function generateEBSIUrls() { - const { data: proofRequest } = await postRequest(`${dockUrl}/proof-requests`, { + const { data: proofRequest } = await postRequestLocal('create-proof-request-object', { did: process.env.NEXT_PUBLIC_QUOTIENT_ISSUER_ID, ...ebsiConformanceProofRequest, });