Skip to content

Commit

Permalink
refactor: Updating keymaster route names (#252)
Browse files Browse the repository at this point in the history
* updating route names

* route updates

* keymaster sdk route names update

* exportDID update

* updating ids/current route name
  • Loading branch information
howitworks18 authored Jul 26, 2024
1 parent cf2c41f commit 6f68fba
Show file tree
Hide file tree
Showing 2 changed files with 180 additions and 24 deletions.
24 changes: 12 additions & 12 deletions src/kc-app/src/keymaster-sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function saveWallet(wallet) {

export async function newWallet(mnemonic, overwrite = false) {
try {
const response = await axios.post(`/api/v1/wallet`, { mnemonic, overwrite });
const response = await axios.post(`/api/v1/wallet/new`, { mnemonic, overwrite });
return response.data;
}
catch (error) {
Expand All @@ -40,7 +40,7 @@ export async function newWallet(mnemonic, overwrite = false) {

export async function backupWallet() {
try {
const response = await axios.post(`/api/v1/backup-wallet`);
const response = await axios.post(`/api/v1/wallet/backup`);
return response.data;
}
catch (error) {
Expand All @@ -50,7 +50,7 @@ export async function backupWallet() {

export async function recoverWallet() {
try {
const response = await axios.post(`/api/v1/recover-wallet`);
const response = await axios.post(`/api/v1/wallet/recover`);
return response.data;
}
catch (error) {
Expand All @@ -60,7 +60,7 @@ export async function recoverWallet() {

export async function checkWallet() {
try {
const response = await axios.post(`/api/v1/check-wallet`);
const response = await axios.post(`/api/v1/wallet/check`);
return response.data;
}
catch (error) {
Expand All @@ -70,7 +70,7 @@ export async function checkWallet() {

export async function fixWallet() {
try {
const response = await axios.post(`/api/v1/fix-wallet`);
const response = await axios.post(`/api/v1/wallet/fix`);
return response.data;
}
catch (error) {
Expand Down Expand Up @@ -100,7 +100,7 @@ export async function listRegistries() {

export async function getCurrentId() {
try {
const response = await axios.get(`/api/v1/current-id`);
const response = await axios.get(`/api/v1/ids/current`);
return response.data;
}
catch (error) {
Expand All @@ -110,7 +110,7 @@ export async function getCurrentId() {

export async function setCurrentId(name) {
try {
const response = await axios.put(`/api/v1/current-id`, { name: name });
const response = await axios.put(`/api/v1/ids/current`, { name: name });
return response.data;
}
catch (error) {
Expand Down Expand Up @@ -140,7 +140,7 @@ export async function resolveId(id) {

export async function createId(name, registry) {
try {
const response = await axios.post(`/api/v1/ids`, { name: name, registry: registry });
const response = await axios.post(`/api/v1/ids/new`, { name: name, registry: registry });
return response.data;
}
catch (error) {
Expand Down Expand Up @@ -170,7 +170,7 @@ export async function backupId(id) {

export async function recoverId(did) {
try {
const response = await axios.post(`/api/v1/recover-id`, { did: did });
const response = await axios.post(`/api/v1/ids/recover`, { did: did });
return response.data;
}
catch (error) {
Expand Down Expand Up @@ -240,7 +240,7 @@ export async function createResponse(challengeDID) {

export async function verifyResponse(responseDID, challengeDID) {
try {
const response = await axios.post(`/api/v1/verify-response`, { response: responseDID, challenge: challengeDID });
const response = await axios.post(`/api/v1/response/verify`, { response: responseDID, challenge: challengeDID });
return response.data;
}
catch (error) {
Expand Down Expand Up @@ -350,7 +350,7 @@ export async function testAgent(id) {

export async function bindCredential(schema, subject) {
try {
const response = await axios.post(`/api/v1/bind-credential`, { schema, subject });
const response = await axios.post(`/api/v1/credentials/bind`, { schema, subject });
return response.data;
}
catch (error) {
Expand All @@ -360,7 +360,7 @@ export async function bindCredential(schema, subject) {

export async function issueCredential(credential, registry) {
try {
const response = await axios.post(`/api/v1/issue-credential`, { credential, registry });
const response = await axios.post(`/api/v1/credentials/issue`, { credential, registry });
return response.data;
}
catch (error) {
Expand Down
180 changes: 168 additions & 12 deletions src/keymaster-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ v1router.put('/wallet', async (req, res) => {
}
});

v1router.post('/wallet', async (req, res) => {
v1router.post('/wallet/new', async (req, res) => {
try {
const { mnemonic, overwrite } = req.body;
const wallet = keymaster.newWallet(mnemonic, overwrite);
Expand All @@ -64,7 +64,7 @@ v1router.post('/wallet', async (req, res) => {
}
});

v1router.post('/backup-wallet', async (req, res) => {
v1router.post('/wallet/backup', async (req, res) => {
try {
const response = await keymaster.backupWallet();
res.json(response);
Expand All @@ -73,7 +73,7 @@ v1router.post('/backup-wallet', async (req, res) => {
}
});

v1router.post('/recover-wallet', async (req, res) => {
v1router.post('/wallet/recover', async (req, res) => {
try {
const response = await keymaster.recoverWallet();
res.json(response);
Expand All @@ -82,7 +82,7 @@ v1router.post('/recover-wallet', async (req, res) => {
}
});

v1router.post('/check-wallet', async (req, res) => {
v1router.post('/wallet/check', async (req, res) => {
try {
const response = await keymaster.checkWallet();
res.json(response);
Expand All @@ -91,7 +91,7 @@ v1router.post('/check-wallet', async (req, res) => {
}
});

v1router.post('/fix-wallet', async (req, res) => {
v1router.post('/wallet/fix', async (req, res) => {
try {
const response = await keymaster.fixWallet();
res.json(response);
Expand All @@ -109,7 +109,7 @@ v1router.get('/mnemonic', async (req, res) => {
}
});

v1router.get('/current-id', async (req, res) => {
v1router.get('/ids/current', async (req, res) => {
try {
const current = keymaster.getCurrentId();
res.json(current);
Expand All @@ -118,7 +118,7 @@ v1router.get('/current-id', async (req, res) => {
}
});

v1router.put('/current-id', async (req, res) => {
v1router.put('/ids/current', async (req, res) => {
try {
const { name } = req.body;
keymaster.setCurrentId(name);
Expand All @@ -137,7 +137,7 @@ v1router.get('/ids', async (req, res) => {
}
});

v1router.post('/ids', async (req, res) => {
v1router.post('/ids/new', async (req, res) => {
try {
const { name, registry } = req.body;
const did = await keymaster.createId(name, registry);
Expand Down Expand Up @@ -174,7 +174,7 @@ v1router.post('/ids/:id/backup', async (req, res) => {
}
});

v1router.post('/recover-id', async (req, res) => {
v1router.post('/ids/recover', async (req, res) => {
try {
const { did } = req.body;
const response = await keymaster.recoverId(did);
Expand Down Expand Up @@ -249,7 +249,7 @@ v1router.post('/response', async (req, res) => {
}
});

v1router.post('/verify-response', async (req, res) => {
v1router.post('/response/verify', async (req, res) => {
try {
const { response, challenge } = req.body;
const verify = await keymaster.verifyResponse(response, challenge);
Expand Down Expand Up @@ -355,7 +355,7 @@ v1router.post('/agents/:id/test', async (req, res) => {
}
});

v1router.post('/bind-credential', async (req, res) => {
v1router.post('/credentials/bind', async (req, res) => {
try {
const { schema, subject } = req.body;
const response = await keymaster.bindCredential(schema, subject);
Expand All @@ -365,7 +365,7 @@ v1router.post('/bind-credential', async (req, res) => {
}
});

v1router.post('/issue-credential', async (req, res) => {
v1router.post('/credentials/issue', async (req, res) => {
try {
const { credential, registry } = req.body;
const response = await keymaster.issueCredential(credential, registry);
Expand Down Expand Up @@ -462,6 +462,162 @@ v1router.delete('/issued/:did', async (req, res) => {
}
});

v1router.get('/dids/:did/export', async (req, res) => {
try {
const response = await keymaster.exportDID(req.params.did);
res.json(response);
} catch (error) {
res.status(500).send(error.toString());
}
});

v1router.post('/batch/import', async (req, res) => {
try {
const response = await keymaster.importBatch(req.body.ops);
res.json(response);
} catch (error) {
res.status(500).send(error.toString());
}
});

v1router.post('/keys/rotate', async (req, res) => {
try {
const response = await keymaster.rotateKeys();
res.json(response);
} catch (error) {
res.status(500).send(error.toString());
}
});

v1router.post('/encrypt', async (req, res) => {
try {
const { msg, did } = req.body;
const response = await keymaster.encrypt(msg, did);
res.json(response);
} catch (error) {
res.status(500).send(error.toString());
}
});

v1router.post('/decrypt', async (req, res) => {
try {
const response = await keymaster.decrypt(req.body.did);
res.json(response);
} catch (error) {
res.status(500).send(error.toString());
}
});

v1router.post('/signature/add', async (req, res) => {
try {
const response = await keymaster.addSignature(JSON.parse(req.body.contents));
res.json(response);
} catch (error) {
res.status(500).send(error.toString());
}
});

v1router.post('/signature/verify', async (req, res) => {
try {
const response = await keymaster.verifySignature(req.body.json);
res.json(response);
} catch (error) {
res.status(500).send(error.toString());
}
});

v1router.post('/credentials/create', async (req, res) => {
try {
const response = await keymaster.createCredential(req.body.schema);
res.json(response);
} catch (error) {
res.status(500).send(error.toString());
}
});

v1router.post('/template/create', async (req, res) => {
try {
const response = await keymaster.createTemplate(req.body.schema);
res.json(response);
} catch (error) {
res.status(500).send(error.toString());
}
});

v1router.post('/asset/create', async (req, res) => {
try {
const response = await keymaster.createAsset(req.body.asset);
res.json(response);
} catch (error) {
res.status(500).send(error.toString());
}
});

v1router.get('/templates/poll', async (req, res) => {
try {
const response = await keymaster.pollTemplate();
res.json(response);
} catch (error) {
res.status(500).send(error.toString());
}
});

v1router.post('/poll/create', async (req, res) => {
try {
const response = await keymaster.createPoll(req.body.poll);
res.json(response);
} catch (error) {
res.status(500).send(error.toString());
}
});

v1router.get('/poll/:poll/view', async (req, res) => {
try {
const response = await keymaster.viewPoll(req.params.poll);
res.json(response);
} catch (error) {
res.status(500).send(error.toString());
}
});

v1router.post('/poll/vote', async (req, res) => {
try {
const { poll, vote, spoil } = req.body;
const response = await keymaster.votePoll(poll, vote, spoil);
res.json(response);
} catch (error) {
res.status(500).send(error.toString());
}
});

v1router.put('/poll/update', async (req, res) => {
try {
const response = await keymaster.updatePoll(req.body.ballot);
res.json(response);
} catch (error) {
res.status(500).send(error.toString());
}
});

v1router.post('/poll/:poll/publish', async (req, res) => {
try {
const reveal = req.body.reveal || false;
const response = await keymaster.publishPoll(req.params.poll, reveal);
res.json(response);
} catch (error) {
res.status(500).send(error.toString());
}
});

v1router.delete('/poll/:poll/unpublish', async (req, res) => {
try {
const response = await keymaster.unpublishPoll(req.params.poll);
res.json(response);
} catch (error) {
res.status(500).send(error.toString());
}
});

app.use('/api/v1', v1router);

app.use((req, res) => {
Expand Down

0 comments on commit 6f68fba

Please sign in to comment.