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: add support for new out-of-band protocol #531

Closed
wants to merge 46 commits into from

Conversation

jakubkoci
Copy link
Contributor

This is the first step in the implementation of #344.

It corresponds approximately to Step 1 defined in Aries RFC 0496: Transition to the Out of Band and DID Exchange Protocols.

As you can see I decided to create an Out-of-band module and keep the implementation there. I realized that putting it into the Connection module could cause more issues than benefits right now. It has only two drawbacks:

  • API users would need to decide what method to call for now. But it allows more gradual adoption of new out-of-band by users. When we have a full implementation, users will ideally just call one method for OOB messages.
  • I copy-pasted methods for connection creation. That can be solved by calling the whole Connections module from the OOB module.

@jakubkoci jakubkoci requested a review from a team as a code owner November 8, 2021 15:59
@jakubkoci jakubkoci changed the title Out of band feat: Add support for new out-of-band protocol Stage 1 Nov 8, 2021
@codecov-commenter
Copy link

codecov-commenter commented Nov 8, 2021

Codecov Report

Merging #531 (7a6ea0e) into main (8e03f35) will increase coverage by 0.49%.
The diff coverage is 92.59%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #531      +/-   ##
==========================================
+ Coverage   86.88%   87.38%   +0.49%     
==========================================
  Files         308      316       +8     
  Lines        6513     6755     +242     
  Branches      965     1067     +102     
==========================================
+ Hits         5659     5903     +244     
+ Misses        850      848       -2     
  Partials        4        4              
Impacted Files Coverage Δ
.../core/src/modules/connections/ConnectionsModule.ts 83.13% <ø> (+9.63%) ⬆️
.../modules/connections/services/ConnectionService.ts 89.86% <ø> (+1.32%) ⬆️
packages/core/src/modules/oob/OutOfBandModule.ts 91.25% <91.25%> (ø)
.../core/src/modules/oob/messages/OutOfBandMessage.ts 92.72% <92.72%> (ø)
packages/core/src/agent/Agent.ts 99.03% <100.00%> (+0.99%) ⬆️
packages/core/src/agent/MessageReceiver.ts 83.16% <100.00%> (+1.72%) ⬆️
packages/core/src/index.ts 100.00% <100.00%> (ø)
.../src/modules/oob/handlers/HandshakeReuseHandler.ts 100.00% <100.00%> (ø)
packages/core/src/modules/oob/handlers/index.ts 100.00% <100.00%> (ø)
.../src/modules/oob/messages/HandshakeReuseMessage.ts 100.00% <100.00%> (ø)
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8e03f35...7a6ea0e. Read the comment docs.

Copy link
Contributor

@TimoGlastra TimoGlastra left a comment

Choose a reason for hiding this comment

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

Nice work @jakubkoci! Glad to see the OOB protocol finally being added to AFJ.

I'm not so sure on splitting the createInvitation from createOobMessage. Both create an OOB invitation. And I think we're missing some of the nice combinations here. handshake_protocols and requests~attach are not exclusive, so I think it may be easier to just create a single createInvitation and a single receiveInvitation method that allows to specify what should be done with handshake protocols / attached messages.

Second point is that I'd rather not merge this PR as is. It feels like we are leaving a lot of TODOs out there, while I would rather just add OOB as a whole, where we have really thought about all implementation details. There are still a lot of unknowns with connection reuse, connectionless, did-exchange and an OOB record that I would rather keep it in a separate OOB branch for now. What do you think?

packages/core/src/modules/oob/OutOfBandMessage.ts Outdated Show resolved Hide resolved
packages/core/src/modules/oob/OutOfBandMessage.ts Outdated Show resolved Hide resolved
public readonly goal?: string

// TODO what type is it, is there any enum or should we create a new one
public readonly accept: string[] = []
Copy link
Contributor

Choose a reason for hiding this comment

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

No enum yet, need to create a new one

Copy link
Contributor Author

@jakubkoci jakubkoci Nov 24, 2021

Choose a reason for hiding this comment

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

Not sure if the enum is the best solution. It could prevent the framework from being dynamically enhanced. I've been thinking about where the information about accepted mime types should reside. Maybe inside the EnvelopeService 🤔

@IsInstance(Attachment, { each: true })
private requests?: Attachment[]

public readonly services: DidCommService[] = []
Copy link
Contributor

Choose a reason for hiding this comment

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

Can also be plain dids (strings)

packages/core/src/modules/oob/OutOfBandModule.ts Outdated Show resolved Hide resolved
const invitation = new ConnectionInvitationMessage({ label: 'connection label', ...outOfBandMessage.services[0] })

let connectionRecord = await this.connectionService.processInvitation(invitation, { routing })
if (config.autoAccept) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want this to take into account agent config autoAcceptConnection?

