Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revoke given statement #26

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
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
86 changes: 40 additions & 46 deletions src/controller/credential_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ export async function getCredById(req: express.Request, res: express.Response) {
export async function updateCred(req: express.Request, res: express.Response) {
const data = req.body;

if (!data.property || typeof data.property !== 'object') {
return res.status(400).json({
error: '"property" is a required field and should be an object',
});
}

try {
const cred = await getConnection()
.getRepository(Cred)
Expand Down Expand Up @@ -170,7 +176,7 @@ export async function updateCred(req: express.Request, res: express.Response) {

await getConnection().manager.save(cred);

console.log('\n✅ Document updated!');
console.log('\n✅ Statement updated!');

return res.status(200).json({
result: 'Updated successufully',
Expand All @@ -184,48 +190,36 @@ export async function updateCred(req: express.Request, res: express.Response) {
}
}

// export async function revokeCred(req: express.Request, res: express.Response) {
// const data = req.body;

// if (!data.identifier || typeof data.identifier !== 'string') {
// return res.status(400).json({
// error: 'identifier is a required field and should be a string',
// });
// }

// if (!issuerDid) {
// await setupDidAndIdentities();
// }

// const cred = await getConnection()
// .getRepository(Cred)
// .createQueryBuilder('cred')
// .where('cred.identifier = :identifier', { identifier: data.identifier })
// .getOne();

// if (!cred) {
// return res.status(400).json({ error: 'Invalid identifier' });
// }

// try {
// const document = JSON.parse(cred.credential!) as IDocument;

// await revokeCredential(
// issuerDid.uri,
// authorIdentity,
// async ({ data }) => ({
// signature: issuerKeys.assertionMethod.sign(data),
// keyType: issuerKeys.assertionMethod.type,
// }),
// document,
// false
// );

// console.log(`✅ Credential revoked!`);

// return res.status(200).json({ result: 'Revoked Successfully' });
// } catch (error) {
// console.log('err: ', error);
// return res.status(400).json({ err: error });
// }
// }
export async function revokeCred(req: express.Request, res: express.Response) {
try {
const cred = await getConnection()
.getRepository(Cred)
.findOne({ identifier: req.params.id });

if (!cred) {
return res.status(400).json({ error: 'Invalid identifier' });
}

await Cord.Statement.dispatchRevokeToChain(
cred.credentialEntry.elementUri,
delegateDid.uri,
authorIdentity,
delegateSpaceAuth as Cord.AuthorizationUri,
async ({ data }) => ({
signature: delegateKeysProperty.authentication.sign(data),
keyType: delegateKeysProperty.authentication.type,
})
);

cred.active = false;

await getConnection().manager.save(cred);

console.log(`✅ Statement revoked!`);

return res.status(200).json({ result: 'Statement revoked Successfully' });
} catch (error) {
console.log('err: ', error);
return res.status(400).json({ err: error });
}
}
13 changes: 9 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { createSchema, getSchemaById } from './controller/schema_controller';
import { createConnection } from 'typeorm';
import { dbConfig } from './dbconfig';
import { addDelegateAsRegistryDelegate } from './init';
import { getCredById, issueVD, updateCred } from './controller/credential_controller';
import {
getCredById,
issueVD,
revokeCred,
updateCred,
} from './controller/credential_controller';

const app = express();
export const { PORT } = process.env;
Expand All @@ -30,9 +35,9 @@ credentialRouter.put('/update/:id', async (req, res) => {
return await updateCred(req, res);
});

// credentialRouter.post('/revoke', async (req, res) => {
// return await revokeCred(req, res);
// });
credentialRouter.post('/revoke/:id', async (req, res) => {
return await revokeCred(req, res);
});

schemaRouter.post('/', async (req, res) => {
return await createSchema(req, res);
Expand Down
Loading