Skip to content

Commit

Permalink
feat: Add credential-status check API [DEV-2940] (#293)
Browse files Browse the repository at this point in the history
* feat: Add credential-status check api

* build: Bump did-provider-cheqd

* Update package-lock.json

---------

Co-authored-by: Ankur Banerjee <ankurdotb@users.noreply.github.com>
  • Loading branch information
DaevMithran and ankurdotb committed Jul 11, 2023
1 parent a0229ec commit 34ad827
Show file tree
Hide file tree
Showing 9 changed files with 2,735 additions and 2,463 deletions.
454 changes: 280 additions & 174 deletions package-lock.json

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,11 @@ class App {
app.post(`/presentation/verify`, CredentialController.presentationValidator, new CredentialController().verifyPresentation)

//revocation
app.post('/credential-status/create', RevocationController.queryValidator, RevocationController.statusListValidator, new RevocationController().createStatusList)
app.post('/credential-status/create', RevocationController.commonValidator, RevocationController.statusListValidator, new RevocationController().createStatusList)
app.post('/credential-status/update', RevocationController.updateValidator, new RevocationController().updateStatusList)
app.post('/credential-status/publish', RevocationController.queryValidator, new RevocationController().createStatusList)
app.get('/credential-status/search', RevocationController.queryValidator, new RevocationController().fetchStatusList)
app.post('/credential-status/publish', RevocationController.commonValidator, new RevocationController().createStatusList)
app.post('/credential-status/check', RevocationController.commonValidator, RevocationController.checkValidator, new RevocationController().checkStatusList)
app.get('/credential-status/search', RevocationController.commonValidator, new RevocationController().fetchStatusList)

// store
app.post(`/store`, new StoreController().set)
Expand Down
34 changes: 32 additions & 2 deletions src/controllers/revocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class RevocationController {
check('statusPurpose').optional().isIn(['revocation', 'suspension']).withMessage('invalid statusPurpose')
]

static queryValidator = [
static commonValidator = [
check('did').isString().withMessage('DID is required')
.contains('did:cheqd:').withMessage('Provide a valid cheqd DID'),
query('statusPurpose').optional().isString().withMessage('statusPurpose should be a string')
Expand All @@ -34,6 +34,13 @@ export class RevocationController {
query('publish').isBoolean().withMessage('publish should be a boolean value')
]

static checkValidator = [
check('index').exists().withMessage('Index is required')
.isNumeric().withMessage('Index should be a number'),
check('statusListName').exists().withMessage('StatusListName is required')
.isString().withMessage('Invalid statusListName')
]

async createStatusList(request: Request, response: Response) {
const result = validationResult(request)
if (!result.isEmpty()) {
Expand Down Expand Up @@ -101,7 +108,7 @@ export class RevocationController {
}
}

async updateStatusList(request: Request, response: Response) {
async updateStatusList(request: Request, response: Response) {
const result = validationResult(request)
if (!result.isEmpty()) {
return response.status(400).json({ error: result.array()[0].msg })
Expand All @@ -125,4 +132,27 @@ export class RevocationController {
})
}
}

async checkStatusList(request: Request, response: Response) {
const result = validationResult(request)
if (!result.isEmpty()) {
return response.status(400).json({ error: result.array()[0].msg })
}

let { did, statusListName, index } = request.body
const statusPurpose = request.query.statusPurpose as 'revocation' | 'suspension'

try {
let result: any
result = await Identity.instance.checkStatusList2021(did, { statusListIndex: index, statusListName, statusPurpose }, response.locals.customerId)
if (result.error) {
return response.status(400).json(result)
}
return response.status(200).json(result)
} catch (error) {
return response.status(500).json({
error: `Internal error: ${error}`
})
}
}
}
7 changes: 4 additions & 3 deletions src/services/identity/IIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import type {
} from '@veramo/core'
import type { AbstractPrivateKeyStore } from '@veramo/key-manager'
import type { ResourcePayload } from '@cheqd/did-provider-cheqd'
import type { BulkRevocationResult, BulkSuspensionResult, BulkUnsuspensionResult, CreateStatusList2021Result, RevocationResult, SuspensionResult, UnsuspensionResult } from '@cheqd/did-provider-cheqd/build/types/agent/ICheqd'
import type { BroadCastStatusListOptions, CreateStatusListOptions, CredentialRequest, StatusOptions, UpdateStatusListOptions, VeramoAgent, VerificationOptions } from '../../types/types'
import type { BulkRevocationResult, BulkSuspensionResult, BulkUnsuspensionResult, CreateStatusList2021Result, RevocationResult, StatusCheckResult, SuspensionResult, UnsuspensionResult } from '@cheqd/did-provider-cheqd/build/types/agent/ICheqd'
import type { BroadCastStatusListOptions, CheckStatusListOptions, CreateStatusListOptions, CredentialRequest, StatusOptions, UpdateStatusListOptions, VeramoAgent, VerificationOptions } from '../../types/types'

export interface IIdentity {
agent?: TAgent<any>
Expand All @@ -35,7 +35,8 @@ export interface IIdentity {
createStatusList2021(did: string, resourceOptions: ResourcePayload, statusOptions: CreateStatusListOptions, agentId: string): Promise<CreateStatusList2021Result>
updateStatusList2021(did: string, statusOptions: UpdateStatusListOptions, publish?: boolean, agentId?: string): Promise<BulkRevocationResult | BulkSuspensionResult | BulkUnsuspensionResult>
broadcastStatusList2021(did: string, resourceOptions: ResourcePayload, statusOptions: BroadCastStatusListOptions, agentId?: string): Promise<boolean>
checkStatusList2021(did: string, statusOptions: CheckStatusListOptions, agentId?: string): Promise<StatusCheckResult>
revokeCredentials(credential: VerifiableCredential | VerifiableCredential[], publish: boolean, agentId?: string): Promise<RevocationResult| BulkRevocationResult>
suspendCredentials(credential: VerifiableCredential | VerifiableCredential[], publish: boolean, agentId?: string): Promise<SuspensionResult| BulkSuspensionResult>
reinstateCredentials(credential: VerifiableCredential | VerifiableCredential[], publish: boolean, agentId?: string): Promise<UnsuspensionResult| BulkUnsuspensionResult>
reinstateCredentials(credential: VerifiableCredential | VerifiableCredential[], publish: boolean, agentId?: string): Promise<UnsuspensionResult| BulkUnsuspensionResult>
}
12 changes: 12 additions & 0 deletions src/services/identity/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { CheqdNetwork } from '@cheqd/sdk'
import { Resolver, ResolverRegistry } from 'did-resolver'
import type {
ICheqdBroadcastStatusList2021Args,
ICheqdCheckCredentialStatusWithStatusList2021Args,
ICheqdCreateStatusList2021Args,
ICheqdDeactivateIdentifierArgs,
ICheqdRevokeBulkCredentialsWithStatusList2021Args,
Expand All @@ -38,6 +39,7 @@ import type {
} from '@cheqd/did-provider-cheqd/build/types/agent/ICheqd'
import {
BroadCastStatusListOptions,
CheckStatusListOptions,
cheqdDidRegex,
CreateAgentRequest,
CreateStatusListOptions,
Expand Down Expand Up @@ -409,4 +411,14 @@ export class Veramo {
})
}
}

async checkStatusList2021(agent: VeramoAgent, did: string, statusOptions: CheckStatusListOptions) {
return await agent.cheqdCheckCredentialStatus({
statusOptions: {
issuerDid: did,
...statusOptions,
},
fetchList: true
} satisfies ICheqdCheckCredentialStatusWithStatusList2021Args)
}
}
8 changes: 6 additions & 2 deletions src/services/identity/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import {
import { AbstractPrivateKeyStore, MemoryPrivateKeyStore } from '@veramo/key-manager'
import { KeyManagementSystem } from '@veramo/kms-local'
import { CheqdDIDProvider, ResourcePayload } from '@cheqd/did-provider-cheqd'
import { BulkRevocationResult, BulkSuspensionResult, BulkUnsuspensionResult, CreateStatusList2021Result } from '@cheqd/did-provider-cheqd/build/types/agent/ICheqd'
import { BulkRevocationResult, BulkSuspensionResult, BulkUnsuspensionResult, CreateStatusList2021Result, StatusCheckResult } from '@cheqd/did-provider-cheqd/build/types/agent/ICheqd'
import { CheqdNetwork } from '@cheqd/sdk'

import { BroadCastStatusListOptions, CreateStatusListOptions, CredentialRequest, DefaultRPCUrl, StatusOptions, UpdateStatusListOptions, VeramoAgent, VerificationOptions } from '../../types/types.js'
import { BroadCastStatusListOptions, CheckStatusListOptions, CreateStatusListOptions, CredentialRequest, DefaultRPCUrl, StatusOptions, UpdateStatusListOptions, VeramoAgent, VerificationOptions } from '../../types/types.js'
import { Connection } from '../../database/connection/connection.js'
import { IIdentity } from './IIdentity.js'
import { Veramo } from './agent.js'
Expand Down Expand Up @@ -166,6 +166,10 @@ export class LocalIdentity implements IIdentity {
return await Veramo.instance.broadcastStatusList2021(this.initAgent(), did, resourceOptions, statusOptions)
}

async checkStatusList2021(did: string, statusOptions: CheckStatusListOptions): Promise<StatusCheckResult> {
return await Veramo.instance.checkStatusList2021(this.initAgent(), did, statusOptions)
}

async revokeCredentials(credentials: VerifiableCredential | VerifiableCredential[], publish: boolean) {
return await Veramo.instance.revokeCredentials(this.initAgent(), credentials, publish)
}
Expand Down
9 changes: 7 additions & 2 deletions src/services/identity/postgres.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ import { KeyManagementSystem, SecretBox } from '@veramo/kms-local'
import { PrivateKeyStore } from '@veramo/data-store'
import { CheqdDIDProvider, ResourcePayload } from '@cheqd/did-provider-cheqd'
import { CheqdNetwork } from '@cheqd/sdk'
import { BroadCastStatusListOptions, cheqdDidRegex, CreateStatusListOptions, CredentialRequest, DefaultRPCUrl, StatusOptions, UpdateStatusListOptions, VeramoAgent, VerificationOptions } from '../../types/types.js'
import { BroadCastStatusListOptions, CheckStatusListOptions, cheqdDidRegex, CreateStatusListOptions, CredentialRequest, DefaultRPCUrl, StatusOptions, UpdateStatusListOptions, VeramoAgent, VerificationOptions } from '../../types/types.js'
import { Connection } from '../../database/connection/connection.js'
import { CustomerEntity } from '../../database/entities/customer.entity.js'
import { IIdentity } from './IIdentity.js'
import { CustomerService } from '../customer.js'
import { Veramo } from './agent.js'

import * as dotenv from 'dotenv'
import { BulkRevocationResult, BulkSuspensionResult, BulkUnsuspensionResult, CreateStatusList2021Result } from '@cheqd/did-provider-cheqd/build/types/agent/ICheqd.js'
import { BulkRevocationResult, BulkSuspensionResult, BulkUnsuspensionResult, CreateStatusList2021Result, StatusCheckResult } from '@cheqd/did-provider-cheqd/build/types/agent/ICheqd.js'
dotenv.config()

const {
Expand Down Expand Up @@ -234,6 +234,11 @@ export class PostgresIdentity implements IIdentity {
return await Veramo.instance.updateStatusList2021(agent, did, statusOptions, publish)
}

async checkStatusList2021(did: string, statusOptions: CheckStatusListOptions, agentId: string): Promise<StatusCheckResult> {
const agent = await this.createAgent(agentId)
return await Veramo.instance.checkStatusList2021(agent, did, statusOptions)
}

async broadcastStatusList2021(did: string, resourceOptions: ResourcePayload, statusOptions: BroadCastStatusListOptions, agentId: string): Promise<boolean> {
const agent = await this.createAgent(agentId)
return await Veramo.instance.broadcastStatusList2021(agent, did, resourceOptions, statusOptions)
Expand Down

0 comments on commit 34ad827

Please sign in to comment.