From f52f8ff2c51d0a9227c97a6507f527d1b226f644 Mon Sep 17 00:00:00 2001 From: mrz1836 Date: Tue, 6 Oct 2020 15:19:57 -0400 Subject: [PATCH] Added nil checks to reduce potential panics --- hd_key.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hd_key.go b/hd_key.go index 137c343..b29e91c 100644 --- a/hd_key.go +++ b/hd_key.go @@ -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) @@ -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() }