Пример #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);
            }
        }
Пример #2
0
 public static void ThrowIfError(string responseString)
 {
     if (HwiParser.TryParseErrors(responseString, out HwiException error))
     {
         throw error;
     }
 }
Пример #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);
        }
Пример #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);
        }
Пример #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);
        }
Пример #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));
        }