Skip to content

Commit

Permalink
Merge pull request #1690 from shaangill025/issue#1687
Browse files Browse the repository at this point in the history
Fix: DIF proof proposal when creating bound presentation request [Issue#1687]
  • Loading branch information
andrewwhitehead authored Mar 30, 2022
2 parents bdba6b5 + 490c948 commit 4f89394
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from ....messaging.models.openapi import OpenAPISchema

from .pres_exch import InputDescriptorsSchema
from .pres_exch import InputDescriptorsSchema, DIFOptionsSchema


class DIFProofProposalSchema(OpenAPISchema):
Expand All @@ -16,3 +16,7 @@ class DIFProofProposalSchema(OpenAPISchema):
),
required=False,
)
options = fields.Nested(
DIFOptionsSchema(),
required=False,
)
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,18 @@ async def create_bound_request(
A tuple (updated presentation exchange record, presentation request message)
"""
dif_proof_request = pres_ex_record.pres_proposal.attachment(
dif_proof_request = {}
pres_proposal_dict = pres_ex_record.pres_proposal.attachment(
DIFPresFormatHandler.format
)
if "options" not in pres_proposal_dict:
dif_proof_request["options"] = {"challenge": str(uuid4())}
else:
dif_proof_request["options"] = pres_proposal_dict["options"]
del pres_proposal_dict["options"]
if "challenge" not in dif_proof_request.get("options"):
dif_proof_request["options"]["challenge"] = str(uuid4())
dif_proof_request["presentation_definition"] = pres_proposal_dict

return self.get_format_data(PRES_20_REQUEST, dif_proof_request)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ async def test_get_all_suites(self):
for suite in suites:
assert type(suite) in types

async def test_create_bound_request(self):
async def test_create_bound_request_a(self):
dif_proposal_dict = {
"input_descriptors": [
{
Expand Down Expand Up @@ -339,6 +339,118 @@ async def test_create_bound_request(self):
output[1], AttachDecorator
)

async def test_create_bound_request_b(self):
dif_proposal_dict = {
"options": {"challenge": "test123"},
"input_descriptors": [
{
"id": "citizenship_input_1",
"name": "EU Driver's License",
"group": ["A"],
"schema": [
{
"uri": "https://www.w3.org/2018/credentials#VerifiableCredential"
}
],
"constraints": {
"limit_disclosure": "required",
"fields": [
{
"path": ["$.credentialSubject.givenName"],
"purpose": "The claim must be from one of the specified issuers",
"filter": {"type": "string", "enum": ["JOHN", "CAI"]},
}
],
},
}
],
}
dif_pres_proposal = V20PresProposal(
formats=[
V20PresFormat(
attach_id="dif",
format_=ATTACHMENT_FORMAT[PRES_20_PROPOSAL][
V20PresFormat.Format.DIF.api
],
)
],
proposals_attach=[
AttachDecorator.data_json(dif_proposal_dict, ident="dif")
],
)
record = V20PresExRecord(
pres_ex_id="pxid",
thread_id="thid",
connection_id="conn_id",
initiator="init",
role="role",
state="state",
pres_proposal=dif_pres_proposal,
verified="false",
auto_present=True,
error_msg="error",
)
output = await self.handler.create_bound_request(pres_ex_record=record)
assert isinstance(output[0], V20PresFormat) and isinstance(
output[1], AttachDecorator
)

async def test_create_bound_request_c(self):
dif_proposal_dict = {
"options": {"domain": "test123"},
"input_descriptors": [
{
"id": "citizenship_input_1",
"name": "EU Driver's License",
"group": ["A"],
"schema": [
{
"uri": "https://www.w3.org/2018/credentials#VerifiableCredential"
}
],
"constraints": {
"limit_disclosure": "required",
"fields": [
{
"path": ["$.credentialSubject.givenName"],
"purpose": "The claim must be from one of the specified issuers",
"filter": {"type": "string", "enum": ["JOHN", "CAI"]},
}
],
},
}
],
}
dif_pres_proposal = V20PresProposal(
formats=[
V20PresFormat(
attach_id="dif",
format_=ATTACHMENT_FORMAT[PRES_20_PROPOSAL][
V20PresFormat.Format.DIF.api
],
)
],
proposals_attach=[
AttachDecorator.data_json(dif_proposal_dict, ident="dif")
],
)
record = V20PresExRecord(
pres_ex_id="pxid",
thread_id="thid",
connection_id="conn_id",
initiator="init",
role="role",
state="state",
pres_proposal=dif_pres_proposal,
verified="false",
auto_present=True,
error_msg="error",
)
output = await self.handler.create_bound_request(pres_ex_record=record)
assert isinstance(output[0], V20PresFormat) and isinstance(
output[1], AttachDecorator
)

async def test_create_pres(self):
dif_pres_request = V20PresRequest(
formats=[
Expand Down
2 changes: 1 addition & 1 deletion requirements.bbs.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ursa-bbs-signatures~=1.0.1
ursa-bbs-signatures==1.0.1

0 comments on commit 4f89394

Please sign in to comment.