aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Coleman <ian@iancoleman.io>2019-12-18 10:32:25 +1100
committerIan Coleman <ian@iancoleman.io>2019-12-18 10:32:25 +1100
commit9cf02dd452bec4d0fe4e894dbe19f0b4f7ddc50a (patch)
tree1c4a4c133eca5a1621d25450ee2d80d1d85268fb
parentf12242014d1ed5c7606c3350a9780c3883abc565 (diff)
downloadBIP39-9cf02dd452bec4d0fe4e894dbe19f0b4f7ddc50a.tar.gz
BIP39-9cf02dd452bec4d0fe4e894dbe19f0b4f7ddc50a.tar.zst
BIP39-9cf02dd452bec4d0fe4e894dbe19f0b4f7ddc50a.zip
Make seed field editable
-rw-r--r--src/index.html2
-rw-r--r--src/js/index.js42
-rw-r--r--tests/spec/tests.js13
3 files changed, 56 insertions, 1 deletions
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 @@
221 <div class="form-group"> 221 <div class="form-group">
222 <label for="seed" class="col-sm-2 control-label">BIP39 Seed</label> 222 <label for="seed" class="col-sm-2 control-label">BIP39 Seed</label>
223 <div class="col-sm-10"> 223 <div class="col-sm-10">
224 <textarea id="seed" class="seed private-data form-control" readonly="readonly" data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea> 224 <textarea id="seed" class="seed private-data form-control" data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
225 </div> 225 </div>
226 </div> 226 </div>
227 <div class="form-group"> 227 <div class="form-group">
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 @@
19 var entropyTypeAutoDetect = true; 19 var entropyTypeAutoDetect = true;
20 var entropyChangeTimeoutEvent = null; 20 var entropyChangeTimeoutEvent = null;
21 var phraseChangeTimeoutEvent = null; 21 var phraseChangeTimeoutEvent = null;
22 var seedChangedTimeoutEvent = null;
22 var rootKeyChangedTimeoutEvent = null; 23 var rootKeyChangedTimeoutEvent = null;
23 24
24 var generationProcesses = []; 25 var generationProcesses = [];
@@ -135,6 +136,7 @@
135 DOM.passphrase.on("input", delayedPhraseChanged); 136 DOM.passphrase.on("input", delayedPhraseChanged);
136 DOM.generate.on("click", generateClicked); 137 DOM.generate.on("click", generateClicked);
137 DOM.more.on("click", showMore); 138 DOM.more.on("click", showMore);
139 DOM.seed.on("input", delayedSeedChanged);
138 DOM.rootKey.on("input", delayedRootKeyChanged); 140 DOM.rootKey.on("input", delayedRootKeyChanged);
139 DOM.litecoinUseLtub.on("change", litecoinUseLtubChanged); 141 DOM.litecoinUseLtub.on("change", litecoinUseLtubChanged);
140 DOM.bip32path.on("input", calcForDerivationPath); 142 DOM.bip32path.on("input", calcForDerivationPath);
@@ -340,6 +342,30 @@
340 entropyChanged(); 342 entropyChanged();
341 } 343 }
342 344
345 function delayedSeedChanged() {
346 // Warn if there is an existing mnemonic or passphrase.
347 if (DOM.phrase.val().length > 0 || DOM.passphrase.val().length > 0) {
348 if (!confirm("This will clear existing mnemonic and passphrase")) {
349 DOM.seed.val(seed);
350 return
351 }
352 }
353 hideValidationError();
354 showPending();
355 // Clear existing mnemonic and passphrase
356 DOM.phrase.val("");
357 DOM.phraseSplit.val("");
358 DOM.passphrase.val("");
359 DOM.rootKey.val("");
360 clearAddressesList();
361 clearDerivedKeys();
362 seed = null;
363 if (seedChangedTimeoutEvent != null) {
364 clearTimeout(seedChangedTimeoutEvent);
365 }
366 seedChangedTimeoutEvent = setTimeout(seedChanged, 400);
367 }
368
343 function delayedRootKeyChanged() { 369 function delayedRootKeyChanged() {
344 // Warn if there is an existing mnemonic or passphrase. 370 // Warn if there is an existing mnemonic or passphrase.
345 if (DOM.phrase.val().length > 0 || DOM.passphrase.val().length > 0) { 371 if (DOM.phrase.val().length > 0 || DOM.passphrase.val().length > 0) {
@@ -361,6 +387,22 @@
361 rootKeyChangedTimeoutEvent = setTimeout(rootKeyChanged, 400); 387 rootKeyChangedTimeoutEvent = setTimeout(rootKeyChanged, 400);
362 } 388 }
363 389
390 function seedChanged() {
391 showPending();
392 hideValidationError();
393 seed = DOM.seed.val();
394 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromSeedHex(seed, network);
395 var rootKeyBase58 = bip32RootKey.toBase58();
396 DOM.rootKey.val(rootKeyBase58);
397 var errorText = validateRootKey(rootKeyBase58);
398 if (errorText) {
399 showValidationError(errorText);
400 return;
401 }
402 // Calculate and display
403 calcForDerivationPath();
404 }
405
364 function rootKeyChanged() { 406 function rootKeyChanged() {
365 showPending(); 407 showPending();
366 hideValidationError(); 408 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) {
4336 }); 4336 });
4337}); 4337});
4338 4338
4339// https://github.com/iancoleman/bip39/issues/388
4340// Make field for bip39 seed editable
4341it('Generates addresses when seed is set', function(done) {
4342 driver.findElement(By.css('.seed'))
4343 .sendKeys("20da140d3dd1df8713cefcc4d54ce0e445b4151027a1ab567b832f6da5fcc5afc1c3a3f199ab78b8e0ab4652efd7f414ac2c9a3b81bceb879a70f377aa0a58f3");
4344 driver.sleep(generateDelay).then(function() {
4345 getFirstAddress(function(address) {
4346 expect(address).toBe("1Di3Vp7tBWtyQaDABLAjfWtF6V7hYKJtug");
4347 done();
4348 });
4349 });
4350});
4351
4339}); 4352});