X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fjs%2Findex.js;h=3db0a31938fe8c093187c8dbace172093c42ece5;hb=516c16d721db88b4b2c39964e2d5e8f6310c7bff;hp=db4741256e30ba66b0873800013db5333f364793;hpb=5c203fab6ac25fc76e2b805b7709d9b06ccdd995;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/src/js/index.js b/src/js/index.js index db47412..3db0a31 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -16,6 +16,7 @@ var showQr = false; var litecoinUseLtub = true; + var entropyTypeAutoDetect = true; var entropyChangeTimeoutEvent = null; var phraseChangeTimeoutEvent = null; var rootKeyChangedTimeoutEvent = null; @@ -32,6 +33,7 @@ DOM.entropy = $(".entropy"); DOM.entropyFiltered = DOM.entropyContainer.find(".filtered"); DOM.entropyType = DOM.entropyContainer.find(".type"); + DOM.entropyTypeInputs = DOM.entropyContainer.find("input[name='entropy-type']"); DOM.entropyCrackTime = DOM.entropyContainer.find(".crack-time"); DOM.entropyEventCount = DOM.entropyContainer.find(".event-count"); DOM.entropyBits = DOM.entropyContainer.find(".bits"); @@ -128,6 +130,7 @@ DOM.useEntropy.on("change", setEntropyVisibility); DOM.entropy.on("input", delayedEntropyChanged); DOM.entropyMnemonicLength.on("change", entropyChanged); + DOM.entropyTypeInputs.on("change", entropyTypeChanged); DOM.phrase.on("input", delayedPhraseChanged); DOM.passphrase.on("input", delayedPhraseChanged); DOM.generate.on("click", generateClicked); @@ -330,6 +333,11 @@ } } + function entropyTypeChanged() { + entropyTypeAutoDetect = false; + entropyChanged(); + } + function delayedRootKeyChanged() { // Warn if there is an existing mnemonic or passphrase. if (DOM.phrase.val().length > 0 || DOM.passphrase.val().length > 0) { @@ -1152,12 +1160,19 @@ address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network) } else if (isP2wsh) { - // TODO - address = ""; + // https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/test/integration/addresses.js#L71 + // This is a 1-of-1 + var witnessScript = bitcoinjs.bitcoin.script.multisig.output.encode(1, [key.getPublicKeyBuffer()]); + var scriptPubKey = bitcoinjs.bitcoin.script.witnessScriptHash.output.encode(bitcoinjs.bitcoin.crypto.sha256(witnessScript)); + address = bitcoinjs.bitcoin.address.fromOutputScript(scriptPubKey, network); } else if (isP2wshInP2sh) { - // TODO - address = ""; + // https://github.com/bitcoinjs/bitcoinjs-lib/blob/v3.3.2/test/integration/transactions.js#L183 + // This is a 1-of-1 + var witnessScript = bitcoinjs.bitcoin.script.multisig.output.encode(1, [key.getPublicKeyBuffer()]); + var redeemScript = bitcoinjs.bitcoin.script.witnessScriptHash.output.encode(bitcoinjs.bitcoin.crypto.sha256(witnessScript)); + var scriptPubKey = bitcoinjs.bitcoin.script.scriptHash.output.encode(bitcoinjs.bitcoin.crypto.hash160(redeemScript)); + address = bitcoinjs.bitcoin.address.fromOutputScript(scriptPubKey, network) } } @@ -1544,7 +1559,14 @@ // Get entropy value var entropyStr = DOM.entropy.val(); // Work out minimum base for entropy - var entropy = Entropy.fromString(entropyStr); + var entropy = null; + if (entropyTypeAutoDetect) { + entropy = Entropy.fromString(entropyStr); + } + else { + let base = DOM.entropyTypeInputs.filter(":checked").val(); + entropy = Entropy.fromString(entropyStr, base); + } if (entropy.binaryStr.length == 0) { return; } @@ -1625,6 +1647,8 @@ console.log(e); } var entropyTypeStr = getEntropyTypeStr(entropy); + DOM.entropyTypeInputs.attr("checked", false); + DOM.entropyTypeInputs.filter("[value='" + entropyTypeStr + "']").attr("checked", true); var wordCount = Math.floor(numberOfBits / 32) * 3; var bitsPerEvent = entropy.bitsPerEvent.toFixed(2); var spacedBinaryStr = addSpacesEveryElevenBits(entropy.binaryStr);