bitbox

package
v4.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2018 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package bitbox contains the API to the physical device.

Index

Constants

View Source
const (
	// EventStatusChanged is fired when the status changes. Check the status using Status().
	EventStatusChanged device.Event = "statusChanged"

	// EventBootloaderStatusChanged is fired when the bootloader status changes. Check the status
	// using BootloaderStatus().
	EventBootloaderStatusChanged device.Event = "bootloaderStatusChanged"

	// ProductName is the name of the bitbox.
	ProductName = "bitbox"
)
View Source
const (
	// ErrIONoPassword is returned when no password has been configured.
	ErrIONoPassword = 101

	// ErrTouchAbort is returned when the user short-touches the button.
	ErrTouchAbort = 600

	// ErrTouchTimeout is returned when the user does not confirm or abort for 30s.
	ErrTouchTimeout = 601

	// ErrSDCard is returned when the SD card is needed, but not inserted.
	ErrSDCard = 400

	// ErrInitializing is returned when the device is still booting up.
	ErrInitializing = 503

	// ErrSDNoMatch is returned when the backup check fails.
	ErrSDNoMatch = 410
)
View Source
const (
	// EventPairingStarted is fired when the pairing started.
	EventPairingStarted device.Event = "pairingStarted"

	// EventPairingTimedout is fired when the pairing timed out.
	EventPairingTimedout device.Event = "pairingTimedout"

	// EventPairingAborted is fired when the pairing aborted.
	EventPairingAborted device.Event = "pairingAborted"

	// EventPairingError is fired when an error happened during the pairing.
	EventPairingError device.Event = "pairingError"

	// EventPairingSuccess is fired when the pairing successfully finished.
	EventPairingSuccess device.Event = "pairingSuccess"

	// EventSignProgress is fired when starting to sign a new batch of hashes.
	EventSignProgress device.Event = "signProgress"
)

TODO: improve error handling and change event data into a JSON object, and split BitBox events from generic device events

Variables

This section is empty.

Functions

func BundledFirmware

func BundledFirmware() []byte

BundledFirmware returns the binary of the bundled firmware.

func BundledFirmwareVersion

func BundledFirmwareVersion() *semver.SemVer

BundledFirmwareVersion returns the version of the bundled firmware.

func IsErrorAbort

func IsErrorAbort(err error) bool

IsErrorAbort returns whether the user aborted the operation.

func IsErrorSDCard

func IsErrorSDCard(err error) bool

IsErrorSDCard returns whether the SD card was not inserted during an operation that requires it.

Types

type BootloaderStatus

type BootloaderStatus struct {
	Upgrading         bool    `json:"upgrading"`
	Progress          float64 `json:"progress"`
	UpgradeSuccessful bool    `json:"upgradeSuccessful"`
	ErrMsg            string  `json:"errMsg"`
}

BootloaderStatus has all the info to handle the bootloader mode.

type CommunicationInterface

type CommunicationInterface interface {
	SendPlain(string) (map[string]interface{}, error)
	SendEncrypt(string, string) (map[string]interface{}, error)
	SendBootloader([]byte) ([]byte, error)
	Close()
}

CommunicationInterface contains functions needed to communicate with the device.

type Device

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

Device provides the API to communicate with the digital bitbox. It is not safe for concurrent use.

func NewDevice

func NewDevice(
	deviceID string,
	bootloader bool,
	version *semver.SemVer,
	channelConfigDir string,
	communication CommunicationInterface) (*Device, error)

NewDevice creates a new instance of Device. bootloader enables the bootloader API and should be true only if the device is in bootloader mode. communication is used for transporting messages to/from the device.

The channelConfigDir is the location of the channel settings file. Callers can use util/config.AppDir to obtain user standard config dir.

func (*Device) BackupList

func (dbb *Device) BackupList() ([]map[string]string, error)

BackupList returns a list of backup filenames.

func (dbb *Device) Blink() error

Blink flashes the LED.

func (*Device) BootloaderStatus

func (dbb *Device) BootloaderStatus() (*BootloaderStatus, error)

BootloaderStatus returns the progress of a firmware upgrade. Returns an error if the device is not in bootloader mode.

func (*Device) BootloaderUpgradeFirmware

func (dbb *Device) BootloaderUpgradeFirmware(signedFirmware []byte) error

