Skip to content

Commit ca1a0c8

Browse files
committed
adding admin-holder/0.1/credential-offer-reject
Signed-off-by: Matthew Wright <[email protected]>
1 parent 8da2e06 commit ca1a0c8

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

acapy_plugin_toolbox/holder/__init__.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
)
99
from aries_cloudagent.protocols.issue_credential.v1_0.messages.inner.credential_preview import \
1010
CredAttrSpec as CredentialAttributeSpec
11+
from aries_cloudagent.protocols.issue_credential.v1_0.messages.credential_problem_report import \
12+
CredentialProblemReport
1113
from aries_cloudagent.protocols.issue_credential.v1_0.models.credential_exchange import \
1214
V10CredentialExchange as CredExRecord
1315
from aries_cloudagent.protocols.issue_credential.v1_0.models.credential_exchange import \
@@ -37,7 +39,7 @@
3739

3840
__all__ = [
3941
"issue_credential", "CredentialManager", "CredentialManagerError",
40-
"CredentialAttributeSpec", "CredExRecord", "CredExRecordSchema",
42+
"CredentialAttributeSpec", "CredExRecord", "CredExRecordSchema", "CredentialProblemReport",
4143
"CredentialProposalRequestSchema", "present_proof",
4244
"PresentationManager", "PresentationManagerError",
4345
"PresentationPreview", "PresExRecord", "PresExRecordSchema", "IndyCredPrecisSchema",

acapy_plugin_toolbox/holder/v0_1.py

+64-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
)
3535
from . import (
3636
CredentialAttributeSpec, CredentialManager, CredentialManagerError,
37-
CredentialProposalRequestSchema, CredExRecord, CredExRecordSchema,
37+
CredentialProposalRequestSchema, CredExRecord, CredExRecordSchema, CredentialProblemReport,
3838
IndyCredPrecisSchema, PresentationPreview,
3939
PresentationProposalRequestSchema, PresExRecord, PresExRecordSchema,
4040
issue_credential, present_proof, PresentationManager,
@@ -317,6 +317,68 @@ class CredRequestSent(AdminHolderMessage):
317317
fields_from = CredExRecordSchema
318318

319319

320+
@expand_message_class
321+
class CredOfferReject(AdminHolderMessage):
322+
"""Credential offer reject message."""
323+
message_type = "credential-offer-reject"
324+
325+
class Fields:
326+
credential_exchange_id = fields.Str(
327+
required=True,
328+
description="ID of the credential exchange to reject.",
329+
example=UUIDFour.EXAMPLE
330+
)
331+
332+
def __init__(self, credential_exchange_id: str, **kwargs):
333+
super().__init__(**kwargs)
334+
self.credential_exchange_id = credential_exchange_id
335+
336+
@log_handling
337+
@admin_only
338+
async def handle(self, context: RequestContext, responder: BaseResponder):
339+
"""Handle credential offer reject message."""
340+
async with context.session() as session:
341+
async with ExceptionReporter(
342+
responder,
343+
(StorageError, CredentialManagerError, BaseModelError),
344+
self
345+
):
346+
cred_ex_record = await CredExRecord.retrieve_by_id(
347+
session, self.credential_exchange_id
348+
)
349+
cred_ex_record = cast(CredExRecord, cred_ex_record)
350+
connection_id = cred_ex_record.connection_id
351+
connection_record = await get_connection(session, connection_id)
352+
353+
# TODO add credential_manager.reject(..) to ACA-Py
354+
355+
cred_ex_record.state = "reject-sent" # TODO add CredExRecord.STATE_REJECT_SENT to ACA-Py
356+
async with context.session() as session:
357+
await cred_ex_record.save(session, reason="Rejected credential offer.")
358+
359+
problem_report = CredentialProblemReport(
360+
description={
361+
"en": "Rejected credential offer.",
362+
"code": "rejected", # TODO add ProblemReportReason.REJECTED to ACA-Py
363+
}
364+
)
365+
problem_report.assign_thread_id(cred_ex_record.thread_id)
366+
367+
sent = CredOfferRejectSent(**cred_ex_record.serialize())
368+
sent.assign_thread_from(self)
369+
370+
await responder.send(problem_report, connection_id=connection_record.connection_id)
371+
await responder.send_reply(sent)
372+
373+
374+
@with_generic_init
375+
@expand_message_class
376+
class CredOfferRejectSent(AdminHolderMessage):
377+
"""Credential offer reject sent."""
378+
message_type = "credential-offer-reject-sent"
379+
fields_from = CredExRecordSchema
380+
381+
320382
@with_generic_init
321383
@expand_message_class
322384
class CredReceived(AdminHolderMessage):
@@ -881,6 +943,7 @@ def __init__(
881943
CredGetList,
882944
CredList,
883945
CredOfferAccept,
946+
CredOfferReject,
884947
CredOfferRecv,
885948
CredRequestSent,
886949
CredReceived,

0 commit comments

Comments
 (0)