"github.com/bytom/crypto"
"github.com/bytom/crypto/ed25519"
"github.com/bytom/crypto/ed25519/chainkd"
+ chainjson "github.com/bytom/encoding/json"
)
// SignMsgResp is response for sign message
}
func (a *API) signMessage(ctx context.Context, ins struct {
- Address string `json:"address"`
- Message string `json:"message"`
- Password string `json:"password"`
+ Address string `json:"address"`
+ Message chainjson.HexBytes `json:"message"`
+ Password string `json:"password"`
}) Response {
cp, err := a.wallet.AccountMgr.GetLocalCtrlProgramByAddress(ins.Address)
if err != nil {
}
derivedXPubs := chainkd.DeriveXPubs(account.XPubs, path)
- sig, err := a.wallet.Hsm.XSign(account.XPubs[0], path, []byte(ins.Message), ins.Password)
+ sig, err := a.wallet.Hsm.XSign(account.XPubs[0], path, ins.Message, ins.Password)
if err != nil {
return NewErrorResponse(err)
}
}
func (a *API) verifyMessage(ctx context.Context, ins struct {
- Address string `json:"address"`
- DerivedXPub chainkd.XPub `json:"derived_xpub"`
- Message string `json:"message"`
- Signature string `json:"signature"`
+ Address string `json:"address"`
+ DerivedXPub chainkd.XPub `json:"derived_xpub"`
+ Message chainjson.HexBytes `json:"message"`
+ Signature string `json:"signature"`
}) Response {
sig, err := hex.DecodeString(ins.Signature)
if err != nil {
return NewSuccessResponse(VerifyMsgResp{VerifyResult: false})
}
- if ed25519.Verify(ins.DerivedXPub.PublicKey(), []byte(ins.Message), sig) {
+ if ed25519.Verify(ins.DerivedXPub.PublicKey(), ins.Message, sig) {
return NewSuccessResponse(VerifyMsgResp{VerifyResult: true})
}
return NewSuccessResponse(VerifyMsgResp{VerifyResult: false})
package commands
import (
+ "encoding/hex"
"os"
"github.com/spf13/cobra"
jww "github.com/spf13/jwalterweatherman"
"github.com/bytom/crypto/ed25519/chainkd"
+ chainjson "github.com/bytom/encoding/json"
"github.com/bytom/util"
)
Short: "sign message to generate signature",
Args: cobra.ExactArgs(3),
Run: func(cmd *cobra.Command, args []string) {
+ message, err := hex.DecodeString(args[1])
+ if err != nil {
+ jww.ERROR.Println("sign-message args not valid:", err)
+ os.Exit(util.ErrLocalExe)
+ }
+
var req = struct {
- Address string `json:"address"`
- Message string `json:"message"`
- Password string `json:"password"`
- }{Address: args[0], Message: args[1], Password: args[2]}
+ Address string `json:"address"`
+ Message chainjson.HexBytes `json:"message"`
+ Password string `json:"password"`
+ }{Address: args[0], Message: message, Password: args[2]}
data, exitCode := util.ClientCall("/sign-message", &req)
if exitCode != util.Success {
os.Exit(util.ErrLocalExe)
}
+ message, err := hex.DecodeString(args[2])
+ if err != nil {
+ jww.ERROR.Println("sign-message args not valid:", err)
+ os.Exit(util.ErrLocalExe)
+ }
+
var req = struct {
- Address string `json:"address"`
- DerivedXPub chainkd.XPub `json:"derived_xpub"`
- Message string `json:"message"`
- Signature string `json:"signature"`
- }{Address: args[0], DerivedXPub: xpub, Message: args[2], Signature: args[3]}
+ Address string `json:"address"`
+ DerivedXPub chainkd.XPub `json:"derived_xpub"`
+ Message chainjson.HexBytes `json:"message"`
+ Signature string `json:"signature"`
+ }{Address: args[0], DerivedXPub: xpub, Message: message, Signature: args[3]}
data, exitCode := util.ClientCall("/verify-message", &req)
if exitCode != util.Success {