Skip to content

Commit

Permalink
Merge pull request #44 from docknetwork/fix/api-routes-not-bundled
Browse files Browse the repository at this point in the history
Add individual API proxy routes instead of bundled into one
  • Loading branch information
cykoder authored Sep 26, 2024
2 parents 799fa81 + d5bc904 commit 6259e9a
Show file tree
Hide file tree
Showing 24 changed files with 335 additions and 234 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 0 additions & 3 deletions _credentials/equinet.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 0 additions & 2 deletions _credentials/forsur.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { v4 as uuidv4 } from 'uuid';
import { dockUrl } from 'utils/constants';
import { validateEmail } from 'utils/validation';

export function createBiometricsCredential({
Expand All @@ -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',
Expand Down
2 changes: 0 additions & 2 deletions _credentials/quotient.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { v4 as uuidv4 } from 'uuid';
import { dockUrl } from 'utils/constants';
import { validateEmail } from 'utils/validation';

export function createBankIdCredential({
Expand All @@ -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',
Expand Down
6 changes: 0 additions & 6 deletions hooks/useRevoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
44 changes: 44 additions & 0 deletions pages/api/create-credential-offer.js
Original file line number Diff line number Diff line change
@@ -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);
};
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
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 body = req.body;

console.log('body::', body);

const result = await fetch(body.url, {
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(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}`);
Expand Down
30 changes: 30 additions & 0 deletions pages/api/create-proof-request.js
Original file line number Diff line number Diff line change
@@ -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);
};
26 changes: 26 additions & 0 deletions pages/api/create-registry.js
Original file line number Diff line number Diff line change
@@ -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}/registries`, {
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);
};
29 changes: 29 additions & 0 deletions pages/api/find-registry.js
Original file line number Diff line number Diff line change
@@ -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);
};
7 changes: 3 additions & 4 deletions pages/api/handle-get.js → pages/api/get-job.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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 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}`,
Expand All @@ -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();
Expand Down
29 changes: 29 additions & 0 deletions pages/api/get-oid4vp-url.js
Original file line number Diff line number Diff line change
@@ -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);
};
39 changes: 39 additions & 0 deletions pages/api/issue-biometric.js
Original file line number Diff line number Diff line change
@@ -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);
};
26 changes: 26 additions & 0 deletions pages/api/issue-credential.js
Original file line number Diff line number Diff line change
@@ -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);
};
29 changes: 29 additions & 0 deletions pages/api/revoke-action.js
Original file line number Diff line number Diff line change
@@ -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);
};
Loading

0 comments on commit 6259e9a

Please sign in to comment.