Skip to content

Commit

Permalink
v 0.13.2, fix for custom derivation path, improvement for segwit addr…
Browse files Browse the repository at this point in the history
…esses check
  • Loading branch information
PawelGorny committed Sep 14, 2021
1 parent eeb978a commit 4f0e606
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.pawelgorny</groupId>
<artifactId>lostword</artifactId>
<version>0.13.1</version>
<version>0.13.2</version>
<packaging>jar</packaging>

<dependencies>
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/pawelgorny/lostword/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ public final class Configuration {
private List<ChildNumber> keyPath;

private LegacyAddress legacyAddress;
private byte[] legacyAddressHash;
private SegwitAddress segwitAddress;
private byte[] segwitAddressHash;
private String ethereumAddress;

private final WORK work;
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/pawelgorny/lostword/Worker.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ protected boolean check(final List<String> 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());
}
Expand Down

0 comments on commit 4f0e606

Please sign in to comment.