diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 79241726f..a4388b2c8 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -12,6 +12,14 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi - [evidence] \#4725 Remove `Pubkey` from DuplicateVoteEvidence - [rpc] [\#4792](https://github.com/tendermint/tendermint/pull/4792) `/validators` are now sorted by voting power (@melekes) + - [crypto] \#4941 Remove suffixes from all keys. + - ed25519: type `PrivKeyEd25519` is now `PrivKey` + - ed25519: type `PubKeyEd25519` is now `PubKey` + - secp256k1: type`PrivKeySecp256k1` is now `PrivKey` + - secp256k1: type`PubKeySecp256k1` is now `PubKey` + - sr25519: type `PrivKeySr25519` is now `PrivKey` + - sr25519: type `PubKeySr25519` is now `PubKey` + - multisig: type `PubKeyMultisigThreshold` is now `PubKey` - Apps diff --git a/abci/example/kvstore/persistent_kvstore.go b/abci/example/kvstore/persistent_kvstore.go index f4ba2da9d..245d3e96d 100644 --- a/abci/example/kvstore/persistent_kvstore.go +++ b/abci/example/kvstore/persistent_kvstore.go @@ -232,7 +232,7 @@ func (app *PersistentKVStoreApplication) execValidatorTx(tx []byte) types.Respon func (app *PersistentKVStoreApplication) updateValidator(v types.ValidatorUpdate) types.ResponseDeliverTx { key := []byte("val:" + string(v.PubKey.Data)) - pubkey := ed25519.PubKeyEd25519{} + pubkey := ed25519.PubKey{} copy(pubkey[:], v.PubKey.Data) if v.Power == 0 { diff --git a/crypto/README.md b/crypto/README.md index cfbceb449..3b31dea26 100644 --- a/crypto/README.md +++ b/crypto/README.md @@ -3,6 +3,7 @@ crypto is the cryptographic package adapted for Tendermint's uses ## Importing it + To get the interfaces, `import "github.com/tendermint/tendermint/crypto"` @@ -23,8 +24,8 @@ crypto `.Bytes()` uses Amino:binary encoding, but Amino:JSON is also supported. ```go Example Amino:JSON encodings: -ed25519.PrivKeyEd25519 - {"type":"tendermint/PrivKeyEd25519","value":"EVkqJO/jIXp3rkASXfh9YnyToYXRXhBr6g9cQVxPFnQBP/5povV4HTjvsy530kybxKHwEi85iU8YL0qQhSYVoQ=="} -ed25519.PubKeyEd25519 - {"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="} +ed25519.PrivKey - {"type":"tendermint/PrivKeyEd25519","value":"EVkqJO/jIXp3rkASXfh9YnyToYXRXhBr6g9cQVxPFnQBP/5povV4HTjvsy530kybxKHwEi85iU8YL0qQhSYVoQ=="} +ed25519.PubKey - {"type":"tendermint/PubKeyEd25519","value":"AT/+aaL1eB0477Mud9JMm8Sh8BIvOYlPGC9KkIUmFaE="} sr25519.PrivKeySr25519 - {"type":"tendermint/PrivKeySr25519","value":"xtYVH8UCIqfrY8FIFc0QEpAEBShSG4NT0zlEOVSZ2w4="} sr25519.PubKeySr25519 - {"type":"tendermint/PubKeySr25519","value":"8sKBLKQ/OoXMcAJVxBqz1U7TyxRFQ5cmliuHy4MrF0s="} crypto.PrivKeySecp256k1 - {"type":"tendermint/PrivKeySecp256k1","value":"zx4Pnh67N+g2V+5vZbQzEyRerX9c4ccNZOVzM9RvJ0Y="} diff --git a/crypto/ed25519/ed25519.go b/crypto/ed25519/ed25519.go index ff19b93d8..33245db81 100644 --- a/crypto/ed25519/ed25519.go +++ b/crypto/ed25519/ed25519.go @@ -15,7 +15,7 @@ import ( //------------------------------------- -var _ crypto.PrivKey = PrivKeyEd25519{} +var _ crypto.PrivKey = PrivKey{} const ( PrivKeyAminoName = "tendermint/PrivKeyEd25519" @@ -29,19 +29,19 @@ var cdc = amino.NewCodec() func init() { cdc.RegisterInterface((*crypto.PubKey)(nil), nil) - cdc.RegisterConcrete(PubKeyEd25519{}, + cdc.RegisterConcrete(PubKey{}, PubKeyAminoName, nil) cdc.RegisterInterface((*crypto.PrivKey)(nil), nil) - cdc.RegisterConcrete(PrivKeyEd25519{}, + cdc.RegisterConcrete(PrivKey{}, PrivKeyAminoName, nil) } -// PrivKeyEd25519 implements crypto.PrivKey. -type PrivKeyEd25519 [64]byte +// PrivKey implements crypto.PrivKey. +type PrivKey [64]byte // Bytes marshals the privkey using amino encoding. -func (privKey PrivKeyEd25519) Bytes() []byte { +func (privKey PrivKey) Bytes() []byte { return cdc.MustMarshalBinaryBare(privKey) } @@ -52,13 +52,13 @@ func (privKey PrivKeyEd25519) Bytes() []byte { // The latter 32 bytes should be the compressed public key. // If these conditions aren't met, Sign will panic or produce an // incorrect signature. -func (privKey PrivKeyEd25519) Sign(msg []byte) ([]byte, error) { +func (privKey PrivKey) Sign(msg []byte) ([]byte, error) { signatureBytes := ed25519.Sign(privKey[:], msg) return signatureBytes, nil } // PubKey gets the corresponding public key from the private key. -func (privKey PrivKeyEd25519) PubKey() crypto.PubKey { +func (privKey PrivKey) PubKey() crypto.PubKey { privKeyBytes := [64]byte(privKey) initialized := false // If the latter 32 bytes of the privkey are all zero, compute the pubkey @@ -72,18 +72,18 @@ func (privKey PrivKeyEd25519) PubKey() crypto.PubKey { } if !initialized { - panic("Expected PrivKeyEd25519 to include concatenated pubkey bytes") + panic("Expected ed25519 PrivKey to include concatenated pubkey bytes") } - var pubkeyBytes [PubKeyEd25519Size]byte + var pubkeyBytes [PubKeySize]byte copy(pubkeyBytes[:], privKeyBytes[32:]) - return PubKeyEd25519(pubkeyBytes) + return PubKey(pubkeyBytes) } // Equals - you probably don't need to use this. // Runs in constant time based on length of the keys. -func (privKey PrivKeyEd25519) Equals(other crypto.PrivKey) bool { - if otherEd, ok := other.(PrivKeyEd25519); ok { +func (privKey PrivKey) Equals(other crypto.PrivKey) bool { + if otherEd, ok := other.(PrivKey); ok { return subtle.ConstantTimeCompare(privKey[:], otherEd[:]) == 1 } @@ -93,12 +93,12 @@ func (privKey PrivKeyEd25519) Equals(other crypto.PrivKey) bool { // GenPrivKey generates a new ed25519 private key. // It uses OS randomness in conjunction with the current global random seed // in tendermint/libs/common to generate the private key. -func GenPrivKey() PrivKeyEd25519 { +func GenPrivKey() PrivKey { return genPrivKey(crypto.CReader()) } // genPrivKey generates a new ed25519 private key using the provided reader. -func genPrivKey(rand io.Reader) PrivKeyEd25519 { +func genPrivKey(rand io.Reader) PrivKey { seed := make([]byte, 32) _, err := io.ReadFull(rand, seed) if err != nil { @@ -106,7 +106,7 @@ func genPrivKey(rand io.Reader) PrivKeyEd25519 { } privKey := ed25519.NewKeyFromSeed(seed) - var privKeyEd PrivKeyEd25519 + var privKeyEd PrivKey copy(privKeyEd[:], privKey) return privKeyEd } @@ -115,32 +115,32 @@ func genPrivKey(rand io.Reader) PrivKeyEd25519 { // that 32 byte output to create the private key. // NOTE: secret should be the output of a KDF like bcrypt, // if it's derived from user input. -func GenPrivKeyFromSecret(secret []byte) PrivKeyEd25519 { +func GenPrivKeyFromSecret(secret []byte) PrivKey { seed := crypto.Sha256(secret) // Not Ripemd160 because we want 32 bytes. privKey := ed25519.NewKeyFromSeed(seed) - var privKeyEd PrivKeyEd25519 + var privKeyEd PrivKey copy(privKeyEd[:], privKey) return privKeyEd } //------------------------------------- -var _ crypto.PubKey = PubKeyEd25519{} +var _ crypto.PubKey = PubKey{} -// PubKeyEd25519Size is the number of bytes in an Ed25519 signature. -const PubKeyEd25519Size = 32 +// PubKeySize is the number of bytes in an Ed25519 signature. +const PubKeySize = 32 -// PubKeyEd25519 implements crypto.PubKey for the Ed25519 signature scheme. -type PubKeyEd25519 [PubKeyEd25519Size]byte +// PubKey implements crypto.PubKey for the Ed25519 signature scheme. +type PubKey [PubKeySize]byte // Address is the SHA256-20 of the raw pubkey bytes. -func (pubKey PubKeyEd25519) Address() crypto.Address { +func (pubKey PubKey) Address() crypto.Address { return crypto.Address(tmhash.SumTruncated(pubKey[:])) } // Bytes marshals the PubKey using amino encoding. -func (pubKey PubKeyEd25519) Bytes() []byte { +func (pubKey PubKey) Bytes() []byte { bz, err := cdc.MarshalBinaryBare(pubKey) if err != nil { panic(err) @@ -148,7 +148,7 @@ func (pubKey PubKeyEd25519) Bytes() []byte { return bz } -func (pubKey PubKeyEd25519) VerifyBytes(msg []byte, sig []byte) bool { +func (pubKey PubKey) VerifyBytes(msg []byte, sig []byte) bool { // make sure we use the same algorithm to sign if len(sig) != SignatureSize { return false @@ -156,12 +156,12 @@ func (pubKey PubKeyEd25519) VerifyBytes(msg []byte, sig []byte) bool { return ed25519.Verify(pubKey[:], msg, sig) } -func (pubKey PubKeyEd25519) String() string { - return fmt.Sprintf("PubKeyEd25519{%X}", pubKey[:]) +func (pubKey PubKey) String() string { + return fmt.Sprintf("PubKey{%X}", pubKey[:]) } -func (pubKey PubKeyEd25519) Equals(other crypto.PubKey) bool { - if otherEd, ok := other.(PubKeyEd25519); ok { +func (pubKey PubKey) Equals(other crypto.PubKey) bool { + if otherEd, ok := other.(PubKey); ok { return bytes.Equal(pubKey[:], otherEd[:]) } diff --git a/crypto/encoding/amino/amino.go b/crypto/encoding/amino/amino.go index f7a2dde77..3da6078ee 100644 --- a/crypto/encoding/amino/amino.go +++ b/crypto/encoding/amino/amino.go @@ -17,7 +17,7 @@ var cdc = amino.NewCodec() // nameTable is used to map public key concrete types back // to their registered amino names. This should eventually be handled // by amino. Example usage: -// nameTable[reflect.TypeOf(ed25519.PubKeyEd25519{})] = ed25519.PubKeyAminoName +// nameTable[reflect.TypeOf(ed25519.PubKey{})] = ed25519.PubKeyAminoName var nameTable = make(map[reflect.Type]string, 3) func init() { @@ -31,10 +31,10 @@ func init() { // TODO: Have amino provide a way to go from concrete struct to route directly. // Its currently a private API - nameTable[reflect.TypeOf(ed25519.PubKeyEd25519{})] = ed25519.PubKeyAminoName - nameTable[reflect.TypeOf(sr25519.PubKeySr25519{})] = sr25519.PubKeyAminoName - nameTable[reflect.TypeOf(secp256k1.PubKeySecp256k1{})] = secp256k1.PubKeyAminoName - nameTable[reflect.TypeOf(multisig.PubKeyMultisigThreshold{})] = multisig.PubKeyMultisigThresholdAminoRoute + nameTable[reflect.TypeOf(ed25519.PubKey{})] = ed25519.PubKeyAminoName + nameTable[reflect.TypeOf(sr25519.PubKey{})] = sr25519.PubKeyAminoName + nameTable[reflect.TypeOf(secp256k1.PubKey{})] = secp256k1.PubKeyAminoName + nameTable[reflect.TypeOf(multisig.PubKey{})] = multisig.PubKeyAminoRoute } // PubkeyAminoName returns the amino route of a pubkey @@ -49,21 +49,21 @@ func PubkeyAminoName(cdc *amino.Codec, key crypto.PubKey) (string, bool) { func RegisterAmino(cdc *amino.Codec) { // These are all written here instead of cdc.RegisterInterface((*crypto.PubKey)(nil), nil) - cdc.RegisterConcrete(ed25519.PubKeyEd25519{}, + cdc.RegisterConcrete(ed25519.PubKey{}, ed25519.PubKeyAminoName, nil) - cdc.RegisterConcrete(sr25519.PubKeySr25519{}, + cdc.RegisterConcrete(sr25519.PubKey{}, sr25519.PubKeyAminoName, nil) - cdc.RegisterConcrete(secp256k1.PubKeySecp256k1{}, + cdc.RegisterConcrete(secp256k1.PubKey{}, secp256k1.PubKeyAminoName, nil) - cdc.RegisterConcrete(multisig.PubKeyMultisigThreshold{}, - multisig.PubKeyMultisigThresholdAminoRoute, nil) + cdc.RegisterConcrete(multisig.PubKey{}, + multisig.PubKeyAminoRoute, nil) cdc.RegisterInterface((*crypto.PrivKey)(nil), nil) - cdc.RegisterConcrete(ed25519.PrivKeyEd25519{}, + cdc.RegisterConcrete(ed25519.PrivKey{}, ed25519.PrivKeyAminoName, nil) - cdc.RegisterConcrete(sr25519.PrivKeySr25519{}, + cdc.RegisterConcrete(sr25519.PrivKey{}, sr25519.PrivKeyAminoName, nil) - cdc.RegisterConcrete(secp256k1.PrivKeySecp256k1{}, + cdc.RegisterConcrete(secp256k1.PrivKey{}, secp256k1.PrivKeyAminoName, nil) } diff --git a/crypto/encoding/amino/encode_test.go b/crypto/encoding/amino/encode_test.go index edc54292f..18be9351c 100644 --- a/crypto/encoding/amino/encode_test.go +++ b/crypto/encoding/amino/encode_test.go @@ -58,13 +58,13 @@ func ExamplePrintRegisteredTypes() { cdc.PrintTypes(os.Stdout) // Output: | Type | Name | Prefix | Length | Notes | //| ---- | ---- | ------ | ----- | ------ | - //| PubKeyEd25519 | tendermint/PubKeyEd25519 | 0x1624DE64 | 0x20 | | - //| PubKeySr25519 | tendermint/PubKeySr25519 | 0x0DFB1005 | 0x20 | | - //| PubKeySecp256k1 | tendermint/PubKeySecp256k1 | 0xEB5AE987 | 0x21 | | - //| PubKeyMultisigThreshold | tendermint/PubKeyMultisigThreshold | 0x22C1F7E2 | variable | | - //| PrivKeyEd25519 | tendermint/PrivKeyEd25519 | 0xA3288910 | 0x40 | | - //| PrivKeySr25519 | tendermint/PrivKeySr25519 | 0x2F82D78B | 0x20 | | - //| PrivKeySecp256k1 | tendermint/PrivKeySecp256k1 | 0xE1B0F79B | 0x20 | | + //| PubKey | tendermint/PubKeyEd25519 | 0x1624DE64 | 0x20 | | + //| PubKey | tendermint/PubKeySr25519 | 0x0DFB1005 | 0x20 | | + //| PubKey | tendermint/PubKeySecp256k1 | 0xEB5AE987 | 0x21 | | + //| PubKey | tendermint/PubKeyMultisigThreshold | 0x22C1F7E2 | variable | | + //| PrivKey | tendermint/PrivKeyEd25519 | 0xA3288910 | 0x40 | | + //| PrivKey | tendermint/PrivKeySr25519 | 0x2F82D78B | 0x20 | | + //| PrivKey | tendermint/PrivKeySecp256k1 | 0xE1B0F79B | 0x20 | | } func TestKeyEncodings(t *testing.T) { @@ -148,10 +148,10 @@ func TestPubkeyAminoName(t *testing.T) { want string found bool }{ - {ed25519.PubKeyEd25519{}, ed25519.PubKeyAminoName, true}, - {sr25519.PubKeySr25519{}, sr25519.PubKeyAminoName, true}, - {secp256k1.PubKeySecp256k1{}, secp256k1.PubKeyAminoName, true}, - {multisig.PubKeyMultisigThreshold{}, multisig.PubKeyMultisigThresholdAminoRoute, true}, + {ed25519.PubKey{}, ed25519.PubKeyAminoName, true}, + {sr25519.PubKey{}, sr25519.PubKeyAminoName, true}, + {secp256k1.PubKey{}, secp256k1.PubKeyAminoName, true}, + {multisig.PubKey{}, multisig.PubKeyAminoRoute, true}, } for i, tc := range tests { got, found := PubkeyAminoName(cdc, tc.key) @@ -229,8 +229,8 @@ func TestRegisterKeyType(t *testing.T) { cdc = amino.NewCodec() nameTable = make(map[reflect.Type]string, 3) RegisterAmino(cdc) - nameTable[reflect.TypeOf(ed25519.PubKeyEd25519{})] = ed25519.PubKeyAminoName - nameTable[reflect.TypeOf(sr25519.PubKeySr25519{})] = sr25519.PubKeyAminoName - nameTable[reflect.TypeOf(secp256k1.PubKeySecp256k1{})] = secp256k1.PubKeyAminoName - nameTable[reflect.TypeOf(multisig.PubKeyMultisigThreshold{})] = multisig.PubKeyMultisigThresholdAminoRoute + nameTable[reflect.TypeOf(ed25519.PubKey{})] = ed25519.PubKeyAminoName + nameTable[reflect.TypeOf(sr25519.PubKey{})] = sr25519.PubKeyAminoName + nameTable[reflect.TypeOf(secp256k1.PubKey{})] = secp256k1.PubKeyAminoName + nameTable[reflect.TypeOf(multisig.PubKey{})] = multisig.PubKeyAminoRoute } diff --git a/crypto/encoding/codec.go b/crypto/encoding/codec.go index 05d64e00e..961d7770b 100644 --- a/crypto/encoding/codec.go +++ b/crypto/encoding/codec.go @@ -13,7 +13,7 @@ import ( func PubKeyToProto(k crypto.PubKey) (pc.PublicKey, error) { var kp pc.PublicKey switch k := k.(type) { - case ed25519.PubKeyEd25519: + case ed25519.PubKey: kp = pc.PublicKey{ Sum: &pc.PublicKey_Ed25519{ Ed25519: k[:], @@ -29,11 +29,11 @@ func PubKeyToProto(k crypto.PubKey) (pc.PublicKey, error) { func PubKeyFromProto(k pc.PublicKey) (crypto.PubKey, error) { switch k := k.Sum.(type) { case *pc.PublicKey_Ed25519: - if len(k.Ed25519) != ed25519.PubKeyEd25519Size { + if len(k.Ed25519) != ed25519.PubKeySize { return nil, fmt.Errorf("invalid size for PubKeyEd25519. Got %d, expected %d", - len(k.Ed25519), ed25519.PubKeyEd25519Size) + len(k.Ed25519), ed25519.PubKeySize) } - var pk ed25519.PubKeyEd25519 + var pk ed25519.PubKey copy(pk[:], k.Ed25519) return pk, nil default: @@ -45,7 +45,7 @@ func PubKeyFromProto(k pc.PublicKey) (crypto.PubKey, error) { func PrivKeyToProto(k crypto.PrivKey) (pc.PrivateKey, error) { var kp pc.PrivateKey switch k := k.(type) { - case ed25519.PrivKeyEd25519: + case ed25519.PrivKey: kp = pc.PrivateKey{ Sum: &pc.PrivateKey_Ed25519{ Ed25519: k[:], @@ -62,11 +62,11 @@ func PrivKeyFromProto(k pc.PrivateKey) (crypto.PrivKey, error) { switch k := k.Sum.(type) { case *pc.PrivateKey_Ed25519: - if len(k.Ed25519) != ed25519.PubKeyEd25519Size { + if len(k.Ed25519) != ed25519.PubKeySize { return nil, fmt.Errorf("invalid size for PubKeyEd25519. Got %d, expected %d", - len(k.Ed25519), ed25519.PubKeyEd25519Size) + len(k.Ed25519), ed25519.PubKeySize) } - var pk ed25519.PrivKeyEd25519 + var pk ed25519.PrivKey copy(pk[:], k.Ed25519) return pk, nil default: diff --git a/crypto/multisig/codec.go b/crypto/multisig/codec.go index cc1e12f92..f56cfed28 100644 --- a/crypto/multisig/codec.go +++ b/crypto/multisig/codec.go @@ -12,19 +12,19 @@ import ( // TODO: Figure out API for others to either add their own pubkey types, or // to make verify / marshal accept a cdc. const ( - PubKeyMultisigThresholdAminoRoute = "tendermint/PubKeyMultisigThreshold" + PubKeyAminoRoute = "tendermint/PubKeyMultisigThreshold" ) var cdc = amino.NewCodec() func init() { cdc.RegisterInterface((*crypto.PubKey)(nil), nil) - cdc.RegisterConcrete(PubKeyMultisigThreshold{}, - PubKeyMultisigThresholdAminoRoute, nil) - cdc.RegisterConcrete(ed25519.PubKeyEd25519{}, + cdc.RegisterConcrete(PubKey{}, + PubKeyAminoRoute, nil) + cdc.RegisterConcrete(ed25519.PubKey{}, ed25519.PubKeyAminoName, nil) - cdc.RegisterConcrete(sr25519.PubKeySr25519{}, + cdc.RegisterConcrete(sr25519.PubKey{}, sr25519.PubKeyAminoName, nil) - cdc.RegisterConcrete(secp256k1.PubKeySecp256k1{}, + cdc.RegisterConcrete(secp256k1.PubKey{}, secp256k1.PubKeyAminoName, nil) } diff --git a/crypto/multisig/threshold_pubkey.go b/crypto/multisig/threshold_pubkey.go index 36e2dc2dd..3e0deb83b 100644 --- a/crypto/multisig/threshold_pubkey.go +++ b/crypto/multisig/threshold_pubkey.go @@ -4,13 +4,13 @@ import ( "github.com/tendermint/tendermint/crypto" ) -// PubKeyMultisigThreshold implements a K of N threshold multisig. -type PubKeyMultisigThreshold struct { +// PubKey implements a K of N threshold multisig. +type PubKey struct { K uint `json:"threshold"` PubKeys []crypto.PubKey `json:"pubkeys"` } -var _ crypto.PubKey = PubKeyMultisigThreshold{} +var _ crypto.PubKey = PubKey{} // NewPubKeyMultisigThreshold returns a new PubKeyMultisigThreshold. // Panics if len(pubkeys) < k or 0 >= k. @@ -26,7 +26,7 @@ func NewPubKeyMultisigThreshold(k int, pubkeys []crypto.PubKey) crypto.PubKey { panic("nil pubkey") } } - return PubKeyMultisigThreshold{uint(k), pubkeys} + return PubKey{uint(k), pubkeys} } // VerifyBytes expects sig to be an amino encoded version of a MultiSignature. @@ -35,7 +35,7 @@ func NewPubKeyMultisigThreshold(k int, pubkeys []crypto.PubKey) crypto.PubKey { // and all signatures are valid. (Not just k of the signatures) // The multisig uses a bitarray, so multiple signatures for the same key is not // a concern. -func (pk PubKeyMultisigThreshold) VerifyBytes(msg []byte, marshalledSig []byte) bool { +func (pk PubKey) VerifyBytes(msg []byte, marshalledSig []byte) bool { var sig Multisignature err := cdc.UnmarshalBinaryBare(marshalledSig, &sig) if err != nil { @@ -67,20 +67,20 @@ func (pk PubKeyMultisigThreshold) VerifyBytes(msg []byte, marshalledSig []byte) return true } -// Bytes returns the amino encoded version of the PubKeyMultisigThreshold -func (pk PubKeyMultisigThreshold) Bytes() []byte { +// Bytes returns the amino encoded version of the PubKey +func (pk PubKey) Bytes() []byte { return cdc.MustMarshalBinaryBare(pk) } -// Address returns tmhash(PubKeyMultisigThreshold.Bytes()) -func (pk PubKeyMultisigThreshold) Address() crypto.Address { +// Address returns tmhash(PubKey.Bytes()) +func (pk PubKey) Address() crypto.Address { return crypto.AddressHash(pk.Bytes()) } // Equals returns true iff pk and other both have the same number of keys, and // all constituent keys are the same, and in the same order. -func (pk PubKeyMultisigThreshold) Equals(other crypto.PubKey) bool { - otherKey, sameType := other.(PubKeyMultisigThreshold) +func (pk PubKey) Equals(other crypto.PubKey) bool { + otherKey, sameType := other.(PubKey) if !sameType { return false } diff --git a/crypto/multisig/threshold_pubkey_test.go b/crypto/multisig/threshold_pubkey_test.go index 34b6a4773..a3aebe6f0 100644 --- a/crypto/multisig/threshold_pubkey_test.go +++ b/crypto/multisig/threshold_pubkey_test.go @@ -125,7 +125,7 @@ func TestMultiSigPubKeyEquality(t *testing.T) { msg := []byte{1, 2, 3, 4} pubkeys, _ := generatePubKeysAndSignatures(5, msg) multisigKey := NewPubKeyMultisigThreshold(2, pubkeys) - var unmarshalledMultisig PubKeyMultisigThreshold + var unmarshalledMultisig PubKey cdc.MustUnmarshalBinaryBare(multisigKey.Bytes(), &unmarshalledMultisig) require.True(t, multisigKey.Equals(unmarshalledMultisig)) @@ -152,8 +152,8 @@ func TestPubKeyMultisigThresholdAminoToIface(t *testing.T) { ab, err := cdc.MarshalBinaryLengthPrefixed(multisigKey) require.NoError(t, err) - // like other crypto.Pubkey implementations (e.g. ed25519.PubKeyEd25519), - // PubKeyMultisigThreshold should be deserializable into a crypto.PubKey: + // like other crypto.Pubkey implementations (e.g. ed25519.PubKey), + // PubKey should be deserializable into a crypto.PubKey: var pubKey crypto.PubKey err = cdc.UnmarshalBinaryLengthPrefixed(ab, &pubKey) require.NoError(t, err) diff --git a/crypto/secp256k1/secp256k1.go b/crypto/secp256k1/secp256k1.go index 5338d10a5..2d0aa2618 100644 --- a/crypto/secp256k1/secp256k1.go +++ b/crypto/secp256k1/secp256k1.go @@ -26,39 +26,39 @@ var cdc = amino.NewCodec() func init() { cdc.RegisterInterface((*crypto.PubKey)(nil), nil) - cdc.RegisterConcrete(PubKeySecp256k1{}, + cdc.RegisterConcrete(PubKey{}, PubKeyAminoName, nil) cdc.RegisterInterface((*crypto.PrivKey)(nil), nil) - cdc.RegisterConcrete(PrivKeySecp256k1{}, + cdc.RegisterConcrete(PrivKey{}, PrivKeyAminoName, nil) } //------------------------------------- -var _ crypto.PrivKey = PrivKeySecp256k1{} +var _ crypto.PrivKey = PrivKey{} -// PrivKeySecp256k1 implements PrivKey. -type PrivKeySecp256k1 [32]byte +// PrivKey implements PrivKey. +type PrivKey [32]byte // Bytes marshalls the private key using amino encoding. -func (privKey PrivKeySecp256k1) Bytes() []byte { +func (privKey PrivKey) Bytes() []byte { return cdc.MustMarshalBinaryBare(privKey) } // PubKey performs the point-scalar multiplication from the privKey on the // generator point to get the pubkey. -func (privKey PrivKeySecp256k1) PubKey() crypto.PubKey { +func (privKey PrivKey) PubKey() crypto.PubKey { _, pubkeyObject := secp256k1.PrivKeyFromBytes(secp256k1.S256(), privKey[:]) - var pubkeyBytes PubKeySecp256k1 + var pubkeyBytes PubKey copy(pubkeyBytes[:], pubkeyObject.SerializeCompressed()) return pubkeyBytes } // Equals - you probably don't need to use this. // Runs in constant time based on length of the keys. -func (privKey PrivKeySecp256k1) Equals(other crypto.PrivKey) bool { - if otherSecp, ok := other.(PrivKeySecp256k1); ok { +func (privKey PrivKey) Equals(other crypto.PrivKey) bool { + if otherSecp, ok := other.(PrivKey); ok { return subtle.ConstantTimeCompare(privKey[:], otherSecp[:]) == 1 } return false @@ -66,12 +66,12 @@ func (privKey PrivKeySecp256k1) Equals(other crypto.PrivKey) bool { // GenPrivKey generates a new ECDSA private key on curve secp256k1 private key. // It uses OS randomness to generate the private key. -func GenPrivKey() PrivKeySecp256k1 { +func GenPrivKey() PrivKey { return genPrivKey(crypto.CReader()) } // genPrivKey generates a new secp256k1 private key using the provided reader. -func genPrivKey(rand io.Reader) PrivKeySecp256k1 { +func genPrivKey(rand io.Reader) PrivKey { var privKeyBytes [32]byte d := new(big.Int) for { @@ -89,7 +89,7 @@ func genPrivKey(rand io.Reader) PrivKeySecp256k1 { } } - return PrivKeySecp256k1(privKeyBytes) + return PrivKey(privKeyBytes) } var one = new(big.Int).SetInt64(1) @@ -104,7 +104,7 @@ var one = new(big.Int).SetInt64(1) // // NOTE: secret should be the output of a KDF like bcrypt, // if it's derived from user input. -func GenPrivKeySecp256k1(secret []byte) PrivKeySecp256k1 { +func GenPrivKeySecp256k1(secret []byte) PrivKey { secHash := sha256.Sum256(secret) // to guarantee that we have a valid field element, we use the approach of: // "Suite B Implementer’s Guide to FIPS 186-3", A.2.1 @@ -120,26 +120,26 @@ func GenPrivKeySecp256k1(secret []byte) PrivKeySecp256k1 { // copy feB over to fixed 32 byte privKey32 and pad (if necessary) copy(privKey32[32-len(feB):32], feB) - return PrivKeySecp256k1(privKey32) + return PrivKey(privKey32) } //------------------------------------- -var _ crypto.PubKey = PubKeySecp256k1{} +var _ crypto.PubKey = PubKey{} -// PubKeySecp256k1Size is comprised of 32 bytes for one field element +// PubKeySize is comprised of 32 bytes for one field element // (the x-coordinate), plus one byte for the parity of the y-coordinate. -const PubKeySecp256k1Size = 33 +const PubKeySize = 33 -// PubKeySecp256k1 implements crypto.PubKey. +// PubKey implements crypto.PubKey. // It is the compressed form of the pubkey. The first byte depends is a 0x02 byte // if the y-coordinate is the lexicographically largest of the two associated with // the x-coordinate. Otherwise the first byte is a 0x03. // This prefix is followed with the x-coordinate. -type PubKeySecp256k1 [PubKeySecp256k1Size]byte +type PubKey [PubKeySize]byte // Address returns a Bitcoin style addresses: RIPEMD160(SHA256(pubkey)) -func (pubKey PubKeySecp256k1) Address() crypto.Address { +func (pubKey PubKey) Address() crypto.Address { hasherSHA256 := sha256.New() hasherSHA256.Write(pubKey[:]) // does not error sha := hasherSHA256.Sum(nil) @@ -150,7 +150,7 @@ func (pubKey PubKeySecp256k1) Address() crypto.Address { } // Bytes returns the pubkey marshalled with amino encoding. -func (pubKey PubKeySecp256k1) Bytes() []byte { +func (pubKey PubKey) Bytes() []byte { bz, err := cdc.MarshalBinaryBare(pubKey) if err != nil { panic(err) @@ -158,12 +158,12 @@ func (pubKey PubKeySecp256k1) Bytes() []byte { return bz } -func (pubKey PubKeySecp256k1) String() string { - return fmt.Sprintf("PubKeySecp256k1{%X}", pubKey[:]) +func (pubKey PubKey) String() string { + return fmt.Sprintf("PubKey{%X}", pubKey[:]) } -func (pubKey PubKeySecp256k1) Equals(other crypto.PubKey) bool { - if otherSecp, ok := other.(PubKeySecp256k1); ok { +func (pubKey PubKey) Equals(other crypto.PubKey) bool { + if otherSecp, ok := other.(PubKey); ok { return bytes.Equal(pubKey[:], otherSecp[:]) } return false diff --git a/crypto/secp256k1/secp256k1_cgo.go b/crypto/secp256k1/secp256k1_cgo.go index 3d4a553ac..844e40e84 100644 --- a/crypto/secp256k1/secp256k1_cgo.go +++ b/crypto/secp256k1/secp256k1_cgo.go @@ -8,7 +8,7 @@ import ( ) // Sign creates an ECDSA signature on curve Secp256k1, using SHA256 on the msg. -func (privKey PrivKeySecp256k1) Sign(msg []byte) ([]byte, error) { +func (privKey PrivKey) Sign(msg []byte) ([]byte, error) { rsv, err := secp256k1.Sign(crypto.Sha256(msg), privKey[:]) if err != nil { return nil, err @@ -18,6 +18,6 @@ func (privKey PrivKeySecp256k1) Sign(msg []byte) ([]byte, error) { return rs, nil } -func (pubKey PubKeySecp256k1) VerifyBytes(msg []byte, sig []byte) bool { +func (pubKey PubKey) VerifyBytes(msg []byte, sig []byte) bool { return secp256k1.VerifySignature(pubKey[:], crypto.Sha256(msg), sig) } diff --git a/crypto/secp256k1/secp256k1_cgo_test.go b/crypto/secp256k1/secp256k1_cgo_test.go index 96b026bc9..8793e8010 100644 --- a/crypto/secp256k1/secp256k1_cgo_test.go +++ b/crypto/secp256k1/secp256k1_cgo_test.go @@ -15,7 +15,7 @@ func TestPrivKeySecp256k1SignVerify(t *testing.T) { priv := GenPrivKey() tests := []struct { name string - privKey PrivKeySecp256k1 + privKey PrivKey wantSignErr bool wantVerifyPasses bool }{ diff --git a/crypto/secp256k1/secp256k1_nocgo.go b/crypto/secp256k1/secp256k1_nocgo.go index 18782b375..06f8db9e3 100644 --- a/crypto/secp256k1/secp256k1_nocgo.go +++ b/crypto/secp256k1/secp256k1_nocgo.go @@ -18,7 +18,7 @@ var secp256k1halfN = new(big.Int).Rsh(secp256k1.S256().N, 1) // Sign creates an ECDSA signature on curve Secp256k1, using SHA256 on the msg. // The returned signature will be of the form R || S (in lower-S form). -func (privKey PrivKeySecp256k1) Sign(msg []byte) ([]byte, error) { +func (privKey PrivKey) Sign(msg []byte) ([]byte, error) { priv, _ := secp256k1.PrivKeyFromBytes(secp256k1.S256(), privKey[:]) sig, err := priv.Sign(crypto.Sha256(msg)) if err != nil { @@ -30,7 +30,7 @@ func (privKey PrivKeySecp256k1) Sign(msg []byte) ([]byte, error) { // VerifyBytes verifies a signature of the form R || S. // It rejects signatures which are not in lower-S form. -func (pubKey PubKeySecp256k1) VerifyBytes(msg []byte, sigStr []byte) bool { +func (pubKey PubKey) VerifyBytes(msg []byte, sigStr []byte) bool { if len(sigStr) != 64 { return false } diff --git a/crypto/secp256k1/secp256k1_test.go b/crypto/secp256k1/secp256k1_test.go index a83cd0f5f..1d4dcc6bd 100644 --- a/crypto/secp256k1/secp256k1_test.go +++ b/crypto/secp256k1/secp256k1_test.go @@ -36,11 +36,11 @@ func TestPubKeySecp256k1Address(t *testing.T) { addrBbz, _, _ := base58.CheckDecode(d.addr) addrB := crypto.Address(addrBbz) - var priv secp256k1.PrivKeySecp256k1 + var priv secp256k1.PrivKey copy(priv[:], privB) pubKey := priv.PubKey() - pubT, _ := pubKey.(secp256k1.PubKeySecp256k1) + pubT, _ := pubKey.(secp256k1.PubKey) pub := pubT[:] addr := pubKey.Address() diff --git a/crypto/sr25519/codec.go b/crypto/sr25519/codec.go index f33b616f9..7ea8b36c6 100644 --- a/crypto/sr25519/codec.go +++ b/crypto/sr25519/codec.go @@ -6,7 +6,7 @@ import ( "github.com/tendermint/tendermint/crypto" ) -var _ crypto.PrivKey = PrivKeySr25519{} +var _ crypto.PrivKey = PrivKey{} const ( PrivKeyAminoName = "tendermint/PrivKeySr25519" @@ -21,10 +21,10 @@ var cdc = amino.NewCodec() func init() { cdc.RegisterInterface((*crypto.PubKey)(nil), nil) - cdc.RegisterConcrete(PubKeySr25519{}, + cdc.RegisterConcrete(PubKey{}, PubKeyAminoName, nil) cdc.RegisterInterface((*crypto.PrivKey)(nil), nil) - cdc.RegisterConcrete(PrivKeySr25519{}, + cdc.RegisterConcrete(PrivKey{}, PrivKeyAminoName, nil) } diff --git a/crypto/sr25519/privkey.go b/crypto/sr25519/privkey.go index 17d33ebf2..51595c7b4 100644 --- a/crypto/sr25519/privkey.go +++ b/crypto/sr25519/privkey.go @@ -10,19 +10,19 @@ import ( schnorrkel "github.com/ChainSafe/go-schnorrkel" ) -// PrivKeySr25519Size is the number of bytes in an Sr25519 private key. -const PrivKeySr25519Size = 32 +// PrivKeySize is the number of bytes in an Sr25519 private key. +const PrivKeySize = 32 -// PrivKeySr25519 implements crypto.PrivKey. -type PrivKeySr25519 [PrivKeySr25519Size]byte +// PrivKey implements crypto.PrivKey. +type PrivKey [PrivKeySize]byte // Bytes marshals the privkey using amino encoding. -func (privKey PrivKeySr25519) Bytes() []byte { +func (privKey PrivKey) Bytes() []byte { return cdc.MustMarshalBinaryBare(privKey) } // Sign produces a signature on the provided message. -func (privKey PrivKeySr25519) Sign(msg []byte) ([]byte, error) { +func (privKey PrivKey) Sign(msg []byte) ([]byte, error) { miniSecretKey, err := schnorrkel.NewMiniSecretKeyFromRaw(privKey) if err != nil { return []byte{}, err @@ -41,7 +41,7 @@ func (privKey PrivKeySr25519) Sign(msg []byte) ([]byte, error) { } // PubKey gets the corresponding public key from the private key. -func (privKey PrivKeySr25519) PubKey() crypto.PubKey { +func (privKey PrivKey) PubKey() crypto.PubKey { miniSecretKey, err := schnorrkel.NewMiniSecretKeyFromRaw(privKey) if err != nil { panic(fmt.Sprintf("Invalid private key: %v", err)) @@ -53,13 +53,13 @@ func (privKey PrivKeySr25519) PubKey() crypto.PubKey { panic(fmt.Sprintf("Could not generate public key: %v", err)) } - return PubKeySr25519(pubkey.Encode()) + return PubKey(pubkey.Encode()) } // Equals - you probably don't need to use this. // Runs in constant time based on length of the keys. -func (privKey PrivKeySr25519) Equals(other crypto.PrivKey) bool { - if otherEd, ok := other.(PrivKeySr25519); ok { +func (privKey PrivKey) Equals(other crypto.PrivKey) bool { + if otherEd, ok := other.(PrivKey); ok { return subtle.ConstantTimeCompare(privKey[:], otherEd[:]) == 1 } return false @@ -68,12 +68,12 @@ func (privKey PrivKeySr25519) Equals(other crypto.PrivKey) bool { // GenPrivKey generates a new sr25519 private key. // It uses OS randomness in conjunction with the current global random seed // in tendermint/libs/common to generate the private key. -func GenPrivKey() PrivKeySr25519 { +func GenPrivKey() PrivKey { return genPrivKey(crypto.CReader()) } // genPrivKey generates a new sr25519 private key using the provided reader. -func genPrivKey(rand io.Reader) PrivKeySr25519 { +func genPrivKey(rand io.Reader) PrivKey { var seed [64]byte out := make([]byte, 64) @@ -91,9 +91,9 @@ func genPrivKey(rand io.Reader) PrivKeySr25519 { // that 32 byte output to create the private key. // NOTE: secret should be the output of a KDF like bcrypt, // if it's derived from user input. -func GenPrivKeyFromSecret(secret []byte) PrivKeySr25519 { +func GenPrivKeyFromSecret(secret []byte) PrivKey { seed := crypto.Sha256(secret) // Not Ripemd160 because we want 32 bytes. - var bz [PrivKeySr25519Size]byte + var bz [PrivKeySize]byte copy(bz[:], seed) privKey, _ := schnorrkel.NewMiniSecretKeyFromRaw(bz) return privKey.ExpandEd25519().Encode() diff --git a/crypto/sr25519/pubkey.go b/crypto/sr25519/pubkey.go index a678806f2..3c6d92441 100644 --- a/crypto/sr25519/pubkey.go +++ b/crypto/sr25519/pubkey.go @@ -10,21 +10,21 @@ import ( schnorrkel "github.com/ChainSafe/go-schnorrkel" ) -var _ crypto.PubKey = PubKeySr25519{} +var _ crypto.PubKey = PubKey{} -// PubKeySr25519Size is the number of bytes in an Sr25519 public key. -const PubKeySr25519Size = 32 +// PubKeySize is the number of bytes in an Sr25519 public key. +const PubKeySize = 32 -// PubKeySr25519 implements crypto.PubKey for the Sr25519 signature scheme. -type PubKeySr25519 [PubKeySr25519Size]byte +// PubKey implements crypto.PubKey for the Sr25519 signature scheme. +type PubKey [PubKeySize]byte // Address is the SHA256-20 of the raw pubkey bytes. -func (pubKey PubKeySr25519) Address() crypto.Address { +func (pubKey PubKey) Address() crypto.Address { return crypto.Address(tmhash.SumTruncated(pubKey[:])) } // Bytes marshals the PubKey using amino encoding. -func (pubKey PubKeySr25519) Bytes() []byte { +func (pubKey PubKey) Bytes() []byte { bz, err := cdc.MarshalBinaryBare(pubKey) if err != nil { panic(err) @@ -32,7 +32,7 @@ func (pubKey PubKeySr25519) Bytes() []byte { return bz } -func (pubKey PubKeySr25519) VerifyBytes(msg []byte, sig []byte) bool { +func (pubKey PubKey) VerifyBytes(msg []byte, sig []byte) bool { // make sure we use the same algorithm to sign if len(sig) != SignatureSize { return false @@ -57,14 +57,14 @@ func (pubKey PubKeySr25519) VerifyBytes(msg []byte, sig []byte) bool { return publicKey.Verify(signature, signingContext) } -func (pubKey PubKeySr25519) String() string { - return fmt.Sprintf("PubKeySr25519{%X}", pubKey[:]) +func (pubKey PubKey) String() string { + return fmt.Sprintf("PubKey{%X}", pubKey[:]) } // Equals - checks that two public keys are the same time // Runs in constant time based on length of the keys. -func (pubKey PubKeySr25519) Equals(other crypto.PubKey) bool { - if otherEd, ok := other.(PubKeySr25519); ok { +func (pubKey PubKey) Equals(other crypto.PubKey) bool { + if otherEd, ok := other.(PubKey); ok { return bytes.Equal(pubKey[:], otherEd[:]) } return false diff --git a/p2p/conn/secret_connection.go b/p2p/conn/secret_connection.go index a7915fff1..5d48fa1c6 100644 --- a/p2p/conn/secret_connection.go +++ b/p2p/conn/secret_connection.go @@ -163,7 +163,7 @@ func MakeSecretConnection(conn io.ReadWriteCloser, locPrivKey crypto.PrivKey) (* } remPubKey, remSignature := authSigMsg.Key, authSigMsg.Sig - if _, ok := remPubKey.(ed25519.PubKeyEd25519); !ok { + if _, ok := remPubKey.(ed25519.PubKey); !ok { return nil, fmt.Errorf("expected ed25519 pubkey, got %T", remPubKey) } if !remPubKey.VerifyBytes(challenge[:], remSignature) { diff --git a/p2p/conn/secret_connection_test.go b/p2p/conn/secret_connection_test.go index 9044d73be..cffa3879e 100644 --- a/p2p/conn/secret_connection_test.go +++ b/p2p/conn/secret_connection_test.go @@ -362,7 +362,7 @@ func TestNonEd25519Pubkey(t *testing.T) { assert.NotPanics(t, func() { _, err := MakeSecretConnection(fooConn, fooPrvKey) if assert.Error(t, err) { - assert.Equal(t, "expected ed25519 pubkey, got secp256k1.PubKeySecp256k1", err.Error()) + assert.Equal(t, "expected ed25519 pubkey, got secp256k1.PubKey", err.Error()) } }) } diff --git a/privval/file_test.go b/privval/file_test.go index 343131e1a..64de3ce95 100644 --- a/privval/file_test.go +++ b/privval/file_test.go @@ -119,7 +119,7 @@ func TestUnmarshalValidatorKey(t *testing.T) { privKey := ed25519.GenPrivKey() pubKey := privKey.PubKey() addr := pubKey.Address() - pubArray := [32]byte(pubKey.(ed25519.PubKeyEd25519)) + pubArray := [32]byte(pubKey.(ed25519.PubKey)) pubBytes := pubArray[:] privArray := [64]byte(privKey) privBytes := privArray[:] diff --git a/privval/socket_listeners.go b/privval/socket_listeners.go index 0e12e4268..908e05e2e 100644 --- a/privval/socket_listeners.go +++ b/privval/socket_listeners.go @@ -45,7 +45,7 @@ var _ net.Listener = (*TCPListener)(nil) type TCPListener struct { *net.TCPListener - secretConnKey ed25519.PrivKeyEd25519 + secretConnKey ed25519.PrivKey timeoutAccept time.Duration timeoutReadWrite time.Duration @@ -53,7 +53,7 @@ type TCPListener struct { // NewTCPListener returns a listener that accepts authenticated encrypted connections // using the given secretConnKey and the default timeout values. -func NewTCPListener(ln net.Listener, secretConnKey ed25519.PrivKeyEd25519) *TCPListener { +func NewTCPListener(ln net.Listener, secretConnKey ed25519.PrivKey) *TCPListener { return &TCPListener{ TCPListener: ln.(*net.TCPListener), secretConnKey: secretConnKey, diff --git a/privval/socket_listeners_test.go b/privval/socket_listeners_test.go index 3c4cb8588..5e95ec10c 100644 --- a/privval/socket_listeners_test.go +++ b/privval/socket_listeners_test.go @@ -13,7 +13,7 @@ import ( //------------------------------------------- // helper funcs -func newPrivKey() ed25519.PrivKeyEd25519 { +func newPrivKey() ed25519.PrivKey { return ed25519.GenPrivKey() } diff --git a/rpc/client/evidence_test.go b/rpc/client/evidence_test.go index 153506ed6..32909bba2 100644 --- a/rpc/client/evidence_test.go +++ b/rpc/client/evidence_test.go @@ -123,7 +123,7 @@ func TestBroadcastEvidence_DuplicateVoteEvidence(t *testing.T) { require.NoError(t, err) client.WaitForHeight(c, status.SyncInfo.LatestBlockHeight+2, nil) - ed25519pub := pv.Key.PubKey.(ed25519.PubKeyEd25519) + ed25519pub := pv.Key.PubKey.(ed25519.PubKey) rawpub := ed25519pub[:] result2, err := c.ABCIQuery("/val", rawpub) require.NoError(t, err) diff --git a/tools/tm-signer-harness/internal/test_harness.go b/tools/tm-signer-harness/internal/test_harness.go index f9d48fdcb..bb854ebc0 100644 --- a/tools/tm-signer-harness/internal/test_harness.go +++ b/tools/tm-signer-harness/internal/test_harness.go @@ -72,7 +72,7 @@ type TestHarnessConfig struct { ConnDeadline time.Duration AcceptRetries int - SecretConnKey ed25519.PrivKeyEd25519 + SecretConnKey ed25519.PrivKey ExitWhenComplete bool // Whether or not to call os.Exit when the harness has completed. } diff --git a/tools/tm-signer-harness/main.go b/tools/tm-signer-harness/main.go index c45b44b0c..64bb96400 100644 --- a/tools/tm-signer-harness/main.go +++ b/tools/tm-signer-harness/main.go @@ -135,7 +135,7 @@ func extractKey(tmhome, outputPath string) { keyFile := filepath.Join(internal.ExpandPath(tmhome), "config", "priv_validator_key.json") stateFile := filepath.Join(internal.ExpandPath(tmhome), "data", "priv_validator_state.json") fpv := privval.LoadFilePV(keyFile, stateFile) - pkb := [64]byte(fpv.Key.PrivKey.(ed25519.PrivKeyEd25519)) + pkb := [64]byte(fpv.Key.PrivKey.(ed25519.PrivKey)) if err := ioutil.WriteFile(internal.ExpandPath(outputPath), pkb[:32], 0600); err != nil { logger.Info("Failed to write private key", "output", outputPath, "err", err) os.Exit(1) diff --git a/types/protobuf.go b/types/protobuf.go index 3fe049574..1f700efe2 100644 --- a/types/protobuf.go +++ b/types/protobuf.go @@ -101,17 +101,17 @@ func (tm2pb) ValidatorUpdate(val *Validator) abci.ValidatorUpdate { // TODO: add cases when new pubkey types are added to crypto func (tm2pb) PubKey(pubKey crypto.PubKey) abci.PubKey { switch pk := pubKey.(type) { - case ed25519.PubKeyEd25519: + case ed25519.PubKey: return abci.PubKey{ Type: ABCIPubKeyTypeEd25519, Data: pk[:], } - case sr25519.PubKeySr25519: + case sr25519.PubKey: return abci.PubKey{ Type: ABCIPubKeyTypeSr25519, Data: pk[:], } - case secp256k1.PubKeySecp256k1: + case secp256k1.PubKey: return abci.PubKey{ Type: ABCIPubKeyTypeSecp256k1, Data: pk[:], @@ -205,27 +205,27 @@ type pb2tm struct{} func (pb2tm) PubKey(pubKey abci.PubKey) (crypto.PubKey, error) { switch pubKey.Type { case ABCIPubKeyTypeEd25519: - if len(pubKey.Data) != ed25519.PubKeyEd25519Size { + if len(pubKey.Data) != ed25519.PubKeySize { return nil, fmt.Errorf("invalid size for PubKeyEd25519. Got %d, expected %d", - len(pubKey.Data), ed25519.PubKeyEd25519Size) + len(pubKey.Data), ed25519.PubKeySize) } - var pk ed25519.PubKeyEd25519 + var pk ed25519.PubKey copy(pk[:], pubKey.Data) return pk, nil case ABCIPubKeyTypeSr25519: - if len(pubKey.Data) != sr25519.PubKeySr25519Size { + if len(pubKey.Data) != sr25519.PubKeySize { return nil, fmt.Errorf("invalid size for PubKeySr25519. Got %d, expected %d", - len(pubKey.Data), sr25519.PubKeySr25519Size) + len(pubKey.Data), sr25519.PubKeySize) } - var pk sr25519.PubKeySr25519 + var pk sr25519.PubKey copy(pk[:], pubKey.Data) return pk, nil case ABCIPubKeyTypeSecp256k1: - if len(pubKey.Data) != secp256k1.PubKeySecp256k1Size { + if len(pubKey.Data) != secp256k1.PubKeySize { return nil, fmt.Errorf("invalid size for PubKeySecp256k1. Got %d, expected %d", - len(pubKey.Data), secp256k1.PubKeySecp256k1Size) + len(pubKey.Data), secp256k1.PubKeySize) } - var pk secp256k1.PubKeySecp256k1 + var pk secp256k1.PubKey copy(pk[:], pubKey.Data) return pk, nil default: diff --git a/types/validator_set_test.go b/types/validator_set_test.go index 2f3476c74..38f80512e 100644 --- a/types/validator_set_test.go +++ b/types/validator_set_test.go @@ -362,7 +362,7 @@ func newValidator(address []byte, power int64) *Validator { func randPubKey() crypto.PubKey { var pubKey [32]byte copy(pubKey[:], tmrand.Bytes(32)) - return ed25519.PubKeyEd25519(pubKey) + return ed25519.PubKey(pubKey) } func randValidator(totalVotingPower int64) *Validator {