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')