diff --git a/CHANGELOG.md b/CHANGELOG.md index b51c6ac..fd982d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +1.35.5: + - allow keystore to be output to the console + 1.35.4: - provide consensus and execution client info in block info output diff --git a/cmd/account/derive/input.go b/cmd/account/derive/input.go index d8ba0fa..531bb7b 100644 --- a/cmd/account/derive/input.go +++ b/cmd/account/derive/input.go @@ -22,6 +22,7 @@ import ( type dataIn struct { quiet bool + json bool // Derivation information. mnemonic string path string @@ -37,6 +38,9 @@ func input(_ context.Context) (*dataIn, error) { // Quiet. data.quiet = viper.GetBool("quiet") + // JSON. + data.json = viper.GetBool("json") + // Mnemonic. if viper.GetString("mnemonic") == "" { return nil, errors.New("mnemonic is required") diff --git a/cmd/account/derive/output.go b/cmd/account/derive/output.go index 3a835d8..264b786 100644 --- a/cmd/account/derive/output.go +++ b/cmd/account/derive/output.go @@ -31,6 +31,7 @@ import ( ) type dataOut struct { + json bool showPrivateKey bool showWithdrawalCredentials bool generateKeystore bool @@ -94,10 +95,14 @@ func outputKeystore(_ context.Context, data *dataOut) (string, error) { return "", errors.Wrap(err, "failed to marshal keystore JSON") } - keystoreFilename := fmt.Sprintf("keystore-%s-%d.json", strings.ReplaceAll(data.path, "/", "_"), time.Now().Unix()) + if data.json { + fmt.Fprintf(os.Stdout, "%s\n", string(out)) + } else { + keystoreFilename := fmt.Sprintf("keystore-%s-%d.json", strings.ReplaceAll(data.path, "/", "_"), time.Now().Unix()) - if err := os.WriteFile(keystoreFilename, out, 0o600); err != nil { - return "", errors.Wrap(err, fmt.Sprintf("failed to write %s", keystoreFilename)) + if err := os.WriteFile(keystoreFilename, out, 0o600); err != nil { + return "", errors.Wrap(err, fmt.Sprintf("failed to write %s", keystoreFilename)) + } } return "", nil } diff --git a/cmd/account/derive/process.go b/cmd/account/derive/process.go index 7a1a6be..feb01ba 100644 --- a/cmd/account/derive/process.go +++ b/cmd/account/derive/process.go @@ -38,6 +38,7 @@ func process(ctx context.Context, data *dataIn) (*dataOut, error) { } results := &dataOut{ + json: data.json, showPrivateKey: data.showPrivateKey, showWithdrawalCredentials: data.showWithdrawalCredentials, generateKeystore: data.generateKeystore, diff --git a/cmd/accountderive.go b/cmd/accountderive.go index bb1a73a..2049f87 100644 --- a/cmd/accountderive.go +++ b/cmd/accountderive.go @@ -50,6 +50,7 @@ func init() { accountDeriveCmd.Flags().Bool("show-private-key", false, "show private key for derived account") accountDeriveCmd.Flags().Bool("show-withdrawal-credentials", false, "show withdrawal credentials for derived account") accountDeriveCmd.Flags().Bool("generate-keystore", false, "generate a keystore for the derived account") + accountDeriveCmd.Flags().Bool("json", false, "display the JSON keystore for the derived account on stdout") } func accountDeriveBindings(cmd *cobra.Command) { @@ -62,4 +63,7 @@ func accountDeriveBindings(cmd *cobra.Command) { if err := viper.BindPFlag("generate-keystore", cmd.Flags().Lookup("generate-keystore")); err != nil { panic(err) } + if err := viper.BindPFlag("json", cmd.Flags().Lookup("json")); err != nil { + panic(err) + } } diff --git a/cmd/version.go b/cmd/version.go index d2df7c4..34edf6d 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -24,7 +24,7 @@ import ( // ReleaseVersion is the release version of the codebase. // Usually overridden by tag names when building binaries. -var ReleaseVersion = "local build (latest release 1.35.4)" +var ReleaseVersion = "local build (latest release 1.35.5)" // versionCmd represents the version command. var versionCmd = &cobra.Command{ diff --git a/docs/usage.md b/docs/usage.md index ffab5ed..0950991 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -183,6 +183,7 @@ $ ethdo account create --account="Personal wallet/Operations" --wallet-passphras - `show-private-key`: show the private of the derived account. **Warning** displaying private keys, especially those derived from seeds held on hardware wallets, can expose your Ether to risk of being stolen. Only use this option if you are sure you understand the risks involved - `show-withdrawal-credentials`: show the withdrawal credentials of the derived account - `generate-keystore`: generate a keystore for the account +- `json`: output the generated keystore to stdout ```sh $ ethdo account derive --mnemonic="abandon ... abandon art" --path="m/12381/3600/0/0"