@@ -4,19 +4,23 @@ import type { ProofRecord } from './repository'
4
4
import type { RetrievedCredentials } from './v1/models'
5
5
import type {
6
6
AcceptProposalOptions ,
7
+ CreateRequestOptions ,
7
8
ProofRequestAsResponse ,
8
9
ProofRequestsOptions ,
9
10
ProposeProofOptions ,
11
+ RequestProofOptions ,
10
12
} from './v2/interface'
11
13
12
- import { Lifecycle , scoped } from 'tsyringe'
14
+ import { inject , Lifecycle , scoped } from 'tsyringe'
13
15
14
16
import { AgentConfig } from '../../agent/AgentConfig'
15
17
import { Dispatcher } from '../../agent/Dispatcher'
16
18
import { EventEmitter } from '../../agent/EventEmitter'
17
19
import { MessageSender } from '../../agent/MessageSender'
18
20
import { createOutboundMessage } from '../../agent/helpers'
21
+ import { InjectionSymbols } from '../../constants'
19
22
import { AriesFrameworkError } from '../../error/AriesFrameworkError'
23
+ import { Wallet } from '../../wallet/Wallet'
20
24
import { ConnectionService } from '../connections/services/ConnectionService'
21
25
import { IndyHolderService } from '../indy'
22
26
import { MediationRecipientService } from '../routing'
@@ -29,11 +33,14 @@ import { ProofsModule } from './ProofsModule'
29
33
import { ProofRepository } from './repository'
30
34
import { V1LegacyProofService } from './v1/V1LegacyProofService'
31
35
import { V1ProofService } from './v1/V1ProofService'
36
+ import { ProofRequest } from './v1/models'
32
37
import { ProofRole } from './v2/ProofRole'
33
38
import { V2ProofService } from './v2/V2ProofService'
34
39
35
40
export interface ProofsAPI {
36
41
proposeProof ( proofOptions : ProposeProofOptions ) : Promise < PresentationExchangeRecord >
42
+ acceptProposal ( acceptProposalOptions : AcceptProposalOptions ) : Promise < ProofRecord >
43
+ requestProof ( requestProofOptions : RequestProofOptions ) : Promise < ProofRecord >
37
44
getById ( proofRecordId : string ) : Promise < ProofRecord >
38
45
}
39
46
@@ -51,6 +58,7 @@ export class ProofsAPI extends ProofsModule implements ProofsAPI {
51
58
private v2Service : V2ProofService
52
59
private serviceMap : { '1.0' : V1ProofService ; '2.0' : V2ProofService }
53
60
private indyHolderService : IndyHolderService
61
+ private wallet : Wallet
54
62
55
63
public constructor (
56
64
dispatcher : Dispatcher ,
@@ -62,7 +70,8 @@ export class ProofsAPI extends ProofsModule implements ProofsAPI {
62
70
v1ProofService : V1LegacyProofService ,
63
71
proofRepository : ProofRepository ,
64
72
eventEmitter : EventEmitter ,
65
- indyHolderService : IndyHolderService
73
+ indyHolderService : IndyHolderService ,
74
+ @inject ( InjectionSymbols . Wallet ) wallet : Wallet
66
75
) {
67
76
super (
68
77
dispatcher ,
@@ -82,6 +91,7 @@ export class ProofsAPI extends ProofsModule implements ProofsAPI {
82
91
this . agntConfig = agentConfig
83
92
this . proofResponseCoord = proofResponseCoordinator
84
93
this . indyHolderService = indyHolderService
94
+ this . wallet = wallet
85
95
this . v1Service = new V1ProofService ( this . v1ProofService , this . connService )
86
96
this . v2Service = new V2ProofService (
87
97
this . proofRepository ,
@@ -90,6 +100,7 @@ export class ProofsAPI extends ProofsModule implements ProofsAPI {
90
100
this . agntConfig ,
91
101
this . dispatcher ,
92
102
this . proofResponseCoord ,
103
+ this . wallet ,
93
104
this . indyHolderService
94
105
)
95
106
@@ -120,8 +131,8 @@ export class ProofsAPI extends ProofsModule implements ProofsAPI {
120
131
121
132
const recordBinding : PresentationRecordBinding = {
122
133
presentationRecordType : proofOptions . proofFormats ?. indy
123
- ? PresentationRecordType . INDY
124
- : PresentationRecordType . W3C ,
134
+ ? PresentationRecordType . Indy
135
+ : PresentationRecordType . W3c ,
125
136
presentationRecordId : proofRecord . id ,
126
137
}
127
138
@@ -139,7 +150,7 @@ export class ProofsAPI extends ProofsModule implements ProofsAPI {
139
150
return presentationExchangeRecord
140
151
}
141
152
142
- public async acceptProof ( acceptProposalOptions : AcceptProposalOptions ) : Promise < ProofRecord > {
153
+ public async acceptProposal ( acceptProposalOptions : AcceptProposalOptions ) : Promise < ProofRecord > {
143
154
const version : ProofProtocolVersion = acceptProposalOptions . protocolVersion
144
155
145
156
const service : ProofService = this . getService ( version )
@@ -208,6 +219,44 @@ export class ProofsAPI extends ProofsModule implements ProofsAPI {
208
219
return service . getRequestedCredentialsForProofRequest ( indyProofRequest , presentationPreview )
209
220
}
210
221
222
+ public async requestProof ( requestProofOptions : RequestProofOptions ) : Promise < ProofRecord > {
223
+ const version : ProofProtocolVersion = requestProofOptions . protocolVersion
224
+
225
+ const { proofRequestOptions } = requestProofOptions
226
+
227
+ const service : ProofService = this . getService ( version )
228
+
229
+ const connection = await this . connService . getById ( requestProofOptions . connectionId )
230
+
231
+ const nonce = proofRequestOptions . nonce ?? ( await this . generateProofRequestNonce ( ) )
232
+
233
+ const proofRequest = new ProofRequest ( {
234
+ name : proofRequestOptions . name ?? 'proof-request' ,
235
+ version : proofRequestOptions . name ?? '1.0' ,
236
+ nonce,
237
+ requestedAttributes : proofRequestOptions . requestedAttributes ,
238
+ requestedPredicates : proofRequestOptions . requestedPredicates ,
239
+ } )
240
+
241
+ const createRequestOptions : CreateRequestOptions = {
242
+ proofRequest,
243
+ connectionRecord : connection ,
244
+ comment : requestProofOptions . comment ,
245
+ autoAcceptProof : requestProofOptions . autoAcceptProof ,
246
+ }
247
+
248
+ const { message, proofRecord } = await service . createRequest ( createRequestOptions )
249
+
250
+ const outboundMessage = createOutboundMessage ( connection , message )
251
+ await this . msgSender . sendMessage ( outboundMessage )
252
+
253
+ return proofRecord
254
+ }
255
+
256
+ public async generateProofRequestNonce ( ) {
257
+ return this . wallet . generateNonce ( )
258
+ }
259
+
211
260
/**
212
261
* Retrieve a proof record by id
213
262
*
0 commit comments