refactor(x/auth): allow empty public keys for GetSignBytesAdapter (#19651)
This commit is contained in:
parent
41f9272339
commit
06a398931e
@ -80,6 +80,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i
|
||||
* (crypto/keys) [#18026](https://github.com/cosmos/cosmos-sdk/pull/18026) Made public key generation constant time on `secp256k1`
|
||||
* (crypto | x/auth) [#14372](https://github.com/cosmos/cosmos-sdk/pull/18194) Key checks on signatures antehandle.
|
||||
* (types) [#18963](https://github.com/cosmos/cosmos-sdk/pull/18963) Swap out amino json encoding of `ABCIMessageLogs` for std lib json encoding
|
||||
* (x/auth) [#19651](https://github.com/cosmos/cosmos-sdk/pull/19651) Allow empty public keys in `GetSignBytesAdapter`.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
34
x/auth/signing/adapter_test.go
Normal file
34
x/auth/signing/adapter_test.go
Normal file
@ -0,0 +1,34 @@
|
||||
package signing_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
authsign "cosmossdk.io/x/auth/signing"
|
||||
|
||||
"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…
Reference in New Issue
Block a user