Commit ae90f271 authored by zeroleak's avatar zeroleak
Browse files

restrict setExternalXpub to bip84 XPpubs

parent dd724b81
...@@ -41,21 +41,21 @@ public class RunSetExternalXpub { ...@@ -41,21 +41,21 @@ public class RunSetExternalXpub {
String xpub = readXpub(params); String xpub = readXpub(params);
if (xpub != null) { if (xpub != null) {
// chain // chain
log.info("⣿ • Chain for XPub derivation path m/84'/<chain>' (use 0 for standard):"); log.info("⣿ • Chain for derivation path m/84'/<chain>' (use 0 for standard):");
int chain = CliUtils.readUserInputRequiredInt("Chain?(0)", 0, 0); int chain = CliUtils.readUserInputRequiredInt("Chain?(0)", 0, 0);
log.info("⣿ "); log.info("⣿ ");
// startIndex // startIndex
log.info( log.info(
"⣿ • Starting index for XPub derivation path m/84'/" "⣿ • Starting index for derivation path m/84'/"
+ chain + chain
+ "'/<starting index>' (use 0 for standard):"); + "'/<starting index>' (use 0 for standard):");
int startIndex = CliUtils.readUserInputRequiredInt("Starting index?(0)", 0, 0); int startIndex = CliUtils.readUserInputRequiredInt("Starting index?(0)", 0, 0);
log.info("⣿ "); log.info("⣿ ");
// mixs // mixs
log.info("⣿ • Number of mixs to achieve before sending funds to XPub (>0):"); log.info("⣿ • Number of mixs to achieve before sending funds:");
int mixs = CliUtils.readUserInputRequiredInt("Mixs?", 1); int mixs = CliUtils.readUserInputRequiredInt("Mixs?(>0)", 1);
log.info("⣿ "); log.info("⣿ ");
// print addresses // print addresses
...@@ -104,16 +104,15 @@ public class RunSetExternalXpub { ...@@ -104,16 +104,15 @@ public class RunSetExternalXpub {
private String readXpub(NetworkParameters params) { private String readXpub(NetworkParameters params) {
while (true) { while (true) {
String zpubOrVpub = formatUtil.isTestNet(params) ? "VPub" : "ZPub"; String input = CliUtils.readUserInput("External BIP84 XPub/ZPub or <enter> to unset?", false);
String input = CliUtils.readUserInput(zpubOrVpub + " or <enter> to unset?", false);
if (StringUtils.isEmpty(input)) { if (StringUtils.isEmpty(input)) {
// clear current xpub // clear current xpub
return null; return null;
} else { } else {
try { try {
// if (!formatUtil.isValidXpub(input)) { // if (!formatUtil.isValidXpub(input)) {
if (!isValidXpubBip84(input, params)) { if (!isValidXpubOrZpub(input, params)) {
throw new NotifiableException("Invalid " + zpubOrVpub); throw new NotifiableException("Invalid BIP84 XPub/ZPub");
} }
return input; return input;
} catch (Exception e) { } catch (Exception e) {
...@@ -127,9 +126,14 @@ public class RunSetExternalXpub { ...@@ -127,9 +126,14 @@ public class RunSetExternalXpub {
// TODO use extlibj // TODO use extlibj
private static final int MAGIC_ZPUB = 0x04B24746; private static final int MAGIC_ZPUB = 0x04B24746;
private static final int MAGIC_VPUB = 0x045F1CF6; private static final int MAGIC_VPUB = 0x045F1CF6;
public static final int MAGIC_TPUB = 0x043587CF;
public boolean isValidXpubBip84(String xpub, NetworkParameters params) { public static final int MAGIC_XPUB = 0x0488B21E;
int magic = formatUtil.isTestNet(params) ? MAGIC_VPUB : MAGIC_ZPUB;
public boolean isValidXpubOrZpub(String xpub, NetworkParameters params) {
int[] magic =
formatUtil.isTestNet(params)
? new int[] {MAGIC_VPUB, MAGIC_TPUB}
: new int[] {MAGIC_ZPUB, MAGIC_XPUB};
return isValidXpub(xpub, magic); return isValidXpub(xpub, magic);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment