diff --git a/pom.xml b/pom.xml index 2213ff9..e47204a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.pawelgorny lostword - 0.13.1 + 0.13.2 jar diff --git a/src/main/java/com/pawelgorny/lostword/Configuration.java b/src/main/java/com/pawelgorny/lostword/Configuration.java index 9eba4cc..55effd3 100644 --- a/src/main/java/com/pawelgorny/lostword/Configuration.java +++ b/src/main/java/com/pawelgorny/lostword/Configuration.java @@ -37,7 +37,9 @@ public final class Configuration { private List keyPath; private LegacyAddress legacyAddress; + private byte[] legacyAddressHash; private SegwitAddress segwitAddress; + private byte[] segwitAddressHash; private String ethereumAddress; private final WORK work; @@ -91,9 +93,11 @@ private void parseScript(String targetAddress) { switch (getDBscriptType()){ case P2PKH: legacyAddress = LegacyAddress.fromBase58(getNETWORK_PARAMETERS(), getTargetAddress()); + legacyAddressHash = legacyAddress.getHash(); break; case P2WPKH: segwitAddress = SegwitAddress.fromBech32(getNETWORK_PARAMETERS(), getTargetAddress()); + segwitAddressHash = segwitAddress.getHash(); break; } } @@ -142,7 +146,7 @@ private void parsePath(String path) { derivationPath.add(new ChildNumber(Integer.parseInt(x), true)); if (i==2){ this.coin = Integer.parseInt(x); - this.keyPath = HDUtils.parsePath(this.derivationPathFull); + this.keyPath = HDUtils.parsePath(this.derivationPathFull.contains("-")?this.derivationPathFull.substring(0, this.derivationPathFull.indexOf("-")):this.derivationPathFull); } } } @@ -208,10 +212,18 @@ public void setLegacyAddress(LegacyAddress legacyAddress) { this.legacyAddress = legacyAddress; } + public byte[] getLegacyAddressHash() { + return legacyAddressHash; + } + public SegwitAddress getSegwitAddress() { return segwitAddress; } + public byte[] getSegwitAddressHash() { + return segwitAddressHash; + } + public void setSegwitAddress(SegwitAddress segwitAddress) { this.segwitAddress = segwitAddress; } diff --git a/src/main/java/com/pawelgorny/lostword/Worker.java b/src/main/java/com/pawelgorny/lostword/Worker.java index 09dcc91..d8b47c2 100644 --- a/src/main/java/com/pawelgorny/lostword/Worker.java +++ b/src/main/java/com/pawelgorny/lostword/Worker.java @@ -120,7 +120,8 @@ protected boolean check(final List mnemonic, HMac SHA512DIGEST, MessageD } } if (configuration.getDBscriptType().equals(Script.ScriptType.P2WPKH)){ - result = Address.fromKey(configuration.getNETWORK_PARAMETERS(), deterministicKey, Script.ScriptType.P2WPKH).equals(configuration.getSegwitAddress()); +// result = Address.fromKey(configuration.getNETWORK_PARAMETERS(), deterministicKey, Script.ScriptType.P2WPKH).equals(configuration.getSegwitAddress()); + result = Arrays.equals(configuration.getSegwitAddressHash(), deterministicKey.getPubKeyHash()); }else { result = Address.fromKey(configuration.getNETWORK_PARAMETERS(), deterministicKey, configuration.getDBscriptType()).equals(configuration.getLegacyAddress()); }