Update. Updated the Key to ExtendedKey operation to take in fingerprint, i, level as well as the chaincode and version type.

This commit is contained in:
David C Goldenberg 2025-12-02 15:16:12 -05:00
parent 1cad7fbb96
commit 7fb2a9640a
2 changed files with 81 additions and 8 deletions

View file

@ -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;
}

View file

@ -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"
}
]
}
],