use mysecret util and avoid dep inj
This commit is contained in:
parent
1b0202c950
commit
f26612c0d6
1 changed files with 19 additions and 18 deletions
|
|
@ -143,31 +143,32 @@ const successfulHandshakeAlreadyExists = async recipientPub => {
|
||||||
return userToIncoming.get(recipientPub).then()
|
return userToIncoming.get(recipientPub).then()
|
||||||
})
|
})
|
||||||
|
|
||||||
return typeof maybeIncomingID === 'string'
|
const maybeOutgoingID = await tryAndWait((_, user) => {
|
||||||
|
const recipientToOutgoing = user.get(Key.RECIPIENT_TO_OUTGOING)
|
||||||
|
|
||||||
|
return recipientToOutgoing.get(recipientPub).then()
|
||||||
|
})
|
||||||
|
|
||||||
|
return (
|
||||||
|
typeof maybeIncomingID === 'string' && typeof maybeOutgoingID === 'string'
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} recipientPub
|
* @param {string} recipientPub
|
||||||
* @param {UserGUNNode} user
|
|
||||||
* @param {ISEA} SEA
|
|
||||||
* @returns {Promise<string|null>}
|
* @returns {Promise<string|null>}
|
||||||
*/
|
*/
|
||||||
const recipientToOutgoingID = async (recipientPub, user, SEA) => {
|
const recipientToOutgoingID = async recipientPub => {
|
||||||
const mySecret = await SEA.secret(user._.sea.epub, user._.sea)
|
const maybeEncryptedOutgoingID = await getUser()
|
||||||
|
|
||||||
if (typeof mySecret !== 'string') {
|
|
||||||
throw new TypeError('could not get mySecret')
|
|
||||||
}
|
|
||||||
|
|
||||||
const maybeEncryptedOutgoingID = await tryAndWait((_, user) =>
|
|
||||||
user
|
|
||||||
.get(Key.RECIPIENT_TO_OUTGOING)
|
.get(Key.RECIPIENT_TO_OUTGOING)
|
||||||
.get(recipientPub)
|
.get(recipientPub)
|
||||||
.then()
|
.then()
|
||||||
)
|
|
||||||
|
|
||||||
if (typeof maybeEncryptedOutgoingID === 'string') {
|
if (typeof maybeEncryptedOutgoingID === 'string') {
|
||||||
const outgoingID = await SEA.decrypt(maybeEncryptedOutgoingID, mySecret)
|
const outgoingID = await SEA.decrypt(
|
||||||
|
maybeEncryptedOutgoingID,
|
||||||
|
await mySecret()
|
||||||
|
)
|
||||||
|
|
||||||
return outgoingID || null
|
return outgoingID || null
|
||||||
}
|
}
|
||||||
|
|
@ -196,7 +197,7 @@ const reqWasAccepted = async (reqResponse, recipientPub, user, SEA) => {
|
||||||
throw new TypeError('typeof decryptedResponse !== "string"')
|
throw new TypeError('typeof decryptedResponse !== "string"')
|
||||||
}
|
}
|
||||||
|
|
||||||
const myFeedID = await recipientToOutgoingID(recipientPub, user, SEA)
|
const myFeedID = await recipientToOutgoingID(recipientPub)
|
||||||
|
|
||||||
if (typeof myFeedID === 'string' && decryptedResponse === myFeedID) {
|
if (typeof myFeedID === 'string' && decryptedResponse === myFeedID) {
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue