use memoized secret

This commit is contained in:
Daniel Lugo 2020-02-09 13:41:04 -04:00
parent b8aae30f67
commit 6774278e77
3 changed files with 7 additions and 18 deletions

View file

@ -58,12 +58,7 @@ const __createOutgoingFeed = async (withPublicKey, user, SEA) => {
throw new Error(ErrorCode.NOT_AUTH) throw new Error(ErrorCode.NOT_AUTH)
} }
const mySecret = await SEA.secret(user._.sea.epub, user._.sea) const mySecret = require('../Mediator').getMySecret()
if (typeof mySecret !== 'string') {
throw new TypeError(
"__createOutgoingFeed() -> typeof mySecret !== 'string'"
)
}
const encryptedForMeRecipientPub = await SEA.encrypt(withPublicKey, mySecret) const encryptedForMeRecipientPub = await SEA.encrypt(withPublicKey, mySecret)
const maybeEncryptedForMeOutgoingFeedID = await Utils.tryAndWait( const maybeEncryptedForMeOutgoingFeedID = await Utils.tryAndWait(
@ -254,10 +249,7 @@ const acceptRequest = async (
SEA SEA
) )
const mySecret = await SEA.secret(user._.sea.epub, user._.sea) const mySecret = require('../Mediator').getMySecret()
if (typeof mySecret !== 'string') {
throw new TypeError("acceptRequest() -> typeof mySecret !== 'string'")
}
const encryptedForMeIncomingID = await SEA.encrypt(incomingID, mySecret) const encryptedForMeIncomingID = await SEA.encrypt(incomingID, mySecret)
await new Promise((res, rej) => { await new Promise((res, rej) => {
@ -430,7 +422,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => {
console.log('sendHR() -> before mySecret') console.log('sendHR() -> before mySecret')
const mySecret = await SEA.secret(user._.sea.epub, user._.sea) const mySecret = require('../Mediator').getMySecret()
console.log('sendHR() -> before ourSecret') console.log('sendHR() -> before ourSecret')
const ourSecret = await SEA.secret(recipientEpub, user._.sea) const ourSecret = await SEA.secret(recipientEpub, user._.sea)
@ -1030,7 +1022,7 @@ const saveSeedBackup = async (mnemonicPhrase, user, SEA) => {
throw new TypeError('expected mnemonicPhrase to be an string array') throw new TypeError('expected mnemonicPhrase to be an string array')
} }
const mySecret = await SEA.secret(user._.sea.epub, user._.sea) const mySecret = require('../Mediator').getMySecret()
const encryptedSeed = await SEA.encrypt(mnemonicPhrase.join(' '), mySecret) const encryptedSeed = await SEA.encrypt(mnemonicPhrase.join(' '), mySecret)
return new Promise((res, rej) => { return new Promise((res, rej) => {

View file

@ -42,10 +42,7 @@ const __onUserToIncoming = async (cb, user, SEA) => {
/** @type {Record<string, string>} */ /** @type {Record<string, string>} */
const userToIncoming = {} const userToIncoming = {}
const mySecret = await SEA.secret(user._.sea.epub, user._.sea) const mySecret = require('../../Mediator').getMySecret()
if (typeof mySecret !== 'string') {
throw new TypeError("__onUserToIncoming() -> typeof mySecret !== 'string'")
}
user user
.get(Key.USER_TO_INCOMING) .get(Key.USER_TO_INCOMING)
@ -520,7 +517,7 @@ const onSeedBackup = async (cb, user, SEA) => {
throw new Error(ErrorCode.NOT_AUTH) throw new Error(ErrorCode.NOT_AUTH)
} }
const mySecret = await SEA.secret(user._.sea.epub, user._.sea) const mySecret = require('../../Mediator').getMySecret()
const callb = debounce(cb, DEBOUNCE_WAIT_TIME) const callb = debounce(cb, DEBOUNCE_WAIT_TIME)
callb(currentSeedBackup) callb(currentSeedBackup)

View file

@ -23,7 +23,7 @@ const onAcceptedRequests = async (user, SEA) => {
throw new Error(ErrorCode.NOT_AUTH) throw new Error(ErrorCode.NOT_AUTH)
} }
const mySecret = await SEA.secret(user._.sea.epub, user._.sea) const mySecret = require('../../Mediator').getMySecret()
if (typeof mySecret !== 'string') { if (typeof mySecret !== 'string') {
console.log("Jobs.onAcceptedRequests() -> typeof mySecret !== 'string'") console.log("Jobs.onAcceptedRequests() -> typeof mySecret !== 'string'")