Skip to content

Commit

Permalink
Apply changes to fundraiserParams and coinTypes related functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ggomma authored and cl9200 committed Jul 25, 2019
1 parent f4df6bd commit 05b6895
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
7 changes: 4 additions & 3 deletions crypto/keys/hd/hdpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"testing"

"github.com/cosmos/cosmos-sdk/types"
bip39 "github.com/cosmos/go-bip39"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -29,10 +30,10 @@ func ExampleStringifyPathParams() {
}

func TestStringifyFundraiserPathParams(t *testing.T) {
path := NewFundraiserParams(4, 22)
path := NewFundraiserParams(4, 118, 22)
require.Equal(t, "44'/118'/4'/0/22", path.String())

path = NewFundraiserParams(4, 57)
path = NewFundraiserParams(4, 118, 57)
require.Equal(t, "44'/118'/4'/0/57", path.String())
}

Expand Down Expand Up @@ -105,7 +106,7 @@ func ExampleSomeBIP32TestVecs() {
fmt.Println("keys from fundraiser test-vector (cosmos, bitcoin, ether)")
fmt.Println()
// cosmos
priv, err := DerivePrivateKeyForPath(master, ch, FullFundraiserPath)
priv, err := DerivePrivateKeyForPath(master, ch, types.FullFundraiserPath)
if err != nil {
fmt.Println("INVALID")
} else {
Expand Down
9 changes: 6 additions & 3 deletions crypto/keys/keybase.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,15 @@ func (kb dbKeybase) CreateMnemonic(name string, language Language, passwd string
}

seed := bip39.NewSeed(mnemonic, DefaultBIP39Passphrase)
info, err = kb.persistDerivedKey(seed, passwd, name, hd.FullFundraiserPath)
fullFundraiserPath := types.GetConfig().GetFullFundraiserPath()
info, err = kb.persistDerivedKey(seed, passwd, name, fullFundraiserPath)
return
}

// CreateAccount converts a mnemonic to a private key and persists it, encrypted with the given password.
func (kb dbKeybase) CreateAccount(name, mnemonic, bip39Passwd, encryptPasswd string, account uint32, index uint32) (Info, error) {
hdPath := hd.NewFundraiserParams(account, index)
coinType := types.GetConfig().GetCoinType()
hdPath := hd.NewFundraiserParams(account, coinType, index)
return kb.Derive(name, mnemonic, bip39Passwd, encryptPasswd, *hdPath)
}

Expand All @@ -142,7 +144,8 @@ func (kb dbKeybase) CreateLedger(name string, algo SigningAlgo, hrp string, acco
return nil, ErrUnsupportedSigningAlgo
}

hdPath := hd.NewFundraiserParams(account, index)
coinType := types.GetConfig().GetCoinType()
hdPath := hd.NewFundraiserParams(account, coinType, index)
priv, _, err := crypto.NewPrivKeyLedgerSecp256k1(*hdPath, hrp)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion crypto/keys/keybase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func TestSeedPhrase(t *testing.T) {
require.NotNil(t, err)

// let us re-create it from the mnemonic-phrase
params := *hd.NewFundraiserParams(0, 0)
params := *hd.NewFundraiserParams(0, 118, 0)
newInfo, err := cstore.Derive(n2, mnemonic, DefaultBIP39Passphrase, p2, params)
require.NoError(t, err)
require.Equal(t, n2, newInfo.GetName())
Expand Down
2 changes: 1 addition & 1 deletion crypto/keys/lazy_keybase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func TestLazySeedPhrase(t *testing.T) {
require.NotNil(t, err)

// let us re-create it from the mnemonic-phrase
params := *hd.NewFundraiserParams(0, 0)
params := *hd.NewFundraiserParams(0, 118, 0)
newInfo, err := kb.Derive(n2, mnemonic, DefaultBIP39Passphrase, p2, params)
require.NoError(t, err)
require.Equal(t, n2, newInfo.GetName())
Expand Down
2 changes: 1 addition & 1 deletion crypto/keys/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func Test_writeReadLedgerInfo(t *testing.T) {
lInfo := ledgerInfo{
"some_name",
tmpKey,
*hd.NewFundraiserParams(5, 1)}
*hd.NewFundraiserParams(5, 118, 1)}
assert.Equal(t, TypeLedger, lInfo.GetType())

path, err := lInfo.GetPath()
Expand Down
12 changes: 6 additions & 6 deletions crypto/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestLedgerErrorHandling(t *testing.T) {
}

func TestPublicKeyUnsafe(t *testing.T) {
path := *hd.NewFundraiserParams(0, 0)
path := *hd.NewFundraiserParams(0, 118, 0)
priv, err := NewPrivKeyLedgerSecp256k1Unsafe(path)
require.Nil(t, err, "%s", err)
require.NotNil(t, priv)
Expand Down Expand Up @@ -61,7 +61,7 @@ func TestPublicKeyUnsafeHDPath(t *testing.T) {

// Check with device
for i := uint32(0); i < 10; i++ {
path := *hd.NewFundraiserParams(0, i)
path := *hd.NewFundraiserParams(0, 118, i)
fmt.Printf("Checking keys at %v\n", path)

priv, err := NewPrivKeyLedgerSecp256k1Unsafe(path)
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestPublicKeyUnsafeHDPath(t *testing.T) {
}

func TestPublicKeySafe(t *testing.T) {
path := *hd.NewFundraiserParams(0, 0)
path := *hd.NewFundraiserParams(0, 118, 0)
priv, addr, err := NewPrivKeyLedgerSecp256k1(path, "cosmos")

require.Nil(t, err, "%s", err)
Expand Down Expand Up @@ -152,7 +152,7 @@ func TestPublicKeyHDPath(t *testing.T) {

// Check with device
for i := uint32(0); i < 10; i++ {
path := *hd.NewFundraiserParams(0, i)
path := *hd.NewFundraiserParams(0, 118, i)
fmt.Printf("Checking keys at %v\n", path)

priv, addr, err := NewPrivKeyLedgerSecp256k1(path, "cosmos")
Expand Down Expand Up @@ -206,7 +206,7 @@ func TestSignaturesHD(t *testing.T) {
for account := uint32(0); account < 100; account += 30 {
msg := getFakeTx(account)

path := *hd.NewFundraiserParams(account, account/5)
path := *hd.NewFundraiserParams(account, 118, account/5)
fmt.Printf("Checking signature at %v --- PLEASE REVIEW AND ACCEPT IN THE DEVICE\n", path)

priv, err := NewPrivKeyLedgerSecp256k1Unsafe(path)
Expand All @@ -223,7 +223,7 @@ func TestSignaturesHD(t *testing.T) {

func TestRealLedgerSecp256k1(t *testing.T) {
msg := getFakeTx(50)
path := *hd.NewFundraiserParams(0, 0)
path := *hd.NewFundraiserParams(0, 118, 0)
priv, err := NewPrivKeyLedgerSecp256k1Unsafe(path)
require.Nil(t, err, "%s", err)

Expand Down

0 comments on commit 05b6895

Please sign in to comment.