From 2cf19d41af7456ed041a199fa353ffee3df17f6f Mon Sep 17 00:00:00 2001 From: beck <1504068285@qq.com> Date: Wed, 28 Jun 2023 03:29:58 +0800 Subject: [PATCH] not display privatekey --- cli/wallet.go | 21 +++++++++++++++------ go.mod | 2 +- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cli/wallet.go b/cli/wallet.go index c66275cdd..2afe8617b 100644 --- a/cli/wallet.go +++ b/cli/wallet.go @@ -10,6 +10,7 @@ import ( "strings" "github.com/urfave/cli/v2" + "golang.org/x/term" "golang.org/x/xerrors" "github.com/filecoin-project/go-address" @@ -327,13 +328,21 @@ var walletImport = &cli.Command{ var inpdata []byte if !cctx.Args().Present() || cctx.Args().First() == "-" { - reader := bufio.NewReader(os.Stdin) - fmt.Print("Enter private key: ") - indata, err := reader.ReadBytes('\n') - if err != nil { - return err + if term.IsTerminal(int(os.Stdin.Fd())) { + fmt.Print("Enter private key(not display in the terminal): ") + inpdata, err = term.ReadPassword(int(os.Stdin.Fd())) + if err != nil { + return err + } + fmt.Println() + } else { + reader := bufio.NewReader(os.Stdin) + indata, err := reader.ReadBytes('\n') + if err != nil { + return err + } + inpdata = indata } - inpdata = indata } else { fdata, err := os.ReadFile(cctx.Args().First()) diff --git a/go.mod b/go.mod index 0479854bc..ab1f60b6e 100644 --- a/go.mod +++ b/go.mod @@ -155,6 +155,7 @@ require ( golang.org/x/net v0.10.0 golang.org/x/sync v0.2.0 golang.org/x/sys v0.9.0 + golang.org/x/term v0.9.0 golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 golang.org/x/tools v0.9.1 golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 @@ -322,7 +323,6 @@ require ( go.uber.org/dig v1.17.0 // indirect go4.org v0.0.0-20230225012048-214862532bf5 // indirect golang.org/x/mod v0.10.0 // indirect - golang.org/x/term v0.9.0 // indirect golang.org/x/text v0.10.0 // indirect gonum.org/v1/gonum v0.13.0 // indirect google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect