예제 #1
0
        /// <summary>
        /// Note assumes we are looking for non segwit legacy addresses
        /// </summary>
        private static Task <string> GetAddressAsync(uint coinNumber, bool isChange, uint index, bool display, bool isPublicKey = false, bool isLegacy = true)
        {
            var coinInfo    = KeepKeyManager.CoinUtility.GetCoinInfo(coinNumber);
            var addressPath = new BIP44AddressPath(!isLegacy && coinInfo.IsSegwit, coinNumber, 0, isChange, index);

            return(KeepKeyManager.GetAddressAsync(addressPath, isPublicKey, display));
        }
예제 #2
0
        static Task <string> GetAddressAsync(uint coinNumber, bool isChange, uint index, bool display, bool isPublicKey = false, bool isLegacy = true)
        {
            var coinInfo    = _soterDevice.CoinUtility.GetCoinInfo(coinNumber);
            var addressPath = new BIP44AddressPath(!isLegacy && coinInfo.IsSegwit, coinNumber, 0, isChange, index);

            return(_soterDevice.GetAddressAsync((IAddressPath)addressPath, isPublicKey, display));
        }
예제 #3
0
        private async Task <string> GetAddressAsync(bool isSegwit, uint coinNumber, bool isChange, uint index, bool display, string coinName = null, bool isPublicKey = false)
        {
            var addressPath  = new BIP44AddressPath(isSegwit, coinNumber, 0, isChange, index);
            var firstAddress = await TrezorManager.GetAddressAsync(addressPath, isPublicKey, display);

            var addressPathString = $"m/{(isSegwit ? 49 : 44)}'/{coinNumber}'/{(isChange ? 1 : 0)}'/{0}/{index}";
            var secondAddress     = await GetAddressAsync(addressPathString);

            Assert.IsTrue(firstAddress == secondAddress, "The parsed version of the address path yielded a different result to the non-parsed version");

            return(secondAddress);
        }
