diff --git a/bip39-standalone.html b/bip39-standalone.html
index 367d9a2..ca18ea8 100644
--- a/bip39-standalone.html
+++ b/bip39-standalone.html
@@ -18964,6 +18964,10 @@ window.Entropy = new (function() {
}
function calcBip32ExtendedKey(path) {
+ // Check there's a root key to derive from
+ if (!bip32RootKey) {
+ return bip32RootKey;
+ }
var extendedKey = bip32RootKey;
// Derive the key from the path
var pathBits = path.split("/");
@@ -19098,6 +19102,10 @@ window.Entropy = new (function() {
}
}
}
+ // Check root key exists or else derivation path is useless!
+ if (!bip32RootKey) {
+ return "No root key";
+ }
// Check no hardened derivation path when using xpub keys
var hardened = path.indexOf("'") > -1;
var isXpubkey = !("privKey" in bip32RootKey);
diff --git a/src/js/index.js b/src/js/index.js
index 45edea8..13c6178 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -324,6 +324,10 @@
}
function calcBip32ExtendedKey(path) {
+ // Check there's a root key to derive from
+ if (!bip32RootKey) {
+ return bip32RootKey;
+ }
var extendedKey = bip32RootKey;
// Derive the key from the path
var pathBits = path.split("/");
@@ -458,6 +462,10 @@
}
}
}
+ // Check root key exists or else derivation path is useless!
+ if (!bip32RootKey) {
+ return "No root key";
+ }
// Check no hardened derivation path when using xpub keys
var hardened = path.indexOf("'") > -1;
var isXpubkey = !("privKey" in bip32RootKey);
diff --git a/tests.js b/tests.js
index 19a3712..3cde75f 100644
--- a/tests.js
+++ b/tests.js
@@ -3241,6 +3241,30 @@ page.open(url, function(status) {
});
},
+// github issue 39
+// no root key shows feedback
+function() {
+page.open(url, function(status) {
+ // click the bip32 tab on fresh page
+ page.evaluate(function() {
+ $("#bip32-tab a").click();
+ });
+ waitForFeedback(function() {
+ // Check feedback is correct
+ var expected = "No root key";
+ var actual = page.evaluate(function() {
+ return $(".feedback").text();
+ });
+ if (actual != expected) {
+ console.log("Blank root key not detected");
+ console.log("Expected: " + expected);
+ console.log("Actual: " + actual);
+ fail();
+ }
+ next();
+ });
+});
+},
// If you wish to add more tests, do so here...