X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fjs%2Findex.js;h=3148ca49bcd2993b8aa6d6d813abeebade70d58e;hb=8017442c509ef1fa545367e727608bdc91bc1504;hp=3db0a31938fe8c093187c8dbace172093c42ece5;hpb=516c16d721db88b4b2c39964e2d5e8f6310c7bff;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/src/js/index.js b/src/js/index.js index 3db0a31..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); @@ -239,10 +241,12 @@ } phraseChangeTimeoutEvent = setTimeout(function() { phraseChanged(); - var entropy = mnemonic.toRawEntropyBin(DOM.phrase.val()); + var entropy = mnemonic.toRawEntropyHex(DOM.phrase.val()); if (entropy !== null) { DOM.entropyMnemonicLength.val("raw"); DOM.entropy.val(entropy); + DOM.entropyTypeInputs.filter("[value='hexadecimal']").prop("checked", true); + entropyTypeAutoDetect = false; } }, 400); } @@ -338,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) { @@ -359,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(); @@ -2097,6 +2141,15 @@ setHdCoin(0); }, }, + { + name: "BTC - Bitcoin RegTest", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.regtest; + // Using hd coin value 1 based on bip44_coin_type + // https://github.com/chaintope/bitcoinrb/blob/f1014406f6b8f9b4edcecedc18df70c80df06f11/lib/bitcoin/chainparams/regtest.yml + setHdCoin(1); + }, + }, { name: "BTC - Bitcoin Testnet", onSelect: function() {