Resolve most changes
MODIFY
WalletWasabi/Blockchain/Keys/KeyManager.cs
WalletWasabi/Blockchain/Keys/KeyManager.cs
@@ -235,8 +235,12 @@ public class KeyManager
string jsonString = safeIoManager.ReadAllText(Encoding.UTF8);
var km = JsonConvert.DeserializeObject<KeyManager>(jsonString);
+ if (km is null)
+ {
+ throw new FormatException($"Wallet file at: `{filePath}` is not a valid wallet file or it is corrupted.");
+ }
- km!.SetFilePath(filePath);
+ km.SetFilePath(filePath);
lock (km.HdPubKeyScriptBytesLock)
{
km.HdPubKeyScriptBytes.AddRange(km.GetKeys(x => true).Select(x => x.P2wpkhScript.ToCompressedBytes()));

MODIFY
WalletWasabi/Extensions/NBitcoinExtensions.cs
WalletWasabi/Extensions/NBitcoinExtensions.cs
@@ -353,9 +353,9 @@ public static class NBitcoinExtensions
public static ScriptPubKeyType? GetInputScriptPubKeyType(this PSBTInput i)
{
- if (i.WitnessUtxo is not { })
+ if (i.WitnessUtxo is null)
{
- return null;
+ throw new ArgumentNullException($"{nameof(i.WitnessUtxo)} was null, can't get it's ScriptPubKey type.");
}
if (i.WitnessUtxo.ScriptPubKey.IsScriptType(ScriptType.P2WPKH))

MODIFY
WalletWasabi/Helpers/ImportWalletHelper.cs
WalletWasabi/Helpers/ImportWalletHelper.cs
@@ -53,8 +53,16 @@ public static class ImportWalletHelper
private static KeyManager GetKeyManagerByColdcardJson(WalletManager manager, JObject jsonWallet, string walletFullPath)
{
var xpubString = jsonWallet["ExtPubKey"]!.ToString();
- var mfpString = jsonWallet["MasterFingerprint"]!.ToString();
+ if (xpubString is null)
+ {
+ throw new ArgumentNullException($"Can't get KeyManager, ExtPubKey was null.");
+ }
+ var mfpString = jsonWallet["MasterFingerprint"]!.ToString();
+ if (mfpString is null)
+ {
+ throw new ArgumentNullException($"Can't get KeyManager, MasterFingerprint was null.");
+ }
// https://github.com/zkSNACKs/WalletWasabi/pull/1663#issuecomment-508073066
// Coldcard 2.1.0 improperly implemented Wasabi skeleton fingerprint at first, so we must reverse byte order.
// The solution was to add a ColdCardFirmwareVersion json field from 2.1.1 and correct the one generated by 2.1.0.

Resolve most changes