Skip to content

Commit

Permalink
refactor: simplify sign mode (2/2) (#23476)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Jan 22, 2025
1 parent e441778 commit 39b0244
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 56 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
* [#23470](/~https://github.com/cosmos/cosmos-sdk/pull/23470) Converge to use of one single sign mode type and signer data:
* Use api's signmode throughout the SDK to align with `cosmossdk.io/tx`. This allows developer not to juggle between sign mode types
* Deprecate `authsigning.SignerData` in favor of txsigning.SignerData and replace its usage
* Move helpers to go from one sign mode enum to another to `types/signing` instead of `x/auth/signing` (less dependency on `x`)
* Remove `APISignModeToInternal` from `x/auth` as no conversion is necessary by the user anymore

### Bug Fixes

Expand Down
2 changes: 1 addition & 1 deletion client/tx/aux_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (b *AuxTxBuilder) SetSignMode(mode apisigning.SignMode) error {
apisigning.SignMode_SIGN_MODE_DIRECT_AUX, apisigning.SignMode_SIGN_MODE_LEGACY_AMINO_JSON)
}

b.auxSignerData.Mode, _ = signing.APISignModeToInternal(mode)
b.auxSignerData.Mode = signing.SignMode(mode)
return nil
}

Expand Down
4 changes: 1 addition & 3 deletions client/tx/aux_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
typestx "github.com/cosmos/cosmos-sdk/types/tx"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
)

const (
Expand Down Expand Up @@ -249,7 +248,6 @@ func checkCorrectData(t *testing.T, cdc codec.Codec, auxSignerData typestx.AuxSi
require.Equal(t, chainID, auxSignerData.SignDoc.ChainId)
require.Equal(t, msgAny, body.GetMessages()[0])
require.Equal(t, pkAny, auxSignerData.SignDoc.PublicKey)
m, _ := signing.InternalSignModeToAPI(auxSignerData.Mode)
require.Equal(t, signMode, m)
require.Equal(t, signMode, apisigning.SignMode(auxSignerData.Mode))
require.Equal(t, rawSig, auxSignerData.Sig)
}
6 changes: 3 additions & 3 deletions types/tx/direct_aux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package tx
import (
gogoprotoany "github.com/cosmos/gogoproto/types/any"

apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
Expand Down Expand Up @@ -50,12 +52,10 @@ func (a *AuxSignerData) GetSignatureV2() (signing.SignatureV2, error) {
return signing.SignatureV2{}, sdkerrors.ErrInvalidType.Wrapf("expected %T, got %T", (cryptotypes.PubKey)(nil), pk)
}

signMode, _ := signing.InternalSignModeToAPI(a.Mode)

return signing.SignatureV2{
PubKey: pk,
Data: &signing.SingleSignatureData{
SignMode: signMode,
SignMode: apisigning.SignMode(a.Mode),
Signature: a.Sig,
},
Sequence: a.SignDoc.Sequence,
Expand Down
5 changes: 3 additions & 2 deletions types/tx/direct_aux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

"github.com/stretchr/testify/require"

apisigning "cosmossdk.io/api/cosmos/tx/signing/v1beta1"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
Expand Down Expand Up @@ -76,8 +78,7 @@ func TestAuxSignerData(t *testing.T) {
require.NoError(t, err)
sigV2, err := tc.sd.GetSignatureV2()
require.NoError(t, err)
m, _ := signing.InternalSignModeToAPI(tc.sd.Mode)
require.Equal(t, m, sigV2.Data.(*signing.SingleSignatureData).SignMode)
require.Equal(t, apisigning.SignMode(tc.sd.Mode), sigV2.Data.(*signing.SingleSignatureData).SignMode)
require.Equal(t, tc.sd.Sig, sigV2.Data.(*signing.SingleSignatureData).Signature)
require.Equal(t, tc.sd.SignDoc.Sequence, sigV2.Sequence)
require.True(t, tc.sd.SignDoc.PublicKey.GetCachedValue().(cryptotypes.PubKey).Equals(sigV2.PubKey))
Expand Down
8 changes: 4 additions & 4 deletions types/tx/signing/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (

gogoprotoany "github.com/cosmos/gogoproto/types/any"

signingv1beta1 "cosmossdk.io/api/cosmos/tx/signing/v1beta1"

cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)

Expand Down Expand Up @@ -32,11 +34,10 @@ type SignatureV2 struct {
func SignatureDataToProto(data SignatureData) *SignatureDescriptor_Data {
switch data := data.(type) {
case *SingleSignatureData:
signMode, _ := APISignModeToInternal(data.SignMode)
return &SignatureDescriptor_Data{
Sum: &SignatureDescriptor_Data_Single_{
Single: &SignatureDescriptor_Data_Single{
Mode: signMode,
Mode: SignMode(data.SignMode),
Signature: data.Signature,
},
},
Expand Down Expand Up @@ -67,9 +68,8 @@ func SignatureDataToProto(data SignatureData) *SignatureDescriptor_Data {
func SignatureDataFromProto(descData *SignatureDescriptor_Data) SignatureData {
switch descData := descData.Sum.(type) {
case *SignatureDescriptor_Data_Single_:
signMode, _ := InternalSignModeToAPI(descData.Single.Mode)
return &SingleSignatureData{
SignMode: signMode,
SignMode: signingv1beta1.SignMode(descData.Single.Mode),
Signature: descData.Single.Signature,
}
case *SignatureDescriptor_Data_Multi_:
Expand Down
39 changes: 0 additions & 39 deletions types/tx/signing/types.go

This file was deleted.

4 changes: 1 addition & 3 deletions x/auth/tx/sigs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ func SignatureDataToModeInfoAndSig(data signing.SignatureData) (*tx.ModeInfo, []

switch data := data.(type) {
case *signing.SingleSignatureData:
signMode, _ := signing.APISignModeToInternal(data.SignMode)

return &tx.ModeInfo{
Sum: &tx.ModeInfo_Single_{
Single: &tx.ModeInfo_Single{Mode: signMode},
Single: &tx.ModeInfo_Single{Mode: signing.SignMode(data.SignMode)},
},
}, data.Signature
case *signing.MultiSignatureData:
Expand Down

0 comments on commit 39b0244

Please sign in to comment.