diff --git a/CHANGELOG.md b/CHANGELOG.md index f06db43e4f37..11ef49af3134 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/gov) [\#8473](https://github.com/cosmos/cosmos-sdk/pull/8473) On genesis init, if the gov module account balance, coming from bank module state, does not match the one in gov module state, the initialization will panic. * (x/distribution) [\#8473](https://github.com/cosmos/cosmos-sdk/pull/8473) On genesis init, if the distribution module account balance, coming from bank module state, does not match the one in distribution module state, the initialization will panic. * (client/keys) [\#8500](https://github.com/cosmos/cosmos-sdk/pull/8500) `InfoImporter` interface is removed from legacy keybase. +* [\#8629](https://github.com/cosmos/cosmos-sdk/pull/8629) Deprecated `SetFullFundraiserPath` from `Config` in favor of `SetPurpose` and `SetCoinType`. ### State Machine Breaking diff --git a/client/keys/add_ledger_test.go b/client/keys/add_ledger_test.go index b8ba1ec7f59e..5e32f755f70e 100644 --- a/client/keys/add_ledger_test.go +++ b/client/keys/add_ledger_test.go @@ -29,8 +29,8 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) { bech32PrefixConsAddr := "terravalcons" bech32PrefixConsPub := "terravalconspub" + config.SetPurpose(44) config.SetCoinType(330) - config.SetFullFundraiserPath("44'/330'/0'/0/0") config.SetBech32PrefixForAccount(bech32PrefixAccAddr, bech32PrefixAccPub) config.SetBech32PrefixForValidator(bech32PrefixValAddr, bech32PrefixValPub) config.SetBech32PrefixForConsensusNode(bech32PrefixConsAddr, bech32PrefixConsPub) @@ -77,8 +77,8 @@ func Test_runAddCmdLedgerWithCustomCoinType(t *testing.T) { "terrapub1addwnpepqvpg7r26nl2pvqqern00m6s9uaax3hauu2rzg8qpjzq9hy6xve7sw0d84m6", sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeAccPub, key1.GetPubKey())) + config.SetPurpose(44) config.SetCoinType(118) - config.SetFullFundraiserPath("44'/118'/0'/0/0") config.SetBech32PrefixForAccount(sdk.Bech32PrefixAccAddr, sdk.Bech32PrefixAccPub) config.SetBech32PrefixForValidator(sdk.Bech32PrefixValAddr, sdk.Bech32PrefixValPub) config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub) diff --git a/client/keys/delete_test.go b/client/keys/delete_test.go index 5a0013967196..49da92bf1f72 100644 --- a/client/keys/delete_test.go +++ b/client/keys/delete_test.go @@ -31,7 +31,7 @@ func Test_runDeleteCmd(t *testing.T) { fakeKeyName1 := "runDeleteCmd_Key1" fakeKeyName2 := "runDeleteCmd_Key2" - path := sdk.GetConfig().GetFullFundraiserPath() + path := sdk.GetConfig().GetFullBIP44Path() kb, err := keyring.New(sdk.KeyringServiceName(), keyring.BackendTest, kbHome, mockIn) require.NoError(t, err) diff --git a/client/keys/export_test.go b/client/keys/export_test.go index b01bbf823023..782af754024f 100644 --- a/client/keys/export_test.go +++ b/client/keys/export_test.go @@ -31,7 +31,7 @@ func Test_runExportCmd(t *testing.T) { kb.Delete("keyname1") // nolint:errcheck }) - path := sdk.GetConfig().GetFullFundraiserPath() + path := sdk.GetConfig().GetFullBIP44Path() _, err = kb.NewAccount("keyname1", testutil.TestMnemonic, "", path, hd.Secp256k1) require.NoError(t, err) diff --git a/client/keys/list_test.go b/client/keys/list_test.go index 5904f74bfdd2..17f8dd8e4f94 100644 --- a/client/keys/list_test.go +++ b/client/keys/list_test.go @@ -30,7 +30,7 @@ func Test_runListCmd(t *testing.T) { clientCtx := client.Context{}.WithKeyring(kb) ctx := context.WithValue(context.Background(), client.ClientContextKey, &clientCtx) - path := "" //sdk.GetConfig().GetFullFundraiserPath() + path := "" //sdk.GetConfig().GetFullBIP44Path() _, err = kb.NewAccount("something", testutil.TestMnemonic, "", path, hd.Secp256k1) require.NoError(t, err) diff --git a/types/address.go b/types/address.go index eabff6fa97ee..9f3f8216051e 100644 --- a/types/address.go +++ b/types/address.go @@ -26,13 +26,16 @@ const ( // config.SetBech32PrefixForAccount(yourBech32PrefixAccAddr, yourBech32PrefixAccPub) // config.SetBech32PrefixForValidator(yourBech32PrefixValAddr, yourBech32PrefixValPub) // config.SetBech32PrefixForConsensusNode(yourBech32PrefixConsAddr, yourBech32PrefixConsPub) + // config.SetPurpose(yourPurpose) // config.SetCoinType(yourCoinType) - // config.SetFullFundraiserPath(yourFullFundraiserPath) // config.Seal() // Bech32MainPrefix defines the main SDK Bech32 prefix of an account's address Bech32MainPrefix = "cosmos" + // Purpose is the ATOM purpose as defined in SLIP44 (https://github.com/satoshilabs/slips/blob/master/slip-0044.md) + Purpose = 44 + // CoinType is the ATOM coin type as defined in SLIP44 (https://github.com/satoshilabs/slips/blob/master/slip-0044.md) CoinType = 118 diff --git a/types/config.go b/types/config.go index a3181703df1e..00b701a025d7 100644 --- a/types/config.go +++ b/types/config.go @@ -2,6 +2,7 @@ package types import ( "context" + "fmt" "sync" "github.com/cosmos/cosmos-sdk/version" @@ -18,9 +19,13 @@ type Config struct { txEncoder TxEncoder addressVerifier func([]byte) error mtx sync.RWMutex - coinType uint32 - sealed bool - sealedch chan struct{} + + // SLIP-44 related + purpose uint32 + coinType uint32 + + sealed bool + sealedch chan struct{} } // cosmos-sdk wide global singleton @@ -41,9 +46,11 @@ func NewConfig() *Config { "validator_pub": Bech32PrefixValPub, "consensus_pub": Bech32PrefixConsPub, }, - coinType: CoinType, fullFundraiserPath: FullFundraiserPath, - txEncoder: nil, + + purpose: Purpose, + coinType: CoinType, + txEncoder: nil, } } @@ -112,16 +119,24 @@ func (config *Config) SetAddressVerifier(addressVerifier func([]byte) error) { config.addressVerifier = addressVerifier } -// Set the BIP-0044 CoinType code on the config -func (config *Config) SetCoinType(coinType uint32) { +// Set the FullFundraiserPath (BIP44Prefix) on the config. +// +// Deprecated: This method is supported for backward compatibility only and will be removed in a future release. Use SetPurpose and SetCoinType instead. +func (config *Config) SetFullFundraiserPath(fullFundraiserPath string) { config.assertNotSealed() - config.coinType = coinType + config.fullFundraiserPath = fullFundraiserPath } -// Set the FullFundraiserPath (BIP44Prefix) on the config -func (config *Config) SetFullFundraiserPath(fullFundraiserPath string) { +// Set the BIP-0044 Purpose code on the config +func (config *Config) SetPurpose(purpose uint32) { config.assertNotSealed() - config.fullFundraiserPath = fullFundraiserPath + config.purpose = purpose +} + +// Set the BIP-0044 CoinType code on the config +func (config *Config) SetCoinType(coinType uint32) { + config.assertNotSealed() + config.coinType = coinType } // Seal seals the config such that the config state could not be modified further @@ -181,16 +196,28 @@ func (config *Config) GetAddressVerifier() func([]byte) error { return config.addressVerifier } +// GetPurpose returns the BIP-0044 Purpose code on the config. +func (config *Config) GetPurpose() uint32 { + return config.purpose +} + // GetCoinType returns the BIP-0044 CoinType code on the config. func (config *Config) GetCoinType() uint32 { return config.coinType } // GetFullFundraiserPath returns the BIP44Prefix. +// +// Deprecated: This method is supported for backward compatibility only and will be removed in a future release. Use GetFullBIP44Path instead. func (config *Config) GetFullFundraiserPath() string { return config.fullFundraiserPath } +// GetFullBIP44Path returns the BIP44Prefix. +func (config *Config) GetFullBIP44Path() string { + return fmt.Sprintf("m/%d'/%d'/0'/0/0", config.purpose, config.coinType) +} + func KeyringServiceName() string { if len(version.Name) == 0 { return DefaultKeyringServiceName diff --git a/types/config_test.go b/types/config_test.go index e2027f38569f..df281b1f852a 100644 --- a/types/config_test.go +++ b/types/config_test.go @@ -17,6 +17,18 @@ func TestConfigTestSuite(t *testing.T) { suite.Run(t, new(configTestSuite)) } +func (s *contextTestSuite) TestConfig_SetPurpose() { + config := sdk.NewConfig() + config.SetPurpose(44) + s.Require().Equal(uint32(44), config.GetPurpose()) + + config.SetPurpose(0) + s.Require().Equal(uint32(0), config.GetPurpose()) + + config.Seal() + s.Require().Panics(func() { config.SetPurpose(10) }) +} + func (s *configTestSuite) TestConfig_SetCoinType() { config := sdk.NewConfig() config.SetCoinType(1) diff --git a/x/authz/types/authorization_grant.go b/x/authz/types/authorization_grant.go index c94e9d6d730a..03a83bdefd5c 100644 --- a/x/authz/types/authorization_grant.go +++ b/x/authz/types/authorization_grant.go @@ -3,10 +3,11 @@ package types import ( "time" + proto "github.com/gogo/protobuf/proto" + "github.com/cosmos/cosmos-sdk/codec/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/x/authz/exported" - proto "github.com/gogo/protobuf/proto" ) // NewAuthorizationGrant returns new AuthrizationGrant diff --git a/x/staking/types/authz.go b/x/staking/types/authz.go index aae9b706f1fe..e88288da4e2d 100644 --- a/x/staking/types/authz.go +++ b/x/staking/types/authz.go @@ -1,10 +1,11 @@ package types import ( + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" authz "github.com/cosmos/cosmos-sdk/x/authz/exported" - tmproto "github.com/tendermint/tendermint/proto/tendermint/types" ) var ( diff --git a/x/staking/types/authz_test.go b/x/staking/types/authz_test.go index 7f5dd2c22c10..18709d9ecd51 100644 --- a/x/staking/types/authz_test.go +++ b/x/staking/types/authz_test.go @@ -5,9 +5,10 @@ import ( tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "github.com/stretchr/testify/require" + sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - "github.com/stretchr/testify/require" ) var (