diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index f89456d..0242509 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -100,7 +100,7 @@ import ( "github.com/terpnetwork/terp-core/v5/x/smart-account/authenticator" smartaccountkeeper "github.com/terpnetwork/terp-core/v5/x/smart-account/keeper" - smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types" + sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types" // cwhookskeeper "github.com/terpnetwork/terp-core/v5/x/cw-hooks/keeper" // cwhookstypes "github.com/terpnetwork/terp-core/v5/x/cw-hooks/types" @@ -277,8 +277,8 @@ func NewAppKeepers( smartAccountKeeper := smartaccountkeeper.NewKeeper( appCodec, - appKeepers.keys[smartaccounttypes.StoreKey], - authtypes.NewModuleAddress(govtypes.ModuleName), appKeepers.GetSubspace(smartaccounttypes.ModuleName), + appKeepers.keys[sat.StoreKey], + authtypes.NewModuleAddress(govtypes.ModuleName), appKeepers.GetSubspace(sat.ModuleName), appKeepers.AuthenticatorManager, *appKeepers.FeeGrantKeeper, ) @@ -643,7 +643,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(globalfee.ModuleName) paramsKeeper.Subspace(ibchookstypes.ModuleName) paramsKeeper.Subspace(feesharetypes.ModuleName).WithKeyTable(feesharetypes.ParamKeyTable()) - paramsKeeper.Subspace(smartaccounttypes.ModuleName).WithKeyTable(smartaccounttypes.ParamKeyTable()) + paramsKeeper.Subspace(sat.ModuleName).WithKeyTable(sat.ParamKeyTable()) paramsKeeper.Subspace(wasmtypes.ModuleName) return paramsKeeper diff --git a/app/keepers/keys.go b/app/keepers/keys.go index 4bdd675..8c9e829 100644 --- a/app/keepers/keys.go +++ b/app/keepers/keys.go @@ -32,7 +32,7 @@ import ( ibchookstypes "github.com/cosmos/ibc-apps/modules/ibc-hooks/v10/types" ibcexported "github.com/cosmos/ibc-go/v10/modules/core/exported" - smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types" + sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types" // cwhookstypes "github.com/terpnetwork/terp-core/v5/x/cw-hooks/types" driptypes "github.com/terpnetwork/terp-core/v5/x/drip/types" @@ -68,7 +68,7 @@ func (appKeepers *AppKeepers) GenerateKeys() { feesharetypes.StoreKey, globalfeetypes.StoreKey, driptypes.StoreKey, - smartaccounttypes.StoreKey, + sat.StoreKey, tokenfactorytypes.StoreKey, ) diff --git a/app/modules.go b/app/modules.go index 428409b..b35e48d 100644 --- a/app/modules.go +++ b/app/modules.go @@ -71,7 +71,7 @@ import ( tokenfactorytypes "github.com/terpnetwork/terp-core/v5/x/tokenfactory/types" smartaccount "github.com/terpnetwork/terp-core/v5/x/smart-account" - smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types" + sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types" groupmodule "github.com/cosmos/cosmos-sdk/x/group/module" ) @@ -212,7 +212,7 @@ func orderEndBlockers() []string { globalfee.ModuleName, ibchookstypes.ModuleName, tokenfactorytypes.ModuleName, - smartaccounttypes.ModuleName, + sat.ModuleName, // cwhooks.ModuleName, wasmtypes.ModuleName, } @@ -236,7 +236,7 @@ func orderInitBlockers() []string { packetforwardtypes.ModuleName, ibchookstypes.ModuleName, tokenfactorytypes.ModuleName, - smartaccounttypes.ModuleName, + sat.ModuleName, // cwhooks.ModuleName, wasmtypes.ModuleName, } diff --git a/app/upgrades/v5/constants.go b/app/upgrades/v5/constants.go index c5b3283..91800b0 100644 --- a/app/upgrades/v5/constants.go +++ b/app/upgrades/v5/constants.go @@ -5,7 +5,7 @@ import ( circuittypes "cosmossdk.io/x/circuit/types" wasmlctypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/v10/types" "github.com/terpnetwork/terp-core/v5/app/upgrades" - smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types" + sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types" ) const UpgradeName = "v5" @@ -16,7 +16,7 @@ var Upgrade = upgrades.Upgrade{ StoreUpgrades: store.StoreUpgrades{ Added: []string{ circuittypes.ModuleName, - smartaccounttypes.ModuleName, + sat.ModuleName, wasmlctypes.StoreKey, }, Deleted: []string{ diff --git a/proto/buf.lock b/proto/buf.lock index 4597686..4eb8f48 100644 --- a/proto/buf.lock +++ b/proto/buf.lock @@ -19,5 +19,5 @@ deps: - remote: buf.build owner: googleapis repository: googleapis - commit: 61b203b9a9164be9a834f58c37be6f62 - digest: shake256:e619113001d6e284ee8a92b1561e5d4ea89a47b28bf0410815cb2fa23914df8be9f1a6a98dcf069f5bc2d829a2cfb1ac614863be45cd4f8a5ad8606c5f200224 + commit: 72c8614f3bd0466ea67931ef2c43d608 + digest: shake256:b3ac4d383db09f92ab0ca85d12bff8c49eddf7031bd3a854c260b6ac4ed6a2bb85b52b3393c316d28f8038bf3b8e70cb3d16470e8cc4423007678fb6d89d36d4 diff --git a/proto/terp/smartaccount/v1beta1/tx.proto b/proto/terp/smartaccount/v1beta1/tx.proto index 9223bbc..06d676c 100644 --- a/proto/terp/smartaccount/v1beta1/tx.proto +++ b/proto/terp/smartaccount/v1beta1/tx.proto @@ -7,6 +7,7 @@ import "gogoproto/gogo.proto"; option go_package = "github.com/terpnetwork/terp-core/x/smart-account/types"; + // Msg defines the Msg service. service Msg { option (cosmos.msg.v1.service) = true; @@ -28,7 +29,27 @@ message MsgAddAuthenticator { string sender = 1; string authenticator_type = 2; - bytes data = 3; + // data is the initialization data for the authenticator. + // It must be set to exactly one of the following. + AuthenticatorConfig config = 3; +} + + +// AuthenticatorData represents initialization data that can be passed as raw JSON or JSON string. +message AuthenticatorConfig { + oneof data { + // value_string contains JSON as a string (e.g., "{\"threshold\":\"2\"}") + string value_string = 1; + + // value_raw contains raw binary JSON (e.g., {"threshold":"2"}) + bytes value_raw = 2; + } +} + + +message SubAuthenticatorInitData { + string type = 1; + AuthenticatorConfig config = 2; } // MsgAddAuthenticatorResponse defines the Msg/AddAuthenticator response type. diff --git a/scripts/makefiles/build.mk b/scripts/makefiles/build.mk index 9f6a060..54a800f 100644 --- a/scripts/makefiles/build.mk +++ b/scripts/makefiles/build.mk @@ -59,6 +59,7 @@ build-dev-build: # to get a statically linked binary with CosmWasm build-reproducible: build-reproducible-amd64 build-reproducible-arm64 + sh scripts/release/prep-release.sh build-reproducible-amd64: go.sum mkdir -p $(BUILDDIR) @@ -75,7 +76,7 @@ build-reproducible-amd64: go.sum -f Dockerfile . $(DOCKER) rm -f terpbinary || true $(DOCKER) create -ti --name terpbinary terp-core:local-amd64 - $(DOCKER) cp terpbinary:/usr/bin/terpd $(BUILDDIR)/terpd-linux-amd64 + $(DOCKER) cp terpbinary:/usr/local/bin/terpd $(BUILDDIR)/terpd-linux-amd64 $(DOCKER) rm -f terpbinary build-reproducible-arm64: go.sum @@ -93,6 +94,6 @@ build-reproducible-arm64: go.sum -f Dockerfile . $(DOCKER) rm -f terpbinary || true $(DOCKER) create -ti --name terpbinary terp-core:local-arm64 - $(DOCKER) cp terpbinary:/usr/bin/terpd $(BUILDDIR)/terpd-linux-arm64 + $(DOCKER) cp terpbinary:/usr/local/bin/terpd $(BUILDDIR)/terpd-linux-arm64 $(DOCKER) rm -f terpbinary diff --git a/scripts/release/prep-release.sh b/scripts/release/prep-release.sh new file mode 100644 index 0000000..860d2f7 --- /dev/null +++ b/scripts/release/prep-release.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +# 1. Build reproducible images +# echo "Building reproducible images..." +# make build-reproducible + +# 2. Create tar.gz files of binaries +echo "Creating tar.gz files of binaries..." +tar -czvf build/terpd-linux-amd64.tar.gz build/terpd-linux-amd64 +tar -czvf build/terpd-linux-arm64.tar.gz build/terpd-linux-arm64 + +# 3. Calculate sha256sum for all images into checksum.txt in ./build +echo "Calculating sha256sum for all images..." + +sha256sum build/terpd-linux-amd64 > build/checksum.txt +sha256sum build/terpd-linux-arm64 >> build/checksum.txt +sha256sum build/terpd-linux-amd64.tar.gz >> build/checksum.txt +sha256sum build/terpd-linux-arm64.tar.gz >> build/checksum.txt + +echo "SHA256 checksums have been saved to build/checksum.txt." \ No newline at end of file diff --git a/tests/ibctesting/chain.go b/tests/ibctesting/chain.go index 9c72615..e5569de 100644 --- a/tests/ibctesting/chain.go +++ b/tests/ibctesting/chain.go @@ -26,7 +26,7 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" - smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types" + sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types" ) const SimAppChainID = "simulation-app" @@ -386,7 +386,7 @@ func SignAuthenticatorMsg( return nil, fmt.Errorf("expected authtx.ExtensionOptionsTxBuilder, got %T", baseTxBuilder) } if len(selectedAuthenticators) > 0 { - value, err := types.NewAnyWithValue(&smartaccounttypes.TxExtension{ + value, err := types.NewAnyWithValue(&sat.TxExtension{ SelectedAuthenticators: selectedAuthenticators, }) if err != nil { @@ -603,7 +603,7 @@ func SignAuthenticatorMsgWithCompoundSigs( return nil, fmt.Errorf("expected authtx.ExtensionOptionsTxBuilder, got %T", baseTxBuilder) } if len(selectedAuthenticators) > 0 { - value, err := types.NewAnyWithValue(&smartaccounttypes.TxExtension{ + value, err := types.NewAnyWithValue(&sat.TxExtension{ SelectedAuthenticators: selectedAuthenticators, }) if err != nil { diff --git a/x/smart-account/ante/ante_test.go b/x/smart-account/ante/ante_test.go index d398aa1..ccaab8b 100644 --- a/x/smart-account/ante/ante_test.go +++ b/x/smart-account/ante/ante_test.go @@ -15,7 +15,7 @@ import ( sdkante "github.com/cosmos/cosmos-sdk/x/auth/ante" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" - smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types" + sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" "github.com/cosmos/cosmos-sdk/client" @@ -459,7 +459,7 @@ func GenTx( return nil, fmt.Errorf("expected authtx.ExtensionOptionsTxBuilder, got %T", baseTxBuilder) } if len(selectedAuthenticators) > 0 { - value, err := types.NewAnyWithValue(&smartaccounttypes.TxExtension{ + value, err := types.NewAnyWithValue(&sat.TxExtension{ SelectedAuthenticators: selectedAuthenticators, }) if err != nil { diff --git a/x/smart-account/ante/circuit_breaker.go b/x/smart-account/ante/circuit_breaker.go index 38d7f50..6e19ba5 100644 --- a/x/smart-account/ante/circuit_breaker.go +++ b/x/smart-account/ante/circuit_breaker.go @@ -6,7 +6,7 @@ import ( authante "github.com/cosmos/cosmos-sdk/x/auth/ante" smartaccountkeeper "github.com/terpnetwork/terp-core/v5/x/smart-account/keeper" - smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types" + sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types" ) // CircuitBreakerDecorator routes transactions through appropriate ante handlers based on @@ -53,7 +53,7 @@ func IsCircuitBreakActive( ctx sdk.Context, tx sdk.Tx, smartAccountKeeper *smartaccountkeeper.Keeper, -) (bool, smartaccounttypes.AuthenticatorTxOptions) { +) (bool, sat.AuthenticatorTxOptions) { isSmartAccountActive := smartAccountKeeper.GetIsSmartAccountActive(ctx) // If the smart accounts are not active, the circuit breaker activates (i.e. return true). if !isSmartAccountActive { @@ -69,7 +69,7 @@ func IsCircuitBreakActive( func IsSelectedAuthenticatorTxExtensionMissing( tx sdk.Tx, smartAccountKeeper *smartaccountkeeper.Keeper, -) (bool, smartaccounttypes.AuthenticatorTxOptions) { +) (bool, sat.AuthenticatorTxOptions) { extTx, ok := tx.(authante.HasExtensionOptionsTx) if !ok { return true, nil diff --git a/x/smart-account/ante/pubkey.go b/x/smart-account/ante/pubkey.go index aed0d00..6f8fd80 100644 --- a/x/smart-account/ante/pubkey.go +++ b/x/smart-account/ante/pubkey.go @@ -11,7 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx/signing" authante "github.com/cosmos/cosmos-sdk/x/auth/ante" authsigning "github.com/cosmos/cosmos-sdk/x/auth/signing" - smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types" + sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types" ) // EmitPubKeyDecoratorEvents emits the events that the SetPubKeyDecorator would emit. This is needed for backwards @@ -51,7 +51,7 @@ func (spkd EmitPubKeyDecoratorEvents) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim for i, sig := range sigs { events = append(events, sdk.NewEvent(sdk.EventTypeTx, sdk.NewAttribute(sdk.AttributeKeyAccountSequence, fmt.Sprintf("%s/%d", signers[i], sig.Sequence)), - sdk.NewAttribute(smartaccounttypes.AttributeKeyAccountSequenceAuthenticator, fmt.Sprintf("%s/%d", signers[i], sig.Sequence)), + sdk.NewAttribute(sat.AttributeKeyAccountSequenceAuthenticator, fmt.Sprintf("%s/%d", signers[i], sig.Sequence)), )) sigBzs, err := signatureDataToBz(sig.Data) @@ -61,7 +61,7 @@ func (spkd EmitPubKeyDecoratorEvents) AnteHandle(ctx sdk.Context, tx sdk.Tx, sim for _, sigBz := range sigBzs { events = append(events, sdk.NewEvent(sdk.EventTypeTx, sdk.NewAttribute(sdk.AttributeKeySignature, base64.StdEncoding.EncodeToString(sigBz)), - sdk.NewAttribute(smartaccounttypes.AttributeKeySignatureAuthenticator, base64.StdEncoding.EncodeToString(sigBz)), + sdk.NewAttribute(sat.AttributeKeySignatureAuthenticator, base64.StdEncoding.EncodeToString(sigBz)), )) } } diff --git a/x/smart-account/authenticator/all_of.go b/x/smart-account/authenticator/all_of.go index 64c38fb..ed833e4 100644 --- a/x/smart-account/authenticator/all_of.go +++ b/x/smart-account/authenticator/all_of.go @@ -6,6 +6,7 @@ import ( errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types" ) type AllOf struct { @@ -48,26 +49,40 @@ func (aoa AllOf) StaticGas() uint64 { } func (aoa AllOf) Initialize(config []byte) (Authenticator, error) { - var initDatas []SubAuthenticatorInitData - if err := json.Unmarshal(config, &initDatas); err != nil { - return nil, errorsmod.Wrap(err, "failed to parse sub-authenticators initialization data") + // Decode the initialization data for each sub-authenticator + var count int + var items []subAuthDataJSON + if err := json.Unmarshal(config, &items); err != nil { + return nil, errorsmod.Wrapf(err, "failed to parse top-level JSON") } - if len(initDatas) <= 1 { - return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "allOf must have at least 2 sub-authenticators") - } + for _, item := range items { + var config sat.AuthenticatorConfig + if err := UnmarshalAuthConfig(item.Config, &config); err != nil { + return nil, errorsmod.Wrap(err, "failed to unmarshal AuthenticatorConfig from JSON") + } + count++ + + authenticatorCode := aoa.am.GetAuthenticatorByType(item.Type) + raw := config.GetValueRaw() + // transform data into bytes dependent on its type + if len(raw) == 0 { + raw = []byte(config.GetValueString()) + } - for _, initData := range initDatas { - authenticatorCode := aoa.am.GetAuthenticatorByType(initData.Type) - instance, err := authenticatorCode.Initialize(initData.Config) + instance, err := authenticatorCode.Initialize(raw) if err != nil { - return nil, errorsmod.Wrapf(err, "failed to initialize sub-authenticator (type = %s)", initData.Type) + return nil, errorsmod.Wrapf(err, "failed to initialize sub-authenticator (type = %s)", item.Type) } aoa.SubAuthenticators = append(aoa.SubAuthenticators, instance) } + if count <= 1 { + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "allOf must have at least 2 sub-authenticators") + } + // If not all sub-authenticators are registered, return an error - if len(aoa.SubAuthenticators) != len(initDatas) { + if len(aoa.SubAuthenticators) != count { return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "failed to initialize all sub-authenticators") } diff --git a/x/smart-account/authenticator/any_of.go b/x/smart-account/authenticator/any_of.go index 1ae3a82..67e1c73 100644 --- a/x/smart-account/authenticator/any_of.go +++ b/x/smart-account/authenticator/any_of.go @@ -9,6 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types" ) type SignatureAssignment string @@ -59,28 +60,39 @@ func (aoa AnyOf) StaticGas() uint64 { func (aoa AnyOf) Initialize(config []byte) (Authenticator, error) { // Decode the initialization data for each sub-authenticator - var initDatas []SubAuthenticatorInitData - if err := json.Unmarshal(config, &initDatas); err != nil { - return nil, errorsmod.Wrap(err, "failed to parse sub-authenticators initialization data") + var count int + var items []subAuthDataJSON + if err := json.Unmarshal(config, &items); err != nil { + return nil, errorsmod.Wrapf(err, "any_of.Initialize: failed to parse top-level JSON") } - if len(initDatas) <= 1 { - return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "anyOf must have at least 2 sub-authenticators") - } - - // Call Initialize on each sub-authenticator with its appropriate data using AuthenticatorManager - for _, initData := range initDatas { - authenticatorCode := aoa.am.GetAuthenticatorByType(initData.Type) - instance, err := authenticatorCode.Initialize(initData.Config) + for _, item := range items { + var config sat.AuthenticatorConfig + if err := UnmarshalAuthConfig(item.Config, &config); err != nil { + return nil, errorsmod.Wrap(err, "any_of.Initialize: failed to unmarshal AuthenticatorConfig from JSON,index") + } + authenticatorCode := aoa.am.GetAuthenticatorByType(item.Type) + // transform data into bytes dependent on its type: + raw := config.GetValueRaw() + if len(raw) == 0 { + raw = []byte(config.GetValueString()) + } + // Call Initialize on sub-authenticator with its appropriate data using AuthenticatorManager + instance, err := authenticatorCode.Initialize(raw) if err != nil { - return nil, errorsmod.Wrapf(err, "failed to initialize sub-authenticator (type = %s)", initData.Type) + return nil, errorsmod.Wrapf(err, "any_of.Initialize: failed to initialize sub-authenticator (type = %s)", item.Type) } aoa.SubAuthenticators = append(aoa.SubAuthenticators, instance) + count++ + } + + if count <= 1 { + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "anyOf must have at least 2 sub-authenticators") } // If not all sub-authenticators are registered, return an error - if len(aoa.SubAuthenticators) != len(initDatas) { - return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "failed to initialize all sub-authenticators") + if len(aoa.SubAuthenticators) != count { + return nil, errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "any_of.Initialize: failed to initialize all sub-authenticators") } return aoa, nil diff --git a/x/smart-account/authenticator/base_test.go b/x/smart-account/authenticator/base_test.go index f354f51..c0943d4 100644 --- a/x/smart-account/authenticator/base_test.go +++ b/x/smart-account/authenticator/base_test.go @@ -19,10 +19,9 @@ import ( "github.com/terpnetwork/terp-core/v5/x/smart-account/authenticator" - smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types" + sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types" "github.com/terpnetwork/terp-core/v5/app" - "github.com/terpnetwork/terp-core/v5/app/params" appparams "github.com/terpnetwork/terp-core/v5/app/params" ) @@ -30,7 +29,7 @@ type BaseAuthenticatorSuite struct { suite.Suite TerpApp *app.TerpApp Ctx sdk.Context - EncodingConfig params.EncodingConfig + EncodingConfig appparams.EncodingConfig SigVerificationAuthenticator authenticator.SignatureVerification TestKeys []string TestAccAddress []sdk.AccAddress @@ -139,7 +138,7 @@ func (s *BaseAuthenticatorSuite) GenSimpleTxWithSelectedAuthenticators(msgs []sd return nil, fmt.Errorf("expected authtx.ExtensionOptionsTxBuilder, got %T", baseTxBuilder) } if len(selectedAuthenticators) > 0 { - value, err := types.NewAnyWithValue(&smartaccounttypes.TxExtension{ + value, err := types.NewAnyWithValue(&sat.TxExtension{ SelectedAuthenticators: selectedAuthenticators, }) if err != nil { diff --git a/x/smart-account/authenticator/composite.go b/x/smart-account/authenticator/composite.go index c1346e0..00feb30 100644 --- a/x/smart-account/authenticator/composite.go +++ b/x/smart-account/authenticator/composite.go @@ -1,17 +1,35 @@ package authenticator import ( + "encoding/base64" "encoding/json" + "fmt" "strconv" errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types" ) -type SubAuthenticatorInitData struct { - Type string `json:"type"` - Config []byte `json:"config"` +// Custom struct that matches the JSON shape +type subAuthDataJSON struct { + Type string `json:"type"` + Config authenticatorConfigJSON `json:"config"` +} + +// authenticatorConfigJSON mirrors the JSON shape of sat.AuthenticatorConfig +// It handles both top-level and Data-wrapped oneof cases +type authenticatorConfigJSON struct { + // Support for direct oneof fields + ValueString *string `json:"value_string,omitempty"` + ValueRaw *string `json:"value_raw,omitempty"` + + // Support for wrapped case: { "Data": { "value_string": ... } } + Data *struct { + ValueString *string `json:"value_string,omitempty"` + ValueRaw *string `json:"value_raw,omitempty"` + } `json:"Data,omitempty"` } func subTrack( @@ -43,9 +61,28 @@ func splitSignatures(signature []byte, total int) ([][]byte, error) { } func onSubAuthenticatorsAdded(ctx sdk.Context, account sdk.AccAddress, data []byte, authenticatorId string, am *AuthenticatorManager) error { - var initDatas []SubAuthenticatorInitData - if err := json.Unmarshal(data, &initDatas); err != nil { - return errorsmod.Wrapf(err, "failed to unmarshal sub-authenticator init data") + + // First: unmarshal into raw parts + var items []subAuthDataJSON + if err := json.Unmarshal(data, &items); err != nil { + return errorsmod.Wrapf(err, "failed to parse top-level JSON") + } + // Now convert each item + var initDatas []sat.SubAuthenticatorInitData + for _, item := range items { + var config sat.AuthenticatorConfig + + // ------------------------------------------------- + // ★ NEW: custom one‑of JSON → protobuf mapper + // ------------------------------------------------- + if err := UnmarshalAuthConfig(item.Config, &config); err != nil { + return errorsmod.Wrap(err, "failed to unmarshal AuthenticatorConfig from JSON") + } + + initDatas = append(initDatas, sat.SubAuthenticatorInitData{ + Type: item.Type, + Config: &config, + }) } if len(initDatas) <= 1 { @@ -60,7 +97,17 @@ func onSubAuthenticatorsAdded(ctx sdk.Context, account sdk.AccAddress, data []by return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "sub-authenticator failed to be added in function `OnAuthenticatorAdded` as type is not registered in manager") } subId := compositeId(baseId, id) - err := authenticatorCode.OnAuthenticatorAdded(ctx, account, initData.Config, subId) + var rawInitData = []byte{} + switch op := initData.Config.Data.(type) { + case *sat.AuthenticatorConfig_ValueRaw: + rawInitData = op.ValueRaw + case *sat.AuthenticatorConfig_ValueString: + rawInitData = []byte(op.ValueString) + default: + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "fatal error initializing allOf authenticator") + } + + err := authenticatorCode.OnAuthenticatorAdded(ctx, account, rawInitData, subId) if err != nil { return errorsmod.Wrapf(err, "sub-authenticator `OnAuthenticatorAdded` failed (sub-authenticator id = %s)", subId) } @@ -77,9 +124,23 @@ func onSubAuthenticatorsAdded(ctx sdk.Context, account sdk.AccAddress, data []by } func onSubAuthenticatorsRemoved(ctx sdk.Context, account sdk.AccAddress, data []byte, authenticatorId string, am *AuthenticatorManager) error { - var initDatas []SubAuthenticatorInitData - if err := json.Unmarshal(data, &initDatas); err != nil { - return err + // First: unmarshal into raw parts + var items []subAuthDataJSON + if err := json.Unmarshal(data, &items); err != nil { + return errorsmod.Wrapf(err, "composite.onSubAuthRemoved: failed to parse top-level JSON") + } + // Now convert each item + var initDatas []sat.SubAuthenticatorInitData + for _, item := range items { + var config sat.AuthenticatorConfig + if err := UnmarshalAuthConfig(item.Config, &config); err != nil { + return errorsmod.Wrap(err, "composite.onSubAuthRemoved: failed to unmarshal AuthenticatorConfig from JSON") + } + + initDatas = append(initDatas, sat.SubAuthenticatorInitData{ + Type: item.Type, + Config: &config, + }) } baseId := authenticatorId @@ -89,7 +150,16 @@ func onSubAuthenticatorsRemoved(ctx sdk.Context, account sdk.AccAddress, data [] return errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "sub-authenticator failed to be removed in function `OnAuthenticatorRemoved` as type is not registered in manager") } subId := compositeId(baseId, id) - err := authenticatorCode.OnAuthenticatorRemoved(ctx, account, initData.Config, subId) + var rawInitData = []byte{} + switch op := initData.Config.Data.(type) { + case *sat.AuthenticatorConfig_ValueRaw: + rawInitData = op.ValueRaw + case *sat.AuthenticatorConfig_ValueString: + rawInitData = []byte(op.ValueString) + default: + return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "fatal error removing allOf authenticator") + } + err := authenticatorCode.OnAuthenticatorRemoved(ctx, account, rawInitData, subId) if err != nil { return errorsmod.Wrapf(err, "sub-authenticator `OnAuthenticatorRemoved` failed (sub-authenticator id = %s)", subId) } @@ -100,3 +170,52 @@ func onSubAuthenticatorsRemoved(ctx sdk.Context, account sdk.AccAddress, data [] func compositeId(baseId string, subId int) string { return baseId + "." + strconv.Itoa(subId) } + +// ------------------------------------------------------------ +// ★ NEW: custom unmarshaller for AuthenticatorConfig (gogo‑proto) +// ------------------------------------------------------------ +// This works with the gogo‑proto generated struct that does **not** +// implement proto.Message. It: +// +// 1. Looks for an optional top‑level “Data” object. +// 2. Inside that (or directly at the top level) checks for the one‑of +// fields “value_string” or “value_raw”. +// 3. For “value_string” we store the string as‑is. +// 4. For “value_raw” we expect a base‑64‑encoded string (the protobuf‑JSON +// encoding) and decode it to []byte before storing it. +// +// If neither one‑of field is present we return an error, which is what +// caused the previous failure you saw. +// +// NOTE: The function only touches the `Data` one‑of; all other generated +// fields on AuthenticatorConfig are left untouched. +func UnmarshalAuthConfig(a authenticatorConfigJSON, dst *sat.AuthenticatorConfig) error { + // Define intermediate struct that mirrors the two possible layouts + // Determine which one-of is set: prefer Data-wrapped, then top-level + var valueString *string + var valueRaw *string + + if a.Data != nil { + valueString = a.Data.ValueString + valueRaw = a.Data.ValueRaw + } else { + valueString = a.ValueString + valueRaw = a.ValueRaw + } + + // Set the one-of field on the destination + switch { + case valueString != nil: + dst.Data = &sat.AuthenticatorConfig_ValueString{ValueString: *valueString} + case valueRaw != nil: + decoded, err := base64.StdEncoding.DecodeString(*valueRaw) + if err != nil { + return fmt.Errorf("value_raw is not valid base64: %w", err) + } + dst.Data = &sat.AuthenticatorConfig_ValueRaw{ValueRaw: decoded} + default: + dst.Data = nil // no data provided — valid state + } + + return nil +} diff --git a/x/smart-account/authenticator/composition_test.go b/x/smart-account/authenticator/composition_test.go index 41d858c..c92b875 100644 --- a/x/smart-account/authenticator/composition_test.go +++ b/x/smart-account/authenticator/composition_test.go @@ -18,7 +18,7 @@ import ( "github.com/terpnetwork/terp-core/v5/x/smart-account/authenticator" "github.com/terpnetwork/terp-core/v5/x/smart-account/testutils" - smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types" + sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types" ) type AggregatedAuthenticatorsTest struct { @@ -65,7 +65,7 @@ func (s *AggregatedAuthenticatorsTest) SetupTest() { Confirm: testutils.Always, } s.spyAuth = testutils.NewSpyAuthenticator( - s.TerpApp.GetKVStoreKey()[smartaccounttypes.StoreKey], + s.TerpApp.GetKVStoreKey()[sat.StoreKey], ) am.RegisterAuthenticator(s.AnyOfAuth) @@ -185,11 +185,11 @@ func (s *AggregatedAuthenticatorsTest) TestAnyOf() { for _, tc := range testCases { s.T().Run(tc.name, func(t *testing.T) { // Convert the authenticators to InitializationData - initData := []authenticator.SubAuthenticatorInitData{} + initData := []sat.SubAuthenticatorInitData{} for _, auth := range tc.authenticators { - initData = append(initData, authenticator.SubAuthenticatorInitData{ + initData = append(initData, sat.SubAuthenticatorInitData{ Type: auth.Type(), - Config: testData, + Config: &sat.AuthenticatorConfig{Data: &sat.AuthenticatorConfig_ValueRaw{ValueRaw: testData}}, }) } @@ -326,11 +326,12 @@ func (s *AggregatedAuthenticatorsTest) TestAllOf() { for _, tc := range testCases { s.T().Run(tc.name, func(t *testing.T) { // Convert the authenticators to InitializationData - initData := []authenticator.SubAuthenticatorInitData{} + fmt.Printf("running test w/ name: = %s\n", tc.name) + initData := []sat.SubAuthenticatorInitData{} for _, auth := range tc.authenticators { - initData = append(initData, authenticator.SubAuthenticatorInitData{ + initData = append(initData, sat.SubAuthenticatorInitData{ Type: auth.Type(), - Config: testData, + Config: &sat.AuthenticatorConfig{Data: &sat.AuthenticatorConfig_ValueRaw{ValueRaw: testData}}, }) } @@ -515,31 +516,31 @@ func (csa *CompositeSpyAuth) buildInitData() ([]byte, error) { } return json.Marshal(spyData) } else if len(csa.anyOf) > 0 { - var initData []authenticator.SubAuthenticatorInitData + var initData []sat.SubAuthenticatorInitData for _, subAuth := range csa.anyOf { data, err := subAuth.buildInitData() if err != nil { return nil, err } - initData = append(initData, authenticator.SubAuthenticatorInitData{ + initData = append(initData, sat.SubAuthenticatorInitData{ Type: subAuth.Type(), - Config: data, + Config: &sat.AuthenticatorConfig{Data: &sat.AuthenticatorConfig_ValueRaw{ValueRaw: data}}, }) } return json.Marshal(initData) } else if len(csa.allOf) > 0 { - var initData []authenticator.SubAuthenticatorInitData + var initData []sat.SubAuthenticatorInitData for _, subAuth := range csa.allOf { data, err := subAuth.buildInitData() if err != nil { return nil, err } - initData = append(initData, authenticator.SubAuthenticatorInitData{ + initData = append(initData, sat.SubAuthenticatorInitData{ Type: subAuth.Type(), - Config: data, + Config: &sat.AuthenticatorConfig{Data: &sat.AuthenticatorConfig_ValueRaw{ValueRaw: data}}, }) } @@ -767,10 +768,12 @@ func (s *AggregatedAuthenticatorsTest) TestAnyOfNotWritingFailedSubAuthState() { s.Require().NoError(err) var auth authenticator.Authenticator + fmt.Printf("running test w/ name: = %s\n", tc.name) if tc.compositeAuth.isAllOf() { auth, err = s.AllOfAuth.Initialize(data) s.Require().NoError(err) } else if tc.compositeAuth.isAnyOf() { + fmt.Printf("initalizing...") auth, err = s.AnyOfAuth.Initialize(data) s.Require().NoError(err) } else { @@ -824,16 +827,16 @@ func (s *AggregatedAuthenticatorsTest) TestAnyOfNotWritingFailedSubAuthState() { } func marshalAuth(ta testAuth, testData []byte) ([]byte, error) { - initData := []authenticator.SubAuthenticatorInitData{} + initData := []sat.SubAuthenticatorInitData{} for _, sub := range ta.subAuths { subData, err := marshalAuth(sub, testData) if err != nil { return nil, err } - initData = append(initData, authenticator.SubAuthenticatorInitData{ + initData = append(initData, sat.SubAuthenticatorInitData{ Type: sub.authenticator.Type(), - Config: subData, + Config: &sat.AuthenticatorConfig{Data: &sat.AuthenticatorConfig_ValueRaw{ValueRaw: subData}}, }) } diff --git a/x/smart-account/authenticator/cosmwasm.go b/x/smart-account/authenticator/cosmwasm.go index 6d1ca9f..bc70a1f 100644 --- a/x/smart-account/authenticator/cosmwasm.go +++ b/x/smart-account/authenticator/cosmwasm.go @@ -4,7 +4,7 @@ import ( "encoding/json" authante "github.com/cosmos/cosmos-sdk/x/auth/ante" - "github.com/terpnetwork/terp-core/v5/x/smart-account/types" + sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types" errorsmod "cosmossdk.io/errors" "github.com/CosmWasm/wasmd/x/wasm/keeper" @@ -14,7 +14,7 @@ import ( ) type CosmwasmAuthenticator struct { - contractKeeper types.ContractKeeper + contractKeeper sat.ContractKeeper ak authante.AccountKeeper cdc codectypes.AnyUnpacker diff --git a/x/smart-account/authenticator/signature_authenticator.go b/x/smart-account/authenticator/signature_authenticator.go index ae1acdc..bfb29be 100644 --- a/x/smart-account/authenticator/signature_authenticator.go +++ b/x/smart-account/authenticator/signature_authenticator.go @@ -1,9 +1,9 @@ package authenticator import ( + "encoding/hex" "fmt" - - authante "github.com/cosmos/cosmos-sdk/x/auth/ante" + "strings" errorsmod "cosmossdk.io/errors" @@ -11,6 +11,7 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + authante "github.com/cosmos/cosmos-sdk/x/auth/ante" ) // Compile time type assertion for the SignatureData using the @@ -43,12 +44,55 @@ func NewSignatureVerification(ak authante.AccountKeeper) SignatureVerification { return SignatureVerification{ak: ak} } -// Initialize sets up the public key to the data supplied from the account-authenticator configuration +// Initialize sets up the public key from the configuration supplied by the account‑authenticator. +// It now accepts three forms: +// +// 1. Raw 33‑byte secp256k1 pubkey (len == secp256k1.PubKeySize) +// 2. Hex‑encoded string, e.g. "033C6F20200AB3…" +// 3. Cosmos‑SDK string representation, e.g. "PubKeySecp256k1{033C6F20200AB3…}" func (sva SignatureVerification) Initialize(config []byte) (Authenticator, error) { - if len(config) != secp256k1.PubKeySize { - sva.PubKey = nil + // ------------------------------------------------- + // 1️⃣ Fast‑path – already a raw 33‑byte key. + // ------------------------------------------------- + if len(config) == secp256k1.PubKeySize { + sva.PubKey = &secp256k1.PubKey{Key: config} + fmt.Printf("DEBUG: Initialize sva.PubKey (raw) = %x\n", sva.PubKey.Bytes()) + return sva, nil + } + + // ------------------------------------------------- + // 2️⃣ Otherwise treat the payload as a string. + // ------------------------------------------------- + str := strings.TrimSpace(string(config)) + + // Strip the Cosmos‑SDK wrapper if present. + if strings.HasPrefix(str, "PubKeySecp256k1{") && strings.HasSuffix(str, "}") { + str = strings.TrimPrefix(str, "PubKeySecp256k1{") + str = strings.TrimSuffix(str, "}") } - sva.PubKey = &secp256k1.PubKey{Key: config} + + // At this point we expect a plain hex string. + hexStr := str + + // Decode the hex representation into raw bytes. + pubKeyBytes, err := hex.DecodeString(hexStr) + if err != nil { + return nil, fmt.Errorf("invalid secp256k1 public key (not hex): %x, %x", hexStr, err) + } + if len(pubKeyBytes) != secp256k1.PubKeySize { + return nil, fmt.Errorf( + "invalid secp256k1 public key size after decoding, expected %d, got %d (key: %x)", + secp256k1.PubKeySize, + len(pubKeyBytes), + pubKeyBytes, + ) + } + + // ------------------------------------------------- + // 3️⃣ Build the SDK pubkey and store it. + // ------------------------------------------------- + sva.PubKey = &secp256k1.PubKey{Key: pubKeyBytes} + fmt.Printf("DEBUG: Initialize sva.PubKey (decoded) = %x\n", sva.PubKey.Bytes()) return sva, nil } @@ -66,6 +110,7 @@ func (sva SignatureVerification) Authenticate(ctx sdk.Context, request Authentic if sva.PubKey == nil { return errorsmod.Wrap(sdkerrors.ErrInvalidPubKey, "pubkey on not set on account or authenticator") } + fmt.Printf("DEBUG: sva.PubKey: %x\n", sva.PubKey) if !sva.PubKey.VerifySignature(request.SignModeTxData.Direct, request.Signature) { return errorsmod.Wrapf( @@ -88,9 +133,33 @@ func (sva SignatureVerification) ConfirmExecution(ctx sdk.Context, request Authe } func (sva SignatureVerification) OnAuthenticatorAdded(ctx sdk.Context, account sdk.AccAddress, config []byte, authenticatorId string) error { - // We allow users to pass no data or a valid public key for signature verification. - if len(config) != secp256k1.PubKeySize { - return fmt.Errorf("invalid secp256k1 public key size, expected %d, got %d. pubkey: %d", secp256k1.PubKeySize, len(config), config) + if len(config) == secp256k1.PubKeySize { + return nil + } + + str := strings.TrimSpace(string(config)) + // Remove the Cosmos‑SDK wrapper if present: + // PubKeySecp256k1{} + if strings.HasPrefix(str, "PubKeySecp256k1{") && strings.HasSuffix(str, "}") { + str = strings.TrimPrefix(str, "PubKeySecp256k1{") + str = strings.TrimSuffix(str, "}") + } + // Decode hex → bytes. + pubKeyBytes, err := hex.DecodeString(str) + if err != nil { + return fmt.Errorf("invalid secp256k1 public key (not hex): %q, %w", str, err) + } + + // ------------------------------------------------- + // 3️⃣ Validate length (33 bytes == 66 hex chars) + // ------------------------------------------------- + if len(pubKeyBytes) != secp256k1.PubKeySize { + return fmt.Errorf( + "invalid secp256k1 public key size, expected %d, got %d. pubkey (hex) = %s", + secp256k1.PubKeySize, + len(pubKeyBytes), + str, + ) } return nil } diff --git a/x/smart-account/client/cli/tx.go b/x/smart-account/client/cli/tx.go index b04140b..1665e9f 100644 --- a/x/smart-account/client/cli/tx.go +++ b/x/smart-account/client/cli/tx.go @@ -53,16 +53,18 @@ func BuildAddAuthenticatorMsg( flags *pflag.FlagSet, ) (sdk.Msg, error) { authenticatorType := args[0] - pubKeyEncoded := args[1] + authenticatorConfig := args[1] - pubKeyBytes, err := base64.StdEncoding.DecodeString(pubKeyEncoded) + authStringBytes, err := base64.StdEncoding.DecodeString(authenticatorConfig) if err != nil { return nil, err } return &types.MsgAddAuthenticator{ AuthenticatorType: authenticatorType, - Data: pubKeyBytes, - Sender: clientCtx.GetFromAddress().String(), + Config: &types.AuthenticatorConfig{ + Data: &types.AuthenticatorConfig_ValueRaw{ValueRaw: authStringBytes}, + }, + Sender: clientCtx.GetFromAddress().String(), }, nil } diff --git a/x/smart-account/integration_test.go b/x/smart-account/integration_test.go index 91f0143..fd3d2b4 100644 --- a/x/smart-account/integration_test.go +++ b/x/smart-account/integration_test.go @@ -1,5 +1,6 @@ package authenticator_test +// TODO: AnyOfAuthenticator OnAuthenticator Removed Test import ( "encoding/json" "fmt" @@ -11,7 +12,7 @@ import ( moduletestutils "github.com/terpnetwork/terp-core/v5/x/smart-account/testutils" "github.com/terpnetwork/terp-core/v5/app" - smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types" + sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types" "github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1" cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" @@ -33,7 +34,6 @@ type AuthenticatorSuite struct { coordinator *ibctesting.Coordinator chainA *terpibctesting.TestChain - app *app.TerpApp EncodingConfig params.EncodingConfig PrivKeys []cryptotypes.PrivKey @@ -275,7 +275,7 @@ func (s *AuthenticatorSuite) TestAuthenticatorState() { Amount: sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 1_000_000_000_000)), } - stateful := moduletestutils.StatefulAuthenticator{KvStoreKey: s.App.GetKVStoreKey()[smartaccounttypes.StoreKey]} + stateful := moduletestutils.StatefulAuthenticator{KvStoreKey: s.App.GetKVStoreKey()[sat.StoreKey]} s.App.AuthenticatorManager.RegisterAuthenticator(stateful) _, err := s.App.SmartAccountKeeper.AddAuthenticator(s.chainA.GetContext(), s.Account.GetAddress(), "Stateful", []byte{}) s.Require().NoError(err, "Failed to add authenticator") @@ -301,7 +301,7 @@ func (s *AuthenticatorSuite) TestAuthenticatorMultiMsg() { Amount: sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 1_000)), } - storeKey := s.App.GetKVStoreKey()[smartaccounttypes.StoreKey] + storeKey := s.App.GetKVStoreKey()[sat.StoreKey] maxAmount := moduletestutils.MaxAmountAuthenticator{KvStoreKey: storeKey} stateful := moduletestutils.StatefulAuthenticator{KvStoreKey: storeKey} @@ -407,20 +407,21 @@ func (s *AuthenticatorSuite) TestCompositeAuthenticatorAnyOf() { anyOf := authenticator.NewAnyOf(s.App.AuthenticatorManager) // construct SubAuthenticatorInitData for each SigVerificationAuthenticator - initDataPrivKey1 := authenticator.SubAuthenticatorInitData{ + initDataPrivKey1 := sat.SubAuthenticatorInitData{ Type: "SignatureVerification", - Config: s.PrivKeys[1].PubKey().Bytes(), + Config: &sat.AuthenticatorConfig{Data: &sat.AuthenticatorConfig_ValueRaw{ValueRaw: s.PrivKeys[1].PubKey().Bytes()}}, } - initDataPrivKey2 := authenticator.SubAuthenticatorInitData{ + initDataPrivKey2 := sat.SubAuthenticatorInitData{ Type: "SignatureVerification", - Config: s.PrivKeys[2].PubKey().Bytes(), + Config: &sat.AuthenticatorConfig{Data: &sat.AuthenticatorConfig_ValueString{ValueString: s.PrivKeys[2].PubKey().String()}}, } // 3. Serialize SigVerificationAuthenticator SubAuthenticatorInitData - compositeData, err := json.Marshal([]authenticator.SubAuthenticatorInitData{ + compositeData, err := json.Marshal([]sat.SubAuthenticatorInitData{ initDataPrivKey1, initDataPrivKey2, }) + s.Require().NoError(err) // Set the authenticator to our account _, err = s.App.SmartAccountKeeper.AddAuthenticator(s.chainA.GetContext(), s.Account.GetAddress(), anyOf.Type(), compositeData) @@ -458,21 +459,20 @@ func (s *AuthenticatorSuite) TestCompositeAuthenticatorAllOf() { allOf := authenticator.NewAllOf(s.App.AuthenticatorManager) // set 2nd test suite key sig required for tx - initDataPrivKey1 := authenticator.SubAuthenticatorInitData{ + initDataPrivKey1 := sat.SubAuthenticatorInitData{ Type: "SignatureVerification", - Config: s.PrivKeys[1].PubKey().Bytes(), + Config: &sat.AuthenticatorConfig{Data: &sat.AuthenticatorConfig_ValueString{ValueString: s.PrivKeys[1].PubKey().String()}}, } // set msgfilter data to include for adding an authenticator - initMessageFilter := authenticator.SubAuthenticatorInitData{ + initMessageFilter := sat.SubAuthenticatorInitData{ Type: "MessageFilter", - Config: []byte( - fmt.Sprintf(`{"@type":"/cosmos.bank.v1beta1.MsgSend","amount": [{"denom": "%s", "amount": "50"}]}`, - sdk.DefaultBondDenom, - )), + Config: &sat.AuthenticatorConfig{Data: &sat.AuthenticatorConfig_ValueRaw{ValueRaw: fmt.Appendf(nil, `{"@type":"/cosmos.bank.v1beta1.MsgSend","amount": [{"denom": "%s", "amount": "50"}]}`, + sdk.DefaultBondDenom, + )}}, } - compositeData, err := json.Marshal([]authenticator.SubAuthenticatorInitData{ + compositeData, err := json.Marshal([]sat.SubAuthenticatorInitData{ initDataPrivKey1, initMessageFilter, }) @@ -511,13 +511,13 @@ func (s *AuthenticatorSuite) TestCompositeAuthenticatorAllOf() { err = s.App.SmartAccountKeeper.RemoveAuthenticator(s.chainA.GetContext(), s.Account.GetAddress(), allOfAuthId) s.Require().NoError(err, "Failed to remove authenticator") - initDataPrivKey2 := authenticator.SubAuthenticatorInitData{ + initDataPrivKey2 := sat.SubAuthenticatorInitData{ Type: "SignatureVerification", - Config: s.PrivKeys[2].PubKey().Bytes(), + Config: &sat.AuthenticatorConfig{Data: &sat.AuthenticatorConfig_ValueRaw{ValueRaw: s.PrivKeys[2].PubKey().Bytes()}}, } // Create an AllOf authenticator with 2 signature verification authenticators - compositeData, err = json.Marshal([]authenticator.SubAuthenticatorInitData{ + compositeData, err = json.Marshal([]sat.SubAuthenticatorInitData{ initDataPrivKey1, initDataPrivKey2, }) diff --git a/x/smart-account/keeper/genesis_test.go b/x/smart-account/keeper/genesis_test.go index a63d130..e36b322 100644 --- a/x/smart-account/keeper/genesis_test.go +++ b/x/smart-account/keeper/genesis_test.go @@ -51,7 +51,7 @@ func (s *KeeperTestSuite) TestKeeper_AddAuthenticatorWithId() { 2, ) s.Require().Error(err) - s.Require().ErrorContains(err, "invalid secp256k1 public key size") + s.Require().ErrorContains(err, "invalid secp256k1 public key") // cannot add non-existing authenticator s.App.AuthenticatorManager.ResetAuthenticators() diff --git a/x/smart-account/keeper/msg_server.go b/x/smart-account/keeper/msg_server.go index 79404f1..2828a18 100644 --- a/x/smart-account/keeper/msg_server.go +++ b/x/smart-account/keeper/msg_server.go @@ -41,9 +41,18 @@ func (m msgServer) AddAuthenticator( if err != nil { return nil, errorsmod.Wrap(err, "invalid sender address") } + var rawData = []byte{} + switch op := msg.Config.Data.(type) { + case *types.AuthenticatorConfig_ValueRaw: + rawData = op.ValueRaw + case *types.AuthenticatorConfig_ValueString: + rawData = []byte(op.ValueString) + default: + return nil, errorsmod.Wrap(err, "invalid sender address") + } // Finally, add the authenticator to the store. - id, err := m.Keeper.AddAuthenticator(ctx, sender, msg.AuthenticatorType, msg.Data) + id, err := m.Keeper.AddAuthenticator(ctx, sender, msg.AuthenticatorType, rawData) if err != nil { return nil, err } diff --git a/x/smart-account/keeper/msg_server_test.go b/x/smart-account/keeper/msg_server_test.go index 11caeba..fe37b38 100644 --- a/x/smart-account/keeper/msg_server_test.go +++ b/x/smart-account/keeper/msg_server_test.go @@ -28,7 +28,7 @@ func (s *KeeperTestSuite) TestMsgServer_AddAuthenticator() { msg := &types.MsgAddAuthenticator{ Sender: accAddress.String(), AuthenticatorType: authenticator.SignatureVerification{}.Type(), - Data: priv.PubKey().Bytes(), + Config: &types.AuthenticatorConfig{Data: &types.AuthenticatorConfig_ValueRaw{ValueRaw: priv.PubKey().Bytes()}}, } resp, err := msgServer.AddAuthenticator(ctx, msg) @@ -64,7 +64,7 @@ func (s *KeeperTestSuite) TestMsgServer_AddAuthenticatorFail() { msg := &types.MsgAddAuthenticator{ Sender: accAddress.String(), AuthenticatorType: authenticator.SignatureVerification{}.Type(), - Data: priv.PubKey().Bytes(), + Config: &types.AuthenticatorConfig{Data: &types.AuthenticatorConfig_ValueRaw{ValueRaw: priv.PubKey().Bytes()}}, } msg.AuthenticatorType = "PassKeyAuthenticator" @@ -86,7 +86,7 @@ func (s *KeeperTestSuite) TestMsgServer_RemoveAuthenticator() { addMsg := &types.MsgAddAuthenticator{ Sender: accAddress.String(), AuthenticatorType: authenticator.SignatureVerification{}.Type(), - Data: priv.PubKey().Bytes(), + Config: &types.AuthenticatorConfig{Data: &types.AuthenticatorConfig_ValueRaw{ValueRaw: priv.PubKey().Bytes()}}, } _, err := msgServer.AddAuthenticator(ctx, addMsg) s.Require().NoError(err) @@ -194,7 +194,7 @@ func (s *KeeperTestSuite) TestMsgServer_SmartAccountsNotActive() { msg := &types.MsgAddAuthenticator{ Sender: "", AuthenticatorType: authenticator.SignatureVerification{}.Type(), - Data: []byte(""), + Config: &types.AuthenticatorConfig{Data: &types.AuthenticatorConfig_ValueRaw{ValueRaw: []byte("")}}, } _, err := msgServer.AddAuthenticator(ctx, msg) diff --git a/x/smart-account/post/post_test.go b/x/smart-account/post/post_test.go index 9e6f743..79eb7b8 100644 --- a/x/smart-account/post/post_test.go +++ b/x/smart-account/post/post_test.go @@ -26,7 +26,7 @@ import ( "github.com/terpnetwork/terp-core/v5/app/params" "github.com/terpnetwork/terp-core/v5/x/smart-account/post" "github.com/terpnetwork/terp-core/v5/x/smart-account/testutils" - smartaccounttypes "github.com/terpnetwork/terp-core/v5/x/smart-account/types" + sat "github.com/terpnetwork/terp-core/v5/x/smart-account/types" "github.com/stretchr/testify/suite" ) @@ -250,7 +250,7 @@ func GenTx( return nil, fmt.Errorf("expected authtx.ExtensionOptionsTxBuilder, got %T", baseTxBuilder) } if len(selectedAuthenticators) > 0 { - value, err := types.NewAnyWithValue(&smartaccounttypes.TxExtension{ + value, err := types.NewAnyWithValue(&sat.TxExtension{ SelectedAuthenticators: selectedAuthenticators, }) if err != nil { diff --git a/x/smart-account/types/tx.pb.go b/x/smart-account/types/tx.pb.go index 553f2b6..799b5c0 100644 --- a/x/smart-account/types/tx.pb.go +++ b/x/smart-account/types/tx.pb.go @@ -34,7 +34,9 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type MsgAddAuthenticator struct { Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty"` AuthenticatorType string `protobuf:"bytes,2,opt,name=authenticator_type,json=authenticatorType,proto3" json:"authenticator_type,omitempty"` - Data []byte `protobuf:"bytes,3,opt,name=data,proto3" json:"data,omitempty"` + // data is the initialization data for the authenticator. + // It must be set to exactly one of the following. + Config *AuthenticatorConfig `protobuf:"bytes,3,opt,name=config,proto3" json:"config,omitempty"` } func (m *MsgAddAuthenticator) Reset() { *m = MsgAddAuthenticator{} } @@ -84,13 +86,152 @@ func (m *MsgAddAuthenticator) GetAuthenticatorType() string { return "" } -func (m *MsgAddAuthenticator) GetData() []byte { +func (m *MsgAddAuthenticator) GetConfig() *AuthenticatorConfig { + if m != nil { + return m.Config + } + return nil +} + +// AuthenticatorData represents initialization data that can be passed as raw JSON or JSON string. +type AuthenticatorConfig struct { + // Types that are valid to be assigned to Data: + // + // *AuthenticatorConfig_ValueString + // *AuthenticatorConfig_ValueRaw + Data isAuthenticatorConfig_Data `protobuf_oneof:"data"` +} + +func (m *AuthenticatorConfig) Reset() { *m = AuthenticatorConfig{} } +func (m *AuthenticatorConfig) String() string { return proto.CompactTextString(m) } +func (*AuthenticatorConfig) ProtoMessage() {} +func (*AuthenticatorConfig) Descriptor() ([]byte, []int) { + return fileDescriptor_5ec1eaeaaf4cce55, []int{1} +} +func (m *AuthenticatorConfig) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *AuthenticatorConfig) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_AuthenticatorConfig.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 *AuthenticatorConfig) XXX_Merge(src proto.Message) { + xxx_messageInfo_AuthenticatorConfig.Merge(m, src) +} +func (m *AuthenticatorConfig) XXX_Size() int { + return m.Size() +} +func (m *AuthenticatorConfig) XXX_DiscardUnknown() { + xxx_messageInfo_AuthenticatorConfig.DiscardUnknown(m) +} + +var xxx_messageInfo_AuthenticatorConfig proto.InternalMessageInfo + +type isAuthenticatorConfig_Data interface { + isAuthenticatorConfig_Data() + MarshalTo([]byte) (int, error) + Size() int +} + +type AuthenticatorConfig_ValueString struct { + ValueString string `protobuf:"bytes,1,opt,name=value_string,json=valueString,proto3,oneof" json:"value_string,omitempty"` +} +type AuthenticatorConfig_ValueRaw struct { + ValueRaw []byte `protobuf:"bytes,2,opt,name=value_raw,json=valueRaw,proto3,oneof" json:"value_raw,omitempty"` +} + +func (*AuthenticatorConfig_ValueString) isAuthenticatorConfig_Data() {} +func (*AuthenticatorConfig_ValueRaw) isAuthenticatorConfig_Data() {} + +func (m *AuthenticatorConfig) GetData() isAuthenticatorConfig_Data { if m != nil { return m.Data } return nil } +func (m *AuthenticatorConfig) GetValueString() string { + if x, ok := m.GetData().(*AuthenticatorConfig_ValueString); ok { + return x.ValueString + } + return "" +} + +func (m *AuthenticatorConfig) GetValueRaw() []byte { + if x, ok := m.GetData().(*AuthenticatorConfig_ValueRaw); ok { + return x.ValueRaw + } + return nil +} + +// XXX_OneofWrappers is for the internal use of the proto package. +func (*AuthenticatorConfig) XXX_OneofWrappers() []interface{} { + return []interface{}{ + (*AuthenticatorConfig_ValueString)(nil), + (*AuthenticatorConfig_ValueRaw)(nil), + } +} + +type SubAuthenticatorInitData struct { + Type string `protobuf:"bytes,1,opt,name=type,proto3" json:"type,omitempty"` + Config *AuthenticatorConfig `protobuf:"bytes,2,opt,name=config,proto3" json:"config,omitempty"` +} + +func (m *SubAuthenticatorInitData) Reset() { *m = SubAuthenticatorInitData{} } +func (m *SubAuthenticatorInitData) String() string { return proto.CompactTextString(m) } +func (*SubAuthenticatorInitData) ProtoMessage() {} +func (*SubAuthenticatorInitData) Descriptor() ([]byte, []int) { + return fileDescriptor_5ec1eaeaaf4cce55, []int{2} +} +func (m *SubAuthenticatorInitData) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *SubAuthenticatorInitData) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_SubAuthenticatorInitData.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 *SubAuthenticatorInitData) XXX_Merge(src proto.Message) { + xxx_messageInfo_SubAuthenticatorInitData.Merge(m, src) +} +func (m *SubAuthenticatorInitData) XXX_Size() int { + return m.Size() +} +func (m *SubAuthenticatorInitData) XXX_DiscardUnknown() { + xxx_messageInfo_SubAuthenticatorInitData.DiscardUnknown(m) +} + +var xxx_messageInfo_SubAuthenticatorInitData proto.InternalMessageInfo + +func (m *SubAuthenticatorInitData) GetType() string { + if m != nil { + return m.Type + } + return "" +} + +func (m *SubAuthenticatorInitData) GetConfig() *AuthenticatorConfig { + if m != nil { + return m.Config + } + return nil +} + // MsgAddAuthenticatorResponse defines the Msg/AddAuthenticator response type. type MsgAddAuthenticatorResponse struct { Success bool `protobuf:"varint,1,opt,name=success,proto3" json:"success,omitempty"` @@ -100,7 +241,7 @@ func (m *MsgAddAuthenticatorResponse) Reset() { *m = MsgAddAuthenticator func (m *MsgAddAuthenticatorResponse) String() string { return proto.CompactTextString(m) } func (*MsgAddAuthenticatorResponse) ProtoMessage() {} func (*MsgAddAuthenticatorResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_5ec1eaeaaf4cce55, []int{1} + return fileDescriptor_5ec1eaeaaf4cce55, []int{3} } func (m *MsgAddAuthenticatorResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -147,7 +288,7 @@ func (m *MsgRemoveAuthenticator) Reset() { *m = MsgRemoveAuthenticator{} func (m *MsgRemoveAuthenticator) String() string { return proto.CompactTextString(m) } func (*MsgRemoveAuthenticator) ProtoMessage() {} func (*MsgRemoveAuthenticator) Descriptor() ([]byte, []int) { - return fileDescriptor_5ec1eaeaaf4cce55, []int{2} + return fileDescriptor_5ec1eaeaaf4cce55, []int{4} } func (m *MsgRemoveAuthenticator) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -200,7 +341,7 @@ func (m *MsgRemoveAuthenticatorResponse) Reset() { *m = MsgRemoveAuthent func (m *MsgRemoveAuthenticatorResponse) String() string { return proto.CompactTextString(m) } func (*MsgRemoveAuthenticatorResponse) ProtoMessage() {} func (*MsgRemoveAuthenticatorResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_5ec1eaeaaf4cce55, []int{3} + return fileDescriptor_5ec1eaeaaf4cce55, []int{5} } func (m *MsgRemoveAuthenticatorResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -245,7 +386,7 @@ func (m *MsgSetActiveState) Reset() { *m = MsgSetActiveState{} } func (m *MsgSetActiveState) String() string { return proto.CompactTextString(m) } func (*MsgSetActiveState) ProtoMessage() {} func (*MsgSetActiveState) Descriptor() ([]byte, []int) { - return fileDescriptor_5ec1eaeaaf4cce55, []int{4} + return fileDescriptor_5ec1eaeaaf4cce55, []int{6} } func (m *MsgSetActiveState) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -295,7 +436,7 @@ func (m *MsgSetActiveStateResponse) Reset() { *m = MsgSetActiveStateResp func (m *MsgSetActiveStateResponse) String() string { return proto.CompactTextString(m) } func (*MsgSetActiveStateResponse) ProtoMessage() {} func (*MsgSetActiveStateResponse) Descriptor() ([]byte, []int) { - return fileDescriptor_5ec1eaeaaf4cce55, []int{5} + return fileDescriptor_5ec1eaeaaf4cce55, []int{7} } func (m *MsgSetActiveStateResponse) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -334,7 +475,7 @@ func (m *AgAuthData) Reset() { *m = AgAuthData{} } func (m *AgAuthData) String() string { return proto.CompactTextString(m) } func (*AgAuthData) ProtoMessage() {} func (*AgAuthData) Descriptor() ([]byte, []int) { - return fileDescriptor_5ec1eaeaaf4cce55, []int{6} + return fileDescriptor_5ec1eaeaaf4cce55, []int{8} } func (m *AgAuthData) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -385,7 +526,7 @@ func (m *TxExtension) Reset() { *m = TxExtension{} } func (m *TxExtension) String() string { return proto.CompactTextString(m) } func (*TxExtension) ProtoMessage() {} func (*TxExtension) Descriptor() ([]byte, []int) { - return fileDescriptor_5ec1eaeaaf4cce55, []int{7} + return fileDescriptor_5ec1eaeaaf4cce55, []int{9} } func (m *TxExtension) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -440,7 +581,7 @@ func (m *BlsConfig) Reset() { *m = BlsConfig{} } func (m *BlsConfig) String() string { return proto.CompactTextString(m) } func (*BlsConfig) ProtoMessage() {} func (*BlsConfig) Descriptor() ([]byte, []int) { - return fileDescriptor_5ec1eaeaaf4cce55, []int{8} + return fileDescriptor_5ec1eaeaaf4cce55, []int{10} } func (m *BlsConfig) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -485,6 +626,8 @@ func (m *BlsConfig) GetThreshold() uint64 { func init() { proto.RegisterType((*MsgAddAuthenticator)(nil), "terp.smartaccount.v1beta1.MsgAddAuthenticator") + proto.RegisterType((*AuthenticatorConfig)(nil), "terp.smartaccount.v1beta1.AuthenticatorConfig") + proto.RegisterType((*SubAuthenticatorInitData)(nil), "terp.smartaccount.v1beta1.SubAuthenticatorInitData") proto.RegisterType((*MsgAddAuthenticatorResponse)(nil), "terp.smartaccount.v1beta1.MsgAddAuthenticatorResponse") proto.RegisterType((*MsgRemoveAuthenticator)(nil), "terp.smartaccount.v1beta1.MsgRemoveAuthenticator") proto.RegisterType((*MsgRemoveAuthenticatorResponse)(nil), "terp.smartaccount.v1beta1.MsgRemoveAuthenticatorResponse") @@ -500,45 +643,51 @@ func init() { } var fileDescriptor_5ec1eaeaaf4cce55 = []byte{ - // 604 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x54, 0xcf, 0x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5e, 0xb5, - 0x5c, 0x16, 0xd8, 0x49, 0x81, 0x10, 0xc5, 0x2d, 0x8b, 0xaf, 0xa5, 0x6d, 0xba, 0x2c, 0x46, 0xbb, - 0xd9, 0x57, 0xbc, 0x99, 0x4a, 0x3e, 0x79, 0xb0, 0x78, 0x75, 0x59, 0x3e, 0x7f, 0xc7, 0xff, 0x02, - 0x00, 0x00, 0xff, 0xff, 0x42, 0xa4, 0xcd, 0xf1, 0x81, 0x05, 0x00, 0x00, + // 695 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x55, 0x41, 0x4f, 0xdb, 0x4a, + 0x10, 0x8e, 0x93, 0xbc, 0x90, 0x0c, 0x11, 0x7a, 0x2c, 0x4f, 0x21, 0x84, 0xf7, 0x22, 0x64, 0xf4, + 0x2a, 0x84, 0x9a, 0x58, 0x81, 0x0a, 0xd4, 0x9c, 0x1a, 0x68, 0x2b, 0x7a, 0x88, 0x54, 0x6d, 0x38, + 0xf5, 0x82, 0x36, 0xf6, 0x76, 0x63, 0x91, 0x78, 0x23, 0xef, 0x3a, 0x09, 0x3d, 0x55, 0x6d, 0x0f, + 0x55, 0x4f, 0xfd, 0x29, 0xfc, 0x8c, 0x1e, 0x39, 0xb6, 0xb7, 0x0a, 0x0e, 0xfc, 0x8d, 0xca, 0x6b, + 0x9b, 0xe2, 0xc4, 0x44, 0xa0, 0x5e, 0x92, 0x9d, 0xf1, 0x37, 0x33, 0xdf, 0xcc, 0x7c, 0x5e, 0x83, + 0x2e, 0xa9, 0x3b, 0x34, 0xc4, 0x80, 0xb8, 0x92, 0x98, 0x26, 0xf7, 0x1c, 0x69, 0x8c, 0x1a, 0x5d, + 0x2a, 0x49, 0xc3, 0x90, 0x93, 0xfa, 0xd0, 0xe5, 0x92, 0xa3, 0x35, 0x1f, 0x53, 0xbf, 0x8d, 0xa9, + 0x87, 0x98, 0xca, 0xaa, 0xc9, 0xc5, 0x80, 0x0b, 0x63, 0x20, 0x98, 0x31, 0x6a, 0xf8, 0x7f, 0x41, + 0x4c, 0x65, 0x99, 0x0c, 0x6c, 0x87, 0x1b, 0xea, 0x37, 0x74, 0xfd, 0xc3, 0x38, 0xe3, 0xea, 0x68, + 0xf8, 0xa7, 0xc0, 0xab, 0xff, 0xd0, 0x60, 0xa5, 0x2d, 0x58, 0xcb, 0xb2, 0x5a, 0x9e, 0xec, 0x51, + 0x47, 0xda, 0x26, 0x91, 0xdc, 0x45, 0x25, 0xc8, 0x09, 0xea, 0x58, 0xd4, 0x2d, 0x6b, 0x1b, 0xda, + 0x56, 0x01, 0x87, 0x16, 0xaa, 0x01, 0x22, 0xb7, 0x81, 0x27, 0xf2, 0x6c, 0x48, 0xcb, 0x69, 0x85, + 0x59, 0x8e, 0x3d, 0x39, 0x3e, 0x1b, 0x52, 0xf4, 0x12, 0x72, 0x26, 0x77, 0xde, 0xda, 0xac, 0x9c, + 0xd9, 0xd0, 0xb6, 0x16, 0x77, 0xea, 0xf5, 0x3b, 0x9b, 0xa9, 0xc7, 0x08, 0x1c, 0xaa, 0x28, 0x1c, + 0x46, 0x37, 0x77, 0x3f, 0x5c, 0x9f, 0x6f, 0x87, 0x1c, 0xbe, 0x5c, 0x9f, 0x6f, 0x6f, 0xce, 0xce, + 0x8d, 0x58, 0x56, 0x2d, 0x46, 0x40, 0x27, 0xb0, 0x92, 0x90, 0x13, 0x6d, 0x42, 0x71, 0x44, 0xfa, + 0x1e, 0x3d, 0x11, 0xd2, 0xb5, 0x1d, 0x16, 0x34, 0x78, 0x94, 0xc2, 0x8b, 0xca, 0xdb, 0x51, 0x4e, + 0xf4, 0x1f, 0x14, 0x02, 0x90, 0x4b, 0xc6, 0xaa, 0xbd, 0xe2, 0x51, 0x0a, 0xe7, 0x95, 0x0b, 0x93, + 0xf1, 0x41, 0x0e, 0xb2, 0x16, 0x91, 0x44, 0x1f, 0x41, 0xb9, 0xe3, 0x75, 0x63, 0x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b, 0x2b, 0x00, 0x00, 0xff, 0xff, 0xe6, + 0xb2, 0xbc, 0x9c, 0x90, 0x06, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -718,10 +867,15 @@ func (m *MsgAddAuthenticator) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if len(m.Data) > 0 { - i -= len(m.Data) - copy(dAtA[i:], m.Data) - i = encodeVarintTx(dAtA, i, uint64(len(m.Data))) + if m.Config != nil { + { + size, err := m.Config.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } i-- dAtA[i] = 0x1a } @@ -742,6 +896,110 @@ func (m *MsgAddAuthenticator) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *AuthenticatorConfig) 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 *AuthenticatorConfig) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AuthenticatorConfig) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Data != nil { + { + size := m.Data.Size() + i -= size + if _, err := m.Data.MarshalTo(dAtA[i:]); err != nil { + return 0, err + } + } + } + return len(dAtA) - i, nil +} + +func (m *AuthenticatorConfig_ValueString) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AuthenticatorConfig_ValueString) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + i -= len(m.ValueString) + copy(dAtA[i:], m.ValueString) + i = encodeVarintTx(dAtA, i, uint64(len(m.ValueString))) + i-- + dAtA[i] = 0xa + return len(dAtA) - i, nil +} +func (m *AuthenticatorConfig_ValueRaw) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *AuthenticatorConfig_ValueRaw) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + if m.ValueRaw != nil { + i -= len(m.ValueRaw) + copy(dAtA[i:], m.ValueRaw) + i = encodeVarintTx(dAtA, i, uint64(len(m.ValueRaw))) + i-- + dAtA[i] = 0x12 + } + return len(dAtA) - i, nil +} +func (m *SubAuthenticatorInitData) 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 *SubAuthenticatorInitData) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *SubAuthenticatorInitData) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.Config != nil { + { + size, err := m.Config.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintTx(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + } + if len(m.Type) > 0 { + i -= len(m.Type) + copy(dAtA[i:], m.Type) + i = encodeVarintTx(dAtA, i, uint64(len(m.Type))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func (m *MsgAddAuthenticatorResponse) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -969,20 +1227,20 @@ func (m *TxExtension) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0x12 } if len(m.SelectedAuthenticators) > 0 { - dAtA3 := make([]byte, len(m.SelectedAuthenticators)*10) - var j2 int + dAtA5 := make([]byte, len(m.SelectedAuthenticators)*10) + var j4 int for _, num := range m.SelectedAuthenticators { for num >= 1<<7 { - dAtA3[j2] = uint8(uint64(num)&0x7f | 0x80) + dAtA5[j4] = uint8(uint64(num)&0x7f | 0x80) num >>= 7 - j2++ + j4++ } - dAtA3[j2] = uint8(num) - j2++ + dAtA5[j4] = uint8(num) + j4++ } - i -= j2 - copy(dAtA[i:], dAtA3[:j2]) - i = encodeVarintTx(dAtA, i, uint64(j2)) + i -= j4 + copy(dAtA[i:], dAtA5[:j4]) + i = encodeVarintTx(dAtA, i, uint64(j4)) i-- dAtA[i] = 0xa } @@ -1051,10 +1309,61 @@ func (m *MsgAddAuthenticator) Size() (n int) { if l > 0 { n += 1 + l + sovTx(uint64(l)) } - l = len(m.Data) + if m.Config != nil { + l = m.Config.Size() + n += 1 + l + sovTx(uint64(l)) + } + return n +} + +func (m *AuthenticatorConfig) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Data != nil { + n += m.Data.Size() + } + return n +} + +func (m *AuthenticatorConfig_ValueString) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.ValueString) + n += 1 + l + sovTx(uint64(l)) + return n +} +func (m *AuthenticatorConfig_ValueRaw) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.ValueRaw != nil { + l = len(m.ValueRaw) + n += 1 + l + sovTx(uint64(l)) + } + return n +} +func (m *SubAuthenticatorInitData) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Type) if l > 0 { n += 1 + l + sovTx(uint64(l)) } + if m.Config != nil { + l = m.Config.Size() + n += 1 + l + sovTx(uint64(l)) + } return n } @@ -1275,7 +1584,125 @@ func (m *MsgAddAuthenticator) Unmarshal(dAtA []byte) error { iNdEx = postIndex case 3: if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) + return fmt.Errorf("proto: wrong wireType = %d for field Config", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Config == nil { + m.Config = &AuthenticatorConfig{} + } + if err := m.Config.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *AuthenticatorConfig) 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 ErrIntOverflowTx + } + 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: AuthenticatorConfig: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: AuthenticatorConfig: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValueString", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Data = &AuthenticatorConfig_ValueString{string(dAtA[iNdEx:postIndex])} + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ValueRaw", wireType) } var byteLen int for shift := uint(0); ; shift += 7 { @@ -1302,9 +1729,126 @@ func (m *MsgAddAuthenticator) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} + v := make([]byte, postIndex-iNdEx) + copy(v, dAtA[iNdEx:postIndex]) + m.Data = &AuthenticatorConfig_ValueRaw{v} + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTx(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthTx + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *SubAuthenticatorInitData) 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 ErrIntOverflowTx + } + 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: SubAuthenticatorInitData: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: SubAuthenticatorInitData: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Type", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Type = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Config", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTx + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTx + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthTx + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Config == nil { + m.Config = &AuthenticatorConfig{} + } + if err := m.Config.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err } iNdEx = postIndex default: