diff --git a/DesktopRoot.js b/DesktopRoot.js index cdaa0bd260..65e738503b 100644 --- a/DesktopRoot.js +++ b/DesktopRoot.js @@ -36,7 +36,7 @@ exports.newDesktopRoot = function newDesktopRoot() { /* Setting up the modules that will be available, defined at the Project Schema file. */ - let MULTI_PROJECT = require('./MultiProject.js'); + let MULTI_PROJECT = require('./MultiProject.js') let MULTI_PROJECT_MODULE = MULTI_PROJECT.newMultiProject() MULTI_PROJECT_MODULE.initialize(DK, 'DK') MULTI_PROJECT_MODULE.initialize(SA, 'SA') @@ -58,22 +58,8 @@ exports.newDesktopRoot = function newDesktopRoot() { /* Setting up Secrets. */ - try { - SA.secrets = { - array: require('./My-Secrets/Secrets.json').secrets, - map: new Map() - } - } catch (err) { - SA.secrets = { - array: [], - map: new Map() - } - } - - for (let i = 0; i < SA.secrets.array.length; i++) { - let secret = SA.secrets.array[i] - SA.secrets.map.set(secret.nodeCodeName, secret) - } + let SECRETS = require('./Secrets.js') + SECRETS.initialize() run() diff --git a/DesktopRootReact.js b/DesktopRootReact.js index 62eed4c023..cbf8212051 100644 --- a/DesktopRootReact.js +++ b/DesktopRootReact.js @@ -58,22 +58,8 @@ exports.newDesktopRoot = function newDesktopRoot() { /* Setting up Secrets. */ - try { - SA.secrets = { - array: require('./My-Secrets/Secrets.json').secrets, - map: new Map() - } - } catch (err) { - SA.secrets = { - array: [], - map: new Map() - } - } - - for (let i = 0; i < SA.secrets.array.length; i++) { - let secret = SA.secrets.array[i] - SA.secrets.map.set(secret.nodeCodeName, secret) - } + let SECRETS = require('./Secrets.js') + SECRETS.initialize() run() diff --git a/NetworkRoot.js b/NetworkRoot.js index f3e69ac411..33141c602e 100644 --- a/NetworkRoot.js +++ b/NetworkRoot.js @@ -56,22 +56,8 @@ exports.newNetworkRoot = function newNetworkRoot() { /* Setting up Secrets. */ - try { - SA.secrets = { - array: require('./My-Secrets/Secrets.json').secrets, - map: new Map() - } - } catch (err) { - SA.secrets = { - array: [], - map: new Map() - } - } - - for (let i = 0; i < SA.secrets.array.length; i++) { - let secret = SA.secrets.array[i] - SA.secrets.map.set(secret.nodeCodeName, secret) - } + let SECRETS = require('./Secrets.js') + SECRETS.initialize() NT.app = require('./Network/NetwokNode.js').newNetworkNode() NT.app.run() diff --git a/Platform/Client/httpInterface.js b/Platform/Client/httpInterface.js index 21e351ef8d..9bd2c5444c 100644 --- a/Platform/Client/httpInterface.js +++ b/Platform/Client/httpInterface.js @@ -380,14 +380,14 @@ exports.newHttpInterface = function newHttpInterface() { break case 'Secrets': { switch (requestPath[2]) { // switch by command - case 'Save-Secrets-File': { + case 'Save-Singing-Accounts-Secrets-File': { SA.projects.foundations.utilities.httpRequests.getRequestBody(httpRequest, httpResponse, processRequest) async function processRequest(body) { try { let filePath = global.env.PATH_TO_SECRETS + '/' - let fileName = "Secrets.json" + let fileName = "SigningAccountsSecrets.json" createNewDir(filePath) SA.nodeModules.fs.writeFileSync(filePath + '/' + fileName, body) @@ -397,9 +397,9 @@ exports.newHttpInterface = function newHttpInterface() { SA.projects.foundations.utilities.httpResponses.respondWithContent(JSON.stringify(global.DEFAULT_OK_RESPONSE), httpResponse) } catch (err) { - console.log('[ERROR] httpInterface -> Secrets -> Save-Secrets-File -> Method call produced an error.') - console.log('[ERROR] httpInterface -> Secrets -> Save-Secrets-File -> err.stack = ' + err.stack) - console.log('[ERROR] httpInterface -> Secrets -> Save-Secrets-File -> Params Received = ' + body) + console.log('[ERROR] httpInterface -> Secrets -> Save-Singing-Accounts-Secrets-File -> Method call produced an error.') + console.log('[ERROR] httpInterface -> Secrets -> Save-Singing-Accounts-Secrets-File -> err.stack = ' + err.stack) + console.log('[ERROR] httpInterface -> Secrets -> Save-Singing-Accounts-Secrets-File -> Params Received = ' + body) let error = { result: 'Fail Because', diff --git a/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js b/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js index 6b34a0844e..ae244a65f4 100644 --- a/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js +++ b/Projects/Governance/UI/Function-Libraries/ProfileConstructor.js @@ -373,15 +373,15 @@ function newGovernanceFunctionLibraryProfileConstructor() { secrets.push(secret) /* - Save Secrets File + Save Signing Accounts Secrets File */ - httpRequest(JSON.stringify(secretsFile, undefined, 4), 'Secrets/Save-Secrets-File', onResponse) + httpRequest(JSON.stringify(secretsFile, undefined, 4), 'Secrets/Save-Singing-Accounts-Secrets-File', onResponse) function onResponse(err, data) { /* Lets check the result of the call through the http interface */ data = JSON.parse(data) if (err.result != GLOBAL.DEFAULT_OK_RESPONSE.result || data.result != GLOBAL.DEFAULT_OK_RESPONSE.result) { node.payload.uiObject.setErrorMessage( - "Secrets file could not be created.", + "Signing Accounts Secrets File could not be created.", UI.projects.governance.globals.designer.SET_ERROR_COUNTER_FACTOR ) } else { @@ -389,7 +389,7 @@ function newGovernanceFunctionLibraryProfileConstructor() { Show nice message. */ node.payload.uiObject.setInfoMessage( - "Secrets file have been sucessfully created.", + "Signing Accounts Secrets File have been sucessfully created.", UI.projects.governance.globals.designer.SET_INFO_COUNTER_FACTOR ) } diff --git a/Projects/Network/NT/Modules/WebSocketsInterface.js b/Projects/Network/NT/Modules/WebSocketsInterface.js index 9693d3ca94..8a84b4ee99 100644 --- a/Projects/Network/NT/Modules/WebSocketsInterface.js +++ b/Projects/Network/NT/Modules/WebSocketsInterface.js @@ -294,11 +294,11 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock */ let signedMessage = { callerProfileHandle: messageHeader.callerProfileHandle, - calledProfileHandle: SA.secrets.map.get(global.env.P2P_NETWORK_NODE_SIGNING_ACCOUNT).userProfileHandle, + calledProfileHandle: SA.secrets.signingAccountSecrets.map.get(global.env.P2P_NETWORK_NODE_SIGNING_ACCOUNT).userProfileHandle, callerTimestamp: messageHeader.callerTimestamp, calledTimestamp: calledTimestamp } - let signature = web3.eth.accounts.sign(JSON.stringify(signedMessage), SA.secrets.map.get(global.env.P2P_NETWORK_NODE_SIGNING_ACCOUNT).privateKey) + let signature = web3.eth.accounts.sign(JSON.stringify(signedMessage), SA.secrets.signingAccountSecrets.map.get(global.env.P2P_NETWORK_NODE_SIGNING_ACCOUNT).privateKey) let response = { result: 'Ok', @@ -393,7 +393,7 @@ exports.newNetworkModulesWebSocketsInterface = function newNetworkModulesWebSock We will check that the signature includes this Network Node handle, to avoid man in the middle attacks. */ - if (signedMessage.calledProfileHandle !== SA.secrets.map.get(global.env.P2P_NETWORK_NODE_SIGNING_ACCOUNT).userProfileHandle) { + if (signedMessage.calledProfileHandle !== SA.secrets.signingAccountSecrets.map.get(global.env.P2P_NETWORK_NODE_SIGNING_ACCOUNT).userProfileHandle) { let response = { result: 'Error', message: 'calledProfileHandle Does Not Match This Network Node Handle.' diff --git a/Projects/Network/SA/Modules/P2PNetwork.js b/Projects/Network/SA/Modules/P2PNetwork.js index 30bcf3c9bd..275429b451 100644 --- a/Projects/Network/SA/Modules/P2PNetwork.js +++ b/Projects/Network/SA/Modules/P2PNetwork.js @@ -33,7 +33,7 @@ exports.newNetworkModulesP2PNetwork = function newNetworkModulesP2PNetwork() { case 'Network Peer': { thisObject.p2pNodesToConnect = [] - let thisP2PNodeId = SA.secrets.map.get(global.env.P2P_NETWORK_NODE_SIGNING_ACCOUNT).nodeId + let thisP2PNodeId = SA.secrets.signingAccountSecrets.map.get(global.env.P2P_NETWORK_NODE_SIGNING_ACCOUNT).nodeId for (let i = 0; i < SA.projects.network.globals.memory.arrays.P2P_NETWORK_NODES.length; i++) { let p2pNetworkNode = SA.projects.network.globals.memory.arrays.P2P_NETWORK_NODES[i] if (thisP2PNodeId !== p2pNetworkNode.node.id) { diff --git a/Projects/Network/SA/Modules/UserProfiles.js b/Projects/Network/SA/Modules/UserProfiles.js index 80d23ffb2f..e95f18a1a3 100644 --- a/Projects/Network/SA/Modules/UserProfiles.js +++ b/Projects/Network/SA/Modules/UserProfiles.js @@ -144,7 +144,7 @@ exports.newNetworkModulesUserProfiles = function newNetworkModulesUserProfiles() Now, we will extract the information from the User Profile, specifically the user app that it is being used. */ if ( - networkClient.id === SA.secrets.map.get(userAppCodeName).nodeId + networkClient.id === SA.secrets.signingAccountSecrets.map.get(userAppCodeName).nodeId ) { p2pNetworkClientIdentity.node = networkClient p2pNetworkClientIdentity.blockchainAccount = blockchainAccount diff --git a/Projects/Network/SA/Modules/WebSocketsNetworkClient.js b/Projects/Network/SA/Modules/WebSocketsNetworkClient.js index dcca609a49..ce6cac31ba 100644 --- a/Projects/Network/SA/Modules/WebSocketsNetworkClient.js +++ b/Projects/Network/SA/Modules/WebSocketsNetworkClient.js @@ -105,7 +105,7 @@ exports.newNetworkModulesWebSocketsNetworkClient = function newNetworkModulesWeb let message = { messageType: 'Handshake', callerRole: thisObject.callerRole, - callerProfileHandle: SA.secrets.map.get(thisObject.p2pNetworkClientCodeName).userProfileHandle, + callerProfileHandle: SA.secrets.signingAccountSecrets.map.get(thisObject.p2pNetworkClientCodeName).userProfileHandle, callerTimestamp: callerTimestamp, step: 'One' } @@ -166,7 +166,7 @@ exports.newNetworkModulesWebSocketsNetworkClient = function newNetworkModulesWeb We will check that the profile handle we sent to the Network Node, is returned at the signed message, to avoid man in the middle attacks. */ - if (signedMessage.callerProfileHandle !== SA.secrets.map.get(thisObject.p2pNetworkClientCodeName).userProfileHandle) { + if (signedMessage.callerProfileHandle !== SA.secrets.signingAccountSecrets.map.get(thisObject.p2pNetworkClientCodeName).userProfileHandle) { console.log('[ERROR] Web Sockets Network Client -> stepOneResponse -> The Network Node callerProfileHandle does not match my own userProfileHandle.') reject() return @@ -196,7 +196,7 @@ exports.newNetworkModulesWebSocketsNetworkClient = function newNetworkModulesWeb */ thisObject.socket.onmessage = socketMessage => { stepTwoResponse(socketMessage) } - let signature = web3.eth.accounts.sign(JSON.stringify(signedMessage), SA.secrets.map.get(thisObject.p2pNetworkClientCodeName).privateKey) + let signature = web3.eth.accounts.sign(JSON.stringify(signedMessage), SA.secrets.signingAccountSecrets.map.get(thisObject.p2pNetworkClientCodeName).privateKey) let message = { messageType: 'Handshake', diff --git a/Projects/Social-Trading/DK/modules/WebAppInterface.js b/Projects/Social-Trading/DK/modules/WebAppInterface.js index d6ef8c92ce..48eb79b747 100644 --- a/Projects/Social-Trading/DK/modules/WebAppInterface.js +++ b/Projects/Social-Trading/DK/modules/WebAppInterface.js @@ -47,7 +47,7 @@ exports.newSocialTradingModulesWebAppInterface = function newSocialTradingModule } return JSON.stringify(response) } - queryMessage.emitterUserProfileId = SA.secrets.map.get(global.env.DESKTOP_APP_SIGNING_ACCOUNT).userProfileId + queryMessage.emitterUserProfileId = SA.secrets.signingAccountSecrets.map.get(global.env.DESKTOP_APP_SIGNING_ACCOUNT).userProfileId messageHeader.queryMessage = JSON.stringify(queryMessage) let response @@ -126,7 +126,7 @@ exports.newSocialTradingModulesWebAppInterface = function newSocialTradingModule eventMessage.postText = undefined } - eventMessage.emitterUserProfileId = SA.secrets.map.get(global.env.DESKTOP_APP_SIGNING_ACCOUNT).userProfileId + eventMessage.emitterUserProfileId = SA.secrets.signingAccountSecrets.map.get(global.env.DESKTOP_APP_SIGNING_ACCOUNT).userProfileId messageHeader.eventMessage = JSON.stringify(eventMessage) let response = { diff --git a/Projects/Trading-Signals/TS/Modules/OutgoingTradingSignals.js b/Projects/Trading-Signals/TS/Modules/OutgoingTradingSignals.js index 638ad8b961..9849cf9ded 100644 --- a/Projects/Trading-Signals/TS/Modules/OutgoingTradingSignals.js +++ b/Projects/Trading-Signals/TS/Modules/OutgoingTradingSignals.js @@ -100,8 +100,8 @@ exports.newTradingSignalsModulesOutgoingTradingSignals = function (processIndex) socialTradingBot: {} } } - signalMessage.signatures.userApp = web3.eth.accounts.sign(JSON.stringify(signalMessage.signal), SA.secrets.map.get(userAppCodeName).privateKey) - signalMessage.signatures.socialTradingBot = web3.eth.accounts.sign(JSON.stringify(signalMessage.signal), SA.secrets.map.get(socialTradingBotCodeName).privateKey) + signalMessage.signatures.userApp = web3.eth.accounts.sign(JSON.stringify(signalMessage.signal), SA.secrets.signingAccountSecrets.map.get(userAppCodeName).privateKey) + signalMessage.signatures.socialTradingBot = web3.eth.accounts.sign(JSON.stringify(signalMessage.signal), SA.secrets.signingAccountSecrets.map.get(socialTradingBotCodeName).privateKey) await TS.projects.foundations.globals.taskConstants.P2P_NETWORK.p2pNetworkStart.sendMessage(signalMessage) } diff --git a/Secrets.js b/Secrets.js new file mode 100644 index 0000000000..01fad29431 --- /dev/null +++ b/Secrets.js @@ -0,0 +1,44 @@ +exports.newSecrets = function () { + + let thisObject = { + initialize: initialize + } + + return thisObject; + + function initialize() { + + SA.secrets = { + signingAccountSecrets: { + array: [], + map: new Map() + }, + apisSecrets: { + array: [], + map: new Map() + } + } + + try { + SA.secrets.signingAccountSecrets = require('./My-Secrets/SigningAccountsSecrets.json').secrets + } catch (err) { + // Still have an empty array. + } + + try { + SA.secrets.apisSecrets = require('./My-Secrets/ApisSecrets.json').secrets + } catch (err) { + // Still have an empty array. + } + + for (let i = 0; i < SA.secrets.signingAccountSecrets.array.length; i++) { + let secret = SA.secrets.signingAccountSecrets.array[i] + SA.secrets.signingAccountSecrets.map.set(secret.nodeCodeName, secret) + } + + for (let i = 0; i < SA.secrets.apisSecrets.array.length; i++) { + let secret = SA.secrets.apisSecrets.array[i] + SA.secrets.apisSecrets.map.set(secret.nodeCodeName, secret) + } + } +} \ No newline at end of file diff --git a/TaskServerRoot.js b/TaskServerRoot.js index 2d8e9d933c..102d214c55 100644 --- a/TaskServerRoot.js +++ b/TaskServerRoot.js @@ -58,22 +58,8 @@ SA.nodeModules = { /* Setting up Secrets. */ -try { - SA.secrets = { - array: require('./My-Secrets/Secrets.json').secrets, - map: new Map() - } -} catch(err) { - SA.secrets = { - array: [], - map: new Map() - } -} - -for (let i = 0; i < SA.secrets.array.length; i++) { - let secret = SA.secrets.array[i] - SA.secrets.map.set(secret.nodeCodeName, secret) -} +let SECRETS = require('./Secrets.js') +SECRETS.initialize() run()