From 918fcd935fc5f075a883bf6a9955dc8b76104802 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Tue, 20 Oct 2020 13:32:08 -0400 Subject: [PATCH] disable reinstantiation --- services/gunDB/Mediator/index.js | 33 ++++------------------- services/gunDB/contact-api/utils/index.js | 4 +-- 2 files changed, 7 insertions(+), 30 deletions(-) diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index 4c941fb4..e4aba797 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -224,7 +224,6 @@ let user /** @type {string|null} */ let _currentAlias = null /** @type {string|null} */ -let _currentPass = null /** @type {string|null} */ let mySec = null @@ -361,7 +360,6 @@ const authenticate = async (alias, pass, __user) => { mySec = await mySEA.secret(_user._.sea.epub, _user._.sea) _currentAlias = alias - _currentPass = await mySEA.encrypt(pass, mySec) await new Promise(res => setTimeout(res, 5000)) @@ -433,30 +431,11 @@ const instantiateGun = () => { instantiateGun() -const freshGun = async () => { - const _gun = /** @type {unknown} */ (new Gun({ - axe: false, - multicast: false, - peers: Config.PEERS - })) - - const gun = /** @type {GUNNode} */ (_gun) - - const user = gun.user() - - if (!_currentAlias || !_currentPass || !mySec) { - throw new Error('Called freshGun() without alias, pass and secret cached') +const freshGun = () => { + return { + gun, + user } - - const pass = await mySEA.decrypt(_currentPass, mySec) - - if (typeof pass !== 'string') { - throw new Error('could not decrypt stored in memory current pass') - } - - await authenticate(_currentAlias, pass, user) - - return { gun, user } } /** @@ -1428,9 +1407,7 @@ const register = async (alias, pass) => { if (typeof ack.err === 'string') { throw new Error(ack.err) } else if (typeof ack.pub === 'string' || typeof user._.sea === 'object') { - const mySecret = await mySEA.secret(user._.sea.epub, user._.sea) - _currentAlias = alias - _currentPass = await mySEA.encrypt(pass, mySecret) + // OK } else { throw new Error('unknown error, ack: ' + JSON.stringify(ack)) } diff --git a/services/gunDB/contact-api/utils/index.js b/services/gunDB/contact-api/utils/index.js index bafa0378..49b5886c 100644 --- a/services/gunDB/contact-api/utils/index.js +++ b/services/gunDB/contact-api/utils/index.js @@ -195,11 +195,11 @@ const tryAndWait = async (promGen, shouldRetry = () => false) => { } logger.info( - `\n recreating a fresh gun and retrying one last time \n` + + `\n NOT recreating a fresh gun but retrying one last time \n` + ` args: ${promGen.toString()} -- ${shouldRetry.toString()}` ) - const { gun, user } = await require('../../Mediator/index').freshGun() + const { gun, user } = require('../../Mediator/index').freshGun() return timeout10(promGen(gun, user)) /* eslint-enable no-empty */