BootloaderUpgradeFirmware uploads a signed bitbox firmware release to the device. Returns an error if the device is not in bootloader mode. See https://github.com/digitalbitbox/mcu/releases

func (*Device) ChangePassword

func (dbb *Device) ChangePassword(oldPIN string, newPIN string) error

ChangePassword replaces the PIN for the device. This only works when logged in, so the oldPIN can be checked.

func (*Device) CheckBackup

func (dbb *Device) CheckBackup(backupPassword, filename string) (bool, error)

CheckBackup uses the provided backup file and recovery password to check if they correspond to the current wallet. Returns true if it matches, false if not.

func (*Device) Close

func (dbb *Device) Close()

Close closes the HID device.

func (*Device) CreateBackup

func (dbb *Device) CreateBackup(backupName string, recoveryPassword string) error

CreateBackup creates a new backup of the current device seed on the SD card.

func (*Device) CreateWallet

func (dbb *Device) CreateWallet(walletName string, backupPassword string) error

CreateWallet creates a new wallet and stores a backup containing `walletName` in the filename. The password used for the backup is passed, and different from the device PIN.

func (*Device) DeviceInfo

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

DeviceInfo gets device information.

func (*Device) DisplayAddress

func (dbb *Device) DisplayAddress(keyPath string, typ string) error

DisplayAddress triggers the display of the address at the given key path.

func (*Device) ECDHPK

func (dbb *Device) ECDHPK(mobileECDHPK string) (interface{}, error)

ECDHPK passes the ECDH public key of the mobile to the device and returns its response.

func (*Device) ECDHPKhash

func (dbb *Device) ECDHPKhash(mobileECDHPKhash string) (interface{}, error)

ECDHPKhash passes the hash of the ECDH public key of the mobile to the device and returns its response.

func (*Device) ECDHchallenge

func (dbb *Device) ECDHchallenge() error

ECDHchallenge forwards a ecdh challenge command to the Bitbox

func (*Device) EraseBackup

func (dbb *Device) EraseBackup(filename string) error

EraseBackup deletes a backup.

func (*Device) ExtendedPublicKey

func (dbb *Device) ExtendedPublicKey(keypath signing.AbsoluteKeypath) (*hdkeychain.ExtendedKey, error)

ExtendedPublicKey implements device.Interface.

func (*Device) Identifier

func (dbb *Device) Identifier() string

Identifier implements device.Interface.

func (*Device) Init

func (dbb *Device) Init(testing bool)

Init initialized the device. testing means the device is initialized for testnet.

func (*Device) KeystoreForConfiguration

func (dbb *Device) KeystoreForConfiguration(
	configuration *signing.Configuration,
	cosignerIndex int,
) keystoreInterface.Keystore

KeystoreForConfiguration implements device.Interface.

func (*Device) Lock

func (dbb *Device) Lock() (bool, error)

Lock locks the device for 2FA. Returns true if successful and false if aborted by the user.

func (*Device) LockBootloader

func (dbb *Device) LockBootloader() error

LockBootloader locks the bootloader.

func (*Device) Login

func (dbb *Device) Login(pin string) (bool, string, error)

Login validates the pin. This needs to be called before using any API call except for Ping() and SetPassword(). It returns whether the next login attempt requires a long-touch, and the number of remaining attempts.

func (*Device) Paired

func (dbb *Device) Paired() bool

Paired returns whether a channel to a mobile exists.

func (*Device) Ping

func (dbb *Device) Ping() (bool, error)

Ping returns true if the device is initialized, and false if it is not.

func (*Device) PingMobile

func (dbb *Device) PingMobile() error

PingMobile pings the mobile if a channel exists. Only returns no error if the pong was received.

func (*Device) ProductName

func (dbb *Device) ProductName() string

ProductName implements device.Interface.

func (*Device) Random

func (dbb *Device) Random(typ string) (string, error)

Random generates a 16 byte random number, hex encoded. typ can be either "true" or "pseudo".

func (*Device) Reset

func (dbb *Device) Reset(pin string) (bool, error)

Reset resets the device. Returns true if erased and false if aborted by the user. Only callable when logged in, so the PIN can be checked.

func (*Device) RestoreBackup

func (dbb *Device) RestoreBackup(backupPassword, filename string) (bool, error)

RestoreBackup restores a backup from the SD card. Returns true if restored and false if aborted by the user.

func (*Device) SetHiddenPassword

