use tryandwait()

This commit is contained in:
Daniel Lugo 2020-02-24 15:28:21 -04:00
parent ad941bcdb1
commit 9a9ea5e7a2

View file

@ -182,12 +182,21 @@ const successfulHandshakeAlreadyExists = async recipientPub => {
* @returns {Promise<string|null>}
*/
const recipientToOutgoingID = async recipientPub => {
const maybeEncryptedOutgoingID = await require('../../Mediator/index')
.getUser()
const maybeEncryptedOutgoingID = await tryAndWait(async (_, user) => {
const oid = await user
.get(Key.RECIPIENT_TO_OUTGOING)
.get(recipientPub)
.then()
if (typeof oid !== 'string' && oid !== null) {
throw new Error(
'Expected outgoing id from recipient-to-outgoing-id map to be an string or null'
)
}
return oid
})
if (typeof maybeEncryptedOutgoingID === 'string') {
const outgoingID = await require('../../Mediator/index').mySEA.decrypt(
maybeEncryptedOutgoingID,