Skip to content

Commit

Permalink
Merge pull request #1251 from ajay-beehyv/HLM-638
Browse files Browse the repository at this point in the history
HLM-638 | Changes in verify certificate for revocation
  • Loading branch information
prasanna-egov authored Sep 21, 2022
2 parents c5b820f + c301770 commit 514bc32
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const sunbirdRegistryService = require('../services/sunbird.service')
const certifyConstants = require('../configs/constants');
const {validationResult} = require('express-validator');
const validationService = require('../services/validation.service');
const {truncateShard} = require("../utils/certification.utils");
const {truncateShard, extractFromArray} = require("../utils/certification.utils");

const REVOKED = "REVOKED";
const SUSPENDED = "SUSPENDED";
Expand Down Expand Up @@ -153,17 +153,19 @@ function getRevokeBody(req) {

async function verifyCertificate (req,res){
const certificate = req.body;
const certificateEntityType = certificate.evidence[0].type[0];
const revokeEntityType = certifyConstants.REVOKED_ENTITY_TYPE;
const token = req.header("Authorization");
let certificateId= certificate.credentialSubject.id;
let certificateStatus = "";
let msg = "";
console.log({certificateId: certificateId});
let body = {
const token = "";

const body = {
signedCredentials : certificate,
}
try{
const certificateEntityType = extractFromArray(extractFromArray(certificate.evidence).type);
const certificateId = extractFromArray(certificate.evidence).certificateId;
console.log({certificateEntityType: certificateEntityType, certificateId:certificateId });

const verifyResp = await sunbirdRegistryService.verifyCertificate(body)
if(verifyResp.verified){
const certificateResponse = await getEntity(certificateId,"certificateId",certificateEntityType,token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ router.get(`/certificate/:entityName/:certificateId`, authMiddleware, certificat
router.put(`/certify/:entityType`, authMiddleware, (req, res) => certificateController.updateCertificate(req, res, kafkaProducer));
router.post(`/certificate/revoke`, [authMiddleware, body(["entityName", "certificateId"], "Missing entityName or CertificateId in request body").exists()], certificateController.revokeCertificate);
router.delete(`/certificate/revoke/:entityName/:revokedCertificateId`, [authMiddleware, param([ "entityName","revokedCertificateId"], "Missing entityName or Revoked CertificateId in request body").exists()], (req, res) => certificateController.deleteRevokeCertificate(req, res, kafkaProducer));
router.post(`/certificate/verify`, authMiddleware, certificateController.verifyCertificate);
router.post(`/certificate/verify`, certificateController.verifyCertificate);
module.exports = {certifyRouter: router, setKafkaProducer}
12 changes: 10 additions & 2 deletions backend/vc-certification-service/src/utils/certification.utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
const truncateShard = (osId) => {
return osId?.substring(2);
}

const extractFromArray = (object) => {
if (object) {
object = Array.isArray(object) ? object[0] : object;
} else {
throw new CustomError(`${object} not available`, 400).error();
}
return object;
}
module.exports = {
truncateShard
truncateShard,
extractFromArray
}

0 comments on commit 514bc32

Please sign in to comment.