Can use fingerprint for commands
MODIFY
WalletWasabi/Hwi2/HwiClient.cs
WalletWasabi/Hwi2/HwiClient.cs
@@ -72,29 +72,47 @@ namespace WalletWasabi.Hwi2
}
}
- public async Task PromptPinAsync(HardwareWalletVendors deviceType, string devicePath, CancellationToken cancel)
+ public async Task PromptPinAsync(HardwareWalletVendors? deviceType, string devicePath, CancellationToken cancel)
+ => await PromptPinImplAsync(deviceType, devicePath, null, cancel);
+
+ public async Task PromptPinAsync(HDFingerprint? fingerprint, CancellationToken cancel)
+ => await PromptPinImplAsync(null, null, fingerprint, cancel);
+
+ private async Task PromptPinImplAsync(HardwareWalletVendors? deviceType, string devicePath, HDFingerprint? fingerprint, CancellationToken cancel)
{
await SendCommandAsync(
- options: new[] { HwiOption.DevicePath(devicePath), HwiOption.DeviceType(deviceType) },
+ options: BuildOptions(deviceType, devicePath, fingerprint),
command: HwiCommands.PromptPin,
commandArguments: null,
cancel).ConfigureAwait(false);
}
- public async Task SendPinAsync(HardwareWalletVendors deviceType, string devicePath, int pin, CancellationToken cancel)
+ public async Task SendPinAsync(HardwareWalletVendors? deviceType, string devicePath, int pin, CancellationToken cancel)
+ => await SendPinImplAsync(deviceType, devicePath, null, pin, cancel);
+
+ public async Task SendPinAsync(HDFingerprint? fingerprint, int pin, CancellationToken cancel)
+ => await SendPinImplAsync(null, null, fingerprint, pin, cancel);
+
+ private async Task SendPinImplAsync(HardwareWalletVendors? deviceType, string devicePath, HDFingerprint? fingerprint, int pin, CancellationToken cancel)
{
await SendCommandAsync(
- options: new[] { HwiOption.DevicePath(devicePath), HwiOption.DeviceType(deviceType) },
+ options: BuildOptions(deviceType, devicePath, fingerprint),
command: HwiCommands.SendPin,
commandArguments: pin.ToString(),
cancel).ConfigureAwait(false);
}
- public async Task<ExtPubKey> GetXpubAsync(HardwareWalletVendors deviceType, string devicePath, KeyPath keyPath, CancellationToken cancel)
+ public async Task<ExtPubKey> GetXpubAsync(HardwareWalletVendors? deviceType, string devicePath, KeyPath keyPath, CancellationToken cancel)
+ => await GetXpubImplAsync(deviceType, devicePath, null, keyPath, cancel);
+
+ public async Task<ExtPubKey> GetXpubAsync(HDFingerprint? fingerprint, KeyPath keyPath, CancellationToken cancel)
+ => await GetXpubImplAsync(null, null, fingerprint, keyPath, cancel);
+
+ private async Task<ExtPubKey> GetXpubImplAsync(HardwareWalletVendors? deviceType, string devicePath, HDFingerprint? fingerprint, KeyPath keyPath, CancellationToken cancel)
{
string keyPathString = keyPath.ToString(true, "h");
var response = await SendCommandAsync(
- options: new[] { HwiOption.DevicePath(devicePath), HwiOption.DeviceType(deviceType) },
+ options: BuildOptions(deviceType, devicePath, fingerprint),
command: HwiCommands.GetXpub,
commandArguments: keyPathString,
cancel).ConfigureAwait(false);
@@ -104,7 +122,7 @@ namespace WalletWasabi.Hwi2
return extPubKey;
}
- public async Task<BitcoinWitPubKeyAddress> DisplayAddressAsync(HardwareWalletVendors deviceType, string devicePath, KeyPath keyPath, CancellationToken cancel)
+ public async Task<BitcoinWitPubKeyAddress> DisplayAddressAsync(HardwareWalletVendors? deviceType, string devicePath, KeyPath keyPath, CancellationToken cancel)
=> await DisplayAddressImplAsync(deviceType, devicePath, null, keyPath, cancel);
public async Task<BitcoinWitPubKeyAddress> DisplayAddressAsync(HDFingerprint fingerprint, KeyPath keyPath, CancellationToken cancel)
@@ -112,22 +130,8 @@ namespace WalletWasabi.Hwi2
private async Task<BitcoinWitPubKeyAddress> DisplayAddressImplAsync(HardwareWalletVendors? deviceType, string devicePath, HDFingerprint? fingerprint, KeyPath keyPath, CancellationToken cancel)
{
- var options = new List<HwiOption>();
- if (devicePath != null)
- {
- options.Add(HwiOption.DevicePath(devicePath));
- }
- if (deviceType.HasValue)
- {
- options.Add(HwiOption.DeviceType(deviceType.Value));
- }
- if (fingerprint.HasValue)
- {
- options.Add(HwiOption.Fingerprint(fingerprint.Value));
- }
-
var response = await SendCommandAsync(
- options: options.ToArray(),
+ options: BuildOptions(deviceType, devicePath, fingerprint),
command: HwiCommands.DisplayAddress,
commandArguments: $"--path {keyPath.ToString(true, "h")} --wpkh",
cancel).ConfigureAwait(false);
@@ -139,12 +143,18 @@ namespace WalletWasabi.Hwi2
return address as BitcoinWitPubKeyAddress;
}
- public async Task<PSBT> SignTxAsync(HardwareWalletVendors deviceType, string devicePath, PSBT psbt, CancellationToken cancel)
+ public async Task<PSBT> SignTxAsync(HardwareWalletVendors? deviceType, string devicePath, PSBT psbt, CancellationToken cancel)
+ => await SignTxImplAsync(deviceType, devicePath, null, psbt, cancel);
+
+ public async Task<PSBT> SignTxAsync(HDFingerprint? fingerprint, PSBT psbt, CancellationToken cancel)
+ => await SignTxImplAsync(null, null, fingerprint, psbt, cancel);
+
+ private async Task<PSBT> SignTxImplAsync(HardwareWalletVendors? deviceType, string devicePath, HDFingerprint? fingerprint, PSBT psbt, CancellationToken cancel)
{
var psbtString = psbt.ToBase64();
var response = await SendCommandAsync(
- options: new[] { HwiOption.DevicePath(devicePath), HwiOption.DeviceType(deviceType) },
+ options: BuildOptions(deviceType, devicePath, fingerprint),
command: HwiCommands.SignTx,
commandArguments: psbtString,
cancel).ConfigureAwait(false);
@@ -159,34 +169,58 @@ namespace WalletWasabi.Hwi2
return signedPsbt;
}
- public async Task WipeAsync(HardwareWalletVendors deviceType, string devicePath, CancellationToken cancel)
+ public async Task WipeAsync(HardwareWalletVendors? deviceType, string devicePath, CancellationToken cancel)
+ => await WipeImplAsync(deviceType, devicePath, null, cancel);
+
+ public async Task WipeAsync(HDFingerprint? fingerprint, CancellationToken cancel)
+ => await WipeImplAsync(null, null, fingerprint, cancel);
+
+ private async Task WipeImplAsync(HardwareWalletVendors? deviceType, string devicePath, HDFingerprint? fingerprint, CancellationToken cancel)
{
await SendCommandAsync(
- options: new[] { HwiOption.DevicePath(devicePath), HwiOption.DeviceType(deviceType) },
+ options: BuildOptions(deviceType, devicePath, fingerprint),
command: HwiCommands.Wipe,
commandArguments: null,
cancel).ConfigureAwait(false);
}
- public async Task SetupAsync(HardwareWalletVendors deviceType, string devicePath, CancellationToken cancel)
+ public async Task SetupAsync(HardwareWalletVendors? deviceType, string devicePath, CancellationToken cancel)
+ => await SetupImplAsync(deviceType, devicePath, null, cancel);
+
+ public async Task SetupAsync(HDFingerprint? fingerprint, CancellationToken cancel)
+ => await SetupImplAsync(null, null, fingerprint, cancel);
+
+ private async Task SetupImplAsync(HardwareWalletVendors? deviceType, string devicePath, HDFingerprint? fingerprint, CancellationToken cancel)
{
await SendCommandAsync(
- options: new[] { HwiOption.DevicePath(devicePath), HwiOption.DeviceType(deviceType), HwiOption.Interactive },
+ options: BuildOptions(deviceType, devicePath, fingerprint, HwiOption.Interactive),
command: HwiCommands.Setup,
commandArguments: null,
cancel).ConfigureAwait(false);
}
- public async Task RestoreAsync(HardwareWalletVendors deviceType, string devicePath, CancellationToken cancel)
+ public async Task RestoreAsync(HardwareWalletVendors? deviceType, string devicePath, CancellationToken cancel)
+ => await RestoreImplAsync(deviceType, devicePath, null, cancel);
+
+ public async Task RestoreAsync(HDFingerprint? fingerprint, CancellationToken cancel)
+ => await RestoreImplAsync(null, null, fingerprint, cancel);
+
+ private async Task RestoreImplAsync(HardwareWalletVendors? deviceType, string devicePath, HDFingerprint? fingerprint, CancellationToken cancel)
{
await SendCommandAsync(
- options: new[] { HwiOption.DevicePath(devicePath), HwiOption.DeviceType(deviceType), HwiOption.Interactive },
+ options: BuildOptions(deviceType, devicePath, fingerprint, HwiOption.Interactive),
command: HwiCommands.Restore,
commandArguments: null,
cancel).ConfigureAwait(false);
}
- public async Task BackupAsync(HardwareWalletVendors deviceType, string devicePath, CancellationToken cancel)
+ public async Task BackupAsync(HardwareWalletVendors? deviceType, string devicePath, CancellationToken cancel)
+ => await BackupImplAsync(deviceType, devicePath, null, cancel);
+
+ public async Task BackupAsync(HDFingerprint? fingerprint, CancellationToken cancel)
+ => await BackupImplAsync(null, null, fingerprint, cancel);
+
+ private async Task BackupImplAsync(HardwareWalletVendors? deviceType, string devicePath, HDFingerprint? fingerprint, CancellationToken cancel)
{
if (deviceType == HardwareWalletVendors.Trezor)
{
@@ -195,7 +229,7 @@ namespace WalletWasabi.Hwi2
}
await SendCommandAsync(
- options: new[] { HwiOption.DevicePath(devicePath), HwiOption.DeviceType(deviceType), HwiOption.Interactive },
+ options: BuildOptions(deviceType, devicePath, fingerprint, HwiOption.Interactive),
command: HwiCommands.Backup,
commandArguments: null,
cancel).ConfigureAwait(false);
@@ -242,6 +276,29 @@ namespace WalletWasabi.Hwi2
}
}
+ private static HwiOption[] BuildOptions(HardwareWalletVendors? deviceType, string devicePath, HDFingerprint? fingerprint, params HwiOption[] extraOptions)
+ {
+ var options = new List<HwiOption>();
+ if (devicePath != null)
+ {
+ options.Add(HwiOption.DevicePath(devicePath));
+ }
+ if (deviceType.HasValue)
+ {
+ options.Add(HwiOption.DeviceType(deviceType.Value));
+ }
+ if (fingerprint.HasValue)
+ {
+ options.Add(HwiOption.Fingerprint(fingerprint.Value));
+ }
+ foreach (var opt in extraOptions)
+ {
+ options.Add(opt);
+ }
+
+ return options.ToArray();
+ }
+
#endregion Helpers
}
}

Can use fingerprint for commands