/python-trezor

:snake: Client side implementation for TREZOR-compatible Bitcoin hardware wallets.

Primary LanguagePythonGNU Lesser General Public License v3.0LGPL-3.0

python-trezor

https://travis-ci.org/trezor/python-trezor.svg?branch=master

Python library for communicating with TREZOR Hardware Wallet

See https://trezor.io for more information

Install

Linux requirements:

sudo apt-get install python-dev cython libusb-1.0-0-dev libudev-dev git

Linux & Mac Python requirements:

sudo -H pip install setuptools
sudo -H pip install -r requirements.txt
sudo -H pip install trezor

On FreeBSD you can install the packages:

pkg install security/py-trezor

or build via ports:

cd /usr/ports/security/py-trezor
make install clean

Usage

There is a command line tool called trezorctl which can perform various tasks. Use the following to learn about its commands:

trezorctl --help

or to learn options of a particular command:

trezorctl commands --help

or visit usage page for more info.

NOTE: The trezorctl command is available for Debian Stretch (and comes pre-installed on Tails OS).

To use the library in your application look at the following example.

Example

also found in tools/helloworld.py

#!/usr/bin/env python

from trezorlib.client import TrezorClient
from trezorlib.transport_hid import HidTransport

def main():
    # List all connected TREZORs on USB
    devices = HidTransport.enumerate()

    # Check whether we found any
    if len(devices) == 0:
        print('No TREZOR found')
        return

    # Use first connected device
    transport = HidTransport(devices[0])

    # Creates object for manipulating TREZOR
    client = TrezorClient(transport)

    # Print out TREZOR's features and settings
    print(client.features)

    # Get the first address of first BIP44 account
    # (should be the same address as shown in wallet.trezor.io)
    bip32_path = client.expand_path("44'/0'/0'/0/0")
    address = client.get_address('Bitcoin', bip32_path)
    print('Bitcoin address:', address)

    client.close()

if __name__ == '__main__':
    main()

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