Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add verification method issue-credentials-2.0/send endpoint #2135

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from ......vc.ld_proofs.check import get_properties_without_context
import logging

from typing import Mapping
from typing import Mapping, Optional

from marshmallow import EXCLUDE, INCLUDE

Expand Down Expand Up @@ -253,7 +253,9 @@ async def _did_info_for_did(self, did: str) -> DIDInfo:
# All other methods we can just query
return await wallet.get_local_did(did)

async def _get_suite_for_detail(self, detail: LDProofVCDetail) -> LinkedDataProof:
async def _get_suite_for_detail(
self, detail: LDProofVCDetail, verification_method: Optional[str] = None
) -> LinkedDataProof:
issuer_id = detail.credential.issuer_id
proof_type = detail.options.proof_type

Expand All @@ -268,7 +270,9 @@ async def _get_suite_for_detail(self, detail: LDProofVCDetail) -> LinkedDataProo
)

did_info = await self._did_info_for_did(issuer_id)
verification_method = self._get_verification_method(issuer_id)
verification_method = verification_method or self._get_verification_method(
issuer_id
)

suite = await self._get_suite(
proof_type=proof_type,
Expand Down Expand Up @@ -457,7 +461,9 @@ async def receive_request(
"""Receive linked data proof request."""

async def issue_credential(
self, cred_ex_record: V20CredExRecord, retries: int = 5
self,
cred_ex_record: V20CredExRecord,
retries: int = 5,
) -> CredFormatAttachment:
"""Issue linked data proof credential."""
if not cred_ex_record.cred_request:
Expand All @@ -472,7 +478,9 @@ async def issue_credential(
detail = await self._prepare_detail(detail)

# Get signature suite, proof purpose and document loader
suite = await self._get_suite_for_detail(detail)
suite = await self._get_suite_for_detail(
detail, cred_ex_record.verification_method
)
proof_purpose = self._get_proof_purpose(
proof_purpose=detail.options.proof_purpose,
challenge=detail.options.challenge,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ async def test_issue_credential(self):

detail = LDProofVCDetail.deserialize(LD_PROOF_VC_DETAIL)

mock_get_suite.assert_called_once_with(detail)
mock_get_suite.assert_called_once_with(detail, None)
mock_issue.assert_called_once_with(
credential=LD_PROOF_VC_DETAIL["credential"],
suite=mock_get_suite.return_value,
Expand Down
6 changes: 4 additions & 2 deletions aries_cloudagent/protocols/issue_credential/v2_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ async def prepare_send(
self,
connection_id: str,
cred_proposal: V20CredProposal,
verification_method: Optional[str] = None,
auto_remove: bool = None,
) -> Tuple[V20CredExRecord, V20CredOffer]:
"""
Expand All @@ -63,6 +64,7 @@ async def prepare_send(
Args:
connection_id: connection for which to create offer
cred_proposal: credential proposal with preview
verification_method: an optional verification method to be used when issuing
auto_remove: flag to remove the record automatically on completion

Returns:
Expand All @@ -73,19 +75,19 @@ async def prepare_send(
auto_remove = not self._profile.settings.get("preserve_exchange_records")
cred_ex_record = V20CredExRecord(
connection_id=connection_id,
verification_method=verification_method,
initiator=V20CredExRecord.INITIATOR_SELF,
role=V20CredExRecord.ROLE_ISSUER,
cred_proposal=cred_proposal,
auto_issue=True,
auto_remove=auto_remove,
trace=(cred_proposal._trace is not None),
)
(cred_ex_record, cred_offer) = await self.create_offer(
return await self.create_offer(
cred_ex_record=cred_ex_record,
counter_proposal=None,
comment="create automated v2.0 credential exchange record",
)
return (cred_ex_record, cred_offer)

async def create_proposal(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(
*,
cred_ex_id: str = None,
connection_id: str = None,
verification_method: Optional[str] = None,
thread_id: str = None,
parent_thread_id: str = None,
initiator: str = None,
Expand All @@ -82,6 +83,7 @@ def __init__(
super().__init__(cred_ex_id, state, trace=trace, **kwargs)
self._id = cred_ex_id
self.connection_id = connection_id or conn_id
self.verification_method = verification_method
self.thread_id = thread_id
self.parent_thread_id = parent_thread_id
self.initiator = initiator
Expand Down Expand Up @@ -217,6 +219,7 @@ def record_value(self) -> Mapping:
prop: getattr(self, prop)
for prop in (
"connection_id",
"verification_method",
"parent_thread_id",
"initiator",
"role",
Expand Down
10 changes: 10 additions & 0 deletions aries_cloudagent/protocols/issue_credential/v2_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ class V20CredExFreeSchema(V20IssueCredSchemaCore):
example=UUIDFour.EXAMPLE, # typically but not necessarily a UUID4
)

verification_method = fields.Str(
required=False,
default=None,
allow_none=True,
description="For ld-proofs. Verification method for signing.",
)


class V20CredBoundOfferRequestSchema(OpenAPISchema):
"""Request schema for sending bound credential offer admin message."""
Expand Down Expand Up @@ -628,6 +635,8 @@ async def credential_exchange_send(request: web.BaseRequest):

comment = body.get("comment")
connection_id = body.get("connection_id")
verification_method = body.get("verification_method")

filt_spec = body.get("filter")
if not filt_spec:
raise web.HTTPBadRequest(reason="Missing filter")
Expand Down Expand Up @@ -668,6 +677,7 @@ async def credential_exchange_send(request: web.BaseRequest):
cred_manager = V20CredManager(profile)
(cred_ex_record, cred_offer_message) = await cred_manager.prepare_send(
connection_id,
verification_method=verification_method,
cred_proposal=cred_proposal,
auto_remove=auto_remove,
)
Expand Down