7
7
// scalarSize is the size of an encoded big endian scalar
8
8
const scalarSize = 32
9
9
10
- // Signature is same with schnorr.Signature
10
+ // Signature represents the signature
11
11
type Signature struct {
12
12
r btcec.FieldVal
13
13
s btcec.ModNScalar
@@ -28,16 +28,40 @@ func NewSignature(sigBytes []byte) *Signature {
28
28
}
29
29
}
30
30
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 )
35
34
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
37
42
}
38
43
39
44
// SerializeScalar serializes the given scalar
40
45
func SerializeScalar (scalar * btcec.ModNScalar ) []byte {
41
46
bz := scalar .Bytes ()
42
47
return bz [:]
43
48
}
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