@@ -25,8 +25,8 @@ import (
25
25
"fmt"
26
26
"math/big"
27
27
28
- "github.com/btcsuite/btcd/btcec/v2 "
29
- btc_ecdsa "github.com/btcsuite/btcd/btcec/v2 /ecdsa"
28
+ "github.com/decred/dcrd/dcrec/secp256k1/v4 "
29
+ decred_ecdsa "github.com/decred/dcrd/dcrec/secp256k1/v4 /ecdsa"
30
30
)
31
31
32
32
// Ecrecover returns the uncompressed public key that created the given signature.
@@ -39,16 +39,16 @@ func Ecrecover(hash, sig []byte) ([]byte, error) {
39
39
return bytes , err
40
40
}
41
41
42
- func sigToPub (hash , sig []byte ) (* btcec .PublicKey , error ) {
42
+ func sigToPub (hash , sig []byte ) (* secp256k1 .PublicKey , error ) {
43
43
if len (sig ) != SignatureLength {
44
44
return nil , errors .New ("invalid signature" )
45
45
}
46
- // Convert to btcec input format with 'recovery id' v at the beginning.
46
+ // Convert to secp256k1 input format with 'recovery id' v at the beginning.
47
47
btcsig := make ([]byte , SignatureLength )
48
48
btcsig [0 ] = sig [RecoveryIDOffset ] + 27
49
49
copy (btcsig [1 :], sig )
50
50
51
- pub , _ , err := btc_ecdsa .RecoverCompact (btcsig , hash )
51
+ pub , _ , err := decred_ecdsa .RecoverCompact (btcsig , hash )
52
52
return pub , err
53
53
}
54
54
@@ -82,13 +82,13 @@ func Sign(hash []byte, prv *ecdsa.PrivateKey) ([]byte, error) {
82
82
if prv .Curve != S256 () {
83
83
return nil , errors .New ("private key curve is not secp256k1" )
84
84
}
85
- // ecdsa.PrivateKey -> btcec .PrivateKey
86
- var priv btcec .PrivateKey
85
+ // ecdsa.PrivateKey -> secp256k1 .PrivateKey
86
+ var priv secp256k1 .PrivateKey
87
87
if overflow := priv .Key .SetByteSlice (prv .D .Bytes ()); overflow || priv .Key .IsZero () {
88
88
return nil , errors .New ("invalid private key" )
89
89
}
90
90
defer priv .Zero ()
91
- sig := btc_ecdsa .SignCompact (& priv , hash , false ) // ref uncompressed pubkey
91
+ sig := decred_ecdsa .SignCompact (& priv , hash , false ) // ref uncompressed pubkey
92
92
// Convert to Ethereum signature format with 'recovery id' v at the end.
93
93
v := sig [0 ] - 27
94
94
copy (sig , sig [1 :])
@@ -103,19 +103,19 @@ func VerifySignature(pubkey, hash, signature []byte) bool {
103
103
if len (signature ) != 64 {
104
104
return false
105
105
}
106
- var r , s btcec .ModNScalar
106
+ var r , s secp256k1 .ModNScalar
107
107
if r .SetByteSlice (signature [:32 ]) {
108
108
return false // overflow
109
109
}
110
110
if s .SetByteSlice (signature [32 :]) {
111
111
return false
112
112
}
113
- sig := btc_ecdsa .NewSignature (& r , & s )
114
- key , err := btcec .ParsePubKey (pubkey )
113
+ sig := decred_ecdsa .NewSignature (& r , & s )
114
+ key , err := secp256k1 .ParsePubKey (pubkey )
115
115
if err != nil {
116
116
return false
117
117
}
118
- // Reject malleable signatures. libsecp256k1 does this check but btcec doesn't.
118
+ // Reject malleable signatures. libsecp256k1 does this check but decred doesn't.
119
119
if s .IsOverHalfOrder () {
120
120
return false
121
121
}
@@ -127,7 +127,7 @@ func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error) {
127
127
if len (pubkey ) != 33 {
128
128
return nil , errors .New ("invalid compressed public key length" )
129
129
}
130
- key , err := btcec .ParsePubKey (pubkey )
130
+ key , err := secp256k1 .ParsePubKey (pubkey )
131
131
if err != nil {
132
132
return nil , err
133
133
}
@@ -148,20 +148,20 @@ func DecompressPubkey(pubkey []byte) (*ecdsa.PublicKey, error) {
148
148
// when constructing a PrivateKey.
149
149
func CompressPubkey (pubkey * ecdsa.PublicKey ) []byte {
150
150
// NOTE: the coordinates may be validated with
151
- // btcec .ParsePubKey(FromECDSAPub(pubkey))
152
- var x , y btcec .FieldVal
151
+ // secp256k1 .ParsePubKey(FromECDSAPub(pubkey))
152
+ var x , y secp256k1 .FieldVal
153
153
x .SetByteSlice (pubkey .X .Bytes ())
154
154
y .SetByteSlice (pubkey .Y .Bytes ())
155
- return btcec .NewPublicKey (& x , & y ).SerializeCompressed ()
155
+ return secp256k1 .NewPublicKey (& x , & y ).SerializeCompressed ()
156
156
}
157
157
158
158
// S256 returns an instance of the secp256k1 curve.
159
159
func S256 () EllipticCurve {
160
- return btCurve {btcec .S256 ()}
160
+ return btCurve {secp256k1 .S256 ()}
161
161
}
162
162
163
163
type btCurve struct {
164
- * btcec .KoblitzCurve
164
+ * secp256k1 .KoblitzCurve
165
165
}
166
166
167
167
// Marshal converts a point given as (x, y) into a byte slice.
0 commit comments