Remove ExtPubKey loader from KeyManager
MODIFY
WalletWasabi.Gui/Tabs/WalletManager/HardwareWallets/ConnectHardwareWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/HardwareWallets/ConnectHardwareWalletViewModel.cs
@@ -318,11 +318,9 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.HardwareWallets
MainWindowViewModel.Instance.StatusBar.TryRemoveStatus(StatusType.AcquiringXpubFromHardwareWallet);
}
- if (TryFindWalletByExtPubKey(extPubKey, out string wn))
- {
- walletName = wn.TrimEnd(".json", StringComparison.OrdinalIgnoreCase);
- }
- else
+ walletName = WalletManager.GetWallets(true).FirstOrDefault(w => w.KeyManager.ExtPubKey == extPubKey)?.WalletName;
+
+ if (walletName is null)
{
var prefix = selectedWallet.HardwareWalletInfo?.Model.FriendlyName() ?? HardwareWalletModels.Unknown.FriendlyName();
walletName = WalletManager.WalletDirectories.GetNextWalletName(prefix);
@@ -425,15 +423,5 @@ namespace WalletWasabi.Gui.Tabs.WalletManager.HardwareWallets
IsHwWalletSearchTextVisible = false;
}
}
-
- private bool TryFindWalletByExtPubKey(ExtPubKey extPubKey, out string walletName)
- {
- walletName = WalletManager.WalletDirectories
- .EnumerateWalletFiles(includeBackupDir: false)
- .FirstOrDefault(fi => KeyManager.TryGetExtPubKeyFromFile(fi.FullName, out ExtPubKey epk) && epk == extPubKey)
- ?.Name;
-
- return walletName is { };
- }
}
}

MODIFY
WalletWasabi/Blockchain/Keys/KeyManager.cs
WalletWasabi/Blockchain/Keys/KeyManager.cs
@@ -239,79 +239,6 @@ namespace WalletWasabi.Blockchain.Keys
return true;
}
- public static bool TryGetExtPubKeyFromFile(string filePath, out ExtPubKey extPubKey)
- {
- extPubKey = default;
- filePath = Guard.NotNullOrEmptyOrWhitespace(nameof(filePath), filePath);
-
- if (!File.Exists(filePath))
- {
- throw new FileNotFoundException($"Wallet file not found at: `{filePath}`.");
- }
-
- // Example text to handle: "ExtPubKey": "03BF8271268000000013B9013C881FE456DDF524764F6322F611B03CF6".
- var extPubKeyLine = File.ReadLines(filePath) // Enumerated read.
- .Take(21) // Limit reads to x lines.
- .FirstOrDefault(line => line.Contains("\"ExtPubKey\": \"", StringComparison.OrdinalIgnoreCase));
-
- if (string.IsNullOrEmpty(extPubKeyLine))
- {
- return false;
- }
-
- var parts = extPubKeyLine.Split("\"ExtPubKey\": \"");
- if (parts.Length != 2)
- {
- throw new FormatException($"Could not split line: {extPubKeyLine}");
- }
-
- var xpub = parts[1].TrimEnd(',', '"');
- if (string.IsNullOrEmpty(xpub) || xpub.Equals("null", StringComparison.OrdinalIgnoreCase))
- {
- return false;
- }
-
- extPubKey = NBitcoinHelpers.BetterParseExtPubKey(xpub);
- return true;
- }
-
- public static bool TryGetMasterFingerprintFromFile(string filePath, out HDFingerprint masterFingerprint)
- {
- masterFingerprint = default;
- filePath = Guard.NotNullOrEmptyOrWhitespace(nameof(filePath), filePath);
-
- if (!File.Exists(filePath))
- {
- throw new FileNotFoundException($"Wallet file not found at: `{filePath}`.");
- }
-
- // Example text to handle: "ExtPubKey": "03BF8271268000000013B9013C881FE456DDF524764F6322F611B03CF6".
- var masterFpLine = File.ReadLines(filePath) // Enumerated read.
- .Take(21) // Limit reads to x lines.
- .FirstOrDefault(line => line.Contains("\"MasterFingerprint\": \"", StringComparison.OrdinalIgnoreCase));
-
- if (string.IsNullOrEmpty(masterFpLine))
- {
- return false;
- }
-
- var parts = masterFpLine.Split("\"MasterFingerprint\": \"");
- if (parts.Length != 2)
- {
- throw new FormatException($"Could not split line: {masterFpLine}");
- }
-
- var hex = parts[1].TrimEnd(',', '"');
- if (string.IsNullOrEmpty(hex) || hex.Equals("null", StringComparison.OrdinalIgnoreCase))
- {
- return false;
- }
-
- var mfp = new HDFingerprint(ByteHelpers.FromHex(hex));
- masterFingerprint = mfp;
- return true;
- }
-
public void SetFilePath(string filePath)
{
FilePath = string.IsNullOrWhiteSpace(filePath) ? null : filePath;

Remove ExtPubKey loader from KeyManager