-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(oob): expose parseInvitation publicly (#834)
Signed-off-by: Berend Sliedrecht <[email protected]> Co-authored-by: Timo Glastra <[email protected]>
- Loading branch information
1 parent
a4bc215
commit 5767500
Showing
3 changed files
with
34 additions
and
20 deletions.
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
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`.' | ||
) | ||
} |