Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: package build #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
23 changes: 23 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Go workspace file
go.work

_tools
go-keepkey
tags
TAGS
.DS_Store
151 changes: 78 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
# go-keepkey #
# go-keepkey

go-keepkey is a client library and CLI for interacting with Keepkey storage devices.
This library is unofficial and in development. For the official client see https://github.com/keepkey/python-keepkey

## Dependencies ##
## Dependencies

Since the device has transitioned to communicating over webUSB you need install libusb for your platform

brew install libusb
brew install libusb

## Installation

## Installation ##
go get -u github.com/keepkey/go-keepkey
go install github.com/keepkey/go-keepkey

## Command Line Interface (CLI)

go get -u github.com/solipsis/go-keepkey
go install github.com/solipsis/go-keepkey

## Command Line Interface (CLI) ##
```
```
go-keepkey --help

Usage:
go-keepkey [command]
go-keepkey [command]

Available Commands:
applyPolicy Enable/Disable a named policy
applySettings Update the label, language, and enable/disable the passphrase
changePin Change or add a pin to the device
clearSession Clear session data such as the pin session and passphrase
debugGetState Get device debug info. This REVEALS SECRETS and can only be used with debug enabled firmware
decryptKeyValue Decrypt a value with a given key and nodepath
encryptKeyValue Encrypt a value with a given key and nodepath
flashDump dump certain section of flash
flashHash Request hash of certain segment of flash memory
flashWrite Write data over flash sectors
getAddress Get an address for a coinType and nodePath
getEntropy Request sample data from the hardware RNG
getEthAddress Get the ethereum address for a given node path
getFeatures Ask the device for features and model information
getPublicKey Get a public key for a nodePath including the XPUB
help Help about any command
loadDevice Load the device from seed words
ping Ping the device with a message
recoverDevice Begin interactive device recovery
removePin Disable pin on the device
replay Replay messages in kk log format to the device
resetDevice Reset the device and generate a new seed using device RNG
signEthTx Sign an ethereum transaction
signMessage Sign a message using a given node path and coin
softReset Soft reset / power cycle the device. Only works on devices in manufacturer mode
upgradeFirmware Upgrade firmware to a specified tagged version or latest if none is specified
uploadFirmware Upload a new firmware binary to the device
verifyMessage Verify a signed message
wipeDevice Erase all sensitive information on the device
applyPolicy Enable/Disable a named policy
applySettings Update the label, language, and enable/disable the passphrase
changePin Change or add a pin to the device
clearSession Clear session data such as the pin session and passphrase
debugGetState Get device debug info. This REVEALS SECRETS and can only be used with debug enabled firmware
decryptKeyValue Decrypt a value with a given key and nodepath
encryptKeyValue Encrypt a value with a given key and nodepath
flashDump dump certain section of flash
flashHash Request hash of certain segment of flash memory
flashWrite Write data over flash sectors
getAddress Get an address for a coinType and nodePath
getEntropy Request sample data from the hardware RNG
getEthAddress Get the ethereum address for a given node path
getFeatures Ask the device for features and model information
getPublicKey Get a public key for a nodePath including the XPUB
help Help about any command
loadDevice Load the device from seed words
ping Ping the device with a message
recoverDevice Begin interactive device recovery
removePin Disable pin on the device
replay Replay messages in kk log format to the device
resetDevice Reset the device and generate a new seed using device RNG
signEthTx Sign an ethereum transaction
signMessage Sign a message using a given node path and coin
softReset Soft reset / power cycle the device. Only works on devices in manufacturer mode
upgradeFirmware Upgrade firmware to a specified tagged version or latest if none is specified
uploadFirmware Upload a new firmware binary to the device
verifyMessage Verify a signed message
wipeDevice Erase all sensitive information on the device

Flags:
--autoButton Automatic button pressing if debug link is enabled (default true)
--debug Debug level logging
-h, --help help for go-keepkey
--target string Device label or HID serial to connect to if more than one device is connected
--autoButton Automatic button pressing if debug link is enabled (default true)
--debug Debug level logging
-h, --help help for go-keepkey
--target string Device label or HID serial to connect to if more than one device is connected

```
```

## Usage ##
## Usage

```go
import "github.com/solipsis/go-keepkey/keepkey"
import "github.com/keepkey/go-keepkey/keepkey"
```

### Connect to all connected Keepkey devices ###
### Connect to all connected Keepkey devices

```go
devices, err := keepkey.GetDevices()
Expand All @@ -76,7 +76,7 @@ kk := devices[0]
features, err := kk.GetFeatures()
```

### Wipe the device and load with new seed words and settings ###
### Wipe the device and load with new seed words and settings

```go
kk.WipeDevice() // Error ignored
Expand All @@ -86,69 +86,74 @@ words := "water wink explain proof size gift silly sort collect differ anger yar
pin := "123"
label := "test"
usePassphrase := false
useChecksum := false
useChecksum := false

kk.LoadDevice(strings.Split(words, " "), pin, label, usePassphrase, useChecksum)
```
### Upload custom firmware ###

### Upload custom firmware

```go
path := "path/to/firmware.bin"
numBtyes, err := kk.UploadFirmware(path)
```

