Skip to content

Commit

Permalink
dex/keygen: use ChildBIP32Std for extended key derivation
Browse files Browse the repository at this point in the history
This updates the GenDeepChild helper, which is used in both client/core
to setup DEX account keys from the app seed, and in client/asset/eth to
derive the account private key from the wallet seed.

This is especially in the eth key derivation, where the intent is to
follow BIP44 with the path m/44'/60'/0'/0/0, which requires generating
child keys as per BIP32 strictly.

For generating DEX account keys from the app seed, it is also good from
a standardness point of view to use strict BIP32 derivation.  The legacy
derivation is only required for Decred wallets for compatibility.
  • Loading branch information
chappjc committed Dec 9, 2021
1 parent 6c947e0 commit fbbd942
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dex/keygen/keygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func GenDeepChild(seed []byte, kids []uint32) (*hdkeychain.ExtendedKey, error) {
err := hdkeychain.ErrInvalidChild
for err == hdkeychain.ErrInvalidChild {
var kid *hdkeychain.ExtendedKey
kid, err = parent.Child(childIdx)
kid, err = parent.ChildBIP32Std(childIdx)
if err == nil {
return kid, nil
}
Expand Down
6 changes: 3 additions & 3 deletions dex/keygen/keygen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ func TestGenDeepChild(t *testing.T) {
t.Fatalf("error getting HD keychain root: %v", err)
}

expectedChild, err := root.Child(1)
expectedChild, err := root.ChildBIP32Std(1)
if err != nil {
t.Fatalf("error deriving child: %v", err)
}

expectedChild, err = expectedChild.Child(2)
expectedChild, err = expectedChild.ChildBIP32Std(2)
if err != nil {
t.Fatalf("error deriving child: %v", err)
}

expectedChild, err = expectedChild.Child(3)
expectedChild, err = expectedChild.ChildBIP32Std(3)
if err != nil {
t.Fatalf("error deriving child: %v", err)
}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module decred.org/dcrdex

go 1.16

replace github.com/decred/dcrd/hdkeychain/v3 => github.com/chappjc/dcrd/hdkeychain/v3 v3.0.0-20211209152155-a5ed31b4792c

require (
decred.org/dcrwallet/v2 v2.0.0-20211206163037-9537363becbb
github.com/btcsuite/btcd v0.22.0-beta.0.20211026140004-31791ba4dc6e
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/chappjc/dcrd/hdkeychain/v3 v3.0.0-20211209152155-a5ed31b4792c h1:38QutUk71CWIJS/R499su//6VABu3sDP7lD37AvcUes=
github.com/chappjc/dcrd/hdkeychain/v3 v3.0.0-20211209152155-a5ed31b4792c/go.mod h1:rDCdqwGkcTfEyRheG1g8Wc38appT2C9+D1XTlLy21lo=
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
Expand Down Expand Up @@ -185,8 +187,6 @@ github.com/decred/dcrd/dcrutil/v4 v4.0.0/go.mod h1:QQpX5WVH3/ixVtiW15xZMe+neugXX
github.com/decred/dcrd/gcs/v3 v3.0.0-20210916172859-ca03de05ecd0/go.mod h1:cfMmjV1ArvX+nemwwq1texW5pD0wrUt5TEw4IYuTmMM=
github.com/decred/dcrd/gcs/v3 v3.0.0 h1:MjWevhoAzKENUgpaJAbZkJlKDN4HIz2nR/i3laZAT5c=
github.com/decred/dcrd/gcs/v3 v3.0.0/go.mod h1:/OVb/rYrAz4TCtxcPneYfBs0+YI1pGIp8RA6RUNqOp4=
github.com/decred/dcrd/hdkeychain/v3 v3.0.1 h1:wvfHa3VY8YW1sB2TzXipCehO6N0u1H6rSsNAYtEE9VY=
github.com/decred/dcrd/hdkeychain/v3 v3.0.1/go.mod h1:rDCdqwGkcTfEyRheG1g8Wc38appT2C9+D1XTlLy21lo=
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
github.com/decred/dcrd/lru v1.1.0 h1:QwT6v8LFKOL3xQ3qtucgRk4pdiawrxIfCbUXWpm+JL4=
github.com/decred/dcrd/lru v1.1.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
Expand Down

0 comments on commit fbbd942

Please sign in to comment.