Skip to content

Commit 6dbba50

Browse files
authored
FIX: ssv keystore normalization for public key (#2278)
* FIX: ssv keystore normalization for public key * CHORE: fix code style to pass test
1 parent bcd336c commit 6dbba50

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

launcher/src/backend/NodeConnection.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -728,15 +728,13 @@ export class NodeConnection {
728728
}
729729
let private_key_data;
730730
try {
731-
private_key_data = JSON.parse(private_key);
731+
private_key_data = this.normalizeSSVKeystoreData(JSON.parse(private_key));
732732
} catch (e) {
733733
throw new Error("Given encrypted SSV private_key (keystore) is invalid (not JSON format)");
734734
}
735-
// SSV generated keystore uses "pubKey" since v1.3.3, previously it was "publicKey"
736-
if (!private_key_data?.publicKey && !private_key_data?.pubKey) {
735+
if (!private_key_data?.publicKey) {
737736
throw new Error("Given encrypted SSV private_key (keystore) is invalid (no public key available)");
738737
}
739-
private_key_data.publicKey = private_key_data?.publicKey ? private_key_data.publicKey : private_key_data?.pubKey;
740738
const newPubKey = private_key_data.publicKey;
741739

742740
// Add password_file and keystore_file to secrets dir
@@ -993,8 +991,7 @@ export class NodeConnection {
993991
throw new Error(SSHService.extractExecError(keystore_read));
994992
}
995993
const keystore_content = keystore_read.stdout;
996-
const keystore_data = JSON.parse(keystore_content);
997-
keystore_data.publicKey = keystore_data?.publicKey ? keystore_data.publicKey : keystore_data?.pubKey;
994+
const keystore_data = this.normalizeSSVKeystoreData(JSON.parse(keystore_content));
998995
const newPubKey = keystore_data.publicKey;
999996

1000997
// Write network config
@@ -1104,8 +1101,7 @@ export class NodeConnection {
11041101
throw new Error(SSHService.extractExecError(keystore_read));
11051102
}
11061103
const keystore_content = keystore_read.stdout;
1107-
const keystore_data = JSON.parse(keystore_content);
1108-
keystore_data.publicKey = keystore_data?.publicKey ? keystore_data.publicKey : keystore_data?.pubKey;
1104+
const keystore_data = this.normalizeSSVKeystoreData(JSON.parse(keystore_content));
11091105
const newPubKey = keystore_data.publicKey;
11101106

11111107
// Write network config
@@ -1362,8 +1358,7 @@ export class NodeConnection {
13621358
privateKeyFilePath: keyStorePrivateKeyFile,
13631359
privateKeyFileData: (() => {
13641360
try {
1365-
let pkfdata = JSON.parse(keyStorePrivateKeyFileContent);
1366-
pkfdata.publicKey = pkfdata?.publicKey ? pkfdata.publicKey : pkfdata?.pubKey;
1361+
let pkfdata = this.normalizeSSVKeystoreData(JSON.parse(keyStorePrivateKeyFileContent));
13671362
return pkfdata;
13681363
} catch (e) {
13691364
return keyStorePrivateKeyFileContent;
@@ -1552,8 +1547,7 @@ export class NodeConnection {
15521547
privateKeyFilePath: keyStorePrivateKeyFile,
15531548
privateKeyFileData: (() => {
15541549
try {
1555-
let pkfdata = JSON.parse(keyStorePrivateKeyFileContent);
1556-
pkfdata.publicKey = pkfdata?.publicKey ? pkfdata.publicKey : pkfdata?.pubKey;
1550+
let pkfdata = this.normalizeSSVKeystoreData(JSON.parse(keyStorePrivateKeyFileContent));
15571551
return pkfdata;
15581552
} catch (e) {
15591553
return keyStorePrivateKeyFileContent;
@@ -1627,7 +1621,26 @@ export class NodeConnection {
16271621
return;
16281622
}
16291623

1630-
// <-------- NEW SSVDKGMODAL END --------->
1624+
// <-------- NEW SSVMODAL & SSVDKGMODAL HELPERS START --------->
1625+
1626+
// SSV keystore field naming for the public key has changed over time:
1627+
// - v1.3.3 used "pubKey"
1628+
// - v2.3.5 used "pubkey"
1629+
// - originally it was "publicKey".
1630+
// This method ensures that an additional "publicKey" property
1631+
// is always set, copying from whichever variant is present.
1632+
normalizeSSVKeystoreData(keystore_data) {
1633+
keystore_data.publicKey = keystore_data?.publicKey
1634+
? keystore_data.publicKey
1635+
: keystore_data?.publickey
1636+
? keystore_data.publickey
1637+
: keystore_data?.pubKey
1638+
? keystore_data.pubKey
1639+
: keystore_data?.pubkey;
1640+
return keystore_data;
1641+
}
1642+
1643+
// <-------- NNEW SSVMODAL & SSVDKGMODAL HELPERS END --------->
16311644

16321645
async readPrometheusConfig(serviceID) {
16331646
let prometheusConfig;

0 commit comments

Comments
 (0)