From ff22f9746d9222580b39b8a9479d930098449966 Mon Sep 17 00:00:00 2001 From: David C Goldenberg Date: Wed, 22 Jul 2026 08:51:13 -0400 Subject: [PATCH] Update. Added more tests and refined the Private EC Key to Public operation. --- src/core/operations/PrivateECKeyToPublic.mjs | 18 ++++--- .../operations/tests/PrivateECKeyToPublic.mjs | 50 ++++++++++++++++++- 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/src/core/operations/PrivateECKeyToPublic.mjs b/src/core/operations/PrivateECKeyToPublic.mjs index fd38e859..387c5ac4 100644 --- a/src/core/operations/PrivateECKeyToPublic.mjs +++ b/src/core/operations/PrivateECKeyToPublic.mjs @@ -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] + "."); } diff --git a/tests/operations/tests/PrivateECKeyToPublic.mjs b/tests/operations/tests/PrivateECKeyToPublic.mjs index 9229dbd2..37ea88ae 100644 --- a/tests/operations/tests/PrivateECKeyToPublic.mjs +++ b/tests/operations/tests/PrivateECKeyToPublic.mjs @@ -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"] + }, + ], + }, ]);