14
14
from .manager import CredentialManager
15
15
from .messages .credential_proposal import CredentialProposal
16
16
from .messages .inner .credential_preview import (
17
- CredAttrSpec ,
18
17
CredentialPreview ,
19
18
CredentialPreviewSchema ,
20
19
)
@@ -51,7 +50,7 @@ class V10CredentialProposalRequestSchema(Schema):
51
50
** INDY_CRED_DEF_ID ,
52
51
)
53
52
comment = fields .Str (description = "Human-readable comment" , required = False )
54
- credential_proposal = fields .Nested (CredentialPreviewSchema , required = True )
53
+ credential_preview = fields .Nested (CredentialPreviewSchema , required = True )
55
54
56
55
57
56
class V10CredentialOfferRequestSchema (Schema ):
@@ -190,27 +189,12 @@ async def credential_exchange_send(request: web.BaseRequest):
190
189
connection_id = body .get ("connection_id" )
191
190
credential_definition_id = body .get ("credential_definition_id" )
192
191
comment = body .get ("comment" )
193
- credential_proposal = CredentialProposal (
194
- comment = comment ,
195
- credential_proposal = CredentialPreview (
196
- attributes = [
197
- CredAttrSpec (
198
- name = attr_preview ["name" ],
199
- mime_type = attr_preview .get ("mime-type" , None ),
200
- value = attr_preview ["value" ],
201
- )
202
- for attr_preview in body .get ("credential_proposal" )["attributes" ]
203
- ]
204
- ),
205
- cred_def_id = credential_definition_id ,
206
- )
192
+ preview_spec = body .get ("credential_preview" )
207
193
208
- if not credential_proposal :
209
- raise web .HTTPBadRequest (
210
- reason = "credential_proposal must be provided with attribute values."
211
- )
212
-
213
- credential_manager = CredentialManager (context )
194
+ if not credential_definition_id :
195
+ raise web .HTTPBadRequest (reason = "credential_definition_id must be provided." )
196
+ if not preview_spec :
197
+ raise web .HTTPBadRequest (reason = "credential_preview must be provided." )
214
198
215
199
try :
216
200
connection_record = await ConnectionRecord .retrieve_by_id (
@@ -222,18 +206,19 @@ async def credential_exchange_send(request: web.BaseRequest):
222
206
if not connection_record .is_ready :
223
207
raise web .HTTPForbidden ()
224
208
225
- credential_exchange_record = await credential_manager .prepare_send (
226
- connection_id , credential_proposal = credential_proposal
209
+ credential_proposal = CredentialProposal (
210
+ comment = comment ,
211
+ credential_proposal = CredentialPreview .deserialize (preview_spec ),
212
+ cred_def_id = credential_definition_id ,
227
213
)
228
214
215
+ credential_manager = CredentialManager (context )
216
+
229
217
(
230
218
credential_exchange_record ,
231
219
credential_offer_message ,
232
- ) = await credential_manager .create_offer (
233
- credential_exchange_record ,
234
- comment = "Automated offer creation on cred def id "
235
- f"{ credential_exchange_record .credential_definition_id } , "
236
- f"parent thread { credential_exchange_record .parent_thread_id } " ,
220
+ ) = await credential_manager .prepare_send (
221
+ connection_id , credential_proposal = credential_proposal
237
222
)
238
223
await outbound_handler (
239
224
credential_offer_message , connection_id = credential_exchange_record .connection_id
@@ -264,14 +249,10 @@ async def credential_exchange_send_proposal(request: web.BaseRequest):
264
249
connection_id = body .get ("connection_id" )
265
250
credential_definition_id = body .get ("credential_definition_id" )
266
251
comment = body .get ("comment" )
267
- proposal_spec = body .get ("credential_proposal" )
268
-
269
- if not proposal_spec :
270
- raise web .HTTPBadRequest (reason = "credential_proposal must be provided." )
271
-
272
- credential_preview = CredentialPreview .deserialize (proposal_spec )
252
+ preview_spec = body .get ("credential_preview" )
273
253
274
- credential_manager = CredentialManager (context )
254
+ if not preview_spec :
255
+ raise web .HTTPBadRequest (reason = "credential_preview must be provided." )
275
256
276
257
try :
277
258
connection_record = await ConnectionRecord .retrieve_by_id (
@@ -283,6 +264,10 @@ async def credential_exchange_send_proposal(request: web.BaseRequest):
283
264
if not connection_record .is_ready :
284
265
raise web .HTTPForbidden ()
285
266
267
+ credential_preview = CredentialPreview .deserialize (preview_spec )
268
+
269
+ credential_manager = CredentialManager (context )
270
+
286
271
credential_exchange_record = await credential_manager .create_proposal (
287
272
connection_id ,
288
273
comment = comment ,
@@ -332,19 +317,17 @@ async def credential_exchange_send_free_offer(request: web.BaseRequest):
332
317
"auto_issue" , context .settings .get ("debug.auto_respond_credential_request" )
333
318
)
334
319
comment = body .get ("comment" )
335
- proposal_spec = body .get ("credential_proposal " )
320
+ preview_spec = body .get ("credential_preview " )
336
321
337
322
if not credential_definition_id :
338
323
raise web .HTTPBadRequest (reason = "credential_definition_id is required" )
339
324
340
- if auto_issue and not proposal_spec :
325
+ if auto_issue and not preview_spec :
341
326
raise web .HTTPBadRequest (
342
327
reason = "If auto_issue is set to"
343
328
+ " true then credential_preview must also be provided."
344
329
)
345
330
346
- credential_manager = CredentialManager (context )
347
-
348
331
try :
349
332
connection_record = await ConnectionRecord .retrieve_by_id (
350
333
context , connection_id
@@ -355,8 +338,8 @@ async def credential_exchange_send_free_offer(request: web.BaseRequest):
355
338
if not connection_record .is_ready :
356
339
raise web .HTTPForbidden ()
357
340
358
- if proposal_spec :
359
- credential_preview = CredentialPreview .deserialize (proposal_spec )
341
+ if preview_spec :
342
+ credential_preview = CredentialPreview .deserialize (preview_spec )
360
343
credential_proposal = CredentialProposal (
361
344
comment = comment ,
362
345
credential_proposal = credential_preview ,
@@ -374,6 +357,8 @@ async def credential_exchange_send_free_offer(request: web.BaseRequest):
374
357
auto_issue = auto_issue ,
375
358
)
376
359
360
+ credential_manager = CredentialManager (context )
361
+
377
362
(
378
363
credential_exchange_record ,
379
364
credential_offer_message ,
@@ -466,8 +451,6 @@ async def credential_exchange_send_request(request: web.BaseRequest):
466
451
V10CredentialExchange .STATE_OFFER_RECEIVED
467
452
)
468
453
469
- credential_manager = CredentialManager (context )
470
-
471
454
try :
472
455
connection_record = await ConnectionRecord .retrieve_by_id (
473
456
context , connection_id
@@ -478,6 +461,8 @@ async def credential_exchange_send_request(request: web.BaseRequest):
478
461
if not connection_record .is_ready :
479
462
raise web .HTTPForbidden ()
480
463
464
+ credential_manager = CredentialManager (context )
465
+
481
466
(
482
467
credential_exchange_record ,
483
468
credential_request_message ,
@@ -508,7 +493,10 @@ async def credential_exchange_issue(request: web.BaseRequest):
508
493
509
494
body = await request .json ()
510
495
comment = body .get ("comment" )
511
- credential_preview = CredentialPreview .deserialize (body ["credential_preview" ])
496
+ preview_spec = body .get ("credential_preview" )
497
+
498
+ if not preview_spec :
499
+ raise web .HTTPBadRequest (reason = "credential_preview must be provided." )
512
500
513
501
credential_exchange_id = request .match_info ["cred_ex_id" ]
514
502
cred_exch_record = await V10CredentialExchange .retrieve_by_id (
@@ -518,8 +506,6 @@ async def credential_exchange_issue(request: web.BaseRequest):
518
506
519
507
assert cred_exch_record .state == V10CredentialExchange .STATE_REQUEST_RECEIVED
520
508
521
- credential_manager = CredentialManager (context )
522
-
523
509
try :
524
510
connection_record = await ConnectionRecord .retrieve_by_id (
525
511
context , connection_id
@@ -530,6 +516,10 @@ async def credential_exchange_issue(request: web.BaseRequest):
530
516
if not connection_record .is_ready :
531
517
raise web .HTTPForbidden ()
532
518
519
+ credential_preview = CredentialPreview .deserialize (preview_spec )
520
+
521
+ credential_manager = CredentialManager (context )
522
+
533
523
(
534
524
cred_exch_record ,
535
525
credential_issue_message ,
@@ -569,8 +559,6 @@ async def credential_exchange_store(request: web.BaseRequest):
569
559
V10CredentialExchange .STATE_CREDENTIAL_RECEIVED
570
560
)
571
561
572
- credential_manager = CredentialManager (context )
573
-
574
562
try :
575
563
connection_record = await ConnectionRecord .retrieve_by_id (
576
564
context , connection_id
@@ -581,6 +569,8 @@ async def credential_exchange_store(request: web.BaseRequest):
581
569
if not connection_record .is_ready :
582
570
raise web .HTTPForbidden ()
583
571
572
+ credential_manager = CredentialManager (context )
573
+
584
574
(
585
575
credential_exchange_record ,
586
576
credential_stored_message ,
0 commit comments