api

package
v4.14.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2019 License: Apache-2.0 Imports: 21 Imported by: 3

Documentation

Overview

Package api contains the API to the physical device.

Package api contains the API to the physical device.

Index

Constants

View Source
const (
	// EventChannelHashChanged is fired when the return values of ChannelHash() change.
	EventChannelHashChanged event.Event = "channelHashChanged"

	// EventStatusChanged is fired when the status changes. Check the status using Status().
	EventStatusChanged event.Event = "statusChanged"

	// EventAttestationCheckFailed is fired when the device does not pass the attestation signature
	// check, indicating that it might not be an authentic device.
	EventAttestationCheckFailed event.Event = "attestationCheckFailed"
)
View Source
const (

	// ErrInvalidInput is returned when the request sends and invalid or unexpected input
	ErrInvalidInput = 101

	// ErrUserAbort is returned when the user aborts an action on the device.
	ErrUserAbort = 104
)

Variables

This section is empty.

Functions

func IsErrorAbort

func IsErrorAbort(err error) bool

IsErrorAbort returns whether the user aborted the operation.

Types

type Backup

type Backup struct {
	ID   string
	Name string
	Time time.Time
}

Backup contains the metadata of one backup.

type Communication

type Communication interface {
	SendFrame(string) error
	ReadFrame() ([]byte, error)
	Query([]byte) ([]byte, error)
	Close()
}

Communication contains functions needed to communicate with the device.

type Config

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

Config perists the bitbox02 related configuration in a file.

func NewConfig

func NewConfig(configDir string) *Config

NewConfig creates a new Config instance. The config will be stored in the given location.

func (*Config) AddDeviceStaticPubkey

func (config *Config) AddDeviceStaticPubkey(pubkey []byte) error

AddDeviceStaticPubkey implements ConfigurationInterface.

func (*Config) ContainsDeviceStaticPubkey

func (config *Config) ContainsDeviceStaticPubkey(pubkey []byte) bool

ContainsDeviceStaticPubkey implements ConfigurationInterface.

func (*Config) GetAppNoiseStaticKeypair

func (config *Config) GetAppNoiseStaticKeypair() *noise.DHKey

GetAppNoiseStaticKeypair implements ConfigurationInterface.

func (*Config) SetAppNoiseStaticKeypair

func (config *Config) SetAppNoiseStaticKeypair(key *noise.DHKey) error

SetAppNoiseStaticKeypair implements ConfigurationInterface.

type ConfigData

type ConfigData struct {
	AppNoiseStaticKeypair    *NoiseKeypair `json:"appNoiseStaticKeypair"`
	DeviceNoiseStaticPubkeys [][]byte      `json:"deviceNoiseStaticPubkeys"`
}

ConfigData holds the persisted app configuration related to bitbox02 devices.

type ConfigInterface

type ConfigInterface interface {
	// ContainsDeviceStaticPubkey returns true if a device pubkey has been added before.
	ContainsDeviceStaticPubkey(pubkey []byte) bool
	// AddDeviceStaticPubkey adds a device pubkey.
	AddDeviceStaticPubkey(pubkey []byte) error
	// GetAppNoiseStaticKeypair retrieves the app keypair. Returns nil if none has been set before.
	GetAppNoiseStaticKeypair() *noise.DHKey
	// SetAppNoiseStaticKeypair stores the app keypair. Overwrites keypair if one already exists.
	SetAppNoiseStaticKeypair(key *noise.DHKey) error
}

ConfigInterface lets the library client provide their own persisted config backend.

type Device

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

Device provides the API to communicate with the BitBox02.

func NewDevice

func NewDevice(
	version *semver.SemVer,
	edition bitbox02common.Edition,
	config ConfigInterface,
	communication Communication,
	log Logger,
) *Device

NewDevice creates a new instance of Device.

func (*Device) Attestation

func (device *Device) Attestation() bool

