1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-27 16:48:09 +00:00
trezor-firmware/python
JoeGruff e3ea32a986 multi: Add decred staking.
Add two new input and four output script types.

Decred ticket purchases consist of a stake submission, op returns, and
change addresses. Although change addresses are allowed by consensus,
they are no longer used in practice and so have been given the
restrictions of a null pubkey and no value. Stake scripts are almost
identical to p2pkh or p2sh except for an extra opcode in front. Inputs
are currently only used in the form of one input three outputs with the
first output, or stake submission, paying to a public key hash, or with
two inputs and five outputs with the stake submission paying to a
multisig script hash. The op returns are directed to the user in the
case of one and the voting service provider and user in the case of two.

One of the sstx commitment for a ticket must pay back to the trezor
wallet. This is checked and an error is thrown if we don't find the
expected public key hash.

Because this adds the ability to create new types of outputs once the
ticket votes, two new input script types are also needed. A successful
vote will lead to a stake generation script that must be spent, and an
unsuccessful vote will lead to a revocation script that must be spent.
If we allowed stake change scripts to have a valid pubkey, that too
would require another op code, but we disallow those for output.
2021-03-17 12:16:08 +01:00
..
bash_completion.d
docs fix(python): drop references to beta-wallet.trezor.io 2020-11-16 09:45:42 +01:00
helper-scripts fix(python): drop references to beta-wallet.trezor.io 2020-11-16 09:45:42 +01:00
src/trezorlib multi: Add decred staking. 2021-03-17 12:16:08 +01:00
tests fix(python): append checksum to descriptors (#1445) 2021-02-05 17:46:02 +01:00
tools feat(python): update build_tx.py to new API 2020-10-30 10:25:51 +01:00
.gitignore python: restructure package 2019-08-12 12:57:25 +02:00
AUTHORS Adding @jonathancross to AUTHORS 2020-04-06 10:11:08 +02:00
CHANGELOG.md feat(python): add possibility to enter PIN via letters (#1496) 2021-02-23 10:39:26 +01:00
COPYING
default.nix Drop pyargs 2020-01-02 12:55:35 +01:00
Makefile python: update dist target 2020-08-05 16:45:56 +02:00
MANIFEST.in python: restructure package 2019-08-12 12:57:25 +02:00
README.md chore(python): replace pipenv with poetry 2020-10-07 16:21:00 +02:00
requirements-optional.txt python: add Pillow as an optional requirement (fixes #1224) 2020-08-25 13:13:32 +02:00
requirements.txt test(python): add flake8-requirements 2020-09-29 11:30:40 +02:00
setup.cfg test(python): add flake8-requirements 2020-09-29 11:30:40 +02:00
setup.py feat(python): drop Python 3.5 compatibility (fixes #810) 2020-10-30 10:25:51 +01:00
tox.ini feat(python): drop Python 3.5 compatibility (fixes #810) 2020-10-30 10:25:51 +01:00

trezorlib

repology image

Python library and command-line client for communicating with Trezor Hardware Wallet.

See https://trezor.io for more information.

Install

Python Trezor tools require Python 3.5 or higher, and libusb 1.0. The easiest 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.

On a typical system, you already have all you need. Install trezor with:

pip3 install trezor

On Windows, you also need to either install Trezor Bridge, or libusb and the appropriate drivers.

Firmware version requirements

Current trezorlib version supports Trezor One version 1.8.0 and up, and Trezor T version 2.1.0 and up.

For firmware versions below 1.8.0 and 2.1.0 respectively, the only supported operation is "upgrade firmware".

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

Installation options

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

    Install with:

    pip3 install trezor[hidapi]
    
  • Ethereum: To support Ethereum signing from command line, additional packages are needed. Install with:

    pip3 install trezor[ethereum]
    

To install both, use pip3 install trezor[hidapi,ethereum].

Distro packages

Check out Repology to see if your operating system has an up-to-date python-trezor package.

Installing latest version from GitHub

pip3 install "git+https://github.com/trezor/trezor-firmware#egg=trezor&subdirectory=python"

Running from source

Install the Poetry tool, checkout trezor-firmware from git, and enter the poetry shell:

pip3 install poetry
git clone https://github.com/trezor/trezor-firmware
cd trezor-firmware
poetry install
poetry shell

In this environment, trezorlib and the trezorctl tool is running from the live sources, so your changes are immediately effective.

Command line client (trezorctl)

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/ sub folder for detailed examples and options.

NOTE: An older version of the trezorctl command is available for Debian Stretch (and comes pre-installed on Tails OS).

Python Library

You can use this python library to interact with a Trezor and use its capabilities in your application. See examples here in the tools/ sub folder.

PIN Entering

When you are asked for PIN, you have to enter scrambled PIN. Follow the numbers shown on Trezor display and enter the their positions using the numeric keyboard mapping:

7 8 9
4 5 6
1 2 3

Example: your PIN is 1234 and Trezor is displaying the following:

2 8 3
5 4 6
7 9 1

You have to enter: 3795

Contributing

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:

git submodule update --init --recursive

Then, rebuild the protobuf messages by running, from the trezor-firmware top-level directory:

make gen

To get support for BTC-like coins, these steps are enough and no further changes to the library are necessary.