Skip to content

Commit

Permalink
fix(oob): expose parseInvitation publicly (#834)
Browse files Browse the repository at this point in the history
Signed-off-by: Berend Sliedrecht <[email protected]>

Co-authored-by: Timo Glastra <[email protected]>
  • Loading branch information
berendsliedrecht and TimoGlastra authored Jun 8, 2022
1 parent a4bc215 commit 5767500
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type { Wallet } from './wallet/Wallet'
export type { TransportSession } from './agent/TransportService'
export { TransportService } from './agent/TransportService'

import { parseInvitationUrl } from './utils/parseInvitation'
import { uuid } from './utils/uuid'

export * from './transport'
Expand All @@ -44,6 +45,7 @@ export * from './agent/Events'

const utils = {
uuid,
parseInvitationUrl,
}

export { utils }
25 changes: 5 additions & 20 deletions packages/core/src/modules/oob/OutOfBandModule.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import type { AgentMessage } from '../../agent/AgentMessage'
import type { AgentMessageReceivedEvent } from '../../agent/Events'
import type { Logger } from '../../logger'
import type { ConnectionRecord, Routing } from '../../modules/connections'
import type { ConnectionRecord, Routing, ConnectionInvitationMessage } from '../../modules/connections'
import type { PlaintextMessage } from '../../types'
import type { Key } from '../dids'
import type { HandshakeReusedEvent } from './domain/OutOfBandEvents'

import { parseUrl } from 'query-string'
import { catchError, EmptyError, first, firstValueFrom, map, of, timeout } from 'rxjs'
import { Lifecycle, scoped } from 'tsyringe'

Expand All @@ -18,15 +17,11 @@ import { MessageSender } from '../../agent/MessageSender'
import { createOutboundMessage } from '../../agent/helpers'
import { ServiceDecorator } from '../../decorators/service/ServiceDecorator'
import { AriesFrameworkError } from '../../error'
import {
DidExchangeState,
HandshakeProtocol,
ConnectionInvitationMessage,
ConnectionsModule,
} from '../../modules/connections'
import { DidExchangeState, HandshakeProtocol, ConnectionsModule } from '../../modules/connections'
import { DidCommMessageRepository, DidCommMessageRole } from '../../storage'
import { JsonEncoder, JsonTransformer } from '../../utils'
import { parseMessageType, supportsIncomingMessageType } from '../../utils/messageType'
import { parseInvitationUrl } from '../../utils/parseInvitation'
import { DidKey } from '../dids'
import { didKeyToVerkey } from '../dids/helpers'
import { outOfBandServiceToNumAlgo2Did } from '../dids/methods/peer/peerDidNumAlgo2'
Expand Down Expand Up @@ -280,18 +275,8 @@ export class OutOfBandModule {
*
* @returns OutOfBandInvitation
*/
public async parseInvitation(invitationUrl: string) {
const parsedUrl = parseUrl(invitationUrl).query
if (parsedUrl['oob']) {
const outOfBandInvitation = await OutOfBandInvitation.fromUrl(invitationUrl)
return outOfBandInvitation
} else if (parsedUrl['c_i'] || parsedUrl['d_m']) {
const invitation = await ConnectionInvitationMessage.fromUrl(invitationUrl)
return convertToNewInvitation(invitation)
}
throw new AriesFrameworkError(
'InvitationUrl is invalid. It needs to contain one, and only one, of the following parameters: `oob`, `c_i` or `d_m`.'
)
public async parseInvitation(invitationUrl: string): Promise<OutOfBandInvitation> {
return await parseInvitationUrl(invitationUrl)
}

/**
Expand Down
27 changes: 27 additions & 0 deletions packages/core/src/utils/parseInvitation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { parseUrl } from 'query-string'

import { AriesFrameworkError } from '../error'
import { ConnectionInvitationMessage } from '../modules/connections'
import { convertToNewInvitation } from '../modules/oob/helpers'
import { OutOfBandInvitation } from '../modules/oob/messages'

/**
* Parses URL containing encoded invitation and returns invitation message.
*
* @param invitationUrl URL containing encoded invitation
*
* @returns OutOfBandInvitation
*/
export const parseInvitationUrl = async (invitationUrl: string): Promise<OutOfBandInvitation> => {
const parsedUrl = parseUrl(invitationUrl).query
if (parsedUrl['oob']) {
const outOfBandInvitation = await OutOfBandInvitation.fromUrl(invitationUrl)
return outOfBandInvitation
} else if (parsedUrl['c_i'] || parsedUrl['d_m']) {
const invitation = await ConnectionInvitationMessage.fromUrl(invitationUrl)
return convertToNewInvitation(invitation)
}
throw new AriesFrameworkError(
'InvitationUrl is invalid. It needs to contain one, and only one, of the following parameters: `oob`, `c_i` or `d_m`.'
)
}

0 comments on commit 5767500

Please sign in to comment.