|
3 | 3 | // Distributed under the MIT software license, see the accompanying
|
4 | 4 | // file LICENCE or http://www.opensource.org/licenses/mit-license.php.
|
5 | 5 |
|
| 6 | +using Autarkysoft.Bitcoin.Cryptography.Asymmetric.KeyPairs; |
6 | 7 | using Autarkysoft.Bitcoin.ImprovementProposals;
|
7 | 8 | using FinderOuter.Backend.Cryptography.Asymmetric.EllipticCurve;
|
8 | 9 | using FinderOuter.Backend.Cryptography.Hashing;
|
@@ -1413,20 +1414,49 @@ public async void FindMissing(string mnemonic, char missChar, string pass, strin
|
1413 | 1414 | {
|
1414 | 1415 | try
|
1415 | 1416 | {
|
1416 |
| - if (mnType == MnemonicTypes.BIP39) |
| 1417 | + BIP0032 temp = mnType switch |
1417 | 1418 | {
|
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); |
1419 | 1429 | }
|
1420 |
| - else if (mnType == MnemonicTypes.Electrum) |
| 1430 | + catch (Exception ex) |
1421 | 1431 | {
|
1422 |
| - using ElectrumMnemonic temp = new(mnemonic, wl, pass); |
| 1432 | + report.Fail($"Invalid path ({ex.Message})."); |
| 1433 | + return; |
1423 | 1434 | }
|
1424 | 1435 |
|
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 | + } |
1426 | 1456 | }
|
1427 | 1457 | catch (Exception ex)
|
1428 | 1458 | {
|
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}"); |
1430 | 1460 | }
|
1431 | 1461 |
|
1432 | 1462 | return;
|
|
0 commit comments