Skip to content

Commit

Permalink
fix: DID update in chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
DaevMithran committed Jul 3, 2023
1 parent d2949b7 commit 24ee606
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 33 deletions.
12 changes: 6 additions & 6 deletions src/controllers/issuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class IssuerController {

try {

const { did, service, verificationMethod, authentication } = request.body as { did: string, service: Service, verificationMethod: VerificationMethod, authentication: string }
const { did, service, verificationMethod, authentication } = request.body as { did: string, service: Service[], verificationMethod: VerificationMethod[], authentication: string[] }
let updatedDocument: DIDDocument
if (request.body.didDocument) {
updatedDocument = request.body.didDocument
Expand All @@ -146,14 +146,14 @@ export class IssuerController {
})
}
const resolvedDocument = resolvedResult.didDocument
if (service && isValidService(service)) {
resolvedDocument.service = resolvedDocument.service ? resolvedDocument.service.concat(service) : [service]
if (service) {
resolvedDocument.service = Array.isArray(service) ? service : [service]
}
if (verificationMethod && isValidVerificationMethod(verificationMethod)) {
resolvedDocument.verificationMethod?.push(verificationMethod)
if (verificationMethod) {
resolvedDocument.verificationMethod = Array.isArray(verificationMethod) ? verificationMethod : [verificationMethod]
}
if (authentication) {
resolvedDocument.authentication = resolvedDocument.authentication ? resolvedDocument.authentication.concat(authentication) : [authentication]
resolvedDocument.authentication = Array.isArray(authentication) ? authentication : [authentication]
}

updatedDocument = resolvedDocument
Expand Down
9 changes: 7 additions & 2 deletions src/controllers/revocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ export class RevocationController {

static updateValidator = [
check('index').optional().isNumeric().withMessage('index should be a number'),
check('indices').custom((value, {req})=>!(value && req.body.index))
.withMessage('Either an index or list of indices should be provided'),
check('indices').custom((value, {req})=>{
if(value) {
return Array.isArray(value)
} else {
return req.body.index
}
}).withMessage('Either an index or an array of indices should be provided'),
check('statusListName').exists().withMessage('StatusListName is required').isString(),
check('statusListVerion').optional().isString().withMessage('Invalid statusListVersion'),
query('statusAction').exists().withMessage('StatusAction is required')
Expand Down
3 changes: 1 addition & 2 deletions src/middleware/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ export class Middleware {
if (request.body[key] === '') {
request.body[key] = undefined
} else {
request.body[key] = JSON.parse(request.body[key])

if (typeof request.body[key] === 'string' && request.body[key].includes(',')) {
// Check if the value contains commas
request.body[key] = request.body[key].split(',')
}
request.body[key] = JSON.parse(request.body[key])
}
} catch (error) {
// Failed to parse the value as JSON, leave it as is
Expand Down
11 changes: 6 additions & 5 deletions src/services/identity/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
IAgentPlugin,
ICreateVerifiableCredentialArgs,
IDIDManager,
IDIDManagerDeleteArgs,
IDIDManagerUpdateArgs,
IIdentifier,
IKeyManager,
IResolver,
Expand Down Expand Up @@ -332,7 +330,8 @@ export class Veramo {
statusListVersion: statusOptions.statusListVersion
},
fetchList: true,
publish
publish,
returnUpdatedStatusList: !publish
})
case 'suspend':
return await agent.cheqdSuspendCredentials({
Expand All @@ -343,7 +342,8 @@ export class Veramo {
statusListVersion: statusOptions.statusListVersion
},
fetchList: true,
publish
publish,
returnUpdatedStatusList: !publish
})
case 'reinstate':
return await agent.cheqdUnsuspendCredentials({
Expand All @@ -354,7 +354,8 @@ export class Veramo {
statusListVersion: statusOptions.statusListVersion
},
fetchList: true,
publish
publish,
returnUpdatedStatusList: !publish
})
}
}
Expand Down
33 changes: 15 additions & 18 deletions src/static/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2234,28 +2234,25 @@
"type": "string"
},
"service": {
"allOf": [
{
"description": "This input field appends a service Object to the didDocument"
},
{
"$ref": "#/components/schemas/Service"
}
]
"type": "array",
"description": "This input field assigns the provided service array to the didDocument",
"items": {
"$ref": "#/components/schemas/Service"
}
},
"verificationMethod": {
"allOf": [
{
"description": "This input field appends a verificationMethod to the didDocument"
},
{
"$ref": "#/components/schemas/VerificationMethod"
}
]
"type": "array",
"description": "This input field assigns the provided verificationMethod array to the didDocument",
"items": {
"$ref": "#/components/schemas/VerificationMethod"
}
},
"authentication": {
"description": "This input field appends a authenticationMethod to the didDocument",
"type": "string"
"description": "This input field assigns the provided authentication array to the didDocument",
"type": "array",
"items": {
"type": "string"
}
},
"didDocument": {
"$ref": "#/components/schemas/DidDocument"
Expand Down

0 comments on commit 24ee606

Please sign in to comment.