Skip to content

Commit

Permalink
fix linter ref fibercrypto#165
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvaro Denis committed Mar 4, 2020
1 parent 6484cf9 commit ed199f4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/cli/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,8 @@ func TestRecovery(t *testing.T) {
var stdInDone = false

wg := sync.WaitGroup{}
wg.Add(2)
go func() {
wg.Add(1)
defer wg.Done()
scanner := bufio.NewScanner(stdoutPipe)

Expand All @@ -558,7 +558,6 @@ func TestRecovery(t *testing.T) {
}()

go func() {
wg.Add(1)
defer wg.Done()
scanner := bufio.NewScanner(stderrPipe)
scanner.Split(bufio.ScanWords)
Expand Down
12 changes: 10 additions & 2 deletions src/integration/proxy/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,26 @@ type Sequencer struct {
scan func(requestKind skywallet.InputRequestKind, title, message string) (string, error)
}

// ActionCancelableFrom is used for masking options, for example:
// ActionConfirmFrom is used for masking options, for example:
// 00000000 ActionConfirmNone
// 00000001 ActionConfirmOkFromDevButton
// 00000010 ActionConfirmCancelFromDevButton
type ActionConfirmFrom uint8
// ActionConfirmNone no thing to confirm
var ActionConfirmNone ActionConfirmFrom = 0x0
// ActionConfirmOkFromDevButton confirm in the device
var ActionConfirmOkFromDevButton ActionConfirmFrom = 0x1
// ActionConfirmCancelFromDevButton cancel from the device
var ActionConfirmCancelFromDevButton ActionConfirmFrom = 0x2
// ActionConfirmOkAndCancelFromDevButton ok and/or cancel from the device
var ActionConfirmOkAndCancelFromDevButton ActionConfirmFrom = 0x4
// ActionConfirmOkFromWireProtocol confirm ok though wire
var ActionConfirmOkFromWireProtocol ActionConfirmFrom = 0x8
// ActionConfirmCancelFromWireProtocol confirm cancel though wire
var ActionConfirmCancelFromWireProtocol ActionConfirmFrom = 0x16
// ActionConfirmOkAndCancelFromWireProtocol confirm ok and/or cancel though wire
var ActionConfirmOkAndCancelFromWireProtocol ActionConfirmFrom = 0x32
// ActionWordRequest a word was request
var ActionWordRequest ActionConfirmFrom = 0x64

// mixActionConfirmFrom create a merged value from all the masks
Expand Down Expand Up @@ -88,7 +96,7 @@ func (sq *Sequencer) handleInputReaderResponse(err error) error {
return err
}

func (sq *Sequencer) handleInputReaderCanceled(err error) error {
func (sq *Sequencer) handleInputReaderCanceled(_ error) error {
msg, err := sq.dev.Cancel()
if err != nil {
sq.log.WithError(err).Errorln("unable to cancel command")
Expand Down
2 changes: 1 addition & 1 deletion src/skywallet/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func NewDriver(deviceType DeviceType, emulatorAddress ...string) (*Driver, error
if len(emulatorAddress) == 0 {
emulatorAddress = []string{"127.0.0.1"}
} else if len(emulatorAddress) > 1 {
return nil, ErrInvalidArgCountForEmulatorIpAddress
return nil, ErrInvalidArgCountForEmulatorIPAddress
}
udpBus, err := usb.InitUDP([]int{EmulatorPort}, emulatorAddress[0])
if err != nil {
Expand Down
35 changes: 29 additions & 6 deletions src/skywallet/skywallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@ var (
ErrDeviceTypeEmulator = errors.New("device type cannot be emulator")
// ErrInvalidWordCount is returned if word count is not valid mnemonic word length
ErrInvalidWordCount = errors.New("word count must be 12 or 24")
// ErrInvalidArgCountForEmulatorIpAddress emulator ip address is the only one expected argument for emulatorAddress
ErrInvalidArgCountForEmulatorIpAddress = errors.New("emulator ip address is the only one expected argument for emulatorAddress")
// ErrInvalidArgCountForEmulatorIPAddress emulator ip address is the only one expected argument for emulatorAddress
ErrInvalidArgCountForEmulatorIPAddress = errors.New("emulator ip address is the only one expected argument for emulatorAddress")
// ErrNoDeviceConnected is returned if no device is connected to the system
ErrNoDeviceConnected = errors.New("no device connected")
// ErrInvalidWalletType a valid wallet type should be specified
ErrInvalidWalletType = errors.New("invalid wallet type, options are: " + WalletTypeDeterministic + " or " + WalletTypeBip44)
// ErrUserCancelledWithDeviceButton the requested operation has been cancelled from the device input button
ErrUserCancelledWithDeviceButton = errors.New("the requested operation has been cancelled from the device input button")
// ErrUserCancelledFromInputReader the requested operation has been cancelled from the device input button
ErrUserCancelledFromInputReader = errors.New("the requested operation has been cancelled from the user interaction")
// ErrUserCancelledWithDeviceButton the requested operation has been canceled from the device input button
ErrUserCancelledWithDeviceButton = errors.New("the requested operation has been canceled from the device input button")
// ErrUserCancelledFromInputReader the requested operation has been canceled from the device input button
ErrUserCancelledFromInputReader = errors.New("the requested operation has been canceled from the user interaction")
)

const (
Expand All @@ -70,33 +70,54 @@ const (
firstHardenedChild = uint32(0x80000000)
)

// InputRequestKind specify the input required for the reader
type InputRequestKind uint32
const (
// RequestKindPinMatrix require an input reader for a matrix
RequestKindPinMatrix InputRequestKind = iota
// RequestKindPassphrase require an input reader for a pass phrase
RequestKindPassphrase
// RequestKindWord require an input reader for a word
RequestKindWord
// RequestInformUserOnlyOk no special input, just accept
RequestInformUserOnlyOk
// RequestInformUserOnlyCancel just cancel if required
RequestInformUserOnlyCancel
// RequestInformUserOkAndCancel use ok or cancel inpt reader as required
RequestInformUserOkAndCancel
)

//go:generate mockery -name Devicer -case underscore -inpkg -testonly

// Devicer provides api for the hw wallet functions
type Devicer interface {
// AddressGen generate addresses
AddressGen(addressN, startIndex uint32, confirmAddress bool, walletType string) (wire.Message, error)
// ApplySettings to the device
ApplySettings(usePassphrase *bool, label string, language string) (wire.Message, error)
// Backup create a seed backup
Backup() (wire.Message, error)
// Cancel cancel current operation
Cancel() (wire.Message, error)
// CheckMessageSignature check if a message signature is valid
CheckMessageSignature(message, signature, address string) (wire.Message, error)
// ChangePin change device PIN
ChangePin(removePin *bool) (wire.Message, error)
// Connected check if the is a device connected
Connected() bool
// Available check if the device is reachable
Available() bool
// EraseFirmware erase device firmware (bootloader mode).
EraseFirmware(length uint32) (wire.Message, error)
// UploadFirmware upload a new firmware (bootloader mode).
UploadFirmware(payload []byte, hash [32]byte) (wire.Message, error)
// GetFeatures return the device features
GetFeatures() (wire.Message, error)
// GenerateMnemonic generate a mnemonic
GenerateMnemonic(wordCount uint32, usePassphrase bool) (wire.Message, error)
// Recovery a device mnemonic
Recovery(wordCount uint32, usePassphrase *bool, dryRun bool) (wire.Message, error)
// SetMnemonic sets a specific mnemonic
SetMnemonic(mnemonic string) (wire.Message, error)
TransactionSign(inputs []*messages.SkycoinTransactionInput, outputs []*messages.SkycoinTransactionOutput, walletType string) (wire.Message, error)
SignMessage(addressN, addressIndex int, message string, walletType string) (wire.Message, error)
Expand Down Expand Up @@ -596,6 +617,7 @@ func (d *Device) Available() bool {
return true
}

// EraseFirmware erase current firmware
func (d *Device) EraseFirmware(length uint32) (wire.Message, error) {
if d.Driver.DeviceType() != DeviceTypeUSB {
return wire.Message{}, ErrDeviceTypeEmulator
Expand All @@ -614,6 +636,7 @@ func (d *Device) EraseFirmware(length uint32) (wire.Message, error) {
return d.Driver.SendToDevice(d.dev, eraseFirmwareChunks)
}

// UploadFirmware upload a new firmware
func (d *Device) UploadFirmware(payload []byte, hash [32]byte) (wire.Message, error) {
if d.Driver.DeviceType() != DeviceTypeUSB {
return wire.Message{}, ErrDeviceTypeEmulator
Expand Down

0 comments on commit ed199f4

Please sign in to comment.