public async Task DisplayAddressAsync(ScriptPubKeyType addressType, KeyPath keyPath, CancellationToken cancellationToken = default) { if (keyPath == null) { throw new ArgumentNullException(nameof(keyPath)); } List <string> commandArguments = new List <string>(); commandArguments.Add("--path"); commandArguments.Add(keyPath.ToString(true, "h")); switch (addressType) { case ScriptPubKeyType.Segwit: commandArguments.Add("--wpkh"); break; case ScriptPubKeyType.SegwitP2SH: commandArguments.Add("--sh_wpkh"); break; } var response = await SendCommandAsync( command : HwiCommands.DisplayAddress, commandArguments : commandArguments.ToArray(), cancellationToken).ConfigureAwait(false); if (!HwiClient.IgnoreInvalidNetwork) { HwiParser.ParseAddress(response, HwiClient.Network); } }
public static void ThrowIfError(string responseString) { if (HwiParser.TryParseErrors(responseString, out HwiException error)) { throw error; } }
public async Task <Version> GetVersionAsync(CancellationToken cancellationToken = default) { string responseString = await SendCommandCoreAsync( options : new[] { HwiOption.Version }, cancellationToken : cancellationToken).ConfigureAwait(false); var version = HwiParser.ParseVersion(responseString); return(version); }
public async Task <IEnumerable <HwiEnumerateEntry> > EnumerateEntriesAsync(CancellationToken cancellationToken = default) { string responseString = await SendCommandCoreAsync( command : HwiCommands.Enumerate, cancellationToken : cancellationToken).ConfigureAwait(false); IEnumerable <HwiEnumerateEntry> response = HwiParser.ParseHwiEnumerateResponse(responseString); return(response); }
private async Task <string> SendCommandCoreAsync(DeviceSelector deviceSelector = null, IEnumerable <HwiOption> options = null, HwiCommands?command = null, string[] commandArguments = null, CancellationToken cancellationToken = default) { var arguments = HwiParser.ToArgumentString(deviceSelector, Network, options, command, commandArguments); var response = await Transport.SendCommandAsync(arguments, cancellationToken).ConfigureAwait(false); ThrowIfError(response); return(response); }
public async Task <PSBT> SignPSBTAsync(PSBT psbt, CancellationToken cancellationToken = default) { if (psbt == null) { throw new ArgumentNullException(nameof(psbt)); } var psbtString = psbt.ToBase64(); var response = await SendCommandAsync( command : HwiCommands.SignTx, commandArguments : new string[] { psbtString }, cancellationToken : cancellationToken).ConfigureAwait(false); return(HwiParser.ParsePsbt(response, HwiClient.Network)); }