Skip to content

Commit

Permalink
Chore/windows build (#100)
Browse files Browse the repository at this point in the history
* check erro on git version

* random pk and address from pk cli

* mnemonic to privatekey example/test

* ETH recover not implemented for windows build

* add windows xbuild

* update readme

* update go-ethereum v1.12.2
  • Loading branch information
fbsobreira authored Sep 7, 2023
1 parent a6734d0 commit 1e82440
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 72 deletions.
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ env := GO111MODULE=on
all:
$(env) go build -o $(cli) -ldflags="$(ldflags)" cmd/main.go

windows:
$(env) GOOS=windows GOARCH=amd64 go build -o $(cli).exe -ldflags="$(ldflags)" cmd/main.go

run:
$(env) go run -ldflags="$(ldflags)" cmd/main.go

debug:
$(env) go build $(flags) -o $(cli) -ldflags="$(ldflags)" cmd/main.go

Expand All @@ -24,4 +30,4 @@ install:all

clean:
@rm -f $(cli)
@rm -rf ./bin
@rm -rf ./bin
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ $ git pull -r origin master
$ make
```

### cross build for windows
```
make windows
```

# Usage & Examples

# bash completions
Expand Down Expand Up @@ -70,8 +75,8 @@ TLS credentials can also be set persistent in config file: `withTLS: true`

# Trongrid API Key

To set trongrid API Key first create you api key at `www.trongrid.io` and use parameter
To set trongrid API Key first create you api key at `www.trongrid.io` and use parameter
`--apiKey=25f66928-0b70-48cd-9ac6-da6f8247c663` (replace with your API key)
Trongrid API Key can also be set persistent in config file: `apiKey: 25f66928-0b70-48cd-9ac6-da6f8247c663` (replace with your API key)

OS environment variable `TRONGRID_APIKEY` will overwrite any prior API key configuration if set.
OS environment variable `TRONGRID_APIKEY` will overwrite any prior API key configuration if set.
54 changes: 50 additions & 4 deletions cmd/subcommands/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ package cmd

import (
"bufio"
"encoding/hex"
"fmt"
"os"

"github.com/btcsuite/btcd/btcec/v2"
"github.com/fatih/color"
"github.com/fbsobreira/gotron-sdk/pkg/account"
"github.com/fbsobreira/gotron-sdk/pkg/address"
"github.com/fbsobreira/gotron-sdk/pkg/common"
c "github.com/fbsobreira/gotron-sdk/pkg/common"
"golang.org/x/crypto/ssh/terminal"

"github.com/fbsobreira/gotron-sdk/pkg/ledger"
"github.com/fbsobreira/gotron-sdk/pkg/mnemonic"
Expand All @@ -25,9 +30,6 @@ var (
quietImport bool
recoverFromMnemonic bool
passphrase string
blsFilePath string
blsShardID uint32
blsCount uint32
ppPrompt = fmt.Sprintf(
"prompt for passphrase, otherwise use default passphrase: \"`%s`\"", c.DefaultPassphrase,
)
Expand Down Expand Up @@ -228,8 +230,52 @@ func keysSub() []*cobra.Command {
},
}

randomPrivateKey := &cobra.Command{
Use: "random-pk",
Short: "export a random private key",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
key, err := bip39.NewEntropy(256)
if err != nil {
return err
}
fmt.Println(hex.EncodeToString(key))
return nil
},
}

addressFromPrivateKey := &cobra.Command{
Use: "address-pk",
Short: "export address from private key",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("Enter privete key hex format:")
data, err := terminal.ReadPassword(int(os.Stdin.Fd()))
if err != nil {
return err
}

// decode hex
privateKeyBytes, err := hex.DecodeString(string(data))
if err != nil {
return err
}

if len(privateKeyBytes) != common.Secp256k1PrivateKeyBytesLength {
return common.ErrBadKeyLength
}

// btcec.PrivKeyFromBytes only returns a secret key and public key
sk, _ := btcec.PrivKeyFromBytes(privateKeyBytes)

addr := address.PubkeyToAddress(*sk.PubKey().ToECDSA())
fmt.Println(addr)
return nil
},
}

return []*cobra.Command{cmdList, cmdLocation, cmdAdd, cmdRemove, cmdMnemonic, cmdRecoverMnemonic, cmdImportKS, cmdImportPK,
cmdExportKS, cmdExportPK}
cmdExportKS, cmdExportPK, randomPrivateKey, addressFromPrivateKey}
}

func init() {
Expand Down
12 changes: 8 additions & 4 deletions cmd/subcommands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@ var (
versionFormat = regexp.MustCompile("v[0-9]+-[a-z0-9]{7}")
)

//GitHubReleaseAssets json struct
// GitHubReleaseAssets json struct
type GitHubReleaseAssets struct {
ID json.Number `json:"id"`
Name string `json:"name"`
Size json.Number `json:"size"`
URL string `json:"browser_download_url"`
}

//GitHubRelease json struct
// GitHubRelease json struct
type GitHubRelease struct {
Prerelease bool `json:"prerelease"`
TagName string `json:"tag_name"`
Expand All @@ -172,7 +172,7 @@ type GitHubRelease struct {
Assets []GitHubReleaseAssets `json:"assets"`
}

//GitHubTag json struct
// GitHubTag json struct
type GitHubTag struct {
Ref string `json:"ref"`
NodeID string `json:"node_id"`
Expand All @@ -183,7 +183,11 @@ type GitHubTag struct {
}

func getGitVersion() (string, error) {
resp, _ := http.Get(versionLink)
resp, err := http.Get(versionLink)
if err != nil {
return "", err
}

defer resp.Body.Close()
// if error, no op
if resp != nil && resp.StatusCode == 200 {
Expand Down
25 changes: 13 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/araddon/dateparse v0.0.0-20200409225146-d820a6159ab1
github.com/btcsuite/btcd/btcec/v2 v2.2.0
github.com/deckarep/golang-set v1.8.0
github.com/ethereum/go-ethereum v1.10.26
github.com/ethereum/go-ethereum v1.12.2
github.com/fatih/color v1.9.0
github.com/fatih/structs v1.1.0
github.com/mitchellh/go-homedir v1.1.0
Expand All @@ -15,11 +15,11 @@ require (
github.com/rjeczalik/notify v0.9.3
github.com/shengdoushi/base58 v1.0.0
github.com/spf13/cobra v1.0.0
github.com/stretchr/testify v1.7.2
github.com/tyler-smith/go-bip39 v1.0.2
github.com/stretchr/testify v1.8.1
github.com/tyler-smith/go-bip39 v1.1.0
github.com/zondax/hid v0.9.1
go.uber.org/zap v1.15.0
golang.org/x/crypto v0.7.0
golang.org/x/crypto v0.9.0
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987
google.golang.org/grpc v1.37.0
google.golang.org/protobuf v1.28.1
Expand All @@ -30,20 +30,21 @@ require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/uuid v1.2.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spf13/pflag v1.0.3 // indirect
go.uber.org/atomic v1.6.0 // indirect
go.uber.org/multierr v1.5.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 1e82440

Please sign in to comment.