Skip to content

Commit 20a8da6

Browse files
feat(proofs): add v2 message types
Signed-off-by: NB-Karim <[email protected]>
1 parent 1f8b369 commit 20a8da6

File tree

4 files changed

+145
-8
lines changed

4 files changed

+145
-8
lines changed

Diff for: packages/core/src/modules/proofs/protocol/v2/messages/PresentationAckMessageV2.ts renamed to packages/core/src/modules/proofs/protocol/v2/messages/V2PresentationAckMessage.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import type { PresentationAckMessage, PresentationAckMessageOptions } from '../../../messages/PresentationAckMessage'
2+
13
import { Equals } from 'class-validator'
2-
import { PresentationAckMessageOptions } from '../..'
3-
import { AckMessage } from '../../../common'
4-
import { PresentationAckMessage } from '../../messages/PresentationAckMessage'
4+
5+
import { AckMessage } from 'packages/core/src/modules/common'
56

67
/**
78
* @see https://github.com/hyperledger/aries-rfcs/blob/master/features/0015-acks/README.md#explicit-acks
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import type { ProofAttachmentFormat } from '../../../formats/ProofFormatService'
2+
3+
import { Expose, Type } from 'class-transformer'
4+
import { Equals, IsArray, IsBoolean, IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator'
5+
6+
import { ProofFormatSpec } from '../../../formats/models/ProofFormatServiceOptions'
7+
8+
import { AgentMessage } from '@aries-framework/core'
9+
import { Attachment } from 'packages/core/src/decorators/attachment/Attachment'
10+
import { uuid } from 'packages/core/src/utils/uuid'
11+
12+
export interface V2PresentationMessageOptions {
13+
id?: string
14+
goalCode?: string
15+
comment?: string
16+
attachmentInfo: ProofAttachmentFormat[]
17+
}
18+
19+
export class V2PresentationMessage extends AgentMessage {
20+
public constructor(options: V2PresentationMessageOptions) {
21+
super()
22+
if (options) {
23+
this.id = options.id ?? uuid()
24+
this.comment = options.comment
25+
this.goalCode = options.goalCode
26+
27+
for (const entry of options.attachmentInfo) {
28+
this.addPresentationsAttachment(entry)
29+
}
30+
}
31+
}
32+
33+
public addPresentationsAttachment(attachment: ProofAttachmentFormat) {
34+
this.formats.push(attachment.format)
35+
this.presentationsAttach.push(attachment.attachment)
36+
}
37+
38+
@Equals(V2PresentationMessage.type)
39+
public readonly type = V2PresentationMessage.type
40+
public static readonly type = 'https://didcomm.org/present-proof/2.0/presentation'
41+
42+
@IsString()
43+
@IsOptional()
44+
public comment?: string
45+
46+
@Expose({ name: 'goal_code' })
47+
@IsString()
48+
@IsOptional()
49+
public goalCode?: string
50+
51+
@Expose({ name: 'will_confirm' })
52+
@IsBoolean()
53+
public willConfirm = false
54+
55+
@Expose({ name: 'formats' })
56+
@Type(() => ProofFormatSpec)
57+
@IsArray()
58+
@ValidateNested({ each: true })
59+
@IsInstance(ProofFormatSpec, { each: true })
60+
public formats!: ProofFormatSpec[]
61+
62+
@Expose({ name: 'presentations~attach' })
63+
@Type(() => Attachment)
64+
@IsArray()
65+
@ValidateNested({ each: true })
66+
@IsInstance(Attachment, { each: true })
67+
public presentationsAttach!: Attachment[]
68+
}

Diff for: packages/core/src/modules/proofs/protocol/v2/messages/V2ProposalPresentationMessage.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import type { V2ProofFormatSpec } from '../formats/V2ProofFormat'
1+
import type { ProofFormatSpec } from '../../../formats/models/ProofFormatServiceOptions'
22

33
import { Expose, Type } from 'class-transformer'
44
import { Equals, IsArray, IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator'
55

66
import { AgentMessage } from '../../../../../agent/AgentMessage'
7-
import { Attachment } from '../../../../../decorators/attachment/Attachment'
87
import { uuid } from '../../../../../utils/uuid'
98
import { PresentationPreview } from '../../v1/models/PresentationPreview'
10-
import { PRES_20_PROPOSAL } from '../formats/MessageTypes'
9+
10+
import { Attachment } from 'packages/core/src/decorators/attachment/Attachment'
1111

1212
export interface V2ProposePresentationMessageOptions {
1313
id?: string
14-
formats: V2ProofFormatSpec
14+
formats: ProofFormatSpec
1515
filtersAttach: Attachment[]
1616
comment?: string
1717
presentationProposal: PresentationPreview
@@ -58,5 +58,5 @@ export class V2ProposalPresentationMessage extends AgentMessage {
5858
@IsInstance(PresentationPreview)
5959
public presentationProposal!: PresentationPreview
6060

61-
public formats!: V2ProofFormatSpec
61+
public formats!: ProofFormatSpec
6262
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import type { ProofAttachmentFormat } from '../../../formats/ProofFormatService'
2+
3+
import { Expose, Type } from 'class-transformer'
4+
import { Equals, IsArray, IsBoolean, IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator'
5+
6+
import { ProofFormatSpec } from '../../../formats/models/ProofFormatServiceOptions'
7+
8+
import { AgentMessage } from '@aries-framework/core'
9+
import { Attachment } from 'packages/core/src/decorators/attachment/Attachment'
10+
import { uuid } from 'packages/core/src/utils/uuid'
11+
12+
export interface V2RequestPresentationMessageOptions {
13+
id?: string
14+
goalCode?: string
15+
comment?: string
16+
attachmentInfo: ProofAttachmentFormat[]
17+
}
18+
19+
export class V2RequestPresentationMessage extends AgentMessage {
20+
public constructor(options: V2RequestPresentationMessageOptions) {
21+
super()
22+
if (options) {
23+
this.id = options.id ?? uuid()
24+
this.comment = options.comment
25+
this.goalCode = options.goalCode
26+
27+
for (const entry of options.attachmentInfo) {
28+
this.addProposalsAttachment(entry)
29+
}
30+
}
31+
}
32+
33+
public addProposalsAttachment(attachment: ProofAttachmentFormat) {
34+
this.formats.push(attachment.format)
35+
this.proposalsAttach.push(attachment.attachment)
36+
}
37+
38+
@Equals(V2RequestPresentationMessage.type)
39+
public readonly type = V2RequestPresentationMessage.type
40+
public static readonly type = 'https://didcomm.org/present-proof/2.0/request-presentation'
41+
42+
@IsString()
43+
@IsOptional()
44+
public comment?: string
45+
46+
@Expose({ name: 'goal_code' })
47+
@IsString()
48+
@IsOptional()
49+
public goalCode?: string
50+
51+
@Expose({ name: 'will_confirm' })
52+
@IsBoolean()
53+
public willConfirm = false
54+
55+
@Expose({ name: 'formats' })
56+
@Type(() => ProofFormatSpec)
57+
@IsArray()
58+
@ValidateNested({ each: true })
59+
@IsInstance(ProofFormatSpec, { each: true })
60+
public formats!: ProofFormatSpec[]
61+
62+
@Expose({ name: 'proposals~attach' })
63+
@Type(() => Attachment)
64+
@IsArray()
65+
@ValidateNested({ each: true })
66+
@IsInstance(Attachment, { each: true })
67+
public proposalsAttach!: Attachment[]
68+
}

0 commit comments

Comments
 (0)