From 6774278e77fc5cf94e248ee23c779e9246646b39 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Sun, 9 Feb 2020 13:41:04 -0400 Subject: [PATCH] use memoized secret --- services/gunDB/contact-api/actions.js | 16 ++++------------ services/gunDB/contact-api/events/index.js | 7 ++----- .../gunDB/contact-api/jobs/onAcceptedRequests.js | 2 +- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/services/gunDB/contact-api/actions.js b/services/gunDB/contact-api/actions.js index 6e81fd47..4df52296 100644 --- a/services/gunDB/contact-api/actions.js +++ b/services/gunDB/contact-api/actions.js @@ -58,12 +58,7 @@ const __createOutgoingFeed = async (withPublicKey, user, SEA) => { throw new Error(ErrorCode.NOT_AUTH) } - const mySecret = await SEA.secret(user._.sea.epub, user._.sea) - if (typeof mySecret !== 'string') { - throw new TypeError( - "__createOutgoingFeed() -> typeof mySecret !== 'string'" - ) - } + const mySecret = require('../Mediator').getMySecret() const encryptedForMeRecipientPub = await SEA.encrypt(withPublicKey, mySecret) const maybeEncryptedForMeOutgoingFeedID = await Utils.tryAndWait( @@ -254,10 +249,7 @@ const acceptRequest = async ( SEA ) - const mySecret = await SEA.secret(user._.sea.epub, user._.sea) - if (typeof mySecret !== 'string') { - throw new TypeError("acceptRequest() -> typeof mySecret !== 'string'") - } + const mySecret = require('../Mediator').getMySecret() const encryptedForMeIncomingID = await SEA.encrypt(incomingID, mySecret) await new Promise((res, rej) => { @@ -430,7 +422,7 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => { 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') 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') } - const mySecret = await SEA.secret(user._.sea.epub, user._.sea) + const mySecret = require('../Mediator').getMySecret() const encryptedSeed = await SEA.encrypt(mnemonicPhrase.join(' '), mySecret) return new Promise((res, rej) => { diff --git a/services/gunDB/contact-api/events/index.js b/services/gunDB/contact-api/events/index.js index 1890a7f2..2e4c98c2 100644 --- a/services/gunDB/contact-api/events/index.js +++ b/services/gunDB/contact-api/events/index.js @@ -42,10 +42,7 @@ const __onUserToIncoming = async (cb, user, SEA) => { /** @type {Record} */ const userToIncoming = {} - const mySecret = await SEA.secret(user._.sea.epub, user._.sea) - if (typeof mySecret !== 'string') { - throw new TypeError("__onUserToIncoming() -> typeof mySecret !== 'string'") - } + const mySecret = require('../../Mediator').getMySecret() user .get(Key.USER_TO_INCOMING) @@ -520,7 +517,7 @@ const onSeedBackup = async (cb, user, SEA) => { 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) callb(currentSeedBackup) diff --git a/services/gunDB/contact-api/jobs/onAcceptedRequests.js b/services/gunDB/contact-api/jobs/onAcceptedRequests.js index 3f6efff4..33c32a12 100644 --- a/services/gunDB/contact-api/jobs/onAcceptedRequests.js +++ b/services/gunDB/contact-api/jobs/onAcceptedRequests.js @@ -23,7 +23,7 @@ const onAcceptedRequests = async (user, SEA) => { 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') { console.log("Jobs.onAcceptedRequests() -> typeof mySecret !== 'string'")