Skip to content

Commit

Permalink
reorginization
Browse files Browse the repository at this point in the history
  • Loading branch information
solipsis committed Feb 20, 2018
1 parent 43fbee4 commit 20657c1
Show file tree
Hide file tree
Showing 4 changed files with 1,067 additions and 20 deletions.
7 changes: 7 additions & 0 deletions cmd/ping.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package cmd

import "fmt"

func main() {
fmt.Println("vim-go")
}
97 changes: 77 additions & 20 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,10 @@ func promptPin() (string, error) {
return res, nil
}

// ChangePin requests setting/changing/removing the pin
func (kk *Keepkey) ChangePin(remove bool) error {
// ChangePin requests setting/changing the pin
func (kk *Keepkey) ChangePin() error {

//TODO: separate change vs remove functions
change := &kkProto.ChangePin{
Remove: &remove,
}
change := &kkProto.ChangePin{}

// User may be prompted for pin up to 2 times
if _, err := kk.keepkeyExchange(change, &kkProto.PinMatrixRequest{}, &kkProto.Success{}); err != nil {
Expand All @@ -438,6 +435,21 @@ func (kk *Keepkey) ChangePin(remove bool) error {
return nil
}

// RemovePin disables pin protection for the device. If a pin is currently enabled
// it will prompt the user to enter the current pin
func (kk *Keepkey) RemovePin() error {

t := true
rem := &kkProto.ChangePin{
Remove: &t,
}

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

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

Expand Down Expand Up @@ -555,20 +567,6 @@ func (kk *Keepkey) Cancel() error {
return err
}

// *
// Request: Ask device to encrypt or decrypt value of given key
// @next CipheredKeyValue
// @next Failure
type CipherKeyValue struct {
AddressN []uint32 `protobuf:"varint,1,rep,name=address_n,json=addressN" json:"address_n,omitempty"`
Key *string `protobuf:"bytes,2,opt,name=key" json:"key,omitempty"`
Value []byte `protobuf:"bytes,3,opt,name=value" json:"value,omitempty"`
Encrypt *bool `protobuf:"varint,4,opt,name=encrypt" json:"encrypt,omitempty"`
AskOnEncrypt *bool `protobuf:"varint,5,opt,name=ask_on_encrypt,json=askOnEncrypt" json:"ask_on_encrypt,omitempty"`
AskOnDecrypt *bool `protobuf:"varint,6,opt,name=ask_on_decrypt,json=askOnDecrypt" json:"ask_on_decrypt,omitempty"`
Iv []byte `protobuf:"bytes,7,opt,name=iv" json:"iv,omitempty"`
}

// CipherKeyValue encrypts or decrypts a value with a given key, nodepath, and initializationVector
// This method encrypts if encrypt is true and decrypts if false, the confirm paramater determines wether
// the user is prompted on the device. See EncryptKeyValue() and DecryptKeyValue() for convenience methods
Expand Down Expand Up @@ -688,6 +686,7 @@ func (kk *Keepkey) EthereumSignTx(derivationPath []uint32, tx *EthereumTx) (*kkP
if tx.GasPrice != nil {
est.GasPrice = emptyOrVal(tx.GasPrice)
}
fmt.Println("forwarding eth")
return kk.ethereumSignTx(est)
}

Expand Down Expand Up @@ -794,6 +793,64 @@ func (kk *Keepkey) ethereumSignTx(est *kkProto.EthereumSignTx) (*kkProto.Ethereu
// TODO:
}

// *
// Response: Device asks for information for signing transaction or returns the last result
// If request_index is set, device awaits TxAck message (with fields filled in according to request_type)
// If signature_index is set, 'signature' contains signed input of signature_index's input
// @prev SignTx
// @prev SimpleSignTx
// @prev TxAck
type TxRequest struct {
RequestType *RequestType `protobuf:"varint,1,opt,name=request_type,json=requestType,enum=RequestType" json:"request_type,omitempty"`
Details *TxRequestDetailsType `protobuf:"bytes,2,opt,name=details" json:"details,omitempty"`
Serialized *TxRequestSerializedType `protobuf:"bytes,3,opt,name=serialized" json:"serialized,omitempty"`
XXX_unrecognized []byte `json:"-"`
}

// *
// Type of information required by transaction signing process
// @used_in TxRequest
type RequestType int32

const (
RequestType_TXINPUT RequestType = 0
RequestType_TXOUTPUT RequestType = 1
RequestType_TXMETA RequestType = 2
RequestType_TXFINISHED RequestType = 3
RequestType_TXEXTRADATA RequestType = 4
)

// *
// Structure representing request details
// @used_in TxRequest
type TxRequestDetailsType struct {
RequestIndex *uint32 `protobuf:"varint,1,opt,name=request_index,json=requestIndex" json:"request_index,omitempty"`
TxHash []byte `protobuf:"bytes,2,opt,name=tx_hash,json=txHash" json:"tx_hash,omitempty"`
ExtraDataLen *uint32 `protobuf:"varint,3,opt,name=extra_data_len,json=extraDataLen" json:"extra_data_len,omitempty"`
ExtraDataOffset *uint32 `protobuf:"varint,4,opt,name=extra_data_offset,json=extraDataOffset" json:"extra_data_offset,omitempty"`
XXX_unrecognized []byte `json:"-"`
}

// Structure representing serialized data
// @used_in TxRequest
type TxRequestSerializedType struct {
SignatureIndex *uint32 `protobuf:"varint,1,opt,name=signature_index,json=signatureIndex" json:"signature_index,omitempty"`
Signature []byte `protobuf:"bytes,2,opt,name=signature" json:"signature,omitempty"`
SerializedTx []byte `protobuf:"bytes,3,opt,name=serialized_tx,json=serializedTx" json:"serialized_tx,omitempty"`
XXX_unrecognized []byte `json:"-"`
}

func (kk *Keepkey) SignTx(outCount, inCount, version, locktime uint32, name string) {
// send SignTx
//kkProto.SignTx

// device responds with TxRequest
//kkProto.TxRequest
//kkProto.TxAck
// if details.request_idex. Send an ack with fields base on request type
// if serilazed.signatur_index signature contains signed input of signatur_index's input
}

func isDebugMessage(req interface{}) bool {
switch req.(type) {
case *kkProto.DebugLinkDecision, *kkProto.DebugLinkFillConfig, *kkProto.DebugLinkGetState:
Expand Down
File renamed without changes.
Loading

0 comments on commit 20657c1

Please sign in to comment.