Skip to content

Commit

Permalink
add pubkeys to account
Browse files Browse the repository at this point in the history
  • Loading branch information
testinginprod committed Aug 29, 2024
1 parent 3c5570e commit 803aafa
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,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)
Expand Down
2 changes: 1 addition & 1 deletion x/accounts/defaults/base/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (

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"
"cosmossdk.io/x/accounts/accountstd"
v1 "cosmossdk.io/x/accounts/defaults/base/v1"
aa_interface_v1 "cosmossdk.io/x/accounts/interfaces/account_abstraction/v1"
"cosmossdk.io/x/tx/signing"
dcrd_secp256k1 "github.com/decred/dcrd/dcrec/secp256k1/v4"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
Expand Down
12 changes: 11 additions & 1 deletion x/accounts/defaults/base/pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import (
"strings"

gogoproto "github.com/cosmos/gogoproto/proto"
dcrd_secp256k1 "github.com/decred/dcrd/dcrec/secp256k1/v4"

"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 {
gogoproto.Message
VerifySignature(msg []byte, sig []byte) bool
VerifySignature(msg, sig []byte) bool
}

type PubKeyG[T any] interface {
Expand All @@ -25,6 +28,13 @@ type pubKeyImpl struct {
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
Expand Down
2 changes: 1 addition & 1 deletion x/accounts/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 803aafa

Please sign in to comment.