Add Trezor BIP44 fallback
MODIFY
WalletWasabi/Hwi/HwiClient.cs
WalletWasabi/Hwi/HwiClient.cs
@@ -48,13 +48,7 @@ namespace WalletWasabi.Hwi
{
(string responseString, int exitCode) = await Bridge.SendCommandAsync(arguments, openConsole, cancel).ConfigureAwait(false);
- if (exitCode != 0)
- {
- ThrowIfError(responseString, options);
- throw new HwiException(HwiErrorCode.UnknownError, $"'hwi {arguments}' exited with incorrect exit code: {exitCode}.");
- }
-
- ThrowIfError(responseString, options);
+ ThrowIfError(options, arguments, responseString, exitCode);
return responseString;
}
@@ -85,6 +79,16 @@ namespace WalletWasabi.Hwi
var newOptions = BuildOptions(firstNoFingerprintEntry.Model, firstNoFingerprintEntry.Path, fingerprint: null, options.Where(x => x.Type != HwiOptions.Fingerprint).ToArray());
return await SendCommandAsync(newOptions, command, arguments, openConsole, cancel, isRecursion: true);
}
+ catch (HwiException ex) when (Network != Network.Main && ex.ErrorCode == HwiErrorCode.UnknownError && ex.Message?.Contains("DataError: Forbidden key path") is true)
+ {
+ // Trezor only accepts KeyPath 84'/1' on TestNet from v2.3.1. We fake that we are on MainNet to ensure compatibility.
+ string fixedArguments = HwiParser.ToArgumentString(Network.Main, options, command, commandArguments);
+ (string responseString, int exitCode) = await Bridge.SendCommandAsync(fixedArguments, openConsole, cancel).ConfigureAwait(false);
+
+ ThrowIfError(options, fixedArguments, responseString, exitCode);
+
+ return responseString;
+ }
}
public async Task PromptPinAsync(HardwareWalletModels deviceType, string devicePath, CancellationToken cancel)
@@ -262,12 +266,21 @@ namespace WalletWasabi.Hwi
#region Helpers
- private static void ThrowIfError(string responseString, IEnumerable<HwiOption> options)
+ private static void ThrowIfError(IEnumerable<HwiOption> options, string arguments, string responseString, int exitCode)
+ {
+ if (exitCode != 0)
{
if (HwiParser.TryParseErrors(responseString, options, out HwiException error))
{
throw error;
}
+ throw new HwiException(HwiErrorCode.UnknownError, $"'hwi {arguments}' exited with incorrect exit code: {exitCode}.");
+ }
+
+ if (HwiParser.TryParseErrors(responseString, options, out HwiException error2))
+ {
+ throw error2;
+ }
}
private static HwiOption[] BuildOptions(HardwareWalletModels? deviceType, string devicePath, HDFingerprint? fingerprint, params HwiOption[] extraOptions)

MODIFY
WalletWasabi/Hwi/Parsers/HwiParser.cs
WalletWasabi/Hwi/Parsers/HwiParser.cs
@@ -290,7 +290,7 @@ namespace WalletWasabi.Hwi.Parsers
{
int startIndex = hwiResponse.IndexOf(substringFrom) + substringFrom.Length;
int endIndex = hwiResponse.IndexOf("-");
- var versionString = hwiResponse.Substring(startIndex, endIndex - startIndex).Trim();
+ var versionString = hwiResponse[startIndex..endIndex].Trim();
version = null;
if (Version.TryParse(versionString, out Version v))
{

Add Trezor BIP44 fallback