Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(x/auth): allow empty public keys for GetSignBytesAdapter (backport #19651) #19675

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [v0.50.5](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.5) - 2024-XX-XX

### Improvements

* (x/auth) [#19651](https://github.com/cosmos/cosmos-sdk/pull/19651) Allow empty public keys in `GetSignBytesAdapter`.

### Bug Fixes

* (x/auth) [#19549](https://github.com/cosmos/cosmos-sdk/pull/19549) Accept custom get signers when injecting `x/auth/tx`.
Expand Down
20 changes: 12 additions & 8 deletions x/auth/signing/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,24 @@ func GetSignBytesAdapter(
return nil, err
}

anyPk, err := codectypes.NewAnyWithValue(signerData.PubKey)
if err != nil {
return nil, err
}
var pubKey *anypb.Any
if signerData.PubKey != nil {
anyPk, err := codectypes.NewAnyWithValue(signerData.PubKey)
if err != nil {
return nil, err
}

pubKey = &anypb.Any{
TypeUrl: anyPk.TypeUrl,
Value: anyPk.Value,
}
}
txSignerData := txsigning.SignerData{
ChainID: signerData.ChainID,
AccountNumber: signerData.AccountNumber,
Sequence: signerData.Sequence,
Address: signerData.Address,
PubKey: &anypb.Any{
TypeUrl: anyPk.TypeUrl,
Value: anyPk.Value,
},
PubKey: pubKey,
}
// Generate the bytes to be signed.
return handlerMap.GetSignBytes(ctx, txSignMode, txSignerData, txData)
Expand Down
34 changes: 34 additions & 0 deletions x/auth/signing/adapter_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package signing_test

import (
"context"
"testing"

"github.com/stretchr/testify/require"

authsign "cosmossdk.io/x/auth/signing"

Check failure on line 9 in x/auth/signing/adapter_test.go

View workflow job for this annotation

GitHub Actions / tests (01)

cannot find module providing package cosmossdk.io/x/auth/signing: import lookup disabled by -mod=readonly
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved

"github.com/cosmos/cosmos-sdk/testutil/testdata"
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
"github.com/cosmos/cosmos-sdk/types/tx/signing"
)

func TestGetSignBytesAdapterNoPublicKey(t *testing.T) {
encodingConfig := moduletestutil.MakeTestEncodingConfig()
txConfig := encodingConfig.TxConfig
_, _, addr := testdata.KeyTestPubAddr()
signerData := authsign.SignerData{
Address: addr.String(),
ChainID: "test-chain",
AccountNumber: 11,
Sequence: 15,
}
w := txConfig.NewTxBuilder()
_, err := authsign.GetSignBytesAdapter(
context.Background(),
txConfig.SignModeHandler(),
signing.SignMode_SIGN_MODE_DIRECT,
signerData,
w.GetTx())
require.NoError(t, err)
}
Loading