Skip to content

Commit

Permalink
Added nil checks to reduce potential panics
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Oct 6, 2020
1 parent 4b5120f commit f52f8ff
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions hd_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func GenerateHDKey(seedLength uint8) (hdKey *hdkeychain.ExtendedKey, err error)

// GenerateHDKeyFromString will create a new master node for use in creating a
// hierarchical deterministic key chain from an xPrivKey string
func GenerateHDKeyFromString(xpriv string) (hdKey *hdkeychain.ExtendedKey, err error) {
return hdkeychain.NewKeyFromString(xpriv)
func GenerateHDKeyFromString(xPriv string) (hdKey *hdkeychain.ExtendedKey, err error) {
return hdkeychain.NewKeyFromString(xPriv)
}

// GenerateHDKeyPair will generate a new xPub HD master node (xPrivateKey & xPublicKey)
Expand Down Expand Up @@ -111,12 +111,18 @@ func GetPrivateKeyByPath(hdKey *hdkeychain.ExtendedKey, chain, num uint32) (*bsv
// GetPrivateKeyFromHDKey - helper function to get the Private Key associated
// with a given hdKey
func GetPrivateKeyFromHDKey(hdKey *hdkeychain.ExtendedKey) (*bsvec.PrivateKey, error) {
if hdKey == nil {
return nil, errors.New("hdKey is nil")
}
return hdKey.ECPrivKey()
}

// GetPublicKeyFromHDKey - helper function to get the Public Key associated
// with a given hdKey
func GetPublicKeyFromHDKey(hdKey *hdkeychain.ExtendedKey) (*bsvec.PublicKey, error) {
if hdKey == nil {
return nil, errors.New("hdKey is nil")
}
return hdKey.ECPubKey()
}

Expand Down

0 comments on commit f52f8ff

Please sign in to comment.