diff --git a/client/cmd.go b/client/cmd.go index d5e9f86952..63c3116945 100644 --- a/client/cmd.go +++ b/client/cmd.go @@ -250,7 +250,6 @@ func readTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err clientCtx = clientCtx.WithSignModeStr(flags.SignModeLegacyAminoJSON) } } - return clientCtx, nil } diff --git a/client/flags/flags.go b/client/flags/flags.go index 32763cc276..f2a1b5f354 100644 --- a/client/flags/flags.go +++ b/client/flags/flags.go @@ -36,6 +36,8 @@ const ( SignModeDirect = "direct" // SignModeLegacyAminoJSON is the value of the --sign-mode flag for SIGN_MODE_LEGACY_AMINO_JSON SignModeLegacyAminoJSON = "amino-json" + // SignModeEIP191 is the value of the --sign-mode flag for SIGN_MODE_EIP_191 + SignModeEIP191 = "eip-191" ) // List of CLI flags diff --git a/client/tx/factory.go b/client/tx/factory.go index 6cddad4154..9628aa8776 100644 --- a/client/tx/factory.go +++ b/client/tx/factory.go @@ -43,6 +43,8 @@ func NewFactoryCLI(clientCtx client.Context, flagSet *pflag.FlagSet) Factory { signMode = signing.SignMode_SIGN_MODE_DIRECT case flags.SignModeLegacyAminoJSON: signMode = signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON + case flags.SignModeEIP191: + signMode = signing.SignMode_SIGN_MODE_EIP_191 } accNum, _ := flagSet.GetUint64(flags.FlagAccountNumber) diff --git a/proto/cosmos/tx/signing/v1beta1/signing.proto b/proto/cosmos/tx/signing/v1beta1/signing.proto index f7fce76f5b..31eeb220c1 100644 --- a/proto/cosmos/tx/signing/v1beta1/signing.proto +++ b/proto/cosmos/tx/signing/v1beta1/signing.proto @@ -24,6 +24,18 @@ enum SignMode { // SIGN_MODE_LEGACY_AMINO_JSON is a backwards compatibility mode which uses // Amino JSON and will be removed in the future SIGN_MODE_LEGACY_AMINO_JSON = 127; + + // SIGN_MODE_EIP_191 specifies the sign mode for EIP 191 signing on the Cosmos + // SDK. Ref: https://eips.ethereum.org/EIPS/eip-191 + // + // Currently, SIGN_MODE_EIP_191 is registered as a SignMode enum variant, + // but is not implemented on the SDK by default. To enable EIP-191, you need + // to pass a custom `TxConfig` that has an implementation of + // `SignModeHandler` for EIP-191. The SDK may decide to fully support + // EIP-191 in the future. + // + // Since: cosmos-sdk 0.45.2 + SIGN_MODE_EIP_191 = 191; } // SignatureDescriptors wraps multiple SignatureDescriptor's. diff --git a/types/tx/signing/signing.pb.go b/types/tx/signing/signing.pb.go index 5069f11aa8..c31d37c06b 100644 --- a/types/tx/signing/signing.pb.go +++ b/types/tx/signing/signing.pb.go @@ -41,6 +41,11 @@ const ( // SIGN_MODE_LEGACY_AMINO_JSON is a backwards compatibility mode which uses // Amino JSON and will be removed in the future SignMode_SIGN_MODE_LEGACY_AMINO_JSON SignMode = 127 + // SIGN_MODE_EIP_191 specifies the sign mode for EIP 191 signing on the Cosmos + // SDK. Ref: https://eips.ethereum.org/EIPS/eip-191 + // + // Since: cosmos-sdk 0.45 + SignMode_SIGN_MODE_EIP_191 SignMode = 191 ) var SignMode_name = map[int32]string{ @@ -48,6 +53,7 @@ var SignMode_name = map[int32]string{ 1: "SIGN_MODE_DIRECT", 2: "SIGN_MODE_TEXTUAL", 127: "SIGN_MODE_LEGACY_AMINO_JSON", + 191: "SIGN_MODE_EIP_191", } var SignMode_value = map[string]int32{ @@ -55,6 +61,7 @@ var SignMode_value = map[string]int32{ "SIGN_MODE_DIRECT": 1, "SIGN_MODE_TEXTUAL": 2, "SIGN_MODE_LEGACY_AMINO_JSON": 127, + "SIGN_MODE_EIP_191": 191, } func (x SignMode) String() string { diff --git a/x/auth/tx/config.go b/x/auth/tx/config.go index 2329240cf9..934d516978 100644 --- a/x/auth/tx/config.go +++ b/x/auth/tx/config.go @@ -23,9 +23,16 @@ type config struct { // NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec and sign modes. The // first enabled sign mode will become the default sign mode. +// NOTE: Use NewTxConfigWithHandler to provide a custom signing handler in case the sign mode +// is not supported by default (eg: SignMode_SIGN_MODE_EIP_191). func NewTxConfig(protoCodec codec.ProtoCodecMarshaler, enabledSignModes []signingtypes.SignMode) client.TxConfig { + return NewTxConfigWithHandler(protoCodec, makeSignModeHandler(enabledSignModes)) +} + +// NewTxConfig returns a new protobuf TxConfig using the provided ProtoCodec and signing handler. +func NewTxConfigWithHandler(protoCodec codec.ProtoCodecMarshaler, handler signing.SignModeHandler) client.TxConfig { return &config{ - handler: makeSignModeHandler(enabledSignModes), + handler: handler, decoder: DefaultTxDecoder(protoCodec), encoder: DefaultTxEncoder(), jsonDecoder: DefaultJSONTxDecoder(protoCodec),