func (dbb *Device) SetHiddenPassword(hiddenPIN string, hiddenBackupPassword string) (bool, error)

SetHiddenPassword creates a hidden pin/seed. Returns false if aborted by the user.

func (*Device) SetName

func (dbb *Device) SetName(name string) error

SetName sets the device name. Retrieve the device name using DeviceInfo().

func (*Device) SetOnEvent

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

SetOnEvent installs a callback which is called for various events.

func (*Device) SetPassword

func (dbb *Device) SetPassword(pin string) error

SetPassword defines a PIN for the device. This only works on a fresh device. If a password has already been configured, a new one cannot be set until the device is reset.

func (*Device) Sign

func (dbb *Device) Sign(
	txProposal *maketx.TxProposal,
	signatureHashes [][]byte,
	keyPaths []string,
) ([]btcec.Signature, error)

Sign returns signatures for the provided hashes. The private keys used to sign them are derived using the provided keyPaths.

func (*Device) StartPairing

func (dbb *Device) StartPairing() (*relay.Channel, error)

StartPairing creates, stores and returns a new channel and finishes the pairing asynchronously.

func (*Device) Status

func (dbb *Device) Status() Status

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

func (*Device) UnlockBootloader

func (dbb *Device) UnlockBootloader() (bool, error)

UnlockBootloader unlocks the bootloader. It returns true on success, and false on user abort.

func (*Device) XPub

func (dbb *Device) XPub(path string) (*hdkeychain.ExtendedKey, error)

XPub returns the extended publickey at the path.

type DeviceInfo

type DeviceInfo struct {
	Version   string `json:"version"`
	Serial    string `json:"serial"`
	ID        string `json:"id"`
	TFA       string `json:"TFA"`
	Bootlock  bool   `json:"bootlock"`
	Name      string `json:"name"`
	SDCard    bool   `json:"sdcard"`
	Lock      bool   `json:"lock"`
	U2F       bool   `json:"U2F"`
	U2FHijack bool   `json:"U2F_hijack"`
	Seeded    bool   `json:"seeded"`
}

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

type Error

type Error struct {
	Code float64
	// contains filtered or unexported fields
}

Error wraps an error by the bitbox.

func NewError

func NewError(message string, code float64) *Error

NewError creates a error with the given message and code.

func (*Error) Error

func (error *Error) Error() string

Error implements the error interface.

type PasswordPolicy

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

PasswordPolicy represents the password policy.

func NewPasswordPolicy

func NewPasswordPolicy(mustMatchPattern string) *PasswordPolicy

NewPasswordPolicy creates a new password policy with a regular expression pattern, which is used to match the password.

func (*PasswordPolicy) ValidatePassword

func (passwordMatcher *PasswordPolicy) ValidatePassword(password string) (bool, error)

ValidatePassword evaluates a given password against the password policy. If valid, returns true if invalid, returns false and the PasswordValidationError that explains what went wrong.

type PasswordValidationError

type PasswordValidationError string

PasswordValidationError indicates an error when the given password does not comply with the policy.

func (PasswordValidationError) Error

func (p PasswordValidationError) Error() string

type Status

type Status string

Status represents the device status.

const (
	// StatusBootloader means that the device is in bootloader mode, and the bootloader API can be
	// used.
	StatusBootloader Status = "bootloader"

	// StatusUninitialized is the uninitialized device, i.e. unseeded and no password set.
	// Use SetPassword() to proceed to StatusLoggedIn.
	StatusUninitialized Status = "uninitialized"

	// StatusInitialized means the password was set and the device was seeded. Use Login() to
	// proceed to StatusSeeded.
	StatusInitialized Status = "initialized"

	// StatusLoggedIn means device authentication was successful, but the device is not yet
	// seeded. Use CreateWallet() or RestoreBackup() to seed and proceed to StatusSeeded.
	StatusLoggedIn Status = "logged_in"

	// StatusSeeded means we are authenticated, and the device is seeded. We are ready to use
	// XPub(), Sign() etc.
	StatusSeeded Status = "seeded"

	// StatusRequireUpgrade means that the a firmware upgrade is required before being able to
	// proceed to StatusLoggedIn or StatusSeeded.
	StatusRequireUpgrade = "require_upgrade"
)

Directories

Path Synopsis
Code generated by mockery v1.0.0.
Code generated by mockery v1.0.0.

Jump to

Keyboard shortcuts

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