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

feat: Revoke feature implementation #33

Merged
merged 1 commit into from
Mar 18, 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
60 changes: 30 additions & 30 deletions src/controller/credential_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Cred } from '../entity/Cred';
import { Schema } from '../entity/Schema';
const { CHAIN_SPACE_ID, CHAIN_SPACE_AUTH } = process.env;

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

if (!authorIdentity) {
Expand Down Expand Up @@ -78,11 +78,10 @@ export async function issueVD(req: express.Request, res: express.Response) {

const cred = new Cred();
cred.schemaId = req.params.id;
cred.identifier = statement;
cred.identifier = vc.proof[1].identifier;
cred.active = true;
cred.fromDid = issuerDid.uri;
cred.credHash = newCredContent.credentialHash;
cred.newCredContent = newCredContent;
cred.vc = vc;

if (statement) {
Expand Down Expand Up @@ -206,9 +205,8 @@ export async function updateCred(req: express.Request, res: express.Response) {
console.log(`✅ UpdatedStatement element registered - ${updatedStatement}`);

if (updatedStatement) {
cred.identifier = updatedStatement;
cred.identifier = updatedVc.proof[1].identifier;
cred.credHash = updatedCredContent.credentialHash;
cred.newCredContent = updatedCredContent;
cred.vc = updatedVc;

await getConnection().manager.save(cred);
Expand All @@ -228,29 +226,31 @@ export async function updateCred(req: express.Request, res: express.Response) {
}

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.vc[1].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 });
// }
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.vc.proof[1].elementUri as `stmt:cord:${string}`,
delegateDid.uri,
authorIdentity,
delegateSpaceAuth as Cord.AuthorizationUri,
async ({ data }) => ({
signature: delegateKeysProperty.authentication.sign(data),
keyType: delegateKeysProperty.authentication.type,
})
);

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 });
}
}
3 changes: 0 additions & 3 deletions src/entity/Cred.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ export class Cred {
@Column()
credHash?: string;

@Column('simple-json', { nullable: true, default: null })
newCredContent?: any;

@Column('simple-json', { nullable: true, default: null })
vc?: any;

Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { dbConfig } from './dbconfig';
import { addDelegateAsRegistryDelegate } from './init';
import {
getCredById,
issueVD,
issueVC,
revokeCred,
updateCred,
} from './controller/credential_controller';
Expand All @@ -24,7 +24,7 @@ const credentialRouter = express.Router({ mergeParams: true });
const schemaRouter = express.Router({ mergeParams: true });

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

credentialRouter.get('/:id', async (req, res) => {
Expand Down
Loading