From 9f57d86f20447a2c94ad6877cc054663b48dc5b4 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Wed, 10 May 2023 16:23:48 -0400 Subject: [PATCH 01/11] Add basic ledger wallet support Update upstream dependencies Don't print master key by default Allow empty private keys and mnemonics --- Makefile | 28 +++++------ cmd/wallet.go | 125 ++++++++++++++++++++++++++++++----------------- wallet/bip32.go | 47 +++++++++++++++--- wallet/wallet.go | 16 ++++++ 4 files changed, 149 insertions(+), 67 deletions(-) diff --git a/Makefile b/Makefile index 0e0680d..51dca10 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,12 @@ # Based on https://gist.github.com/trosendal/d4646812a43920bfe94e -DEPTAG := 1.0.7 -DEPLIBNAME := ed25519_bip32 +DEPTAG := 0.0.1 +DEPLIBNAME := spacemesh-sdk DEPLOC := https://github.com/spacemeshos/$(DEPLIBNAME)/releases/download -DEPLIB := lib$(DEPLIBNAME) -# Exclude dylib files (we only need the static libs) -EXCLUDE_PATTERN := "LICENSE" "*.so" "*.dylib" UNZIP_DEST := deps REAL_DEST := $(shell realpath .)/$(UNZIP_DEST) -DOWNLOAD_DEST := $(UNZIP_DEST)/$(DEPLIB).tar.gz -EXTLDFLAGS := -L$(UNZIP_DEST) -l$(DEPLIBNAME) +DOWNLOAD_DEST := $(UNZIP_DEST)/$(DEPLIBNAME).tar.gz +EXTLDFLAGS := -L$(UNZIP_DEST) -led25519_bip32 -lspacemesh_remote_wallet # Detect operating system ifeq ($(OS),Windows_NT) @@ -77,18 +74,14 @@ ifeq ($(SYSTEM),windows) RMDIR = rmdir /S /Q MKDIR = mkdir - FN = $(DEPLIB)_windows-amd64.zip - DOWNLOAD_DEST = $(UNZIP_DEST)/$(DEPLIB).zip + FN = $(DEPLIBNAME)_windows-amd64.tar.gz + DOWNLOAD_DEST = $(UNZIP_DEST)/$(DEPLIBNAME).zip EXTRACT = 7z x -y - - # TODO: fix this, it doesn't seem to work as expected - #EXCLUDES = -x!$(EXCLUDE_PATTERN) else # Linux and macOS settings RM = rm -f RMDIR = rm -rf MKDIR = mkdir -p - EXCLUDES = $(addprefix --exclude=,$(EXCLUDE_PATTERN)) EXTRACT = tar -xzf ifeq ($(GOARCH),amd64) @@ -98,11 +91,11 @@ else else $(error Unknown processor architecture: $(GOARCH)) endif - FN = $(DEPLIB)_$(PLATFORM).tar.gz + FN = $(DEPLIBNAME)_$(PLATFORM).tar.gz endif $(UNZIP_DEST): $(DOWNLOAD_DEST) - cd $(UNZIP_DEST) && $(EXTRACT) ../$(DOWNLOAD_DEST) $(EXCLUDES) + cd $(UNZIP_DEST) && $(EXTRACT) ../$(DOWNLOAD_DEST) $(DOWNLOAD_DEST): $(MKDIR) $(UNZIP_DEST) @@ -125,7 +118,10 @@ build: $(UNZIP_DEST) .PHONY: test test: $(UNZIP_DEST) - LD_LIBRARY_PATH=$(REAL_DEST) go test -v -ldflags "-extldflags \"-L$(REAL_DEST) -led25519_bip32\"" ./... + CGO_CFLAGS="-I$(REAL_DEST)" \ + CGO_LDFLAGS="-L$(REAL_DEST)" \ + LD_LIBRARY_PATH=$(REAL_DEST) \ + go test -v -count 1 -ldflags "-extldflags \"$(EXTLDFLAGS)\"" ./... .PHONY: test-tidy test-tidy: diff --git a/cmd/wallet.go b/cmd/wallet.go index db5aa58..d92b677 100644 --- a/cmd/wallet.go +++ b/cmd/wallet.go @@ -30,6 +30,12 @@ var ( // printBase58 indicates that keys should be printed in base58 format. printBase58 bool + + // printParent indicates that the parent key should be printed. + printParent bool + + // useLedger indicates that the Ledger device should be used. + useLedger bool ) // walletCmd represents the wallet command. @@ -46,10 +52,14 @@ to quickly create a Cobra application.`, // createCmd represents the create command. var createCmd = &cobra.Command{ - Use: "create [numaccounts]", - Short: "Generate a new wallet file from a BIP-39-compatible mnemonic", - Long: `Create a new wallet file containing one or more accounts using a BIP-39-compatible mnemonic. -You can choose to use an existing mnemonic or generate a new, random mnemonic.`, + Use: "create [--ledger] [numaccounts]", + Short: "Generate a new wallet file from a BIP-39-compatible mnemonic or Ledger device", + Long: `Create a new wallet file containing one or more accounts using a BIP-39-compatible mnemonic +or a Ledger hardware wallet. If using a mnemonic you can choose to use an existing mnemonic or generate +a new, random mnemonic. + +Add --ledger to instead read the public key from a Ledger device. If using a Ledger device please make +sure the device is connected, unlocked, and the Spacemesh app is open.`, Args: cobra.MaximumNArgs(1), Run: func(cmd *cobra.Command, args []string) { // get the number of accounts to create @@ -60,31 +70,41 @@ You can choose to use an existing mnemonic or generate a new, random mnemonic.`, n = int(tmpN) } - // get or generate the mnemonic - fmt.Print("Enter a BIP-39-compatible mnemonic (or leave blank to generate a new one): ") - text, err := password.Read(os.Stdin) - fmt.Println() - cobra.CheckErr(err) - fmt.Println("Note: This application does not yet support BIP-39-compatible optional passwords. Support will be added soon.") - - // It's critical that we trim whitespace, including CRLF. Otherwise it will get included in the mnemonic. - text = strings.TrimSpace(text) - var w *wallet.Wallet - if text == "" { - w, err = wallet.NewMultiWalletRandomMnemonic(n) + var err error + + // Short-circuit and check for a ledger device + if useLedger { + w, err = wallet.NewMultiWalletFromLedger(n) cobra.CheckErr(err) - fmt.Println("\nThis is your mnemonic (seed phrase). Write it down and store it safely. It is the ONLY way to restore your wallet.") - fmt.Println("Neither Spacemesh nor anyone else can help you restore your wallet without this mnemonic.") - fmt.Println("\n***********************************\nSAVE THIS MNEMONIC IN A SAFE PLACE!\n***********************************") - fmt.Println() - fmt.Println(w.Mnemonic()) - fmt.Println("\nPress enter when you have securely saved your mnemonic.") - _, _ = fmt.Scanln() + fmt.Println("Note that, when using a hardware wallet, the wallet file I'm about to produce won't " + + "contain any private keys or mnemonics, but you may still choose to encrypt it to protect privacy.") } else { - // try to use as a mnemonic - w, err = wallet.NewMultiWalletFromMnemonic(text, n) + // get or generate the mnemonic + fmt.Print("Enter a BIP-39-compatible mnemonic (or leave blank to generate a new one): ") + text, err := password.Read(os.Stdin) + fmt.Println() cobra.CheckErr(err) + fmt.Println("Note: This application does not yet support BIP-39-compatible optional passwords. Support will be added soon.") + + // It's critical that we trim whitespace, including CRLF. Otherwise it will get included in the mnemonic. + text = strings.TrimSpace(text) + + if text == "" { + w, err = wallet.NewMultiWalletRandomMnemonic(n) + cobra.CheckErr(err) + fmt.Println("\nThis is your mnemonic (seed phrase). Write it down and store it safely. It is the ONLY way to restore your wallet.") + fmt.Println("Neither Spacemesh nor anyone else can help you restore your wallet without this mnemonic.") + fmt.Println("\n***********************************\nSAVE THIS MNEMONIC IN A SAFE PLACE!\n***********************************") + fmt.Println() + fmt.Println(w.Mnemonic()) + fmt.Println("\nPress enter when you have securely saved your mnemonic.") + _, _ = fmt.Scanln() + } else { + // try to use as a mnemonic + w, err = wallet.NewMultiWalletFromMnemonic(text, n) + cobra.CheckErr(err) + } } fmt.Print("Enter a secure password used to encrypt the wallet file (optional but strongly recommended): ") @@ -125,7 +145,8 @@ var readCmd = &cobra.Command{ successfully read and decrypted, whether the password to open the file is correct, etc. It prints the accounts from the wallet file. By default it does not print private keys. Add --private to print private keys. Add --full to print full keys. Add --base58 to print -keys in base58 format rather than hexadecimal.`, +keys in base58 format rather than hexadecimal. Add --parent to print parent key (and not +only child keys).`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { walletFn := args[0] @@ -201,36 +222,48 @@ keys in base58 format rather than hexadecimal.`, }) } - // print the master keypair - master := w.Secrets.MasterKeypair + // set the encoder encoder := hex.EncodeToString if printBase58 { encoder = base58.Encode } - if master != nil { - if printPrivate { - t.AppendRow(table.Row{ - encoder(master.Public), - encoder(master.Private), - master.Path.String(), - master.DisplayName, - master.Created, - }) - } else { - t.AppendRow(table.Row{ - encoder(master.Public), - master.Path.String(), - master.DisplayName, - master.Created, - }) + + privKeyEncoder := func(privKey []byte) string { + if privKey == nil { + return "(none)" + } + return encoder(privKey) + } + + // print the master account + if printParent { + master := w.Secrets.MasterKeypair + if master != nil { + if printPrivate { + t.AppendRow(table.Row{ + encoder(master.Public), + privKeyEncoder(master.Private), + master.Path.String(), + master.DisplayName, + master.Created, + }) + } else { + t.AppendRow(table.Row{ + encoder(master.Public), + master.Path.String(), + master.DisplayName, + master.Created, + }) + } } } + // print child accounts for _, a := range w.Secrets.Accounts { if printPrivate { t.AppendRow(table.Row{ encoder(a.Public), - encoder(a.Private), + privKeyEncoder(a.Private), a.Path.String(), a.DisplayName, a.Created, @@ -255,5 +288,7 @@ func init() { readCmd.Flags().BoolVarP(&printPrivate, "private", "p", false, "Print private keys") readCmd.Flags().BoolVarP(&printFull, "full", "f", false, "Print full keys (no abbreviation)") readCmd.Flags().BoolVar(&printBase58, "base58", false, "Print keys in base58 (rather than hex)") + readCmd.Flags().BoolVar(&printParent, "parent", false, "Print parent key (not only child keys)") readCmd.PersistentFlags().BoolVarP(&debug, "debug", "d", false, "enable debug mode") + createCmd.Flags().BoolVarP(&useLedger, "ledger", "l", false, "Create a wallet using a Ledger device") } diff --git a/wallet/bip32.go b/wallet/bip32.go index 262262e..8e7dcb6 100644 --- a/wallet/bip32.go +++ b/wallet/bip32.go @@ -7,6 +7,7 @@ import ( "fmt" smbip32 "github.com/spacemeshos/smkeys/bip32" + ledger "github.com/spacemeshos/smkeys/remote-wallet" "github.com/spacemeshos/smcli/common" ) @@ -16,6 +17,13 @@ import ( type PublicKey ed25519.PublicKey +type keyType int + +const ( + typeSoftware keyType = iota + typeLedger +) + func (k *PublicKey) MarshalJSON() ([]byte, error) { return json.Marshal(hex.EncodeToString(*k)) } @@ -50,6 +58,7 @@ type EDKeyPair struct { Path HDPath `json:"path"` Public PublicKey `json:"publicKey"` Private PrivateKey `json:"secretKey"` + KeyType keyType `json:"keyType"` } func NewMasterKeyPair(seed []byte) (*EDKeyPair, error) { @@ -70,15 +79,41 @@ func NewMasterKeyPair(seed []byte) (*EDKeyPair, error) { func (kp *EDKeyPair) NewChildKeyPair(seed []byte, childIdx int) (*EDKeyPair, error) { path := kp.Path.Extend(BIP44HardenedAccountIndex(uint32(childIdx))) - key, err := smbip32.Derive(HDPathToString(path), seed) + if kp.KeyType == typeLedger { + return pubkeyFromLedger(path) + } else if kp.KeyType == typeSoftware { + key, err := smbip32.Derive(HDPathToString(path), seed) + if err != nil { + return nil, err + } + return &EDKeyPair{ + DisplayName: fmt.Sprintf("Child Key %d", childIdx), + Created: common.NowTimeString(), + Private: key[:], + Public: PublicKey(ed25519.PrivateKey(key[:]).Public().(ed25519.PublicKey)), + Path: path, + }, nil + } else { + return nil, fmt.Errorf("unknown key type") + } +} + +func NewMasterKeyPairFromLedger() (*EDKeyPair, error) { + return pubkeyFromLedger(DefaultPath()) +} + +func pubkeyFromLedger(path HDPath) (*EDKeyPair, error) { + // TODO: support multiple ledger devices (https://github.com/spacemeshos/smcli/issues/46) + key, err := ledger.ReadPubkeyFromLedger("", HDPathToString(path), true) if err != nil { - return nil, err + return nil, fmt.Errorf("error reading pubkey from ledger. Are you sure it's connected, unlocked, and the Spacemesh app is open? err: %w", err) } + return &EDKeyPair{ - DisplayName: fmt.Sprintf("Child Key %d", childIdx), + DisplayName: "Master Ledger Key", Created: common.NowTimeString(), - Private: key[:], - Public: PublicKey(ed25519.PrivateKey(key[:]).Public().(ed25519.PublicKey)), - Path: path, + // note: we do not set a Private key here (it lives on the device) + Public: key[:], + Path: path, }, nil } diff --git a/wallet/wallet.go b/wallet/wallet.go index ed7fd61..338b53c 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -108,6 +108,22 @@ func NewMultiWalletFromMnemonic(m string, n int) (*Wallet, error) { return walletFromMnemonicAndAccounts(m, masterKeyPair, accounts) } +func NewMultiWalletFromLedger(n int) (*Wallet, error) { + if n < 0 || n > common.MaxAccountsPerWallet { + return nil, fmt.Errorf("invalid number of accounts") + } + masterKeyPair, err := NewMasterKeyPairFromLedger() + if err != nil { + return nil, err + } + // seed is not used in case of ledger + accounts, err := accountsFromMaster(masterKeyPair, []byte{}, n) + if err != nil { + return nil, err + } + return walletFromMnemonicAndAccounts("(none)", masterKeyPair, accounts) +} + func walletFromMnemonicAndAccounts(m string, masterKp *EDKeyPair, kp []*EDKeyPair) (*Wallet, error) { w := &Wallet{ Meta: walletMetadata{ From 524275e9e9e00f62be6b3a2392980775753f121d Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Wed, 10 May 2023 17:25:24 -0400 Subject: [PATCH 02/11] Bugfixes and misc. improvements Correctly print missing privkey, set key names correctly when using ledger Don't prompt twice on device when creating keys --- cmd/wallet.go | 2 +- wallet/bip32.go | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/cmd/wallet.go b/cmd/wallet.go index d92b677..a19d22b 100644 --- a/cmd/wallet.go +++ b/cmd/wallet.go @@ -229,7 +229,7 @@ only child keys).`, } privKeyEncoder := func(privKey []byte) string { - if privKey == nil { + if len(privKey) == 0 { return "(none)" } return encoder(privKey) diff --git a/wallet/bip32.go b/wallet/bip32.go index 8e7dcb6..8b7b238 100644 --- a/wallet/bip32.go +++ b/wallet/bip32.go @@ -80,7 +80,7 @@ func NewMasterKeyPair(seed []byte) (*EDKeyPair, error) { func (kp *EDKeyPair) NewChildKeyPair(seed []byte, childIdx int) (*EDKeyPair, error) { path := kp.Path.Extend(BIP44HardenedAccountIndex(uint32(childIdx))) if kp.KeyType == typeLedger { - return pubkeyFromLedger(path) + return pubkeyFromLedger(path, false) } else if kp.KeyType == typeSoftware { key, err := smbip32.Derive(HDPathToString(path), seed) if err != nil { @@ -99,21 +99,29 @@ func (kp *EDKeyPair) NewChildKeyPair(seed []byte, childIdx int) (*EDKeyPair, err } func NewMasterKeyPairFromLedger() (*EDKeyPair, error) { - return pubkeyFromLedger(DefaultPath()) + return pubkeyFromLedger(DefaultPath(), true) } -func pubkeyFromLedger(path HDPath) (*EDKeyPair, error) { +func pubkeyFromLedger(path HDPath, master bool) (*EDKeyPair, error) { // TODO: support multiple ledger devices (https://github.com/spacemeshos/smcli/issues/46) - key, err := ledger.ReadPubkeyFromLedger("", HDPathToString(path), true) + // don't bother confirming the master key; we only want the user to have to confirm a single key, + // the one they really care about, which is the first child key. + key, err := ledger.ReadPubkeyFromLedger("", HDPathToString(path), !master) if err != nil { return nil, fmt.Errorf("error reading pubkey from ledger. Are you sure it's connected, unlocked, and the Spacemesh app is open? err: %w", err) } + name := "Ledger Master Key" + if !master { + name = "Ledger Child Key" + } + return &EDKeyPair{ - DisplayName: "Master Ledger Key", + DisplayName: name, Created: common.NowTimeString(), // note: we do not set a Private key here (it lives on the device) - Public: key[:], - Path: path, + Public: key[:], + Path: path, + KeyType: typeLedger, }, nil } From 9789dbcbd68078baa0d71bb972c6f9da31973807 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Wed, 10 May 2023 17:41:55 -0400 Subject: [PATCH 03/11] Remove musl toolchain Add required dylibs on Linux --- Makefile | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 51dca10..fdc2039 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ DEPLOC := https://github.com/spacemeshos/$(DEPLIBNAME)/releases/download UNZIP_DEST := deps REAL_DEST := $(shell realpath .)/$(UNZIP_DEST) DOWNLOAD_DEST := $(UNZIP_DEST)/$(DEPLIBNAME).tar.gz -EXTLDFLAGS := -L$(UNZIP_DEST) -led25519_bip32 -lspacemesh_remote_wallet +STATICLDFLAGS := -L$(UNZIP_DEST) -led25519_bip32 -lspacemesh_remote_wallet # Detect operating system ifeq ($(OS),Windows_NT) @@ -49,19 +49,18 @@ ifeq ($(GOOS),linux) MACHINE = linux # Linux specific settings - # We do a static build on Linux using musl toolchain - CPREFIX = CC=musl-gcc - LDFLAGS = -linkmode external -extldflags "-static $(EXTLDFLAGS)" + # We statically link our own libraries and dynamically link other required libraries + LDFLAGS = -linkmode external -extldflags "-Wl,-Bstatic $(STATICLDFLAGS) -Wl,-Bdynamic -ludev -lm" else ifeq ($(GOOS),darwin) MACHINE = macos # macOS specific settings # dynamic build using default toolchain - LDFLAGS = -extldflags "$(EXTLDFLAGS)" + LDFLAGS = -extldflags "$(STATICLDFLAGS)" else ifeq ($(GOOS),windows) # static build using default toolchain # add a few extra required libs - LDFLAGS = -linkmode external -extldflags "-static $(EXTLDFLAGS) -lws2_32 -luserenv -lbcrypt" + LDFLAGS = -linkmode external -extldflags "-static $(STATICLDFLAGS) -lws2_32 -luserenv -lbcrypt" else $(error Unknown operating system: $(GOOS)) endif @@ -114,14 +113,19 @@ tidy: .PHONY: build build: $(UNZIP_DEST) - $(CPREFIX) GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=1 go build -ldflags '$(LDFLAGS)' + CGO_CFLAGS="-I$(REAL_DEST)" \ + CGO_LDFLAGS="-L$(REAL_DEST)" \ + GOOS=$(GOOS) \ + GOARCH=$(GOARCH) \ + CGO_ENABLED=1 \ + go build -ldflags '$(LDFLAGS)' .PHONY: test test: $(UNZIP_DEST) CGO_CFLAGS="-I$(REAL_DEST)" \ CGO_LDFLAGS="-L$(REAL_DEST)" \ LD_LIBRARY_PATH=$(REAL_DEST) \ - go test -v -count 1 -ldflags "-extldflags \"$(EXTLDFLAGS)\"" ./... + go test -v -count 1 -ldflags "-extldflags \"$(STATICLDFLAGS)\"" ./... .PHONY: test-tidy test-tidy: From 9e9f38c81d4a64217a2fb8b02dc1b0650f1b168b Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 11 May 2023 15:11:47 -0400 Subject: [PATCH 04/11] Factor in review comments --- go.mod | 2 +- go.sum | 4 ++-- wallet/bip32.go | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index b435aaa..22b2403 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.18 require ( github.com/btcsuite/btcutil v1.0.2 github.com/jedib0t/go-pretty/v6 v6.4.6 - github.com/spacemeshos/smkeys v1.0.2 + github.com/spacemeshos/smkeys v1.0.3-0.20230511190607-5b2cfe71b4ba github.com/stretchr/testify v1.8.2 ) diff --git a/go.sum b/go.sum index 3f09e27..a5e41be 100644 --- a/go.sum +++ b/go.sum @@ -183,8 +183,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/spacemeshos/smkeys v1.0.2 h1:6bD2+CsLkd+gNUojyvjyu/5dvxMKktkGndtuFqTbK+s= -github.com/spacemeshos/smkeys v1.0.2/go.mod h1:gj9yv0Zek5D9p6zWmVV/2d0WdhPwyKXDMQm2MpmxIow= +github.com/spacemeshos/smkeys v1.0.3-0.20230511190607-5b2cfe71b4ba h1:r3HTtml9uDAdpqiZDbZcIO/Xt1w+kjHE8QHe2wudrVk= +github.com/spacemeshos/smkeys v1.0.3-0.20230511190607-5b2cfe71b4ba/go.mod h1:gj9yv0Zek5D9p6zWmVV/2d0WdhPwyKXDMQm2MpmxIow= github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= diff --git a/wallet/bip32.go b/wallet/bip32.go index 8b7b238..10d7c53 100644 --- a/wallet/bip32.go +++ b/wallet/bip32.go @@ -79,9 +79,10 @@ func NewMasterKeyPair(seed []byte) (*EDKeyPair, error) { func (kp *EDKeyPair) NewChildKeyPair(seed []byte, childIdx int) (*EDKeyPair, error) { path := kp.Path.Extend(BIP44HardenedAccountIndex(uint32(childIdx))) - if kp.KeyType == typeLedger { + switch kp.KeyType { + case typeLedger: return pubkeyFromLedger(path, false) - } else if kp.KeyType == typeSoftware { + case typeSoftware: key, err := smbip32.Derive(HDPathToString(path), seed) if err != nil { return nil, err @@ -90,10 +91,10 @@ func (kp *EDKeyPair) NewChildKeyPair(seed []byte, childIdx int) (*EDKeyPair, err DisplayName: fmt.Sprintf("Child Key %d", childIdx), Created: common.NowTimeString(), Private: key[:], - Public: PublicKey(ed25519.PrivateKey(key[:]).Public().(ed25519.PublicKey)), + Public: PublicKey(ed25519.PrivateKey(key).Public().(ed25519.PublicKey)), Path: path, }, nil - } else { + default: return nil, fmt.Errorf("unknown key type") } } From 6985cda6b0527d67e384de5d45de77bb8323c21d Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 11 May 2023 15:50:23 -0400 Subject: [PATCH 05/11] Attempt to fix CI workflow Remove musl as it's no longer needed Run golangci-lint through an action Set necessary env vars in Makefile for staticcheck --- .github/workflows/ci.yml | 26 +++----------------------- Makefile | 4 +++- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4468b7a..b6d483c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,11 +21,6 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ env.go-version }} - - name: install musl - uses: awalsh128/cache-apt-pkgs-action@v1 - with: - packages: musl-tools # provides musl-gcc - version: 1.0 - name: fmt, tidy run: | make install @@ -44,15 +39,8 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ env.go-version }} - - name: install musl - uses: awalsh128/cache-apt-pkgs-action@v1 - with: - packages: musl-tools # provides musl-gcc - version: 1.0 - - name: setup env - run: make install - name: lint - run: make lint-github-action + uses: golangci/golangci-lint-action@v3 build: runs-on: ubuntu-latest @@ -60,15 +48,12 @@ jobs: steps: - name: checkout uses: actions/checkout@v3 + - name: install udev + run: sudo apt-get install -y libudev-dev - name: set up go uses: actions/setup-go@v4 with: go-version: ${{ env.go-version }} - - name: install musl - uses: awalsh128/cache-apt-pkgs-action@v1 - with: - packages: musl-tools # provides musl-gcc - version: 1.0 - name: build run: make build @@ -82,10 +67,5 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ env.go-version }} - - name: install musl - uses: awalsh128/cache-apt-pkgs-action@v1 - with: - packages: musl-tools # provides musl-gcc - version: 1.0 - name: go test run: make test diff --git a/Makefile b/Makefile index fdc2039..55c8fae 100644 --- a/Makefile +++ b/Makefile @@ -103,7 +103,6 @@ $(DOWNLOAD_DEST): .PHONY: install install: go mod download - curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.52.0 go install gotest.tools/gotestsum@v1.9.0 go install honnef.co/go/tools/cmd/staticcheck@v0.3.3 @@ -157,6 +156,9 @@ lint-github-action: .PHONY: staticcheck staticcheck: + CGO_CFLAGS="-I$(REAL_DEST)" \ + CGO_LDFLAGS="-L$(REAL_DEST)" \ + LD_LIBRARY_PATH=$(REAL_DEST) \ staticcheck ./... clean: From 1ef9ecbb0b8324bd0e3ad55e2a9e5eb575bd3bf3 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 11 May 2023 15:56:00 -0400 Subject: [PATCH 06/11] Update dependencies --- go.mod | 8 ++++---- go.sum | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index 22b2403..06bf83d 100644 --- a/go.mod +++ b/go.mod @@ -17,11 +17,11 @@ require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/magiconair/properties v1.8.7 // indirect - github.com/mattn/go-runewidth v0.0.13 // indirect + github.com/mattn/go-runewidth v0.0.14 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/pelletier/go-toml/v2 v2.0.7 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/rivo/uniseg v0.2.0 // indirect + github.com/rivo/uniseg v0.4.4 // indirect github.com/spf13/afero v1.9.5 // indirect github.com/spf13/cast v1.5.0 // indirect github.com/spf13/cobra v1.7.0 @@ -31,9 +31,9 @@ require ( github.com/subosito/gotenv v1.4.2 // indirect github.com/tyler-smith/go-bip39 v1.1.0 github.com/xdg-go/pbkdf2 v1.0.0 - golang.org/x/crypto v0.8.0 // indirect + golang.org/x/crypto v0.9.0 // indirect golang.org/x/sys v0.8.0 // indirect - golang.org/x/term v0.7.0 // indirect + golang.org/x/term v0.8.0 // indirect golang.org/x/text v0.9.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/ini.v1 v1.67.0 // indirect diff --git a/go.sum b/go.sum index a5e41be..eb1db0f 100644 --- a/go.sum +++ b/go.sum @@ -163,6 +163,8 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= +github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= @@ -179,6 +181,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= +github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= @@ -239,6 +243,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ= golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= +golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= +golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -380,6 +386,8 @@ golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuX golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ= golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= +golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= From 526c493895046c25fc9f3dc5e38bb19535a08c15 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 11 May 2023 16:00:56 -0400 Subject: [PATCH 07/11] Ran go mod tidy --- go.sum | 4 ---- 1 file changed, 4 deletions(-) diff --git a/go.sum b/go.sum index eb1db0f..d53cfab 100644 --- a/go.sum +++ b/go.sum @@ -161,7 +161,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= -github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -179,7 +178,6 @@ github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qR github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= @@ -241,7 +239,6 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.8.0 h1:pd9TJtTueMTVQXzk8E2XESSMQDj/U7OUu0PqJqPXQjQ= golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= @@ -384,7 +381,6 @@ golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.7.0 h1:BEvjmm5fURWqcfbSKTdpkDXYBrUS1c0m8agp14W48vQ= golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= From 866956cf70c9b34fb72ada86d150d83ef2e8e654 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 11 May 2023 16:04:14 -0400 Subject: [PATCH 08/11] Fix linting --- .github/workflows/ci.yml | 4 +++- Makefile | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b6d483c..505debe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,8 +39,10 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ env.go-version }} + - name: setup env + run: make install - name: lint - uses: golangci/golangci-lint-action@v3 + run: make lint-github-action build: runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index 55c8fae..1cbc903 100644 --- a/Makefile +++ b/Makefile @@ -103,6 +103,7 @@ $(DOWNLOAD_DEST): .PHONY: install install: go mod download + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.52.0 go install gotest.tools/gotestsum@v1.9.0 go install honnef.co/go/tools/cmd/staticcheck@v0.3.3 @@ -143,15 +144,24 @@ test-fmt: .PHONY: lint lint: + CGO_CFLAGS="-I$(REAL_DEST)" \ + CGO_LDFLAGS="-L$(REAL_DEST)" \ + LD_LIBRARY_PATH=$(REAL_DEST) \ ./bin/golangci-lint run --config .golangci.yml # Auto-fixes golangci-lint issues where possible. .PHONY: lint-fix lint-fix: + CGO_CFLAGS="-I$(REAL_DEST)" \ + CGO_LDFLAGS="-L$(REAL_DEST)" \ + LD_LIBRARY_PATH=$(REAL_DEST) \ ./bin/golangci-lint run --config .golangci.yml --fix .PHONY: lint-github-action lint-github-action: + CGO_CFLAGS="-I$(REAL_DEST)" \ + CGO_LDFLAGS="-L$(REAL_DEST)" \ + LD_LIBRARY_PATH=$(REAL_DEST) \ ./bin/golangci-lint run --config .golangci.yml --out-format=github-actions .PHONY: staticcheck From 2c77ed3d2cf3d354a0a0f9b0dc28b1603715cac6 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Thu, 11 May 2023 16:12:51 -0400 Subject: [PATCH 09/11] Fix up makefile recipes and GH workflow --- .github/workflows/ci.yml | 3 --- Makefile | 14 +++++++------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 505debe..85d257e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,7 +23,6 @@ jobs: go-version: ${{ env.go-version }} - name: fmt, tidy run: | - make install make test-fmt make test-tidy - name: staticcheck @@ -39,8 +38,6 @@ jobs: uses: actions/setup-go@v4 with: go-version: ${{ env.go-version }} - - name: setup env - run: make install - name: lint run: make lint-github-action diff --git a/Makefile b/Makefile index 1cbc903..e642b2a 100644 --- a/Makefile +++ b/Makefile @@ -101,7 +101,7 @@ $(DOWNLOAD_DEST): curl -sSfL $(DEPLOC)/v$(DEPTAG)/$(FN) -o $(DOWNLOAD_DEST) .PHONY: install -install: +install: $(UNZIP_DEST) go mod download curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.52.0 go install gotest.tools/gotestsum@v1.9.0 @@ -128,7 +128,7 @@ test: $(UNZIP_DEST) go test -v -count 1 -ldflags "-extldflags \"$(STATICLDFLAGS)\"" ./... .PHONY: test-tidy -test-tidy: +test-tidy: install # Working directory must be clean, or this test would be destructive git diff --quiet || (echo "\033[0;31mWorking directory not clean!\033[0m" && git --no-pager diff && exit 1) # We expect `go mod tidy` not to change anything, the test should fail otherwise @@ -136,14 +136,14 @@ test-tidy: git diff --exit-code || (git --no-pager diff && git checkout . && exit 1) .PHONY: test-fmt -test-fmt: +test-fmt: install git diff --quiet || (echo "\033[0;31mWorking directory not clean!\033[0m" && git --no-pager diff && exit 1) # We expect `go fmt` not to change anything, the test should fail otherwise go fmt ./... git diff --exit-code || (git --no-pager diff && git checkout . && exit 1) .PHONY: lint -lint: +lint: install CGO_CFLAGS="-I$(REAL_DEST)" \ CGO_LDFLAGS="-L$(REAL_DEST)" \ LD_LIBRARY_PATH=$(REAL_DEST) \ @@ -151,21 +151,21 @@ lint: # Auto-fixes golangci-lint issues where possible. .PHONY: lint-fix -lint-fix: +lint-fix: install CGO_CFLAGS="-I$(REAL_DEST)" \ CGO_LDFLAGS="-L$(REAL_DEST)" \ LD_LIBRARY_PATH=$(REAL_DEST) \ ./bin/golangci-lint run --config .golangci.yml --fix .PHONY: lint-github-action -lint-github-action: +lint-github-action: install CGO_CFLAGS="-I$(REAL_DEST)" \ CGO_LDFLAGS="-L$(REAL_DEST)" \ LD_LIBRARY_PATH=$(REAL_DEST) \ ./bin/golangci-lint run --config .golangci.yml --out-format=github-actions .PHONY: staticcheck -staticcheck: +staticcheck: $(UNZIP_DEST) CGO_CFLAGS="-I$(REAL_DEST)" \ CGO_LDFLAGS="-L$(REAL_DEST)" \ LD_LIBRARY_PATH=$(REAL_DEST) \ From 281c8f6f4cf161e14ca1f04b8efda7ed59a262a8 Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Sat, 13 May 2023 15:47:01 -0400 Subject: [PATCH 10/11] Update github.com/spacemeshos/smkeys dependency --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 06bf83d..50a3f88 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.18 require ( github.com/btcsuite/btcutil v1.0.2 github.com/jedib0t/go-pretty/v6 v6.4.6 - github.com/spacemeshos/smkeys v1.0.3-0.20230511190607-5b2cfe71b4ba + github.com/spacemeshos/smkeys v1.0.3 github.com/stretchr/testify v1.8.2 ) diff --git a/go.sum b/go.sum index d53cfab..f30086c 100644 --- a/go.sum +++ b/go.sum @@ -185,8 +185,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/spacemeshos/smkeys v1.0.3-0.20230511190607-5b2cfe71b4ba h1:r3HTtml9uDAdpqiZDbZcIO/Xt1w+kjHE8QHe2wudrVk= -github.com/spacemeshos/smkeys v1.0.3-0.20230511190607-5b2cfe71b4ba/go.mod h1:gj9yv0Zek5D9p6zWmVV/2d0WdhPwyKXDMQm2MpmxIow= +github.com/spacemeshos/smkeys v1.0.3 h1:v1O8NgRtSTCMBClvBM/MqxWJ35moKYURadFDwZRQki4= +github.com/spacemeshos/smkeys v1.0.3/go.mod h1:gj9yv0Zek5D9p6zWmVV/2d0WdhPwyKXDMQm2MpmxIow= github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM= github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ= github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= From c7cbcd4f30aa5f2fb4632753a88e93dfe33c97ee Mon Sep 17 00:00:00 2001 From: Lane Rettig Date: Sat, 13 May 2023 16:25:37 -0400 Subject: [PATCH 11/11] Clean up Makefile recipes and CI workflow Fix previous commit based on review feedback --- .github/workflows/ci.yml | 5 ++++- .gitignore | 3 +++ Makefile | 12 ++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 85d257e..a76b964 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,7 @@ jobs: go-version: ${{ env.go-version }} - name: fmt, tidy run: | + make install make test-fmt make test-tidy - name: staticcheck @@ -39,7 +40,9 @@ jobs: with: go-version: ${{ env.go-version }} - name: lint - run: make lint-github-action + run: | + make install + make lint-github-action build: runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 3383004..304de18 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,6 @@ deps/ go.work .idea + +# Default build artifact +smcli \ No newline at end of file diff --git a/Makefile b/Makefile index e642b2a..3284a83 100644 --- a/Makefile +++ b/Makefile @@ -101,7 +101,7 @@ $(DOWNLOAD_DEST): curl -sSfL $(DEPLOC)/v$(DEPTAG)/$(FN) -o $(DOWNLOAD_DEST) .PHONY: install -install: $(UNZIP_DEST) +install: go mod download curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.52.0 go install gotest.tools/gotestsum@v1.9.0 @@ -128,7 +128,7 @@ test: $(UNZIP_DEST) go test -v -count 1 -ldflags "-extldflags \"$(STATICLDFLAGS)\"" ./... .PHONY: test-tidy -test-tidy: install +test-tidy: # Working directory must be clean, or this test would be destructive git diff --quiet || (echo "\033[0;31mWorking directory not clean!\033[0m" && git --no-pager diff && exit 1) # We expect `go mod tidy` not to change anything, the test should fail otherwise @@ -136,14 +136,14 @@ test-tidy: install git diff --exit-code || (git --no-pager diff && git checkout . && exit 1) .PHONY: test-fmt -test-fmt: install +test-fmt: git diff --quiet || (echo "\033[0;31mWorking directory not clean!\033[0m" && git --no-pager diff && exit 1) # We expect `go fmt` not to change anything, the test should fail otherwise go fmt ./... git diff --exit-code || (git --no-pager diff && git checkout . && exit 1) .PHONY: lint -lint: install +lint: CGO_CFLAGS="-I$(REAL_DEST)" \ CGO_LDFLAGS="-L$(REAL_DEST)" \ LD_LIBRARY_PATH=$(REAL_DEST) \ @@ -151,14 +151,14 @@ lint: install # Auto-fixes golangci-lint issues where possible. .PHONY: lint-fix -lint-fix: install +lint-fix: CGO_CFLAGS="-I$(REAL_DEST)" \ CGO_LDFLAGS="-L$(REAL_DEST)" \ LD_LIBRARY_PATH=$(REAL_DEST) \ ./bin/golangci-lint run --config .golangci.yml --fix .PHONY: lint-github-action -lint-github-action: install +lint-github-action: CGO_CFLAGS="-I$(REAL_DEST)" \ CGO_LDFLAGS="-L$(REAL_DEST)" \ LD_LIBRARY_PATH=$(REAL_DEST) \