The Trezor is a crypto currency hardwarewallet. Use my library Trezor.Net for cross-platform .NET projects. You can use the Trezor via C# or VB.Net on Android, UWP, Windows, and potentially mcaOS and Linux. The code is in this repo. Contribution is needed to keep this library up to date and finish implementing the public interface.
Developing for the Trezor wallet is very straight forward. If you have a basic understanding of USB development or request/response development, you will be able to get your head around programming for the Trezor device. This article is only a introductory article and does not give detail about how to write your first Trezor application. Instead, this article will point you to the relevant resources and give you some idea on how to get started.
The first thing to know about the Trezor is that it is a HID USB device. HID devices are very simple by nature. You simply send and receive data from the device. All data is sent in binary format by default which is unlike how most web transfer protocols like REST work. But, like REST, Trezor works on a request/response basis. You send the Trezor a message, and it will send you one back.
Here is a starting point for reading about Trezor’s programming interface: Trezor Developers Guide
I cracked the system without any documentation. I trawled through the existing code and examples which give ample information on how to get information. If you do not use one of the existing libraries, you will also need a HID library. I have posted a C# library called Hid.Net on NuGet.org which you may be able to use currently. You will need to convert messages generated in your language of choice in to protobuf binary messages using a protobuf library, and then, you will need to send those messages to the Trezor via the HID library. The Trezor will then respond with its own message.
Here is the documentation about Trezor workflow.
A typical conversation will go like this:
App->Trezor: GetAddress (Request an address for a coin)
Trezor->App: PinMatrixRequest (Request pin in encrypted format)
App->Trezor: PinMatrixAck (Send pin in encrypted format)
Trezor->App: Address (Get address information)
To summarize, I recommend using on of the existing libraries or sample apps to get started, but it’s not impossible to figure all this stuff out without doing so. The next article will have more details and have some code samples.
Generate the Protobuf Messages
You will need to generate the protobuf messages in the language of your choice. You can get the definitions by cloning this repo and then grabbing the .proto files from this folder. I used the app protogen from the protobuf-net C# repo. These were the steps I took for C#
- Clone Trezor Firmware repo
- Clone protobuf-net
- Build the protogen project with Visual Studio
- Drop the proto files from the Trezor Firmware repo in the bin folder of the protogen app in a folder called proto.
- Lastly, run this at the command line. It generates the code in the C# Code folder
protogen *.proto –proto_path=Proto –csharp_out=Code