Skip to content

Commit

Permalink
feat(proofs): add v2 message types
Browse files Browse the repository at this point in the history
Signed-off-by: NB-Karim <[email protected]>
  • Loading branch information
NB-KarimStekelenburg committed Jan 25, 2022
1 parent 1f8b369 commit 20a8da6
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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[]
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -58,5 +58,5 @@ export class V2ProposalPresentationMessage extends AgentMessage {
@IsInstance(PresentationPreview)
public presentationProposal!: PresentationPreview

public formats!: V2ProofFormatSpec
public formats!: ProofFormatSpec
}
Original file line number Diff line number Diff line change
@@ -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[]
}

0 comments on commit 20a8da6

Please sign in to comment.