diff --git a/crypto/types/multisig/threshold_pubkey_test.go b/crypto/types/multisig/threshold_pubkey_test.go index 4eaf52ffa1..cb40646032 100644 --- a/crypto/types/multisig/threshold_pubkey_test.go +++ b/crypto/types/multisig/threshold_pubkey_test.go @@ -193,7 +193,7 @@ func TestMultiSigMigration(t *testing.T) { err := multisig.AddSignatureFromPubKey(multisignature, sigs[0], pkSet[0], pkSet) // create a StdSignature for msg, and convert it to sigV2 - sig := authtypes.StdSignature{PubKey: pkSet[1].Bytes(), Signature: msg} + sig := authtypes.StdSignature{PubKey: pkSet[1], Signature: msg} sigV2, err := authtypes.StdSignatureToSignatureV2(cdc, sig) require.NoError(t, multisig.AddSignatureV2(multisignature, sigV2, pkSet)) diff --git a/x/auth/ante/basic.go b/x/auth/ante/basic.go index 695cb6ebdf..05053d3d83 100644 --- a/x/auth/ante/basic.go +++ b/x/auth/ante/basic.go @@ -123,7 +123,7 @@ func (cgts ConsumeTxSizeGasDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim // use stdsignature to mock the size of a full signature simSig := types.StdSignature{ //nolint:staticcheck // this will be removed when proto is ready Signature: simSecp256k1Sig[:], - PubKey: pubkey.Bytes(), + PubKey: pubkey, } sigBz := legacy.Cdc.MustMarshalBinaryBare(simSig) diff --git a/x/auth/ante/sigverify_test.go b/x/auth/ante/sigverify_test.go index c980878cd2..7e78a31dd9 100644 --- a/x/auth/ante/sigverify_test.go +++ b/x/auth/ante/sigverify_test.go @@ -74,7 +74,7 @@ func (suite *AnteTestSuite) TestConsumeSignatureVerificationGas() { multisignature1 := multisig.NewMultisig(len(pkSet1)) expectedCost1 := expectedGasCostByKeys(pkSet1) for i := 0; i < len(pkSet1); i++ { - stdSig := types.StdSignature{PubKey: pkSet1[i].Bytes(), Signature: sigSet1[i]} + stdSig := types.StdSignature{PubKey: pkSet1[i], Signature: sigSet1[i]} sigV2, err := types.StdSignatureToSignatureV2(cdc, stdSig) suite.Require().NoError(err) err = multisig.AddSignatureV2(multisignature1, sigV2, pkSet1) diff --git a/x/auth/signing/verify_test.go b/x/auth/signing/verify_test.go index 30f53013a0..55f1f75144 100644 --- a/x/auth/signing/verify_test.go +++ b/x/auth/signing/verify_test.go @@ -55,7 +55,7 @@ func TestVerifySignature(t *testing.T) { signature, err := priv.Sign(signBytes) require.NoError(t, err) - stdSig := types.StdSignature{PubKey: pubKey.Bytes(), Signature: signature} + stdSig := types.StdSignature{PubKey: pubKey, Signature: signature} sigV2, err := types.StdSignatureToSignatureV2(cdc, stdSig) require.NoError(t, err) @@ -73,13 +73,13 @@ func TestVerifySignature(t *testing.T) { sig1, err := priv.Sign(multiSignBytes) require.NoError(t, err) - stdSig1 := types.StdSignature{PubKey: pubKey.Bytes(), Signature: sig1} + stdSig1 := types.StdSignature{PubKey: pubKey, Signature: sig1} sig1V2, err := types.StdSignatureToSignatureV2(cdc, stdSig1) require.NoError(t, err) sig2, err := priv1.Sign(multiSignBytes) require.NoError(t, err) - stdSig2 := types.StdSignature{PubKey: pubKey.Bytes(), Signature: sig2} + stdSig2 := types.StdSignature{PubKey: pubKey, Signature: sig2} sig2V2, err := types.StdSignatureToSignatureV2(cdc, stdSig2) require.NoError(t, err) diff --git a/x/auth/types/client_tx_test.go b/x/auth/types/client_tx_test.go index 2be71b74ca..26684ac202 100644 --- a/x/auth/types/client_tx_test.go +++ b/x/auth/types/client_tx_test.go @@ -3,6 +3,8 @@ package types_test import ( "testing" + cryptoAmino "github.com/cosmos/cosmos-sdk/crypto/codec" + "github.com/cosmos/cosmos-sdk/testutil/testdata" "github.com/cosmos/cosmos-sdk/client/testutil" @@ -17,6 +19,7 @@ import ( func testCodec() *codec.Codec { cdc := codec.New() sdk.RegisterCodec(cdc) + cryptoAmino.RegisterCrypto(cdc) cdc.RegisterConcrete(&testdata.TestMsg{}, "cosmos-sdk/Test", nil) return cdc } diff --git a/x/auth/types/stdtx.go b/x/auth/types/stdtx.go index d8402c06cb..2434a27833 100644 --- a/x/auth/types/stdtx.go +++ b/x/auth/types/stdtx.go @@ -71,12 +71,7 @@ func (fee StdFee) GasPrices() sdk.DecCoins { // Deprecated func NewStdSignature(pk crypto.PubKey, sig []byte) StdSignature { - var pkBz []byte - if pk != nil { - pkBz = pk.Bytes() - } - - return StdSignature{PubKey: pkBz, Signature: sig} + return StdSignature{PubKey: pk, Signature: sig} } // GetSignature returns the raw signature bytes. @@ -86,13 +81,8 @@ func (ss StdSignature) GetSignature() []byte { // GetPubKey returns the public key of a signature as a crypto.PubKey using the // Amino codec. -func (ss StdSignature) GetPubKey() (pk crypto.PubKey) { - if len(ss.PubKey) == 0 { - return nil - } - - amino.MustUnmarshalBinaryBare(ss.PubKey, &pk) - return pk +func (ss StdSignature) GetPubKey() crypto.PubKey { + return ss.PubKey } // MarshalYAML returns the YAML representation of the signature. @@ -319,8 +309,8 @@ func StdSignBytes(chainID string, accnum uint64, sequence uint64, fee StdFee, ms // Deprecated: StdSignature represents a sig type StdSignature struct { - PubKey []byte `json:"pub_key" yaml:"pub_key"` // optional - Signature []byte `json:"signature" yaml:"signature"` + crypto.PubKey `json:"pub_key" yaml:"pub_key"` // optional + Signature []byte `json:"signature" yaml:"signature"` } // DefaultTxDecoder logic for standard transaction decoding @@ -397,13 +387,6 @@ func StdSignatureToSignatureV2(cdc *codec.Codec, sig StdSignature) (signing.Sign // SignatureV2ToStdSignature converts a SignatureV2 to a StdSignature func SignatureV2ToStdSignature(cdc *codec.Codec, sig signing.SignatureV2) (StdSignature, error) { - var pubKeyBz []byte - - pubKey := sig.PubKey - if pubKey != nil { - pubKeyBz = pubKey.Bytes() - } - var ( sigBz []byte err error @@ -417,7 +400,7 @@ func SignatureV2ToStdSignature(cdc *codec.Codec, sig signing.SignatureV2) (StdSi } return StdSignature{ - PubKey: pubKeyBz, + PubKey: sig.PubKey, Signature: sigBz, }, nil } diff --git a/x/auth/types/stdtx_test.go b/x/auth/types/stdtx_test.go index 70d0ff2f74..829f1ef4e8 100644 --- a/x/auth/types/stdtx_test.go +++ b/x/auth/types/stdtx_test.go @@ -46,7 +46,7 @@ func NewTestTx(ctx sdk.Context, msgs []sdk.Msg, privs []crypto.PrivKey, accNums panic(err) } - sigs[i] = StdSignature{PubKey: priv.PubKey().Bytes(), Signature: sig} + sigs[i] = StdSignature{PubKey: priv.PubKey(), Signature: sig} } tx := NewStdTx(msgs, fee, sigs, "") @@ -184,11 +184,11 @@ func TestStdSignatureMarshalYAML(t *testing.T) { "|\n pubkey: \"\"\n signature: \"\"\n", }, { - StdSignature{PubKey: pubKey.Bytes(), Signature: []byte("dummySig")}, + StdSignature{PubKey: pubKey, Signature: []byte("dummySig")}, fmt.Sprintf("|\n pubkey: %s\n signature: 64756D6D79536967\n", sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pubKey)), }, { - StdSignature{PubKey: pubKey.Bytes(), Signature: nil}, + StdSignature{PubKey: pubKey, Signature: nil}, fmt.Sprintf("|\n pubkey: %s\n signature: \"\"\n", sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, pubKey)), }, } @@ -206,7 +206,7 @@ func TestSignatureV2Conversions(t *testing.T) { sdk.RegisterCodec(cdc) RegisterCodec(cdc) dummy := []byte("dummySig") - sig := StdSignature{PubKey: pubKey.Bytes(), Signature: dummy} + sig := StdSignature{PubKey: pubKey, Signature: dummy} sigV2, err := StdSignatureToSignatureV2(cdc, sig) require.NoError(t, err) @@ -247,7 +247,7 @@ func TestSignatureV2Conversions(t *testing.T) { require.NoError(t, err) sigV2, err = StdSignatureToSignatureV2(cdc, StdSignature{ - PubKey: multiPK.Bytes(), + PubKey: multiPK, Signature: msig, }) require.NoError(t, err) @@ -264,7 +264,7 @@ func TestGetSignaturesV2(t *testing.T) { RegisterCodec(cdc) fee := NewStdFee(50000, sdk.Coins{sdk.NewInt64Coin("atom", 150)}) - sig := StdSignature{PubKey: pubKey.Bytes(), Signature: dummy} + sig := StdSignature{PubKey: pubKey, Signature: dummy} stdTx := NewStdTx([]sdk.Msg{testdata.NewTestMsg()}, fee, []StdSignature{sig}, "testsigs") sigs, err := stdTx.GetSignaturesV2() diff --git a/x/auth/types/txbuilder.go b/x/auth/types/txbuilder.go index 8fe98c92de..9ba806aa55 100644 --- a/x/auth/types/txbuilder.go +++ b/x/auth/types/txbuilder.go @@ -300,7 +300,7 @@ func MakeSignature(kr keyring.Keyring, name string, msg StdSignMsg) (sig StdSign } return StdSignature{ - PubKey: pubkey.Bytes(), + PubKey: pubkey, Signature: sigBytes, }, nil }