func Verify(publicKey *ecdsa.PublicKey, sig []byte, message []byte) (valid bool, err error) {
	signature := new(common.SchnorrSignature)
	err = json.Unmarshal(sig, signature)
	if err != nil {
		return false, fmt.Errorf("Failed unmashalling schnorr signature [%s]", err)
	}
	curve := publicKey.Curve
	x1, y1 := curve.ScalarBaseMult(signature.S.Bytes())
	x2, y2 := curve.ScalarMult(publicKey.X, publicKey.Y, signature.E.Bytes())
	x, y := curve.Add(x1, y1, x2, y2)
	e := hash.HashUsingSM3(utils.BytesCombine(message, elliptic.Marshal(curve, x, y)))
	intE := new(big.Int).SetBytes(e)
	if intE.Cmp(signature.E) != 0 {
		return false, nil
	}
	return true, nil
}
In order to verify the signature, only need to check the equation:
H'(m, s, e) = H(m || s * G + e * P) = e
i.e. whether e is equal to H(m || s * G + e * P)
package schnorr_sign
import (
	"crypto/ecdsa"
	"crypto/elliptic"
	"encoding/json"
	"errors"
	"fmt"
	"math/big"
	"github.com/xuperchain/crypto/common/utils"
	"github.com/xuperchain/crypto/gm/common"
	"github.com/xuperchain/crypto/gm/hash"
)
var (
	GenerateSignatureError = errors.New("Failed to generate the schnorr signature, s = 0 happened.")
	EmptyMessageError      = errors.New("The message to be signed should not be empty")
)
func Sign(privateKey *ecdsa.PrivateKey, message []byte) (schnorrSignature []byte, err error) {
	if privateKey == nil {
		return nil, fmt.Errorf("Invalid privateKey. PrivateKey must not be nil.")
	}
	k := hash.HashUsingSM3(utils.BytesCombine(message, privateKey.D.Bytes()))
	curve := privateKey.Curve
	x, y := curve.ScalarBaseMult(k)
	e := hash.HashUsingSM3(utils.BytesCombine(message, elliptic.Marshal(curve, x, y)))
	intK := new(big.Int).SetBytes(k)
	intE := new(big.Int).SetBytes(e)
	intS, err := ComputeSByKEX(curve, intK, intE, privateKey.D)
	if err != nil {
		return nil, GenerateSignatureError
	}
	schnorrSig := &common.SchnorrSignature{
		E: intE,
		S: intS,
	}
	sigContent, err := json.Marshal(schnorrSig)
	if err != nil {
		return nil, err
	}
	xuperSig := &common.XuperSignature{
		SigType:    common.Schnorr,
		SigContent: sigContent,
	}
	sig, err := json.Marshal(xuperSig)
	if err != nil {
		return nil, err
	}
	return sig, nil
}
func ComputeSByKEX(curve elliptic.Curve, k, e, x *big.Int) (*big.Int, error) {
	intS := new(big.Int).Sub(k, new(big.Int).Mul(e, x))
	if intS.Sign() == -1 {
		intS = intS.Add(intS, new(big.Int).Mul(e, curve.Params().N))
		_, intS = intS.DivMod(intS, curve.Params().N, new(big.Int))
		if intS.Sign() != 1 {
			return nil, GenerateSignatureError
		}
	}
	return intS, nil
}