예제 #4
0
        /// <summary>
        /// TODO: This should be made in to a unit test but it's annoying to add the UI for a unit test as the KeepKey requires human intervention for the pin
        /// </summary>
        /// <returns></returns>
        private static async Task Go()
        {
            try
            {
                using (var keepKeyHid = await Connect())
                {
                    using (var keepKeyManager = new KeepKeyManager(GetPin, keepKeyHid))
                    {
                        await keepKeyManager.InitializeAsync();

                        var cointTable = await keepKeyManager.GetCoinTable();

                        keepKeyManager.CoinUtility = new KeepKeyCoinUtility(cointTable);

                        var tasks = new List <Task>();

                        for (uint i = 0; i < 50; i++)
                        {
                            tasks.Add(DoGetAddress(keepKeyManager, i));
                        }

                        await Task.WhenAll(tasks);

                        for (uint i = 0; i < 50; i++)
                        {
                            var address = await GetAddress(keepKeyManager, i);

                            Console.WriteLine($"Index: {i} (No change) - Address: {address}");

                            if (address != _Addresses[i])
                            {
                                throw new Exception("The ordering got messed up");
                            }
                        }

                        var addressPath = new BIP44AddressPath(false, 60, 0, false, 0);

                        var ethAddress = await keepKeyManager.GetAddressAsync(addressPath, false, false);

                        Console.WriteLine($"First ETH address: {ethAddress}");

                        Console.WriteLine("All good");

                        Console.ReadLine();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
            }
        }
예제 #5
0
        /// <summary>
        /// TODO: This should be made in to a unit test but it's annoying to add the UI for a unit test as the Trezor requires human intervention for the pin
        /// </summary>
        /// <returns></returns>
        private static async Task Go()
        {
            try
            {
                using (var trezorManager = await ConnectAsync())
                {
                    Console.WriteLine("Trezor connection recognized");

                    var tasks = new List <Task>();

                    for (uint i = 0; i < 50; i++)
                    {
                        tasks.Add(DoGetAddress(trezorManager, i));
                    }

                    await Task.WhenAll(tasks);

                    for (uint i = 0; i < 50; i++)
                    {
                        var address = await GetAddress(trezorManager, i);

                        Console.WriteLine($"Index: {i} (No change) - Address: {address}");

                        if (address != _Addresses[i])
                        {
                            throw new Exception("The ordering got messed up");
                        }
                    }

                    var addressPath = new BIP44AddressPath(false, 60, 0, false, 0);

                    var ethAddress = await trezorManager.GetAddressAsync(addressPath, false, false);

                    Console.WriteLine($"First ETH address: {ethAddress}");

                    Console.WriteLine("All good");

                    while (true)
                    {
                        Console.WriteLine($"Count of connected Trezors: {_TrezorManagerBroker.TrezorManagers.Count}");
                        await Task.Delay(5000);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
            }
        }
예제 #6
0
        public static async Task LoadCoinTableFromDeviceAsync(ISoterDevice device)
        {
            using (var db = new DatabaseContext())
            {
                db.Database.EnsureCreated();
                db.Transactions.Clear();
                db.Addresses.Clear();
                db.Coins.Clear();
                var coinTable = await device.GetCoinTableAsync(48);

                device.CoinUtility = new CoinUtility(coinTable);
                foreach (var coinType in coinTable)
                {
                    if (SupportedCoins.Any(c => c.Equals(coinType.CoinShortcut)))
                    {
                        db.Coins.Add(new Coin(coinType)
                        {
                            WalletDeviceId = _currentDevice.Id
                        });
                    }
                }
                db.SaveChanges();
                foreach (var coin in db.Coins)
                {
                    var addressPath = new BIP44AddressPath(coin.Segwit, AddressUtilities.UnhardenNumber(coin.Bip44AccountPath), 0, false, 0);
                    var addressStr  = await device.GetAddressAsync((IAddressPath)addressPath, false, false);

                    var address = new Address()
                    {
                        CoinId        = coin.Id,
                        Account       = addressPath.Account,
                        Change        = addressPath.Change,
                        AddressIndex  = addressPath.AddressIndex,
                        AddressString = addressStr,
                        CoinType      = addressPath.CoinType,
                        Purpose       = addressPath.Purpose,
                    };
                    db.Addresses.Add(address);
                }
                db.SaveChanges();
            }
        }
예제 #7
0
        /// <summary>
        /// TODO: This should be made in to a unit test but it's annoying to add the UI for a unit test as the KeepKey requires human intervention for the pin
        /// </summary>
        /// <returns></returns>
        private static async Task Go()
        {
            try
            {
                using (var keepKeyHid = await Connect())
                {
                    Console.WriteLine();
                    Console.WriteLine("PIN CHALLENGE!!");
                    Console.WriteLine("┌───┬───┬───┐");
                    Console.WriteLine("│ 7 │ 8 │ 9 │");
                    Console.WriteLine("├───┼───┼───┤");
                    Console.WriteLine("│ 4 │ 5 │ 6 │");
                    Console.WriteLine("├───┼───┼───┤");
                    Console.WriteLine("│ 1 │ 2 │ 3 │");
                    Console.WriteLine("└───┴───┴───┘");
                    Console.WriteLine("Match the device screen with the above and enter the numbers of your scrambled pin below, press <enter> to send.");
                    Console.WriteLine();

                    using (var keepKeyManager = new KeepKeyManager(GetPin, keepKeyHid))
                    {
                        await keepKeyManager.InitializeAsync();

                        var cointTable = await keepKeyManager.GetCoinTable();

                        keepKeyManager.CoinUtility = new KeepKeyCoinUtility(cointTable);

                        var tasks = new List <Task>();

                        for (uint i = 0; i < 50; i++)
                        {
                            tasks.Add(DoGetAddress(keepKeyManager, i));
                        }

                        await Task.WhenAll(tasks);

                        for (uint i = 0; i < 50; i++)
                        {
                            var address = await GetAddress(keepKeyManager, i);

                            Console.WriteLine($"Index: {i} (No change) - Address: {address}");

                            if (address != _Addresses[i])
                            {
                                throw new Exception("The ordering got messed up");
                            }
                        }

                        var addressPath = new BIP44AddressPath(false, 60, 0, false, 0);

                        var ethAddress = await keepKeyManager.GetAddressAsync(addressPath, false, false);

                        Console.WriteLine($"First ETH address: {ethAddress}");

                        Console.WriteLine("All good");

                        Console.ReadLine();
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.ReadLine();
            }
        }