private void KeepKeyHidDevice_Connected(object sender, System.EventArgs e) { Device.BeginInvokeOnMainThread(async() => { await _KeepKeyManager.InitializeAsync(); var coinTable = await _KeepKeyManager.GetCoinTable(); _KeepKeyManager.CoinUtility = new KeepKeyCoinUtility(coinTable); Address = await _KeepKeyManager.GetAddressAsync(new BIP44AddressPath(false, 0, 0, false, 0), false, true); GetAddress?.Invoke(this, new EventArgs()); }); }
/// <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; }
/// <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(); } }