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(did-comm) Support DIDComm Mediation #1095

Merged

Conversation

codynhat
Copy link
Contributor

@codynhat codynhat commented Dec 31, 2022

Initial part of #1051. Adds support for forwarding messages to mediators. I am submitting a draft PR here to make sure I am on the right track.

Still to do is handling forwarded messages and setting up the relationship between a user and mediator.

What issue is this PR fixing

closes #1051

What is being changed

A clear description of what this PR brings.

Quality

Check all that apply:

  • I want these changes to be integrated
  • I successfully ran yarn, yarn build, yarn test, yarn test:browser locally.
  • I allow my PR to be updated by the reviewers (to speed up the review process).
  • I added unit tests.
  • I added integration tests.
  • I did not add automated tests because _________, and I am aware that a PR without tests will likely get rejected.

@codecov
Copy link

codecov bot commented Dec 31, 2022

Codecov Report

Base: 80.25% // Head: 84.65% // Increases project coverage by +4.40% 🎉

Coverage data is based on head (765489b) compared to base (125bf42).
Patch coverage: 81.03% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #1095      +/-   ##
==========================================
+ Coverage   80.25%   84.65%   +4.40%     
==========================================
  Files         118      145      +27     
  Lines        4056    14800   +10744     
  Branches      875     1548     +673     
==========================================
+ Hits         3255    12529    +9274     
- Misses        798     2271    +1473     
+ Partials        3        0       -3     
Impacted Files Coverage Δ
packages/core-types/src/agent.ts 0.00% <0.00%> (ø)
packages/core-types/src/coreEvents.ts 0.00% <ø> (ø)
packages/core-types/src/index.ts 0.00% <0.00%> (ø)
...s/credential-ld/src/module-types/jsonld/index.d.ts 0.00% <0.00%> (ø)
packages/data-store-json/src/types.ts 0.00% <0.00%> (ø)
packages/did-provider-ion/src/functions.ts 95.68% <ø> (ø)
packages/did-provider-ion/src/index.ts 100.00% <ø> (ø)
packages/did-provider-ion/src/ion-did-provider.ts 85.21% <ø> (ø)
packages/did-provider-ion/src/ion-did-resolver.ts 82.35% <ø> (ø)
packages/did-provider-ion/src/ion-signer.ts 91.48% <ø> (ø)
... and 215 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

],
}

context.agent.emit('DIDCommV2Message-forwarded', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we want to emit this message at some point, but probably not here, since this is just the message wrapping. this event shouldn't get emitted until after the message is actually forwarded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about if the event was DIDCommV2Message-wrappedForward? In the case of their being more than one mediator, multiple messages would be wrapped but only one would be forwarded. Should this emit one message per wrap? Or only one message for the single forward?

// 2. Pack message for routingKey with anoncrypt
if (shouldUseSpecificKid) {
return this.packDIDCommMessageJWE(
{ message: forwardMessage, packing: 'anoncrypt', options: { recipientKids: [routingKey] } },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the forward protocol assume anoncrypt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see anywhere in the spec where this is mentioned explicitly. The example does not have a from field, meaning anoncrypt is used. https://identity.foundation/didcomm-messaging/spec/#messages

This seems to mean either could be used?

@codynhat codynhat force-pushed the feat/did-comm-routing branch 2 times, most recently from c752ea1 to de5353f Compare January 10, 2023 18:26
@codynhat codynhat changed the title [WIP] feat(did-comm) Support DIDComm Mediation feat(did-comm) Support DIDComm Mediation Jan 10, 2023
@codynhat codynhat marked this pull request as ready for review January 10, 2023 23:03
@codynhat
Copy link
Contributor Author

@nickreynolds This is ready for review. Here is a summary:

  • Three DIDComm protocols (Pickup, Mediator Coordinator, Routing) were added under protocols in the didcomm package, similar to Trust Ping
  • Routing Protocol
    • Handles a mediator receiving forward messages and saving one message for each kid
  • Mediator Coordinator Protocol
    • Handles a mediator receiving mediate-request and currently grants mediation to anyone who requests it
    • Handles a receiver receiving mediate-grant and mediate-deny and updates the DID doc service endpoint accordingly
  • Pickup Protocol
    • Handles a mediator receiving a status-request message, currently responding with the required message_count
    • Handles a mediator receiving a delivery-request and responding with a delivery
    • Handles a mediator receiving a messages-received message and deleting messages
    • Handles a recipient receiving a delivery request and handling all messages in a batch
  • Also adds return_route functionality to the HTTP transport
  • Also adds wrapping of messages in a forward when sent to a DID with a mediator in their DID doc

@nickreynolds
Copy link
Contributor

At first glance, this looks amazing. Thank you so much @codynhat !

This one might take a little while to fully review (and we're trying to finish up the ESM upgrade before merging in any other big features so might go unmerged even after it's approved) but thanks!

@codynhat
Copy link
Contributor Author

Sounds good!

@@ -137,6 +138,18 @@ export class DataStoreJson implements IAgentPlugin {
}
}

async dataStoreDeleteMessage(args: IDataStoreDeleteMessageArgs): Promise<boolean> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mirceanis I see that you originally removed this function, can you review this file's changes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were some unpleasant consequences when deleting stuff because of some typeorm misconfiguration in our entities, causing a cascade effect and deleting more than just the message, or throwing foreign key errors.

This should not be the case now, but this is the reason why some "delete" methods are weirdly missing or commented out.

The missing methods were not added to the data-store-json plugin to keep the API uniform, but we need to review this and normalize the API.

@codynhat codynhat force-pushed the feat/did-comm-routing branch from b3dece3 to a762bd2 Compare January 30, 2023 21:49
Copy link
Contributor

@nickreynolds nickreynolds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@nickreynolds nickreynolds merged commit 4b46a79 into decentralized-identity:next Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[proposal] Add Support for DIDCommv2 Mediation
3 participants