trezor

package module
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2022 License: AGPL-3.0 Imports: 11 Imported by: 0

README

Go Report Card GoDoc

Bitbank - Trezor

(c) 2022 Bernd Fix brf@hoi-polloi.org >Y<

bitbank-trezor is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

bitbank-trezor is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see http://www.gnu.org/licenses/.

SPDX-License-Identifier: AGPL3.0-or-later

WARNING

This software is not yet ready for productive use; it is work-in-progress.

It is designed and implemented for the purpose of initializing bitbank-relay configuration files (see bitbank-relay). So currently only extracting a public master key and generating a derived coin address is supported.

The implementation of all other Trezor supported functionality is straight foreward; new implementations will be available as soon as they happen :)

Building the Trezor module

Building the module is only possible on Linux or BSD (MacOS, FreeBSD); Windows is not supported because of a missing libusb-1.0-dev library.

Prerequisites

  • Go 1.16+
  • libusb-1.0-dev

To make sure all external dependencies are available, issue the command

go mod tidy

Generating sources from protobuf definitions (optional)

Change to the protob folder that contains the Protobuf definitions for messages exchanged with the Trezor. The definition originate from the trezor-firmware repository on Github in the folder common/protob. These definitions (and the corresponding source files) should be up-to-date in this module, but if you want to make sure you can copy and prepare the definition files with:

make setup

After updating the definitions you need to generate the Go sources from the definitions with

make build

Check if the files have been created successfully.

Building the module

Just issue a go build to make sure the module builds fine.

If you use the module in your own project, the Go module system should make sure automatically that the build process is successful.

Using the Trezor module

PIN/password entry

If you have protected your Trezor wallet with a pin (and possibly a password), some functions might require you to authorize access by providing pin and/or password. The entry of these credentials is handled by implementations of the PinEntry interface; the library provides a simple implementation that works from the command line.

PIN entry

If a PIN is required, the Trezor device will display the pin matrix and the console shows a 3x3 matrix with numbers too:

+---+---+---+
| 7 | 8 | 9 |
+---+---+---+
| 4 | 5 | 6 |
+---+---+---+
| 1 | 2 | 3 |
+---+---+---+

PIN? █

Locate the first pin digit position on the Trezor and enter the corresponding number shown on the console display. Proceed until all pin digits are entered. Press ENTER to submit the entry.

The layout of the numbers to enter corresponds with the ordering of the number keys on the number block of your keyboard (on the right side). If you have enabled NUM_LOCK on your keyboard, you can easily enter the pin using the positions on the number block.

Password entry

If you have protected your wallet with a passphrase ("hidden wallet" in Trezor lingo), you might be asked for a password too. If you just press ENTER (empty passphrase), the "simple wallet" will be used (the one that would be used if passphrase protection is turned off); otherwise the corresponding hidden wallet would be used. Make sure you get the passphrase right; there is no "wrong" passphrase but only another hidden wallet...

Password? █

Test the module

Testing is described in a separate page.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTrezorPINNeeded      = errors.New("pin needed")
	ErrTrezorPasswordNeeded = errors.New("password required")
	ErrTrezorAddrPath       = errors.New("invalid address path")
	ErrTrezorPINCancelled   = errors.New("pin cancelled")
	ErrTrezorPINInvalid     = errors.New("pin invalid")
)

Error codes

Functions

This section is empty.

Types

type BitcoinProc

type BitcoinProc struct{}

BitcoinProc for Bitcoin-related methods

func (*BitcoinProc) GetAddress

func (p *BitcoinProc) GetAddress(dev *Trezor, path []uint32, coin, mode string) (addr string, err error)

GetAddress returns an address referenced by the derivation path

func (*BitcoinProc) GetXpub

func (p *BitcoinProc) GetXpub(dev *Trezor, path []uint32, coin, mode string) (pk string, err error)

GetXpub returns the master public key for given derivation path

type ConsoleEntry

type ConsoleEntry struct{}

ConsoleEntry handle PIN/password dialogs on stdin/stdout

func (*ConsoleEntry) Ask

func (e *ConsoleEntry) Ask(mode int) (in string)

Ask for PIN or passphrase

type EthereumProc

type EthereumProc struct{}

EthereumProc for Ethereum-related methods

func (*EthereumProc) GetAddress

func (p *EthereumProc) GetAddress(dev *Trezor, path []uint32, coin, mode string) (addr string, err error)

GetAddress returns an address referenced by the derivation path

func (*EthereumProc) GetXpub

func (p *EthereumProc) GetXpub(dev *Trezor, path []uint32, coin, mode string) (pk string, err error)

GetXpub returns the master public key for given derivation path

type PinEntry

type PinEntry interface {
	Ask(mode int) string
}

PinEntry interface for PIN/password dialogs

type Processor

type Processor interface {
	GetXpub(dev *Trezor, path []uint32, coin, mode string) (pk string, err error)
	// GetPublicKey(dev *Trezor, path []uint32, coin, mode string) (pk string, err error)
	GetAddress(dev *Trezor, path []uint32, coin, mode string) (addr string, err error)
}

Processor interface for common methods

type Trezor

type Trezor struct {
	// contains filtered or unexported fields
}

Trezor device

func OpenTrezor

func OpenTrezor(pe PinEntry) (*Trezor, error)

OpenTrezor: open a Trezor connected via USB (only one Trezor must be connected)

func (*Trezor) Close

func (t *Trezor) Close() (err error)

Close Trezor device

func (*Trezor) Firmware

func (t *Trezor) Firmware() [3]uint32

Firmware returns the firmware versionof the device

func (*Trezor) GetAddress

func (t *Trezor) GetAddress(path, coin, mode string) (addr string, err error)

DeriveAddress returns an address referenced by the derivation path (coin-agnostic; BIP-39 compatible multi-coin path)

func (*Trezor) GetXpub

func (t *Trezor) GetXpub(path, coin, mode string) (pk string, err error)

GetXpub returns the master public key for given derivation path

func (*Trezor) Label

func (t *Trezor) Label() string

Label returns the hman-readable label of the device

func (*Trezor) Ping

func (t *Trezor) Ping() (err error)

Ping a device to see if it is still online.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL