Skip to content

Commit

Permalink
v 0.9.0, support for BIP141, BIP84, BIP44, BIP32
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelGorny committed Feb 19, 2021
1 parent ef84f78 commit 8fc1fb5
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 18 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# LostWord
Tool for finding missing word for BIP39 seed, having (n-1) known ordered words.
Program works with BIP84/P2WPKH or BIP32/P2PKH Derivation Path.
Program works with P2WPKH: BIP84, BIP141 or P2PKH: BIP32, BIP44 Derivation Path.

Usage:
`java -jar lostWord.jar configurationFile`
Expand All @@ -11,11 +11,13 @@ How to use it
-------------
Please check files in /examples/ folder to see how to set up the configuration file.
Configuration file expects: address, number of words, known words and additionally derivation path. If not specified, the default will be used (m/0/0).
This version checks only one address - for the given path. In the future (or if requested) I will add possibility to verify all the addresses up to address number x. Today, if you know address but you do not know if it was first or second from the derivation path, you must launch program twice, using two different paths (m/0/0 and m/0/1).
This version checks only one address - for the given path. In the future (or if requested) I will add possibility to verify all the addresses up to address number x. If you know the address but you do not know if it was first or second from the derivation path, you must launch program twice, using two different paths (for example m/0/0 and m/0/1).
It is possible to launch tests against 'hardened' addresses, using ' (apostrophe) as the last character of path.
Using page https://iancoleman.io/bip39/ you may easily check what to expect for the given seed.
By default program uses P2PKH script semantics for addresses like "1..." and P2WPKH for addresses like "bc1...".

If derivation path is not specified, by default program is using "m/0/0" (BIP32 for P2PKH and BIP141 for P2WPKH). If you want to do calculations for BIP44 or BIP84, please use the proper derivation path, for example "m/44'/0'/0'/0/0" or "m/84'/0'/0'/0/0".

Program could be launched in 2 modes:
<ol>
<li>ONE_UNKNOWN</li>
Expand Down
28 changes: 28 additions & 0 deletions examples/example_14.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#example with BIP44
ONE_UNKNOWN
1AWvRYYtcBA2iwM43meVvP6duoVf8ZbAV7
24
twelve
early
treat
random
theme
belt
display
impulse
rookie
dignity
real
wedding
dose
situate
leisure
idle
river
knife
december
betray
economy
cloth
mad
m/44'/0'/0'/0/0
28 changes: 28 additions & 0 deletions examples/example_15.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#example with BIP84
ONE_UNKNOWN
bc1qfv3np70y2vu8lf829zpyzecckfn4te3mxvh4ea
24
twelve
early
treat
random
theme
belt
display
impulse
rookie
dignity
real
wedding
dose
situate
leisure
idle
river
knife
december
betray
economy
cloth
mad
m/84'/0'/0'/0/0
28 changes: 28 additions & 0 deletions examples/example_16.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#example with BIP141
ONE_UNKNOWN
bc1qtw2rtg52s7e9jl9yuud9avfhqpcf2f93pes45x
24
twelve
early
treat
random
theme
belt
display
impulse
rookie
dignity
real
wedding
dose
situate
leisure
idle
river
knife
december
betray
economy
cloth
mad
m/0/0
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.8.2</version>
<version>0.9.0</version>
<packaging>jar</packaging>

<dependencies>
Expand Down
25 changes: 11 additions & 14 deletions src/main/java/com/pawelgorny/lostword/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,24 @@ private void parsePath(String path) {
}
String[] dpath = path.replaceAll("'", "").split("/");
try {
Integer.parseInt(dpath[1]);
Integer.parseInt(dpath[2]);
DPaccount = Integer.parseInt(dpath[1]);
DPaddress = Integer.parseInt(dpath[2]);
Integer.parseInt(dpath[dpath.length-2]);
Integer.parseInt(dpath[dpath.length-1]);
DPaccount = Integer.parseInt(dpath[dpath.length-2]);
DPaddress = Integer.parseInt(dpath[dpath.length-1]);
DPhard = path.endsWith("'");
if (DBscriptType.equals(Script.ScriptType.P2PKH)){
derivationPath = new ArrayList<>(2);
}else if (DBscriptType.equals(Script.ScriptType.P2WPKH)){
derivationPath = new ArrayList<>(5);
derivationPath.add(new ChildNumber(84, true));
derivationPath.add(new ChildNumber(0, true));
derivationPath.add(new ChildNumber(0, true));
derivationPath = new ArrayList<>(5);
boolean pathProvided = dpath.length>3;
if (pathProvided){
for (int i=1; i<dpath.length-2; i++){
String x = dpath[i].replaceAll("'","");
derivationPath.add(new ChildNumber(Integer.parseInt(x), true));
}
}
derivationPath.add(new ChildNumber(getDPaccount(), false));
derivationPath.add(new ChildNumber(getDPaddress(), isDPhard()));

String derivationPathString = "m/"+derivationPath.stream().map(Object::toString)
.collect(Collectors.joining("/")).replaceAll("H", "'");

System.out.println("Using derivation path " + derivationPathString);

} catch (Exception e) {
parsePath(this.DEFAULT_PATH);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/pawelgorny/lostword/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private static Configuration readConfiguration(String file) {
path = line;
} else if (words.size() < size - 1) {
if (!Configuration.MNEMONIC_CODE.getWordList().contains(line)) {
System.out.println("WORD not in BIP39: " + line);
System.out.println("WORD not in BIP39 dictionary: " + line);
System.exit(1);
}
words.add(line);
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ java -jar lostWord.jar input.conf
Available solvers:
ONE_UNKNOWN - seed with one unknown word, on unknown position
KNOWN_POSITION - seed with one or more unknown word, on known position
POOL - seed with one or more unknown word, on known position, with a candidates
ONE_UNKNOWN_CHECK_ALL - online check for balance of 10 addresses for each generated seed (with one missing word)
For details, please check the corresponding example files.

0 comments on commit 8fc1fb5

Please sign in to comment.