Skip to content

Commit 9d8791a

Browse files
Merge pull request #3 from hyperledger/feat/present-proof-v2
Feat/present proof v2
2 parents 7e03954 + 4a201c1 commit 9d8791a

File tree

5 files changed

+233
-37
lines changed

5 files changed

+233
-37
lines changed

packages/core/src/modules/proofs/ProofService.ts

+47-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type {
1010
RequestProofOptions,
1111
} from './models/ServiceOptions'
1212
import type { RetrievedCredentials } from './protocol/v1/models'
13-
import type { ProofRecord } from './repository'
13+
import type { ProofRecord, ProofRepository } from './repository'
1414
import type { PresentationRecordType } from './repository/PresentationExchangeRecord'
1515

1616
import { ConsoleLogger, LogLevel } from '../../logger'
@@ -22,7 +22,14 @@ const logger = new ConsoleLogger(LogLevel.debug)
2222
* - stores records
2323
* - returns records & messages
2424
*/
25+
2526
export abstract class ProofService {
27+
private proofRepository: ProofRepository
28+
29+
public constructor(proofRepository: ProofRepository) {
30+
this.proofRepository = proofRepository
31+
}
32+
2633
abstract getVersion(): ProofProtocolVersion
2734

2835
/**
@@ -101,7 +108,45 @@ export abstract class ProofService {
101108
throw Error('Not Implemented')
102109
}
103110

104-
public getById(proofRecordId: string): Promise<ProofRecord> {
111+
/**
112+
* Retrieve all proof records
113+
*
114+
* @returns List containing all proof records
115+
*/
116+
public async getAll(): Promise<ProofRecord[]> {
117+
return this.proofRepository.getAll()
118+
}
119+
120+
/**
121+
* Retrieve a proof record by id
122+
*
123+
* @param proofRecordId The proof record id
124+
* @throws {RecordNotFoundError} If no record is found
125+
* @return The proof record
126+
*
127+
*/
128+
public async getById(proofRecordId: string): Promise<ProofRecord> {
105129
return this.proofRepository.getById(proofRecordId)
106130
}
131+
132+
/**
133+
* Retrieve a proof record by id
134+
*
135+
* @param proofRecordId The proof record id
136+
* @return The proof record or null if not found
137+
*
138+
*/
139+
public async findById(proofRecordId: string): Promise<ProofRecord | null> {
140+
return this.proofRepository.findById(proofRecordId)
141+
}
142+
143+
/**
144+
* Delete a proof record by id
145+
*
146+
* @param proofId the proof record id
147+
*/
148+
public async deleteById(proofId: string) {
149+
const proofRecord = await this.getById(proofId)
150+
return this.proofRepository.delete(proofRecord)
151+
}
107152
}

packages/core/src/modules/proofs/protocol/v2/messages/PresentationAckMessageV2.ts 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,70 @@
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+
willConfirm?: boolean
17+
attachmentInfo: ProofAttachmentFormat[]
18+
}
19+
20+
export class V2PresentationMessage extends AgentMessage {
21+
public constructor(options: V2PresentationMessageOptions) {
22+
super()
23+
if (options) {
24+
this.id = options.id ?? uuid()
25+
this.comment = options.comment
26+
this.goalCode = options.goalCode
27+
this.willConfirm = options.willConfirm ?? false
28+
29+
for (const entry of options.attachmentInfo) {
30+
this.addPresentationsAttachment(entry)
31+
}
32+
}
33+
}
34+
35+
public addPresentationsAttachment(attachment: ProofAttachmentFormat) {
36+
this.formats.push(attachment.format)
37+
this.presentationsAttach.push(attachment.attachment)
38+
}
39+
40+
@Equals(V2PresentationMessage.type)
41+
public readonly type = V2PresentationMessage.type
42+
public static readonly type = 'https://didcomm.org/present-proof/2.0/presentation'
43+
44+
@IsString()
45+
@IsOptional()
46+
public comment?: string
47+
48+
@Expose({ name: 'goal_code' })
49+
@IsString()
50+
@IsOptional()
51+
public goalCode?: string
52+
53+
@Expose({ name: 'will_confirm' })
54+
@IsBoolean()
55+
public willConfirm = false
56+
57+
@Expose({ name: 'formats' })
58+
@Type(() => ProofFormatSpec)
59+
@IsArray()
60+
@ValidateNested({ each: true })
61+
@IsInstance(ProofFormatSpec, { each: true })
62+
public formats!: ProofFormatSpec[]
63+
64+
@Expose({ name: 'presentations~attach' })
65+
@Type(() => Attachment)
66+
@IsArray()
67+
@ValidateNested({ each: true })
68+
@IsInstance(Attachment, { each: true })
69+
public presentationsAttach!: Attachment[]
70+
}
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
import type { V2ProofFormatSpec } from '../formats/V2ProofFormat'
1+
import type { ProofAttachmentFormat } from '../../../formats/models/ProofFormatServiceOptions'
22

