Skip to content

Commit

Permalink
Support credential status in issue
Browse files Browse the repository at this point in the history
  • Loading branch information
DaevMithran committed Oct 8, 2024
1 parent b4002fd commit 8415ff5
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/controllers/api/accreditation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export class AccreditationController {
attributes,
accreditationName,
format,
credentialStatus,
} = request.body as DIDAccreditationRequestBody;

try {
Expand Down Expand Up @@ -253,6 +254,7 @@ export class AccreditationController {
connector: CredentialConnectors.Resource, // resource connector
credentialId: resourceId,
credentialName: accreditationName,
credentialStatus,
};

let resourceType: string;
Expand Down
12 changes: 10 additions & 2 deletions src/static/swagger-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,19 @@
]
},
"parentAccreditation": {
"description": "DID Url of the parent Verifiable Accreditation.",
"description": "DID Url of the parent Verifiable Accreditation, required for accredit/attest operation.",
"type": "string"
},
"rootAuthorization": {
"description": "DID Url of the root Verifiable Accreditation.",
"description": "DID Url of the root Verifiable Accreditation, required for accredit/attest operation.",
"type": "string"
},
"trustFramework": {
"description": "Name or Type of the Trust Framework, required for authorize operation.",
"type": "string"
},
"trustFrameworkId": {
"description": "Url of the Trust Framework, required for authorize operation.",
"type": "string"
},
"type": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"type": "Learn"
}
],
"accreditationName": "authorizeAccreditation",
"accreditationName": "revocationAccreditation",
"trustFrameworkId": "https://learn.cheqd.io/governance/start",
"trustFramework": "cheqd Governance Framework"
}
10 changes: 6 additions & 4 deletions tests/e2e/sequential/accreditation/revocation-flow.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { VerifiableCredential } from '@veramo/core';
import * as fs from 'fs';
import { test, expect } from '@playwright/test';
import { StatusCodes } from 'http-status-codes';
import { CONTENT_TYPE, PAYLOADS_PATH } from '../../constants';

test.use({ storageState: 'playwright/.auth/user.json' });

let didUrl: string;

