62
62
from ....v1_0 .models .data_agreement_instance_model import DataAgreementInstance , DataAgreementInstanceSchema
63
63
from ....v1_0 .utils .did .mydata_did import DIDMyData
64
64
from ....v1_0 .utils .wallet .key_type import KeyType
65
+ from ....v1_0 .utils .util import comma_separated_str_to_list
66
+
65
67
66
68
class V10CredentialExchangeListQueryStringSchema (OpenAPISchema ):
67
69
"""Parameters and validators for credential exchange list query."""
@@ -113,6 +115,13 @@ class V10CredentialExchangeListQueryStringSchema(OpenAPISchema):
113
115
example = UUIDFour .EXAMPLE ,
114
116
)
115
117
118
+ # Response fields
119
+ include_fields = fields .Str (
120
+ required = False ,
121
+ description = "Comma separated fields to be included in the response." ,
122
+ example = "connection_id,state,presentation_exchange_id" ,
123
+ )
124
+
116
125
117
126
class V10CredentialExchangeListResultSchema (OpenAPISchema ):
118
127
"""Result schema for Aries#0036 v1.0 credential exchange query."""
@@ -384,11 +393,14 @@ class DataAgreementBoundCredentialOfferMatchInfoSchema(OpenAPISchema):
384
393
example = UUIDFour .EXAMPLE
385
394
)
386
395
396
+
387
397
class SendDataAgreementNegotiationProblemReportRequestSchema (OpenAPISchema ):
388
398
"""Request schema for sending problem report."""
389
399
390
- explain = fields .Str (description = "Describe the problem" , required = True , example = "Data agreement context decorator not found in the didcomm message." )
391
- problem_code = fields .Str (description = "Problem code" , required = True , example = DataAgreementNegotiationProblemReportReason .DATA_AGREEMENT_CONTEXT_INVALID .value )
400
+ explain = fields .Str (description = "Describe the problem" , required = True ,
401
+ example = "Data agreement context decorator not found in the didcomm message." )
402
+ problem_code = fields .Str (description = "Problem code" , required = True ,
403
+ example = DataAgreementNegotiationProblemReportReason .DATA_AGREEMENT_CONTEXT_INVALID .value )
392
404
393
405
394
406
@docs (tags = ["issue-credential" ], summary = "Fetch all credential exchange records" )
@@ -416,8 +428,18 @@ async def credential_exchange_list(request: web.BaseRequest):
416
428
}
417
429
418
430
try :
431
+
419
432
records = await V10CredentialExchange .query (context , tag_filter , post_filter )
420
- results = [record .serialize () for record in records ]
433
+
434
+ # Fields to be included in the response.
435
+ include_fields = request .query .get ("include_fields" )
436
+ include_fields = comma_separated_str_to_list (
437
+ include_fields ) if include_fields else None
438
+
439
+ # Serialise presentation exchange records and customize it based on include_fields.
440
+ results = ADAManager .serialize_credential_exchange_records (
441
+ records , True , include_fields )
442
+
421
443
except (StorageError , BaseModelError ) as err :
422
444
raise web .HTTPBadRequest (reason = err .roll_up ) from err
423
445
@@ -1539,11 +1561,12 @@ async def send_data_agreement_reject_message_for_credential_offer(request: web.B
1539
1561
1540
1562
await outbound_handler (data_agreement_negotiation_reject_message , connection_id = cred_ex_record .connection_id )
1541
1563
1542
- except (ADAManagerError ,StorageError ) as err :
1564
+ except (ADAManagerError , StorageError ) as err :
1543
1565
raise web .HTTPBadRequest (reason = err .roll_up ) from err
1544
1566
1545
1567
return web .json_response (cred_ex_record .serialize ())
1546
1568
1569
+
1547
1570
@docs (
1548
1571
tags = ["issue-credential" ], summary = "Send data agreement negotiation problem report message"
1549
1572
)
@@ -1579,11 +1602,9 @@ async def send_data_agreement_negotiation_problem_report(request: web.BaseReques
1579
1602
)
1580
1603
except StorageNotFoundError as err :
1581
1604
raise web .HTTPNotFound (reason = err .roll_up ) from err
1582
-
1583
1605
1584
1606
if not cred_ex_record .data_agreement :
1585
1607
raise web .HTTPBadRequest (reason = f"Data agreement is not available." )
1586
-
1587
1608
1588
1609
# Initialize ADA manager
1589
1610
ada_manager = ADAManager (context )
@@ -1597,7 +1618,6 @@ async def send_data_agreement_negotiation_problem_report(request: web.BaseReques
1597
1618
if not connection_record .is_ready :
1598
1619
raise web .HTTPForbidden (
1599
1620
reason = f"Connection { connection_id } not ready" )
1600
-
1601
1621
1602
1622
data_agreement_negotiation_problem_report = await ada_manager .construct_data_agreement_negotiation_problem_report_message (
1603
1623
connection_record = connection_record ,
@@ -1611,7 +1631,7 @@ async def send_data_agreement_negotiation_problem_report(request: web.BaseReques
1611
1631
data_agreement_negotiation_problem_report_message = data_agreement_negotiation_problem_report ,
1612
1632
)
1613
1633
1614
- except (ADAManagerError ,StorageError ) as err :
1634
+ except (ADAManagerError , StorageError ) as err :
1615
1635
raise web .HTTPBadRequest (reason = err .roll_up ) from err
1616
1636
1617
1637
return web .json_response ({})
@@ -1675,19 +1695,18 @@ async def send_data_agreement_termination_message(request: web.BaseRequest):
1675
1695
if not connection_record .is_ready :
1676
1696
raise web .HTTPForbidden (
1677
1697
reason = f"Connection { connection_id } not ready" )
1678
-
1698
+
1679
1699
# Fetch wallet from context
1680
1700
wallet : IndyWallet = await context .inject (BaseWallet )
1681
-
1701
+
1682
1702
pairwise_local_did_record = await wallet .get_local_did (connection_record .my_did )
1683
1703
principle_did = DIDMyData .from_public_key_b58 (
1684
1704
pairwise_local_did_record .verkey , key_type = KeyType .ED25519 )
1685
-
1705
+
1686
1706
if data_agreement_instance .principle_did != principle_did .did :
1687
1707
raise web .HTTPBadRequest (
1688
1708
reason = f"Only the principle can terminate the data agreement."
1689
1709
)
1690
-
1691
1710
1692
1711
(data_agreement_instance , data_agreement_terminate_message ) = await ada_manager .construct_data_agreement_termination_terminate_message (
1693
1712
data_agreement_instance = data_agreement_instance ,
@@ -1702,11 +1721,12 @@ async def send_data_agreement_termination_message(request: web.BaseRequest):
1702
1721
1703
1722
await outbound_handler (data_agreement_terminate_message , connection_id = cred_ex_record .connection_id )
1704
1723
1705
- except (ADAManagerError ,StorageError ) as err :
1724
+ except (ADAManagerError , StorageError ) as err :
1706
1725
raise web .HTTPBadRequest (reason = err .roll_up ) from err
1707
1726
1708
1727
return web .json_response (cred_ex_record .serialize ())
1709
1728
1729
+
1710
1730
async def register (app : web .Application ):
1711
1731
"""Register routes."""
1712
1732
0 commit comments