diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index 2aa3e827..3bd236a3 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -325,9 +325,9 @@ class Mediator { const deviceId = socket.handshake.query['x-shockwallet-device-id'] socket.on(eventName, data => { try { - // if (nonEncryptedEvents.includes(eventName)) { - // return cb(data) - // } + if (Encryption.isNonEncrypted(eventName)) { + return cb(data) + } if (!data) { return cb(data) @@ -350,7 +350,8 @@ class Mediator { console.error('Unknown Device', error) return false } - if(typeof data === 'string'){ + console.log('Emitting Data...', data) + if (typeof data === 'string') { data = JSON.parse(data) } console.log('Event:', eventName) @@ -378,6 +379,11 @@ class Mediator { }, emit: (eventName, data) => { try { + if (Encryption.isNonEncrypted(eventName)) { + socket.emit(eventName, data) + return + } + const deviceId = socket.handshake.query['x-shockwallet-device-id'] const authorized = Encryption.isAuthorizedDevice({ deviceId }) const encryptedMessage = authorized diff --git a/src/routes.js b/src/routes.js index 7a07a8d2..89254ec4 100644 --- a/src/routes.js +++ b/src/routes.js @@ -327,7 +327,7 @@ module.exports = async ( try { const { publicKey, deviceId } = req.body; - if (!publicKey || publicKey.length < 600) { + if (!publicKey) { return res.status(400).json({ field: 'publicKey', message: "Please provide a valid public key" diff --git a/utils/encryptionStore.js b/utils/encryptionStore.js index 60ebfc4d..d892642c 100644 --- a/utils/encryptionStore.js +++ b/utils/encryptionStore.js @@ -6,7 +6,10 @@ const { Buffer } = require('buffer') const APIKeyPair = new Map() const authorizedDevices = new Map() +const nonEncryptedEvents = ['ping', 'disconnect'] + const Encryption = { + isNonEncrypted: event => nonEncryptedEvents.includes(event), encryptKey: ({ deviceId, message }) => { if (!authorizedDevices.has(deviceId)) { throw { field: 'deviceId', message: 'Unknown Device ID' }