const didUrl: string = `did:cheqd:testnet:5RpEg66jhhbmASWPXJRWrA?resourceName=revocationAccreditation&resourceType=VerifiableAuthorisationForTrustChain`;
const subjectDid: string = 'did:cheqd:testnet:15b74787-6e48-4fd5-8020-eab24e990578';
test(' Issue an Accreditation with revocation statuslist', async ({ request }) => {
const payload = JSON.parse(
fs.readFileSync(`${PAYLOADS_PATH.ACCREDITATION}/authorize-jwt-revocation.json`, 'utf-8')
Expand All @@ -19,7 +18,7 @@ test(' Issue an Accreditation with revocation statuslist', async ({ request }) =
},
});
const { didUrls, accreditation } = await issueResponse.json();
didUrl = didUrls[0];
expect(didUrls).toContain(didUrl);
expect(issueResponse).toBeOK();
expect(issueResponse.status()).toBe(StatusCodes.OK);
expect(accreditation.proof.type).toBe('JwtProof2020');
Expand All @@ -41,6 +40,7 @@ test(" Verify a Accreditation's revocation status", async ({ request }) => {
const response = await request.post(`/trust-registry/accreditation/verify?verifyStatus=true`, {
data: JSON.stringify({
didUrl,
subjectDid,
}),
headers: {
'Content-Type': CONTENT_TYPE.APPLICATION_JSON,
Expand All @@ -57,6 +57,7 @@ test(' Verify a Accreditation status after revocation', async ({ request }) => {
const response = await request.post(`/trust-registry/accreditation/revoke?publish=true`, {
data: JSON.stringify({
didUrl,
subjectDid,
}),
headers: {
'Content-Type': CONTENT_TYPE.APPLICATION_JSON,
Expand All @@ -71,6 +72,7 @@ test(' Verify a Accreditation status after revocation', async ({ request }) => {
const verificationResponse = await request.post(`/trust-registry/accreditation/verify?verifyStatus=true`, {
data: JSON.stringify({
didUrl,
subjectDid,
}),
headers: {
'Content-Type': CONTENT_TYPE.APPLICATION_JSON,
Expand Down
119 changes: 119 additions & 0 deletions tests/e2e/sequential/accreditation/suspension-flow.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { test, expect } from '@playwright/test';
import { StatusCodes } from 'http-status-codes';
import * as fs from 'fs';
import { CONTENT_TYPE, PAYLOADS_PATH } from '../../constants';

test.use({ storageState: 'playwright/.auth/user.json' });

const didUrl: string = `did:cheqd:testnet:5RpEg66jhhbmASWPXJRWrA?resourceName=suspensionAccreditation&resourceType=VerifiableAuthorisationForTrustChain`;
const subjectDid: string = 'did:cheqd:testnet:15b74787-6e48-4fd5-8020-eab24e990578';

test(' Issue a jwt accreditation with suspension statuslist', async ({ request }) => {
const payload = JSON.parse(
fs.readFileSync(`${PAYLOADS_PATH.ACCREDITATION}/authorize-jwt-revocation.json`, 'utf-8')
);
payload.credentialStatus.statusPurpose = 'suspension';
payload.accreditationName = 'suspensionAccreditation';
const issueResponse = await request.post(`/trust-registry/accreditation/issue?accreditationType=authorize`, {
data: JSON.stringify(payload),
headers: {
'Content-Type': CONTENT_TYPE.APPLICATION_JSON,
},
});
const { didUrls, accreditation } = await issueResponse.json();
expect(didUrls).toContain(didUrl);
expect(issueResponse.status()).toBe(StatusCodes.OK);
expect(accreditation.proof.type).toBe('JwtProof2020');
expect(accreditation.proof).toHaveProperty('jwt');
expect(typeof accreditation.issuer === 'string' ? accreditation.issuer : accreditation.issuer.id).toBe(
payload.issuerDid
);
expect(accreditation.type).toContain('VerifiableCredential');
expect(accreditation.credentialSubject.id).toBe(payload.subjectDid);
expect(accreditation.credentialStatus).toMatchObject({
type: 'StatusList2021Entry',
statusPurpose: 'suspension',
});
expect(accreditation.credentialStatus).toHaveProperty('statusListIndex');
expect(accreditation.credentialStatus).toHaveProperty('id');
});

test(" Verify a Accreditation's suspension status", async ({ request }) => {
const response = await request.post(`/trust-registry/accreditation/verify?verifyStatus=true`, {
data: JSON.stringify({
didUrl,
subjectDid,
}),
headers: {
'Content-Type': CONTENT_TYPE.APPLICATION_JSON,
},
});
const result = await response.json();
expect(response).toBeOK();
expect(response.status()).toBe(StatusCodes.OK);
expect(result.verified).toBe(true);
expect(result.suspended).toBe(false);
});

test(' Verify a credential status after suspension', async ({ request }) => {
const response = await request.post(`/trust-registry/accreditation/suspend?publish=true`, {
data: JSON.stringify({
didUrl,
subjectDid,
}),
headers: {
'Content-Type': CONTENT_TYPE.APPLICATION_JSON,
},
});
const result = await response.json();
expect(response).toBeOK();
expect(response.status()).toBe(StatusCodes.OK);
expect(result.suspended).toBe(true);
expect(result.published).toBe(true);

const verificationResponse = await request.post(`/trust-registry/accreditation/verify?verifyStatus=true`, {
data: JSON.stringify({
didUrl,
subjectDid,
}),
headers: {
'Content-Type': CONTENT_TYPE.APPLICATION_JSON,
},
});
const verificationResult = await verificationResponse.json();
expect(verificationResponse).toBeOK();
expect(verificationResponse.status()).toBe(StatusCodes.OK);
expect(verificationResult.verified).toBe(true);
expect(verificationResult.suspended).toBe(true);
});

test(' Verify a accreditation status after reinstating', async ({ request }) => {
const response = await request.post(`/trust-registry/accreditation/reinstate?publish=true`, {
data: JSON.stringify({
didUrl,
subjectDid,
}),
headers: {
'Content-Type': CONTENT_TYPE.APPLICATION_JSON,
},
});
const result = await response.json();
expect(response).toBeOK();
expect(response.status()).toBe(StatusCodes.OK);
expect(result.unsuspended).toBe(true);

const verificationResponse = await request.post(`/trust-registry/accreditation/verify?verifyStatus=true`, {
data: JSON.stringify({
didUrl,
subjectDid,
}),
headers: {
'Content-Type': CONTENT_TYPE.APPLICATION_JSON,
},
});
const verificationResult = await verificationResponse.json();
expect(verificationResponse).toBeOK();
expect(verificationResponse.status()).toBe(StatusCodes.OK);
expect(verificationResult.verified).toBe(true);
expect(verificationResult.suspended).toBe(false);
});

0 comments on commit 8415ff5

Please sign in to comment.