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

fix: allow reconnections to a multi-use invitation. #1395

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TheTreek
Copy link
Contributor

We were not able to connect to a multi-use invitation more than once. Removing this check will allow us to do so.

@TheTreek TheTreek requested a review from a team as a code owner March 20, 2023 22:03
@genaris
Copy link
Contributor

genaris commented Mar 20, 2023

AFAIK the purpose of multi-use invitations is for an inviter to publish a single invitation that can be received by multiple invitees. This does not mean that an invitee (a.k.a. Receiver) can process the same invitation multiple times. So in that sense I think the check in current code is correct.

Is that the use case you are referring to?

@TimoGlastra
Copy link
Contributor

What's the specific use case here? In general we need the invitation id to be unique so we can use that for querying the records. So even if this may work in this case, it's not designed for it.

I think you could either remove the old connection, or query for a connection using the existing invitation id. Would that work?

@TimoGlastra
Copy link
Contributor

@genaris do you know if it's safe to remove this check?

@TimoGlastra
Copy link
Contributor

Ah you already commented, my GH was outdated

@genaris
Copy link
Contributor

genaris commented Mar 20, 2023

@genaris do you know if it's safe to remove this check?

OutOfBandService has a findByReceivedInvitationId method where it expects to find a single OutOfBandRecord related to a given invitation id. As far as I can see, this is only used at agent initialization when using mediatorInvitationUrl: it's used to find out if we are already connected to the mediator.

I could not find a limitation from RFCs/protocol point of view to process the same invitation more than once, so probably it can be safe to remove this check and refactor findByReceivedInvitationId to findAllByReceivedInvitationId. Also it will be needed a bit of rework in getMediationConnection to accept an array of OutOfBandRecord instead of a single one.

@JamesKEbert
Copy link
Contributor

What's the specific use case here? In general we need the invitation id to be unique so we can use that for querying the records. So even if this may work in this case, it's not designed for it.

The #1 best use case that comes to mind is if an invitation is printed on poster or sign for a physical event or where you provide a single invitation to the end user. Additionally, if that issuer does not support connection reuse then there may need to be multiple connections created for workflows that get repeated multiple times.

Indicio's immediate-term use case requires us to hard-code the invitation with the application at build time, so it can't be dynamic/single-use and the user needs to be able to run through the workflow multiple times.

@NimeshNB
Copy link

@TheTreek Did you found any solution for this?
I'm facing similar type of issue,
i.e: if user accidentally delete connection and wanted to reconnect then can use multi-use invitation

@TimoGlastra
Copy link
Contributor

I think with some work we can fix the issue that this PR is trying to solve. But I do think it needs to be a bit more complex. ids for messages are meant to be unique, and thus I would rather say we reuse the same out of band record (becuase it's the same oob invitation). We should check though if the invitation from the oob record is the same as the invitation that is parsed the second time (so we don't have two different invitations that have the same id).

@NimeshNB
Copy link

NimeshNB commented Jun 2, 2023

@TimoGlastra we are able to solve this by adding some conditions
if outOfBandRecord does not exist then only it will create new outOfBandRecord else it will use existing one for multi use invite so that id will remain same

if(!outOfBandRecord){
           const recipientKeyFingerprints = [];
           for (const service of outOfBandInvitation.getServices()) {
               // Resolve dids to DIDDocs to retrieve services
               if (typeof service === 'string') {
                   this.logger.debug(`Resolving services for did ${service}.`);
                   const resolvedDidCommServices = await this.didCommDocumentService.resolveServicesFromDid(this.agentContext, service);
                   recipientKeyFingerprints.push(...resolvedDidCommServices
                       .reduce((aggr, { recipientKeys }) => [...aggr, ...recipientKeys], [])
                       .map((key) => key.fingerprint));
               }
               else {
                   recipientKeyFingerprints.push(...service.recipientKeys.map((didKey) => dids_1.DidKey.fromDid(didKey).key.fingerprint));
               }
           }
           outOfBandRecord = new OutOfBandRecord_1.OutOfBandRecord({
               role: OutOfBandRole_1.OutOfBandRole.Receiver,
               state: OutOfBandState_1.OutOfBandState.Initial,
               outOfBandInvitation: outOfBandInvitation,
               autoAcceptConnection,
               tags: { recipientKeyFingerprints },
           });
           await this.outOfBandService.save(this.agentContext, outOfBandRecord);
           this.outOfBandService.emitStateChangedEvent(this.agentContext, outOfBandRecord, null);
       }

@TimoGlastra
Copy link
Contributor

Discussed in AFJ WG call. The change to remove the check is a good one, but there may be some issues as @genaris pointed out. @TheTreek do you have time to make the changes as @genaris suggested? Otherwise @genaris can pick this up

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.

5 participants