Documentation ¶
Overview ¶
Package bitbox contains the API to the physical device.
Index ¶
- Constants
- Variables
- func Asset(name string) ([]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func BundledFirmware() []byte
- func BundledFirmwareVersion() *semver.SemVer
- func IsErrorSDCard(err error) bool
- func MustAsset(name string) []byte
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- type BootloaderStatus
- type CommunicationInterface
- type Device
- func (dbb *Device) BackupList() ([]map[string]string, error)
- func (dbb *Device) Blink() error
- func (dbb *Device) BootloaderStatus() (*BootloaderStatus, error)
- func (dbb *Device) BootloaderUpgradeFirmware(signedFirmware []byte) error
- func (dbb *Device) ChangePassword(oldPIN string, newPIN string) error
- func (dbb *Device) CheckBackup(backupPassword, filename string) (bool, error)
- func (dbb *Device) Close()
- func (dbb *Device) CreateBackup(backupName string, recoveryPassword string) (bool, error)
- func (dbb *Device) CreateWallet(walletName string, backupPassword string) error
- func (dbb *Device) DeviceInfo() (*DeviceInfo, error)
- func (dbb *Device) EraseBackup(filename string) error
- func (dbb *Device) ExtendedPublicKey(keypath signing.AbsoluteKeypath) (*hdkeychain.ExtendedKey, error)
- func (dbb *Device) FeatureSet(featureSet *FeatureSet) error
- func (dbb *Device) HasMobileChannel() bool
- func (dbb *Device) Identifier() string
- func (dbb *Device) Init(testing bool)
- func (dbb *Device) KeystoreForConfiguration(configuration *signing.Configuration, cosignerIndex int) keystoreInterface.Keystore
- func (dbb *Device) Lock() (bool, error)
- func (dbb *Device) LockBootloader() error
- func (dbb *Device) Login(pin string) (bool, string, error)
- func (dbb *Device) Ping() (bool, error)
- func (dbb *Device) PingMobile() error
- func (dbb *Device) ProductName() string
- func (dbb *Device) Random(typ string) (string, error)
- func (dbb *Device) Reset(pin string) (bool, error)
- func (dbb *Device) RestoreBackup(backupPassword, filename string) (bool, error)
- func (dbb *Device) SetHiddenPassword(hiddenPIN string, hiddenBackupPassword string) (bool, error)
- func (dbb *Device) SetName(name string) error
- func (dbb *Device) SetOnEvent(onEvent func(device.Event, interface{}))
- func (dbb *Device) SetPassword(pin string) error
- func (dbb *Device) Sign(txProposal *maketx.TxProposal, signatureHashes [][]byte, keyPaths []string) ([]SignatureWithRecID, error)
- func (dbb *Device) StartPairing() (*relay.Channel, error)
- func (dbb *Device) Status() Status
- func (dbb *Device) UnlockBootloader() (bool, error)
- type DeviceInfo
- type Error
- type FeatureSet
- type PasswordPolicy
- type PasswordValidationError
- type SignatureWithRecID
- type Status
Constants ¶
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" )
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 )
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" // EventSignConfirmDevice is fired when the user is about to be prompted to sign the tx with the // device. EventSignConfirm device.Event = "signConfirm" )
TODO: improve error handling and change event data into a JSON object, and split BitBox events from generic device events
Variables ¶
var ErrMustBeLoggedIn = errors.New("must be logged in")
ErrMustBeLoggedIn is returned by API calls when a login is required, but the device has not beed unlocked.
Functions ¶
func Asset ¶
Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.
func AssetDir ¶
AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:
data/ foo.txt img/ a.png b.png
then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.
func AssetInfo ¶
AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.
func BundledFirmware ¶
func BundledFirmware() []byte
BundledFirmware returns the binary of the bundled firmware.
func BundledFirmwareVersion ¶
BundledFirmwareVersion returns the version of the bundled firmware.
func IsErrorSDCard ¶
IsErrorSDCard returns whether the SD card was not inserted during an operation that requires it.
func MustAsset ¶
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.
func RestoreAsset ¶
RestoreAsset restores an asset under the given directory
func RestoreAssets ¶
RestoreAssets restores an asset under the given directory recursively
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 ¶
BackupList returns a list of backup filenames.
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 ¶
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 ¶
ChangePassword replaces the PIN for the device. This only works when logged in, so the oldPIN can be checked.
func (*Device) CheckBackup ¶
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) CreateBackup ¶
CreateBackup creates a new backup of the current device seed on the SD card. The recoveryPassword is used as a sanity check (does the backed up seed + recoveryPassword dervive the current keys in the BitBox?). Returns false if this check fails.
func (*Device) CreateWallet ¶
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) EraseBackup ¶
EraseBackup deletes a backup.
func (*Device) ExtendedPublicKey ¶
func (dbb *Device) ExtendedPublicKey(keypath signing.AbsoluteKeypath) (*hdkeychain.ExtendedKey, error)
ExtendedPublicKey implements device.Interface.
func (*Device) FeatureSet ¶
func (dbb *Device) FeatureSet(featureSet *FeatureSet) error
FeatureSet modifies device features.
func (*Device) HasMobileChannel ¶
HasMobileChannel returns whether a channel to a mobile exists.
func (*Device) Identifier ¶
Identifier implements device.Interface.
func (*Device) Init ¶
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 ¶
Lock locks the device for 2FA. Returns true if successful and false if aborted by the user.
func (*Device) LockBootloader ¶
LockBootloader locks the bootloader.
func (*Device) Login ¶
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) PingMobile ¶
PingMobile pings the mobile if a channel exists. Only returns no error if the pong was received.
func (*Device) ProductName ¶
ProductName implements device.Interface.
func (*Device) Random ¶
Random generates a 16 byte random number, hex encoded. typ can be either "true" or "pseudo".
func (*Device) Reset ¶
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 ¶
RestoreBackup restores a backup from the SD card. Returns true if restored and false if aborted by the user.
func (*Device) SetHiddenPassword ¶
SetHiddenPassword creates a hidden pin/seed. Returns false if aborted by the user.
func (*Device) SetOnEvent ¶
SetOnEvent installs a callback which is called for various events.
func (*Device) SetPassword ¶
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, ) ([]SignatureWithRecID, error)
Sign returns signatures for the provided hashes. The private keys used to sign them are derived using the provided keyPaths.
func (*Device) StartPairing ¶
StartPairing creates, stores and returns a new channel and finishes the pairing asynchronously.
func (*Device) UnlockBootloader ¶
UnlockBootloader unlocks the bootloader. It returns true on success, and false on user abort.
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"` NewHiddenWallet bool `json:"new_hidden_wallet"` Pairing bool `json:"pairing"` }
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.
type FeatureSet ¶
type FeatureSet struct { NewHiddenWallet *bool `json:"new_hidden_wallet,omitempty"` Pairing *bool `json:"pairing,omitempty"` }
FeatureSet are the device features one can modify with FeatureSet().
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 SignatureWithRecID ¶
SignatureWithRecID also contains the recoverable ID, with which one can more efficiently recover the public key.
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" // 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" )