diff --git a/launcher/src/backend/NodeConnection.js b/launcher/src/backend/NodeConnection.js index 351e285ca..c3bdb2a16 100755 --- a/launcher/src/backend/NodeConnection.js +++ b/launcher/src/backend/NodeConnection.js @@ -728,15 +728,13 @@ export class NodeConnection { } let private_key_data; try { - private_key_data = JSON.parse(private_key); + private_key_data = this.normalizeSSVKeystoreData(JSON.parse(private_key)); } catch (e) { throw new Error("Given encrypted SSV private_key (keystore) is invalid (not JSON format)"); } - // SSV generated keystore uses "pubKey" since v1.3.3, previously it was "publicKey" - if (!private_key_data?.publicKey && !private_key_data?.pubKey) { + if (!private_key_data?.publicKey) { throw new Error("Given encrypted SSV private_key (keystore) is invalid (no public key available)"); } - private_key_data.publicKey = private_key_data?.publicKey ? private_key_data.publicKey : private_key_data?.pubKey; const newPubKey = private_key_data.publicKey; // Add password_file and keystore_file to secrets dir @@ -993,8 +991,7 @@ export class NodeConnection { throw new Error(SSHService.extractExecError(keystore_read)); } const keystore_content = keystore_read.stdout; - const keystore_data = JSON.parse(keystore_content); - keystore_data.publicKey = keystore_data?.publicKey ? keystore_data.publicKey : keystore_data?.pubKey; + const keystore_data = this.normalizeSSVKeystoreData(JSON.parse(keystore_content)); const newPubKey = keystore_data.publicKey; // Write network config @@ -1104,8 +1101,7 @@ export class NodeConnection { throw new Error(SSHService.extractExecError(keystore_read)); } const keystore_content = keystore_read.stdout; - const keystore_data = JSON.parse(keystore_content); - keystore_data.publicKey = keystore_data?.publicKey ? keystore_data.publicKey : keystore_data?.pubKey; + const keystore_data = this.normalizeSSVKeystoreData(JSON.parse(keystore_content)); const newPubKey = keystore_data.publicKey; // Write network config @@ -1362,8 +1358,7 @@ export class NodeConnection { privateKeyFilePath: keyStorePrivateKeyFile, privateKeyFileData: (() => { try { - let pkfdata = JSON.parse(keyStorePrivateKeyFileContent); - pkfdata.publicKey = pkfdata?.publicKey ? pkfdata.publicKey : pkfdata?.pubKey; + let pkfdata = this.normalizeSSVKeystoreData(JSON.parse(keyStorePrivateKeyFileContent)); return pkfdata; } catch (e) { return keyStorePrivateKeyFileContent; @@ -1552,8 +1547,7 @@ export class NodeConnection { privateKeyFilePath: keyStorePrivateKeyFile, privateKeyFileData: (() => { try { - let pkfdata = JSON.parse(keyStorePrivateKeyFileContent); - pkfdata.publicKey = pkfdata?.publicKey ? pkfdata.publicKey : pkfdata?.pubKey; + let pkfdata = this.normalizeSSVKeystoreData(JSON.parse(keyStorePrivateKeyFileContent)); return pkfdata; } catch (e) { return keyStorePrivateKeyFileContent; @@ -1627,7 +1621,26 @@ export class NodeConnection { return; } - // <-------- NEW SSVDKGMODAL END ---------> + // <-------- NEW SSVMODAL & SSVDKGMODAL HELPERS START ---------> + + // SSV keystore field naming for the public key has changed over time: + // - v1.3.3 used "pubKey" + // - v2.3.5 used "pubkey" + // - originally it was "publicKey". + // This method ensures that an additional "publicKey" property + // is always set, copying from whichever variant is present. + normalizeSSVKeystoreData(keystore_data) { + keystore_data.publicKey = keystore_data?.publicKey + ? keystore_data.publicKey + : keystore_data?.publickey + ? keystore_data.publickey + : keystore_data?.pubKey + ? keystore_data.pubKey + : keystore_data?.pubkey; + return keystore_data; + } + + // <-------- NNEW SSVMODAL & SSVDKGMODAL HELPERS END ---------> async readPrometheusConfig(serviceID) { let prometheusConfig;