Made an improvement to two operations where now an error in deserializing an extended key is passed onto the operations itseslf, which then throw an OperationError.
This commit is contained in:
parent
5265da5714
commit
1cad7fbb96
@ -7,6 +7,7 @@
|
||||
*/
|
||||
|
||||
import Operation from "../Operation.mjs";
|
||||
import OperationError from "../errors/OperationError.mjs";
|
||||
import { deserializeExtendedKeyFunc, serializeExtendedKeyFunc, getExtendedKeyVersion, getVersions } from "../lib/Bitcoin.mjs";
|
||||
|
||||
|
||||
@ -53,6 +54,9 @@ class ChangeExtendedKeyVersion extends Operation {
|
||||
return "";
|
||||
}
|
||||
const result = deserializeExtendedKeyFunc(input);
|
||||
if ("error" in result) {
|
||||
throw new OperationError("Error in deserializing key. Error is: " + result.error);
|
||||
}
|
||||
const newVersion = getExtendedKeyVersion(args[0]);
|
||||
return serializeExtendedKeyFunc(newVersion, result.level, result.fingerprint, result.i, result.chaincode, result.masterkey);
|
||||
}
|
||||
|
||||
@ -45,6 +45,9 @@ class PrivateExtendedKeyToPublic extends Operation {
|
||||
input = input.trim();
|
||||
|
||||
const result = deserializeExtendedKeyFunc(input);
|
||||
if ("error" in result) {
|
||||
throw new OperationError("Error in deserializing key. Error is: " + result.error);
|
||||
}
|
||||
const versionString = getExtendedKeyString(result.version);
|
||||
const privateVersions = ["xprv", "yprv", "zprv", "Zprv", "Yprv", "Ltpv", "Mtpv", "ttpv", "tprv", "uprv", "vprv", "Uprv", "Vprv"];
|
||||
if (privateVersions.indexOf(versionString) === -1) {
|
||||
|
||||
@ -52,5 +52,16 @@ TestRegister.addTests([
|
||||
"args": ["xprv"],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: "Change Extended Key Version (bad cheksums))",
|
||||
input: "zprvAWgYBBk7JR8GkFBvcbtyjkviqhbXpwsiQwVVHmmePfBQH6MC2gna9L64DcoQZAS2tsGhZkTg9xTbAd7LdaACX5J9kyPM2qTC8kE9XXGNzuz",
|
||||
expectedOutput: "Error in deserializing key. Error is: Invalid checksum.",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Change Extended Key Version",
|
||||
"args": ["xprv"],
|
||||
},
|
||||
],
|
||||
}
|
||||
]);
|
||||
|
||||
@ -43,6 +43,17 @@ TestRegister.addTests([
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Private Extended Key To Public (invalid checksum)",
|
||||
input: "zprvAdjAKuQajRu4ptst29FzkcB18fyZuHCKJhe51m38ejMcjW5P4frUffXMYfwLiTs4UrFD5m41So3VhAWGyrb4YV4gFRwYuLom8psLoW252Xe",
|
||||
expectedOutput: "Error in deserializing key. Error is: Invalid checksum.",
|
||||
recipeConfig: [
|
||||
{
|
||||
"op": "Private Extended Key To Public",
|
||||
"args": []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: "Private Extended Key To Public (blank)",
|
||||
input: "",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user