-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
+2,887
−42
Closed
keys: define proto type #5997
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 0668da6
Update client/keys/root.go
fedekunze 7b42d88
Update crypto/keyring/errors.go
fedekunze 018b256
Update crypto/keyring/keybase.go
fedekunze 3f4609e
Update crypto/keyring/options.go
fedekunze 9e23f88
format
fedekunze 30e0a38
Merge branch 'fedekunze/5819-move-keys' of https://github.com/cosmos/…
fedekunze 49b6fd4
changelog
fedekunze 715cd36
fix build
fedekunze c36c9f1
format
fedekunze 2e10608
crypto/keys: move tendermint key types to the SDK
fedekunze 1e96870
crypto/keys: flatten pkgs
fedekunze 49034e9
crypto/keys: cleanup types
fedekunze 5e4724d
revert dep change
fedekunze 7849944
cleanup
fedekunze e040f03
update proto message for multisig
fedekunze 47032f9
genprivkey functions
fedekunze 411ae36
build errors
fedekunze 0455a2f
add missing methods for secp256k1
fedekunze 239abd5
more fixes
fedekunze 4e7cad3
rebase to master
fedekunze 2ce648f
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into fe…
fedekunze c7c9ab8
crypto/keys: add ByteArray util function for each key type
fedekunze 371241f
crypto/keys: fixes from tests
fedekunze b7c6fcd
tests
fedekunze dd94902
cast types
tac0turtle 9135567
merge master
fedekunze 6ae127e
Merge branch 'fedekunze/5819-tm-keys' of github.com:cosmos/cosmos-sdk…
fedekunze 92dc996
fix build
tac0turtle 3586202
Merge branch 'marko/pubkeys' of https://github.com/cosmos/cosmos-sdk …
tac0turtle 1960b0f
move PubKey and PrivKey to codec/std/
fedekunze 980ae75
add to/from proto keys
tac0turtle 9a3f012
remove bit array
tac0turtle fe64a81
bring back multisig
tac0turtle 625ef37
Merge branch 'master' into marko/pubkeys
tac0turtle 9f5b23d
add pubkey threshold to from to pubkeys
tac0turtle ddcbae3
add marshlers to compactbitarray
tac0turtle 7015bdf
appease linter
tac0turtle e49b200
format according to guidelines
tac0turtle c5dd830
Apply suggestions from code review
tac0turtle 3769492
Merge branch 'master' into marko/pubkeys
fedekunze c75f2b2
Merge branch 'master' into marko/pubkeys
fedekunze c47a74c
Merge branch 'master' into marko/pubkeys
tac0turtle 34f5af2
migrate multisig to sdk
tac0turtle c2b3dc0
move bitarray to types
tac0turtle ea2afd8
move it up on dir
tac0turtle 1f1d07d
Merge branch 'master' into marko/pubkeys
fedekunze e0b1ce1
fix pubkey tests
tac0turtle a15dfd7
Merge branch 'master' into marko/pubkeys
fedekunze 855e976
Merge branch 'master' into marko/pubkeys
fedekunze 94efb32
Merge branch 'master' into marko/pubkeys
6e1bdd6
Merge branch 'master' into marko/pubkeys
tac0turtle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
// 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) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?