Skip to content

Commit 19a5a09

Browse files
Produce a complete report when the mnemonic isn't missing any words
1 parent 20d227f commit 19a5a09

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

Src/FinderOuter/Services/MnemonicSevice.cs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Distributed under the MIT software license, see the accompanying
44
// file LICENCE or http://www.opensource.org/licenses/mit-license.php.
55

6+
using Autarkysoft.Bitcoin.Cryptography.Asymmetric.KeyPairs;
67
using Autarkysoft.Bitcoin.ImprovementProposals;
78
using FinderOuter.Backend.Cryptography.Asymmetric.EllipticCurve;
89
using FinderOuter.Backend.Cryptography.Hashing;
@@ -1413,20 +1414,49 @@ public async void FindMissing(string mnemonic, char missChar, string pass, strin
14131414
{
14141415
try
14151416
{
1416-
if (mnType == MnemonicTypes.BIP39)
1417+
BIP0032 temp = mnType switch
14171418
{
1418-
using BIP0039 temp = new(mnemonic, wl, pass);
1419+
MnemonicTypes.BIP39 => new BIP0039(mnemonic, wl, pass),
1420+
MnemonicTypes.Electrum => new(mnemonic, wl, pass),
1421+
_ => throw new ArgumentException("Undefined mnemonic type.")
1422+
};
1423+
1424+
report.Pass($"Given input is a valid {mnType} mnemonic.");
1425+
1426+
try
1427+
{
1428+
this.path = new BIP0032Path(path);
14191429
}
1420-
else if (mnType == MnemonicTypes.Electrum)
1430+
catch (Exception ex)
14211431
{
1422-
using ElectrumMnemonic temp = new(mnemonic, wl, pass);
1432+
report.Fail($"Invalid path ({ex.Message}).");
1433+
return;
14231434
}
14241435

1425-
report.Pass($"Given mnemonic is a valid {mnType}.");
1436+
if (!inputService.TryGetCompareService(extraType, extra, out comparer))
1437+
{
1438+
report.Fail($"Invalid extra input or input type {extraType}.");
1439+
return;
1440+
}
1441+
1442+
uint startIndex = this.path.Indexes[^1];
1443+
uint[] indices = new uint[this.path.Indexes.Length - 1];
1444+
Array.Copy(this.path.Indexes, 0, indices, 0, indices.Length);
1445+
var newPath = new BIP0032Path(indices);
1446+
1447+
PrivateKey[] keys = temp.GetPrivateKeys(newPath, 1, startIndex);
1448+
if (comparer.Compare(keys[0].ToBigInt()))
1449+
{
1450+
report.Pass($"The given child key is derived from this mnemonic at {this.path} path.");
1451+
}
1452+
else
1453+
{
1454+
report.Fail($"The given child key is not derived from this mnemonic or not at {this.path} path.");
1455+
}
14261456
}
14271457
catch (Exception ex)
14281458
{
1429-
report.Fail($"Mnemonic is not missing any characters but is invalid. Error: {ex.Message}.");
1459+
report.Fail($"Mnemonic is not missing any characters but is invalid. Error: {ex.Message}");
14301460
}
14311461

14321462
return;

0 commit comments

Comments
 (0)