### Sign an ethereum transaction ###
### Sign an ethereum transaction

```go
var nonce uint64 = 20
recipient := "0x6b68c94fc31A10707f9c0f1281aad5ec9a4eeff0"
amount := big.NewInt(1337)
recipient := "0x6b68c94fc31A10707f9c0f1281aad5ec9a4eeff0"
amount := big.NewInt(1337)
gasLimit := big.NewInt(80000)
gasPrice := big.NewInt(22000000000)
data := []byte{}

// Create the transaction
tx := NewTransaction(nonce, recipient, amount, gasLimit, gasPrice, data)
tx := NewTransaction(nonce, recipient, amount, gasLimit, gasPrice, data)

// Ask the device to sign the transaction
tx, err := kk.EthereumSignTx(ethPath, tx)
if err != nil {
log.Fatalf("Unable to sign tx: %s", err)
}

// Encode the transaction as raw transaction hex string
raw, err := tx.ToRawTransaction()
if err != nil {
log.Fatalf("Unable to convert to raw tx:", err)
}
tx, err := kk.EthereumSignTx(ethPath, tx)
if err != nil {
log.Fatalf("Unable to sign tx: %s", err)
}

// Encode the transaction as raw transaction hex string
raw, err := tx.ToRawTransaction()
if err != nil {
log.Fatalf("Unable to convert to raw tx:", err)
}
fmt.Println(raw)
```

### Get an ethereum address for a BIP44 node ###
### Get an ethereum address for a BIP44 node

```go
nodePath := []uint32{0x8000002C, 0x8000003C, 0x80000000, 0x0, 0x01} // m/44'/60'/0'/0/1
display := true // display the address and QR code on the device screen

kk.EthereumGetAddress(nodePath, display)
```

### Get entropy sample from the device RNG ###
### Get entropy sample from the device RNG

```go
var entropy []byte
size := 1024 // number of bytes of entropy to request up to 1024 bytes
entropy, err := kk.GetEntropy(size)
```

## Development ##
## Development

### Regenerating Protobufs ###
### Regenerating Protobufs

Fetch the latest submoduled version

git submodule update --init --recursive
git submodule update --init --recursive

This project uses [retool](https://github.com/twitchtv/retool) to vendor tools such as protoc

go get github.com/twitchtv/retool
go get github.com/twitchtv/retool

Once retool is installed you can regenerate the protobufs using (from the project root)

retool do go generate ./...
retool do go generate ./...
2 changes: 1 addition & 1 deletion cmd/decryptKeyValue.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"github.com/solipsis/go-keepkey/pkg/keepkey"
"github.com/keepkey/go-keepkey/pkg/keepkey"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/encryptKeyValue.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"github.com/solipsis/go-keepkey/pkg/keepkey"
"github.com/keepkey/go-keepkey/pkg/keepkey"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/getAddress.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"github.com/solipsis/go-keepkey/pkg/keepkey"
"github.com/keepkey/go-keepkey/pkg/keepkey"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/getEthAddress.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"github.com/solipsis/go-keepkey/pkg/keepkey"
"github.com/keepkey/go-keepkey/pkg/keepkey"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/getPublicKey.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"os"

"github.com/solipsis/go-keepkey/pkg/keepkey"
"github.com/keepkey/go-keepkey/pkg/keepkey"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"io/ioutil"
"log"

"github.com/solipsis/go-keepkey/pkg/keepkey"
"github.com/keepkey/go-keepkey/pkg/keepkey"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/resetDevice.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"strings"

"github.com/solipsis/go-keepkey/pkg/keepkey"
"github.com/keepkey/go-keepkey/pkg/keepkey"
"github.com/spf13/cobra"
)

Expand Down
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import (
"log"
"os"

"github.com/keepkey/go-keepkey/pkg/keepkey"

"github.com/fatih/color"
"github.com/solipsis/go-keepkey/pkg/keepkey"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/signEthTx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"strconv"

"github.com/solipsis/go-keepkey/pkg/keepkey"
"github.com/keepkey/go-keepkey/pkg/keepkey"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/signMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"
"os"

"github.com/solipsis/go-keepkey/pkg/keepkey"
"github.com/keepkey/go-keepkey/pkg/keepkey"
"github.com/spf13/cobra"
)

Expand Down
2 changes: 1 addition & 1 deletion cmd/xpubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"text/tabwriter"

"github.com/fatih/color"
"github.com/solipsis/go-keepkey/pkg/keepkey"
"github.com/keepkey/go-keepkey/pkg/keepkey"
"github.com/spf13/cobra"
)

Expand Down
27 changes: 27 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module github.com/keepkey/go-keepkey

go 1.22.0

require (
github.com/ethereum/go-ethereum v1.13.14
github.com/fatih/color v1.16.0
github.com/golang/protobuf v1.5.3
github.com/google/go-github v17.0.0+incompatible
github.com/google/gousb v1.1.3
github.com/karalabe/hid v1.0.0
github.com/manifoldco/promptui v0.9.0
github.com/pkg/term v1.1.0
github.com/spf13/cobra v1.8.0
)

require (
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.16.0 // indirect
google.golang.org/protobuf v1.27.1 // indirect
)
Loading