- Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathProgram.cs
More file actions
Latest commit
123 lines (104 loc) · 3.99 KB
/
Copy pathProgram.cs
File metadata and controls
123 lines (104 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
usingDevice.Net;
usingHardwarewallets.Net.AddressManagement;
usingHid.Net.Windows;
usingKeepKey.Net;
usingSystem;
usingSystem.Collections.Generic;
usingSystem.Threading.Tasks;
usingUsb.Net.Windows;
namespaceKeepKeyTestApp
{
internalclassProgram
{
#region Fields
privatestaticreadonlystring[]_Addresses=newstring[50];
#endregion
#region Main
privatestaticvoidMain(string[]args)
{
try
{
Go();
while(true);
}
catch(Exceptionex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
#endregion
#region Private Methods
privatestaticasyncTask<KeepKeyManager>ConnectAsync()
{
//This only needs to be done once.
//Register the factory for creating Usb devices. Trezor One Firmware 1.7.x / Trezor Model T
WindowsUsbDeviceFactory.Register(newDebugLogger(),newDebugTracer());
//Register the factory for creating Hid devices. Trezor One Firmware 1.6.x
WindowsHidDeviceFactory.Register(newDebugLogger(),newDebugTracer());
varkeepKeyManagerBroker=newKeepKeyManagerBroker(GetPin,GetPassphrase,2000);
varkeepKeyManager=awaitkeepKeyManagerBroker.WaitForFirstTrezorAsync();
varcoinTable=awaitkeepKeyManager.GetCoinTable();
keepKeyManager.CoinUtility=newKeepKeyCoinUtility(coinTable);
returnkeepKeyManager;
}
/// <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>
privatestaticasyncTaskGo()
{
try
{
using(varkeepKeyManager=awaitConnectAsync())
{
vartasks=newList<Task>();
for(uinti=0;i<50;i++)
{
tasks.Add(DoGetAddress(keepKeyManager,i));
}
awaitTask.WhenAll(tasks);
for(uinti=0;i<50;i++)
{
varaddress=awaitGetAddress(keepKeyManager,i);
Console.WriteLine($"Index: {i} (No change) - Address: {address}");
if(address!=_Addresses[i])
{
thrownewException("The ordering got messed up");
}
}
varaddressPath=newBIP44AddressPath(false,60,0,false,0);
varethAddress=awaitkeepKeyManager.GetAddressAsync(addressPath,false,false);
Console.WriteLine($"First ETH address: {ethAddress}");
Console.WriteLine("All good");
Console.ReadLine();
}
}
catch(Exceptionex)
{
Console.WriteLine(ex.ToString());
Console.ReadLine();
}
}
privatestaticasyncTaskDoGetAddress(KeepKeyManagerkeepKeyManager,uinti)
{
varaddress=awaitGetAddress(keepKeyManager,i);
_Addresses[i]=address;
}
privatestaticasyncTask<string>GetAddress(KeepKeyManagerkeepKeyManager,uinti)
{
returnawaitkeepKeyManager.GetAddressAsync(newBIP44AddressPath(true,0,0,false,i),false,false);
}
privatestaticasyncTask<string>GetPassphrase()
{
Console.WriteLine("Enter passphrase: ");
returnConsole.ReadLine().Trim();
}
privatestaticasyncTask<string>GetPin()
{
Console.WriteLine("Enter PIN based on values: ");
returnConsole.ReadLine().Trim();
}
#endregion
}
}