From: Ian Coleman Date: Tue, 17 Dec 2019 23:32:25 +0000 (+1100) Subject: Make seed field editable X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git;a=commitdiff_plain;h=9cf02dd452bec4d0fe4e894dbe19f0b4f7ddc50a Make seed field editable --- diff --git a/src/index.html b/src/index.html index fe048dc..e8aac4d 100644 --- a/src/index.html +++ b/src/index.html @@ -221,7 +221,7 @@
- +
diff --git a/src/js/index.js b/src/js/index.js index d169ed2..3148ca4 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -19,6 +19,7 @@ var entropyTypeAutoDetect = true; var entropyChangeTimeoutEvent = null; var phraseChangeTimeoutEvent = null; + var seedChangedTimeoutEvent = null; var rootKeyChangedTimeoutEvent = null; var generationProcesses = []; @@ -135,6 +136,7 @@ DOM.passphrase.on("input", delayedPhraseChanged); DOM.generate.on("click", generateClicked); DOM.more.on("click", showMore); + DOM.seed.on("input", delayedSeedChanged); DOM.rootKey.on("input", delayedRootKeyChanged); DOM.litecoinUseLtub.on("change", litecoinUseLtubChanged); DOM.bip32path.on("input", calcForDerivationPath); @@ -340,6 +342,30 @@ entropyChanged(); } + function delayedSeedChanged() { + // Warn if there is an existing mnemonic or passphrase. + if (DOM.phrase.val().length > 0 || DOM.passphrase.val().length > 0) { + if (!confirm("This will clear existing mnemonic and passphrase")) { + DOM.seed.val(seed); + return + } + } + hideValidationError(); + showPending(); + // Clear existing mnemonic and passphrase + DOM.phrase.val(""); + DOM.phraseSplit.val(""); + DOM.passphrase.val(""); + DOM.rootKey.val(""); + clearAddressesList(); + clearDerivedKeys(); + seed = null; + if (seedChangedTimeoutEvent != null) { + clearTimeout(seedChangedTimeoutEvent); + } + seedChangedTimeoutEvent = setTimeout(seedChanged, 400); + } + function delayedRootKeyChanged() { // Warn if there is an existing mnemonic or passphrase. if (DOM.phrase.val().length > 0 || DOM.passphrase.val().length > 0) { @@ -361,6 +387,22 @@ rootKeyChangedTimeoutEvent = setTimeout(rootKeyChanged, 400); } + function seedChanged() { + showPending(); + hideValidationError(); + seed = DOM.seed.val(); + bip32RootKey = bitcoinjs.bitcoin.HDNode.fromSeedHex(seed, network); + var rootKeyBase58 = bip32RootKey.toBase58(); + DOM.rootKey.val(rootKeyBase58); + var errorText = validateRootKey(rootKeyBase58); + if (errorText) { + showValidationError(errorText); + return; + } + // Calculate and display + calcForDerivationPath(); + } + function rootKeyChanged() { showPending(); hideValidationError(); diff --git a/tests/spec/tests.js b/tests/spec/tests.js index 260ff2c..0e93343 100644 --- a/tests/spec/tests.js +++ b/tests/spec/tests.js @@ -4336,4 +4336,17 @@ it('Allows entropy type to be manually selected', function(done) { }); }); +// https://github.com/iancoleman/bip39/issues/388 +// Make field for bip39 seed editable +it('Generates addresses when seed is set', function(done) { + driver.findElement(By.css('.seed')) + .sendKeys("20da140d3dd1df8713cefcc4d54ce0e445b4151027a1ab567b832f6da5fcc5afc1c3a3f199ab78b8e0ab4652efd7f414ac2c9a3b81bceb879a70f377aa0a58f3"); + driver.sleep(generateDelay).then(function() { + getFirstAddress(function(address) { + expect(address).toBe("1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug"); + done(); + }); + }); +}); + });