func (a *API) signMessage(ctx context.Context, ins struct {
Address string `json:"address"`
- Message []byte `json:"message"`
+ Message string `json:"message"`
Password string `json:"password"`
}) Response {
cp, err := a.wallet.AccountMgr.GetProgramByAddress(ins.Address)
path := signers.Path(account.Signer, signers.AccountKeySpace, cp.KeyIndex)
derivedXPubs := chainkd.DeriveXPubs(account.XPubs, path)
- sig, err := a.wallet.Hsm.XSign(account.XPubs[0], path, ins.Message, ins.Password)
+ sig, err := a.wallet.Hsm.XSign(account.XPubs[0], path, []byte(ins.Message), ins.Password)
if err != nil {
return NewErrorResponse(err)
}
// VerifyMsgResp is response for verify message
type VerifyMsgResp struct {
- VerifyResult bool `json:" result"`
+ VerifyResult bool `json:"result"`
}
func (a *API) verifyMessage(ctx context.Context, ins struct {
Address string `json:"address"`
DerivedXPub chainkd.XPub `json:"derived_xpub"`
- Message []byte `json:"message"`
- Signature []byte `json:"signature"`
+ Message string `json:"message"`
+ Signature string `json:"signature"`
}) Response {
+ sig, err := hex.DecodeString(ins.Signature)
+ if err != nil {
+ return NewErrorResponse(err)
+ }
+
derivedPK := ins.DerivedXPub.PublicKey()
pubHash := crypto.Ripemd160(derivedPK)
addressPubHash, err := common.NewAddressWitnessPubKeyHash(pubHash, &consensus.ActiveNetParams)
return NewSuccessResponse(VerifyMsgResp{VerifyResult: false})
}
- if ed25519.Verify(ins.DerivedXPub.PublicKey(), ins.Message, ins.Signature) {
+ if ed25519.Verify(ins.DerivedXPub.PublicKey(), []byte(ins.Message), sig) {
return NewSuccessResponse(VerifyMsgResp{VerifyResult: true})
}
return NewSuccessResponse(VerifyMsgResp{VerifyResult: false})
package commands
import (
- "encoding/hex"
"os"
"github.com/spf13/cobra"
Run: func(cmd *cobra.Command, args []string) {
var req = struct {
Address string `json:"address"`
- Message []byte `json:"message"`
+ Message string `json:"message"`
Password string `json:"password"`
- }{Address: args[0], Message: []byte(args[1]), Password: args[2]}
+ }{Address: args[0], Message: args[1], Password: args[2]}
data, exitCode := util.ClientCall("/sign-message", &req)
if exitCode != util.Success {
os.Exit(util.ErrLocalExe)
}
- signature, err := hex.DecodeString(args[3])
- if err != nil {
- jww.ERROR.Println("convert signature error:", err)
- os.Exit(util.ErrLocalExe)
- }
-
var req = struct {
Address string `json:"address"`
DerivedXPub chainkd.XPub `json:"derived_xpub"`
- Message []byte `json:"message"`
- Signature []byte `json:"signature"`
- }{Address: args[0], DerivedXPub: xpub, Message: []byte(args[2]), Signature: signature}
+ Message string `json:"message"`
+ Signature string `json:"signature"`
+ }{Address: args[0], DerivedXPub: xpub, Message: args[2], Signature: args[3]}
data, exitCode := util.ClientCall("/verify-message", &req)
if exitCode != util.Success {