Skip to content

Commit

Permalink
additional messages supported
Browse files Browse the repository at this point in the history
  • Loading branch information
solipsis committed Feb 17, 2018
1 parent 9f7d56b commit b83ed13
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 0 deletions.
69 changes: 69 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,75 @@ func (kk *Keepkey) Initialize(device *hid.Device) (*kkProto.Features, error) {
return features, nil
}

// Returns the features and other device information such as the version, label, and supported coins
func (kk *Keepkey) GetFeatures() (*kkProto.Features, error) {

features := new(kkProto.Features)
if _, err := kk.keepkeyExchange(&kkProto.GetFeatures{}, features); err != nil {
return nil, err
}
return features, nil
}

// Ping the device. If a message is provided it will be shown on the device screen and returned
// in the success message. Optionally require a button press, pin, or passphrase to continue
func (kk *Keepkey) Ping(msg string, button, pin, password bool) (*kkProto.Success, error) {

ping := &kkProto.Ping{
Message: &msg,
ButtonProtection: &button,
PinProtection: &pin,
PassphraseProtection: &password,
}
success := new(kkProto.Success)
if _, err := kk.keepkeyExchange(ping, success); err != nil {
return nil, err
}
return success, nil
}

// TODO:
// ChangePin requests setting/changing/removing the pin
//func (kk *Keepkey) ChangePin(remove bool) (*kkProto.ChangePin, error) {
/*
change := &kkProto.ChangePin{
Remove: &remove,
}
resp := new(kkProto.PinMatrixRequest)
if _, err := kk.KeepkeyExchange(change, resp); err != nil {
return nil, err
}
// TODO: get user input twice
pin1 := &kkProto.PinMatrixAck{
}
// TODO: remove vs update
*/
//}

// WipeDevice wipes all sensitive data and settings
func (kk *Keepkey) WipeDevice() error {

if _, err := kk.keepkeyExchange(&kkProto.WipeDevice{}, &kkProto.Success{}); err != nil {
return err
}
return nil
}

// FirmwareErase askes the device to erase its firmware
func (kk *Keepkey) FirmwareErase() error {

if _, err := kk.keepkeyExchange(&kkProto.FirmwareErase{}, &kkProto.Success{}); err != nil {
return err
}
return nil
}

func (kk *Keepkey) GetEntropy(size uint32) ([]byte, error) {
kkProto.GetEntropy

}

// UploadFirmware reads the contents of a given filepath and uploads data from the file
// to the device. It returns the number of bytes written and an error
func (kk *Keepkey) UploadFirmware(path string) (int, error) {
Expand Down
41 changes: 41 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package gokeepkey

import (
"log"
"os"
"testing"
)

var kk *Keepkey

func TestMain(m *testing.M) {
k, err := GetDevice()
if err != nil {
log.Fatal("No keepkey detected")
}
kk = k
os.Exit(m.Run())
}

func TestGetFeatures(t *testing.T) {
t.Log("Testing GetFeatures")
features, err := kk.GetFeatures()
if err != nil {
t.Fail()
}
if features.GetDeviceId() == "" {
t.Fail()
}
}

func TestPing(t *testing.T) {
t.Log("Testing Ping")
s, err := kk.Ping("Hello", false, false, false)
if err != nil || s.GetMessage() != "Hello" {
t.Fail()
}
s, err = kk.Ping("Button", true, false, false)
if err != nil || s.GetMessage() != "Button" {
t.Fail()
}
}

0 comments on commit b83ed13

Please sign in to comment.