mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-25 07:45:18 +00:00
Merge branch 'master' into develop
This commit is contained in:
commit
6e8e3f5bb9
@ -36,6 +36,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [v.0.3.2]
|
||||||
|
|
||||||
|
[\#364] Use new BIP44 coin type in the CLI, retain support for the old one through a flag.
|
||||||
|
|
||||||
## [v0.3.1]
|
## [v0.3.1]
|
||||||
|
|
||||||
[\#266] Bump tendermint version to 0.32.7 to address cosmos security advisory [Periwinkle](https://forum.cosmos.network/t/cosmos-mainnet-security-advisory-periwinkle/2911)
|
[\#266] Bump tendermint version to 0.32.7 to address cosmos security advisory [Periwinkle](https://forum.cosmos.network/t/cosmos-mainnet-security-advisory-periwinkle/2911)
|
||||||
|
@ -37,6 +37,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
appName = "kava"
|
appName = "kava"
|
||||||
Bech32MainPrefix = "kava"
|
Bech32MainPrefix = "kava"
|
||||||
|
Bip44CoinType = 459 // see https://github.com/satoshilabs/slips/blob/master/slip-0044.md
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -341,12 +342,18 @@ func MakeCodec() *codec.Codec {
|
|||||||
return cdc.Seal()
|
return cdc.Seal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetBech32AddressPrefixes sets the global prefix to be used when serializing addresses to bech32 strings.
|
||||||
func SetBech32AddressPrefixes(config *sdk.Config) {
|
func SetBech32AddressPrefixes(config *sdk.Config) {
|
||||||
config.SetBech32PrefixForAccount(Bech32MainPrefix, Bech32MainPrefix+sdk.PrefixPublic)
|
config.SetBech32PrefixForAccount(Bech32MainPrefix, Bech32MainPrefix+sdk.PrefixPublic)
|
||||||
config.SetBech32PrefixForValidator(Bech32MainPrefix+sdk.PrefixValidator+sdk.PrefixOperator, Bech32MainPrefix+sdk.PrefixValidator+sdk.PrefixOperator+sdk.PrefixPublic)
|
config.SetBech32PrefixForValidator(Bech32MainPrefix+sdk.PrefixValidator+sdk.PrefixOperator, Bech32MainPrefix+sdk.PrefixValidator+sdk.PrefixOperator+sdk.PrefixPublic)
|
||||||
config.SetBech32PrefixForConsensusNode(Bech32MainPrefix+sdk.PrefixValidator+sdk.PrefixConsensus, Bech32MainPrefix+sdk.PrefixValidator+sdk.PrefixConsensus+sdk.PrefixPublic)
|
config.SetBech32PrefixForConsensusNode(Bech32MainPrefix+sdk.PrefixValidator+sdk.PrefixConsensus, Bech32MainPrefix+sdk.PrefixValidator+sdk.PrefixConsensus+sdk.PrefixPublic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetBip44CoinType sets the global coin type to be used in hierarchical deterministic wallets.
|
||||||
|
func SetBip44CoinType(config *sdk.Config) {
|
||||||
|
config.SetCoinType(Bip44CoinType)
|
||||||
|
}
|
||||||
|
|
||||||
// application updates every end block
|
// application updates every end block
|
||||||
func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
|
func (app *App) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
|
||||||
return app.mm.BeginBlock(ctx, req)
|
return app.mm.BeginBlock(ctx, req)
|
||||||
|
@ -61,7 +61,12 @@ func TestGaiaCLIKeysAddRecover(t *testing.T) {
|
|||||||
|
|
||||||
exitSuccess, _, _ = f.KeysAddRecover("test-recover", "dentist task convince chimney quality leave banana trade firm crawl eternal easily")
|
exitSuccess, _, _ = f.KeysAddRecover("test-recover", "dentist task convince chimney quality leave banana trade firm crawl eternal easily")
|
||||||
require.True(t, exitSuccess)
|
require.True(t, exitSuccess)
|
||||||
require.Equal(t, "kava1qcfdf69js922qrdr4yaww3ax7gjml6pd39p8lj", f.KeyAddress("test-recover").String())
|
require.Equal(t, "kava1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recover").String())
|
||||||
|
|
||||||
|
// test old bip44 coin type
|
||||||
|
exitSuccess, _, _ = f.KeysAddRecover("test-recover-legacy", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", "--legacy-hd-path")
|
||||||
|
require.True(t, exitSuccess)
|
||||||
|
require.Equal(t, "kava1qcfdf69js922qrdr4yaww3ax7gjml6pd39p8lj", f.KeyAddress("test-recover-legacy").String())
|
||||||
|
|
||||||
// Cleanup testing directories
|
// Cleanup testing directories
|
||||||
f.Cleanup()
|
f.Cleanup()
|
||||||
@ -72,16 +77,20 @@ func TestGaiaCLIKeysAddRecoverHDPath(t *testing.T) {
|
|||||||
f := InitFixtures(t)
|
f := InitFixtures(t)
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverHD1", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 0, 0)
|
f.KeysAddRecoverHDPath("test-recoverHD1", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 0, 0)
|
||||||
require.Equal(t, "kava1qcfdf69js922qrdr4yaww3ax7gjml6pd39p8lj", f.KeyAddress("test-recoverHD1").String())
|
require.Equal(t, "kava1rsjxn2e4dfl3a2qzuzzjvvgjmmate383g9q4cz", f.KeyAddress("test-recoverHD1").String())
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverH2", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 5)
|
f.KeysAddRecoverHDPath("test-recoverH2", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 5)
|
||||||
require.Equal(t, "kava1pdfav2cjhry9k79nu6r8kgknnjtq6a7rcr0qlr", f.KeyAddress("test-recoverH2").String())
|
require.Equal(t, "kava1qpj6nstqn0n5gzcsaezspuhulje6msjq5t8cq5", f.KeyAddress("test-recoverH2").String())
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverH3", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 17)
|
f.KeysAddRecoverHDPath("test-recoverH3", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 1, 17)
|
||||||
require.Equal(t, "kava1909k354n6wl8ujzu6kmh49w4d02ax7qvrrcgx5", f.KeyAddress("test-recoverH3").String())
|
require.Equal(t, "kava1vayfpstgapt7dmv7074kc3ll8xpf0rlzvh4k08", f.KeyAddress("test-recoverH3").String())
|
||||||
|
|
||||||
f.KeysAddRecoverHDPath("test-recoverH4", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17)
|
f.KeysAddRecoverHDPath("test-recoverH4", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17)
|
||||||
require.Equal(t, "kava1v9plmhvyhgxk3th9ydacm7j4z357s3nhhmy0tv", f.KeyAddress("test-recoverH4").String())
|
require.Equal(t, "kava1xvsfnksmhr887skcfrm4pe3va54tkmrtw7wyer", f.KeyAddress("test-recoverH4").String())
|
||||||
|
|
||||||
|
// test old bip44 coin type
|
||||||
|
f.KeysAddRecoverHDPath("test-recoverH5", "dentist task convince chimney quality leave banana trade firm crawl eternal easily", 2, 17, "--legacy-hd-path")
|
||||||
|
require.Equal(t, "kava1v9plmhvyhgxk3th9ydacm7j4z357s3nhhmy0tv", f.KeyAddress("test-recoverH5").String())
|
||||||
|
|
||||||
// Cleanup testing directories
|
// Cleanup testing directories
|
||||||
f.Cleanup()
|
f.Cleanup()
|
||||||
|
86
cmd/kvcli/cmd_keys.go
Normal file
86
cmd/kvcli/cmd_keys.go
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/keys"
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
|
|
||||||
|
"github.com/kava-labs/kava/app"
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
NOTE TO FUTURE IMPLEMENTERS
|
||||||
|
This monkey patches the sdk `keys` command, therefore needs to be reviewed on any sdk updates.
|
||||||
|
|
||||||
|
Where a bip44 coin type is used (cosmos-sdk 18de630d):
|
||||||
|
- adding local keys
|
||||||
|
- global variable `sdk.Config.CoinType` is used to derive the key from a mnemonic (supplied by user or generated), but only the private key is stored
|
||||||
|
- adding ledger keys
|
||||||
|
- global variable `sdk.Config.CoinType` is used to reference a key on a ledger device, bip44 path (not private key) is stored locally
|
||||||
|
- signing txs with local keys
|
||||||
|
- the stored the priv key is used to sign, mnemonics or bip44 paths not involved
|
||||||
|
- signing txs with ledger
|
||||||
|
- the stored bip44 path is used to instruct the ledger which key to sign with
|
||||||
|
*/
|
||||||
|
|
||||||
|
const flagLegacyHDPath = "legacy-hd-path"
|
||||||
|
|
||||||
|
// getModifiedKeysCmd returns the standard cosmos-sdk/client/keys cmd but modified to support new and old bip44 coin types supported by kava.
|
||||||
|
func getModifiedKeysCmd() *cobra.Command {
|
||||||
|
keysCmd := keys.Commands()
|
||||||
|
for _, c := range keysCmd.Commands() {
|
||||||
|
if c.Name() == "add" {
|
||||||
|
monkeyPatchCmdKeysAdd(c)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return keysCmd
|
||||||
|
}
|
||||||
|
|
||||||
|
// monkeyPatchCmdKeysAdd modifies the `keys add` command to use the old bip44 coin type when a flag is passed.
|
||||||
|
func monkeyPatchCmdKeysAdd(keysAddCmd *cobra.Command) {
|
||||||
|
// add flag
|
||||||
|
keysAddCmd.Flags().Bool(flagLegacyHDPath, false, fmt.Sprintf("Use the old bip44 coin type (%d) to derive addresses from mnemonics.", sdk.CoinType))
|
||||||
|
|
||||||
|
// replace description
|
||||||
|
keysAddCmd.Long = fmt.Sprintf(`Derive a new private key and encrypt to disk.
|
||||||
|
Optionally specify a BIP39 mnemonic, a BIP39 passphrase to further secure the mnemonic,
|
||||||
|
and BIP44 account/index numbers to derive a specific key. The key will be stored under the given name
|
||||||
|
and encrypted with the given password.
|
||||||
|
|
||||||
|
NOTE: This cli defaults to Kava's BIP44 coin type %d. Use the --%s flag to use the old one (%d).
|
||||||
|
|
||||||
|
The flag --recover allows one to recover a key from a seed passphrase.
|
||||||
|
If run with --dry-run, a key would be generated (or recovered) but not stored to the
|
||||||
|
local keystore.
|
||||||
|
Use the --pubkey flag to add arbitrary public keys to the keystore for constructing
|
||||||
|
multisig transactions.
|
||||||
|
|
||||||
|
You can add a multisig key by passing the list of key names you want the public
|
||||||
|
key to be composed of to the --multisig flag and the minimum number of signatures
|
||||||
|
required through --multisig-threshold. The keys are sorted by address, unless
|
||||||
|
the flag --nosort is set.
|
||||||
|
`, app.Bip44CoinType, flagLegacyHDPath, sdk.CoinType)
|
||||||
|
|
||||||
|
// replace the run function with a wrapped version that sets the old coin type in the global config
|
||||||
|
oldRun := keysAddCmd.RunE
|
||||||
|
keysAddCmd.RunE = func(cmd *cobra.Command, args []string) error {
|
||||||
|
preExistingCoinType := sdk.GetConfig().GetCoinType()
|
||||||
|
|
||||||
|
if viper.GetBool(flagLegacyHDPath) {
|
||||||
|
sdk.GetConfig().SetCoinType(sdk.CoinType) // set old coin type
|
||||||
|
err := oldRun(cmd, args)
|
||||||
|
sdk.GetConfig().SetCoinType(preExistingCoinType) // revert to preexisting coin type
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
if viper.GetBool(flags.FlagUseLedger) {
|
||||||
|
return fmt.Errorf("cosmos ledger app only supports legacy bip44 coin type, must use --%s flag when adding ledger key", flagLegacyHDPath)
|
||||||
|
}
|
||||||
|
return oldRun(cmd, args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/tendermint/tendermint/libs/cli"
|
"github.com/tendermint/tendermint/libs/cli"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client"
|
"github.com/cosmos/cosmos-sdk/client"
|
||||||
"github.com/cosmos/cosmos-sdk/client/keys"
|
|
||||||
"github.com/cosmos/cosmos-sdk/client/lcd"
|
"github.com/cosmos/cosmos-sdk/client/lcd"
|
||||||
"github.com/cosmos/cosmos-sdk/client/rpc"
|
"github.com/cosmos/cosmos-sdk/client/rpc"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
@ -33,10 +32,11 @@ func main() {
|
|||||||
// Instantiate the codec for the command line application
|
// Instantiate the codec for the command line application
|
||||||
cdc := app.MakeCodec()
|
cdc := app.MakeCodec()
|
||||||
|
|
||||||
// Read in the configuration file for the sdk
|
// Set the global config
|
||||||
|
// config is not sealed as the cli supports two coin types for legacy reasons.
|
||||||
config := sdk.GetConfig()
|
config := sdk.GetConfig()
|
||||||
app.SetBech32AddressPrefixes(config)
|
app.SetBech32AddressPrefixes(config)
|
||||||
config.Seal()
|
app.SetBip44CoinType(config)
|
||||||
|
|
||||||
// TODO: setup keybase, viper object, etc. to be passed into
|
// TODO: setup keybase, viper object, etc. to be passed into
|
||||||
// the below functions and eliminate global vars, like we do
|
// the below functions and eliminate global vars, like we do
|
||||||
@ -62,7 +62,7 @@ func main() {
|
|||||||
client.LineBreak,
|
client.LineBreak,
|
||||||
lcd.ServeCommand(cdc, registerRoutes),
|
lcd.ServeCommand(cdc, registerRoutes),
|
||||||
client.LineBreak,
|
client.LineBreak,
|
||||||
keys.Commands(),
|
getModifiedKeysCmd(),
|
||||||
client.LineBreak,
|
client.LineBreak,
|
||||||
version.Cmd,
|
version.Cmd,
|
||||||
client.NewCompletionCmd(rootCmd, true),
|
client.NewCompletionCmd(rootCmd, true),
|
||||||
|
@ -18,9 +18,9 @@ import (
|
|||||||
"github.com/cosmos/cosmos-sdk/server"
|
"github.com/cosmos/cosmos-sdk/server"
|
||||||
"github.com/cosmos/cosmos-sdk/store"
|
"github.com/cosmos/cosmos-sdk/store"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
|
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
|
||||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
|
||||||
|
|
||||||
"github.com/kava-labs/kava/app"
|
"github.com/kava-labs/kava/app"
|
||||||
)
|
)
|
||||||
@ -35,6 +35,7 @@ func main() {
|
|||||||
|
|
||||||
config := sdk.GetConfig()
|
config := sdk.GetConfig()
|
||||||
app.SetBech32AddressPrefixes(config)
|
app.SetBech32AddressPrefixes(config)
|
||||||
|
app.SetBip44CoinType(config)
|
||||||
config.Seal()
|
config.Seal()
|
||||||
|
|
||||||
ctx := server.NewDefaultContext()
|
ctx := server.NewDefaultContext()
|
||||||
|
@ -112,7 +112,7 @@
|
|||||||
summary: Syncing state of node
|
summary: Syncing state of node
|
||||||
tags:
|
tags:
|
||||||
- Tendermint RPC
|
- Tendermint RPC
|
||||||
description: Get if the node is currently syning with other nodes
|
description: Get the syncing status of the node
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
@ -298,7 +298,7 @@
|
|||||||
$ref: "#/definitions/StdTx"
|
$ref: "#/definitions/StdTx"
|
||||||
mode:
|
mode:
|
||||||
type: string
|
type: string
|
||||||
example: block
|
example: sync
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: Tx broadcasting result
|
description: Tx broadcasting result
|
||||||
@ -1991,7 +1991,19 @@
|
|||||||
value:
|
value:
|
||||||
type: string
|
type: string
|
||||||
Msg:
|
Msg:
|
||||||
type: string
|
type: object
|
||||||
|
required:
|
||||||
|
- from
|
||||||
|
properties:
|
||||||
|
type:
|
||||||
|
type: string
|
||||||
|
example: "cosmos-sdk/MsgSend"
|
||||||
|
value:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
from:
|
||||||
|
type: string
|
||||||
|
example: kava1mzqz3jfs9nzfp6v7qp647rv0afxlu2csl0txmq
|
||||||
Address:
|
Address:
|
||||||
type: string
|
type: string
|
||||||
description: bech32 encoded address
|
description: bech32 encoded address
|
||||||
@ -2005,13 +2017,28 @@
|
|||||||
properties:
|
properties:
|
||||||
denom:
|
denom:
|
||||||
type: string
|
type: string
|
||||||
example: stake
|
example: ukava
|
||||||
amount:
|
amount:
|
||||||
type: string
|
type: string
|
||||||
example: "50"
|
example: "50"
|
||||||
Hash:
|
Hash:
|
||||||
type: string
|
type: string
|
||||||
example: EE5F3404034C524501629B56E0DDC38FAD651F04
|
example: EE5F3404034C524501629B56E0DDC38FAD651F04
|
||||||
|
Signature:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
signature:
|
||||||
|
type: string
|
||||||
|
example: "W1HfKcc4F0rCSoxheZ7fsrB5nGK58U4gKysuzsmUwhloVnCxmbCx289uVMMvQN6tOcQsz7hMVTJrXSA1xzevvw=="
|
||||||
|
pubkey:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
type:
|
||||||
|
type: string
|
||||||
|
example: "tendermint/PubKeySecp256k1"
|
||||||
|
value:
|
||||||
|
type: string
|
||||||
|
example: "Agey31h/NYpcy0sYm4liHMrXJMzbQUrgV4uHd/w09CXN"
|
||||||
TxQuery:
|
TxQuery:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
@ -2078,27 +2105,10 @@
|
|||||||
$ref: "#/definitions/Coin"
|
$ref: "#/definitions/Coin"
|
||||||
memo:
|
memo:
|
||||||
type: string
|
type: string
|
||||||
signature:
|
signatures:
|
||||||
type: object
|
type: array
|
||||||
properties:
|
items:
|
||||||
signature:
|
$ref: "#/definitions/Signature"
|
||||||
type: string
|
|
||||||
example: MEUCIQD02fsDPra8MtbRsyB1w7bqTM55Wu138zQbFcWx4+CFyAIge5WNPfKIuvzBZ69MyqHsqD8S1IwiEp+iUb6VSdtlpgY=
|
|
||||||
pub_key:
|
|
||||||
type: object
|
|
||||||
properties:
|
|
||||||
type:
|
|
||||||
type: string
|
|
||||||
example: "tendermint/PubKeySecp256k1"
|
|
||||||
value:
|
|
||||||
type: string
|
|
||||||
example: "Avz04VhtKJh8ACCVzlI8aTosGy0ikFXKIVHQ3jKMrosH"
|
|
||||||
account_number:
|
|
||||||
type: string
|
|
||||||
example: "0"
|
|
||||||
sequence:
|
|
||||||
type: string
|
|
||||||
example: "0"
|
|
||||||
BlockID:
|
BlockID:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
Loading…
Reference in New Issue
Block a user