From 600f7740ccd933448e37815f564431fa6ab39c1e Mon Sep 17 00:00:00 2001 From: Devon Bear Date: Mon, 24 Jun 2024 03:54:34 -0400 Subject: [PATCH] fix(bls12381): go build flags were not configured correctly. (#20752) Co-authored-by: ocnc2 <169075746+ocnc2@users.noreply.github.com> --- crypto/keys/bls12_381/const.go | 7 ++++--- crypto/keys/bls12_381/key.go | 2 ++ crypto/keys/bls12_381/key_cgo.go | 16 +++++++++++----- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/crypto/keys/bls12_381/const.go b/crypto/keys/bls12_381/const.go index bfabbdcc56..4a9169259b 100644 --- a/crypto/keys/bls12_381/const.go +++ b/crypto/keys/bls12_381/const.go @@ -1,8 +1,10 @@ package bls12_381 const ( + // PrivKeyName is the name of the private key as it is stored in the keystore. PrivKeyName = "cometbft/PrivKeyBls12_381" - PubKeyName = "cometbft/PubKeyBls12_381" + // PubKeyName is the name of the public key as it is stored in the keystore. + PubKeyName = "cometbft/PubKeyBls12_381" // PubKeySize is the size, in bytes, of public keys as used in this package. PubKeySize = 32 // PrivKeySize is the size, in bytes, of private keys as used in this package. @@ -12,9 +14,8 @@ const ( // SeedSize is the size, in bytes, of private key seeds. These are the // private key representations used by RFC 8032. SeedSize = 32 - // MaxMsgLen defines the maximum length of the message bytes as passed to Sign. MaxMsgLen = 32 - + // KeyType is the type of key this package provides. KeyType = "bls12381" ) diff --git a/crypto/keys/bls12_381/key.go b/crypto/keys/bls12_381/key.go index 70370ceb87..fc146d5f80 100644 --- a/crypto/keys/bls12_381/key.go +++ b/crypto/keys/bls12_381/key.go @@ -1,3 +1,5 @@ +//go:build !bls12381 + package bls12_381 import ( diff --git a/crypto/keys/bls12_381/key_cgo.go b/crypto/keys/bls12_381/key_cgo.go index 9ad681179d..3e0fd433ae 100644 --- a/crypto/keys/bls12_381/key_cgo.go +++ b/crypto/keys/bls12_381/key_cgo.go @@ -36,13 +36,17 @@ func NewPrivateKeyFromBytes(bz []byte) (PrivKey, error) { if err != nil { return PrivKey{}, err } - return secretKey.Marshal(), nil + return PrivKey{ + Key: secretKey.Marshal(), + }, nil } // GenPrivKey generates a new key. func GenPrivKey() (PrivKey, error) { secretKey, err := bls12381.RandKey() - return PrivKey(secretKey.Marshal()), err + return PrivKey{ + Key: secretKey.Marshal(), + }, err } // Bytes returns the byte representation of the Key. @@ -58,7 +62,9 @@ func (privKey PrivKey) PubKey() cryptotypes.PubKey { return nil } - return PubKey(secretKey.PublicKey().Marshal()) + return &PubKey{ + Key: secretKey.PublicKey().Marshal(), + } } // Equals returns true if two keys are equal and false otherwise. @@ -68,7 +74,7 @@ func (privKey PrivKey) Equals(other cryptotypes.LedgerPrivKey) bool { // Type returns the type. func (PrivKey) Type() string { - return keyType + return KeyType } // Sign signs the given byte array. If msg is larger than @@ -167,7 +173,7 @@ func (pubKey PubKey) Bytes() []byte { // Type returns the key's type. func (PubKey) Type() string { - return keyType + return KeyType } // Equals returns true if the other's type is the same and their bytes are deeply equal.