Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keys: define proto type #5997

Closed
wants to merge 52 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
caa7560
crypto/keys: move keybase and keyring to crypto/keyring/ dir
fedekunze Mar 24, 2020
0668da6
Update client/keys/root.go
fedekunze Mar 24, 2020
7b42d88
Update crypto/keyring/errors.go
fedekunze Mar 24, 2020
018b256
Update crypto/keyring/keybase.go
fedekunze Mar 24, 2020
3f4609e
Update crypto/keyring/options.go
fedekunze Mar 24, 2020
9e23f88
format
fedekunze Mar 24, 2020
30e0a38
Merge branch 'fedekunze/5819-move-keys' of https://github.com/cosmos/…
fedekunze Mar 24, 2020
49b6fd4
changelog
fedekunze Mar 24, 2020
715cd36
fix build
fedekunze Mar 24, 2020
c36c9f1
format
fedekunze Mar 24, 2020
2e10608
crypto/keys: move tendermint key types to the SDK
fedekunze Mar 24, 2020
1e96870
crypto/keys: flatten pkgs
fedekunze Mar 25, 2020
49034e9
crypto/keys: cleanup types
fedekunze Mar 25, 2020
5e4724d
revert dep change
fedekunze Mar 25, 2020
7849944
cleanup
fedekunze Mar 25, 2020
e040f03
update proto message for multisig
fedekunze Mar 25, 2020
47032f9
genprivkey functions
fedekunze Mar 25, 2020
411ae36
build errors
fedekunze Mar 25, 2020
0455a2f
add missing methods for secp256k1
fedekunze Mar 25, 2020
239abd5
more fixes
fedekunze Mar 25, 2020
4e7cad3
rebase to master
fedekunze Mar 25, 2020
2ce648f
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into fe…
fedekunze Mar 26, 2020
c7c9ab8
crypto/keys: add ByteArray util function for each key type
fedekunze Mar 26, 2020
371241f
crypto/keys: fixes from tests
fedekunze Mar 26, 2020
b7c6fcd
tests
fedekunze Mar 26, 2020
dd94902
cast types
tac0turtle Apr 15, 2020
9135567
merge master
fedekunze Apr 15, 2020
6ae127e
Merge branch 'fedekunze/5819-tm-keys' of github.com:cosmos/cosmos-sdk…
fedekunze Apr 15, 2020
92dc996
fix build
tac0turtle Apr 15, 2020
3586202
Merge branch 'marko/pubkeys' of https://github.com/cosmos/cosmos-sdk …
tac0turtle Apr 15, 2020
1960b0f
move PubKey and PrivKey to codec/std/
fedekunze Apr 15, 2020
980ae75
add to/from proto keys
tac0turtle Apr 16, 2020
9a3f012
remove bit array
tac0turtle Apr 16, 2020
fe64a81
bring back multisig
tac0turtle Apr 16, 2020
625ef37
Merge branch 'master' into marko/pubkeys
tac0turtle Apr 16, 2020
9f5b23d
add pubkey threshold to from to pubkeys
tac0turtle Apr 16, 2020
ddcbae3
add marshlers to compactbitarray
tac0turtle Apr 16, 2020
7015bdf
appease linter
tac0turtle Apr 16, 2020
e49b200
format according to guidelines
tac0turtle Apr 16, 2020
c5dd830
Apply suggestions from code review
tac0turtle Apr 16, 2020
3769492
Merge branch 'master' into marko/pubkeys
fedekunze Apr 16, 2020
c75f2b2
Merge branch 'master' into marko/pubkeys
fedekunze Apr 18, 2020
c47a74c
Merge branch 'master' into marko/pubkeys
tac0turtle Apr 20, 2020
34f5af2
migrate multisig to sdk
tac0turtle Apr 20, 2020
c2b3dc0
move bitarray to types
tac0turtle Apr 20, 2020
ea2afd8
move it up on dir
tac0turtle Apr 20, 2020
1f1d07d
Merge branch 'master' into marko/pubkeys
fedekunze Apr 20, 2020
e0b1ce1
fix pubkey tests
tac0turtle Apr 21, 2020
a15dfd7
Merge branch 'master' into marko/pubkeys
fedekunze Apr 21, 2020
855e976
Merge branch 'master' into marko/pubkeys
fedekunze Apr 21, 2020
94efb32
Merge branch 'master' into marko/pubkeys
Apr 21, 2020
6e1bdd6
Merge branch 'master' into marko/pubkeys
tac0turtle Apr 22, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions codec/std/codec.proto
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,8 @@ message StdFee {
option (gogoproto.goproto_getters) = false;
option (gogoproto.equal) = true;

repeated cosmos_sdk.v1.Coin amount = 1
[(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
uint64 gas = 2;
repeated cosmos_sdk.v1.Coin amount = 1 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
uint64 gas = 2;
}

// StdSignature defines a signature structure that contains the signature of a
Expand Down
140 changes: 140 additions & 0 deletions codec/std/keys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
package std

import (
"fmt"

"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/multisig"
"github.com/tendermint/tendermint/crypto/secp256k1"
"github.com/tendermint/tendermint/crypto/sr25519"
)

//TODO: Deprecate this file when tendermint 0.34 is released
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you say a little bit more about why and what the condition is? Basically if interfacetype can be used right?


// PubKeyToProto takes crypto.PubKey and transforms it to a protobuf Pubkey
func PubKeyToProto(k crypto.PubKey) (PublicKey, error) {
var kp PublicKey
switch k := k.(type) {
case sr25519.PubKeySr25519:
kp = PublicKey{
fedekunze marked this conversation as resolved.
Show resolved Hide resolved
Sum: &PublicKey_Sr25519{
Sr25519: k[:],
},
}
case ed25519.PubKeyEd25519:
kp = PublicKey{
Sum: &PublicKey_Ed25519{
Ed25519: k[:],
},
}
case secp256k1.PubKeySecp256k1:
kp = PublicKey{
Sum: &PublicKey_Secp256K1{
Secp256K1: k[:],
},
}
case multisig.PubKeyMultisigThreshold:
pk := make([]*PublicKey, len(k.PubKeys))
for i := 0; i < len(k.PubKeys); i++ {
pkp, err := PubKeyToProto(k.PubKeys[i])
if err != nil {
return PublicKey{}, err
}
pk[i] = &pkp
}
kp = PublicKey{
Sum: &PublicKey_Multisig{
Multisig: &PubKeyMultisigThreshold{
K: uint32(k.K),
PubKeys: pk,
},
},
}
default:
return kp, fmt.Errorf("toproto: key type %T is not supported", k)
}
return kp, nil
}

// PubKeyFromProto takes a protobuf Pubkey and transforms it to a crypto.Pubkey
func PubKeyFromProto(k PublicKey) (crypto.PubKey, error) {
switch k := k.Sum.(type) {
case *PublicKey_Ed25519:
var pk ed25519.PubKeyEd25519
copy(pk[:], k.Ed25519)
return pk, nil
case *PublicKey_Sr25519:
var pk sr25519.PubKeySr25519
copy(pk[:], k.Sr25519)
return pk, nil
case *PublicKey_Secp256K1:
var pk secp256k1.PubKeySecp256k1
copy(pk[:], k.Secp256K1)
return pk, nil
case *PublicKey_Multisig:
pk := make([]crypto.PubKey, len(k.Multisig.PubKeys))
for i := range k.Multisig.PubKeys {
pkp, err := PubKeyFromProto(*k.Multisig.PubKeys[i])
if err != nil {
return nil, err
}
pk[i] = pkp
}

return multisig.PubKeyMultisigThreshold{
K: uint(k.Multisig.K),
PubKeys: pk,
}, nil
default:
return nil, fmt.Errorf("fromproto: key type %T is not supported", k)
}
}

// PrivKeyToProto takes crypto.PrivKey and transforms it to a protobuf PrivKey
func PrivKeyToProto(k crypto.PrivKey) (PrivateKey, error) {
var kp PrivateKey
switch k := k.(type) {
case ed25519.PrivKeyEd25519:
kp = PrivateKey{
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
Sum: &PrivateKey_Ed25519{
Ed25519: k[:],
},
}
case sr25519.PrivKeySr25519:
kp = PrivateKey{
Sum: &PrivateKey_Sr25519{
Sr25519: k[:],
},
}
case secp256k1.PrivKeySecp256k1:
kp = PrivateKey{
Sum: &PrivateKey_Secp256K1{
Secp256K1: k[:],
},
}
default:
return kp, fmt.Errorf("toproto: key type %T is not supported", k)
}
return kp, nil
}

// PrivKeyFromProto takes a protobuf PrivateKey and transforms it to a crypto.PrivKey
func PrivKeyFromProto(k PrivateKey) (crypto.PrivKey, error) {
switch k := k.Sum.(type) {
case *PrivateKey_Ed25519:
var pk ed25519.PrivKeyEd25519
copy(pk[:], k.Ed25519)
return pk, nil
case *PrivateKey_Sr25519:
var pk sr25519.PrivKeySr25519
copy(pk[:], k.Sr25519)
return pk, nil
case *PrivateKey_Secp256K1:
var pk secp256k1.PrivKeySecp256k1
copy(pk[:], k.Secp256K1)
return pk, nil
default:
return nil, fmt.Errorf("fromproto: key type %T is not supported", k)
}
}
Loading