Some checks are pending
Build SimApp / build (amd64) (push) Waiting to run
Build SimApp / build (arm64) (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
Build & Push / build (push) Waiting to run
Run Gosec / Gosec (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Checks dependencies and mocks generation / Check go mod tidy (push) Waiting to run
Checks dependencies and mocks generation / Check up to date mocks (push) Waiting to run
System Tests / setup (push) Waiting to run
System Tests / test-system (push) Blocked by required conditions
System Tests / test-system-legacy (push) Blocked by required conditions
Tests / Code Coverage / split-test-files (push) Waiting to run
Tests / Code Coverage / tests (00) (push) Blocked by required conditions
Tests / Code Coverage / tests (01) (push) Blocked by required conditions
Tests / Code Coverage / tests (02) (push) Blocked by required conditions
Tests / Code Coverage / tests (03) (push) Blocked by required conditions
Tests / Code Coverage / test-integration (push) Waiting to run
Tests / Code Coverage / test-e2e (push) Waiting to run
Tests / Code Coverage / repo-analysis (push) Blocked by required conditions
Tests / Code Coverage / test-sim-nondeterminism (push) Waiting to run
Tests / Code Coverage / test-clientv2 (push) Waiting to run
Tests / Code Coverage / test-core (push) Waiting to run
Tests / Code Coverage / test-depinject (push) Waiting to run
Tests / Code Coverage / test-errors (push) Waiting to run
Tests / Code Coverage / test-math (push) Waiting to run
Tests / Code Coverage / test-schema (push) Waiting to run
Tests / Code Coverage / test-collections (push) Waiting to run
Tests / Code Coverage / test-cosmovisor (push) Waiting to run
Tests / Code Coverage / test-confix (push) Waiting to run
Tests / Code Coverage / test-store (push) Waiting to run
Tests / Code Coverage / test-log (push) Waiting to run
Tests / Code Coverage / test-x-tx (push) Waiting to run
Tests / Code Coverage / test-x-nft (push) Waiting to run
Tests / Code Coverage / test-x-circuit (push) Waiting to run
Tests / Code Coverage / test-x-feegrant (push) Waiting to run
Tests / Code Coverage / test-x-evidence (push) Waiting to run
Tests / Code Coverage / test-x-upgrade (push) Waiting to run
Tests / Code Coverage / test-tools-benchmark (push) Waiting to run
92 lines
2.9 KiB
Go
92 lines
2.9 KiB
Go
package codec
|
|
|
|
import (
|
|
cmtcrypto "git.cw.tr/mukan-network/mukan-consensus/crypto"
|
|
"git.cw.tr/mukan-network/mukan-consensus/crypto/encoding"
|
|
cmtprotocrypto "git.cw.tr/mukan-network/mukan-consensus/proto/tendermint/crypto"
|
|
|
|
"cosmossdk.io/errors"
|
|
|
|
"git.cw.tr/mukan-network/mukan-sdk/crypto/keys/ed25519"
|
|
"git.cw.tr/mukan-network/mukan-sdk/crypto/keys/secp256k1"
|
|
cryptotypes "git.cw.tr/mukan-network/mukan-sdk/crypto/types"
|
|
sdkerrors "git.cw.tr/mukan-network/mukan-sdk/types/errors"
|
|
)
|
|
|
|
// FromCmtProtoPublicKey converts a CMT's cmtprotocrypto.PublicKey into our own PubKey.
|
|
func FromCmtProtoPublicKey(protoPk cmtprotocrypto.PublicKey) (cryptotypes.PubKey, error) {
|
|
switch protoPk := protoPk.Sum.(type) {
|
|
case *cmtprotocrypto.PublicKey_Ed25519:
|
|
return &ed25519.PubKey{
|
|
Key: protoPk.Ed25519,
|
|
}, nil
|
|
case *cmtprotocrypto.PublicKey_Secp256K1:
|
|
return &secp256k1.PubKey{
|
|
Key: protoPk.Secp256K1,
|
|
}, nil
|
|
default:
|
|
return nil, errors.Wrapf(sdkerrors.ErrInvalidType, "cannot convert %v from Tendermint public key", protoPk)
|
|
}
|
|
}
|
|
|
|
// ToCmtProtoPublicKey converts our own PubKey to Cmt's cmtprotocrypto.PublicKey.
|
|
func ToCmtProtoPublicKey(pk cryptotypes.PubKey) (cmtprotocrypto.PublicKey, error) {
|
|
switch pk := pk.(type) {
|
|
case *ed25519.PubKey:
|
|
return cmtprotocrypto.PublicKey{
|
|
Sum: &cmtprotocrypto.PublicKey_Ed25519{
|
|
Ed25519: pk.Key,
|
|
},
|
|
}, nil
|
|
case *secp256k1.PubKey:
|
|
return cmtprotocrypto.PublicKey{
|
|
Sum: &cmtprotocrypto.PublicKey_Secp256K1{
|
|
Secp256K1: pk.Key,
|
|
},
|
|
}, nil
|
|
default:
|
|
return cmtprotocrypto.PublicKey{}, errors.Wrapf(sdkerrors.ErrInvalidType, "cannot convert %v to Tendermint public key", pk)
|
|
}
|
|
}
|
|
|
|
// FromCmtPubKeyInterface converts CMT's cmtcrypto.PubKey to our own PubKey.
|
|
func FromCmtPubKeyInterface(tmPk cmtcrypto.PubKey) (cryptotypes.PubKey, error) {
|
|
tmProtoPk, err := encoding.PubKeyToProto(tmPk)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return FromCmtProtoPublicKey(tmProtoPk)
|
|
}
|
|
|
|
// ToCmtPubKeyInterface converts our own PubKey to CMT's cmtcrypto.PubKey.
|
|
func ToCmtPubKeyInterface(pk cryptotypes.PubKey) (cmtcrypto.PubKey, error) {
|
|
tmProtoPk, err := ToCmtProtoPublicKey(pk)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return encoding.PubKeyFromProto(tmProtoPk)
|
|
}
|
|
|
|
// ----------------------
|
|
|
|
// Deprecated: use FromCmtProtoPublicKey instead.
|
|
func FromTmProtoPublicKey(protoPk cmtprotocrypto.PublicKey) (cryptotypes.PubKey, error) {
|
|
return FromCmtProtoPublicKey(protoPk)
|
|
}
|
|
|
|
// Deprecated: use ToCmtProtoPublicKey instead.
|
|
func ToTmProtoPublicKey(pk cryptotypes.PubKey) (cmtprotocrypto.PublicKey, error) {
|
|
return ToCmtProtoPublicKey(pk)
|
|
}
|
|
|
|
// Deprecated: use FromCmtPubKeyInterface instead.
|
|
func FromTmPubKeyInterface(tmPk cmtcrypto.PubKey) (cryptotypes.PubKey, error) {
|
|
return FromCmtPubKeyInterface(tmPk)
|
|
}
|
|
|
|
// Deprecated: use ToCmtPubKeyInterface instead.
|
|
func ToTmPubKeyInterface(pk cryptotypes.PubKey) (cmtcrypto.PubKey, error) {
|
|
return ToCmtPubKeyInterface(pk)
|
|
}
|