From 6f68fbab2711c33d479ed40e0d2e246141eee45e Mon Sep 17 00:00:00 2001 From: "Matt H." Date: Fri, 26 Jul 2024 15:45:29 -0500 Subject: [PATCH] refactor: Updating keymaster route names (#252) * updating route names * route updates * keymaster sdk route names update * exportDID update * updating ids/current route name --- src/kc-app/src/keymaster-sdk.js | 24 ++--- src/keymaster-api.js | 180 +++++++++++++++++++++++++++++--- 2 files changed, 180 insertions(+), 24 deletions(-) diff --git a/src/kc-app/src/keymaster-sdk.js b/src/kc-app/src/keymaster-sdk.js index a3ce26a9..d6bd9fef 100644 --- a/src/kc-app/src/keymaster-sdk.js +++ b/src/kc-app/src/keymaster-sdk.js @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { @@ -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) { diff --git a/src/keymaster-api.js b/src/keymaster-api.js index b3619ae5..f77283e0 100644 --- a/src/keymaster-api.js +++ b/src/keymaster-api.js @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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); @@ -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) => {