-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move codec.RegisterCrypto and codec.Cdc to new packages (#6330)
* Move codec.Cdc to legacy_global.Cdc * Update CHANGELOG.md * Updates * nit * Fix imports * Updates * Use cosmos multisig instead of tendermint multisig everywhere * Fix tests * Rename legacy_global -> legacy * Add doc.go * Linting, move all RegisterCrypto calls to crypto/codec * Update crypto/codec/amino.go Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
- Loading branch information
Showing
62 changed files
with
216 additions
and
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package legacy | ||
|
||
import ( | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" | ||
) | ||
|
||
// Deprecated: Cdc defines a global generic sealed Amino codec to be used throughout sdk. It | ||
// has all Tendermint crypto and evidence types registered. | ||
// | ||
// TODO: remove this global. | ||
var Cdc *codec.Codec | ||
|
||
func init() { | ||
Cdc = codec.New() | ||
cryptocodec.RegisterCrypto(Cdc) | ||
codec.RegisterEvidences(Cdc) | ||
Cdc.Seal() | ||
} |
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,4 @@ | ||
// Package legacy contains a global amino Cdc which is deprecated but | ||
// still used in several places within the SDK. This package is intended | ||
// to be removed at some point in the future when the global Cdc is removed. | ||
package legacy |
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 |
---|---|---|
@@ -1,19 +1,19 @@ | ||
package crypto | ||
|
||
import ( | ||
amino "github.com/tendermint/go-amino" | ||
cryptoAmino "github.com/tendermint/tendermint/crypto/encoding/amino" | ||
"github.com/cosmos/cosmos-sdk/codec" | ||
cryptoAmino "github.com/cosmos/cosmos-sdk/crypto/codec" | ||
) | ||
|
||
var cdc = amino.NewCodec() | ||
var cdc = codec.New() | ||
|
||
func init() { | ||
RegisterAmino(cdc) | ||
cryptoAmino.RegisterAmino(cdc) | ||
cryptoAmino.RegisterCrypto(cdc) | ||
} | ||
|
||
// RegisterAmino registers all go-crypto related types in the given (amino) codec. | ||
func RegisterAmino(cdc *amino.Codec) { | ||
func RegisterAmino(cdc *codec.Codec) { | ||
cdc.RegisterConcrete(PrivKeyLedgerSecp256k1{}, | ||
"tendermint/PrivKeyLedgerSecp256k1", nil) | ||
} |
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,52 @@ | ||
package codec | ||
|
||
import ( | ||
"github.com/tendermint/tendermint/crypto" | ||
"github.com/tendermint/tendermint/crypto/ed25519" | ||
"github.com/tendermint/tendermint/crypto/secp256k1" | ||
"github.com/tendermint/tendermint/crypto/sr25519" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/crypto/types/multisig" | ||
) | ||
|
||
var amino *codec.Codec | ||
|
||
func init() { | ||
amino = codec.New() | ||
RegisterCrypto(amino) | ||
} | ||
|
||
// RegisterCrypto registers all crypto dependency types with the provided Amino | ||
// codec. | ||
func RegisterCrypto(cdc *codec.Codec) { | ||
cdc.RegisterInterface((*crypto.PubKey)(nil), nil) | ||
cdc.RegisterConcrete(ed25519.PubKeyEd25519{}, | ||
ed25519.PubKeyAminoName, nil) | ||
cdc.RegisterConcrete(sr25519.PubKeySr25519{}, | ||
sr25519.PubKeyAminoName, nil) | ||
cdc.RegisterConcrete(secp256k1.PubKeySecp256k1{}, | ||
secp256k1.PubKeyAminoName, nil) | ||
cdc.RegisterConcrete(multisig.PubKeyMultisigThreshold{}, | ||
multisig.PubKeyAminoRoute, nil) | ||
|
||
cdc.RegisterInterface((*crypto.PrivKey)(nil), nil) | ||
cdc.RegisterConcrete(ed25519.PrivKeyEd25519{}, | ||
ed25519.PrivKeyAminoName, nil) | ||
cdc.RegisterConcrete(sr25519.PrivKeySr25519{}, | ||
sr25519.PrivKeyAminoName, nil) | ||
cdc.RegisterConcrete(secp256k1.PrivKeySecp256k1{}, | ||
secp256k1.PrivKeyAminoName, nil) | ||
} | ||
|
||
// PrivKeyFromBytes unmarshals private key bytes and returns a PrivKey | ||
func PrivKeyFromBytes(privKeyBytes []byte) (privKey crypto.PrivKey, err error) { | ||
err = amino.UnmarshalBinaryBare(privKeyBytes, &privKey) | ||
return | ||
} | ||
|
||
// PubKeyFromBytes unmarshals public key bytes and returns a PubKey | ||
func PubKeyFromBytes(pubKeyBytes []byte) (pubKey crypto.PubKey, err error) { | ||
err = amino.UnmarshalBinaryBare(pubKeyBytes, &pubKey) | ||
return | ||
} |
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
Oops, something went wrong.