Skip to content

Commit

Permalink
Merge key index into path in mnemonic recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
Coding-Enthusiast committed Jan 28, 2021
1 parent 04ff6df commit b3e285d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 45 deletions.
5 changes: 1 addition & 4 deletions Src/FinderOuter/Services/MnemonicSevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ public string GetElectrumPath(ElectrumMnemonic.MnemonicType value)


public async void FindMissing(string mnemonic, char missChar, string pass, string extra, InputType extraType,
string path, uint index, bool hardened, MnemonicTypes mnType, BIP0039.WordLists wl,
string path, MnemonicTypes mnType, BIP0039.WordLists wl,
ElectrumMnemonic.MnemonicType elecMnType)
{
report.Init();
Expand All @@ -1501,8 +1501,6 @@ public string GetElectrumPath(ElectrumMnemonic.MnemonicType value)
report.Fail("Missing character is not accepted.");
else if (!TrySplitMnemonic(mnemonic, missChar))
return;
else if (index >= 0x80000000)
report.Fail("Key index is invalid.");
else
{
mnBytes = GetSeedByte(words.Length, maxWordLen);
Expand All @@ -1517,7 +1515,6 @@ public string GetElectrumPath(ElectrumMnemonic.MnemonicType value)
try
{
this.path = new BIP0032Path(path);
this.path.Add(hardened ? index + 0x80000000 : index);
}
catch (Exception ex)
{
Expand Down
36 changes: 6 additions & 30 deletions Src/FinderOuter/ViewModels/MissingMnemonicViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,25 +142,11 @@ public string KeyPath
set => this.RaiseAndSetIfChanged(ref _path, value);
}

private uint _ki = 0;
public uint KeyIndex
{
get => _ki;
set => this.RaiseAndSetIfChanged(ref _ki, value);
}

private bool _isHard = false;
public bool IsHardenedKey
{
get => _isHard;
set => this.RaiseAndSetIfChanged(ref _isHard, value);
}


public override void Find()
{
MnService.FindMissing(Mnemonic, MissingChar, PassPhrase, AdditionalInfo, SelectedInputType.Value,
KeyPath, KeyIndex, IsHardenedKey,
KeyPath,
SelectedMnemonicType, SelectedWordListType,
SelectedElectrumMnType);
}
Expand All @@ -180,9 +166,7 @@ public void Example()
MissingChar = '*';
AdditionalInfo = "1FCptKjDovTGKYz2vLGVtswGqwgp6JmfyN";
SelectedInputType = InputTypeList.First();
KeyPath = "m/44'/0'/0'/0/";
KeyIndex = 0;
IsHardenedKey = false;
KeyPath = "m/44'/0'/0'/0/0";

Result.Message = $"This is example 1 out of {total} taken from BIP-39 test vectors.{Environment.NewLine}" +
$"It is missing one word (grace) and it should take ~1 second to find it." +
Expand All @@ -200,9 +184,7 @@ public void Example()
MissingChar = '-';
AdditionalInfo = "bc1ql5swedpywx3kjq4grv9qmlngapdf6xumv7f2ew";
SelectedInputType = InputTypeList.First();
KeyPath = "m/84'/0'/0'/0";
KeyIndex = 4;
IsHardenedKey = false;
KeyPath = "m/84'/0'/0'/0/4";

Result.Message = $"This is example 2 out of {total} taken from BIP-39 test vectors.{Environment.NewLine}" +
$"It is missing two word (drill, cruise) and it should take ~1 hour to find them." +
Expand All @@ -223,9 +205,7 @@ public void Example()
MissingChar = '*';
AdditionalInfo = "L3YAaUUnQHMJLT63AntZBZ2Yda7rYeW784mfaaC48SpQJyqA2gTs";
SelectedInputType = InputTypeList.ElementAt(5);
KeyPath = "m/0/";
KeyIndex = 2;
IsHardenedKey = false;
KeyPath = "m/0/2";

Result.Message = $"This is example 3 out of {total} with a random mnemonic.{Environment.NewLine}" +
$"It is missing one word (lézard) and it should take ~1 second to find it." +
Expand All @@ -244,9 +224,7 @@ public void Example()
MissingChar = '*';
AdditionalInfo = "32tpfpxY5KG7Bdqf8m8cthoVcyALjvBk5z";
SelectedInputType = InputTypeList.ElementAt(3);
KeyPath = "m/0/";
KeyIndex = 2;
IsHardenedKey = false;
KeyPath = "m/0/2";

Result.Message = $"This is example 4 out of {total} with a random mnemonic.{Environment.NewLine}" +
$"It is missing one word (lézard) and it should take ~1 second to find it." +
Expand All @@ -265,9 +243,7 @@ public void Example()
MissingChar = '*';
AdditionalInfo = "L5fdNeFhX5Kgqnmbn6urPVt77eUocpbCF9f2ScEMu2HZwiFL3Viw";
SelectedInputType = InputTypeList.ElementAt(5);
KeyPath = "m/0'/";
KeyIndex = 0;
IsHardenedKey = true;
KeyPath = "m/0'/0'";

Result.Message = $"This is example 5 out of {total} with a random mnemonic.{Environment.NewLine}" +
$"It is missing 2 words (coast, slow) so it runs in parallel." +
Expand Down
15 changes: 4 additions & 11 deletions Src/FinderOuter/Views/MissingMnemonicView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,10 @@
</ComboBox.ItemTemplate>
</ComboBox>

<Grid ColumnDefinitions="*,*,auto" Grid.Column="0" Grid.Row="3">
<TextBox Text="{Binding KeyPath}"
Watermark="Complete path of the given key/address above"
Grid.Column="0"/>
<TextBox Text="{Binding KeyIndex}"
Watermark="Index of the given key/address above"
Grid.Column="1"/>
<CheckBox Content="Hardened key"
IsChecked="{Binding IsHardenedKey}"
Grid.Column="2"/>
</Grid>
<TextBox Text="{Binding KeyPath}"
Watermark="Complete path of the given key/address above"
Grid.Column="0"
Grid.Row="3"/>

</Grid>
</UserControl>

0 comments on commit b3e285d

Please sign in to comment.