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

Add auto_verify flag in present-proof protocol #1702

Merged
merged 5 commits into from
Mar 31, 2022
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 @@ -49,7 +49,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
)

# Automatically move to next state if flag is set
if context.settings.get("debug.auto_verify_presentation"):
if presentation_exchange_record and presentation_exchange_record.auto_verify:
try:
await presentation_manager.verify_presentation(
presentation_exchange_record
Expand Down
6 changes: 5 additions & 1 deletion aries_cloudagent/protocols/present_proof/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ async def create_bound_request(
return presentation_exchange_record, presentation_request_message

async def create_exchange_for_request(
self, connection_id: str, presentation_request_message: PresentationRequest
self,
connection_id: str,
presentation_request_message: PresentationRequest,
auto_verify: bool = None,
):
"""
Create a presentation exchange record for input presentation request.
Expand All @@ -187,6 +190,7 @@ async def create_exchange_for_request(
state=V10PresentationExchange.STATE_REQUEST_SENT,
presentation_request=presentation_request_message.indy_proof_request(),
presentation_request_dict=presentation_request_message,
auto_verify=auto_verify,
trace=(presentation_request_message._trace is not None),
)
async with self._profile.session() as session:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(
presentation: Union[IndyProof, Mapping] = None, # indy proof
verified: str = None,
auto_present: bool = False,
auto_verify: bool = False,
error_msg: str = None,
trace: bool = False, # backward compat: BaseRecord.from_storage()
**kwargs,
Expand All @@ -96,6 +97,7 @@ def __init__(
self._presentation = IndyProof.serde(presentation)
self.verified = verified
self.auto_present = auto_present
self.auto_verify = auto_verify
self.error_msg = error_msg

@property
Expand Down Expand Up @@ -203,6 +205,7 @@ def record_value(self) -> Mapping:
"role",
"state",
"auto_present",
"auto_verify",
"error_msg",
"verified",
"trace",
Expand Down Expand Up @@ -297,6 +300,9 @@ class Meta:
description="Prover choice to auto-present proof as verifier requests",
example=False,
)
auto_verify = fields.Bool(
required=False, description="Verifier choice to auto-verify proof presentation"
)
error_msg = fields.Str(
required=False, description="Error message", example="Invalid structure"
)
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ async def test_record(self):
"role": None,
"state": None,
"auto_present": True,
"auto_verify": False,
"error_msg": None,
"verified": None,
"trace": False,
Expand Down
33 changes: 32 additions & 1 deletion aries_cloudagent/protocols/present_proof/v1_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ class V10PresentationCreateRequestRequestSchema(AdminAPIMessageTracingSchema):

proof_request = fields.Nested(IndyProofRequestSchema(), required=True)
comment = fields.Str(required=False, allow_none=True)
auto_verify = fields.Bool(
description="Verifier choice to auto-verify proof presentation",
required=False,
example=False,
)
trace = fields.Bool(
description="Whether to trace event (default false)",
required=False,
Expand All @@ -147,6 +152,21 @@ class V10PresentationSendRequestRequestSchema(
)


class V10PresentationSendRequestToProposalSchema(AdminAPIMessageTracingSchema):
"""Request schema for sending a proof request bound to a proposal."""

auto_verify = fields.Bool(
description="Verifier choice to auto-verify proof presentation",
required=False,
example=False,
)
trace = fields.Bool(
description="Whether to trace event (default false)",
required=False,
example=False,
)


class CredentialsFetchQueryStringSchema(OpenAPISchema):
"""Parameters and validators for credentials fetch request query string."""

Expand Down Expand Up @@ -475,6 +495,9 @@ async def presentation_exchange_create_request(request: web.BaseRequest):
)
],
)
auto_verify = body.get(
"auto_verify", context.settings.get("debug.auto_verify_presentation")
)
trace_msg = body.get("trace")
presentation_request_message.assign_trace_decorator(
context.settings,
Expand All @@ -487,6 +510,7 @@ async def presentation_exchange_create_request(request: web.BaseRequest):
pres_ex_record = await presentation_manager.create_exchange_for_request(
connection_id=None,
presentation_request_message=presentation_request_message,
auto_verify=auto_verify,
)
result = pres_ex_record.serialize()
except (BaseModelError, StorageError) as err:
Expand Down Expand Up @@ -562,13 +586,17 @@ async def presentation_exchange_send_free_request(request: web.BaseRequest):
context.settings,
trace_msg,
)
auto_verify = body.get(
"auto_verify", context.settings.get("debug.auto_verify_presentation")
)

pres_ex_record = None
try:
presentation_manager = PresentationManager(profile)
pres_ex_record = await presentation_manager.create_exchange_for_request(
connection_id=connection_id,
presentation_request_message=presentation_request_message,
auto_verify=auto_verify,
)
result = pres_ex_record.serialize()
except (BaseModelError, StorageError) as err:
Expand All @@ -595,7 +623,7 @@ async def presentation_exchange_send_free_request(request: web.BaseRequest):
summary="Sends a presentation request in reference to a proposal",
)
@match_info_schema(V10PresExIdMatchInfoSchema())
@request_schema(AdminAPIMessageTracingSchema())
@request_schema(V10PresentationSendRequestToProposalSchema())
@response_schema(V10PresentationExchangeSchema(), 200, description="")
async def presentation_exchange_send_bound_request(request: web.BaseRequest):
"""
Expand Down Expand Up @@ -644,6 +672,9 @@ async def presentation_exchange_send_bound_request(request: web.BaseRequest):
if not connection_record.is_ready:
raise web.HTTPForbidden(reason=f"Connection {conn_id} not ready")

pres_ex_record.auto_verify = body.get(
"auto_verify", context.settings.get("debug.auto_verify_presentation")
)
try:
presentation_manager = PresentationManager(profile)
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def handle(self, context: RequestContext, responder: BaseResponder):
)

# Automatically move to next state if flag is set
if context.settings.get("debug.auto_verify_presentation"):
if pres_ex_record and pres_ex_record.auto_verify:
try:
await pres_manager.verify_pres(pres_ex_record)
except (BaseModelError, LedgerError, StorageError) as err:
Expand Down
6 changes: 5 additions & 1 deletion aries_cloudagent/protocols/present_proof/v2_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ async def create_bound_request(
return pres_ex_record, pres_request_message

async def create_exchange_for_request(
self, connection_id: str, pres_request_message: V20PresRequest
self,
connection_id: str,
pres_request_message: V20PresRequest,
auto_verify: bool = None,
):
"""
Create a presentation exchange record for input presentation request.
Expand All @@ -182,6 +185,7 @@ async def create_exchange_for_request(
role=V20PresExRecord.ROLE_VERIFIER,
state=V20PresExRecord.STATE_REQUEST_SENT,
pres_request=pres_request_message,
auto_verify=auto_verify,
trace=(pres_request_message._trace is not None),
)
async with self._profile.session() as session:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __init__(
pres: Union[V20Pres, Mapping] = None, # aries message
verified: str = None,
auto_present: bool = False,
auto_verify: bool = False,
error_msg: str = None,
trace: bool = False, # backward compat: BaseRecord.FromStorage()
by_format: Mapping = None, # backward compat: BaseRecord.FromStorage()
Expand All @@ -80,6 +81,7 @@ def __init__(
self._pres = V20Pres.serde(pres)
self.verified = verified
self.auto_present = auto_present
self.auto_verify = auto_verify
self.error_msg = error_msg

@property
Expand Down Expand Up @@ -190,6 +192,7 @@ def record_value(self) -> Mapping:
"state",
"verified",
"auto_present",
"auto_verify",
"error_msg",
"trace",
)
Expand Down Expand Up @@ -309,6 +312,9 @@ class Meta:
description="Prover choice to auto-present proof as verifier requests",
example=False,
)
auto_verify = fields.Bool(
required=False, description="Verifier choice to auto-verify proof presentation"
)
error_msg = fields.Str(
required=False, description="Error message", example="Invalid structure"
)
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ async def test_record(self):
"pres_proposal": pres_proposal.serialize(),
"verified": "false",
"auto_present": True,
"auto_verify": False,
"error_msg": "error",
"trace": False,
}
Expand Down
33 changes: 32 additions & 1 deletion aries_cloudagent/protocols/present_proof/v2_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ class V20PresCreateRequestRequestSchema(AdminAPIMessageTracingSchema):

presentation_request = fields.Nested(V20PresRequestByFormatSchema(), required=True)
comment = fields.Str(required=False, allow_none=True)
auto_verify = fields.Bool(
description="Verifier choice to auto-verify proof presentation",
required=False,
example=False,
)
trace = fields.Bool(
description="Whether to trace event (default false)",
required=False,
Expand All @@ -223,6 +228,21 @@ class V20PresSendRequestRequestSchema(V20PresCreateRequestRequestSchema):
)


class V20PresentationSendRequestToProposalSchema(AdminAPIMessageTracingSchema):
"""Request schema for sending a proof request bound to a proposal."""

auto_verify = fields.Bool(
description="Verifier choice to auto-verify proof presentation",
required=False,
example=False,
)
trace = fields.Bool(
description="Whether to trace event (default false)",
required=False,
example=False,
)


class V20PresSpecByFormatRequestSchema(AdminAPIMessageTracingSchema):
"""Presentation specification schema by format, for send-presentation request."""

Expand Down Expand Up @@ -803,6 +823,9 @@ async def present_proof_create_request(request: web.BaseRequest):
will_confirm=True,
**_formats_attach(pres_request_spec, PRES_20_REQUEST, "request_presentations"),
)
auto_verify = body.get(
"auto_verify", context.settings.get("debug.auto_verify_presentation")
)
trace_msg = body.get("trace")
pres_request_message.assign_trace_decorator(
context.settings,
Expand All @@ -815,6 +838,7 @@ async def present_proof_create_request(request: web.BaseRequest):
pres_ex_record = await pres_manager.create_exchange_for_request(
connection_id=None,
pres_request_message=pres_request_message,
auto_verify=auto_verify,
)
result = pres_ex_record.serialize()
except (BaseModelError, StorageError) as err:
Expand Down Expand Up @@ -880,6 +904,9 @@ async def present_proof_send_free_request(request: web.BaseRequest):
will_confirm=True,
**_formats_attach(pres_request_spec, PRES_20_REQUEST, "request_presentations"),
)
auto_verify = body.get(
"auto_verify", context.settings.get("debug.auto_verify_presentation")
)
trace_msg = body.get("trace")
pres_request_message.assign_trace_decorator(
context.settings,
Expand All @@ -892,6 +919,7 @@ async def present_proof_send_free_request(request: web.BaseRequest):
pres_ex_record = await pres_manager.create_exchange_for_request(
connection_id=connection_id,
pres_request_message=pres_request_message,
auto_verify=auto_verify,
)
result = pres_ex_record.serialize()
except (BaseModelError, StorageError) as err:
Expand All @@ -918,7 +946,7 @@ async def present_proof_send_free_request(request: web.BaseRequest):
summary="Sends a presentation request in reference to a proposal",
)
@match_info_schema(V20PresExIdMatchInfoSchema())
@request_schema(AdminAPIMessageTracingSchema())
@request_schema(V20PresentationSendRequestToProposalSchema())
@response_schema(V20PresExRecordSchema(), 200, description="")
async def present_proof_send_bound_request(request: web.BaseRequest):
"""
Expand Down Expand Up @@ -966,6 +994,9 @@ async def present_proof_send_bound_request(request: web.BaseRequest):
if not conn_record.is_ready:
raise web.HTTPForbidden(reason=f"Connection {connection_id} not ready")

pres_ex_record.auto_verify = body.get(
"auto_verify", context.settings.get("debug.auto_verify_presentation")
)
pres_manager = V20PresManager(profile)
try:
(
Expand Down