Update. Added more tests and refined the Private EC Key to Public operation.

This commit is contained in:
David C Goldenberg 2026-07-22 08:51:13 -04:00
parent e1a4c2303a
commit ff22f9746d
2 changed files with 61 additions and 7 deletions

View File

@ -24,12 +24,16 @@ const OUTPUT_OPTIONS = ["Public Key Only", "Private,Public", "Public,Private"];
* @returns
*/
function formatOutput(privateKey, publicKey, option) {
if (option === "Public Key Only") {
return publicKey;
} else if (option === "Private,Public") {
return privateKey+","+publicKey;
} else if (option === "Public,Private") {
return publicKey+","+privateKey;
switch (option) {
case "Public Key Only":
return publicKey;
case "Private,Public":
return privateKey+","+publicKey;
case "Public,Private":
return publicKey+","+privateKey;
default:
throw OperationError("Invalid output format option: " + option + ".");
}
}
/**
@ -105,6 +109,8 @@ class PrivateECKeyToPublic extends Operation {
const ed = new ec.eddsa("ed25519");
const publicKeyHex = ed.keyFromSecret(processedInput).getPublic("hex");
return formatOutput(processedInput, publicKeyHex, args[2]);
} else {
throw OperationError("Unexpected curve selection: " + args[1] + ".");
}

View File

@ -72,5 +72,53 @@ TestRegister.addTests([
"args": [false, "secp256k1", "Public Key Only"]
},
],
}
},
{
name: "Exodus Solana Private Key To Address Example (Full 64 Private Key)",
input: "S3Y5GEsCMcU15pAGb6fPAb6nG1nk6SA4nSuVLxEH9xVQdtdnDBDxE8kYkAvdnrF7xK5UTVTDeN3zKT3ZLeeBygc",
expectedOutput: "3LzenrN4cveQZbodWxgepAHRyr7Xs53FwMQsuiD13jMS",
recipeConfig: [
{ "op": "From Base58", "args": ["123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz", true] },
{ "op": "Drop bytes", "args": [-32, 32, false] },
{ "op": "To Hex", "args": ["None", 32] },
{ "op": "Private EC Key to Public Key", "args": [true, "ed25519", "Public Key Only"] },
{ "op": "From Hex", "args": ["Auto"] },
{ "op": "To Base58", "args": ["123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"] }
]
},
{
name: "Exodus Solana Private Key To Address Example Private Key to Full Solana Private Key",
input: "1598c4d3c92419359a1901eb9ee4f7836e999959737d002c3b2128aa592bd364",
expectedOutput: "S3Y5GEsCMcU15pAGb6fPAb6nG1nk6SA4nSuVLxEH9xVQdtdnDBDxE8kYkAvdnrF7xK5UTVTDeN3zKT3ZLeeBygc",
// To regenerate in Exodus use seedphrase: announce mesh cake need drink better dwarf profit cute lady want foster
// Should be first Solana address in Exodus.
recipeConfig: [
{ "op": "Private EC Key to Public Key", "args": [true, "ed25519", "Private,Public"] },
{ "op": "Find / Replace", "args": [{ "option": "Regex", "string": "," }, "", true, false, true, false] },
{ "op": "From Hex", "args": ["Auto"] },
{ "op": "To Base58", "args": ["123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"] }
]
},
{
name: "Private EC Key to Public Wrong Curve",
input: "5E2A8FDE9F861056607208F512287CFBD634E124044EE23EBF7289E8E7B3822E",
expectedOutput: "Curve must be one of the following: secp256k1, ed25519.",
recipeConfig: [
{
"op": "Private EC Key to Public Key",
"args": [false, "secp256k2", "Public Key Only"]
},
],
},
{
name: "Private EC Key to Public Wrong Option",
input: "5E2A8FDE9F861056607208F512287CFBD634E124044EE23EBF7289E8E7B3822E",
expectedOutput: "Output Option must be one of the following: Public Key Only, Private,Public, Public,Private.",
recipeConfig: [
{
"op": "Private EC Key to Public Key",
"args": [false, "secp256k1", "Public Key Onl"]
},
],
},
]);