Skip to content

Commit

Permalink
Switch type to types in accreditedFor
Browse files Browse the repository at this point in the history
  • Loading branch information
DaevMithran committed Oct 16, 2024
1 parent a5100dc commit abb06f7
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 17 deletions.
17 changes: 9 additions & 8 deletions src/controllers/api/accreditation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
RevokeAccreditationRequestBody,
RevokeAccreditationRequestQuery,
RevokeAccreditationResponseBody,
SchemaUrlType,
SuspendAccreditationRequestBody,
SuspendAccreditationRequestQuery,
SuspendAccreditationResponseBody,
Expand Down Expand Up @@ -45,9 +46,9 @@ export class AccreditationController {
body('subjectDid').exists().isDID().bail(),
body('schemas').exists().isArray().withMessage('schemas must be a array').bail(),
body('schemas.*.url').isString().withMessage('schema urls must be a string').bail(),
body('schemas.*.type')
body('schemas.*.types')
.custom((value) => typeof value === 'string' || (Array.isArray(value) && typeof value[0] === 'string'))
.withMessage('schema type must be a string'),
.withMessage('schema.types must be a string or a string array'),
body('parentAccreditation').optional().isString().withMessage('parentAccreditation must be a string').bail(),
body('rootAuthorisation').optional().isString().withMessage('rootAuthorisation must be a string').bail(),
body('trustFramework').optional().isString().withMessage('trustFramework must be a string').bail(),
Expand Down Expand Up @@ -96,9 +97,9 @@ export class AccreditationController {
body('resourceType').optional().isString().withMessage('resourceType should be a string').bail(),
body('schemas').optional().isArray().withMessage('schemas must be a array').bail(),
body('schemas.*.url').isString().withMessage('schema urls must be a string').bail(),
body('schemas.*.type')
body('schemas.*.types')
.custom((value) => typeof value === 'string' || (Array.isArray(value) && typeof value[0] === 'string'))
.withMessage('schema type must be a string'),
.withMessage('schema.types must be a string or a string array'),
body('did')
.custom((value, { req }) => {
const { didUrl, resourceId, resourceName, resourceType } = req.body;
Expand Down Expand Up @@ -236,9 +237,9 @@ export class AccreditationController {
}

const resourceId = v4();
const accreditedFor = schemas.map(({ url, type }: any) => ({
const accreditedFor = schemas.map(({ url, types }: SchemaUrlType) => ({
schemaId: url,
type,
types: Array.isArray(types) ? types : [types],
}));

// construct credential request
Expand Down Expand Up @@ -402,9 +403,9 @@ export class AccreditationController {
}

try {
const accreditedFor = schemas?.map(({ url, type }: any) => ({
const accreditedFor = schemas?.map(({ url, types }: SchemaUrlType) => ({
schemaId: url,
type,
types: Array.isArray(types) ? types : [types],
}));

const result = await AccreditationService.instance.verify_accreditation(
Expand Down
4 changes: 3 additions & 1 deletion src/services/api/accreditation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export class AccreditationService {
if (
!accreditedFor.every((schema) =>
accreditation.credentialSubject.accreditedFor.some(
(accredited) => accredited.type === schema.type && accredited.schemaId === schema.schemaId
(accredited) =>
schema.types.every((value) => (accredited.types || []).includes(value)) &&
accredited.schemaId === schema.schemaId
)
)
) {
Expand Down
4 changes: 2 additions & 2 deletions src/types/accreditation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ export enum AccreditationRequestType {
}

export type AccreditationSchemaType = {
type: string;
types: string[];
schemaId: string;
};

export type SchemaUrlType = {
type: string;
types: string[] | string;
url: string;
};

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/payloads/accreditation/accredit-jwt.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"schemas": [
{
"url": "https://schema.org/Person",
"type": "Person"
"types": "Person"
}
],
"format": "jwt",
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/payloads/accreditation/attest-jwt.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"schemas": [
{
"url": "https://schema.org/Person",
"type": "Person"
"types": "Person"
}
],
"format": "jwt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"schemas": [
{
"url": "https://schema.org/Learn",
"type": "Learn"
"types": "Learn"
}
],
"accreditationName": "revocationAccreditation",
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/payloads/accreditation/authorise-jwt.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"schemas": [
{
"url": "https://schema.org/Person",
"type": "Person"
"types": "Person"
}
],
"format": "jwt",
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/payloads/accreditation/child-accredit-jwt.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"schemas": [
{
"url": "https://schema.org/Person",
"type": "Person"
"types": "Person"
}
],
"format": "jwt",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"schemas": [
{
"url": "https://schema.org/Event",
"type": "Event"
"types": "Event"
}
],
"format": "jwt",
Expand Down

0 comments on commit abb06f7

Please sign in to comment.