[PoC] Send PSBT data through stdIn in HwiProcessBridge
MODIFY
WalletWasabi.Tests/UnitTests/Hwi/HwiProcessBridgeMock.cs
WalletWasabi.Tests/UnitTests/Hwi/HwiProcessBridgeMock.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -19,7 +20,7 @@ namespace WalletWasabi.Tests.UnitTests.Hwi
public HardwareWalletModels Model { get; }
- public Task<(string response, int exitCode)> SendCommandAsync(string arguments, bool openConsole, CancellationToken cancel)
+ public Task<(string response, int exitCode)> SendCommandAsync(string arguments, bool openConsole, CancellationToken cancel, Action<StreamWriter> standartInputWriter = null)
{
if (openConsole)
{

MODIFY
WalletWasabi/Hwi/HwiClient.cs
WalletWasabi/Hwi/HwiClient.cs
@@ -40,8 +40,15 @@ namespace WalletWasabi.Hwi
#region Commands
- private async Task<string> SendCommandAsync(IEnumerable<HwiOption> options, HwiCommands? command, string commandArguments, bool openConsole, CancellationToken cancel, bool isRecursion = false)
+ private async Task<string> SendCommandAsync(IEnumerable<HwiOption> options, HwiCommands? command, string commandArguments, bool openConsole, CancellationToken cancel, bool isRecursion = false, Action<StreamWriter> standartInputWriter = null)
{
+ if (standartInputWriter is { })
+ {
+ var optList = options.ToList();
+ optList.Add(HwiOption.StdIn);
+ options = optList;
+ }
+
string arguments = HwiParser.ToArgumentString(Network, options, command, commandArguments);
try
@@ -179,9 +186,19 @@ namespace WalletWasabi.Hwi
var response = await SendCommandAsync(
options: BuildOptions(deviceType, devicePath, fingerprint),
command: HwiCommands.SignTx,
- commandArguments: psbtString,
+ commandArguments: "",
openConsole: false,
- cancel).ConfigureAwait(false);
+ cancel,
+ standartInputWriter: (inputWriter) =>
+ {
+ if (!string.IsNullOrEmpty(psbtString))
+ {
+ inputWriter.WriteLine(psbtString);
+ inputWriter.WriteLine();
+ inputWriter.WriteLine();
+ inputWriter.Flush();
+ }
+ }).ConfigureAwait(false);
PSBT signedPsbt = HwiParser.ParsePsbt(response, Network);

MODIFY
WalletWasabi/Hwi/Models/HwiOption.cs
WalletWasabi/Hwi/Models/HwiOption.cs
@@ -22,6 +22,7 @@ namespace WalletWasabi.Hwi.Models
public static HwiOption TestNet => new HwiOption(HwiOptions.TestNet);
public static HwiOption Version => new HwiOption(HwiOptions.Version);
+ public static HwiOption StdIn => new HwiOption(HwiOptions.StdIn);
public HwiOptions Type { get; }
public string Arguments { get; }

MODIFY
WalletWasabi/Hwi/ProcessBridge/HwiProcessBridge.cs
WalletWasabi/Hwi/ProcessBridge/HwiProcessBridge.cs
@@ -19,9 +19,9 @@ namespace WalletWasabi.Hwi.ProcessBridge
{
}
- public new async Task<(string response, int exitCode)> SendCommandAsync(string arguments, bool openConsole, CancellationToken cancel)
+ public new async Task<(string response, int exitCode)> SendCommandAsync(string arguments, bool openConsole, CancellationToken cancel, Action<StreamWriter> standartInputWriter = null)
{
- var (responseString, exitCode) = await base.SendCommandAsync(arguments, openConsole, cancel).ConfigureAwait(false);
+ var (responseString, exitCode) = await base.SendCommandAsync(arguments, openConsole, cancel, standartInputWriter).ConfigureAwait(false);
string modifiedResponseString;

MODIFY
WalletWasabi/Microservices/IProcessBridge.cs
WalletWasabi/Microservices/IProcessBridge.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
+using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -9,7 +10,7 @@ namespace WalletWasabi.Microservices
{
public interface IProcessBridge
{
- Task<(string response, int exitCode)> SendCommandAsync(string arguments, bool openConsole, CancellationToken cancel);
+ Task<(string response, int exitCode)> SendCommandAsync(string arguments, bool openConsole, CancellationToken cancel, Action<StreamWriter> standartInputWriter = null);
Process Start(string arguments, bool openConsole);
}

MODIFY
WalletWasabi/Microservices/ProcessBridge.cs
WalletWasabi/Microservices/ProcessBridge.cs
@@ -77,11 +77,15 @@ namespace WalletWasabi.Microservices
}
}
- public async Task<(string response, int exitCode)> SendCommandAsync(string arguments, bool openConsole, CancellationToken cancel)
+ public async Task<(string response, int exitCode)> SendCommandAsync(string arguments, bool openConsole, CancellationToken cancel, Action<StreamWriter> standartInputWriter = null)
{
int exitCode;
using var process = Start(arguments, openConsole);
+ if (standartInputWriter is { })
+ {
+ standartInputWriter(process.StandardInput);
+ }
await process.WaitForExitAsync(cancel).ConfigureAwait(false);
exitCode = process.ExitCode;

[PoC] Send PSBT data through stdIn in HwiProcessBridge