Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
 public static void ThrowIfError(string responseString)
 {
     if (HwiParser.TryParseErrors(responseString, out HwiException error))
     {
         throw error;
     }
 }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        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));
        }