From: iancoleman <1281387+iancoleman@users.noreply.github.com> Date: Sun, 10 Nov 2019 22:28:28 +0000 (+1100) Subject: Merge pull request #279 from mctrivia/master X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git;a=commitdiff_plain;h=d0428a8d211dd5914c4c8547c69c75aca4cccfd6;hp=-c Merge pull request #279 from mctrivia/master Added Split Phrase Card Output --- d0428a8d211dd5914c4c8547c69c75aca4cccfd6 diff --combined src/index.html index 95fccc1,1d67340..8862904 --- a/src/index.html +++ b/src/index.html @@@ -15,7 -15,7 +15,7 @@@

Mnemonic Code Converter

-

v0.3.9

+

v0.3.12


@@@ -69,7 -69,7 +69,7 @@@
- +
- +
@@@ -748,6 -754,14 +754,6 @@@ Read more at the official BIP49 spec

-

Private Keys

-

- - Use private keys at - brainwallet.org. - - Be careful - it can be easy to make mistakes if you don't know what you're doing. -

Entropy

Entropy values should not include the BIP39 checksum. This is automatically added by the tool. @@@ -926,10 -940,7 +932,10 @@@ + + + @@@ -943,9 -954,6 +949,9 @@@ + + + diff --combined src/js/index.js index da901f6,a778799..035a2b3 --- a/src/js/index.js +++ b/src/js/index.js @@@ -44,6 -44,7 +44,7 @@@ DOM.entropyWeakEntropyOverrideWarning = DOM.entropyContainer.find(".weak-entropy-override-warning"); DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning"); DOM.phrase = $(".phrase"); + DOM.splitPhrase = $(".phraseSplit"); DOM.passphrase = $(".passphrase"); DOM.generateContainer = $(".generate-container"); DOM.generate = $(".generate"); @@@ -232,14 -233,7 +233,14 @@@ if (phraseChangeTimeoutEvent != null) { clearTimeout(phraseChangeTimeoutEvent); } - phraseChangeTimeoutEvent = setTimeout(phraseChanged, 400); + phraseChangeTimeoutEvent = setTimeout(function() { + phraseChanged(); + var entropy = mnemonic.toRawEntropyHex(DOM.phrase.val()); + if (entropy !== null) { + DOM.entropyMnemonicLength.val("raw"); + DOM.entropy.val(entropy); + } + }, 400); } function phraseChanged() { @@@ -304,6 -298,7 +305,7 @@@ clearDisplay(); clearEntropyFeedback(); DOM.phrase.val(""); + DOM.phraseSplit.val(""); showValidationError("Blank entropy"); return; } @@@ -338,6 -333,7 +340,7 @@@ showPending(); // Clear existing mnemonic and passphrase DOM.phrase.val(""); + DOM.phraseSplit.val(""); DOM.passphrase.val(""); seed = null; if (rootKeyChangedTimeoutEvent != null) { @@@ -424,6 -420,7 +427,7 @@@ if (DOM.phrase.val().length > 0) { var newPhrase = convertPhraseToNewLanguage(); DOM.phrase.val(newPhrase); + writeSplitPhrase(newPhrase); phraseChanged(); } else { @@@ -484,6 -481,7 +488,7 @@@ // show the words var words = mnemonic.toMnemonic(data); DOM.phrase.val(words); + writeSplitPhrase(words); // show the entropy var entropyHex = uint8ArrayToHex(data); DOM.entropy.val(entropyHex); @@@ -495,16 -493,9 +500,16 @@@ function calcBip32RootKeyFromSeed(phrase, passphrase) { seed = mnemonic.toSeed(phrase, passphrase); bip32RootKey = bitcoinjs.bitcoin.HDNode.fromSeedHex(seed, network); + if(isGRS()) + bip32RootKey = groestlcoinjs.HDNode.fromSeedHex(seed, network); + } function calcBip32RootKeyFromBase58(rootKeyBase58) { + if(isGRS()) { + calcBip32RootKeyFromBase58GRS(rootKeyBase58); + return; + } // try parsing with various segwit network params since this extended // key may be from any one of them. if (networkHasSegwit()) { @@@ -539,41 -530,6 +544,41 @@@ bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, network); } + function calcBip32RootKeyFromBase58GRS(rootKeyBase58) { + // try parsing with various segwit network params since this extended + // key may be from any one of them. + if (networkHasSegwit()) { + var n = network; + if ("baseNetwork" in n) { + n = bitcoinjs.bitcoin.networks[n.baseNetwork]; + } + // try parsing using base network params + try { + bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n); + return; + } + catch (e) {} + // try parsing using p2wpkh params + if ("p2wpkh" in n) { + try { + bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkh); + return; + } + catch (e) {} + } + // try parsing using p2wpkh-in-p2sh network params + if ("p2wpkhInP2sh" in n) { + try { + bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkhInP2sh); + return; + } + catch (e) {} + } + } + // try the network params as currently specified + bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, network); + } + function calcBip32ExtendedKey(path) { // Check there's a root key to derive from if (!bip32RootKey) { @@@ -644,9 -600,6 +649,9 @@@ } function validateRootKey(rootKeyBase58) { + if(isGRS()) + return validateRootKeyGRS(rootKeyBase58); + // try various segwit network params since this extended key may be from // any one of them. if (networkHasSegwit()) { @@@ -687,47 -640,6 +692,47 @@@ return ""; } + function validateRootKeyGRS(rootKeyBase58) { + // try various segwit network params since this extended key may be from + // any one of them. + if (networkHasSegwit()) { + var n = network; + if ("baseNetwork" in n) { + n = bitcoinjs.bitcoin.networks[n.baseNetwork]; + } + // try parsing using base network params + try { + groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n); + return ""; + } + catch (e) {} + // try parsing using p2wpkh params + if ("p2wpkh" in n) { + try { + groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkh); + return ""; + } + catch (e) {} + } + // try parsing using p2wpkh-in-p2sh network params + if ("p2wpkhInP2sh" in n) { + try { + groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkhInP2sh); + return ""; + } + catch (e) {} + } + } + // try the network params as currently specified + try { + groestlcoinjs.HDNode.fromBase58(rootKeyBase58, network); + } + catch (e) { + return "Invalid root key"; + } + return ""; + } + function getDerivationPath() { if (bip44TabSelected()) { var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44); @@@ -838,10 -750,6 +843,10 @@@ return false; } + function isGRS() { + return networks[DOM.network.val()].name == "GRS - Groestlcoin" || networks[DOM.network.val()].name == "GRS - Groestlcoin Testnet"; + } + function displayBip44Info() { // Get the derivation path for the account var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44); @@@ -985,9 -893,6 +990,9 @@@ var useUncompressed = useBip38; if (useUncompressed) { keyPair = new bitcoinjs.bitcoin.ECPair(keyPair.d, null, { network: network, compressed: false }); + if(isGRS()) + keyPair = new groestlcoinjs.ECPair(keyPair.d, null, { network: network, compressed: false }); + } // get address var address = keyPair.getAddress().toString(); @@@ -998,14 -903,9 +1003,14 @@@ privkey = keyPair.toWIF(); // BIP38 encode private key if required if (useBip38) { - privkey = bitcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) { - console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index); - }); + if(isGRS()) + privkey = groestlcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) { + console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index); + }, null, networks[DOM.network.val()].name.includes("Testnet")); + else + privkey = bitcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) { + console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index); + }); } } // get pubkey @@@ -1022,12 -922,7 +1027,12 @@@ || (networks[DOM.network.val()].name == "MUSIC - Musicoin") || (networks[DOM.network.val()].name == "POA - Poa") || (networks[DOM.network.val()].name == "EXP - Expanse") - || (networks[DOM.network.val()].name == "CLO - Callisto")) { + || (networks[DOM.network.val()].name == "CLO - Callisto") + || (networks[DOM.network.val()].name == "DXN - DEXON") + || (networks[DOM.network.val()].name == "ELLA - Ellaism") + || (networks[DOM.network.val()].name == "ESN - Ethersocial Network") + || (networks[DOM.network.val()].name == "VET - VeChain") + ) { var privKeyBuffer = keyPair.d.toBuffer(32); privkey = privKeyBuffer.toString('hex'); var addressBuffer = ethUtil.privateToAddress(privKeyBuffer); @@@ -1037,38 -932,11 +1042,38 @@@ privkey = ethUtil.addHexPrefix(privkey); pubkey = ethUtil.addHexPrefix(pubkey); } + + // Stellar is different + if (networks[DOM.network.val()].name == "XLM - Stellar") { + var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44); + var coin = parseIntNoNaN(DOM.bip44coin.val(), 0); + var path = "m/"; + path += purpose + "'/"; + path += coin + "'/" + index + "'"; + var keypair = stellarUtil.getKeypair(path, seed); + indexText = path; + privkey = keypair.secret(); + pubkey = address = keypair.publicKey(); + } + if ((networks[DOM.network.val()].name == "NAS - Nebulas")) { + var NasAccount = require("nebulas-account"); + var privKeyBuffer = keyPair.d.toBuffer(32); + var nebulasAccount = new NasAccount(); + nebulasAccount.setPrivateKey(privKeyBuffer); + address = nebulasAccount.getAddressString(); + privkey = nebulasAccount.getPrivateKeyString(); + pubkey = nebulasAccount.getPublicKeyString(); + } // Ripple values are different if (networks[DOM.network.val()].name == "XRP - Ripple") { privkey = convertRipplePriv(privkey); address = convertRippleAdrr(address); } + // CasinoCoin values are different + if (networks[DOM.network.val()].name == "CSC - CasinoCoin") { + privkey = convertCasinoCoinPriv(privkey); + address = convertCasinoCoinAdrr(address); + } // Bitcoin Cash address format may vary if (networks[DOM.network.val()].name == "BCH - Bitcoin Cash") { var bchAddrType = DOM.bitcoinCashAddressType.filter(":checked").val(); @@@ -1079,13 -947,6 +1084,13 @@@ address = bchaddr.toBitpayAddress(address); } } + // Bitcoin Cash address format may vary + if (networks[DOM.network.val()].name == "SLP - Simple Ledger Protocol") { + var bchAddrType = DOM.bitcoinCashAddressType.filter(":checked").val(); + if (bchAddrType == "cashaddr") { + address = bchaddr.toSlpAddress(address); + } + } // Segwit addresses are different if (isSegwit) { if (!segwitAvailable) { @@@ -1104,34 -965,6 +1109,34 @@@ address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network) } } + + if ((networks[DOM.network.val()].name == "CRW - Crown")) { + address = bitcoinjs.bitcoin.networks.crown.toNewAddress(address); + } + + if (networks[DOM.network.val()].name == "EOS - EOSIO") { + address = "" + pubkey = eosUtil.bufferToPublic(keyPair.getPublicKeyBuffer()); + privkey = eosUtil.bufferToPrivate(keyPair.d.toBuffer(32)); + } + + //Groestlcoin Addresses are different + if(isGRS()) { + + if (isSegwit) { + if (!segwitAvailable) { + return; + } + if (isP2wpkh) { + address = groestlcoinjs.address.fromOutputScript(scriptpubkey, network) + } + else if (isP2wpkhInP2sh) { + address = groestlcoinjs.address.fromOutputScript(scriptpubkey, network) + } + } + //non-segwit addresses are handled by using groestlcoinjs for bip32RootKey + } + addAddressToList(indexText, address, pubkey, privkey); if (isLast) { hidePending(); @@@ -1422,6 -1255,28 +1427,28 @@@ } return phrase; } + + function writeSplitPhrase(phrase) { + var wordCount = phrase.split(/\s/g).length; //get number of words in phrase + var left=[]; //initialize array of indexs + for (var i=0;i0) { //while indexs left + groupI=(groupI+1)%3; //get next group to insert index into + seed = seed * 16807 % 2147483647; //change random value.(simple predicatable random number generator works well for this use) + var selected=Math.floor(left.length*(seed - 1) / 2147483646); //get index in left we will use for this group + group[groupI].push(left[selected]); //add index to group + left.splice(selected,1); //remove selected index + } + var cards=[phrase.split(/\s/g),phrase.split(/\s/g),phrase.split(/\s/g)];//make array of cards + for (var i=0;i<3;i++) { //go through each card + for (var ii=0;ii