diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/manager.py b/aries_cloudagent/protocols/issue_credential/v1_0/manager.py index fe8b9ea425..5aecf170bd 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/manager.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/manager.py @@ -515,7 +515,8 @@ async def receive_credential(self) -> V10CredentialExchange: return credential_exchange_record async def store_credential( - self, credential_exchange_record: V10CredentialExchange + self, credential_exchange_record: V10CredentialExchange, + credential_id: str = None ) -> Tuple[V10CredentialExchange, CredentialAck]: """ Store a credential in holder wallet; send ack to issuer. @@ -553,7 +554,8 @@ async def store_credential( credential_definition, raw_credential, credential_exchange_record.credential_request_metadata, - mime_types + mime_types, + credential_id=credential_id ) credential = await holder.get_credential(credential_id) diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/routes.py b/aries_cloudagent/protocols/issue_credential/v1_0/routes.py index a5a56ed4c2..abf15aeb93 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/routes.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/routes.py @@ -4,6 +4,8 @@ from aiohttp_apispec import docs, request_schema, response_schema from marshmallow import fields, Schema +from json.decoder import JSONDecodeError + from ....connections.models.connection_record import ConnectionRecord from ....holder.base import BaseHolder from ....messaging.credential_definitions.util import CRED_DEF_TAGS @@ -43,6 +45,12 @@ class V10CredentialExchangeListResultSchema(Schema): ) +class V10CredentialStoreRequestSchema(Schema): + """Request schema for sending a credential store admin message.""" + + credential_id = fields.Str(required=False) + + class V10CredentialProposalRequestSchemaBase(Schema): """Base class for request schema for sending credential proposal admin message.""" @@ -568,6 +576,7 @@ async def credential_exchange_issue(request: web.BaseRequest): @docs(tags=["issue-credential"], summary="Store a received credential") +@request_schema(V10CredentialStoreRequestSchema()) @response_schema(V10CredentialExchangeSchema(), 200) async def credential_exchange_store(request: web.BaseRequest): """ @@ -583,6 +592,12 @@ async def credential_exchange_store(request: web.BaseRequest): context = request.app["request_context"] outbound_handler = request.app["outbound_message_router"] + try: + body = await request.json() or {} + credential_id = body.get("credential_id") + except JSONDecodeError: + credential_id = None + credential_exchange_id = request.match_info["cred_ex_id"] credential_exchange_record = await V10CredentialExchange.retrieve_by_id( context, credential_exchange_id @@ -608,7 +623,9 @@ async def credential_exchange_store(request: web.BaseRequest): ( credential_exchange_record, credential_stored_message, - ) = await credential_manager.store_credential(credential_exchange_record) + ) = await credential_manager.store_credential( + credential_exchange_record, credential_id + ) await outbound_handler(credential_stored_message, connection_id=connection_id) return web.json_response(credential_exchange_record.serialize()) diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py index 130d908bd9..6dfa8e159f 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/tests/test_manager.py @@ -775,6 +775,7 @@ async def test_store_credential(self): cred, cred_req_meta, mock_preview_deserialize.return_value.mime_types.return_value, + credential_id=None, ) holder.get_credential.assert_called_once_with(cred_id) @@ -831,7 +832,8 @@ async def test_store_credential_no_preview(self): cred_def, cred, cred_req_meta, - None + None, + credential_id=None ) holder.get_credential.assert_called_once_with(cred_id)