X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fjs%2Findex.js;h=da901f6af65a4739f11796f938ddc6aad7a8d2d8;hb=3dbf117928bb17d58cc54fa1faa9354c014e665b;hp=3afa598b39238553cd1dfc926f4ecf82e3660a00;hpb=9f675f2e47f371d2d09bf90f03a2e09ec62a10c4;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/src/js/index.js b/src/js/index.js index 3afa598..da901f6 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -232,7 +232,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() { @@ -488,9 +495,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()) { @@ -525,6 +539,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) { @@ -595,6 +644,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()) { @@ -635,6 +687,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); @@ -745,6 +838,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); @@ -888,6 +985,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(); @@ -898,9 +998,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 @@ -959,6 +1064,11 @@ 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(); @@ -1005,6 +1115,23 @@ 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(); @@ -1691,6 +1818,13 @@ setHdCoin(161); }, }, + { + name: "ARYA - Aryacoin", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.aryacoin; + setHdCoin(357); + }, + }, { name: "AUR - Auroracoin", onSelect: function() { @@ -1824,6 +1958,13 @@ setHdCoin(183); }, }, + { + name: "BSV - BitcoinSV", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.bitcoinsv; + setHdCoin(236); + }, + }, { name: "BTCZ - Bitcoinz", onSelect: function() { @@ -1930,6 +2071,13 @@ setHdCoin(72); }, }, + { + name: "CSC - CasinoCoin", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.bitcoin; + setHdCoin(359); + }, + }, { name: "DASH - Dash", onSelect: function() { @@ -2165,6 +2313,20 @@ setHdCoin(84); }, }, + { + name: "GRS - Groestlcoin", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.groestlcoin; + setHdCoin(17); + }, + }, + { + name: "GRS - Groestlcoin Testnet", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.groestlcointestnet; + setHdCoin(1); + }, + }, { name: "HNC - Helleniccoin", onSelect: function() { @@ -2173,11 +2335,18 @@ }, }, { - name: "HUSH - Hush", + name: "HUSH - Hush (Legacy)", onSelect: function() { network = bitcoinjs.bitcoin.networks.hush; setHdCoin(197); }, + }, + { + name: "HUSH - Hush3", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.hush3; + setHdCoin(197); + }, }, { name: "INSN - Insane", @@ -2325,6 +2494,13 @@ setHdCoin(22); }, }, + { + name: "MONK - Monkey Project", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.monkeyproject, + setHdCoin(214); + }, + }, { name: "MUSIC - Musicoin", segwitAvailable: false, @@ -2531,6 +2707,13 @@ setHdCoin(122); }, }, + { + name: "RPD - Rapids", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.rapids; + setHdCoin(320); + }, + }, { name: "RVN - Ravencoin", onSelect: function() { @@ -2848,7 +3031,7 @@ }, }, { - name: "ZEN - Zencash", + name: "ZEN - Horizen", onSelect: function() { network = bitcoinjs.bitcoin.networks.zencash; setHdCoin(121);