From 20a8da6433cc432721ab78e3abc49dd41f19488d Mon Sep 17 00:00:00 2001 From: NB-Karim Date: Tue, 25 Jan 2022 17:30:38 +0100 Subject: [PATCH] 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[] +}