-
Notifications
You must be signed in to change notification settings - Fork 204
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(core): add support for multi use invitations #460
Merged
TimoGlastra
merged 1 commit into
openwallet-foundation:main
from
TimoGlastra:feat/multi-use-invitations
Sep 30, 2021
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,14 +68,16 @@ export class ConnectionService { | |
routing: Routing | ||
autoAcceptConnection?: boolean | ||
alias?: string | ||
multiUseInvitation?: boolean | ||
}): Promise<ConnectionProtocolMsgReturnType<ConnectionInvitationMessage>> { | ||
// TODO: public did, multi use | ||
// TODO: public did | ||
const connectionRecord = await this.createConnection({ | ||
role: ConnectionRole.Inviter, | ||
state: ConnectionState.Invited, | ||
alias: config?.alias, | ||
routing: config.routing, | ||
autoAcceptConnection: config?.autoAcceptConnection, | ||
multiUseInvitation: config.multiUseInvitation ?? false, | ||
}) | ||
|
||
const { didDoc } = connectionRecord | ||
|
@@ -130,6 +132,7 @@ export class ConnectionService { | |
tags: { | ||
invitationKey: invitation.recipientKeys && invitation.recipientKeys[0], | ||
}, | ||
multiUseInvitation: false, | ||
}) | ||
await this.connectionRepository.update(connectionRecord) | ||
this.eventEmitter.emit<ConnectionStateChangedEvent>({ | ||
|
@@ -179,9 +182,11 @@ export class ConnectionService { | |
* @returns updated connection record | ||
*/ | ||
public async processRequest( | ||
messageContext: InboundMessageContext<ConnectionRequestMessage> | ||
messageContext: InboundMessageContext<ConnectionRequestMessage>, | ||
routing?: Routing | ||
): Promise<ConnectionRecord> { | ||
const { message, connection: connectionRecord, recipientVerkey } = messageContext | ||
const { message, recipientVerkey } = messageContext | ||
let connectionRecord = messageContext.connection | ||
|
||
if (!connectionRecord) { | ||
throw new AriesFrameworkError(`Connection for verkey ${recipientVerkey} not found!`) | ||
|
@@ -194,6 +199,25 @@ export class ConnectionService { | |
throw new AriesFrameworkError('Invalid message') | ||
} | ||
|
||
// Create new connection if using a multi use invitation | ||
if (connectionRecord.multiUseInvitation) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be combined with the if statement below. |
||
if (!routing) { | ||
throw new AriesFrameworkError( | ||
'Cannot process request for multi-use invitation without routing object. Make sure to call processRequest with the routing parameter provided.' | ||
) | ||
} | ||
|
||
connectionRecord = await this.createConnection({ | ||
role: connectionRecord.role, | ||
state: connectionRecord.state, | ||
multiUseInvitation: false, | ||
routing, | ||
autoAcceptConnection: connectionRecord.autoAcceptConnection, | ||
invitation: connectionRecord.invitation, | ||
tags: connectionRecord.getTags(), | ||
}) | ||
} | ||
|
||
connectionRecord.theirDidDoc = message.connection.didDoc | ||
connectionRecord.theirLabel = message.label | ||
connectionRecord.threadId = message.id | ||
|
@@ -233,9 +257,12 @@ export class ConnectionService { | |
throw new AriesFrameworkError(`Connection record with id ${connectionId} does not have a thread id`) | ||
} | ||
|
||
// Use invitationKey by default, fall back to verkey | ||
const signingKey = (connectionRecord.getTag('invitationKey') as string) ?? connectionRecord.verkey | ||
|
||
const connectionResponse = new ConnectionResponseMessage({ | ||
threadId: connectionRecord.threadId, | ||
connectionSig: await signData(connectionJson, this.wallet, connectionRecord.verkey), | ||
connectionSig: await signData(connectionJson, this.wallet, signingKey), | ||
}) | ||
|
||
await this.updateState(connectionRecord, ConnectionState.Responded) | ||
|
@@ -533,6 +560,7 @@ export class ConnectionService { | |
routing: Routing | ||
theirLabel?: string | ||
autoAcceptConnection?: boolean | ||
multiUseInvitation: boolean | ||
tags?: CustomConnectionTags | ||
}): Promise<ConnectionRecord> { | ||
const { endpoints, did, verkey, routingKeys } = options.routing | ||
|
@@ -579,6 +607,7 @@ export class ConnectionService { | |
alias: options.alias, | ||
theirLabel: options.theirLabel, | ||
autoAcceptConnection: options.autoAcceptConnection, | ||
multiUseInvitation: options.multiUseInvitation, | ||
}) | ||
|
||
await this.connectionRepository.save(connectionRecord) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is routing really necessary for multi-use invitations in general? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not. But I would rather take all edge cases into account for these things. Otherwise we need good documentation on what features do and don't work together :)