diff --git a/README-cn.md b/README-cn.md index b286c59..d409a47 100644 --- a/README-cn.md +++ b/README-cn.md @@ -30,6 +30,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 +47,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 a0b9da7..fd0ef96 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,38 @@ 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: +Then you can run commands on the chain, ex: ``` -eosc version +eosc get info +eosc transfer fromaccnt toaccnt 0.0001 --memo "Sent with eosc" ``` -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` -eosc vault ----------- +* 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) -The `eosc vault` is a simple yet powerful EOS wallet. +## 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 +104,7 @@ for cryptographic primitives used. -New wallet with new keys -======================== +### New wallet with new keys Create a new wallet with: @@ -120,8 +119,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 +139,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 +305,22 @@ 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 faff80b..50483d5 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], " ") { @@ -148,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 f28b297..8698f80 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", "https://mainnet.eoscanada.com", "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")