Follow BitcoinAddressJsonConverter logic.
MODIFY
WalletWasabi/Helpers/NBitcoinHelpers.cs
WalletWasabi/Helpers/NBitcoinHelpers.cs
@@ -115,6 +115,30 @@ namespace WalletWasabi.Helpers
return ba;
}
+ public static Key BetterParseKey(string keyString)
+ {
+ keyString = Guard.NotNullOrEmptyOrWhitespace(nameof(keyString), keyString, trim: true);
+
+ Key k;
+ try
+ {
+ k = Key.Parse(keyString, Network.Main);
+ }
+ catch
+ {
+ try
+ {
+ k = Key.Parse(keyString, Network.TestNet);
+ }
+ catch
+ {
+ k = Key.Parse(keyString, Network.RegTest);
+ }
+ }
+
+ return k;
+ }
+
public static async Task<AddressManager> LoadAddressManagerFromPeerFileAsync(string filePath, Network expectedNetwork = null)
{
byte[] data, hash;

MODIFY
WalletWasabi/JsonConverters/KeyJsonConverter.cs
WalletWasabi/JsonConverters/KeyJsonConverter.cs
@@ -3,6 +3,7 @@ using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
+using WalletWasabi.Helpers;
namespace WalletWasabi.JsonConverters
{
@@ -17,19 +18,16 @@ namespace WalletWasabi.JsonConverters
/// <inheritdoc />
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
- var serializedKey = ((string)reader.Value).Trim();
- foreach (var network in Network.GetNetworks())
+ var keyString = reader.Value as string;
+ if (string.IsNullOrWhiteSpace(keyString))
{
- try
- {
- return Key.Parse(serializedKey, network);
+ return default;
}
- catch (FormatException)
+ else
{
+ return NBitcoinHelpers.BetterParseKey(keyString);
}
}
- return null;
- }
/// <inheritdoc />
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)

Follow BitcoinAddressJsonConverter logic.