Attestation returns the result of the automatic attestation check.

func (*Device) BTCPub

func (device *Device) BTCPub(
	coin messages.BTCCoin,
	keypath []uint32,
	outputType messages.BTCPubRequest_OutputType,
	scriptType messages.BTCScriptType,
	display bool) (string, error)

BTCPub queries the device for a btc, ltc, tbtc, tltc xpub or address.

func (*Device) BTCSign

func (device *Device) BTCSign(
	coin messages.BTCCoin,
	scriptType messages.BTCScriptType,
	bip44Account uint32,
	inputs []*messages.BTCSignInputRequest,
	outputs []*messages.BTCSignOutputRequest,
	version uint32,
	locktime uint32,
) ([][]byte, error)

BTCSign signs a bitcoin or bitcoin-like transaction. Returns one 64 byte signature per input.

func (*Device) ChannelHash

func (device *Device) ChannelHash() (string, bool)

ChannelHash returns the hashed handshake channel binding

func (*Device) ChannelHashVerify

func (device *Device) ChannelHashVerify(ok bool)

ChannelHashVerify verifies the ChannelHash

func (*Device) CheckBackup

func (device *Device) CheckBackup(silent bool) (string, error)

CheckBackup checks if any backup on the SD card matches the current seed on the device and returns the name and ID of the matching backup

func (*Device) CheckSDCard

func (device *Device) CheckSDCard() (bool, error)

CheckSDCard checks whether an sd card is inserted in the device

func (*Device) Close

func (device *Device) Close()

Close implements device.Device.

func (*Device) CreateBackup

func (device *Device) CreateBackup() error

CreateBackup is called after SetPassword() to create the backup.

func (*Device) DeviceInfo

func (device *Device) DeviceInfo() (*DeviceInfo, error)

DeviceInfo retrieves the current device info from the bitbox

func (*Device) ETHPub

func (device *Device) ETHPub(
	coin messages.ETHCoin,
	keypath []uint32,
	outputType messages.ETHPubRequest_OutputType,
	display bool,
	contractAddress []byte,
) (string, error)

ETHPub queries the device for an ethereum address or publickey.

func (*Device) ETHSign

func (device *Device) ETHSign(
	coin messages.ETHCoin,
	keypath []uint32,
	nonce uint64,
	gasPrice *big.Int,
	gasLimit uint64,
	recipient [20]byte,
	value *big.Int,
	data []byte) ([]byte, error)

ETHSign signs an ethereum transaction. It returns a 65 byte signature (R, S, and 1 byte recID).

func (*Device) Edition

func (device *Device) Edition() bitbox02common.Edition

Edition returns the device edition.

func (*Device) Init

func (device *Device) Init(testing bool) error

Init implements device.Device.

func (*Device) InsertRemoveSDCard

func (device *Device) InsertRemoveSDCard(action messages.InsertRemoveSDCardRequest_SDCardAction) error

InsertRemoveSDCard sends a command to the device to insert of remove the sd card based on the workflow state

func (*Device) ListBackups

func (device *Device) ListBackups() ([]*Backup, error)

ListBackups returns a list of all backups on the SD card.

func (*Device) Random

func (device *Device) Random() ([]byte, error)

Random requests a random number from the device using protobuf messages

func (*Device) Reset

func (device *Device) Reset() error

Reset factory resets the device.

func (*Device) RestoreBackup

func (device *Device) RestoreBackup(id string) error

RestoreBackup restores a backup returned by ListBackups (id).

func (*Device) RestoreFromMnemonic

func (device *Device) RestoreFromMnemonic() error

RestoreFromMnemonic invokes the mnemonic phrase import workflow.

func (*Device) SetDeviceName

func (device *Device) SetDeviceName(deviceName string) error

SetDeviceName sends a request to the device using protobuf to set the device name

func (*Device) SetMnemonicPassphraseEnabled

func (device *Device) SetMnemonicPassphraseEnabled(enabled bool) error

