예제 #1
0
 private async Task SendPinImplAsync(HardwareWalletModels?deviceType, string devicePath, HDFingerprint?fingerprint, int pin, CancellationToken cancel)
 {
     await SendCommandAsync(
         options : BuildOptions(deviceType, devicePath, fingerprint),
         command : HwiCommands.SendPin,
         commandArguments : pin.ToString(),
         openConsole : false,
         cancel).ConfigureAwait(false);
 }
예제 #2
0
        private async Task <ExtPubKey> GetXpubImplAsync(HardwareWalletModels?deviceType, string devicePath, HDFingerprint?fingerprint, KeyPath keyPath, CancellationToken cancel)
        {
            string keyPathString = keyPath.ToString(true, "h");
            var    response      = await SendCommandAsync(
                options : BuildOptions(deviceType, devicePath, fingerprint),
                command : HwiCommands.GetXpub,
                commandArguments : keyPathString,
                openConsole : false,
                cancel).ConfigureAwait(false);

            var extPubKey = HwiParser.ParseExtPubKey(response);

            return(extPubKey);
        }
예제 #3
0
        private async Task <BitcoinWitPubKeyAddress> DisplayAddressImplAsync(HardwareWalletModels?deviceType, string devicePath, HDFingerprint?fingerprint, KeyPath keyPath, CancellationToken cancel)
        {
            var response = await SendCommandAsync(
                options : BuildOptions(deviceType, devicePath, fingerprint),
                command : HwiCommands.DisplayAddress,
                commandArguments : $"--path {keyPath.ToString(true, "h")} --wpkh",
                openConsole : false,
                cancel).ConfigureAwait(false);

            var address = HwiParser.ParseAddress(response, Network) as BitcoinWitPubKeyAddress;

            address = address.TransformToNetworkNetwork(Network);

            return(address);
        }
예제 #4
0
        private static HwiOption[] BuildOptions(HardwareWalletModels?deviceType, string devicePath, HDFingerprint?fingerprint, params HwiOption[] extraOptions)
        {
            var options = new List <HwiOption>();

            var hasDevicePath  = devicePath != null;
            var hasDeviceType  = deviceType.HasValue;
            var hasFingerprint = fingerprint.HasValue;

            // Fingerprint and devicetype-devicepath pair cannot happen the same time.
            var notSupportedExceptionMessage = $"Provide either {nameof(fingerprint)} or {nameof(devicePath)}-{nameof(deviceType)} pair, not both.";

            if (hasDeviceType)
            {
                Guard.NotNull(nameof(devicePath), devicePath);
                if (hasFingerprint)
                {
                    throw new NotSupportedException(notSupportedExceptionMessage);
                }
            }
            if (hasFingerprint)
            {
                if (hasDevicePath || hasDeviceType)
                {
                    throw new NotSupportedException(notSupportedExceptionMessage);
                }
            }

            if (hasDevicePath)
            {
                options.Add(HwiOption.DevicePath(devicePath));
            }
            if (hasDeviceType)
            {
                options.Add(HwiOption.DeviceType(deviceType.Value));
            }
            if (hasFingerprint)
            {
                options.Add(HwiOption.Fingerprint(fingerprint.Value));
            }
            foreach (var opt in extraOptions)
            {
                options.Add(opt);
            }

            return(options.ToArray());
        }
예제 #5
0
        private async Task <PSBT> SignTxImplAsync(HardwareWalletModels?deviceType, string devicePath, HDFingerprint?fingerprint, PSBT psbt, CancellationToken cancel)
        {
            var psbtString = psbt.ToBase64();

            var response = await SendCommandAsync(
                options : BuildOptions(deviceType, devicePath, fingerprint),
                command : HwiCommands.SignTx,
                commandArguments : psbtString,
                openConsole : false,
                cancel).ConfigureAwait(false);

            PSBT signedPsbt = HwiParser.ParsePsbt(response, Network);

            if (!signedPsbt.IsAllFinalized())
            {
                signedPsbt.Finalize();
            }

            return(signedPsbt);
        }