Skip to content

Commit

Permalink
v 0.5.9, worker end - support for p2sh
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelGorny committed Mar 28, 2022
1 parent 836aa67 commit 4a4706c
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
6 changes: 6 additions & 0 deletions examples/example_END_3.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
END
#target: L2VuM2Mj8E1VwwBLbxj8zujzeKJPQ9UE2GwMjEvLiCMY3kJj6F8F
#2nd line: WIF with missing end
L2VuM2Mj8E1VwwBLbxj8zujzeKJPQ9UE2GwMjEvLiCMY3
#3rd end: expected address, if you know one
3H1qgYqxfzqxmMT9MKAjbxyrpVZ5YtA3wX
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>wifSolver</artifactId>
<version>0.5.8</version>
<version>0.5.9</version>
<packaging>jar</packaging>

<dependencies>
Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/pawelgorny/wifsolver/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Configuration {
private final static int STATUS_PERIOD = 60 * 1000; //1 minute
private final static int CHECKSUM_CHARS = 5;


private Boolean isP2SH;
private final String targetAddress;
private final String wif;
private final String wifStatus;
Expand All @@ -33,9 +33,15 @@ public class Configuration {

public Configuration(String targetAddress, String wif, String wifStatus, WORK work, Map<Integer, char[]> guess) {
this.targetAddress = targetAddress;
isP2SH = false;
if (targetAddress != null) {
this.address = LegacyAddress.fromBase58(NETWORK_PARAMETERS, getTargetAddress());
this.addressHash = address.getHash();
if (targetAddress.startsWith("3")){
compressed = true;
isP2SH = true;
}else {
this.address = LegacyAddress.fromBase58(NETWORK_PARAMETERS, getTargetAddress());
this.addressHash = address.getHash();
}
}
this.wif = wif;
this.compressed = wif.length() == COMPRESSED_WIF_LENGTH || (WORK.END.equals(work) && (wif.startsWith("L") || wif.startsWith("K")));
Expand Down Expand Up @@ -104,6 +110,10 @@ public void setForceThreads(Integer forceThreads) {
this.forceThreads = forceThreads;
}

public Boolean getIsP2SH() {
return isP2SH;
}

class EmailConfiguration{
private final Session mailSession;
private final String emailTo;
Expand Down
27 changes: 21 additions & 6 deletions src/main/java/com/pawelgorny/wifsolver/WorkerEnd.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.pawelgorny.wifsolver;

import org.bitcoinj.core.*;
import org.bitcoinj.script.Script;
import org.bitcoinj.script.ScriptBuilder;
import org.bitcoinj.script.ScriptPattern;

import java.util.Arrays;
import java.util.Date;
Expand Down Expand Up @@ -121,12 +124,24 @@ private String checksumCheck(int missing, String wif, int len, final Address tar
if (!configuration.isCompressed()) {
ecKey = ecKey.decompress();
}
if (targetAddress != null) {
if (Arrays.equals(ecKey.getPubKeyHash(), targetAddress.getHash())) {
Address foundAddress = LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey);
found = true;
super.addResult(encoded + " -> " + foundAddress);
System.out.println(encoded + " -> " + foundAddress);
if (targetAddress != null || configuration.getIsP2SH()) {
if (configuration.getIsP2SH()){
Script redeemScript = ScriptBuilder.createP2WPKHOutputScript(ecKey);
Script script = ScriptBuilder.createP2SHOutputScript(redeemScript);
byte[] scriptHash = ScriptPattern.extractHashFromP2SH(script);
LegacyAddress foundAddress = LegacyAddress.fromScriptHash(configuration.getNetworkParameters(), scriptHash);
if (foundAddress.toString().equals(configuration.getTargetAddress())){
found = true;
super.addResult(encoded + " -> " + foundAddress);
System.out.println(encoded + " -> " + foundAddress);
}
}else {
if (Arrays.equals(ecKey.getPubKeyHash(), targetAddress.getHash())) {
Address foundAddress = LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey);
found = true;
super.addResult(encoded + " -> " + foundAddress);
System.out.println(encoded + " -> " + foundAddress);
}
}
} else {
Address foundAddress = LegacyAddress.fromKey(Configuration.getNetworkParameters(), ecKey);
Expand Down

0 comments on commit 4a4706c

Please sign in to comment.