Comment on lines 137 to 138
outOfBandMessage.services.push(message.service.toDidCommService())
message.service = undefined
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the advantage of using OOB is that the AgentMessage itself doesn't need the ~service anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just a workaround for now. It allows us to pass the AgentMessage into receiveMessage and still be able to process it with the current implementation.

*/
public async receiveOobMessage(outOfBandMessage: OutOfBandMessage): Promise<void> {
if (outOfBandMessage.handshakeProtocols) {
throw new AriesFrameworkError('OOB message contains unsupported `handshake_protocols` attribute.')
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels a bit misleading, handshake_protocols is definitely supported, just not in this method.

Also, does this mean handshake_protocols and requests~attach can't be combined in AFJ?

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'll definitely look at the unification of those methods as you suggested in another comment.

But the combination of handshake_protocols and requests~attach is not allowed according to Step 1 in Aries RFC 0496: Transition to the Out of Band and DID Exchange Protocols

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. It supports both handshake_protocols and requests~attach.

packages/core/src/modules/oob/OutOfBandMessage.ts Outdated Show resolved Hide resolved
Comment on lines 72 to 74
const mediationRecord = await this.mediationRecipientService.discoverMediation()
const routing = await this.mediationRecipientService.getRouting(mediationRecord)
const { connectionRecord: connectionRecord } = await this.connectionService.createInvitation({
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be good to allow modules to call modules as it can prevent some duplication here

@jakubkoci
Copy link
Contributor Author

Hi @TimoGlastra. Thanks for the suggestions and feedback. I unified it into just two methods createMessage and receiveMessage. It make sense for receiveMessage I don't have doubt there, but createMessage looks much worse now. I'm gonna look at oob record and other missing parts you mentioned, how they fit in and maybe it improves implementation by itself :)

I'm good with not merging it right now. I wasn't sure if we want to do it according to that transition spec or not. If we don't we can wait and merge as a whole, I guess.

@jakubkoci jakubkoci force-pushed the out-of-band branch 3 times, most recently from 9677049 to cc60cb2 Compare November 18, 2021 07:59
@jakubkoci jakubkoci force-pushed the out-of-band branch 2 times, most recently from c49b971 to 7fa4006 Compare November 23, 2021 08:35
@jakubkoci jakubkoci force-pushed the out-of-band branch 2 times, most recently from 7464bf3 to 1bc158d Compare November 24, 2021 14:30
@jakubkoci jakubkoci changed the title feat: Add support for new out-of-band protocol Stage 1 feat: add support for new out-of-band protocol Nov 25, 2021
@jakubkoci jakubkoci force-pushed the out-of-band branch 2 times, most recently from 7dd2460 to e3d2a74 Compare December 29, 2021 18:24
@jakubkoci
Copy link
Contributor Author

jakubkoci commented Dec 30, 2021

It's still not polished as I wished, but it's working according to Step 1 at least. It actually does more than Step 1. I wrote a brief overview of what's done and what's missing:

Done

  • create oob with connection invitation
  • create oob with connection invitation with message requests
  • create oob only with message requests
  • create a connection based on oob invitation
  • create a connection based on oob invitation and process message requests
  • process connection-less message requests
  • support for both old and new encoded URL

Todo

  • Handle handshake reuse message
  • Store all messages to prevent losing them when an agent goes down.
  • Replace old ConnectionInvitationMessage with the new OutOfBandMessage.
  • Use DIDs. Transform to/from Peer DID, DID key, DID peer (feat: add generic did resolver #554 helps a lot with it)
  • Allow creating oob for an existing connection.
  • Process only the first supported message
  • Validate services

Copy link
Contributor

@TimoGlastra TimoGlastra left a comment

Choose a reason for hiding this comment

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

Overall structure LGTM 👍 , but have left a lot of quibbles

packages/core/src/modules/oob/OutOfBandModule.ts Outdated Show resolved Hide resolved
packages/core/src/modules/oob/OutOfBandModule.ts Outdated Show resolved Hide resolved
packages/core/src/modules/oob/OutOfBandModule.ts Outdated Show resolved Hide resolved
packages/core/src/modules/oob/OutOfBandModule.ts Outdated Show resolved Hide resolved
packages/core/src/modules/oob/OutOfBandModule.ts Outdated Show resolved Hide resolved
packages/core/src/modules/oob/messages/OutOfBandMessage.ts Outdated Show resolved Hide resolved
packages/core/src/modules/oob/OutOfBandModule.ts Outdated Show resolved Hide resolved
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
@jakubkoci
Copy link
Contributor Author

I consider the code in here approved. I moved it to the feat/out-of-band branch, where I'll continue with adding did exchange protocol.

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.

None yet

3 participants