Skip to content

Commit

Permalink
allow didexchange request to set goal_code and goal
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Sherman <[email protected]>
  • Loading branch information
usingtechnology committed Jul 10, 2023
1 parent 6f10dc0 commit bfbcd12
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 3 deletions.
13 changes: 12 additions & 1 deletion aries_cloudagent/protocols/didexchange/v1_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ async def create_request_implicit(
mediation_id: str = None,
use_public_did: bool = False,
alias: str = None,
goal_code: str = None,
goal: str = None,
) -> ConnRecord:
"""
Create and send a request against a public DID only (no explicit invitation).
Expand All @@ -193,6 +195,8 @@ async def create_request_implicit(
my_endpoint: my endpoint
mediation_id: record id for mediation with routing_keys, service endpoint
use_public_did: use my public DID for this connection
goal_code: Optional self-attested code for sharing intent of connection
goal: Optional self-attested string for sharing intent of connection
Returns:
The new `ConnRecord` instance
Expand Down Expand Up @@ -225,6 +229,8 @@ async def create_request_implicit(
my_label=my_label,
my_endpoint=my_endpoint,
mediation_id=mediation_id,
goal_code=goal_code,
goal=goal,
)
conn_rec.request_id = request._id
conn_rec.state = ConnRecord.State.REQUEST.rfc23
Expand All @@ -242,6 +248,8 @@ async def create_request(
my_label: str = None,
my_endpoint: str = None,
mediation_id: str = None,
goal_code: str = None,
goal: str = None,
) -> DIDXRequest:
"""
Create a new connection request for a previously-received invitation.
Expand All @@ -252,7 +260,8 @@ async def create_request(
my_endpoint: My endpoint
mediation_id: The record id for mediation that contains routing_keys and
service endpoint
goal_code: Optional self-attested code for sharing intent of connection
goal: Optional self-attested string for sharing intent of connection
Returns:
A new `DIDXRequest` message to send to the other agent
Expand Down Expand Up @@ -327,6 +336,8 @@ async def create_request(
label=my_label,
did=conn_rec.my_did,
did_doc_attach=attach,
goal_code=goal_code,
goal=goal,
)
request.assign_thread_id(thid=request._id, pthid=pthid)

Expand Down
23 changes: 23 additions & 0 deletions aries_cloudagent/protocols/didexchange/v1_0/messages/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def __init__(
label: str = None,
did: str = None,
did_doc_attach: AttachDecorator = None,
goal_code: str = None,
goal: str = None,
**kwargs,
):
"""
Expand All @@ -39,11 +41,20 @@ def __init__(
label: Label for this request
did: DID for this request
did_doc_attach: signed DID doc attachment
goal_code: (optional) is a self-attested code the receiver may want to
display to the user or use in automatically deciding what to do with
the request message. The goal code might be used particularly when the
request is sent to a resolvable DID without reference to a specfic
invitation.
goal: (optional) is a self-attested string that the receiver may want to
display to the user about the context-specific goal of the request message.
"""
super().__init__(**kwargs)
self.label = label
self.did = did
self.did_doc_attach = did_doc_attach
self.goal_code = goal_code
self.goal = goal


class DIDXRequestSchema(AgentMessageSchema):
Expand All @@ -67,3 +78,15 @@ class Meta:
description="As signed attachment, DID Doc associated with DID",
data_key="did_doc~attach",
)
goal_code = fields.Str(
required=False,
description="A self-attested code the receiver may want to display to the user "
"or use in automatically deciding what to do with the out-of-band message",
example="issue-vc",
)
goal = fields.Str(
required=False,
description="A self-attested string that the receiver may want to display to the "
"user about the context-specific goal of the out-of-band message",
example="To issue a Faber College Graduate credential",
)
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class TestConfig:
test_verkey = "3Dn1SJNPaCXcvvJvSbsFWP2xaCjMom3can8CQNhWrTRx"
test_label = "Label"
test_endpoint = "http://localhost"
goal_code = "pytest"
goal = "pass pytest"

def make_did_doc(self):
doc = DIDDoc(did=self.test_did)
Expand Down Expand Up @@ -64,12 +66,16 @@ async def setUp(self):
label=TestConfig.test_label,
did=TestConfig.test_did,
did_doc_attach=did_doc_attach,
goal_code=TestConfig.goal_code,
goal=TestConfig.goal,
)

def test_init(self):
"""Test initialization."""
assert self.request.label == TestConfig.test_label
assert self.request.did == TestConfig.test_did
assert self.request.goal_code == TestConfig.goal_code
assert self.request.goal == TestConfig.goal

def test_type(self):
"""Test type."""
Expand Down Expand Up @@ -123,6 +129,8 @@ async def setUp(self):
label=TestConfig.test_label,
did=TestConfig.test_did,
did_doc_attach=did_doc_attach,
goal_code="pytest",
goal="pass pytest",
)

async def test_make_model(self):
Expand Down
16 changes: 16 additions & 0 deletions aries_cloudagent/protocols/didexchange/v1_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ class DIDXCreateRequestImplicitQueryStringSchema(OpenAPISchema):
required=False,
description="Use public DID for this connection",
)
goal_code = fields.Str(
required=False,
description="A self-attested code the receiver may want to display to the user "
"or use in automatically deciding what to do with the out-of-band message",
example="issue-vc",
)
goal = fields.Str(
required=False,
description="A self-attested string that the receiver may want to display to the "
"user about the context-specific goal of the out-of-band message",
example="To issue a Faber College Graduate credential",
)


class DIDXReceiveRequestImplicitQueryStringSchema(OpenAPISchema):
Expand Down Expand Up @@ -190,6 +202,8 @@ async def didx_create_request_implicit(request: web.BaseRequest):
mediation_id = request.query.get("mediation_id") or None
alias = request.query.get("alias") or None
use_public_did = json.loads(request.query.get("use_public_did", "null"))
goal_code = request.query.get("goal_code") or None
goal = request.query.get("goal") or None

profile = context.profile
didx_mgr = DIDXManager(profile)
Expand All @@ -201,6 +215,8 @@ async def didx_create_request_implicit(request: web.BaseRequest):
mediation_id=mediation_id,
use_public_did=use_public_did,
alias=alias,
goal_code=goal_code,
goal=goal,
)
except StorageNotFoundError as err:
raise web.HTTPNotFound(reason=err.roll_up) from err
Expand Down
6 changes: 4 additions & 2 deletions aries_cloudagent/protocols/out_of_band/v1_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,14 @@ class AttachmentDefSchema(OpenAPISchema):
)
goal_code = fields.Str(
required=False,
description="A self-attested code the receiver may want to display to the user or use in automatically deciding what to do with the out-of-band message",
description="A self-attested code the receiver may want to display to the user "
"or use in automatically deciding what to do with the out-of-band message",
example="issue-vc",
)
goal = fields.Str(
required=False,
description="A self-attested string that the receiver may want to display to the user about the context-specific goal of the out-of-band message",
description="A self-attested string that the receiver may want to display to the "
"user about the context-specific goal of the out-of-band message",
example="To issue a Faber College Graduate credential",
)

Expand Down

0 comments on commit bfbcd12

Please sign in to comment.