From 20a8da6433cc432721ab78e3abc49dd41f19488d Mon Sep 17 00:00:00 2001 From: NB-Karim Date: Tue, 25 Jan 2022 17:30:38 +0100 Subject: [PATCH 1/4] feat(proofs): add v2 message types Signed-off-by: NB-Karim --- ...ssageV2.ts => V2PresentationAckMessage.ts} | 7 +- .../v2/messages/V2PresentationMessage.ts | 68 +++++++++++++++++++ .../messages/V2ProposalPresentationMessage.ts | 10 +-- .../messages/V2RequestPresentationMessage.ts | 68 +++++++++++++++++++ 4 files changed, 145 insertions(+), 8 deletions(-) rename packages/core/src/modules/proofs/protocol/v2/messages/{PresentationAckMessageV2.ts => V2PresentationAckMessage.ts} (73%) create mode 100644 packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationMessage.ts create mode 100644 packages/core/src/modules/proofs/protocol/v2/messages/V2RequestPresentationMessage.ts diff --git a/packages/core/src/modules/proofs/protocol/v2/messages/PresentationAckMessageV2.ts b/packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationAckMessage.ts similarity index 73% rename from packages/core/src/modules/proofs/protocol/v2/messages/PresentationAckMessageV2.ts rename to packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationAckMessage.ts index 5fb8855277..41ed6be8ee 100644 --- a/packages/core/src/modules/proofs/protocol/v2/messages/PresentationAckMessageV2.ts +++ b/packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationAckMessage.ts @@ -1,7 +1,8 @@ +import type { PresentationAckMessage, PresentationAckMessageOptions } from '../../../messages/PresentationAckMessage' + import { Equals } from 'class-validator' -import { PresentationAckMessageOptions } from '../..' -import { AckMessage } from '../../../common' -import { PresentationAckMessage } from '../../messages/PresentationAckMessage' + +import { AckMessage } from 'packages/core/src/modules/common' /** * @see https://github.com/hyperledger/aries-rfcs/blob/master/features/0015-acks/README.md#explicit-acks diff --git a/packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationMessage.ts b/packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationMessage.ts new file mode 100644 index 0000000000..0e0f365989 --- /dev/null +++ b/packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationMessage.ts @@ -0,0 +1,68 @@ +import type { ProofAttachmentFormat } from '../../../formats/ProofFormatService' + +import { Expose, Type } from 'class-transformer' +import { Equals, IsArray, IsBoolean, IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator' + +import { ProofFormatSpec } from '../../../formats/models/ProofFormatServiceOptions' + +import { AgentMessage } from '@aries-framework/core' +import { Attachment } from 'packages/core/src/decorators/attachment/Attachment' +import { uuid } from 'packages/core/src/utils/uuid' + +export interface V2PresentationMessageOptions { + id?: string + goalCode?: string + comment?: string + attachmentInfo: ProofAttachmentFormat[] +} + +export class V2PresentationMessage extends AgentMessage { + public constructor(options: V2PresentationMessageOptions) { + super() + if (options) { + this.id = options.id ?? uuid() + this.comment = options.comment + this.goalCode = options.goalCode + + for (const entry of options.attachmentInfo) { + this.addPresentationsAttachment(entry) + } + } + } + + public addPresentationsAttachment(attachment: ProofAttachmentFormat) { + this.formats.push(attachment.format) + this.presentationsAttach.push(attachment.attachment) + } + + @Equals(V2PresentationMessage.type) + public readonly type = V2PresentationMessage.type + public static readonly type = 'https://didcomm.org/present-proof/2.0/presentation' + + @IsString() + @IsOptional() + public comment?: string + + @Expose({ name: 'goal_code' }) + @IsString() + @IsOptional() + public goalCode?: string + + @Expose({ name: 'will_confirm' }) + @IsBoolean() + public willConfirm = false + + @Expose({ name: 'formats' }) + @Type(() => ProofFormatSpec) + @IsArray() + @ValidateNested({ each: true }) + @IsInstance(ProofFormatSpec, { each: true }) + public formats!: ProofFormatSpec[] + + @Expose({ name: 'presentations~attach' }) + @Type(() => Attachment) + @IsArray() + @ValidateNested({ each: true }) + @IsInstance(Attachment, { each: true }) + public presentationsAttach!: Attachment[] +} diff --git a/packages/core/src/modules/proofs/protocol/v2/messages/V2ProposalPresentationMessage.ts b/packages/core/src/modules/proofs/protocol/v2/messages/V2ProposalPresentationMessage.ts index fbf300ddc5..ac267e98a7 100644 --- a/packages/core/src/modules/proofs/protocol/v2/messages/V2ProposalPresentationMessage.ts +++ b/packages/core/src/modules/proofs/protocol/v2/messages/V2ProposalPresentationMessage.ts @@ -1,17 +1,17 @@ -import type { V2ProofFormatSpec } from '../formats/V2ProofFormat' +import type { ProofFormatSpec } from '../../../formats/models/ProofFormatServiceOptions' import { Expose, Type } from 'class-transformer' import { Equals, IsArray, IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator' import { AgentMessage } from '../../../../../agent/AgentMessage' -import { Attachment } from '../../../../../decorators/attachment/Attachment' import { uuid } from '../../../../../utils/uuid' import { PresentationPreview } from '../../v1/models/PresentationPreview' -import { PRES_20_PROPOSAL } from '../formats/MessageTypes' + +import { Attachment } from 'packages/core/src/decorators/attachment/Attachment' export interface V2ProposePresentationMessageOptions { id?: string - formats: V2ProofFormatSpec + formats: ProofFormatSpec filtersAttach: Attachment[] comment?: string presentationProposal: PresentationPreview @@ -58,5 +58,5 @@ export class V2ProposalPresentationMessage extends AgentMessage { @IsInstance(PresentationPreview) public presentationProposal!: PresentationPreview - public formats!: V2ProofFormatSpec + public formats!: ProofFormatSpec } diff --git a/packages/core/src/modules/proofs/protocol/v2/messages/V2RequestPresentationMessage.ts b/packages/core/src/modules/proofs/protocol/v2/messages/V2RequestPresentationMessage.ts new file mode 100644 index 0000000000..7c745b4115 --- /dev/null +++ b/packages/core/src/modules/proofs/protocol/v2/messages/V2RequestPresentationMessage.ts @@ -0,0 +1,68 @@ +import type { ProofAttachmentFormat } from '../../../formats/ProofFormatService' + +import { Expose, Type } from 'class-transformer' +import { Equals, IsArray, IsBoolean, IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator' + +import { ProofFormatSpec } from '../../../formats/models/ProofFormatServiceOptions' + +import { AgentMessage } from '@aries-framework/core' +import { Attachment } from 'packages/core/src/decorators/attachment/Attachment' +import { uuid } from 'packages/core/src/utils/uuid' + +export interface V2RequestPresentationMessageOptions { + id?: string + goalCode?: string + comment?: string + attachmentInfo: ProofAttachmentFormat[] +} + +export class V2RequestPresentationMessage extends AgentMessage { + public constructor(options: V2RequestPresentationMessageOptions) { + super() + if (options) { + this.id = options.id ?? uuid() + this.comment = options.comment + this.goalCode = options.goalCode + + for (const entry of options.attachmentInfo) { + this.addProposalsAttachment(entry) + } + } + } + + public addProposalsAttachment(attachment: ProofAttachmentFormat) { + this.formats.push(attachment.format) + this.proposalsAttach.push(attachment.attachment) + } + + @Equals(V2RequestPresentationMessage.type) + public readonly type = V2RequestPresentationMessage.type + public static readonly type = 'https://didcomm.org/present-proof/2.0/request-presentation' + + @IsString() + @IsOptional() + public comment?: string + + @Expose({ name: 'goal_code' }) + @IsString() + @IsOptional() + public goalCode?: string + + @Expose({ name: 'will_confirm' }) + @IsBoolean() + public willConfirm = false + + @Expose({ name: 'formats' }) + @Type(() => ProofFormatSpec) + @IsArray() + @ValidateNested({ each: true }) + @IsInstance(ProofFormatSpec, { each: true }) + public formats!: ProofFormatSpec[] + + @Expose({ name: 'proposals~attach' }) + @Type(() => Attachment) + @IsArray() + @ValidateNested({ each: true }) + @IsInstance(Attachment, { each: true }) + public proposalsAttach!: Attachment[] +} From 7a021da741512fd391af02bf9451419aeac9a6be Mon Sep 17 00:00:00 2001 From: NB-Karim Date: Tue, 25 Jan 2022 17:30:38 +0100 Subject: [PATCH 2/4] feat(proofs): add v2 message types Signed-off-by: NB-Karim --- ...ssageV2.ts => V2PresentationAckMessage.ts} | 7 +- .../v2/messages/V2PresentationMessage.ts | 68 +++++++++++++++++++ .../messages/V2ProposalPresentationMessage.ts | 10 +-- .../messages/V2RequestPresentationMessage.ts | 68 +++++++++++++++++++ 4 files changed, 145 insertions(+), 8 deletions(-) rename packages/core/src/modules/proofs/protocol/v2/messages/{PresentationAckMessageV2.ts => V2PresentationAckMessage.ts} (73%) create mode 100644 packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationMessage.ts create mode 100644 packages/core/src/modules/proofs/protocol/v2/messages/V2RequestPresentationMessage.ts diff --git a/packages/core/src/modules/proofs/protocol/v2/messages/PresentationAckMessageV2.ts b/packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationAckMessage.ts similarity index 73% rename from packages/core/src/modules/proofs/protocol/v2/messages/PresentationAckMessageV2.ts rename to packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationAckMessage.ts index 5fb8855277..41ed6be8ee 100644 --- a/packages/core/src/modules/proofs/protocol/v2/messages/PresentationAckMessageV2.ts +++ b/packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationAckMessage.ts @@ -1,7 +1,8 @@ +import type { PresentationAckMessage, PresentationAckMessageOptions } from '../../../messages/PresentationAckMessage' + import { Equals } from 'class-validator' -import { PresentationAckMessageOptions } from '../..' -import { AckMessage } from '../../../common' -import { PresentationAckMessage } from '../../messages/PresentationAckMessage' + +import { AckMessage } from 'packages/core/src/modules/common' /** * @see https://github.com/hyperledger/aries-rfcs/blob/master/features/0015-acks/README.md#explicit-acks diff --git a/packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationMessage.ts b/packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationMessage.ts new file mode 100644 index 0000000000..0e0f365989 --- /dev/null +++ b/packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationMessage.ts @@ -0,0 +1,68 @@ +import type { ProofAttachmentFormat } from '../../../formats/ProofFormatService' + +import { Expose, Type } from 'class-transformer' +import { Equals, IsArray, IsBoolean, IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator' + +import { ProofFormatSpec } from '../../../formats/models/ProofFormatServiceOptions' + +import { AgentMessage } from '@aries-framework/core' +import { Attachment } from 'packages/core/src/decorators/attachment/Attachment' +import { uuid } from 'packages/core/src/utils/uuid' + +export interface V2PresentationMessageOptions { + id?: string + goalCode?: string + comment?: string + attachmentInfo: ProofAttachmentFormat[] +} + +export class V2PresentationMessage extends AgentMessage { + public constructor(options: V2PresentationMessageOptions) { + super() + if (options) { + this.id = options.id ?? uuid() + this.comment = options.comment + this.goalCode = options.goalCode + + for (const entry of options.attachmentInfo) { + this.addPresentationsAttachment(entry) + } + } + } + + public addPresentationsAttachment(attachment: ProofAttachmentFormat) { + this.formats.push(attachment.format) + this.presentationsAttach.push(attachment.attachment) + } + + @Equals(V2PresentationMessage.type) + public readonly type = V2PresentationMessage.type + public static readonly type = 'https://didcomm.org/present-proof/2.0/presentation' + + @IsString() + @IsOptional() + public comment?: string + + @Expose({ name: 'goal_code' }) + @IsString() + @IsOptional() + public goalCode?: string + + @Expose({ name: 'will_confirm' }) + @IsBoolean() + public willConfirm = false + + @Expose({ name: 'formats' }) + @Type(() => ProofFormatSpec) + @IsArray() + @ValidateNested({ each: true }) + @IsInstance(ProofFormatSpec, { each: true }) + public formats!: ProofFormatSpec[] + + @Expose({ name: 'presentations~attach' }) + @Type(() => Attachment) + @IsArray() + @ValidateNested({ each: true }) + @IsInstance(Attachment, { each: true }) + public presentationsAttach!: Attachment[] +} diff --git a/packages/core/src/modules/proofs/protocol/v2/messages/V2ProposalPresentationMessage.ts b/packages/core/src/modules/proofs/protocol/v2/messages/V2ProposalPresentationMessage.ts index fbf300ddc5..ac267e98a7 100644 --- a/packages/core/src/modules/proofs/protocol/v2/messages/V2ProposalPresentationMessage.ts +++ b/packages/core/src/modules/proofs/protocol/v2/messages/V2ProposalPresentationMessage.ts @@ -1,17 +1,17 @@ -import type { V2ProofFormatSpec } from '../formats/V2ProofFormat' +import type { ProofFormatSpec } from '../../../formats/models/ProofFormatServiceOptions' import { Expose, Type } from 'class-transformer' import { Equals, IsArray, IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator' import { AgentMessage } from '../../../../../agent/AgentMessage' -import { Attachment } from '../../../../../decorators/attachment/Attachment' import { uuid } from '../../../../../utils/uuid' import { PresentationPreview } from '../../v1/models/PresentationPreview' -import { PRES_20_PROPOSAL } from '../formats/MessageTypes' + +import { Attachment } from 'packages/core/src/decorators/attachment/Attachment' export interface V2ProposePresentationMessageOptions { id?: string - formats: V2ProofFormatSpec + formats: ProofFormatSpec filtersAttach: Attachment[] comment?: string presentationProposal: PresentationPreview @@ -58,5 +58,5 @@ export class V2ProposalPresentationMessage extends AgentMessage { @IsInstance(PresentationPreview) public presentationProposal!: PresentationPreview - public formats!: V2ProofFormatSpec + public formats!: ProofFormatSpec } diff --git a/packages/core/src/modules/proofs/protocol/v2/messages/V2RequestPresentationMessage.ts b/packages/core/src/modules/proofs/protocol/v2/messages/V2RequestPresentationMessage.ts new file mode 100644 index 0000000000..7c745b4115 --- /dev/null +++ b/packages/core/src/modules/proofs/protocol/v2/messages/V2RequestPresentationMessage.ts @@ -0,0 +1,68 @@ +import type { ProofAttachmentFormat } from '../../../formats/ProofFormatService' + +import { Expose, Type } from 'class-transformer' +import { Equals, IsArray, IsBoolean, IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator' + +import { ProofFormatSpec } from '../../../formats/models/ProofFormatServiceOptions' + +import { AgentMessage } from '@aries-framework/core' +import { Attachment } from 'packages/core/src/decorators/attachment/Attachment' +import { uuid } from 'packages/core/src/utils/uuid' + +export interface V2RequestPresentationMessageOptions { + id?: string + goalCode?: string + comment?: string + attachmentInfo: ProofAttachmentFormat[] +} + +export class V2RequestPresentationMessage extends AgentMessage { + public constructor(options: V2RequestPresentationMessageOptions) { + super() + if (options) { + this.id = options.id ?? uuid() + this.comment = options.comment + this.goalCode = options.goalCode + + for (const entry of options.attachmentInfo) { + this.addProposalsAttachment(entry) + } + } + } + + public addProposalsAttachment(attachment: ProofAttachmentFormat) { + this.formats.push(attachment.format) + this.proposalsAttach.push(attachment.attachment) + } + + @Equals(V2RequestPresentationMessage.type) + public readonly type = V2RequestPresentationMessage.type + public static readonly type = 'https://didcomm.org/present-proof/2.0/request-presentation' + + @IsString() + @IsOptional() + public comment?: string + + @Expose({ name: 'goal_code' }) + @IsString() + @IsOptional() + public goalCode?: string + + @Expose({ name: 'will_confirm' }) + @IsBoolean() + public willConfirm = false + + @Expose({ name: 'formats' }) + @Type(() => ProofFormatSpec) + @IsArray() + @ValidateNested({ each: true }) + @IsInstance(ProofFormatSpec, { each: true }) + public formats!: ProofFormatSpec[] + + @Expose({ name: 'proposals~attach' }) + @Type(() => Attachment) + @IsArray() + @ValidateNested({ each: true }) + @IsInstance(Attachment, { each: true }) + public proposalsAttach!: Attachment[] +} From bf824d447ec99c320ab52489820683f0ab9b5ef7 Mon Sep 17 00:00:00 2001 From: NB-Karim Date: Wed, 26 Jan 2022 13:26:28 +0100 Subject: [PATCH 3/4] fix(proofs): add missing goal_code to options Signed-off-by: NB-Karim --- .../v2/messages/V2PresentationMessage.ts | 2 + .../messages/V2ProposalPresentationMessage.ts | 69 +++++++++++-------- .../messages/V2RequestPresentationMessage.ts | 14 ++-- 3 files changed, 49 insertions(+), 36 deletions(-) diff --git a/packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationMessage.ts b/packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationMessage.ts index 0e0f365989..422832e451 100644 --- a/packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationMessage.ts +++ b/packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationMessage.ts @@ -13,6 +13,7 @@ export interface V2PresentationMessageOptions { id?: string goalCode?: string comment?: string + willConfirm?: boolean attachmentInfo: ProofAttachmentFormat[] } @@ -23,6 +24,7 @@ export class V2PresentationMessage extends AgentMessage { this.id = options.id ?? uuid() this.comment = options.comment this.goalCode = options.goalCode + this.willConfirm = options.willConfirm ?? false for (const entry of options.attachmentInfo) { this.addPresentationsAttachment(entry) diff --git a/packages/core/src/modules/proofs/protocol/v2/messages/V2ProposalPresentationMessage.ts b/packages/core/src/modules/proofs/protocol/v2/messages/V2ProposalPresentationMessage.ts index ac267e98a7..fef9c793c7 100644 --- a/packages/core/src/modules/proofs/protocol/v2/messages/V2ProposalPresentationMessage.ts +++ b/packages/core/src/modules/proofs/protocol/v2/messages/V2ProposalPresentationMessage.ts @@ -1,20 +1,21 @@ -import type { ProofFormatSpec } from '../../../formats/models/ProofFormatServiceOptions' +import type { ProofAttachmentFormat } from '../../../formats/models/ProofFormatServiceOptions' import { Expose, Type } from 'class-transformer' -import { Equals, IsArray, IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator' +import { Equals, IsArray, IsBoolean, IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator' import { AgentMessage } from '../../../../../agent/AgentMessage' import { uuid } from '../../../../../utils/uuid' +import { ProofFormatSpec } from '../../../formats/models/ProofFormatServiceOptions' import { PresentationPreview } from '../../v1/models/PresentationPreview' import { Attachment } from 'packages/core/src/decorators/attachment/Attachment' export interface V2ProposePresentationMessageOptions { id?: string - formats: ProofFormatSpec - filtersAttach: Attachment[] comment?: string - presentationProposal: PresentationPreview + goalCode?: string + willConfirm?: boolean + attachmentInfo: ProofAttachmentFormat[] } export class V2ProposalPresentationMessage extends AgentMessage { @@ -23,40 +24,48 @@ export class V2ProposalPresentationMessage extends AgentMessage { if (options) { this.id = options.id ?? uuid() this.comment = options.comment - this.presentationProposal = options.presentationProposal - this.formats = options.formats - this.filtersAttach = options.filtersAttach + this.goalCode = options.goalCode + this.willConfirm = options.willConfirm ?? false + + for (const entry of options.attachmentInfo) { + this.addProposalsAttachment(entry) + } } } + public addProposalsAttachment(attachment: ProofAttachmentFormat) { + this.formats.push(attachment.format) + this.proposalsAttach.push(attachment.attachment) + } + @Equals(V2ProposalPresentationMessage.type) public readonly type = V2ProposalPresentationMessage.type - public static readonly type = `https://didcomm.org/${PRES_20_PROPOSAL}` - - @Expose({ name: 'filters~attach' }) - @Type(() => Attachment) - @IsArray() - @ValidateNested({ - each: true, - }) - @IsInstance(Attachment, { each: true }) - public filtersAttach!: Attachment[] + public static readonly type = `https://didcomm.org/present-proof/2.0/propose-presentation` - /** - * Provides some human readable information about the proposed presentation. - */ @IsString() @IsOptional() public comment?: string - /** - * Represents the presentation example that prover wants to provide. - */ - @Expose({ name: 'presentation_proposal' }) - @Type(() => PresentationPreview) - @ValidateNested() - @IsInstance(PresentationPreview) - public presentationProposal!: PresentationPreview + @Expose({ name: 'goal_code' }) + @IsString() + @IsOptional() + public goalCode?: string + + @Expose({ name: 'will_confirm' }) + @IsBoolean() + public willConfirm = false + + @Expose({ name: 'formats' }) + @Type(() => ProofFormatSpec) + @IsArray() + @ValidateNested({ each: true }) + @IsInstance(ProofFormatSpec, { each: true }) + public formats!: ProofFormatSpec[] - public formats!: ProofFormatSpec + @Expose({ name: 'proposals~attach' }) + @Type(() => Attachment) + @IsArray() + @ValidateNested({ each: true }) + @IsInstance(Attachment, { each: true }) + public proposalsAttach!: Attachment[] } diff --git a/packages/core/src/modules/proofs/protocol/v2/messages/V2RequestPresentationMessage.ts b/packages/core/src/modules/proofs/protocol/v2/messages/V2RequestPresentationMessage.ts index 7c745b4115..ea544151b2 100644 --- a/packages/core/src/modules/proofs/protocol/v2/messages/V2RequestPresentationMessage.ts +++ b/packages/core/src/modules/proofs/protocol/v2/messages/V2RequestPresentationMessage.ts @@ -11,8 +11,9 @@ import { uuid } from 'packages/core/src/utils/uuid' export interface V2RequestPresentationMessageOptions { id?: string - goalCode?: string comment?: string + goalCode?: string + willConfirm?: boolean attachmentInfo: ProofAttachmentFormat[] } @@ -23,16 +24,17 @@ export class V2RequestPresentationMessage extends AgentMessage { this.id = options.id ?? uuid() this.comment = options.comment this.goalCode = options.goalCode + this.willConfirm = options.willConfirm ?? false for (const entry of options.attachmentInfo) { - this.addProposalsAttachment(entry) + this.addRequestPresentationsAttachment(entry) } } } - public addProposalsAttachment(attachment: ProofAttachmentFormat) { + public addRequestPresentationsAttachment(attachment: ProofAttachmentFormat) { this.formats.push(attachment.format) - this.proposalsAttach.push(attachment.attachment) + this.requestPresentationsAttach.push(attachment.attachment) } @Equals(V2RequestPresentationMessage.type) @@ -59,10 +61,10 @@ export class V2RequestPresentationMessage extends AgentMessage { @IsInstance(ProofFormatSpec, { each: true }) public formats!: ProofFormatSpec[] - @Expose({ name: 'proposals~attach' }) + @Expose({ name: 'request_presentations~attach' }) @Type(() => Attachment) @IsArray() @ValidateNested({ each: true }) @IsInstance(Attachment, { each: true }) - public proposalsAttach!: Attachment[] + public requestPresentationsAttach!: Attachment[] } From 84a2f470314e8bf9ee41816f43eeecf05dc935c0 Mon Sep 17 00:00:00 2001 From: NB-Karim Date: Thu, 27 Jan 2022 21:56:28 +0100 Subject: [PATCH 4/4] feat(proofs): add getter methods to ProofService Signed-off-by: NB-Karim --- .../core/src/modules/proofs/ProofService.ts | 49 ++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/packages/core/src/modules/proofs/ProofService.ts b/packages/core/src/modules/proofs/ProofService.ts index ecf77a60c3..50ca8b8370 100644 --- a/packages/core/src/modules/proofs/ProofService.ts +++ b/packages/core/src/modules/proofs/ProofService.ts @@ -10,7 +10,7 @@ import type { RequestProofOptions, } from './models/ServiceOptions' import type { RetrievedCredentials } from './protocol/v1/models' -import type { ProofRecord } from './repository' +import type { ProofRecord, ProofRepository } from './repository' import type { PresentationRecordType } from './repository/PresentationExchangeRecord' import { ConsoleLogger, LogLevel } from '../../logger' @@ -22,7 +22,14 @@ const logger = new ConsoleLogger(LogLevel.debug) * - stores records * - returns records & messages */ + export abstract class ProofService { + private proofRepository: ProofRepository + + public constructor(proofRepository: ProofRepository) { + this.proofRepository = proofRepository + } + abstract getVersion(): ProofProtocolVersion /** @@ -101,7 +108,45 @@ export abstract class ProofService { throw Error('Not Implemented') } - public getById(proofRecordId: string): Promise { + /** + * Retrieve all proof records + * + * @returns List containing all proof records + */ + public async getAll(): Promise { + return this.proofRepository.getAll() + } + + /** + * Retrieve a proof record by id + * + * @param proofRecordId The proof record id + * @throws {RecordNotFoundError} If no record is found + * @return The proof record + * + */ + public async getById(proofRecordId: string): Promise { return this.proofRepository.getById(proofRecordId) } + + /** + * Retrieve a proof record by id + * + * @param proofRecordId The proof record id + * @return The proof record or null if not found + * + */ + public async findById(proofRecordId: string): Promise { + return this.proofRepository.findById(proofRecordId) + } + + /** + * Delete a proof record by id + * + * @param proofId the proof record id + */ + public async deleteById(proofId: string) { + const proofRecord = await this.getById(proofId) + return this.proofRepository.delete(proofRecord) + } }