feat(accounts/base): give chains the possibility to pick their chosen pubkey types for the base accounts (#21466)
This commit is contained in:
parent
54b49d4bcc
commit
8431dbd38a
File diff suppressed because it is too large
Load Diff
@ -29,7 +29,7 @@ for dir in $proto_dirs; do
|
||||
|
||||
# check if buf.gen.gogo.yaml exists in the proto directory
|
||||
if [ -f "buf.gen.gogo.yaml" ]; then
|
||||
for file in $(find . -maxdepth 5 -name '*.proto'); do
|
||||
for file in $(find . -maxdepth 8 -name '*.proto'); do
|
||||
# this regex checks if a proto file has its go_package set to cosmossdk.io/api/...
|
||||
# gogo proto files SHOULD ONLY be generated if this is false
|
||||
# we don't want gogo proto to run for proto files which are natively built for google.golang.org/protobuf
|
||||
|
||||
@ -45,7 +45,7 @@ Always refer to the [UPGRADING.md](https://github.com/cosmos/cosmos-sdk/blob/mai
|
||||
* [#20771](https://github.com/cosmos/cosmos-sdk/pull/20771) Use client/v2 `GetNodeHomeDirectory` helper in `app.go` and use the `DefaultNodeHome` constant everywhere in the app.
|
||||
* [#20490](https://github.com/cosmos/cosmos-sdk/pull/20490) Refactor simulations to make use of `testutil/sims` instead of `runsims`.
|
||||
* [#19726](https://github.com/cosmos/cosmos-sdk/pull/19726) Update APIs to match CometBFT v1.
|
||||
|
||||
* [#21466](https://github.com/cosmos/cosmos-sdk/pull/21466) Allow chains to plug in their own public key types in `base.Account`
|
||||
<!-- TODO: move changelog.md elements to here -->
|
||||
|
||||
## v0.47 to v0.50
|
||||
|
||||
@ -311,7 +311,7 @@ func NewSimApp(
|
||||
accountstd.AddAccount(lockup.DELAYED_LOCKING_ACCOUNT, lockup.NewDelayedLockingAccount),
|
||||
accountstd.AddAccount(lockup.PERMANENT_LOCKING_ACCOUNT, lockup.NewPermanentLockingAccount),
|
||||
// PRODUCTION: add
|
||||
baseaccount.NewAccount("base", txConfig.SignModeHandler()),
|
||||
baseaccount.NewAccount("base", txConfig.SignModeHandler(), baseaccount.WithSecp256K1PubKey()),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
@ -24,6 +24,11 @@ var _ = math.Inf
|
||||
const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
// Pairs defines a repeated slice of Pair objects.
|
||||
//
|
||||
// Deprecated: Store v1 is deprecated as of v0.50.x, please use Store v2 types
|
||||
// instead.
|
||||
//
|
||||
// Deprecated: Do not use.
|
||||
type Pairs struct {
|
||||
Pairs []Pair `protobuf:"bytes,1,rep,name=pairs,proto3" json:"pairs"`
|
||||
}
|
||||
@ -69,6 +74,11 @@ func (m *Pairs) GetPairs() []Pair {
|
||||
}
|
||||
|
||||
// Pair defines a key/value bytes tuple.
|
||||
//
|
||||
// Deprecated: Store v1 is deprecated as of v0.50.x, please use Store v2 types
|
||||
// instead.
|
||||
//
|
||||
// Deprecated: Do not use.
|
||||
type Pair struct {
|
||||
Key []byte `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
|
||||
Value []byte `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
|
||||
@ -131,21 +141,21 @@ func init() {
|
||||
}
|
||||
|
||||
var fileDescriptor_534782c4083e056d = []byte{
|
||||
// 217 bytes of a gzipped FileDescriptorProto
|
||||
// 223 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4c, 0xce, 0x2f, 0xce,
|
||||
0xcd, 0x2f, 0xd6, 0x2f, 0x2e, 0xc9, 0x2f, 0x4a, 0xd5, 0xcf, 0xcc, 0x2b, 0x49, 0x2d, 0xca, 0x4b,
|
||||
0xcc, 0xd1, 0xcf, 0x2e, 0xd3, 0x2f, 0x33, 0x4c, 0x4a, 0x2d, 0x49, 0x34, 0xd4, 0xcf, 0x2e, 0xd3,
|
||||
0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x52, 0x80, 0x28, 0xd5, 0x03, 0x2b, 0xd5, 0x83, 0x29, 0xd5,
|
||||
0xcb, 0x2e, 0xd3, 0x83, 0x2a, 0x95, 0x12, 0x49, 0xcf, 0x4f, 0xcf, 0x07, 0x2b, 0xd6, 0x07, 0xb1,
|
||||
0x20, 0xfa, 0x94, 0xbc, 0xb9, 0x58, 0x03, 0x12, 0x33, 0x8b, 0x8a, 0x85, 0x9c, 0xb8, 0x58, 0x0b,
|
||||
0x20, 0xfa, 0x94, 0xfc, 0xb9, 0x58, 0x03, 0x12, 0x33, 0x8b, 0x8a, 0x85, 0x9c, 0xb8, 0x58, 0x0b,
|
||||
0x40, 0x0c, 0x09, 0x46, 0x05, 0x66, 0x0d, 0x6e, 0x23, 0x35, 0x3d, 0x42, 0x06, 0xea, 0x81, 0xf4,
|
||||
0x39, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x04, 0xd1, 0xaa, 0xa4, 0xc7, 0xc5, 0x02, 0x12, 0x14,
|
||||
0x12, 0xe0, 0x62, 0xce, 0x4e, 0xad, 0x94, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x09, 0x02, 0x31, 0x85,
|
||||
0x44, 0xb8, 0x58, 0xcb, 0x12, 0x73, 0x4a, 0x53, 0x25, 0x98, 0xc0, 0x62, 0x10, 0x8e, 0x93, 0xc5,
|
||||
0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c,
|
||||
0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0xc9, 0x41, 0x6c, 0x2f, 0x4e, 0xc9,
|
||||
0xd6, 0xcb, 0xcc, 0xc7, 0xf4, 0x7f, 0x12, 0x1b, 0xd8, 0xf5, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff,
|
||||
0xff, 0x5d, 0xad, 0x97, 0xdd, 0x22, 0x01, 0x00, 0x00,
|
||||
0x39, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x04, 0xd1, 0x6a, 0xc5, 0x24, 0xc1, 0xa8, 0x64, 0xc4,
|
||||
0xc5, 0x02, 0x92, 0x10, 0x12, 0xe0, 0x62, 0xce, 0x4e, 0xad, 0x94, 0x60, 0x54, 0x60, 0xd4, 0xe0,
|
||||
0x09, 0x02, 0x31, 0x85, 0x44, 0xb8, 0x58, 0xcb, 0x12, 0x73, 0x4a, 0x53, 0x25, 0x98, 0xc0, 0x62,
|
||||
0x10, 0x0e, 0x48, 0x8f, 0x93, 0xc5, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78,
|
||||
0x24, 0xc7, 0x38, 0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44,
|
||||
0xc9, 0x41, 0x5c, 0x51, 0x9c, 0x92, 0xad, 0x97, 0x99, 0x8f, 0x19, 0x0e, 0x49, 0x6c, 0x60, 0x5f,
|
||||
0x18, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xf8, 0x41, 0x82, 0x6e, 0x2a, 0x01, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *Pairs) Marshal() (dAtA []byte, err error) {
|
||||
|
||||
@ -78,7 +78,7 @@ func initFixture(t *testing.T) *fixture {
|
||||
queryRouter := baseapp.NewGRPCQueryRouter()
|
||||
|
||||
handler := directHandler{}
|
||||
account := baseaccount.NewAccount("base", signing.NewHandlerMap(handler))
|
||||
account := baseaccount.NewAccount("base", signing.NewHandlerMap(handler), baseaccount.WithSecp256K1PubKey())
|
||||
accountsKeeper, err := accounts.NewKeeper(
|
||||
cdc,
|
||||
runtime.NewEnvironment(runtime.NewKVStoreService(keys[accounts.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(queryRouter), runtime.EnvWithMsgRouterService(router)),
|
||||
|
||||
@ -5,7 +5,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
dcrd_secp256k1 "github.com/decred/dcrd/dcrec/secp256k1/v4"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
|
||||
@ -20,42 +19,56 @@ import (
|
||||
accountsv1 "cosmossdk.io/x/accounts/v1"
|
||||
"cosmossdk.io/x/tx/signing"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
"github.com/cosmos/cosmos-sdk/types/tx"
|
||||
)
|
||||
|
||||
var (
|
||||
PubKeyPrefix = collections.NewPrefix(0)
|
||||
SequencePrefix = collections.NewPrefix(1)
|
||||
PubKeyPrefix = collections.NewPrefix(0)
|
||||
PubKeyTypePrefix = collections.NewPrefix(1)
|
||||
SequencePrefix = collections.NewPrefix(2)
|
||||
)
|
||||
|
||||
func NewAccount(name string, handlerMap *signing.HandlerMap) accountstd.AccountCreatorFunc {
|
||||
type Option func(a *Account)
|
||||
|
||||
func NewAccount(name string, handlerMap *signing.HandlerMap, options ...Option) accountstd.AccountCreatorFunc {
|
||||
return func(deps accountstd.Dependencies) (string, accountstd.Interface, error) {
|
||||
return name, Account{
|
||||
PubKey: collections.NewItem(deps.SchemaBuilder, PubKeyPrefix, "pub_key", codec.CollValue[secp256k1.PubKey](deps.LegacyStateCodec)),
|
||||
Sequence: collections.NewSequence(deps.SchemaBuilder, SequencePrefix, "sequence"),
|
||||
addrCodec: deps.AddressCodec,
|
||||
signingHandlers: handlerMap,
|
||||
hs: deps.Environment.HeaderService,
|
||||
}, nil
|
||||
acc := Account{
|
||||
PubKey: collections.NewItem(deps.SchemaBuilder, PubKeyPrefix, "pub_key_bytes", collections.BytesValue),
|
||||
PubKeyType: collections.NewItem(deps.SchemaBuilder, PubKeyTypePrefix, "pub_key_type", collections.StringValue),
|
||||
Sequence: collections.NewSequence(deps.SchemaBuilder, SequencePrefix, "sequence"),
|
||||
addrCodec: deps.AddressCodec,
|
||||
hs: deps.Environment.HeaderService,
|
||||
supportedPubKeys: map[string]pubKeyImpl{},
|
||||
signingHandlers: handlerMap,
|
||||
}
|
||||
for _, option := range options {
|
||||
option(&acc)
|
||||
}
|
||||
if len(acc.supportedPubKeys) == 0 {
|
||||
return "", nil, fmt.Errorf("no public keys plugged for account type %s", name)
|
||||
}
|
||||
return name, acc, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Account implements a base account.
|
||||
type Account struct {
|
||||
PubKey collections.Item[secp256k1.PubKey]
|
||||
PubKey collections.Item[[]byte]
|
||||
PubKeyType collections.Item[string]
|
||||
|
||||
Sequence collections.Sequence
|
||||
|
||||
addrCodec address.Codec
|
||||
hs header.Service
|
||||
|
||||
supportedPubKeys map[string]pubKeyImpl
|
||||
|
||||
signingHandlers *signing.HandlerMap
|
||||
}
|
||||
|
||||
func (a Account) Init(ctx context.Context, msg *v1.MsgInit) (*v1.MsgInitResponse, error) {
|
||||
return &v1.MsgInitResponse{}, a.verifyAndSetPubKey(ctx, msg.PubKey)
|
||||
return &v1.MsgInitResponse{}, a.savePubKey(ctx, msg.PubKey)
|
||||
}
|
||||
|
||||
func (a Account) SwapPubKey(ctx context.Context, msg *v1.MsgSwapPubKey) (*v1.MsgSwapPubKeyResponse, error) {
|
||||
@ -63,15 +76,7 @@ func (a Account) SwapPubKey(ctx context.Context, msg *v1.MsgSwapPubKey) (*v1.Msg
|
||||
return nil, errors.New("unauthorized")
|
||||
}
|
||||
|
||||
return &v1.MsgSwapPubKeyResponse{}, a.verifyAndSetPubKey(ctx, msg.NewPubKey)
|
||||
}
|
||||
|
||||
func (a Account) verifyAndSetPubKey(ctx context.Context, key []byte) error {
|
||||
_, err := dcrd_secp256k1.ParsePubKey(key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return a.PubKey.Set(ctx, secp256k1.PubKey{Key: key})
|
||||
return &v1.MsgSwapPubKeyResponse{}, a.savePubKey(ctx, msg.NewPubKey)
|
||||
}
|
||||
|
||||
// Authenticate implements the authentication flow of an abstracted base account.
|
||||
@ -82,12 +87,12 @@ func (a Account) Authenticate(ctx context.Context, msg *aa_interface_v1.MsgAuthe
|
||||
|
||||
pubKey, signerData, err := a.computeSignerData(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("unable to compute signer data: %w", err)
|
||||
}
|
||||
|
||||
txData, err := a.getTxData(msg)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("unable to get tx data: %w", err)
|
||||
}
|
||||
|
||||
gotSeq := msg.Tx.AuthInfo.SignerInfos[msg.SignerIndex].Sequence
|
||||
@ -104,7 +109,7 @@ func (a Account) Authenticate(ctx context.Context, msg *aa_interface_v1.MsgAuthe
|
||||
|
||||
signBytes, err := a.signingHandlers.GetSignBytes(ctx, signMode, signerData, txData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("unable to get sign bytes: %w", err)
|
||||
}
|
||||
|
||||
if !pubKey.VerifySignature(signBytes, signature) {
|
||||
@ -123,31 +128,31 @@ func parseSignMode(info *tx.ModeInfo) (signingv1beta1.SignMode, error) {
|
||||
}
|
||||
|
||||
// computeSignerData will populate signer data and also increase the sequence.
|
||||
func (a Account) computeSignerData(ctx context.Context) (secp256k1.PubKey, signing.SignerData, error) {
|
||||
func (a Account) computeSignerData(ctx context.Context) (PubKey, signing.SignerData, error) {
|
||||
addrStr, err := a.addrCodec.BytesToString(accountstd.Whoami(ctx))
|
||||
if err != nil {
|
||||
return secp256k1.PubKey{}, signing.SignerData{}, err
|
||||
return nil, signing.SignerData{}, err
|
||||
}
|
||||
chainID := a.hs.HeaderInfo(ctx).ChainID
|
||||
|
||||
wantSequence, err := a.Sequence.Next(ctx)
|
||||
if err != nil {
|
||||
return secp256k1.PubKey{}, signing.SignerData{}, err
|
||||
return nil, signing.SignerData{}, err
|
||||
}
|
||||
|
||||
pk, err := a.PubKey.Get(ctx)
|
||||
pk, err := a.loadPubKey(ctx)
|
||||
if err != nil {
|
||||
return secp256k1.PubKey{}, signing.SignerData{}, err
|
||||
return nil, signing.SignerData{}, err
|
||||
}
|
||||
|
||||
pkAny, err := codectypes.NewAnyWithValue(&pk)
|
||||
pkAny, err := codectypes.NewAnyWithValue(pk)
|
||||
if err != nil {
|
||||
return secp256k1.PubKey{}, signing.SignerData{}, err
|
||||
return nil, signing.SignerData{}, err
|
||||
}
|
||||
|
||||
accNum, err := a.getNumber(ctx, addrStr)
|
||||
if err != nil {
|
||||
return secp256k1.PubKey{}, signing.SignerData{}, err
|
||||
return nil, signing.SignerData{}, err
|
||||
}
|
||||
|
||||
return pk, signing.SignerData{
|
||||
@ -200,6 +205,54 @@ func (a Account) getTxData(msg *aa_interface_v1.MsgAuthenticate) (signing.TxData
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (a Account) loadPubKey(ctx context.Context) (PubKey, error) {
|
||||
pkType, err := a.PubKeyType.Get(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
publicKey, exists := a.supportedPubKeys[pkType]
|
||||
// this means that the chain developer suddenly started using a key type.
|
||||
if !exists {
|
||||
return nil, fmt.Errorf("pubkey type %s is not supported by the chain anymore", pkType)
|
||||
}
|
||||
|
||||
pkBytes, err := a.PubKey.Get(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pubKey, err := publicKey.decode(pkBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return pubKey, nil
|
||||
}
|
||||
|
||||
func (a Account) savePubKey(ctx context.Context, anyPk *codectypes.Any) error {
|
||||
// check if known
|
||||
name := nameFromTypeURL(anyPk.TypeUrl)
|
||||
impl, exists := a.supportedPubKeys[name]
|
||||
if !exists {
|
||||
return fmt.Errorf("unknown pubkey type %s", name)
|
||||
}
|
||||
pk, err := impl.decode(anyPk.Value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to decode pubkey: %w", err)
|
||||
}
|
||||
err = impl.validate(pk)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to validate pubkey: %w", err)
|
||||
}
|
||||
|
||||
// save into state
|
||||
err = a.PubKey.Set(ctx, anyPk.Value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to save pubkey: %w", err)
|
||||
}
|
||||
return a.PubKeyType.Set(ctx, name)
|
||||
}
|
||||
|
||||
func (a Account) QuerySequence(ctx context.Context, _ *v1.QuerySequence) (*v1.QuerySequenceResponse, error) {
|
||||
seq, err := a.Sequence.Peek(ctx)
|
||||
if err != nil {
|
||||
|
||||
@ -5,6 +5,9 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
gogoproto "github.com/cosmos/gogoproto/proto"
|
||||
types "github.com/cosmos/gogoproto/types/any"
|
||||
dcrd_secp256k1 "github.com/decred/dcrd/dcrec/secp256k1/v4"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"cosmossdk.io/core/store"
|
||||
@ -24,7 +27,10 @@ func setupBaseAccount(t *testing.T, ss store.KVStoreService) Account {
|
||||
deps := makeMockDependencies(ss)
|
||||
handler := directHandler{}
|
||||
|
||||
createAccFn := NewAccount("base", signing.NewHandlerMap(handler))
|
||||
createAccFn := NewAccount("base", signing.NewHandlerMap(handler), WithPubKeyWithValidationFunc(func(pt *secp256k1.PubKey) error {
|
||||
_, err := dcrd_secp256k1.ParsePubKey(pt.Key)
|
||||
return err
|
||||
}))
|
||||
_, acc, err := createAccFn(deps)
|
||||
baseAcc := acc.(Account)
|
||||
require.NoError(t, err)
|
||||
@ -36,7 +42,7 @@ func TestInit(t *testing.T) {
|
||||
ctx, ss := newMockContext(t)
|
||||
baseAcc := setupBaseAccount(t, ss)
|
||||
_, err := baseAcc.Init(ctx, &v1.MsgInit{
|
||||
PubKey: secp256k1.GenPrivKey().PubKey().Bytes(),
|
||||
PubKey: toAnyPb(t, secp256k1.GenPrivKey().PubKey()),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -48,14 +54,14 @@ func TestInit(t *testing.T) {
|
||||
{
|
||||
"valid init",
|
||||
&v1.MsgInit{
|
||||
PubKey: secp256k1.GenPrivKey().PubKey().Bytes(),
|
||||
PubKey: toAnyPb(t, secp256k1.GenPrivKey().PubKey()),
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"invalid pubkey",
|
||||
&v1.MsgInit{
|
||||
PubKey: []byte("invalid_pk"),
|
||||
PubKey: toAnyPb(t, &secp256k1.PubKey{Key: []byte("invalid")}),
|
||||
},
|
||||
true,
|
||||
},
|
||||
@ -77,7 +83,7 @@ func TestSwapKey(t *testing.T) {
|
||||
ctx, ss := newMockContext(t)
|
||||
baseAcc := setupBaseAccount(t, ss)
|
||||
_, err := baseAcc.Init(ctx, &v1.MsgInit{
|
||||
PubKey: secp256k1.GenPrivKey().PubKey().Bytes(),
|
||||
PubKey: toAnyPb(t, secp256k1.GenPrivKey().PubKey()),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -94,7 +100,7 @@ func TestSwapKey(t *testing.T) {
|
||||
return accountstd.SetSender(ctx, []byte("mock_base_account"))
|
||||
},
|
||||
&v1.MsgSwapPubKey{
|
||||
NewPubKey: secp256k1.GenPrivKey().PubKey().Bytes(),
|
||||
NewPubKey: toAnyPb(t, secp256k1.GenPrivKey().PubKey()),
|
||||
},
|
||||
false,
|
||||
nil,
|
||||
@ -105,7 +111,7 @@ func TestSwapKey(t *testing.T) {
|
||||
return accountstd.SetSender(ctx, []byte("sender"))
|
||||
},
|
||||
&v1.MsgSwapPubKey{
|
||||
NewPubKey: secp256k1.GenPrivKey().PubKey().Bytes(),
|
||||
NewPubKey: toAnyPb(t, secp256k1.GenPrivKey().PubKey()),
|
||||
},
|
||||
true,
|
||||
errors.New("unauthorized"),
|
||||
@ -116,7 +122,7 @@ func TestSwapKey(t *testing.T) {
|
||||
return accountstd.SetSender(ctx, []byte("mock_base_account"))
|
||||
},
|
||||
&v1.MsgSwapPubKey{
|
||||
NewPubKey: []byte("invalid_pk"),
|
||||
NewPubKey: toAnyPb(t, &secp256k1.PubKey{Key: []byte("invalid")}),
|
||||
},
|
||||
true,
|
||||
nil,
|
||||
@ -149,7 +155,7 @@ func TestAuthenticate(t *testing.T) {
|
||||
pkAny, err := codectypes.NewAnyWithValue(privKey.PubKey())
|
||||
require.NoError(t, err)
|
||||
_, err = baseAcc.Init(ctx, &v1.MsgInit{
|
||||
PubKey: privKey.PubKey().Bytes(),
|
||||
PubKey: toAnyPb(t, privKey.PubKey()),
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
@ -251,3 +257,13 @@ func TestAuthenticate(t *testing.T) {
|
||||
})
|
||||
require.Equal(t, errors.New("signature verification failed"), err)
|
||||
}
|
||||
|
||||
func toAnyPb(t *testing.T, pm gogoproto.Message) *codectypes.Any {
|
||||
t.Helper()
|
||||
if gogoproto.MessageName(pm) == gogoproto.MessageName(&types.Any{}) {
|
||||
t.Fatal("no")
|
||||
}
|
||||
pb, err := codectypes.NewAnyWithValue(pm)
|
||||
require.NoError(t, err)
|
||||
return pb
|
||||
}
|
||||
|
||||
75
x/accounts/defaults/base/pubkey.go
Normal file
75
x/accounts/defaults/base/pubkey.go
Normal file
@ -0,0 +1,75 @@
|
||||
package base
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
gogoproto "github.com/cosmos/gogoproto/proto"
|
||||
dcrd_secp256k1 "github.com/decred/dcrd/dcrec/secp256k1/v4"
|
||||
|
||||
"cosmossdk.io/core/transaction"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
|
||||
)
|
||||
|
||||
// this file implements a general mechanism to plugin public keys to a baseaccount
|
||||
|
||||
// PubKey defines a generic pubkey.
|
||||
type PubKey interface {
|
||||
transaction.Msg
|
||||
VerifySignature(msg, sig []byte) bool
|
||||
}
|
||||
|
||||
type PubKeyG[T any] interface {
|
||||
*T
|
||||
PubKey
|
||||
}
|
||||
|
||||
type pubKeyImpl struct {
|
||||
decode func(b []byte) (PubKey, error)
|
||||
validate func(key PubKey) error
|
||||
}
|
||||
|
||||
func WithSecp256K1PubKey() Option {
|
||||
return WithPubKeyWithValidationFunc(func(pt *secp256k1.PubKey) error {
|
||||
_, err := dcrd_secp256k1.ParsePubKey(pt.Key)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
||||
func WithPubKey[T any, PT PubKeyG[T]]() Option {
|
||||
return WithPubKeyWithValidationFunc[T, PT](func(_ PT) error {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func WithPubKeyWithValidationFunc[T any, PT PubKeyG[T]](validateFn func(PT) error) Option {
|
||||
pkImpl := pubKeyImpl{
|
||||
decode: func(b []byte) (PubKey, error) {
|
||||
key := PT(new(T))
|
||||
err := gogoproto.Unmarshal(b, key)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return key, nil
|
||||
},
|
||||
validate: func(k PubKey) error {
|
||||
concrete, ok := k.(PT)
|
||||
if !ok {
|
||||
return fmt.Errorf("invalid pubkey type passed for validation, wanted: %T, got: %T", concrete, k)
|
||||
}
|
||||
return validateFn(concrete)
|
||||
},
|
||||
}
|
||||
return func(a *Account) {
|
||||
a.supportedPubKeys[gogoproto.MessageName(PT(new(T)))] = pkImpl
|
||||
}
|
||||
}
|
||||
|
||||
func nameFromTypeURL(url string) string {
|
||||
name := url
|
||||
if i := strings.LastIndexByte(url, '/'); i >= 0 {
|
||||
name = name[i+len("/"):]
|
||||
}
|
||||
return name
|
||||
}
|
||||
@ -6,6 +6,7 @@ package v1
|
||||
import (
|
||||
fmt "fmt"
|
||||
proto "github.com/cosmos/gogoproto/proto"
|
||||
any "github.com/cosmos/gogoproto/types/any"
|
||||
io "io"
|
||||
math "math"
|
||||
math_bits "math/bits"
|
||||
@ -24,8 +25,8 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package
|
||||
|
||||
// MsgInit is used to initialize a base account.
|
||||
type MsgInit struct {
|
||||
// pub_key defines the secp256k1 pubkey for the account.
|
||||
PubKey []byte `protobuf:"bytes,1,opt,name=pub_key,json=pubKey,proto3" json:"pub_key,omitempty"`
|
||||
// pub_key defines a pubkey for the account arbitrary encapsulated.
|
||||
PubKey *any.Any `protobuf:"bytes,1,opt,name=pub_key,json=pubKey,proto3" json:"pub_key,omitempty"`
|
||||
}
|
||||
|
||||
func (m *MsgInit) Reset() { *m = MsgInit{} }
|
||||
@ -61,7 +62,7 @@ func (m *MsgInit) XXX_DiscardUnknown() {
|
||||
|
||||
var xxx_messageInfo_MsgInit proto.InternalMessageInfo
|
||||
|
||||
func (m *MsgInit) GetPubKey() []byte {
|
||||
func (m *MsgInit) GetPubKey() *any.Any {
|
||||
if m != nil {
|
||||
return m.PubKey
|
||||
}
|
||||
@ -109,7 +110,7 @@ var xxx_messageInfo_MsgInitResponse proto.InternalMessageInfo
|
||||
// MsgSwapPubKey is used to change the pubkey for the account.
|
||||
type MsgSwapPubKey struct {
|
||||
// new_pub_key defines the secp256k1 pubkey to swap the account to.
|
||||
NewPubKey []byte `protobuf:"bytes,1,opt,name=new_pub_key,json=newPubKey,proto3" json:"new_pub_key,omitempty"`
|
||||
NewPubKey *any.Any `protobuf:"bytes,1,opt,name=new_pub_key,json=newPubKey,proto3" json:"new_pub_key,omitempty"`
|
||||
}
|
||||
|
||||
func (m *MsgSwapPubKey) Reset() { *m = MsgSwapPubKey{} }
|
||||
@ -145,7 +146,7 @@ func (m *MsgSwapPubKey) XXX_DiscardUnknown() {
|
||||
|
||||
var xxx_messageInfo_MsgSwapPubKey proto.InternalMessageInfo
|
||||
|
||||
func (m *MsgSwapPubKey) GetNewPubKey() []byte {
|
||||
func (m *MsgSwapPubKey) GetNewPubKey() *any.Any {
|
||||
if m != nil {
|
||||
return m.NewPubKey
|
||||
}
|
||||
@ -273,6 +274,88 @@ func (m *QuerySequenceResponse) GetSequence() uint64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// QueryPubKey is the request used to query the pubkey of an account.
|
||||
type QueryPubKey struct {
|
||||
}
|
||||
|
||||
func (m *QueryPubKey) Reset() { *m = QueryPubKey{} }
|
||||
func (m *QueryPubKey) String() string { return proto.CompactTextString(m) }
|
||||
func (*QueryPubKey) ProtoMessage() {}
|
||||
func (*QueryPubKey) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_7c860870b5ed6dc2, []int{6}
|
||||
}
|
||||
func (m *QueryPubKey) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *QueryPubKey) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_QueryPubKey.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *QueryPubKey) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_QueryPubKey.Merge(m, src)
|
||||
}
|
||||
func (m *QueryPubKey) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *QueryPubKey) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_QueryPubKey.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_QueryPubKey proto.InternalMessageInfo
|
||||
|
||||
// QueryPubKeyResponse is the response returned when a QueryPubKey message is sent.
|
||||
type QueryPubKeyResponse struct {
|
||||
PubKey *any.Any `protobuf:"bytes,1,opt,name=pub_key,json=pubKey,proto3" json:"pub_key,omitempty"`
|
||||
}
|
||||
|
||||
func (m *QueryPubKeyResponse) Reset() { *m = QueryPubKeyResponse{} }
|
||||
func (m *QueryPubKeyResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*QueryPubKeyResponse) ProtoMessage() {}
|
||||
func (*QueryPubKeyResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_7c860870b5ed6dc2, []int{7}
|
||||
}
|
||||
func (m *QueryPubKeyResponse) XXX_Unmarshal(b []byte) error {
|
||||
return m.Unmarshal(b)
|
||||
}
|
||||
func (m *QueryPubKeyResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
if deterministic {
|
||||
return xxx_messageInfo_QueryPubKeyResponse.Marshal(b, m, deterministic)
|
||||
} else {
|
||||
b = b[:cap(b)]
|
||||
n, err := m.MarshalToSizedBuffer(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return b[:n], nil
|
||||
}
|
||||
}
|
||||
func (m *QueryPubKeyResponse) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_QueryPubKeyResponse.Merge(m, src)
|
||||
}
|
||||
func (m *QueryPubKeyResponse) XXX_Size() int {
|
||||
return m.Size()
|
||||
}
|
||||
func (m *QueryPubKeyResponse) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_QueryPubKeyResponse.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_QueryPubKeyResponse proto.InternalMessageInfo
|
||||
|
||||
func (m *QueryPubKeyResponse) GetPubKey() *any.Any {
|
||||
if m != nil {
|
||||
return m.PubKey
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*MsgInit)(nil), "cosmos.accounts.defaults.base.v1.MsgInit")
|
||||
proto.RegisterType((*MsgInitResponse)(nil), "cosmos.accounts.defaults.base.v1.MsgInitResponse")
|
||||
@ -280,6 +363,8 @@ func init() {
|
||||
proto.RegisterType((*MsgSwapPubKeyResponse)(nil), "cosmos.accounts.defaults.base.v1.MsgSwapPubKeyResponse")
|
||||
proto.RegisterType((*QuerySequence)(nil), "cosmos.accounts.defaults.base.v1.QuerySequence")
|
||||
proto.RegisterType((*QuerySequenceResponse)(nil), "cosmos.accounts.defaults.base.v1.QuerySequenceResponse")
|
||||
proto.RegisterType((*QueryPubKey)(nil), "cosmos.accounts.defaults.base.v1.QueryPubKey")
|
||||
proto.RegisterType((*QueryPubKeyResponse)(nil), "cosmos.accounts.defaults.base.v1.QueryPubKeyResponse")
|
||||
}
|
||||
|
||||
func init() {
|
||||
@ -287,23 +372,26 @@ func init() {
|
||||
}
|
||||
|
||||
var fileDescriptor_7c860870b5ed6dc2 = []byte{
|
||||
// 254 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0xd2, 0x4e, 0xce, 0x2f, 0xce,
|
||||
0xcd, 0x2f, 0xd6, 0x4f, 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b, 0x29, 0xd6, 0x4f, 0x49, 0x4d, 0x4b,
|
||||
0x2c, 0xcd, 0x29, 0x29, 0xd6, 0x4f, 0x4a, 0x2c, 0x4e, 0xd5, 0x2f, 0x33, 0x04, 0xd3, 0x7a, 0x05,
|
||||
0x45, 0xf9, 0x25, 0xf9, 0x42, 0x0a, 0x10, 0xc5, 0x7a, 0x30, 0xc5, 0x7a, 0x30, 0xc5, 0x7a, 0x60,
|
||||
0x45, 0x65, 0x86, 0x4a, 0x4a, 0x5c, 0xec, 0xbe, 0xc5, 0xe9, 0x9e, 0x79, 0x99, 0x25, 0x42, 0xe2,
|
||||
0x5c, 0xec, 0x05, 0xa5, 0x49, 0xf1, 0xd9, 0xa9, 0x95, 0x12, 0x8c, 0x0a, 0x8c, 0x1a, 0x3c, 0x41,
|
||||
0x6c, 0x05, 0xa5, 0x49, 0xde, 0xa9, 0x95, 0x4a, 0x82, 0x5c, 0xfc, 0x50, 0x35, 0x41, 0xa9, 0xc5,
|
||||
0x05, 0xf9, 0x79, 0xc5, 0xa9, 0x4a, 0xfa, 0x5c, 0xbc, 0xbe, 0xc5, 0xe9, 0xc1, 0xe5, 0x89, 0x05,
|
||||
0x01, 0x60, 0x35, 0x42, 0x72, 0x5c, 0xdc, 0x79, 0xa9, 0xe5, 0xf1, 0xa8, 0x06, 0x70, 0xe6, 0xa5,
|
||||
0x96, 0x43, 0xe4, 0x95, 0xc4, 0xb9, 0x44, 0x51, 0x34, 0xc0, 0x4d, 0xe2, 0xe7, 0xe2, 0x0d, 0x2c,
|
||||
0x4d, 0x2d, 0xaa, 0x0c, 0x4e, 0x2d, 0x2c, 0x4d, 0xcd, 0x4b, 0x4e, 0x55, 0x32, 0xe6, 0x12, 0x45,
|
||||
0x11, 0x80, 0xa9, 0x14, 0x92, 0xe2, 0xe2, 0x28, 0x86, 0x8a, 0x81, 0xcd, 0x67, 0x09, 0x82, 0xf3,
|
||||
0x9d, 0x9c, 0x4e, 0x3c, 0x92, 0x63, 0xbc, 0xf0, 0x48, 0x8e, 0xf1, 0xc1, 0x23, 0x39, 0xc6, 0x09,
|
||||
0x8f, 0xe5, 0x18, 0x2e, 0x3c, 0x96, 0x63, 0xb8, 0xf1, 0x58, 0x8e, 0x21, 0x4a, 0x03, 0x12, 0x04,
|
||||
0xc5, 0x29, 0xd9, 0x7a, 0x99, 0xf9, 0xfa, 0x15, 0xb8, 0xc3, 0x2d, 0x89, 0x0d, 0x1c, 0x66, 0xc6,
|
||||
0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x99, 0x31, 0x20, 0x4a, 0x62, 0x01, 0x00, 0x00,
|
||||
// 303 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x91, 0xcf, 0x4a, 0xc3, 0x40,
|
||||
0x10, 0xc6, 0x1b, 0x90, 0x56, 0xa7, 0x94, 0x62, 0xb4, 0xa8, 0x3d, 0x2c, 0x65, 0x4f, 0x05, 0x71,
|
||||
0x97, 0x5a, 0x0f, 0x5e, 0x2d, 0x7a, 0x10, 0x29, 0x68, 0x7a, 0xf3, 0x52, 0x92, 0x74, 0x1a, 0x4a,
|
||||
0xeb, 0x6e, 0xec, 0x66, 0x1b, 0xf3, 0x16, 0x3e, 0x96, 0xc7, 0x1e, 0x3d, 0x4a, 0xf2, 0x22, 0xc2,
|
||||
0xe6, 0x0f, 0xf6, 0x20, 0xe8, 0x69, 0x99, 0xe1, 0xf7, 0xfb, 0x06, 0xf6, 0x83, 0x73, 0x5f, 0xaa,
|
||||
0x17, 0xa9, 0xb8, 0xeb, 0xfb, 0x52, 0x8b, 0x48, 0xf1, 0x19, 0xce, 0x5d, 0xbd, 0x8a, 0x14, 0xf7,
|
||||
0x5c, 0x85, 0x7c, 0x33, 0x30, 0x2f, 0x0b, 0xd7, 0x32, 0x92, 0x76, 0x2f, 0x87, 0x59, 0x09, 0xb3,
|
||||
0x12, 0x66, 0x06, 0xda, 0x0c, 0xba, 0x67, 0x81, 0x94, 0xc1, 0x0a, 0xb9, 0xe1, 0x3d, 0x3d, 0xe7,
|
||||
0xae, 0x48, 0x72, 0x99, 0x5e, 0x43, 0x63, 0xac, 0x82, 0x7b, 0xb1, 0x88, 0xec, 0x0b, 0x68, 0x84,
|
||||
0xda, 0x9b, 0x2e, 0x31, 0x39, 0xb5, 0x7a, 0x56, 0xbf, 0x79, 0x79, 0xcc, 0x72, 0x8f, 0x95, 0x1e,
|
||||
0xbb, 0x11, 0x89, 0x53, 0x0f, 0xb5, 0xf7, 0x80, 0x09, 0x3d, 0x84, 0x76, 0x61, 0x3a, 0xa8, 0x42,
|
||||
0x29, 0x14, 0xd2, 0x3b, 0x68, 0x8d, 0x55, 0x30, 0x89, 0xdd, 0xf0, 0xd1, 0x30, 0xf6, 0x15, 0x34,
|
||||
0x05, 0xc6, 0xd3, 0xbf, 0xc4, 0x1e, 0x08, 0x8c, 0x73, 0x8b, 0x9e, 0x40, 0x67, 0x27, 0xa6, 0xca,
|
||||
0x6f, 0x43, 0xeb, 0x49, 0xe3, 0x3a, 0x99, 0xe0, 0xab, 0x46, 0xe1, 0x23, 0x1d, 0x42, 0x67, 0x67,
|
||||
0x51, 0x92, 0x76, 0x17, 0xf6, 0x55, 0xb1, 0x33, 0x57, 0xf7, 0x9c, 0x6a, 0xa6, 0x2d, 0x68, 0x1a,
|
||||
0xa9, 0xb8, 0x76, 0x0b, 0x47, 0x3f, 0xc6, 0x2a, 0xe1, 0x7f, 0xbf, 0x31, 0x1a, 0x7d, 0xa4, 0xc4,
|
||||
0xda, 0xa6, 0xc4, 0xfa, 0x4a, 0x89, 0xf5, 0x9e, 0x91, 0xda, 0x36, 0x23, 0xb5, 0xcf, 0x8c, 0xd4,
|
||||
0x9e, 0xfb, 0x79, 0x3d, 0x6a, 0xb6, 0x64, 0x0b, 0xc9, 0xdf, 0x7e, 0xef, 0xd4, 0xab, 0x9b, 0xe4,
|
||||
0xe1, 0x77, 0x00, 0x00, 0x00, 0xff, 0xff, 0x8f, 0xe1, 0xb2, 0xd8, 0xfe, 0x01, 0x00, 0x00,
|
||||
}
|
||||
|
||||
func (m *MsgInit) Marshal() (dAtA []byte, err error) {
|
||||
@ -326,10 +414,15 @@ func (m *MsgInit) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.PubKey) > 0 {
|
||||
i -= len(m.PubKey)
|
||||
copy(dAtA[i:], m.PubKey)
|
||||
i = encodeVarintBase(dAtA, i, uint64(len(m.PubKey)))
|
||||
if m.PubKey != nil {
|
||||
{
|
||||
size, err := m.PubKey.MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintBase(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
@ -379,10 +472,15 @@ func (m *MsgSwapPubKey) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if len(m.NewPubKey) > 0 {
|
||||
i -= len(m.NewPubKey)
|
||||
copy(dAtA[i:], m.NewPubKey)
|
||||
i = encodeVarintBase(dAtA, i, uint64(len(m.NewPubKey)))
|
||||
if m.NewPubKey != nil {
|
||||
{
|
||||
size, err := m.NewPubKey.MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintBase(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
@ -463,6 +561,64 @@ func (m *QuerySequenceResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *QueryPubKey) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *QueryPubKey) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *QueryPubKey) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func (m *QueryPubKeyResponse) Marshal() (dAtA []byte, err error) {
|
||||
size := m.Size()
|
||||
dAtA = make([]byte, size)
|
||||
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return dAtA[:n], nil
|
||||
}
|
||||
|
||||
func (m *QueryPubKeyResponse) MarshalTo(dAtA []byte) (int, error) {
|
||||
size := m.Size()
|
||||
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||
}
|
||||
|
||||
func (m *QueryPubKeyResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||
i := len(dAtA)
|
||||
_ = i
|
||||
var l int
|
||||
_ = l
|
||||
if m.PubKey != nil {
|
||||
{
|
||||
size, err := m.PubKey.MarshalToSizedBuffer(dAtA[:i])
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
i -= size
|
||||
i = encodeVarintBase(dAtA, i, uint64(size))
|
||||
}
|
||||
i--
|
||||
dAtA[i] = 0xa
|
||||
}
|
||||
return len(dAtA) - i, nil
|
||||
}
|
||||
|
||||
func encodeVarintBase(dAtA []byte, offset int, v uint64) int {
|
||||
offset -= sovBase(v)
|
||||
base := offset
|
||||
@ -480,8 +636,8 @@ func (m *MsgInit) Size() (n int) {
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = len(m.PubKey)
|
||||
if l > 0 {
|
||||
if m.PubKey != nil {
|
||||
l = m.PubKey.Size()
|
||||
n += 1 + l + sovBase(uint64(l))
|
||||
}
|
||||
return n
|
||||
@ -502,8 +658,8 @@ func (m *MsgSwapPubKey) Size() (n int) {
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
l = len(m.NewPubKey)
|
||||
if l > 0 {
|
||||
if m.NewPubKey != nil {
|
||||
l = m.NewPubKey.Size()
|
||||
n += 1 + l + sovBase(uint64(l))
|
||||
}
|
||||
return n
|
||||
@ -539,6 +695,28 @@ func (m *QuerySequenceResponse) Size() (n int) {
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *QueryPubKey) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
return n
|
||||
}
|
||||
|
||||
func (m *QueryPubKeyResponse) Size() (n int) {
|
||||
if m == nil {
|
||||
return 0
|
||||
}
|
||||
var l int
|
||||
_ = l
|
||||
if m.PubKey != nil {
|
||||
l = m.PubKey.Size()
|
||||
n += 1 + l + sovBase(uint64(l))
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func sovBase(x uint64) (n int) {
|
||||
return (math_bits.Len64(x|1) + 6) / 7
|
||||
}
|
||||
@ -578,7 +756,7 @@ func (m *MsgInit) Unmarshal(dAtA []byte) error {
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field PubKey", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowBase
|
||||
@ -588,24 +766,26 @@ func (m *MsgInit) Unmarshal(dAtA []byte) error {
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthBase
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthBase
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.PubKey = append(m.PubKey[:0], dAtA[iNdEx:postIndex]...)
|
||||
if m.PubKey == nil {
|
||||
m.PubKey = []byte{}
|
||||
m.PubKey = &any.Any{}
|
||||
}
|
||||
if err := m.PubKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
@ -712,7 +892,7 @@ func (m *MsgSwapPubKey) Unmarshal(dAtA []byte) error {
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field NewPubKey", wireType)
|
||||
}
|
||||
var byteLen int
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowBase
|
||||
@ -722,24 +902,26 @@ func (m *MsgSwapPubKey) Unmarshal(dAtA []byte) error {
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
byteLen |= int(b&0x7F) << shift
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if byteLen < 0 {
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthBase
|
||||
}
|
||||
postIndex := iNdEx + byteLen
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthBase
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
m.NewPubKey = append(m.NewPubKey[:0], dAtA[iNdEx:postIndex]...)
|
||||
if m.NewPubKey == nil {
|
||||
m.NewPubKey = []byte{}
|
||||
m.NewPubKey = &any.Any{}
|
||||
}
|
||||
if err := m.NewPubKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
@ -932,6 +1114,142 @@ func (m *QuerySequenceResponse) Unmarshal(dAtA []byte) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *QueryPubKey) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowBase
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: QueryPubKey: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: QueryPubKey: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipBase(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthBase
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (m *QueryPubKeyResponse) Unmarshal(dAtA []byte) error {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
for iNdEx < l {
|
||||
preIndex := iNdEx
|
||||
var wire uint64
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowBase
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
wire |= uint64(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
fieldNum := int32(wire >> 3)
|
||||
wireType := int(wire & 0x7)
|
||||
if wireType == 4 {
|
||||
return fmt.Errorf("proto: QueryPubKeyResponse: wiretype end group for non-group")
|
||||
}
|
||||
if fieldNum <= 0 {
|
||||
return fmt.Errorf("proto: QueryPubKeyResponse: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||
}
|
||||
switch fieldNum {
|
||||
case 1:
|
||||
if wireType != 2 {
|
||||
return fmt.Errorf("proto: wrong wireType = %d for field PubKey", wireType)
|
||||
}
|
||||
var msglen int
|
||||
for shift := uint(0); ; shift += 7 {
|
||||
if shift >= 64 {
|
||||
return ErrIntOverflowBase
|
||||
}
|
||||
if iNdEx >= l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
b := dAtA[iNdEx]
|
||||
iNdEx++
|
||||
msglen |= int(b&0x7F) << shift
|
||||
if b < 0x80 {
|
||||
break
|
||||
}
|
||||
}
|
||||
if msglen < 0 {
|
||||
return ErrInvalidLengthBase
|
||||
}
|
||||
postIndex := iNdEx + msglen
|
||||
if postIndex < 0 {
|
||||
return ErrInvalidLengthBase
|
||||
}
|
||||
if postIndex > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
if m.PubKey == nil {
|
||||
m.PubKey = &any.Any{}
|
||||
}
|
||||
if err := m.PubKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||
return err
|
||||
}
|
||||
iNdEx = postIndex
|
||||
default:
|
||||
iNdEx = preIndex
|
||||
skippy, err := skipBase(dAtA[iNdEx:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if (skippy < 0) || (iNdEx+skippy) < 0 {
|
||||
return ErrInvalidLengthBase
|
||||
}
|
||||
if (iNdEx + skippy) > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
iNdEx += skippy
|
||||
}
|
||||
}
|
||||
|
||||
if iNdEx > l {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func skipBase(dAtA []byte) (n int, err error) {
|
||||
l := len(dAtA)
|
||||
iNdEx := 0
|
||||
|
||||
@ -64,7 +64,7 @@ func (s directHandler) GetSignBytes(_ context.Context, _ signing.SignerData, _ s
|
||||
|
||||
func ProvideModule(in ModuleInputs) ModuleOutputs {
|
||||
handler := directHandler{}
|
||||
account := baseaccount.NewAccount("base", signing.NewHandlerMap(handler))
|
||||
account := baseaccount.NewAccount("base", signing.NewHandlerMap(handler), baseaccount.WithSecp256K1PubKey())
|
||||
accountskeeper, err := NewKeeper(
|
||||
in.Cdc, in.Environment, in.AddressCodec, in.Registry, account,
|
||||
accountstd.AddAccount(lockup.CONTINUOUS_LOCKING_ACCOUNT, lockup.NewContinuousLockingAccount),
|
||||
|
||||
@ -4,10 +4,12 @@ package cosmos.accounts.defaults.base.v1;
|
||||
|
||||
option go_package = "cosmossdk.io/x/accounts/defaults/base/v1";
|
||||
|
||||
import "google/protobuf/any.proto";
|
||||
|
||||
// MsgInit is used to initialize a base account.
|
||||
message MsgInit {
|
||||
// pub_key defines the secp256k1 pubkey for the account.
|
||||
bytes pub_key = 1;
|
||||
// pub_key defines a pubkey for the account arbitrary encapsulated.
|
||||
google.protobuf.Any pub_key = 1;
|
||||
}
|
||||
|
||||
// MsgInitResponse is the response returned after base account initialization.
|
||||
@ -17,7 +19,7 @@ message MsgInitResponse {}
|
||||
// MsgSwapPubKey is used to change the pubkey for the account.
|
||||
message MsgSwapPubKey {
|
||||
// new_pub_key defines the secp256k1 pubkey to swap the account to.
|
||||
bytes new_pub_key = 1;
|
||||
google.protobuf.Any new_pub_key = 1;
|
||||
}
|
||||
|
||||
// MsgSwapPubKeyResponse is the response for the MsgSwapPubKey message.
|
||||
@ -32,3 +34,11 @@ message QuerySequenceResponse {
|
||||
// sequence is the current sequence of the account.
|
||||
uint64 sequence = 1;
|
||||
}
|
||||
|
||||
// QueryPubKey is the request used to query the pubkey of an account.
|
||||
message QueryPubKey {}
|
||||
|
||||
// QueryPubKeyResponse is the response returned when a QueryPubKey message is sent.
|
||||
message QueryPubKeyResponse {
|
||||
google.protobuf.Any pub_key = 1;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user