func SerializePrivateKey(p *ecdsa.PrivateKey) []byte {
	b := make([]byte, 0, privateKeyECDSALength)
	return paddedAppend(privateKeyECDSALength, b, p.D.Bytes())
}
SerializePrivateKey serialize private key
package secp256r1
import (
	"crypto/ecdsa"
	"crypto/elliptic"
	"encoding/asn1"
	"errors"
	"fmt"
	"math/big"
)
const (
	pubkeyCompressed   byte = 0x2  
	pubkeyUncompressed byte = 0x4  
)
func MarshalECDSASignature(r, s *big.Int) ([]byte, error) {
	return asn1.Marshal(signatureECDSA{r, s})
}
func UnmarshalECDSASignature(raw []byte) (*big.Int, *big.Int, error) {
	sig := new(signatureECDSA)
	_, err := asn1.Unmarshal(raw, sig)
	if err != nil {
		return nil, nil, fmt.Errorf("failed unmashalling signature [%s]", err)
	}
	if sig.R == nil || sig.S == nil {
		return nil, nil, errors.New("invalid signature, R/S must be different from nil")
	}
	if sig.R.Sign() != 1 || sig.S.Sign() != 1 {
		return nil, nil, errors.New("invalid signature, R/S must be larger than zero")
	}
	return sig.R, sig.S, nil
}
func ToLowS(k *ecdsa.PublicKey, s *big.Int) *big.Int {
	lowS := IsLowS(s)
	if !lowS {
		s.Sub(k.Params().N, s)
		return s
	}
	return s
}
func IsLowS(s *big.Int) bool {
	return s.Cmp(new(big.Int).Rsh(elliptic.P256().Params().N, 1)) != 1
}
func isOdd(a *big.Int) bool {
	return a.Bit(0) == 1
}
func SerializePublicKeyCompressed(p *ecdsa.PublicKey) []byte {
	b := make([]byte, 0, publicKeyECDSALengthCompressed)
	format := pubkeyCompressed
	if isOdd(p.Y) {
		format |= 0x1
	}
	b = append(b, format)
	return paddedAppend(32, b, p.X.Bytes())
}
func polynomial(B, P, x *big.Int) *big.Int {
	x3 := new(big.Int).Mul(x, x)
	x3.Mul(x3, x)
	threeX := new(big.Int).Lsh(x, 1)
	threeX.Add(threeX, x)
	x3.Sub(x3, threeX)
	x3.Add(x3, B)
	x3.Mod(x3, P)
	return x3
}
func parsePubKeyCompressed(data []byte) (*ecdsa.PublicKey, error) {
	curve := elliptic.P256()
	byteLen := (curve.Params().BitSize + 7) / 8
	if len(data) != 1+byteLen {
		return nil, errors.New("parsePubKeyCompressed byteLen error")
	}
	if data[0] != 2 && data[0] != 3 {  
		return nil, errors.New("parsePubKeyCompressed compressed form error")
	}
	p := curve.Params().P
	x := new(big.Int).SetBytes(data[1:])
	if x.Cmp(p) >= 0 {
		return nil, errors.New("parsePubKeyCompressed x data error")
	}
	y := polynomial(curve.Params().B, curve.Params().P, x)
	y = y.ModSqrt(y, p)
	if y == nil {
		return nil, errors.New("parsePubKeyCompressed y data error")
	}
	if byte(y.Bit(0)) != data[0]&1 {
		y.Neg(y).Mod(y, p)
	}
	if !curve.IsOnCurve(x, y) {
		return nil, errors.New("parsePubKeyCompressed IsOnCurve error")
	}
	pubkey := ecdsa.PublicKey{}
	pubkey.Curve = curve
	pubkey.X = x
	pubkey.Y = y
	return &pubkey, nil
}