diff --git a/src/core/operations/KeyToExtendedKey.mjs b/src/core/operations/KeyToExtendedKey.mjs index 3ea350ed4..0c0ba3f11 100644 --- a/src/core/operations/KeyToExtendedKey.mjs +++ b/src/core/operations/KeyToExtendedKey.mjs @@ -33,11 +33,30 @@ class KeyToExtendedKey extends Operation { "value": "", "toggleValues": ["Hex"] }, + { + "name": "Fingerprint", + "type": "toggleString", + "value": "00000000", + "toggleValues": ["Hex"] + }, + { + "name": "Level", + "type": "toggleString", + "value": 0, + "toggleValues": ["Hex", "Number"] + }, { "name": "Version Type", "type": "option", "value": getVersions() + }, + { + "name": "i", + "type": "toggleString", + "value": 0, + "toggleValues": ["Hex", "Number"] } + ]; } @@ -60,16 +79,21 @@ class KeyToExtendedKey extends Operation { if (!isPublic && !isPrivate) { throw new OperationError("Error: String " + inputAsHex + " is not a valid public or private key."); } - if (isPublic && privateVersions.indexOf(args[1]) !== -1) { + if (isPublic && privateVersions.indexOf(args[3]) !== -1) { throw new OperationError("Error: Mis-Match between version and key type. Public Key is entered, but a private version is selected."); } - if (isPrivate && privateVersions.indexOf(args[1]) === -1) { + if (isPrivate && privateVersions.indexOf(args[3]) === -1) { throw new OperationError("Error: Mis-Match between version and key type. Private Key is entered, but a public version is selected."); } const key = isPrivate ? "00" + inputAsHex : inputAsHex; - const newVersion = getExtendedKeyVersion(args[1]); + const radix = (args[2].option === "Hex") ? 16 : 10; + const level = parseInt(args[2].string, radix); + const iRadix = (args[4].option === "Hex") ? 16: 10; + const i = parseInt(args[4].string, iRadix); + const fingerprint = args[1]; + const newVersion = getExtendedKeyVersion(args[3]); - const newExtendedKey = serializeExtendedKeyFunc(newVersion, 0, "00000000", 0, args[0].string, key); + const newExtendedKey = serializeExtendedKeyFunc(newVersion, level, fingerprint.string, i, args[0].string, key); return newExtendedKey; } diff --git a/tests/operations/tests/KeyToExtendedKey.mjs b/tests/operations/tests/KeyToExtendedKey.mjs index cfb532b6f..7f50ece90 100644 --- a/tests/operations/tests/KeyToExtendedKey.mjs +++ b/tests/operations/tests/KeyToExtendedKey.mjs @@ -22,7 +22,20 @@ TestRegister.addTests([ "option": "Hex", "string": "fedf6c5ebcc2fc7b66291e55501a005886128bf97aeced3a91478a0c44f54dbe" }, - "xprv" + { + "option": "Hex", + "string": "00000000" + }, + { + "option": "Number", + "string": "0" + }, + "xprv", + { + "option": "Number", + "string": "0" + }, + ] } ], @@ -39,7 +52,19 @@ TestRegister.addTests([ "option": "Hex", "string": "fedf6c5ebcc2fc7b66291e55501a005886128bf97aeced3a91478a0c44f54dbe" }, - "yprv" + { + "option": "Hex", + "string": "00000000" + }, + { + "option": "Number", + "string": "0" + }, + "yprv", + { + "option": "Number", + "string": "0" + } ] } ], @@ -56,7 +81,19 @@ TestRegister.addTests([ "option": "Hex", "string": "cda6685894f356bdf1bd6af6cb7e3961e550fb9c9b2c82d9ebfd89f48c2afea6" }, - "xprv" + { + "option": "Hex", + "string": "00000000" + }, + { + "option": "Number", + "string": "0" + }, + "xprv", + { + "option": "Number", + "string": "0" + } ] } ], @@ -73,7 +110,19 @@ TestRegister.addTests([ "option": "Hex", "string": "fedf6c5ebcc2fc7b66291e55501a005886128bf97aeced3a91478a0c44f54dbe" }, - "xpub" + { + "option": "Hex", + "string": "00000000" + }, + { + "option": "Number", + "string": "0" + }, + "xpub", + { + "option": "Number", + "string": "0" + } ] } ],