Skip to content

Commit

Permalink
fix: add get revocationDefinition
Browse files Browse the repository at this point in the history
  • Loading branch information
lotharking committed Dec 18, 2024
1 parent d661c9e commit 7eee7bb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,11 @@ export class CredentialTypesController {

const schema = schemaResult.schema

const revocationDefinitionRepository = agent.dependencyManager.resolve(
AnonCredsRevocationRegistryDefinitionRepository,
)
const revocationRegistries = await revocationDefinitionRepository.findAllByCredentialDefinitionId(
agent.context,
record.credentialDefinitionId,
)
const revocationRegistryDefinitionIds = revocationRegistries.map(
item => item.revocationRegistryDefinitionId,
)

return {
id: record.credentialDefinitionId,
name: (record.getTag('name') as string) ?? schema?.name,
version: (record.getTag('version') as string) ?? schema?.version,
attributes: schema?.attrNames || [],
revocationIds: revocationRegistryDefinitionIds,
}
}),
)
Expand Down Expand Up @@ -431,7 +419,7 @@ export class CredentialTypesController {
* @param credentialDefinitionId
* @returns RevocationTypeInfo
*/
@Post('/revoke')
@Post('/revocationDefinition')
public async createRevocationRegistry(@Body() options: CreateRevocationRegistryDto): Promise<string> {
try {
const agent = await this.agentService.getAgent()
Expand All @@ -455,15 +443,14 @@ export class CredentialTypesController {
})
const revocationRegistryDefinitionId =
revocationResult.revocationRegistryDefinitionState.revocationRegistryDefinitionId
this.logger.debug!(
`revocationRegistryDefinitionState: ${JSON.stringify(revocationResult.revocationRegistryDefinitionState)}`,
)

if (!revocationRegistryDefinitionId) {
throw new Error(
`Cannot create credential revocations: ${JSON.stringify(revocationResult.registrationMetadata)}`,
)
}
this.logger.debug!(
`revocationRegistryDefinitionState: ${JSON.stringify(revocationResult.revocationRegistryDefinitionState)}`,
)

const revStatusListResult = await agent.modules.anoncreds.registerRevocationStatusList({
revocationStatusList: {
Expand All @@ -472,6 +459,9 @@ export class CredentialTypesController {
},
options: {},
})
if (!revStatusListResult.revocationStatusListState.revocationStatusList) {
throw new Error(`Failed to create revocation status list`)
}
const revocationDefinitionRepository = agent.dependencyManager.resolve(
AnonCredsRevocationRegistryDefinitionRepository,
)
Expand All @@ -482,7 +472,7 @@ export class CredentialTypesController {
)
revocationDefinitionRecord.metadata.set(
'revStatusList',
revStatusListResult.revocationStatusListState.revocationStatusList!,
revStatusListResult.revocationStatusListState.revocationStatusList,
)
await revocationDefinitionRepository.update(agent.context, revocationDefinitionRecord)

Expand All @@ -502,4 +492,27 @@ export class CredentialTypesController {
)
}
}

/**
* Get all revocation definitions by credentialDefinitionId
*
* @returns string[] with revocationRegistryDefinitionIds
*/
@Get('/revocationDefinition')
public async getRevocationDefinitions(@Body() options: CreateRevocationRegistryDto): Promise<string[]> {
const agent = await this.agentService.getAgent()

const revocationDefinitionRepository = agent.dependencyManager.resolve(
AnonCredsRevocationRegistryDefinitionRepository,
)
const revocationRegistries = await revocationDefinitionRepository.findAllByCredentialDefinitionId(
agent.context,
options.credentialDefinitionId,
)
const revocationRegistryDefinitionIds = revocationRegistries.map(
item => item.revocationRegistryDefinitionId,
)

return revocationRegistryDefinitionIds
}
}
1 change: 0 additions & 1 deletion packages/model/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export interface CreateCredentialTypeOptions {
version: string
attributes: string[]
schemaId?: string
revocationIds?: string[]
supportRevocation?: boolean
}

Expand Down

0 comments on commit 7eee7bb

Please sign in to comment.