SetMnemonicPassphraseEnabled enables or disables entering a mnemonic passphrase after the normal unlock.

func (*Device) SetOnEvent

func (device *Device) SetOnEvent(onEvent func(event.Event, interface{}))

SetOnEvent implements device.Device.

func (*Device) SetPassword

func (device *Device) SetPassword() error

SetPassword invokes the set password workflow on the device. Should be called only if deviceInfo.Initialized is false.

func (*Device) ShowMnemonic

func (device *Device) ShowMnemonic() error

ShowMnemonic lets the user export the bip39 mnemonic phrase on the device.

func (*Device) Status

func (device *Device) Status() Status

Status returns the device state. See the Status* constants.

func (*Device) SupportsETH

func (device *Device) SupportsETH(coinCode string) bool

SupportsETH returns true if ETH is supported by the device api. coinCode is eth/teth/reth or eth-erc20-xyz, ...

func (*Device) SupportsLTC

func (device *Device) SupportsLTC() bool

SupportsLTC returns true if LTC is supported by the device api.

func (*Device) UpgradeFirmware

func (device *Device) UpgradeFirmware() error

UpgradeFirmware reboots into the bootloader so a firmware can be flashed.

func (*Device) Version

func (device *Device) Version() *semver.SemVer

Version returns the firmware version.

type DeviceInfo

type DeviceInfo struct {
	Name                      string `json:"name"`
	Version                   string `json:"version"`
	Initialized               bool   `json:"initialized"`
	MnemonicPassphraseEnabled bool   `json:"mnemonicPassphraseEnabled"`
}

DeviceInfo is the data returned from the device info api call.

type Error

type Error struct {
	Code    int32
	Message string
}

Error wraps an error from bitbox02.

func NewError

func NewError(code int32, message string) *Error

NewError creates a error with the given message and code.

func (*Error) Error

func (err *Error) Error() string

Error implements the error interface.

type Logger

type Logger interface {
	WithField(key string, value interface{}) Logger
	WithError(error) Logger
	Error(msg string)
	Info(msg string)
	Debug(msg string)
}

Logger lets the library client provide their own logging infrastructure.

type NoiseKeypair

type NoiseKeypair struct {
	Private []byte `json:"private"`
	Public  []byte `json:"public"`
}

NoiseKeypair holds a noise keypair.

type Status

type Status string

Status represents the device status.

const (
	// StatusConnected ist the first status, right after the device is connected. We automatically
	// move to StatusUnpaired (directly if the device is uninitialized, or after unlocking the
	// device if it is initialzed).
	StatusConnected = "connected"

	// StatusUnpaired means the pairing has not been confirmed yet. After the pairing screen has
	// been confirmed, we move to StatusUninitialized or StatusInitialized depending on the device
	// status.
	StatusUnpaired Status = "unpaired"

	// StatusPairingFailed is when the pairing code was rejected on the app or on the device.
	StatusPairingFailed Status = "pairingFailed"

	// StatusUninitialized is the uninitialized device. Use SetPassword() to proceed to
	// StatusSeeded.
	StatusUninitialized Status = "uninitialized"

	// StatusSeeded is after SetPassword(), before CreateBack() during initialization of the
	// device. Use CreateBackup() to move to StatusInitialized.
	StatusSeeded Status = "seeded"

	// StatusInitialized means the device is seeded and the backup was created, and the device is
	// unlocked. The keystore is ready to use.
	StatusInitialized Status = "initialized"

	// StatusRequireFirmwareUpgrade means that the a firmware upgrade is required before being able
	// to proceed to StatusLoggedIn or StatusSeeded (firmware version too old).
	StatusRequireFirmwareUpgrade Status = "require_firmware_upgrade"

	// StatusRequireAppUpgrade means that the an app upgrade is required (firmware version too new).
	StatusRequireAppUpgrade Status = "require_app_upgrade"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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