2020-01-24 16:52:03 +00:00
|
|
|
# trezorlib
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
[![repology](https://repology.org/badge/tiny-repos/python:trezor.svg)](https://repology.org/metapackage/python:trezor) [![image](https://badges.gitter.im/trezor/community.svg)](https://gitter.im/trezor/community)
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
Python library and command-line client for communicating with Trezor
|
2020-01-28 09:28:45 +00:00
|
|
|
Hardware Wallet.
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2020-01-28 09:28:45 +00:00
|
|
|
See <https://trezor.io> for more information.
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2018-07-10 23:06:26 +00:00
|
|
|
## Install
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
Python Trezor tools require Python 3.5 or higher, and libusb 1.0. The easiest
|
2018-06-19 14:54:54 +00:00
|
|
|
way to install it is with `pip`. The rest of this guide assumes you have
|
|
|
|
a working `pip`; if not, you can refer to [this
|
|
|
|
guide](https://packaging.python.org/tutorials/installing-packages/).
|
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
On a typical system, you already have all you need. Install `trezor` with:
|
2018-06-19 14:54:54 +00:00
|
|
|
|
|
|
|
```sh
|
|
|
|
pip3 install trezor
|
|
|
|
```
|
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
On Windows, you also need to either install [Trezor Bridge](https://wallet.trezor.io/#/bridge), or
|
|
|
|
[libusb](https://github.com/libusb/libusb/wiki/Windows) and the appropriate
|
|
|
|
[drivers](https://zadig.akeo.ie/).
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
### Firmware version requirements
|
2018-12-18 12:59:49 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
Current trezorlib version supports Trezor One version 1.8.0 and up, and Trezor T version
|
|
|
|
2.1.0 and up.
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
For firmware versions below 1.8.0 and 2.1.0 respectively, the only supported operation
|
|
|
|
is "upgrade firmware".
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
Trezor One with firmware _older than 1.7.0_ (including firmware-less out-of-the-box
|
|
|
|
units) will not be recognized, unless you install HIDAPI support (see below).
|
2018-12-18 12:59:49 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
### Installation options
|
2018-12-18 12:59:49 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
* **Firmware-less Trezor One**: If you are setting up a brand new Trezor One without
|
|
|
|
firmware, you will need HIDAPI support. On Linux, you will need the following packages
|
|
|
|
(or their equivalents) as prerequisites: `python3-dev`, `cython3`, `libusb-1.0-0-dev`,
|
|
|
|
`libudev-dev`.
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
Install with:
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
```sh
|
|
|
|
pip3 install trezor[hidapi]
|
|
|
|
```
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
* **Ethereum**: To support Ethereum signing from command line, additional packages are
|
|
|
|
needed. Install with:
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
```sh
|
|
|
|
pip3 install trezor[ethereum]
|
|
|
|
```
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
To install both, use `pip3 install trezor[hidapi,ethereum]`.
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
### Distro packages
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
Check out [Repology](https://repology.org/metapackage/python:trezor) to see if your
|
|
|
|
operating system has an up-to-date python-trezor package.
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
### Installing latest version from GitHub
|
2018-06-19 14:54:54 +00:00
|
|
|
|
|
|
|
```sh
|
2020-01-24 16:52:03 +00:00
|
|
|
pip3 install "git+https://github.com/trezor/trezor-firmware#egg=trezor&subdirectory=python"
|
2018-06-19 14:54:54 +00:00
|
|
|
```
|
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
### Running from source
|
2019-02-26 17:29:22 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
Install the [pipenv](https://pipenv.readthedocs.io/en/latest/) tool, checkout
|
|
|
|
`trezor-firmware` from git, and enter the pipenv shell:
|
2019-02-26 17:29:22 +00:00
|
|
|
|
|
|
|
```sh
|
2020-01-24 16:52:03 +00:00
|
|
|
pip3 install pipenv
|
|
|
|
git clone https://github.com/trezor/trezor-firmware
|
|
|
|
cd trezor-firmware
|
|
|
|
pipenv sync
|
|
|
|
pipenv shell
|
2019-02-26 17:29:22 +00:00
|
|
|
```
|
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
In this environment, trezorlib and the `trezorctl` tool is running from the live
|
|
|
|
sources, so your changes are immediately effective.
|
2019-02-26 17:29:22 +00:00
|
|
|
|
2018-07-10 23:06:26 +00:00
|
|
|
## Command line client (trezorctl)
|
2018-06-19 14:54:54 +00:00
|
|
|
|
|
|
|
The included `trezorctl` python script can perform various tasks such as
|
|
|
|
changing setting in the Trezor, signing transactions, retrieving account
|
|
|
|
info and addresses. See the [docs/](docs/) sub folder for detailed
|
|
|
|
examples and options.
|
|
|
|
|
|
|
|
NOTE: An older version of the `trezorctl` command is [available for
|
|
|
|
Debian Stretch](https://packages.debian.org/en/stretch/python-trezor)
|
|
|
|
(and comes pre-installed on [Tails OS](https://tails.boum.org/)).
|
|
|
|
|
2018-07-10 23:06:26 +00:00
|
|
|
## Python Library
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
You can use this python library to interact with a Trezor and use its capabilities in
|
|
|
|
your application. See examples here in the [tools/](tools/) sub folder.
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2018-07-10 23:06:26 +00:00
|
|
|
## PIN Entering
|
2018-06-19 14:54:54 +00:00
|
|
|
|
|
|
|
When you are asked for PIN, you have to enter scrambled PIN. Follow the
|
2019-06-17 18:27:55 +00:00
|
|
|
numbers shown on Trezor display and enter the their positions using the
|
2018-06-19 14:54:54 +00:00
|
|
|
numeric keyboard mapping:
|
|
|
|
|
2018-07-10 23:06:26 +00:00
|
|
|
| | | |
|
|
|
|
|---|---|---|
|
|
|
|
| 7 | 8 | 9 |
|
|
|
|
| 4 | 5 | 6 |
|
|
|
|
| 1 | 2 | 3 |
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2019-06-17 18:27:55 +00:00
|
|
|
Example: your PIN is **1234** and Trezor is displaying the following:
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2018-07-10 23:06:26 +00:00
|
|
|
| | | |
|
|
|
|
|---|---|---|
|
|
|
|
| 2 | 8 | 3 |
|
|
|
|
| 5 | 4 | 6 |
|
|
|
|
| 7 | 9 | 1 |
|
2018-06-19 14:54:54 +00:00
|
|
|
|
|
|
|
You have to enter: **3795**
|
|
|
|
|
2018-07-10 23:06:26 +00:00
|
|
|
## Contributing
|
2018-06-19 14:54:54 +00:00
|
|
|
|
2020-01-24 16:52:03 +00:00
|
|
|
If you want to change protobuf or coin definitions, you will need to regenerate
|
|
|
|
definitions in the `python/` subdirectory.
|
|
|
|
|
|
|
|
First, make sure your submodules are up-to-date with:
|
2018-06-19 14:54:54 +00:00
|
|
|
|
|
|
|
```sh
|
2020-01-24 16:52:03 +00:00
|
|
|
git submodule update --init --recursive
|
2018-06-19 14:54:54 +00:00
|
|
|
```
|
|
|
|
|
2020-03-04 12:39:45 +00:00
|
|
|
Then, rebuild the protobuf messages by running, from the `trezor-firmware` top-level
|
|
|
|
directory:
|
2018-06-19 14:54:54 +00:00
|
|
|
|
|
|
|
```sh
|
2020-01-24 16:52:03 +00:00
|
|
|
make gen
|
2018-06-19 14:54:54 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
To get support for BTC-like coins, these steps are enough and no further
|
|
|
|
changes to the library are necessary.
|