Skip to content

Commit 76dab16

Browse files
refactor(proofs): remove ProofProtocolVersion enum in 0.3.0-pre (openwallet-foundation#1062)
Signed-off-by: Mike Richardson <[email protected]>
1 parent 7f37a62 commit 76dab16

22 files changed

+264
-313
lines changed

Diff for: demo/src/Faber.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type BottomBar from 'inquirer/lib/ui/bottom-bar'
55
import {
66
AttributeFilter,
77
ProofAttributeInfo,
8-
ProofProtocolVersion,
98
utils,
109
V1CredentialPreview,
1110
ConnectionEventTypes,
@@ -190,7 +189,7 @@ export class Faber extends BaseAgent {
190189
await this.printProofFlow(greenText('\nRequesting proof...\n', false))
191190

192191
await this.agent.proofs.requestProof({
193-
protocolVersion: ProofProtocolVersion.V1,
192+
protocolVersion: 'v1',
194193
connectionId: connectionRecord.id,
195194
proofFormats: {
196195
indy: {

Diff for: packages/core/src/modules/proofs/ProofsApi.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export class ProofsApi<
164164
* to include in the message
165165
* @returns Proof record associated with the sent proposal message
166166
*/
167-
public async proposeProof(options: ProposeProofOptions): Promise<ProofRecord> {
167+
public async proposeProof(options: ProposeProofOptions<PFs, PSs>): Promise<ProofRecord> {
168168
const service = this.getService(options.protocolVersion)
169169

170170
const { connectionId } = options
@@ -247,7 +247,7 @@ export class ProofsApi<
247247
* @param options multiple properties like connection id, protocol version, proof Formats to build the proof request
248248
* @returns Proof record associated with the sent request message
249249
*/
250-
public async requestProof(options: RequestProofOptions): Promise<ProofRecord> {
250+
public async requestProof(options: RequestProofOptions<PFs, PSs>): Promise<ProofRecord> {
251251
const service = this.getService(options.protocolVersion)
252252

253253
const connection = await this.connectionService.getById(this.agentContext, options.connectionId)
@@ -456,6 +456,7 @@ export class ProofsApi<
456456
/**
457457
* Create a {@link RetrievedCredentials} object. Given input proof request and presentation proposal,
458458
* use credentials in the wallet to build indy requested credentials object for input to proof creation.
459+
*
459460
* If restrictions allow, self attested attributes will be used.
460461
*
461462
* @param options multiple properties like proof record id and optional configuration

Diff for: packages/core/src/modules/proofs/__tests__/V1ProofService.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { IndyLedgerService } from '../../ledger/services'
1818
import { ProofEventTypes } from '../ProofEvents'
1919
import { PresentationProblemReportReason } from '../errors/PresentationProblemReportReason'
2020
import { IndyProofFormatService } from '../formats/indy/IndyProofFormatService'
21-
import { ProofProtocolVersion } from '../models/ProofProtocolVersion'
2221
import { ProofState } from '../models/ProofState'
2322
import { V1ProofService } from '../protocol/v1'
2423
import { INDY_PROOF_REQUEST_ATTACHMENT_ID, V1RequestPresentationMessage } from '../protocol/v1/messages'
@@ -83,7 +82,7 @@ const mockProofRecord = ({
8382
})
8483

8584
const proofRecord = new ProofRecord({
86-
protocolVersion: ProofProtocolVersion.V1,
85+
protocolVersion: 'v1',
8786
id,
8887
state: state || ProofState.RequestSent,
8988
threadId: threadId ?? requestPresentationMessage.id,

Diff for: packages/core/src/modules/proofs/__tests__/V2ProofService.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { ProofEventTypes } from '../ProofEvents'
1616
import { PresentationProblemReportReason } from '../errors/PresentationProblemReportReason'
1717
import { V2_INDY_PRESENTATION, V2_INDY_PRESENTATION_REQUEST } from '../formats/ProofFormatConstants'
1818
import { IndyProofFormatService } from '../formats/indy/IndyProofFormatService'
19-
import { ProofProtocolVersion } from '../models/ProofProtocolVersion'
2019
import { ProofState } from '../models/ProofState'
2120
import { V2ProofService } from '../protocol/v2/V2ProofService'
2221
import { V2PresentationProblemReportMessage, V2RequestPresentationMessage } from '../protocol/v2/messages'
@@ -85,7 +84,7 @@ const mockProofRecord = ({
8584
})
8685

8786
const proofRecord = new ProofRecord({
88-
protocolVersion: ProofProtocolVersion.V2,
87+
protocolVersion: 'v2',
8988
id,
9089
state: state || ProofState.RequestSent,
9190
threadId: threadId ?? requestPresentationMessage.id,

Diff for: packages/core/src/modules/proofs/models/ProofProtocolVersion.ts

-4
This file was deleted.

Diff for: packages/core/src/modules/proofs/models/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export * from './GetRequestedCredentialsConfig'
22
export * from './ProofAutoAcceptType'
3-
export * from './ProofProtocolVersion'
43
export * from './ProofState'

Diff for: packages/core/src/modules/proofs/protocol/v1/V1ProofService.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ import { IndyProofFormatService } from '../../formats/indy/IndyProofFormatServic
5555
import { IndyProofUtils } from '../../formats/indy/IndyProofUtils'
5656
import { ProofRequest } from '../../formats/indy/models/ProofRequest'
5757
import { RequestedCredentials } from '../../formats/indy/models/RequestedCredentials'
58-
import { ProofProtocolVersion } from '../../models/ProofProtocolVersion'
5958
import { ProofState } from '../../models/ProofState'
6059
import { ProofRecord } from '../../repository/ProofRecord'
6160
import { ProofRepository } from '../../repository/ProofRepository'
@@ -148,7 +147,7 @@ export class V1ProofService extends ProofService<[IndyProofFormat]> {
148147
parentThreadId: proposalMessage.thread?.parentThreadId,
149148
state: ProofState.ProposalSent,
150149
autoAcceptProof: options?.autoAcceptProof,
151-
protocolVersion: ProofProtocolVersion.V1,
150+
protocolVersion: 'v1',
152151
})
153152

154153
await this.didCommMessageRepository.saveOrUpdateAgentMessage(agentContext, {
@@ -244,7 +243,7 @@ export class V1ProofService extends ProofService<[IndyProofFormat]> {
244243
threadId: proposalMessage.threadId,
245244
parentThreadId: proposalMessage.thread?.parentThreadId,
246245
state: ProofState.ProposalReceived,
247-
protocolVersion: ProofProtocolVersion.V1,
246+
protocolVersion: 'v1',
248247
})
249248

250249
// Assert
@@ -337,7 +336,7 @@ export class V1ProofService extends ProofService<[IndyProofFormat]> {
337336
parentThreadId: requestPresentationMessage.thread?.parentThreadId,
338337
state: ProofState.RequestSent,
339338
autoAcceptProof: options?.autoAcceptProof,
340-
protocolVersion: ProofProtocolVersion.V1,
339+
protocolVersion: 'v1',
341340
})
342341

343342
await this.didCommMessageRepository.saveOrUpdateAgentMessage(agentContext, {
@@ -424,7 +423,7 @@ export class V1ProofService extends ProofService<[IndyProofFormat]> {
424423
threadId: proofRequestMessage.threadId,
425424
parentThreadId: proofRequestMessage.thread?.parentThreadId,
426425
state: ProofState.RequestReceived,
427-
protocolVersion: ProofProtocolVersion.V1,
426+
protocolVersion: 'v1',
428427
})
429428

430429
await this.didCommMessageRepository.saveOrUpdateAgentMessage(messageContext.agentContext, {

Diff for: packages/core/src/modules/proofs/protocol/v1/__tests__/indy-proof-presentation.test.ts

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type { PresentationPreview } from '../models/V1PresentationPreview'
66
import { setupProofsTest, waitForProofRecord } from '../../../../../../tests/helpers'
77
import testLogger from '../../../../../../tests/logger'
88
import { DidCommMessageRepository } from '../../../../../storage/didcomm'
9-
import { ProofProtocolVersion } from '../../../models/ProofProtocolVersion'
109
import { ProofState } from '../../../models/ProofState'
1110
import { V1PresentationMessage, V1ProposePresentationMessage, V1RequestPresentationMessage } from '../messages'
1211

@@ -44,7 +43,7 @@ describe('Present Proof', () => {
4443

4544
aliceProofRecord = await aliceAgent.proofs.proposeProof({
4645
connectionId: aliceConnection.id,
47-
protocolVersion: ProofProtocolVersion.V1,
46+
protocolVersion: 'v1',
4847
proofFormats: {
4948
indy: {
5049
name: 'ProofRequest',
@@ -100,7 +99,7 @@ describe('Present Proof', () => {
10099
id: expect.anything(),
101100
threadId: faberProofRecord.threadId,
102101
state: ProofState.ProposalReceived,
103-
protocolVersion: ProofProtocolVersion.V1,
102+
protocolVersion: 'v1',
104103
})
105104
})
106105

@@ -146,7 +145,7 @@ describe('Present Proof', () => {
146145
id: expect.anything(),
147146
threadId: faberProofRecord.threadId,
148147
state: ProofState.RequestReceived,
149-
protocolVersion: ProofProtocolVersion.V1,
148+
protocolVersion: 'v1',
150149
})
151150
})
152151

@@ -207,7 +206,7 @@ describe('Present Proof', () => {
207206
expect(faberProofRecord).toMatchObject({
208207
threadId: faberProofRecord.threadId,
209208
state: ProofState.PresentationReceived,
210-
protocolVersion: ProofProtocolVersion.V1,
209+
protocolVersion: 'v1',
211210
})
212211
})
213212

Diff for: packages/core/src/modules/proofs/protocol/v1/__tests__/indy-proof-proposal.test.ts

+9-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type { Agent } from '../../../../../agent/Agent'
22
import type { ConnectionRecord } from '../../../../connections/repository/ConnectionRecord'
33
import type { ProposeProofOptions } from '../../../ProofsApiOptions'
4+
import type { IndyProofFormat } from '../../../formats/indy/IndyProofFormat'
45
import type { ProofRecord } from '../../../repository/ProofRecord'
6+
import type { V1ProofService } from '../V1ProofService'
57
import type { PresentationPreview } from '../models/V1PresentationPreview'
68

79
import { setupProofsTest, waitForProofRecord } from '../../../../../../tests/helpers'
810
import testLogger from '../../../../../../tests/logger'
911
import { DidCommMessageRepository } from '../../../../../storage'
10-
import { ProofProtocolVersion } from '../../../models/ProofProtocolVersion'
1112
import { ProofState } from '../../../models/ProofState'
1213
import { V1ProposePresentationMessage } from '../messages'
1314

@@ -38,9 +39,13 @@ describe('Present Proof', () => {
3839
test(`Alice Creates and sends Proof Proposal to Faber`, async () => {
3940
testLogger.test('Alice sends proof proposal to Faber')
4041

41-
const proposeOptions: ProposeProofOptions = {
42+
const faberProofRecordPromise = waitForProofRecord(faberAgent, {
43+
state: ProofState.ProposalReceived,
44+
})
45+
46+
await aliceAgent.proofs.proposeProof({
4247
connectionId: aliceConnection.id,
43-
protocolVersion: ProofProtocolVersion.V1,
48+
protocolVersion: 'v1',
4449
proofFormats: {
4550
indy: {
4651
name: 'ProofRequest',
@@ -51,14 +56,8 @@ describe('Present Proof', () => {
5156
},
5257
},
5358
comment: 'V1 propose proof test',
54-
}
55-
56-
const faberProofRecordPromise = waitForProofRecord(faberAgent, {
57-
state: ProofState.ProposalReceived,
5859
})
5960

60-
await aliceAgent.proofs.proposeProof(proposeOptions)
61-
6261
testLogger.test('Faber waits for presentation from Alice')
6362
faberProofRecord = await faberProofRecordPromise
6463

@@ -102,7 +101,7 @@ describe('Present Proof', () => {
102101
id: expect.anything(),
103102
threadId: faberProofRecord.threadId,
104103
state: ProofState.ProposalReceived,
105-
protocolVersion: ProofProtocolVersion.V1,
104+
protocolVersion: 'v1',
106105
})
107106
})
108107
})

Diff for: packages/core/src/modules/proofs/protocol/v1/__tests__/indy-proof-request.test.ts

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type { Agent } from '../../../../../agent/Agent'
22
import type { ConnectionRecord } from '../../../../connections/repository/ConnectionRecord'
3-
import type { ProposeProofOptions, AcceptProposalOptions } from '../../../ProofsApiOptions'
3+
import type { AcceptProposalOptions, ProposeProofOptions } from '../../../ProofsApiOptions'
4+
import type { IndyProofFormat } from '../../../formats/indy/IndyProofFormat'
45
import type { ProofRecord } from '../../../repository/ProofRecord'
6+
import type { V1ProofService } from '../V1ProofService'
57
import type { PresentationPreview } from '../models/V1PresentationPreview'
68

79
import { setupProofsTest, waitForProofRecord } from '../../../../../../tests/helpers'
810
import testLogger from '../../../../../../tests/logger'
911
import { DidCommMessageRepository } from '../../../../../storage/didcomm'
10-
import { ProofProtocolVersion } from '../../../models/ProofProtocolVersion'
1112
import { ProofState } from '../../../models/ProofState'
1213
import { V1ProposePresentationMessage, V1RequestPresentationMessage } from '../messages'
1314

@@ -39,9 +40,13 @@ describe('Present Proof', () => {
3940
test(`Alice Creates and sends Proof Proposal to Faber`, async () => {
4041
testLogger.test('Alice sends proof proposal to Faber')
4142

42-
const proposeOptions: ProposeProofOptions = {
43+
const faberProofRecordPromise = waitForProofRecord(faberAgent, {
44+
state: ProofState.ProposalReceived,
45+
})
46+
47+
aliceProofRecord = await aliceAgent.proofs.proposeProof({
4348
connectionId: aliceConnection.id,
44-
protocolVersion: ProofProtocolVersion.V1,
49+
protocolVersion: 'v1',
4550
proofFormats: {
4651
indy: {
4752
name: 'ProofRequest',
@@ -52,14 +57,8 @@ describe('Present Proof', () => {
5257
},
5358
},
5459
comment: 'V1 propose proof test',
55-
}
56-
57-
const faberProofRecordPromise = waitForProofRecord(faberAgent, {
58-
state: ProofState.ProposalReceived,
5960
})
6061

61-
aliceProofRecord = await aliceAgent.proofs.proposeProof(proposeOptions)
62-
6362
testLogger.test('Faber waits for presentation from Alice')
6463
faberProofRecord = await faberProofRecordPromise
6564

@@ -102,7 +101,7 @@ describe('Present Proof', () => {
102101
id: expect.anything(),
103102
threadId: faberProofRecord.threadId,
104103
state: ProofState.ProposalReceived,
105-
protocolVersion: ProofProtocolVersion.V1,
104+
protocolVersion: 'v1',
106105
})
107106
})
108107

@@ -150,7 +149,7 @@ describe('Present Proof', () => {
150149
id: expect.anything(),
151150
threadId: faberProofRecord.threadId,
152151
state: ProofState.RequestReceived,
153-
protocolVersion: ProofProtocolVersion.V1,
152+
protocolVersion: 'v1',
154153
})
155154
})
156155
})

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import { PresentationProblemReportReason } from '../../errors/PresentationProble
4242
import { V2_INDY_PRESENTATION_REQUEST } from '../../formats/ProofFormatConstants'
4343
import { IndyProofFormatService } from '../../formats/indy/IndyProofFormatService'
4444
import { IndyProofUtils } from '../../formats/indy/IndyProofUtils'
45-
import { ProofProtocolVersion } from '../../models/ProofProtocolVersion'
4645
import { ProofState } from '../../models/ProofState'
4746
import { PresentationRecordType, ProofRecord, ProofRepository } from '../../repository'
4847

@@ -114,7 +113,7 @@ export class V2ProofService<PFs extends ProofFormat[] = ProofFormat[]> extends P
114113
threadId: proposalMessage.threadId,
115114
parentThreadId: proposalMessage.thread?.parentThreadId,
116115
state: ProofState.ProposalSent,
117-
protocolVersion: ProofProtocolVersion.V2,
116+
protocolVersion: 'v2',
118117
})
119118

120119
await this.proofRepository.save(agentContext, proofRecord)
@@ -214,7 +213,7 @@ export class V2ProofService<PFs extends ProofFormat[] = ProofFormat[]> extends P
214213
threadId: proposalMessage.threadId,
215214
parentThreadId: proposalMessage.thread?.parentThreadId,
216215
state: ProofState.ProposalReceived,
217-
protocolVersion: ProofProtocolVersion.V2,
216+
protocolVersion: 'v2',
218217
})
219218

220219
// Assert
@@ -264,7 +263,7 @@ export class V2ProofService<PFs extends ProofFormat[] = ProofFormat[]> extends P
264263
threadId: requestMessage.threadId,
265264
parentThreadId: requestMessage.thread?.parentThreadId,
266265
state: ProofState.RequestSent,
267-
protocolVersion: ProofProtocolVersion.V2,
266+
protocolVersion: 'v2',
268267
})
269268

270269
await this.proofRepository.save(agentContext, proofRecord)
@@ -397,7 +396,7 @@ export class V2ProofService<PFs extends ProofFormat[] = ProofFormat[]> extends P
397396
threadId: proofRequestMessage.threadId,
398397
parentThreadId: proofRequestMessage.thread?.parentThreadId,
399398
state: ProofState.RequestReceived,
400-
protocolVersion: ProofProtocolVersion.V2,
399+
protocolVersion: 'v2',
401400
})
402401

403402
await this.didCommMessageRepository.saveOrUpdateAgentMessage(messageContext.agentContext, {

0 commit comments

Comments
 (0)