Skip to content

Commit

Permalink
use ParseDerivationPath from geth
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmota committed Jul 6, 2018
1 parent a9d16bb commit e64b7ba
Show file tree
Hide file tree
Showing 182 changed files with 32,650 additions and 39 deletions.
57 changes: 55 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 13 additions & 37 deletions hdwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import (
"crypto/ecdsa"
"errors"
"fmt"
"strconv"
"strings"

"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcutil/hdkeychain"
"github.com/ethereum/go-ethereum/accounts"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
Expand Down Expand Up @@ -43,31 +42,20 @@ func New(config *Config) (*Wallet, error) {
}

seed := bip39.NewSeed(config.Mnemonic, "")
parts := strings.Split(config.Path, "/")
var err error
var masterKey *hdkeychain.ExtendedKey
var key *hdkeychain.ExtendedKey
// TODO: use https://github.com/ethereum/go-ethereum/blob/ef0edc6e32d98d2fca54076f38cb317f43704900/accounts/hd.go#L67
for _, part := range parts {
p := strings.Split(part, "'")
n := p[0]
h := (len(p) == 2)

if n == "m" {
masterKey, err = hdkeychain.NewMaster(seed, &chaincfg.MainNetParams)
if err != nil {
return nil, err
}
key = masterKey
continue
}
dpath, err := accounts.ParseDerivationPath(config.Path)
if err != nil {
return nil, err
}

u64, err := strconv.ParseUint(n, 10, 32)
if err != nil {
return nil, err
}
masterKey, err := hdkeychain.NewMaster(seed, &chaincfg.MainNetParams)
if err != nil {
return nil, err
}

key := masterKey

key, err = newChild(key, uint32(u64), h)
for _, n := range dpath {
key, err = key.Child(n)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -205,18 +193,6 @@ func (s Wallet) Mnemonic() string {
return s.mnemonic
}

func newChild(key *hdkeychain.ExtendedKey, n uint32, hardened bool) (*hdkeychain.ExtendedKey, error) {
if key == nil {
return nil, errors.New("key is nil")
}

if hardened {
n = hdkeychain.HardenedKeyStart + n
}

return key.Child(n)
}

// NewMnemonic ...
func NewMnemonic() (string, error) {
entropy, err := bip39.NewEntropy(128)
Expand Down
25 changes: 25 additions & 0 deletions vendor/github.com/aristanetworks/goarista/AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

177 changes: 177 additions & 0 deletions vendor/github.com/aristanetworks/goarista/COPYING

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e64b7ba

Please sign in to comment.