From f6bda96d5a5d43212492757472d08bdf0019a4b3 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Tue, 25 Feb 2020 13:35:41 -0800 Subject: [PATCH] Re: #1290: Add a lotus wallet sign CLI command - The command takes an address and a message (in hex) and prints out a signature of the msg --- cli/wallet.go | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/cli/wallet.go b/cli/wallet.go index ad600eadf..40ab3a952 100644 --- a/cli/wallet.go +++ b/cli/wallet.go @@ -24,6 +24,7 @@ var walletCmd = &cli.Command{ walletImport, walletGetDefault, walletSetDefault, + walletSign, }, } @@ -235,3 +236,44 @@ var walletImport = &cli.Command{ return nil }, } + +var walletSign = &cli.Command{ + Name: "sign", + Usage: "sign a message", + ArgsUsage: " ", + Action: func(cctx *cli.Context) error { + api, closer, err := GetFullNodeAPI(cctx) + if err != nil { + return err + } + defer closer() + ctx := ReqContext(cctx) + + if !cctx.Args().Present() || cctx.NArg() != 2 { + return fmt.Errorf("must specify signing address and message to sign") + } + + addr, err := address.NewFromString(cctx.Args().First()) + + if err != nil { + return err + } + + msg, err := hex.DecodeString(cctx.Args().Get(1)) + + if err != nil { + return err + } + + sig, err := api.WalletSign(ctx, addr, msg) + + if err != nil { + return err + } + + sigBytes := append([]byte{byte(sig.TypeCode())}, sig.Data...) + + fmt.Println(hex.EncodeToString(sigBytes)) + return nil + }, +}