From feca3c3a45e019d370b31ae156cf61e75800b19f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Duchesneau?= Date: Fri, 24 Apr 2020 13:10:25 -0400 Subject: [PATCH 1/3] set default API URL to localhost:8888, add HTTP HEADER support in env var, adapt README --- README-cn.md | 7 +++ README.md | 104 ++++++++++++++++----------------------------- eosc/cmd/common.go | 6 +++ eosc/cmd/root.go | 2 +- 4 files changed, 51 insertions(+), 68 deletions(-) diff --git a/README-cn.md b/README-cn.md index b286c594..eb589fe9 100644 --- a/README-cn.md +++ b/README-cn.md @@ -21,6 +21,7 @@ ```bash go get -u -v github.com/eoscanada/eosc/eosc + ``` @@ -30,6 +31,11 @@ go get -u -v github.com/eoscanada/eosc/eosc 安装完成后运行下面命令来导入你的私钥: ``` +export EOSC_GLOBAL_API_URL=https://... + +# export EOSC_GLOBAL_HTTP_HEADER_0="Authorization: bearer abcdef12323453452565676589" +# export EOSC_GLOBAL_HTTP_HEADER_1="Origin: https://... + eosc vault create --import ``` @@ -42,6 +48,7 @@ eosc vote --help 然后运行如下命令为你的候选者投票: ``` + eosc vote producers [your account] [producer1] [producer2] [producer3] ``` 命令中参数依次为: [你的账户名] [你要投票的BP1] [你要投票的BP2] [你要投票的BP3] (你共可以为30个BP投票) diff --git a/README.md b/README.md index a0b9da7c..68e98761 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -`eosc` command-line swiss-army-knife -------------------------------- +# `eosc` command-line swiss-army-knife +## Description [点击查看中文](./README-cn.md) `eosc` is a cross-platform (Windows, Mac and Linux) command-line tool @@ -17,8 +17,7 @@ mainnet launch. Source code for most operations is already available in this repository. -Installation ------------- +## Installation 1. Install from https://github.com/eoscanada/eosc/releases @@ -39,8 +38,7 @@ brew install eoscanada/tap/eosc ``` -Vote now! ---------- +## Getting started Once installed run: @@ -50,36 +48,33 @@ eosc vault create --import to import your keys and follow instructions. -Then run: +Then set your environment variable to the API URL of your choice, optionally setting some HTTP headers: ``` -eosc vote --help -``` - -and run something like this: +export EOSC_GLOBAL_API_URL=https://your-favorite-endpoint -``` -eosc vote producers [your account] [producer1] [producer2] [producer3] +export EOSC_GLOBAL_HTTP_HEADER_0="Authorization: bearer abcdef12323453452565676589" +export EOSC_GLOBAL_HTTP_HEADER_1="Origin: https://something... ``` -Make sure you have version `v0.7.0` or higher: - -``` -eosc version -``` +Then you can -Read more below for details. +## Environment variables +--------------------- +* All global flags (those you get from eosc –help) can be set with the following pattern: EOSC_GLOBAL_FLAG_NAME. The most useful are: + * `EOSC_GLOBAL_WALLET_URL` -> `--wallet-url` + * `EOSC_GLOBAL_VAULT_FILE` -> `--vault-file` +* All (sub)command flags map to the following pattern: EOSC_COMMAND_SUBCOMMAND_CMD_FLAG_NAME (ex: `EOSC_FORUM_POST_CMD_REPLY_TO` -> `eosc forum post --reply-to=...` +* `EOSC_GLOBAL_INSECURE_VAULT_PASSPHRASE` allows you to input the passphrase directly in an environment variable (useful for test automation, risky for most other uses) +* `EOSC_GLOBAL_HTTP_HEADER_0` (available for indexes 0 to 25) -eosc vault ----------- +## eosc vault management The `eosc vault` is a simple yet powerful EOS wallet. - -Import keys in new wallet -========================= +### Import keys in new wallet You can **import externally generated private keys** with `vault create --import` call. @@ -104,8 +99,7 @@ for cryptographic primitives used. -New wallet with new keys -======================== +### New wallet with new keys Create a new wallet with: @@ -120,8 +114,7 @@ Wallet file "./eosc-vault.json" created. Here are your public keys: ``` -Add keys to an existing vault -============================= +### Add keys to an existing vault To add an externally generated private key to an existing vault, use: @@ -141,43 +134,6 @@ Total keys writteN: 3 The vault operations do zero network calls and can be done offline. The file is encrypted, can safely be archived and is future proof. -Casting your votes ------------------- - -With an `eosc-vault.json`, you can vote: - -``` -$ eosc vote producers youraccount eoscanadacom someotherfavo riteproducer -Enter passphrase to unlock vault: -Voter [youraccount] voting for: [eoscanadacom] -Done -``` - -This will sign your vote transaction locally, and submit the -transaction to the network through the `https://mainnet.eoscanada.com` -endpoint. You can also point to some other endpoints that are on the -main network with `-u` or `--api-url`. - -Find what your account is on https://eosq.app - - - -Cryptographic primitives used ------------------------------ - -The cryptography used is NaCl -([C implementation](https://tweetnacl.cr.yp.to/), [Javascript port](https://github.com/dchest/tweetnacl-js), -[Go version, which we use](https://godoc.org/golang.org/x/crypto/nacl/secretbox)). And -key derivation is [Argon2](https://en.wikipedia.org/wiki/Argon2), -using the [Go library -here](https://godoc.org/golang.org/x/crypto/argon2). - -You can inspect the crypto code in our codebase regarding the -`passphrase` implementation: [it is 61 lines](./vault/passphrase.go), -including blanks and comments. - - - ## Offline transaction signature @@ -344,9 +300,23 @@ need to stitch transaction files, or gather signatures into a single place. +## Cryptographic primitives used +----------------------------- -FAQ ---- +The cryptography used is NaCl +([C implementation](https://tweetnacl.cr.yp.to/), [Javascript port](https://github.com/dchest/tweetnacl-js), +[Go version, which we use](https://godoc.org/golang.org/x/crypto/nacl/secretbox)). And +key derivation is [Argon2](https://en.wikipedia.org/wiki/Argon2), +using the [Go library +here](https://godoc.org/golang.org/x/crypto/argon2). + +You can inspect the crypto code in our codebase regarding the +`passphrase` implementation: [it is 61 lines](./vault/passphrase.go), +including blanks and comments. + + + +## FAQ Q: Why not use `cleos` instead ? diff --git a/eosc/cmd/common.go b/eosc/cmd/common.go index faff80b5..6c2605b2 100644 --- a/eosc/cmd/common.go +++ b/eosc/cmd/common.go @@ -76,6 +76,12 @@ func getAPI() *eos.API { httpHeaders := viper.GetStringSlice("global-http-header") api := eos.New(sanitizeAPIURL(viper.GetString("global-api-url"))) + for i := 0; i < 25; i++ { + if val := os.Getenv(fmt.Sprintf("EOSC_GLOBAL_HTTP_HEADER_%d", i)); val != "" { + httpHeaders = append(httpHeaders, val) + } + } + for _, header := range httpHeaders { headerArray := strings.SplitN(header, ": ", 2) if len(headerArray) != 2 || strings.Contains(headerArray[0], " ") { diff --git a/eosc/cmd/root.go b/eosc/cmd/root.go index f28b2978..bc1a3f60 100644 --- a/eosc/cmd/root.go +++ b/eosc/cmd/root.go @@ -47,7 +47,7 @@ func init() { RootCmd.PersistentFlags().BoolP("debug", "", false, "Enables verbose API debug messages") RootCmd.PersistentFlags().StringP("vault-file", "", "./eosc-vault.json", "Wallet file that contains encrypted key material") RootCmd.PersistentFlags().StringSliceP("wallet-url", "", []string{}, "Base URL to wallet endpoint. You can pass this multiple times to use the multi-signer (will use each wallet to sign multi-sig transactions).") - RootCmd.PersistentFlags().StringP("api-url", "u", "https://mainnet.eoscanada.com", "API endpoint of eos.io blockchain node") + RootCmd.PersistentFlags().StringP("api-url", "u", "http://localhost:8888", "API endpoint of eos.io blockchain node") RootCmd.PersistentFlags().StringSliceP("permission", "p", []string{}, "Permission to sign transactions with. Optionally specify more than one, or separate by comma") RootCmd.PersistentFlags().StringSliceP("http-header", "H", []string{}, "HTTP header to add to a request. Optionally repeat this option to specify multiple headers") RootCmd.PersistentFlags().StringP("kms-gcp-keypath", "", "", "Path to the cryptoKeys within a keyRing on GCP") From 7a3e18b07e84e02fc798e0de256dcd26c400526e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Duchesneau?= Date: Fri, 24 Apr 2020 13:52:27 -0400 Subject: [PATCH 2/3] fix typo in README --- README.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 68e98761..38fc6f03 100644 --- a/README.md +++ b/README.md @@ -57,10 +57,15 @@ export EOSC_GLOBAL_HTTP_HEADER_0="Authorization: bearer abcdef123234534525656765 export EOSC_GLOBAL_HTTP_HEADER_1="Origin: https://something... ``` -Then you can +Then you can run commands on the chain, ex: + +``` +eosc get info +eosc transfer fromaccnt toaccnt 0.0001 --memo "Sent with eosc" +``` ## Environment variables ---------------------- + * All global flags (those you get from eosc –help) can be set with the following pattern: EOSC_GLOBAL_FLAG_NAME. The most useful are: * `EOSC_GLOBAL_WALLET_URL` -> `--wallet-url` * `EOSC_GLOBAL_VAULT_FILE` -> `--vault-file` From 74308369b00980fae8793ae6a3eb536c9ebeca2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Duchesneau?= Date: Fri, 24 Apr 2020 14:08:26 -0400 Subject: [PATCH 3/3] add useful error when API URL not set --- README-cn.md | 1 - README.md | 1 - eosc/cmd/common.go | 3 +++ eosc/cmd/root.go | 4 +++- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README-cn.md b/README-cn.md index eb589fe9..d409a472 100644 --- a/README-cn.md +++ b/README-cn.md @@ -21,7 +21,6 @@ ```bash go get -u -v github.com/eoscanada/eosc/eosc - ``` diff --git a/README.md b/README.md index 38fc6f03..fd0ef968 100644 --- a/README.md +++ b/README.md @@ -306,7 +306,6 @@ place. ## Cryptographic primitives used ------------------------------ The cryptography used is NaCl ([C implementation](https://tweetnacl.cr.yp.to/), [Javascript port](https://github.com/dchest/tweetnacl-js), diff --git a/eosc/cmd/common.go b/eosc/cmd/common.go index 6c2605b2..50483d56 100644 --- a/eosc/cmd/common.go +++ b/eosc/cmd/common.go @@ -154,6 +154,9 @@ func sanitizeAPIURL(input string) string { func errorCheck(prefix string, err error) { if err != nil { fmt.Printf("ERROR: %s: %s\n", prefix, err) + if strings.HasSuffix(err.Error(), "connection refused") && strings.Contains(err.Error(), defaultAPIURL) { + fmt.Println("Have you selected a valid EOS HTTP endpoint ? You can use the --api-url flag or EOSC_GLOBAL_API_URL environment variable.") + } os.Exit(1) } } diff --git a/eosc/cmd/root.go b/eosc/cmd/root.go index bc1a3f60..8698f807 100644 --- a/eosc/cmd/root.go +++ b/eosc/cmd/root.go @@ -15,6 +15,8 @@ import ( // Version represents the eosc command version var Version string +const defaultAPIURL = "http://localhost:8888" + // RootCmd represents the eosc command var RootCmd = &cobra.Command{ Use: "eosc", @@ -47,7 +49,7 @@ func init() { RootCmd.PersistentFlags().BoolP("debug", "", false, "Enables verbose API debug messages") RootCmd.PersistentFlags().StringP("vault-file", "", "./eosc-vault.json", "Wallet file that contains encrypted key material") RootCmd.PersistentFlags().StringSliceP("wallet-url", "", []string{}, "Base URL to wallet endpoint. You can pass this multiple times to use the multi-signer (will use each wallet to sign multi-sig transactions).") - RootCmd.PersistentFlags().StringP("api-url", "u", "http://localhost:8888", "API endpoint of eos.io blockchain node") + RootCmd.PersistentFlags().StringP("api-url", "u", defaultAPIURL, "API endpoint of eos.io blockchain node") RootCmd.PersistentFlags().StringSliceP("permission", "p", []string{}, "Permission to sign transactions with. Optionally specify more than one, or separate by comma") RootCmd.PersistentFlags().StringSliceP("http-header", "H", []string{}, "HTTP header to add to a request. Optionally repeat this option to specify multiple headers") RootCmd.PersistentFlags().StringP("kms-gcp-keypath", "", "", "Path to the cryptoKeys within a keyRing on GCP")