Skip to content

Commit

Permalink
Now we will have 2 secrets files, one for Signing Accounts and the ot…
Browse files Browse the repository at this point in the history
…her for APIs
  • Loading branch information
Luis-Fernando-Molina committed Dec 18, 2021
1 parent e26dae7 commit 1906f01
Show file tree
Hide file tree
Showing 13 changed files with 74 additions and 86 deletions.
20 changes: 3 additions & 17 deletions DesktopRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()

Expand Down
18 changes: 2 additions & 16 deletions DesktopRootReact.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
18 changes: 2 additions & 16 deletions NetworkRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
10 changes: 5 additions & 5 deletions Platform/Client/httpInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -373,23 +373,23 @@ 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 {
/*
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
)
}
Expand Down
6 changes: 3 additions & 3 deletions Projects/Network/NT/Modules/WebSocketsInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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.'
Expand Down
2 changes: 1 addition & 1 deletion Projects/Network/SA/Modules/P2PNetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Projects/Network/SA/Modules/UserProfiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions Projects/Network/SA/Modules/WebSocketsNetworkClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down
4 changes: 2 additions & 2 deletions Projects/Social-Trading/DK/modules/WebAppInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down
4 changes: 2 additions & 2 deletions Projects/Trading-Signals/TS/Modules/OutgoingTradingSignals.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
44 changes: 44 additions & 0 deletions Secrets.js
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
18 changes: 2 additions & 16 deletions TaskServerRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 1906f01

Please sign in to comment.