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

feat: add ledger signing to smart account module #8581

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#8535](https://github.com/osmosis-labs/osmosis/pull/8535) Prevent Setting Invalid Before Send Hook
* [#8310](https://github.com/osmosis-labs/osmosis/pull/8310) Taker fee share
* [#8494](https://github.com/osmosis-labs/osmosis/pull/8494) Add additional events in x/lockup, x/superfluid, x/concentratedliquidity
* [#8581](https://github.com/osmosis-labs/osmosis/pull/8581) feat: add ledger signing to smart account module
* [#8573](https://github.com/osmosis-labs/osmosis/pull/8573) fix: increase unauthenticated gas to fix fee token issue

### Config
Expand Down
8 changes: 4 additions & 4 deletions proto/osmosis/smartaccount/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ service Msg {

// MsgAddAuthenticatorRequest defines the Msg/AddAuthenticator request type.
message MsgAddAuthenticator {
option (amino.name) = "osmosis/MsgAddAuthenticator";
option (amino.name) = "osmosis/smartaccount/add-authenticator";
option (cosmos.msg.v1.signer) = "sender";

string sender = 1;
string type = 2;
string authenticator_type = 2;
bytes data = 3;
}

Expand All @@ -34,7 +34,7 @@ message MsgAddAuthenticatorResponse { bool success = 1; }
// MsgRemoveAuthenticatorRequest defines the Msg/RemoveAuthenticator request
// type.
message MsgRemoveAuthenticator {
option (amino.name) = "osmosis/MsgRemoveAuthenticator";
option (amino.name) = "osmosis/smartaccount/remove-authenticator";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did we verify name length on this? sometimes ledger can only handle certain lengths

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Selection_063

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

option (cosmos.msg.v1.signer) = "sender";

string sender = 1;
Expand All @@ -46,7 +46,7 @@ message MsgRemoveAuthenticator {
message MsgRemoveAuthenticatorResponse { bool success = 1; }

message MsgSetActiveState {
option (amino.name) = "osmosis/MsgSetActiveState";
option (amino.name) = "osmosis/smartaccount/set-active-state";
option (cosmos.msg.v1.signer) = "sender";

string sender = 1;
Expand Down
6 changes: 3 additions & 3 deletions x/smart-account/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func BuildAddAuthenticatorMsg(
}

return &types.MsgAddAuthenticator{
Type: authenticatorType,
Data: pubKeyBytes,
Sender: clientCtx.GetFromAddress().String(),
AuthenticatorType: authenticatorType,
Data: pubKeyBytes,
Sender: clientCtx.GetFromAddress().String(),
}, nil
}
4 changes: 2 additions & 2 deletions x/smart-account/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (m msgServer) AddAuthenticator(
}

// Finally, add the authenticator to the store.
id, err := m.Keeper.AddAuthenticator(ctx, sender, msg.Type, msg.Data)
id, err := m.Keeper.AddAuthenticator(ctx, sender, msg.AuthenticatorType, msg.Data)
if err != nil {
return nil, err
}
Expand All @@ -53,7 +53,7 @@ func (m msgServer) AddAuthenticator(
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender),
sdk.NewAttribute(types.AttributeKeyAuthenticatorType, msg.Type),
sdk.NewAttribute(types.AttributeKeyAuthenticatorType, msg.AuthenticatorType),
sdk.NewAttribute(types.AttributeKeyAuthenticatorId, strconv.FormatUint(id, 10)),
),
})
Expand Down
28 changes: 14 additions & 14 deletions x/smart-account/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ func (s *KeeperTestSuite) TestMsgServer_AddAuthenticator() {

// Create a test message
msg := &types.MsgAddAuthenticator{
Sender: accAddress.String(),
Type: authenticator.SignatureVerification{}.Type(),
Data: priv.PubKey().Bytes(),
Sender: accAddress.String(),
AuthenticatorType: authenticator.SignatureVerification{}.Type(),
Data: priv.PubKey().Bytes(),
}

resp, err := msgServer.AddAuthenticator(ctx, msg)
Expand All @@ -41,7 +41,7 @@ func (s *KeeperTestSuite) TestMsgServer_AddAuthenticator() {
sdk.EventTypeMessage,
sdk.NewAttribute(sdk.AttributeKeyModule, types.AttributeValueCategory),
sdk.NewAttribute(sdk.AttributeKeySender, msg.Sender),
sdk.NewAttribute(types.AttributeKeyAuthenticatorType, msg.Type),
sdk.NewAttribute(types.AttributeKeyAuthenticatorType, msg.AuthenticatorType),
sdk.NewAttribute(types.AttributeKeyAuthenticatorId, "1"),
),
})
Expand All @@ -62,12 +62,12 @@ func (s *KeeperTestSuite) TestMsgServer_AddAuthenticatorFail() {

// Create a test message
msg := &types.MsgAddAuthenticator{
Sender: accAddress.String(),
Type: authenticator.SignatureVerification{}.Type(),
Data: priv.PubKey().Bytes(),
Sender: accAddress.String(),
AuthenticatorType: authenticator.SignatureVerification{}.Type(),
Data: priv.PubKey().Bytes(),
}

msg.Type = "PassKeyAuthenticator"
msg.AuthenticatorType = "PassKeyAuthenticator"
_, err := msgServer.AddAuthenticator(ctx, msg)
s.Require().Error(err)
}
Expand All @@ -84,9 +84,9 @@ func (s *KeeperTestSuite) TestMsgServer_RemoveAuthenticator() {

// Create a test message
addMsg := &types.MsgAddAuthenticator{
Sender: accAddress.String(),
Type: authenticator.SignatureVerification{}.Type(),
Data: priv.PubKey().Bytes(),
Sender: accAddress.String(),
AuthenticatorType: authenticator.SignatureVerification{}.Type(),
Data: priv.PubKey().Bytes(),
}
_, err := msgServer.AddAuthenticator(ctx, addMsg)
s.Require().NoError(err)
Expand Down Expand Up @@ -192,9 +192,9 @@ func (s *KeeperTestSuite) TestMsgServer_SmartAccountsNotActive() {

// Create a test message
msg := &types.MsgAddAuthenticator{
Sender: "",
Type: authenticator.SignatureVerification{}.Type(),
Data: []byte(""),
Sender: "",
AuthenticatorType: authenticator.SignatureVerification{}.Type(),
Data: []byte(""),
}

_, err := msgServer.AddAuthenticator(ctx, msg)
Expand Down
24 changes: 23 additions & 1 deletion x/smart-account/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

const (
TypeMsgAddAuthenticator = "add_authenticator"
TypeMsgRemoveAuthenticator = "remove_authenticator"
)

// Helper functions
func validateSender(sender string) error {
_, err := sdk.AccAddressFromBech32(sender)
Expand All @@ -23,7 +28,7 @@ func getSender(sender string) []sdk.AccAddress {
return []sdk.AccAddress{addr}
}

// Msgs
// MsgAddAuthenticator
var _ sdk.Msg = &MsgAddAuthenticator{}

func (msg *MsgAddAuthenticator) ValidateBasic() error {
Expand All @@ -34,16 +39,33 @@ func (msg *MsgAddAuthenticator) GetSigners() []sdk.AccAddress {
return getSender(msg.Sender)
}

func (msg MsgAddAuthenticator) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}
func (msg MsgAddAuthenticator) Route() string { return RouterKey }

func (msg MsgAddAuthenticator) Type() string { return TypeMsgAddAuthenticator }

// MsgRemoveAuthenticator
var _ sdk.Msg = &MsgRemoveAuthenticator{}

func (msg *MsgRemoveAuthenticator) ValidateBasic() error {
return validateSender(msg.Sender)
}

func (msg MsgRemoveAuthenticator) GetSignBytes() []byte {
return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg))
}

func (msg MsgRemoveAuthenticator) Route() string { return RouterKey }

func (msg MsgRemoveAuthenticator) Type() string { return TypeMsgRemoveAuthenticator }

func (msg *MsgRemoveAuthenticator) GetSigners() []sdk.AccAddress {
return getSender(msg.Sender)
}

// MsgSetActiveState
var _ sdk.Msg = &MsgSetActiveState{}

func (msg *MsgSetActiveState) ValidateBasic() error {
Expand Down
88 changes: 45 additions & 43 deletions x/smart-account/types/tx.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.