This is my Hid library. It supports UWP, and Android. https://bitbucket.org/MelbourneDeveloper/hid.net/src/master/
This is an example of the library being used with the Trezor hardware wallet: https://github.com/MelbourneDeveloper/Trezor.Net
I can connect to the Trezor with no problem on UWP, but I cannot connect to the Ledger which is another hardware wallet. This is the code I use to connect to both devices in my library. It looks through a list of devices, tries to connect and returns the first one that connects OK:
public async Task InitializeAsync() { Logger.Log("Initializing Hid device", null, nameof(UWPHidDevice)); foreach (var deviceInformation in _WindowsDeviceInformationList) { var hidDeviceOperation = HidDevice.FromIdAsync(deviceInformation.Id, Windows.Storage.FileAccessMode.ReadWrite); var task = hidDeviceOperation.AsTask(); _HidDevice = await task; if (_HidDevice != null) { break; } } if (_HidDevice == null) { throw new Exception($"Could not obtain a connection to the device."); } _HidDevice.InputReportReceived += _HidDevice_InputReportReceived; if (_HidDevice == null) { throw new Exception("Could not connect to the device"); } Connected?.Invoke(this, new EventArgs()); }
The trezor connection returns fine, but the Ledger just loops through the existing drivers which are valid without returning anything. I strongly suspect that it is a permissions problem. In order to connect to a USB device in UWP, I can need to specify a device capability:
This is the section for Trezor:
<Capabilities> <Capability Name="internetClient" /> <uap:Capability Name="removableStorage" /> <DeviceCapability Name="humaninterfacedevice"> <Device Id="vidpid:534C 0001"> <Function Type="usage:0005 *" /> <Function Type="usage:FF00 0001" /> <Function Type="usage:ff00 *" /> </Device> </DeviceCapability> </Capabilities>
I have exactly the same thing for Ledger except for the vendor:
But, Visual Studio complains about this with this error:
http://schemas.microsoft.com/appx/manifest/types:ST_DeviceId
I tracked down this schema to here: https://github.com/tpn/winsdk-10/blob/master/Include/10.0.16299.0/winrt/AppxManifestTypes.xsd
This seems to be the rules:
<xs:simpleType name="ST_DeviceId"> <xs:restriction base="ST_NonEmptyString"> <xs:pattern value="any"/> <xs:pattern value="vidpid:[0-9a-fA-F]{4} [0-9a-fA-F]{4}( (usb|bluetooth))?"/> <xs:pattern value="model:[^;]{1,512};.{1,512}"/> </xs:restriction> </xs:simpleType>
I'm actually now getting this useful error: