77// scalarSize is the size of an encoded big endian scalar
88const scalarSize = 32
99
10- // Signature is same with schnorr.Signature
10+ // Signature represents the signature
1111type Signature struct {
1212 r btcec.FieldVal
1313 s btcec.ModNScalar
@@ -28,16 +28,40 @@ func NewSignature(sigBytes []byte) *Signature {
2828 }
2929}
3030
31- // NegatePoint negates the given point
32- func NegatePoint (point * btcec.JacobianPoint ) * btcec.JacobianPoint {
33- result := * point
34- result .Y .Negate (1 ).Normalize ()
31+ // Serialize serializes the signature
32+ func (s * Signature ) Serialize () []byte {
33+ sig := make ([]byte , 64 )
3534
36- return & result
35+ rBytes := * s .r .Bytes ()
36+ sBytes := s .s .Bytes ()
37+
38+ copy (sig [0 :32 ], rBytes [:])
39+ copy (sig [32 :64 ], sBytes [:])
40+
41+ return sig
3742}
3843
3944// SerializeScalar serializes the given scalar
4045func SerializeScalar (scalar * btcec.ModNScalar ) []byte {
4146 bz := scalar .Bytes ()
4247 return bz [:]
4348}
49+
50+ // SecretToPubKey gets the serialized public key of the given secret on the secp256k1 curve
51+ func SecretToPubKey (secretBytes []byte ) []byte {
52+ var secret btcec.ModNScalar
53+ secret .SetByteSlice (secretBytes )
54+
55+ var result btcec.JacobianPoint
56+ btcec .ScalarBaseMultNonConst (& secret , & result )
57+
58+ return btcec .JacobianToByteSlice (result )
59+ }
60+
61+ // NegatePoint negates the given point
62+ func NegatePoint (point * btcec.JacobianPoint ) * btcec.JacobianPoint {
63+ result := * point
64+ result .Y .Negate (1 ).Normalize ()
65+
66+ return & result
67+ }
0 commit comments