Example #1
0
 public App(IHidDevice keepKeyHidDevice)
 {
     _KeepKeyManager = new KeepKeyManager(KeepKeyPinPad.GetPin, keepKeyHidDevice);
     InitializeComponent();
     keepKeyHidDevice.Connected += KeepKeyHidDevice_Connected;
     MainNavigationPage          = new NavigationPage(new MainPage());
     MainPage = MainNavigationPage;
 }
Example #2
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();
            }
        }
        public override async Task Initialize()
        {
            if (AddressDeriver != null)
            {
                return;
            }

            var keepKeyDevice = await Connect();

            var keepKeyManager = new KeepKeyManager(GetPin, keepKeyDevice);
            await keepKeyManager.InitializeAsync();

            AddressDeriver = keepKeyManager;
        }
Example #4
0
 private static async Task <string> GetAddress(KeepKeyManager keepKeyManager, uint i)
 {
     return(await keepKeyManager.GetAddressAsync(new BIP44AddressPath(true, 0, 0, false, i), false, false));
 }
Example #5
0
        private static async Task DoGetAddress(KeepKeyManager keepKeyManager, uint i)
        {
            var address = await GetAddress(keepKeyManager, i);

            _Addresses[i] = address;
        }
Example #6
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();
            }
        }