Skip to content

Commit

Permalink
[network] Simplify libp2p -> flow after adding DecodepublicKeyCompressed
Browse files Browse the repository at this point in the history
  • Loading branch information
huitseeker committed Aug 12, 2021
1 parent 1935ef3 commit 70fa19e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions network/p2p/keyTranslator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (

"github.com/onflow/flow-go/crypto"
fcrypto "github.com/onflow/flow-go/crypto"

"github.com/btcsuite/btcd/btcec"
)

// This module is meant to help libp2p <-> flow public key conversions
Expand Down Expand Up @@ -143,9 +141,11 @@ func PublicKeyFromNetwork(lpk lcrypto.PubKey) (fcrypto.PublicKey, error) {
if !ok {
return nil, lcrypto.ErrBadKeyType
}
pk_uncompressed := (*btcec.PublicKey)(lpk_secp256k1).SerializeUncompressed()
// the first bit is the compression bit of X9.62
pk, err := crypto.DecodePublicKey(crypto.ECDSASecp256k1, pk_uncompressed[1:])
secpBytes, err := lpk_secp256k1.Raw()
if err != nil { // this never errors
return nil, lcrypto.ErrBadKeyType
}
pk, err := crypto.DecodePublicKeyCompressed(crypto.ECDSASecp256k1, secpBytes)
if err != nil {
return nil, lcrypto.ErrNotECDSAPubKey
}
Expand Down

0 comments on commit 70fa19e

Please sign in to comment.