-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Credential Revocation Support and Related Services (#57)
- Loading branch information
1 parent
40f71a7
commit d8d34df
Showing
23 changed files
with
628 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// src/services/RevocationRegistryService.ts | ||
|
||
import { RevocationRegistryInfo } from '@2060.io/service-agent-model' | ||
import { Logger } from 'tslog' | ||
|
||
import { ApiVersion } from '../types/enums' | ||
|
||
const logger = new Logger({ | ||
name: 'RevocationRegistryService', | ||
type: 'pretty', | ||
prettyLogTemplate: '{{logLevelName}} [{{name}}]: ', | ||
}) | ||
|
||
/** | ||
* `RevocationRegistryService` class for managing credential types and interacting with | ||
* the available endpoints related to credential types in the Agent Service. | ||
* | ||
* This class provides methods for querying, creating, and managing revocation registry on credential types. | ||
* For a list of available endpoints and functionality, refer to the methods within this class. | ||
*/ | ||
export class RevocationRegistryService { | ||
private url: string | ||
|
||
constructor( | ||
private baseURL: string, | ||
private version: ApiVersion, | ||
) { | ||
this.url = `${this.baseURL.replace(/\/$/, '')}/${this.version}/credential-types` | ||
} | ||
|
||
public async create(options: RevocationRegistryInfo): Promise<string | undefined> { | ||
const response = await fetch(`${this.url}/revocationRegistry`, { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify(options), | ||
}) | ||
|
||
if (!response.ok) { | ||
logger.error(`Failed to create revocation registry`) | ||
return undefined | ||
} | ||
|
||
return await response.text() | ||
} | ||
|
||
public async get(credentialDefinitionId: string): Promise<string[]> { | ||
const response = await fetch( | ||
`${this.url}/revocationRegistry?credentialDefinitionId=${encodeURIComponent(credentialDefinitionId)}`, | ||
{ | ||
method: 'GET', | ||
headers: { 'Content-Type': 'application/json' }, | ||
}, | ||
) | ||
|
||
if (!response.ok) { | ||
throw new Error(`Failed to fetch revocation definitions: ${response.statusText}`) | ||
} | ||
|
||
return (await response.json()) as string[] | ||
} | ||
|
||
public async getAll(): Promise<string[]> { | ||
const response = await fetch(`${this.url}/revocationRegistry`, { | ||
method: 'GET', | ||
headers: { 'Content-Type': 'application/json' }, | ||
}) | ||
|
||
if (!response.ok) { | ||
throw new Error(`Failed to fetch revocation registries: ${response.statusText}`) | ||
} | ||
|
||
return (await response.json()) as string[] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './CredentialTypeService' | ||
export * from './MessageService' | ||
export * from './RevocationRegistryService' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ build | |
*.txn | ||
logs.txt | ||
examples/**/afj | ||
tails/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/main/src/controllers/credentials/CreateRevocationRegistryDto.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ApiProperty } from '@nestjs/swagger' | ||
import { IsString, IsNotEmpty, IsNumber, IsOptional } from 'class-validator' | ||
|
||
export class CreateRevocationRegistryDto { | ||
@ApiProperty({ | ||
description: 'credentialDefinitionId', | ||
example: | ||
'did:web:chatbot-demo.dev.2060.io?service=anoncreds&relativeRef=/credDef/8TsGLaSPVKPVMXK8APzBRcXZryxutvQuZnnTcDmbqd9p', | ||
}) | ||
@IsString() | ||
@IsNotEmpty() | ||
credentialDefinitionId!: string | ||
|
||
@ApiProperty({ | ||
description: 'maximumCredentialNumber', | ||
default: 1000, | ||
example: 1000, | ||
}) | ||
@IsNumber() | ||
@IsNotEmpty() | ||
@IsOptional() | ||
maximumCredentialNumber: number = 1000 | ||
} |
Oops, something went wrong.