"github.com/vapor/crypto"
"github.com/vapor/crypto/ed25519"
"github.com/vapor/crypto/ed25519/chainkd"
+ chainjson "github.com/vapor/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})