-
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.
Merge branch 'feat/add-revocation-registry' into feat/create-revocati…
…on-nestjs-client
- Loading branch information
Showing
9 changed files
with
164 additions
and
55 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
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' |
15 changes: 13 additions & 2 deletions
15
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 |
---|---|---|
@@ -1,12 +1,23 @@ | ||
import { ApiProperty } from '@nestjs/swagger' | ||
import { IsString, IsNotEmpty } from 'class-validator' | ||
import { IsString, IsNotEmpty, IsNumber, IsOptional } from 'class-validator' | ||
|
||
export class CreateRevocationRegistryDto { | ||
@ApiProperty({ | ||
description: 'credentialDefinitionId', | ||
example: 'did:web', | ||
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 | ||
} |
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