Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
fix: always generate even compressed public keys (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
atanmarko committed Sep 15, 2023
1 parent daf4ac8 commit 4b7f2fb
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions secrets/helper/helper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package helper

import (
"crypto/ecdsa"
"errors"
"fmt"

Expand Down Expand Up @@ -76,9 +77,25 @@ func InitECDSAValidatorKey(secretsManager secrets.SecretsManager) (types.Address
return types.ZeroAddress, fmt.Errorf(`secrets "%s" has been already initialized`, secrets.ValidatorKey)
}

validatorKey, validatorKeyEncoded, err := crypto.GenerateAndEncodeECDSAPrivateKey()
if err != nil {
return types.ZeroAddress, err
// As a temporary workaround until sequencer switches to FROST signatures,
// it expects even secp256k1 public keys (when compressed starting with 0x02)
// Generate private keys until you get even public key
var (
validatorKey *ecdsa.PrivateKey
validatorKeyEncoded []byte
err error
)

for {
validatorKey, validatorKeyEncoded, err = crypto.GenerateAndEncodeECDSAPrivateKey()
if err != nil {
return types.ZeroAddress, err
}

y := validatorKey.PublicKey.Y.Bytes()
if y[31]%2 == 0 {
break
}
}

address := crypto.PubKeyToAddress(&validatorKey.PublicKey)
Expand Down

0 comments on commit 4b7f2fb

Please sign in to comment.