Skip to content

Commit

Permalink
refactor(oob)!: merge oob invitation parsing (#1134)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoGlastra authored Dec 1, 2022
1 parent f294129 commit 157a357
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 18 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/agent/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class Agent<AgentModules extends AgentModulesInput = ModulesMap> extends
}

protected async getMediationConnection(mediatorInvitationUrl: string) {
const outOfBandInvitation = this.oob.parseInvitation(mediatorInvitationUrl)
const outOfBandInvitation = await this.oob.parseInvitation(mediatorInvitationUrl)
const outOfBandRecord = await this.oob.findByInvitationId(outOfBandInvitation.id)
const [connection] = outOfBandRecord ? await this.connections.findAllByOutOfBandId(outOfBandRecord.id) : []

Expand Down
20 changes: 5 additions & 15 deletions packages/core/src/modules/oob/OutOfBandApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { inject, injectable } from '../../plugins'
import { DidCommMessageRepository, DidCommMessageRole } from '../../storage'
import { JsonEncoder, JsonTransformer } from '../../utils'
import { parseMessageType, supportsIncomingMessageType } from '../../utils/messageType'
import { parseInvitationUrl, parseInvitationShortUrl } from '../../utils/parseInvitation'
import { parseInvitationShortUrl } from '../../utils/parseInvitation'
import { ConnectionsApi, DidExchangeState, HandshakeProtocol } from '../connections'
import { DidCommDocumentService } from '../didcomm'
import { DidKey } from '../dids'
Expand Down Expand Up @@ -281,32 +281,22 @@ export class OutOfBandApi {
* @returns out-of-band record and connection record if one has been created
*/
public async receiveInvitationFromUrl(invitationUrl: string, config: ReceiveOutOfBandInvitationConfig = {}) {
const message = await this.parseInvitationShortUrl(invitationUrl)
const message = await this.parseInvitation(invitationUrl)

return this.receiveInvitation(message, config)
}

/**
* Parses URL containing encoded invitation and returns invitation message.
*
* @param invitationUrl URL containing encoded invitation
*
* @returns OutOfBandInvitation
*/
public parseInvitation(invitationUrl: string): OutOfBandInvitation {
return parseInvitationUrl(invitationUrl)
}

/**
* Parses URL containing encoded invitation and returns invitation message. Compatible with
* parsing shortened URLs
* Will fetch the url if the url does not contain a base64 encoded invitation.
*
* @param invitationUrl URL containing encoded invitation
*
* @returns OutOfBandInvitation
*/
public async parseInvitationShortUrl(invitation: string): Promise<OutOfBandInvitation> {
return await parseInvitationShortUrl(invitation, this.agentContext.config.agentDependencies)
public async parseInvitation(invitationUrl: string): Promise<OutOfBandInvitation> {
return parseInvitationShortUrl(invitationUrl, this.agentContext.config.agentDependencies)
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/utils/parseInvitation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const parseInvitationUrl = (invitationUrl: string): OutOfBandInvitation =
)
}

//This currently does not follow the RFC because of issues with fetch, currently uses a janky work around
// This currently does not follow the RFC because of issues with fetch, currently uses a janky work around
export const oobInvitationFromShortUrl = async (response: Response): Promise<OutOfBandInvitation> => {
if (response) {
if (response.headers.get('Content-Type')?.startsWith('application/json') && response.ok) {
Expand Down Expand Up @@ -90,7 +90,7 @@ export const oobInvitationFromShortUrl = async (response: Response): Promise<Out
*
* @param invitationUrl URL containing encoded invitation
*
* @param dependencies Agent dependicies containing fetch
* @param dependencies Agent dependencies containing fetch
*
* @returns OutOfBandInvitation
*/
Expand Down

0 comments on commit 157a357

Please sign in to comment.