Added constants for secp256k1
@@ -9,10 +9,16 @@ import (
"github.com/ethereum/go-ethereum/crypto/secp256k1"
)
+const (
+ Secp256k1PubKeyBytes = 33
+ Secp256k1PrivKeyBytes = 32
+ Secp256k1SigBytes = 64
+)
+
// Secp256k1Signer implements the Signer interface using secp256k1 keys
type Secp256k1Signer struct {
- privateKey [32]byte
- publicKey [33]byte
+ privateKey [Secp256k1PrivKeyBytes]byte
+ publicKey [Secp256k1PubKeyBytes]byte
}
func NewSecp256k1Signer(privateKey []byte) *Secp256k1Signer {
@@ -23,7 +29,7 @@ func NewSecp256k1Signer(privateKey []byte) *Secp256k1Signer {
copy(secp256k1Signer.publicKey[:], pubKeyBytes[:])
copy(secp256k1Signer.privateKey[:], privKeyBytes[:])
} else {
- if len(privateKey) != 32 {
+ if len(privateKey) != Secp256k1PrivKeyBytes {
panic(errors.New("Invalid private key length"))
}
@@ -49,15 +55,15 @@ func GenSecp256k1Key() ([]byte, []byte) {
pubKey = secp256k1.CompressPubkey(key.X, key.Y)
- privKeyBytes := make([]byte, 32)
+ privKeyBytes := make([]byte, Secp256k1PrivKeyBytes)
blob := key.D.Bytes()
- copy(privKeyBytes[32-len(blob):], blob)
+ copy(privKeyBytes[Secp256k1PrivKeyBytes-len(blob):], blob)
return pubKey, privKeyBytes[:]
}
func (s *Secp256k1Signer) Sign(msg []byte) []byte {
- var sig [64]byte
+ var sig [Secp256k1SigBytes]byte
hash := sha256.Sum256(msg)
sigBytes, err := secp256k1.Sign(hash[:], s.privateKey[:])
