X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2Fjs%2Findex.js;h=f3302a64bfee229566ff574b82f474ad6db82773;hb=76120cb0b42530e3a40476272c1edbeac679db35;hp=6428aa7bec17d39fb84e3cbb1ad59ef17450be94;hpb=2885ddd5f7d6dbe6211fd699e58ce0da6ac6295c;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/src/js/index.js b/src/js/index.js index 6428aa7..f3302a6 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -488,9 +488,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 +532,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 +637,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 +680,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 +831,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 +978,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 +991,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 @@ -920,6 +1018,8 @@ || (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'); @@ -930,6 +1030,19 @@ 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); @@ -944,6 +1057,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(); @@ -979,11 +1097,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(); @@ -1670,6 +1811,13 @@ setHdCoin(161); }, }, + { + name: "ARYA - Aryacoin", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.aryacoin; + setHdCoin(357); + }, + }, { name: "AUR - Auroracoin", onSelect: function() { @@ -1691,6 +1839,13 @@ setHdCoin(220); }, }, + { + name: "BOLI - Bolivarcoin", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.bolivarcoin; + setHdCoin(278); + }, + }, { name: "BCA - Bitcoin Atom", onSelect: function() { @@ -1796,6 +1951,13 @@ setHdCoin(183); }, }, + { + name: "BSV - BitcoinSV", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.bitcoinsv; + setHdCoin(236); + }, + }, { name: "BTCZ - Bitcoinz", onSelect: function() { @@ -1874,6 +2036,13 @@ setHdCoin(71); }, }, + { + name: "CPU - CPUchain", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.cpuchain; + setHdCoin(363); + }, + }, { name: "CRAVE - Crave", onSelect: function() { @@ -1895,6 +2064,13 @@ setHdCoin(72); }, }, + { + name: "CSC - CasinoCoin", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.bitcoin; + setHdCoin(359); + }, + }, { name: "DASH - Dash", onSelect: function() { @@ -1951,6 +2127,13 @@ setHdCoin(3); }, }, + { + name: "DOGEt - Dogecoin Testnet", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.dogecointestnet; + setHdCoin(1); + }, + }, { name: "DXN - DEXON", onSelect: function() { @@ -2001,6 +2184,21 @@ setHdCoin(151); }, }, + { + name: "EOS - EOSIO", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.bitcoin; + setHdCoin(194); + }, + }, + { + name: "ESN - Ethersocial Network", + segwitAvailable: false, + onSelect: function() { + network = bitcoinjs.bitcoin.networks.bitcoin; + setHdCoin(31102); + }, + }, { name: "ETC - Ethereum Classic", segwitAvailable: false, @@ -2038,6 +2236,20 @@ setHdCoin(40); }, }, + { + name: "FIX - FIX", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.fix; + setHdCoin(336); + }, + }, + { + name: "FIX - FIX Testnet", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.fixtestnet; + setHdCoin(1); + }, + }, { name: "FJC - Fujicoin", onSelect: function() { @@ -2094,6 +2306,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() { @@ -2102,11 +2328,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", @@ -2196,6 +2429,14 @@ DOM.litecoinLtubContainer.removeClass("hidden"); }, }, + { + name: "LTCt - Litecoin Testnet", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.litecointestnet; + setHdCoin(1); + DOM.litecoinLtubContainer.removeClass("hidden"); + }, + }, { name: "LTZ - LitecoinZ", onSelect: function() { @@ -2246,6 +2487,13 @@ setHdCoin(22); }, }, + { + name: "MONK - Monkey Project", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.monkeyproject, + setHdCoin(214); + }, + }, { name: "MUSIC - Musicoin", segwitAvailable: false, @@ -2352,6 +2600,13 @@ setHdCoin(200); }, }, + { + name: "ONION - DeepOnion", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.deeponion; + setHdCoin(305); + }, + }, { name: "ONX - Onixcoin", onSelect: function() { @@ -2445,6 +2700,13 @@ setHdCoin(122); }, }, + { + name: "RPD - Rapids", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.rapids; + setHdCoin(320); + }, + }, { name: "RVN - Ravencoin", onSelect: function() { @@ -2585,6 +2847,20 @@ setHdCoin(159); }, }, + { + name: "TWINS - TWINS", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.twins; + setHdCoin(970); + }, + }, + { + name: "TWINS - TWINS Testnet", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.twinstestnet; + setHdCoin(1); + }, + }, { name: "USC - Ultimatesecurecash", onSelect: function() { @@ -2613,6 +2889,13 @@ setHdCoin(33); }, }, + { + name: "VET - VeChain", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.bitcoin; + setHdCoin(818); + }, + }, { name: "VIA - Viacoin", onSelect: function() { @@ -2641,6 +2924,13 @@ setHdCoin(28); }, }, + { + name: "WGR - Wagerr", + onSelect: function() { + network = bitcoinjs.bitcoin.networks.wagerr; + setHdCoin(7825266); + }, + }, { name: "WC - Wincoin", onSelect: function() { @@ -2662,6 +2952,13 @@ setHdCoin(65); }, }, + { + name: "XLM - Stellar", + onSelect: function() { + network = stellarUtil.dummyNetwork; + setHdCoin(148); + }, + }, { name: "XMY - Myriadcoin", onSelect: function() { @@ -2727,7 +3024,7 @@ }, }, { - name: "ZEN - Zencash", + name: "ZEN - Horizen", onSelect: function() { network = bitcoinjs.bitcoin.networks.zencash; setHdCoin(121);