This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
BIP44 hd-path mistake #605
Closed
Description
System info: [branch:development, commit:ab951e22d0454ba1a0fccc9362491843bf7d4e06]
Steps to reproduce:
- the private key generated through cmd
ethermintcli keys add alice --recover
is not same to metamask using the same mnemonic.
Expected behavior: can generate same private key on metamask
RootCause:
- The String method of BIP44Params in cosmos-sdk v0.39.1 return path without "m".
func RunAddCmd(cmd *cobra.Command, args []string, kb keys.Keybase, inBuf *bufio.Reader) error {
......
......
useBIP44 := !viper.IsSet(flagHDPath)
var hdPath string
if useBIP44 {
hdPath = keys.CreateHDPath(account, index).String()
} else {
hdPath = viper.GetString(flagHDPath)
}
......
......
}
func (p BIP44Params) String() string {
var changeStr string
if p.Change {
changeStr = "1"
} else {
changeStr = "0"
}
// m / Purpose' / coin_type' / Account' / Change / address_index
return fmt.Sprintf("%d'/%d'/%d'/%s/%d",
p.Purpose,
p.CoinType,
p.Account,
changeStr,
p.AddressIndex)
}
- But the code of parsing hd-path that ethermint use is go-ethereum v1.9.24. Path without "m" will impact the parsed result.
func ParseDerivationPath(path string) (DerivationPath, error) {
......
......
case strings.TrimSpace(components[0]) == "m":
components = components[1:]
default:
result = append(result, DefaultRootDerivationPath...)
}
......
......
return result, nil
}
Activity