mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-08 22:23:11 +00:00
crypto: remove proto privatekey (#5301)
## Description This type was used for json but was never removed once we migrated to tmjson. Closes: #XXX
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package encoding
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
@@ -40,36 +39,3 @@ func PubKeyFromProto(k pc.PublicKey) (crypto.PubKey, error) {
|
||||
return nil, fmt.Errorf("fromproto: key type %v is not supported", k)
|
||||
}
|
||||
}
|
||||
|
||||
// PrivKeyToProto takes crypto.PrivKey and transforms it to a protobuf PrivKey
|
||||
func PrivKeyToProto(k crypto.PrivKey) (pc.PrivateKey, error) {
|
||||
var kp pc.PrivateKey
|
||||
switch k := k.(type) {
|
||||
case ed25519.PrivKey:
|
||||
kp = pc.PrivateKey{
|
||||
Sum: &pc.PrivateKey_Ed25519{
|
||||
Ed25519: k,
|
||||
},
|
||||
}
|
||||
default:
|
||||
return kp, errors.New("toproto: key type is not supported")
|
||||
}
|
||||
return kp, nil
|
||||
}
|
||||
|
||||
// PrivKeyFromProto takes a protobuf PrivateKey and transforms it to a crypto.PrivKey
|
||||
func PrivKeyFromProto(k pc.PrivateKey) (crypto.PrivKey, error) {
|
||||
switch k := k.Sum.(type) {
|
||||
case *pc.PrivateKey_Ed25519:
|
||||
|
||||
if len(k.Ed25519) != ed25519.PubKeySize {
|
||||
return nil, fmt.Errorf("invalid size for PubKeyEd25519. Got %d, expected %d",
|
||||
len(k.Ed25519), ed25519.PubKeySize)
|
||||
}
|
||||
pk := make(ed25519.PrivKey, ed25519.PrivateKeySize)
|
||||
copy(pk, k.Ed25519)
|
||||
return pk, nil
|
||||
default:
|
||||
return nil, errors.New("fromproto: key type not supported")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user