forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace tmcrypto.PubKey by our own cryptotypes.PubKey (cosmos#7419)
* WIP on removing tm pub/privkey * Fix part of crypto tests * Add PrivKeyLedgerSecp256K1 proto type * Use BasePrivKey for ledger priv key type * Refacto continued * First round * x/staking * Continue porting * x/* done * Make build pass * More conversion * Remove IntoTmPubKey * Fix test * Remove crypto.PubKey in some other places * Revert ledger changes * Fix comment * Remove useless function * Add To/FromTmPublicKey * Add migrate tests * Fix test * Fix another test * Rename tm conversion functions * Less code * Rename BasePrivKey to LedgerPrivKey * Add changelog * Rename functions Co-authored-by: Amaury Martiny <[email protected]> Co-authored-by: Alessio Treglia <[email protected]>
- Loading branch information
1 parent
e172a08
commit 90e9370
Showing
129 changed files
with
1,079 additions
and
900 deletions.
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
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
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
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
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
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
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,57 @@ | ||
package codec | ||
|
||
import ( | ||
tmcrypto "github.com/tendermint/tendermint/crypto" | ||
"github.com/tendermint/tendermint/crypto/encoding" | ||
tmprotocrypto "github.com/tendermint/tendermint/proto/tendermint/crypto" | ||
|
||
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" | ||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
// FromTmProtoPublicKey converts a TM's tmprotocrypto.PublicKey into our own PubKey. | ||
func FromTmProtoPublicKey(protoPk tmprotocrypto.PublicKey) (cryptotypes.PubKey, error) { | ||
switch protoPk := protoPk.Sum.(type) { | ||
case *tmprotocrypto.PublicKey_Ed25519: | ||
return &ed25519.PubKey{ | ||
Key: protoPk.Ed25519, | ||
}, nil | ||
default: | ||
return nil, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "cannot convert %v from Tendermint public key", protoPk) | ||
} | ||
} | ||
|
||
// ToTmProtoPublicKey converts our own PubKey to TM's tmprotocrypto.PublicKey. | ||
func ToTmProtoPublicKey(pk cryptotypes.PubKey) (tmprotocrypto.PublicKey, error) { | ||
switch pk := pk.(type) { | ||
case *ed25519.PubKey: | ||
return tmprotocrypto.PublicKey{ | ||
Sum: &tmprotocrypto.PublicKey_Ed25519{ | ||
Ed25519: pk.Key, | ||
}, | ||
}, nil | ||
default: | ||
return tmprotocrypto.PublicKey{}, sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "cannot convert %v to Tendermint public key", pk) | ||
} | ||
} | ||
|
||
// FromTmPubKeyInterface converts TM's tmcrypto.PubKey to our own PubKey. | ||
func FromTmPubKeyInterface(tmPk tmcrypto.PubKey) (cryptotypes.PubKey, error) { | ||
tmProtoPk, err := encoding.PubKeyToProto(tmPk) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return FromTmProtoPublicKey(tmProtoPk) | ||
} | ||
|
||
// ToTmPubKeyInterface converts our own PubKey to TM's tmcrypto.PubKey. | ||
func ToTmPubKeyInterface(pk cryptotypes.PubKey) (tmcrypto.PubKey, error) { | ||
tmProtoPk, err := ToTmProtoPublicKey(pk) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return encoding.PubKeyFromProto(tmProtoPk) | ||
} |
Oops, something went wrong.