Buy a Trezor Here

The Trezor is a crypto currency “hardware wallet”.

Many people consider Trezor to be the gold standard for hardware wallets.

My library for accessing Trezor via C# on Android, UWP, and .NET are in this repo.

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.

Trezor’s programming interface uses a technology called Protocol Buffers. It is a Google technology and you can read about it here . Protocol Buffers is a technology that allows for the programming interface to be defined in a markup language which is programming language agnostic. In Protocol Buffers the markup language defines the message types that can be sent and from the device. The Protocol Buffers (protobuf for short) technology has been implemented on many platforms such as Java, JavaScript, C# (.NET, Xamarin, etc.) , Python, and Go. If you paste some protobuf markup in to a language generator, it will pump out code in your language that can be used to talk to protobuf compliant devices. I used this online generator by Marc Gravell to generate code for the Trezor in C#.

Here is a starting point for reading about Trezor’s programming interface: Trezor API Documentation

The above documentation does not give a lot of detail. So, the first step is for you to pick the language that you wish to build your application on. Here is the Trezor Github Page. There are several libraries here which would allow you to get started. There is a Python, Java, JavaScript and Go library already floating around. If no library already exists, once you have chosen your technology, you will need to generate the code for that technology. The protobuf definitions (markup) can be copied and pasted in to a generator to create the code. In order to use Marc Gravell’s online generator, I needed to merge the two definition files together and then the C# generated correctly. Edit: you do not need to do this if you use Marc’s full command line generator. I am currently working on Trezor.Net which will be available at some point in the future with an as yet unknown license structure.

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 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.

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.





1 Comment

  1. “In order to use Marc Gravell’s generator, I needed to merge the two definition files together and then the C# generated correctly.” – note: the command-line version of the tool supports multiple input files, but the online version currently doesn’t. At the time, the command-line version wasn’t readily available (you had to build it yourself), but I now make this available as a download with the tool.

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s