From 5762a2aaf8bb9b063c065dac2412fa0b6b4d0512 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Tue, 4 Feb 2020 10:04:44 -0400 Subject: [PATCH] unused graph/code --- services/gunDB/contact-api/actions.js | 18 -------- services/gunDB/contact-api/events/index.js | 50 ---------------------- services/gunDB/contact-api/key.js | 1 - services/gunDB/contact-api/utils/index.js | 30 ------------- 4 files changed, 99 deletions(-) diff --git a/services/gunDB/contact-api/actions.js b/services/gunDB/contact-api/actions.js index bcf416bc..c5643b8a 100644 --- a/services/gunDB/contact-api/actions.js +++ b/services/gunDB/contact-api/actions.js @@ -542,8 +542,6 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => { }) }) - // save request id to REQUEST_TO_USER - const encryptedForMeRecipientPublicKey = await SEA.encrypt( recipientPublicKey, mySecret @@ -552,22 +550,6 @@ const sendHandshakeRequest = async (recipientPublicKey, gun, user, SEA) => { // This needs to come before the write to sent requests. Because that write // triggers Jobs.onAcceptedRequests and it in turn reads from request-to-user // This also triggers Events.onSimplerSentRequests - await new Promise((res, rej) => { - user - .get(Key.REQUEST_TO_USER) - .get(newHandshakeRequestID) - .put(encryptedForMeRecipientPublicKey, ack => { - if (ack.err) { - rej( - new Error( - `Error saving recipient public key to request to user: ${ack.err}` - ) - ) - } else { - res() - } - }) - }) /** * @type {StoredReq} diff --git a/services/gunDB/contact-api/events/index.js b/services/gunDB/contact-api/events/index.js index f7aeebb5..1890a7f2 100644 --- a/services/gunDB/contact-api/events/index.js +++ b/services/gunDB/contact-api/events/index.js @@ -26,55 +26,6 @@ const Utils = require('../utils') const DEBOUNCE_WAIT_TIME = 500 -/** - * Maps a sent request ID to the public key of the user it was sent to. - * @param {(requestToUser: Record) => void} cb - * @param {UserGUNNode} user Pass only for testing purposes. - * @param {ISEA} SEA - * @returns {Promise} - */ -const __onSentRequestToUser = async (cb, user, SEA) => { - if (!user.is) { - throw new Error(ErrorCode.NOT_AUTH) - } - - const callb = debounce(cb, DEBOUNCE_WAIT_TIME) - - /** @type {Record} */ - const requestToUser = {} - callb(requestToUser) - - const mySecret = await SEA.secret(user._.sea.epub, user._.sea) - if (typeof mySecret !== 'string') { - throw new TypeError( - "__onSentRequestToUser() -> typeof mySecret !== 'string'" - ) - } - - user - .get(Key.REQUEST_TO_USER) - .map() - .on(async (encryptedUserPub, requestID) => { - if (typeof encryptedUserPub !== 'string') { - console.error('got a non string value') - return - } - if (encryptedUserPub.length === 0) { - console.error('got an empty string value') - return - } - - const userPub = await SEA.decrypt(encryptedUserPub, mySecret) - if (typeof userPub !== 'string') { - console.log(`__onSentRequestToUser() -> typeof userPub !== 'string'`) - return - } - - requestToUser[requestID] = userPub - callb(requestToUser) - }) -} - /** * @param {(userToIncoming: Record) => void} cb * @param {UserGUNNode} user Pass only for testing purposes. @@ -583,7 +534,6 @@ const onSeedBackup = async (cb, user, SEA) => { } module.exports = { - __onSentRequestToUser, __onUserToIncoming, onAvatar, onBlacklist, diff --git a/services/gunDB/contact-api/key.js b/services/gunDB/contact-api/key.js index 0902a454..22f83dc6 100644 --- a/services/gunDB/contact-api/key.js +++ b/services/gunDB/contact-api/key.js @@ -12,7 +12,6 @@ exports.RECIPIENT_TO_OUTGOING = 'recipientToOutgoing' exports.USER_TO_INCOMING = 'userToIncoming' exports.STORED_REQS = 'storedReqs' -exports.REQUEST_TO_USER = 'requestToUser' exports.BLACKLIST = 'blacklist' diff --git a/services/gunDB/contact-api/utils/index.js b/services/gunDB/contact-api/utils/index.js index c67eee1a..092b7742 100644 --- a/services/gunDB/contact-api/utils/index.js +++ b/services/gunDB/contact-api/utils/index.js @@ -85,35 +85,6 @@ const pubToEpub = async pub => { } } -/** - * @param {string} reqID - * @param {ISEA} SEA - * @param {string} mySecret - * @returns {Promise} - */ -const reqToRecipientPub = async (reqID, SEA, mySecret) => { - const maybeEncryptedForMeRecipientPub = await tryAndWait(async (_, user) => { - const reqToUser = user.get(Key.REQUEST_TO_USER) - const data = await reqToUser.get(reqID).then() - - if (typeof data !== 'string') { - throw new TypeError("typeof maybeEncryptedForMeRecipientPub !== 'string'") - } - - return data - }) - - const encryptedForMeRecipientPub = maybeEncryptedForMeRecipientPub - - const recipientPub = await SEA.decrypt(encryptedForMeRecipientPub, mySecret) - - if (typeof recipientPub !== 'string') { - throw new TypeError("typeof recipientPub !== 'string'") - } - - return recipientPub -} - /** * Should only be called with a recipient pub that has already been contacted. * If returns null, a disconnect happened. @@ -327,7 +298,6 @@ module.exports = { defaultName, delay, pubToEpub, - reqToRecipientPub, recipientPubToLastReqSentID, successfulHandshakeAlreadyExists, recipientToOutgoingID,