Picolab / aries-cloudagent-pico

Aries Cloud Agent - Pico
MIT License
4 stars 1 forks source link

Need to create a connection based on a pre-existing relationship #20

Closed b1conrad closed 2 years ago

b1conrad commented 2 years ago

Like so: image where the "label" of the connection is the "Id" of the relationship. This allows us to obtain the name of the other participant and the "Tx_role" and "Rx_role" of the other participant and the logged in participant, respectively.

b1conrad commented 2 years ago

The "Manage connections" page shows either a link to each relationship connection or a "make connection" button. If the other party doesn't have the byu.hr.connect ruleset then the button is disabled and a tooltip indicates that "[he] needs this app". It looks like this: Screen Shot 2022-03-16 at 8 33 09 AM

b1conrad commented 2 years ago

Next step is to allow participant to delete a connection. Then, I will delete the one that I created manually with Mirka, by

  1. In her pico's developer UI, grabbed an invitation with label the subscription Id (io.picolabs.aca.connections the invitation query)
  2. Visited the invitation's web page to confirm it looked right
  3. In my pico's developer UI, accepted the invitation (io.picolabs.aca the didcomm:message event)
b1conrad commented 2 years ago

Then write code to replicate what I did manually, in a rule. Pseudo code like this:

  select when byu_hr_connect connection_needed subscription_id re#(.+)# setting(s)
  pre { invite = picoQuery(ECI,"io.picolabs.aca.connections","invitation")}
  fired {
    raise aca event "new_label" attributes {"label":s}
    raise aca event "didcomm:message" attributes {"uri":invite}
    raise aca event "new_label" attributes {"label":ent:agentLabel}
  }

The byu_hr_connect:connection_needed event to be sent from the "Manage connections" page when the "make connection" button is clicked, using XMLHttpRequest and then putting up an alert saying "This may take a moment".

Another rule will select on the terminal event from io.picolabs.aca and redirect to the referer [sic]. While this is happening, the participant will have wasted enough clock time, clicking on the alert's OK button that the connection will be complete.

b1conrad commented 2 years ago

Works, but we have a race condition. The redirectBack ruleset and others in the first schedule complete before the connection is completely built. So, the "Manage connections" page gets refreshed too early.

Workaround is to manually refresh it.

b1conrad commented 2 years ago

Also, the subscription Id as label still didn't get propagated all the way to the other participant. Back to drawing board there.

b1conrad commented 2 years ago

Here's why the Id didn't get propagated. Below, the rules that are evaluated, each reacting to the event raised with the same number. The Id is set as the label at time (2) and reset at time (4). But it is needed at time (7)! The evaluation starts when the web page generates event (1). When the schedule is complete (after time (8)), the send_directive collected at time (5) redirects back to the referer [sic] page.

byu.hr.connect

  rule initiateConnectionForRelationship {
    select when byu_hr_connect connection_needed                                 (1)
      raise aca event "new_label" attributes {"label":Id}                         (2)
      raise didcomm event "message" attributes {"uri":invite}                     (3)
      raise aca event "new_label" attributes {"label":ent:agentLabel}             (4)
      raise byu_hr_connect event "connection_initiated" attributes event:attrs    (5)
...
  rule redirectBack {
    select when byu_hr_connect connection_initiated                               (5)

io.picolabs.aca

  rule route_outofband_message {
    select when didcomm message                                                   (3)
      raise event "didcomm_"+eventSpec attributes {"message":oobm}                 (6)
...
  rule update_label {
    select when aca:new_label                                                     (2,4)

io.picolabs.aca.connections

  rule receive_invitation {
    select when didcomm_connections:invitation                                     (6)
      raise aca_connections event "invitation_accepted"                             (7)
...
  rule initiate_connection_request {
    select when aca_connections invitation_accepted                                 (7)
      raise didcomm event "new_ssi_agent_wire_message"                               (8)
b1conrad commented 2 years ago

I think the rule initiate_connection_request ought to raise a terminal event, say aca_connections:connection_request_sent.

Then a rule in byu_hr_connect could select on it and raise the event that is now at time (4) so that it would be evaluated at time (9).

A parallel terminal event aca_connections:connection_response_sent could be raised in the initiate_connections_response rule. Those are the only two rules that raise didcomm event "new_ssi_agent_wire_message" and thus might be of interest to an outside ruleset that "operates" the agent by triggering its rules.

b1conrad commented 2 years ago

The race condition would be solved by implementing the idea written 10 hours earlier, «The byu_hr_connect:connection_needed event to be sent from the "Manage connections" page when the "make connection" button is clicked, using XMLHttpRequest and then putting up an alert saying "This may take a moment".» And after the participant clicks OK, reloading the page. This would also eliminate the raise and rule selection at time (5).

b1conrad commented 2 years ago

Using JavaScript and XMLHttpRequest means that we can use the encodeURIComponent function in that language instead of punting it in KRL.

b1conrad commented 2 years ago

Adding terminal events (in this commit). Always a good thing. Turns out that the ACA-Pico rulesets do not pass through event attributes. So the rule selecting on the byu_hr_connect event "connection_initiated" doesn't fire. Which is fine, because it'll be gone with the race condition.

b1conrad commented 2 years ago

Urk. The commit that should have fixed the race condition brings up a quoting problem.

<button onclick="makeConnection('#{makeURL}','#{s.encode()}')">make connection</button>

doesn't work because s.encode() produces a lot of double quote characters (cause s is a Map), so need to figure out a different way.

b1conrad commented 2 years ago

The problems have been solved with a few commits. Connections over relationships can now be made and deleted at will, with just a couple of mouse clicks.