33
import { Expose, Type } from 'class-transformer'
4-
import { Equals, IsArray, IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator'
4+
import { Equals, IsArray, IsBoolean, 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'
9-
import { PresentationPreview } from '../../v1/models/PresentationPreview'
10-
import { PRES_20_PROPOSAL } from '../formats/MessageTypes'
8+
import { ProofFormatSpec } from '../../../formats/models/ProofFormatServiceOptions'
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
17-
presentationProposal: PresentationPreview
17+
goalCode?: string
18+
willConfirm?: boolean
19+
attachmentInfo: ProofAttachmentFormat[]
1820
}
1921

2022
export class V2ProposalPresentationMessage extends AgentMessage {
@@ -23,40 +25,48 @@ export class V2ProposalPresentationMessage extends AgentMessage {
2325
if (options) {
2426
this.id = options.id ?? uuid()
2527
this.comment = options.comment
26-
this.presentationProposal = options.presentationProposal
27-
this.formats = options.formats
28-
this.filtersAttach = options.filtersAttach
28+
this.goalCode = options.goalCode
29+
this.willConfirm = options.willConfirm ?? false
30+
31+
for (const entry of options.attachmentInfo) {
32+
this.addProposalsAttachment(entry)
33+
}
2934
}
3035
}
3136

37+
public addProposalsAttachment(attachment: ProofAttachmentFormat) {
38+
this.formats.push(attachment.format)
39+
this.proposalsAttach.push(attachment.attachment)
40+
}
41+
3242
@Equals(V2ProposalPresentationMessage.type)
3343
public readonly type = V2ProposalPresentationMessage.type
34-
public static readonly type = `https://didcomm.org/${PRES_20_PROPOSAL}`
35-
36-
@Expose({ name: 'filters~attach' })
37-
@Type(() => Attachment)
38-
@IsArray()
39-
@ValidateNested({
40-
each: true,
41-
})
42-
@IsInstance(Attachment, { each: true })
43-
public filtersAttach!: Attachment[]
44+
public static readonly type = `https://didcomm.org/present-proof/2.0/propose-presentation`
4445

45-
/**
46-
* Provides some human readable information about the proposed presentation.
47-
*/
4846
@IsString()
4947
@IsOptional()
5048
public comment?: string
5149

52-
/**
53-
* Represents the presentation example that prover wants to provide.
54-
*/
55-
@Expose({ name: 'presentation_proposal' })
56-
@Type(() => PresentationPreview)
57-
@ValidateNested()
58-
@IsInstance(PresentationPreview)
59-
public presentationProposal!: PresentationPreview
50+
@Expose({ name: 'goal_code' })
51+
@IsString()
52+
@IsOptional()
53+
public goalCode?: string
54+
55+
@Expose({ name: 'will_confirm' })
56+
@IsBoolean()
57+
public willConfirm = false
58+
59+
@Expose({ name: 'formats' })
60+
@Type(() => ProofFormatSpec)
61+
@IsArray()
62+
@ValidateNested({ each: true })
63+
@IsInstance(ProofFormatSpec, { each: true })
64+
public formats!: ProofFormatSpec[]
6065

61-
public formats!: V2ProofFormatSpec
66+
@Expose({ name: 'proposals~attach' })
67+
@Type(() => Attachment)
68+
@IsArray()
69+
@ValidateNested({ each: true })
70+
@IsInstance(Attachment, { each: true })
71+
public proposalsAttach!: Attachment[]
6272
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
comment?: string
15+
goalCode?: string
16+
willConfirm?: boolean
17+
attachmentInfo: ProofAttachmentFormat[]
18+
}
19+
20+
export class V2RequestPresentationMessage extends AgentMessage {
21+
public constructor(options: V2RequestPresentationMessageOptions) {
22+
super()
23+
if (options) {
24+
this.id = options.id ?? uuid()
25+
this.comment = options.comment
26+
this.goalCode = options.goalCode
27+
this.willConfirm = options.willConfirm ?? false
28+
29+
for (const entry of options.attachmentInfo) {
30+
this.addRequestPresentationsAttachment(entry)
31+
}
32+
}
33+
}
34+
35+
public addRequestPresentationsAttachment(attachment: ProofAttachmentFormat) {
36+
this.formats.push(attachment.format)
37+
this.requestPresentationsAttach.push(attachment.attachment)
38+
}
39+
40+
@Equals(V2RequestPresentationMessage.type)
41+
public readonly type = V2RequestPresentationMessage.type
42+
public static readonly type = 'https://didcomm.org/present-proof/2.0/request-presentation'
43+
44+
@IsString()
45+
@IsOptional()
46+
public comment?: string
47+
48+
@Expose({ name: 'goal_code' })
49+
@IsString()
50+
@IsOptional()
51+
public goalCode?: string
52+
53+
@Expose({ name: 'will_confirm' })
54+
@IsBoolean()
55+
public willConfirm = false
56+
57+
@Expose({ name: 'formats' })
58+
@Type(() => ProofFormatSpec)
59+
@IsArray()
60+
@ValidateNested({ each: true })
61+
@IsInstance(ProofFormatSpec, { each: true })
62+
public formats!: ProofFormatSpec[]
63+
64+
@Expose({ name: 'request_presentations~attach' })
65+
@Type(() => Attachment)
66+
@IsArray()
67+
@ValidateNested({ each: true })
68+
@IsInstance(Attachment, { each: true })
69+
public requestPresentationsAttach!: Attachment[]
70+
}

0 commit comments

Comments
 (0)