X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fjs%2Findex.js;h=f13063cdc5b0ee6cec1190776194b2a03e4d5e6e;hb=d00c719932123feb4135b4ef537b28e8eb735cd5;hp=261a6d19c43005d77809bae797f7f1726fdbee0e;hpb=c49e881294343b762109bb8104e7c1b45898c894;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/src/js/index.js b/src/js/index.js index 261a6d1..f13063c 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -37,6 +37,7 @@ DOM.entropyBitsPerEvent = DOM.entropyContainer.find(".bits-per-event"); DOM.entropyWordCount = DOM.entropyContainer.find(".word-count"); DOM.entropyBinary = DOM.entropyContainer.find(".binary"); + DOM.entropyWordIndexes = DOM.entropyContainer.find(".word-indexes"); DOM.entropyMnemonicLength = DOM.entropyContainer.find(".mnemonic-length"); DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning"); DOM.phrase = $(".phrase"); @@ -219,6 +220,8 @@ var passphrase = DOM.passphrase.val(); calcBip32RootKeyFromSeed(phrase, passphrase); calcForDerivationPath(); + // Show the word indexes + showWordIndexes(); } function tabChanged() { @@ -420,10 +423,20 @@ showValidationError(errorText); return; } + // get the amount of entropy to use var numWords = parseInt(DOM.generatedStrength.val()); var strength = numWords / 3 * 32; - var words = mnemonic.generate(strength); + var buffer = new Uint8Array(strength / 8); + // create secure entropy + var data = crypto.getRandomValues(buffer); + // show the words + var words = mnemonic.toMnemonic(data); DOM.phrase.val(words); + // show the entropy + var entropyHex = uint8ArrayToHex(data); + DOM.entropy.val(entropyHex); + // ensure entropy fields are consistent with what is being displayed + DOM.entropyMnemonicLength.val("raw"); return words; } @@ -768,6 +781,7 @@ address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network) } } + console.log(address); addAddressToList(indexText, address, pubkey, privkey); if (isLast) { hidePending(); @@ -1103,6 +1117,8 @@ var phrase = mnemonic.toMnemonic(entropyArr); // Set the mnemonic in the UI DOM.phrase.val(phrase); + // Show the word indexes + showWordIndexes(); } function clearEntropyFeedback() { @@ -1225,8 +1241,13 @@ function createQr(e) { var content = e.target.textContent || e.target.value; if (content) { - var size = 130; - DOM.qrImage.qrcode({width: size, height: size, text: content}); + var qrEl = kjua({ + text: content, + render: "canvas", + size: 310, + ecLevel: 'H', + }); + DOM.qrImage.append(qrEl); if (!showQr) { DOM.qrHider.addClass("hidden"); } @@ -1328,6 +1349,32 @@ return parseInt(lastBitClean); } + function uint8ArrayToHex(a) { + var s = "" + for (var i=0; i