github.com/Finschia/finschia-sdk@v0.48.1/codec/legacy/codec.go (about)

     1  package legacy
     2  
     3  import (
     4  	"github.com/Finschia/finschia-sdk/codec"
     5  	cryptocodec "github.com/Finschia/finschia-sdk/crypto/codec"
     6  	cryptotypes "github.com/Finschia/finschia-sdk/crypto/types"
     7  	sdk "github.com/Finschia/finschia-sdk/types"
     8  )
     9  
    10  // Cdc defines a global generic sealed Amino codec to be used throughout sdk. It
    11  // has all Tendermint crypto and evidence types registered.
    12  //
    13  // TODO: Deprecated - remove this global.
    14  var Cdc = codec.NewLegacyAmino()
    15  
    16  func init() {
    17  	cryptocodec.RegisterCrypto(Cdc)
    18  	codec.RegisterEvidences(Cdc)
    19  	sdk.RegisterLegacyAminoCodec(Cdc)
    20  }
    21  
    22  // PrivKeyFromBytes unmarshals private key bytes and returns a PrivKey
    23  func PrivKeyFromBytes(privKeyBytes []byte) (privKey cryptotypes.PrivKey, err error) {
    24  	err = Cdc.Unmarshal(privKeyBytes, &privKey)
    25  	return
    26  }
    27  
    28  // PubKeyFromBytes unmarshals public key bytes and returns a PubKey
    29  func PubKeyFromBytes(pubKeyBytes []byte) (pubKey cryptotypes.PubKey, err error) {
    30  	err = Cdc.Unmarshal(pubKeyBytes, &pubKey)
    31  	return
    32  }