From 65a65a601ebd721e740afbe6828901ffa0d48d95 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Wed, 15 Jul 2020 11:37:55 -0400 Subject: [PATCH 01/21] optional 2nd once() param --- services/gunDB/contact-api/SimpleGUN.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/gunDB/contact-api/SimpleGUN.ts b/services/gunDB/contact-api/SimpleGUN.ts index eb5e4d11..d7e54313 100644 --- a/services/gunDB/contact-api/SimpleGUN.ts +++ b/services/gunDB/contact-api/SimpleGUN.ts @@ -47,7 +47,7 @@ export interface GUNNodeBase { map(): GUNNode on(this: GUNNode, cb: Listener): void - once(this: GUNNode, cb?: Listener): GUNNode + once(this: GUNNode, cb?: Listener, opts?: { wait: number }): GUNNode open(this: GUNNode, cb?: OpenListener): GUNNode load(this: GUNNode, cb?: OpenListener): GUNNode From fee393ae83d884a65cb3bf77d5a07a06860ccf77 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Wed, 15 Jul 2020 12:01:38 -0400 Subject: [PATCH 02/21] avoid duplicate alias sign up --- services/gunDB/Mediator/index.js | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index f8fc73ec..533b57cb 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -1275,6 +1275,38 @@ const register = async (alias, pass) => { ) } + // this import is done here to avoid circular dependency hell + const { timeout5 } = require('../contact-api/utils') + + let userData = await timeout5( + new Promise(res => { + gun.get(`~@${alias}`).once(ud => res(ud)) + }) + ) + + if (userData) { + throw new Error( + 'The given alias has been used before, use an unique alias instead.' + ) + } + + await new Promise(res => setTimeout(res, 300)) + + userData = await timeout5( + new Promise(res => { + gun.get(`~@${alias}`).once(ud => res(ud), { + // https://github.com/amark/gun/pull/971#issue-438630761 + wait: 1500 + }) + }) + ) + + if (userData) { + throw new Error( + 'The given alias has been used before, use an unique alias instead. (Caught at 2nd try)' + ) + } + _isRegistering = true /** @type {import('../contact-api/SimpleGUN').CreateAck} */ @@ -1282,6 +1314,13 @@ const register = async (alias, pass) => { user.create(alias, pass, ack => res(ack)) ) + // An empty ack object seems to be caused by a duplicate alias sign up + if ('{}' === JSON.stringify(ack)) { + throw new Error( + 'The given alias has been used before, use an unique alias instead. (Empty ack)' + ) + } + _isRegistering = false if (typeof ack.err === 'string') { From 6708d1622f2d84ed82f51c230be71e7069785fe1 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Thu, 16 Jul 2020 14:03:44 -0400 Subject: [PATCH 03/21] export super peer as constant --- config/defaults.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/config/defaults.js b/config/defaults.js index d30c9ad4..4443c21f 100644 --- a/config/defaults.js +++ b/config/defaults.js @@ -25,6 +25,8 @@ const parsePath = (filePath = "") => { const lndDirectory = getLndDirectory(); +const SHOCK_SUPER_PEER = "http://gun.shock.network:8765/gun" + module.exports = (mainnet = false) => { const network = mainnet ? "mainnet" : "testnet"; @@ -48,8 +50,10 @@ module.exports = (mainnet = false) => { logfile: "shockapi.log", lndLogFile: parsePath(`${lndDirectory}/logs/bitcoin/${network}/lnd.log`), lndDirPath: lndDirectory, - peers: ["http://gun.shock.network:8765/gun"], + peers: [SHOCK_SUPER_PEER], useTLS: false, tokenExpirationMS: 4500000 }; }; + +module.exports.SHOCK_SUPER_PEER = SHOCK_SUPER_PEER \ No newline at end of file From a3ae71767ea55a35446a53051fe1d30dfe9f6e20 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Thu, 16 Jul 2020 14:08:22 -0400 Subject: [PATCH 04/21] vscode use project TS --- .vscode/settings.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 4718ffd9..bd496df1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,3 +1,4 @@ { - "eslint.enable": true + "eslint.enable": true, + "typescript.tsdk": "node_modules/typescript/lib" } \ No newline at end of file From 3e6054f80a49d94817877a73e9b509cb16340c8c Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Thu, 16 Jul 2020 14:25:28 -0400 Subject: [PATCH 05/21] upgrade typescript version --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 68b03834..90ec91de 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "nodemon": "^1.19.3", "prettier": "^1.18.2", "ts-type": "^1.2.16", - "typescript": "^3.6.3" + "typescript": "^3.9.6" }, "lint-staged": { "*.js": [ diff --git a/yarn.lock b/yarn.lock index f9da858b..d5729324 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6578,10 +6578,10 @@ typedarray-dts@^1.0.0: resolved "https://registry.yarnpkg.com/typedarray-dts/-/typedarray-dts-1.0.0.tgz#9dec9811386dbfba964c295c2606cf9a6b982d06" integrity sha512-Ka0DBegjuV9IPYFT1h0Qqk5U4pccebNIJCGl8C5uU7xtOs+jpJvKGAY4fHGK25hTmXZOEUl9Cnsg5cS6K/b5DA== -typescript@^3.6.3: - version "3.6.3" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.3.tgz#fea942fabb20f7e1ca7164ff626f1a9f3f70b4da" - integrity sha512-N7bceJL1CtRQ2RiG0AQME13ksR7DiuQh/QehubYcghzv20tnh+MQnQIuJddTmsbqYj+dztchykemz0zFzlvdQw== +typescript@^3.9.6: + version "3.9.6" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a" + integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw== uglify-js@^3.1.4: version "3.6.0" From 94c4c19f410427e77e4bbca6a398e3968c5e0279 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Jul 2020 19:54:32 +0000 Subject: [PATCH 06/21] Bump lodash from 4.17.15 to 4.17.19 Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19. - [Release notes](https://github.com/lodash/lodash/releases) - [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19) Signed-off-by: dependabot[bot] --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 90ec91de..5bfb6ea5 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "jsonfile": "^4.0.0", "jsonwebtoken": "^8.3.0", "localtunnel": "^1.9.0", - "lodash": "^4.17.15", + "lodash": "^4.17.19", "method-override": "^2.3.7", "promise": "^8.0.1", "ramda": "^0.27.0", diff --git a/yarn.lock b/yarn.lock index d5729324..7c6ed939 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4345,10 +4345,10 @@ lodash@=4.17.4: resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" integrity sha1-eCA6TRwyiuHYbcpkYONptX9AVa4= -lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.5.0: - version "4.17.15" - resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548" - integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A== +lodash@^4.17.11, lodash@^4.17.13, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.5.0: + version "4.17.19" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b" + integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ== log-symbols@^3.0.0: version "3.0.0" From 58d0fd71e912c485e61eef55b805349c443b89ea Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Thu, 16 Jul 2020 14:05:30 -0400 Subject: [PATCH 07/21] check super peer conn for dup alias check --- services/gunDB/Mediator/index.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index 533b57cb..89f7810b 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -12,8 +12,10 @@ require('gun/lib/open') // @ts-ignore require('gun/lib/load') const debounce = require('lodash/debounce') -const Encryption = require('../../../utils/encryptionStore') +const Encryption = require('../../../utils/encryptionStore') +const { SHOCK_SUPER_PEER } = require('../../../config/defaults') +const { PEERS } = require('../config') const Key = require('../contact-api/key') /** @type {import('../contact-api/SimpleGUN').ISEA} */ @@ -1275,6 +1277,25 @@ const register = async (alias, pass) => { ) } + const shocknetPeerInUse = PEERS.includes(SHOCK_SUPER_PEER) + + if (shocknetPeerInUse) { + /** + * @type {Record} + */ + // @ts-ignore + const currPeers = gun._.opt.peers + // This is a very basic test, only checks that the websocket is there but + // doesn't necessarily mean it is connected or that super peer is UP + const shocknetPeerConnected = !!currPeers[SHOCK_SUPER_PEER].wire + + if (!shocknetPeerConnected) { + throw new Error( + `API Must be connected to super peer to check for duplicate aliases` + ) + } + } + // this import is done here to avoid circular dependency hell const { timeout5 } = require('../contact-api/utils') From 8123042741510732db7843680968b148930d0f80 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Fri, 17 Jul 2020 13:38:37 -0400 Subject: [PATCH 08/21] typings --- services/gunDB/config.js | 4 +++- services/gunDB/contact-api/SimpleGUN.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/services/gunDB/config.js b/services/gunDB/config.js index 355581a1..44dab137 100644 --- a/services/gunDB/config.js +++ b/services/gunDB/config.js @@ -11,7 +11,9 @@ dotenv.config() // @ts-ignore Let it crash if undefined exports.DATA_FILE_NAME = process.env.DATA_FILE_NAME || defaults.dataFileName -// @ts-ignore Let it crash if undefined +/** + * @type {string[]} + */ exports.PEERS = process.env.PEERS ? JSON.parse(process.env.PEERS) : defaults.peers diff --git a/services/gunDB/contact-api/SimpleGUN.ts b/services/gunDB/contact-api/SimpleGUN.ts index d7e54313..1cef7225 100644 --- a/services/gunDB/contact-api/SimpleGUN.ts +++ b/services/gunDB/contact-api/SimpleGUN.ts @@ -30,9 +30,18 @@ interface OpenListenerDataObj { export type Listener = (data: ListenerData, key: string) => void export type Callback = (ack: Ack) => void +export interface Peer { + url: string + id: string + wire: Record +} + export interface Soul { get: string put: Primitive | null | object | undefined + opt: { + peers: Record + } } export type OpenListenerData = Primitive | null | OpenListenerDataObj From e56942123677ca485df708c41c5e89caf7266533 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Fri, 17 Jul 2020 13:44:26 -0400 Subject: [PATCH 09/21] envvar for disabling dup alias check via connected peers --- .env.example | 3 ++- services/gunDB/config.js | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index 4ea11d88..ad9e0eb7 100644 --- a/.env.example +++ b/.env.example @@ -3,4 +3,5 @@ PEERS=["http://gun.shock.network:8765/gun"] MS_TO_TOKEN_EXPIRATION=4500000 DISABLE_SHOCK_ENCRYPTION=false CACHE_HEADERS_MANDATORY=true -SHOCK_CACHE=true \ No newline at end of file +SHOCK_CACHE=true +DISABLE_PEER_ALIAS_CHECK = false diff --git a/services/gunDB/config.js b/services/gunDB/config.js index 44dab137..424cc53c 100644 --- a/services/gunDB/config.js +++ b/services/gunDB/config.js @@ -23,3 +23,6 @@ exports.MS_TO_TOKEN_EXPIRATION = Number( ) exports.SHOW_LOG = process.env.SHOW_GUN_DB_LOG === 'true' + +exports.DISABLE_PEER_ALIAS_CHECK = + process.env.DISABLE_PEER_ALIAS_CHECK === 'true' From 35553a93b6125e040c1a914b5f9a5930b7f4505f Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Fri, 17 Jul 2020 14:00:52 -0400 Subject: [PATCH 10/21] better dup alias check --- config/defaults.js | 2 -- services/gunDB/Mediator/index.js | 34 +++++++++++++++++++++----------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/config/defaults.js b/config/defaults.js index 4443c21f..37cae17a 100644 --- a/config/defaults.js +++ b/config/defaults.js @@ -55,5 +55,3 @@ module.exports = (mainnet = false) => { tokenExpirationMS: 4500000 }; }; - -module.exports.SHOCK_SUPER_PEER = SHOCK_SUPER_PEER \ No newline at end of file diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index 89f7810b..92f48045 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -12,10 +12,10 @@ require('gun/lib/open') // @ts-ignore require('gun/lib/load') const debounce = require('lodash/debounce') +const size = require('lodash/size') const Encryption = require('../../../utils/encryptionStore') -const { SHOCK_SUPER_PEER } = require('../../../config/defaults') -const { PEERS } = require('../config') +const { DISABLE_PEER_ALIAS_CHECK } = require('../config') const Key = require('../contact-api/key') /** @type {import('../contact-api/SimpleGUN').ISEA} */ @@ -1277,23 +1277,33 @@ const register = async (alias, pass) => { ) } - const shocknetPeerInUse = PEERS.includes(SHOCK_SUPER_PEER) - - if (shocknetPeerInUse) { + if (DISABLE_PEER_ALIAS_CHECK) { + logger.warn(`DISABLE_PEER_ALIAS_CHECK true, use only for testing purposes`) + } else { /** - * @type {Record} + * Peers provided to gun. */ - // @ts-ignore const currPeers = gun._.opt.peers - // This is a very basic test, only checks that the websocket is there but - // doesn't necessarily mean it is connected or that super peer is UP - const shocknetPeerConnected = !!currPeers[SHOCK_SUPER_PEER].wire - if (!shocknetPeerConnected) { + if (size(currPeers) === 0) { + logger.info( + `Unexpected: Duplicate alias check enabled but Gun has no peers set. If you're testing gun without peers set DISABLE_PEER_ALIAS_CHECK to true.` + ) throw new Error( - `API Must be connected to super peer to check for duplicate aliases` + `Unexpected: Duplicate alias check enabled but Gun has no peers set.` ) } + + /** + * Of those, how many are actually connected + */ + const connectedPeers = Object.values(currPeers).filter(p => !!p.wire).length + + if (connectedPeers === 0) { + throw new Error( + `No connected peers, therefore cannot check for duplicate aliases.` + ) + } // else it's connected to at least one } // this import is done here to avoid circular dependency hell From ef213ee2dc7d3de0867810864b972a670223cede Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Fri, 17 Jul 2020 14:18:55 -0400 Subject: [PATCH 11/21] better error catch --- src/routes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/routes.js b/src/routes.js index 73222778..032cf5c3 100644 --- a/src/routes.js +++ b/src/routes.js @@ -713,7 +713,7 @@ module.exports = async ( logger.error(err); return res.status(500).json({ field: "unknown", - errorMessage: err + errorMessage: err.message || err }) } }); From bc03211ecc89231e401dfc2ce808d2fa9b5f3cca Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Fri, 17 Jul 2020 14:39:28 -0400 Subject: [PATCH 12/21] throw if connected to peers and peer dup alias check is disabled --- services/gunDB/Mediator/index.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index 92f48045..5a2c06ff 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -1277,14 +1277,25 @@ const register = async (alias, pass) => { ) } - if (DISABLE_PEER_ALIAS_CHECK) { - logger.warn(`DISABLE_PEER_ALIAS_CHECK true, use only for testing purposes`) - } else { - /** - * Peers provided to gun. - */ - const currPeers = gun._.opt.peers + /** + * Peers provided to gun. + */ + const currPeers = gun._.opt.peers + if (DISABLE_PEER_ALIAS_CHECK) { + if (size(currPeers)) { + logger.info( + `Unexpected: disabled peer alias check while peers were specified.` + ) + throw new Error( + `Unexpected: disabled peer alias check while peers were specified.` + ) + } + + logger.warn( + `DISABLE_PEER_ALIAS_CHECK true, use only for testing purposes with no peers connected` + ) + } else { if (size(currPeers) === 0) { logger.info( `Unexpected: Duplicate alias check enabled but Gun has no peers set. If you're testing gun without peers set DISABLE_PEER_ALIAS_CHECK to true.` From b44fd99e56cb9debb955c3584c27cf96bfe4a289 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Fri, 17 Jul 2020 15:36:55 -0400 Subject: [PATCH 13/21] simpler dup alias check --- .env.example | 1 - services/gunDB/Mediator/index.js | 94 +++++++++---------------- services/gunDB/config.js | 3 - services/gunDB/contact-api/SimpleGUN.ts | 4 +- 4 files changed, 38 insertions(+), 64 deletions(-) diff --git a/.env.example b/.env.example index ad9e0eb7..65c31d1c 100644 --- a/.env.example +++ b/.env.example @@ -4,4 +4,3 @@ MS_TO_TOKEN_EXPIRATION=4500000 DISABLE_SHOCK_ENCRYPTION=false CACHE_HEADERS_MANDATORY=true SHOCK_CACHE=true -DISABLE_PEER_ALIAS_CHECK = false diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index 5a2c06ff..bfd8764b 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -12,10 +12,8 @@ require('gun/lib/open') // @ts-ignore require('gun/lib/load') const debounce = require('lodash/debounce') -const size = require('lodash/size') const Encryption = require('../../../utils/encryptionStore') -const { DISABLE_PEER_ALIAS_CHECK } = require('../config') const Key = require('../contact-api/key') /** @type {import('../contact-api/SimpleGUN').ISEA} */ @@ -1280,73 +1278,51 @@ const register = async (alias, pass) => { /** * Peers provided to gun. */ - const currPeers = gun._.opt.peers + const peers = Object.values(gun._.opt.peers) - if (DISABLE_PEER_ALIAS_CHECK) { - if (size(currPeers)) { - logger.info( - `Unexpected: disabled peer alias check while peers were specified.` - ) - throw new Error( - `Unexpected: disabled peer alias check while peers were specified.` - ) - } - - logger.warn( - `DISABLE_PEER_ALIAS_CHECK true, use only for testing purposes with no peers connected` - ) - } else { - if (size(currPeers) === 0) { - logger.info( - `Unexpected: Duplicate alias check enabled but Gun has no peers set. If you're testing gun without peers set DISABLE_PEER_ALIAS_CHECK to true.` - ) - throw new Error( - `Unexpected: Duplicate alias check enabled but Gun has no peers set.` - ) - } - - /** - * Of those, how many are actually connected - */ - const connectedPeers = Object.values(currPeers).filter(p => !!p.wire).length - - if (connectedPeers === 0) { - throw new Error( - `No connected peers, therefore cannot check for duplicate aliases.` - ) - } // else it's connected to at least one - } - - // this import is done here to avoid circular dependency hell - const { timeout5 } = require('../contact-api/utils') - - let userData = await timeout5( - new Promise(res => { - gun.get(`~@${alias}`).once(ud => res(ud)) - }) + const theresPeers = peers.length > 0 + const atLeastOneIsConnected = peers.some( + p => p.wire && p.wire.readyState === 1 ) - if (userData) { + if (theresPeers && !atLeastOneIsConnected) { throw new Error( - 'The given alias has been used before, use an unique alias instead.' + 'No connected to any peers for checking of duplicate aliases' ) } - await new Promise(res => setTimeout(res, 300)) + if (theresPeers && atLeastOneIsConnected) { + // this import is done here to avoid circular dependency hell + const { timeout5 } = require('../contact-api/utils') - userData = await timeout5( - new Promise(res => { - gun.get(`~@${alias}`).once(ud => res(ud), { - // https://github.com/amark/gun/pull/971#issue-438630761 - wait: 1500 + let userData = await timeout5( + new Promise(res => { + gun.get(`~@${alias}`).once(ud => res(ud)) }) - }) - ) - - if (userData) { - throw new Error( - 'The given alias has been used before, use an unique alias instead. (Caught at 2nd try)' ) + + if (userData) { + throw new Error( + 'The given alias has been used before, use an unique alias instead.' + ) + } + + await new Promise(res => setTimeout(res, 300)) + + userData = await timeout5( + new Promise(res => { + gun.get(`~@${alias}`).once(ud => res(ud), { + // https://github.com/amark/gun/pull/971#issue-438630761 + wait: 1500 + }) + }) + ) + + if (userData) { + throw new Error( + 'The given alias has been used before, use an unique alias instead. (Caught at 2nd try)' + ) + } } _isRegistering = true diff --git a/services/gunDB/config.js b/services/gunDB/config.js index 424cc53c..44dab137 100644 --- a/services/gunDB/config.js +++ b/services/gunDB/config.js @@ -23,6 +23,3 @@ exports.MS_TO_TOKEN_EXPIRATION = Number( ) exports.SHOW_LOG = process.env.SHOW_GUN_DB_LOG === 'true' - -exports.DISABLE_PEER_ALIAS_CHECK = - process.env.DISABLE_PEER_ALIAS_CHECK === 'true' diff --git a/services/gunDB/contact-api/SimpleGUN.ts b/services/gunDB/contact-api/SimpleGUN.ts index 1cef7225..3a9cd77b 100644 --- a/services/gunDB/contact-api/SimpleGUN.ts +++ b/services/gunDB/contact-api/SimpleGUN.ts @@ -33,7 +33,9 @@ export type Callback = (ack: Ack) => void export interface Peer { url: string id: string - wire: Record + wire?: { + readyState: number + } } export interface Soul { From 84e439316ba2fd93d9526d9caa8bee4ba34fcea7 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Fri, 17 Jul 2020 18:39:50 -0400 Subject: [PATCH 14/21] handle undefined --- services/gunDB/contact-api/getters/user.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/services/gunDB/contact-api/getters/user.js b/services/gunDB/contact-api/getters/user.js index 8f1d9cf2..fb8054e1 100644 --- a/services/gunDB/contact-api/getters/user.js +++ b/services/gunDB/contact-api/getters/user.js @@ -49,14 +49,14 @@ const getAnUser = async publicKey => { /** @type {Common.SchemaTypes.User} */ const u = { - avatar: oldProfile.avatar, + avatar: oldProfile.avatar || null, // @ts-ignore - bio, - displayName: oldProfile.displayName, + bio: bio || null, + displayName: oldProfile.displayName || null, // @ts-ignore - lastSeenApp, + lastSeenApp: lastSeenApp || 0, // @ts-ignore - lastSeenNode, + lastSeenNode: lastSeenNode || 0, // @ts-ignore publicKey } From 1aace2600d78ca25d5c322136be237c9fa863002 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Fri, 17 Jul 2020 18:40:36 -0400 Subject: [PATCH 15/21] own user profile endpoint --- src/routes.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/routes.js b/src/routes.js index 032cf5c3..22e163e7 100644 --- a/src/routes.js +++ b/src/routes.js @@ -2006,6 +2006,54 @@ module.exports = async ( ap.get(`/api/gun/feed`, apiGunFeedGet) + /** + * @type {RequestHandler<{}>} + */ + const apiGunMeGet = async (_, res) => { + try { + return res.status(200).json(await GunGetters.getMyUser()) + } catch (err) { + logger.error(err) + return res.status(500).json({ + errorMessage: err.message + }) + } + } + + + /** + * @type {RequestHandler<{}>} + */ + const apiGunMePut = async (req, res) => { + try { + const { avatar, bio , displayName} = /** @type {Partial>} */ (req.body) + + if (avatar) { + await GunActions.setAvatar(avatar, require('../services/gunDB/Mediator').getUser()) + } + + if (bio) { + await GunActions.setBio(bio, require('../services/gunDB/Mediator').getUser()) + } + + if (displayName) { + await GunActions.setDisplayName(displayName, require('../services/gunDB/Mediator').getUser()) + } + + return res.status(200).json({ + ok: true + }) + } catch (err) { + logger.error(err) + return res.status(500).json({ + errorMessage: err.message + }) + } + } + + ap.get(`/api/gun/me`, apiGunMeGet) + ap.put(`/api/gun/me`, apiGunMePut) + /** * Return app so that it can be used by express. */ From 670423103b6cd85b4289164b05217ef6d177cd58 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Sat, 18 Jul 2020 18:07:05 -0400 Subject: [PATCH 16/21] revert code smell --- config/defaults.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/config/defaults.js b/config/defaults.js index 37cae17a..4ba82f6d 100644 --- a/config/defaults.js +++ b/config/defaults.js @@ -25,8 +25,6 @@ const parsePath = (filePath = "") => { const lndDirectory = getLndDirectory(); -const SHOCK_SUPER_PEER = "http://gun.shock.network:8765/gun" - module.exports = (mainnet = false) => { const network = mainnet ? "mainnet" : "testnet"; @@ -50,7 +48,7 @@ module.exports = (mainnet = false) => { logfile: "shockapi.log", lndLogFile: parsePath(`${lndDirectory}/logs/bitcoin/${network}/lnd.log`), lndDirPath: lndDirectory, - peers: [SHOCK_SUPER_PEER], + peers: ['http://gun.shock.network:8765/gun'], useTLS: false, tokenExpirationMS: 4500000 }; From 60a0311692bb31048cf992b186f2b1a324a91df2 Mon Sep 17 00:00:00 2001 From: Capitalist Dog Date: Sat, 18 Jul 2020 18:20:48 -0400 Subject: [PATCH 17/21] last known good gun --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5bfb6ea5..fb741148 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "sw-server", + "name": "shockapi", "version": "1.0.0", "description": "", "main": "src/server.js", @@ -33,7 +33,7 @@ "google-proto-files": "^1.0.3", "graphviz": "0.0.8", "grpc": "^1.21.1", - "gun": "git://github.com/amark/gun#c59e0e95f92779ce6bb3aab823d318bc16b20c33", + "gun": "git://github.com/amark/gun#97aa976c97e6219a9f93095d32c220dcd371ca62", "husky": "^4.2.5", "jsonfile": "^4.0.0", "jsonwebtoken": "^8.3.0", From cb4848026cdd87228e246a6e613ea40886663f0e Mon Sep 17 00:00:00 2001 From: CapDog <34176400+capitalistdog@users.noreply.github.com> Date: Tue, 21 Jul 2020 15:16:24 -0400 Subject: [PATCH 18/21] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9d3379c1..54a4ede0 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,8 @@ For easy setup on your Laptop/Desktop, [a wizard is available here.](https://git * Requires [Node.js](https://nodejs.org) 12 #### Steps: -1) Run [LND](https://github.com/lightningnetwork/lnd/releases) - *Example mainnet startup*: +1) Run [LND](https://github.com/shocknet/lnd/releases) - *Example mainnet startup*: +(Neutrino example requires builds with experimental flags, our binaries include them.) ```./lnd --bitcoin.active --bitcoin.mainnet --bitcoin.node=neutrino --neutrino.connect=neutrino.shock.network --routing.assumechanvalid=1 --allow-circular-route=1``` From 23ce6498e740d0d7ba1728a0ee25509cfaf4ebe9 Mon Sep 17 00:00:00 2001 From: CapDog <34176400+capitalistdog@users.noreply.github.com> Date: Tue, 21 Jul 2020 15:17:41 -0400 Subject: [PATCH 19/21] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 54a4ede0..72072983 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,7 @@ For easy setup on your Laptop/Desktop, [a wizard is available here.](https://git #### Steps: 1) Run [LND](https://github.com/shocknet/lnd/releases) - *Example mainnet startup*: + (Neutrino example requires builds with experimental flags, our binaries include them.) ```./lnd --bitcoin.active --bitcoin.mainnet --bitcoin.node=neutrino --neutrino.connect=neutrino.shock.network --routing.assumechanvalid=1 --allow-circular-route=1``` From 2013ff25667219c97c27c87ed43c67937d026dad Mon Sep 17 00:00:00 2001 From: CapDog <34176400+capitalistdog@users.noreply.github.com> Date: Tue, 21 Jul 2020 15:20:32 -0400 Subject: [PATCH 20/21] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 72072983..0f4d74dd 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ For easy setup on your Laptop/Desktop, [a wizard is available here.](https://git (Neutrino example requires builds with experimental flags, our binaries include them.) - ```./lnd --bitcoin.active --bitcoin.mainnet --bitcoin.node=neutrino --neutrino.connect=neutrino.shock.network --routing.assumechanvalid=1 --allow-circular-route=1``` + ```./lnd --bitcoin.active=1 --bitcoin.mainnet --bitcoin.node=neutrino --neutrino.connect=neutrino.shock.network --routing.assumechanvalid=1 --allow-circular-route=1``` 2) Download and Install API From fa63bc7c249b26e72a3296a269ac741d9160ef98 Mon Sep 17 00:00:00 2001 From: CapDog <34176400+capitalistdog@users.noreply.github.com> Date: Tue, 21 Jul 2020 15:28:28 -0400 Subject: [PATCH 21/21] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0f4d74dd..c6f8fb17 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ For easy setup on your Laptop/Desktop, [a wizard is available here.](https://git (Neutrino example requires builds with experimental flags, our binaries include them.) - ```./lnd --bitcoin.active=1 --bitcoin.mainnet --bitcoin.node=neutrino --neutrino.connect=neutrino.shock.network --routing.assumechanvalid=1 --allow-circular-route=1``` + ```./lnd --bitcoin.active --bitcoin.mainnet --bitcoin.node=neutrino --neutrino.connect=neutrino.shock.network --routing.assumechanvalid --allow-circular-route``` 2) Download and Install API