Fix trezor passphrase?
MODIFY
WalletWasabi/Hwi/HwiClient.cs
WalletWasabi/Hwi/HwiClient.cs
@@ -41,7 +41,7 @@ namespace WalletWasabi.Hwi
#region Commands
- private async Task<string> SendCommandAsync(IEnumerable<HwiOption> options, HwiCommands? command, string commandArguments, bool openConsole, CancellationToken cancel)
+ private async Task<string> SendCommandAsync(IEnumerable<HwiOption> options, HwiCommands? command, string commandArguments, bool openConsole, CancellationToken cancel, bool isRecursion = false)
{
string arguments = HwiParser.ToArgumentString(Network, options, command, commandArguments);
@@ -63,6 +63,28 @@ namespace WalletWasabi.Hwi
{
throw new OperationCanceledException($"'hwi {arguments}' operation is canceled.", ex);
}
+ catch (HwiException ex) when (ex.ErrorCode == HwiErrorCode.DeviceConnError)
+ {
+ // Probably didn't find device with specified fingerprint.
+ // Enumerate and call again, but not forever.
+ if (isRecursion || !options.Any(x => x.Type == HwiOptions.Fingerprint))
+ {
+ throw;
+ }
+
+ IEnumerable<HwiEnumerateEntry> hwiEntries = await EnumerateAsync(cancel, isRecursion: true);
+
+ // Trezor T will say passphrase is needed, but don't have to provide it from the software itself.
+ HwiEnumerateEntry firstEntry = hwiEntries.Where(x => x.NeedsPassphraseSent is true).FirstOrDefault();
+ if (firstEntry is null)
+ {
+ throw;
+ }
+
+ // Build options without fingerprint with device model and device path.
+ var newOptions = BuildOptions(firstEntry.Model, firstEntry.Path, fingerprint: null, options.Where(x => x.Type != HwiOptions.Fingerprint).ToArray());
+ return await SendCommandAsync(newOptions, command, arguments, openConsole, cancel, isRecursion: true);
+ }
}
public async Task PromptPinAsync(HardwareWalletModels deviceType, string devicePath, CancellationToken cancel)
@@ -222,14 +244,15 @@ namespace WalletWasabi.Hwi
return responseString;
}
- public async Task<IEnumerable<HwiEnumerateEntry>> EnumerateAsync(CancellationToken cancel)
+ public async Task<IEnumerable<HwiEnumerateEntry>> EnumerateAsync(CancellationToken cancel, bool isRecursion = false)
{
string responseString = await SendCommandAsync(
options: null,
command: HwiCommands.Enumerate,
commandArguments: null,
openConsole: false,
- cancel).ConfigureAwait(false);
+ cancel,
+ isRecursion).ConfigureAwait(false);
IEnumerable<HwiEnumerateEntry> response = HwiParser.ParseHwiEnumerateResponse(responseString);
return response;

MODIFY
WalletWasabi/Hwi/Parsers/HwiParser.cs
WalletWasabi/Hwi/Parsers/HwiParser.cs
@@ -181,9 +181,17 @@ namespace WalletWasabi.Hwi.Parsers
if (JsonHelpers.TryParseJToken(json, out JToken token))
{
var addressString = token["address"]?.ToString()?.Trim() ?? null;
+ try
+ {
var address = BitcoinAddress.Create(addressString, network);
return address;
}
+ catch (FormatException)
+ {
+ BitcoinAddress.Create(addressString, network == Network.Main ? Network.TestNet : Network.Main);
+ throw new FormatException("Wrong network.");
+ }
+ }
else
{
throw new FormatException($"Could not parse address: {json}.");

Fix trezor passphrase?