"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 {
{78000, bc.NewHash([32]byte{0xa9, 0x03, 0xc0, 0x0c, 0x62, 0x1a, 0x3d, 0x00, 0x7f, 0xd8, 0x5d, 0x51, 0xba, 0x43, 0xe4, 0xd0, 0xe3, 0xc5, 0xd4, 0x8f, 0x30, 0xb5, 0x5f, 0xa5, 0x77, 0x62, 0xd8, 0x8b, 0x11, 0x81, 0x5f, 0xb4})},
{82000, bc.NewHash([32]byte{0x56, 0xb1, 0xba, 0x23, 0x69, 0x5c, 0x8f, 0x51, 0x4e, 0x23, 0xc0, 0xae, 0xaa, 0x25, 0x08, 0xc5, 0x85, 0xf3, 0x7c, 0xd1, 0xc6, 0x15, 0xa2, 0x51, 0xda, 0x79, 0x4f, 0x08, 0x13, 0x66, 0xc9, 0x85})},
{83200, bc.NewHash([32]byte{0xb4, 0x6f, 0xc5, 0xcf, 0xa3, 0x3d, 0xe1, 0x11, 0x71, 0x68, 0x40, 0x68, 0x0c, 0xe7, 0x4c, 0xaf, 0x5a, 0x11, 0xfe, 0x82, 0xbc, 0x36, 0x88, 0x0f, 0xbd, 0x04, 0xf0, 0xc4, 0x86, 0xd4, 0xd6, 0xd5})},
+ {93000, bc.NewHash([32]byte{0x6f, 0x4f, 0x37, 0x5f, 0xe9, 0xfb, 0xdf, 0x66, 0x60, 0x0e, 0xf0, 0x39, 0xb7, 0x18, 0x26, 0x75, 0xa0, 0x9a, 0xa5, 0x9b, 0x83, 0xc9, 0x9a, 0x25, 0x45, 0xb8, 0x7d, 0xd4, 0x99, 0x24, 0xa2, 0x8a})},
},
}