aboutsummaryrefslogtreecommitdiff
path: root/src/js/index.js
diff options
context:
space:
mode:
authoriancoleman <1281387+iancoleman@users.noreply.github.com>2019-09-16 10:46:32 +1000
committerGitHub <noreply@github.com>2019-09-16 10:46:32 +1000
commitbc32c841663821ba94c12afc5a7e73d689c7b153 (patch)
tree11d636d9e8f8708dd5532e449d1e3dec71bd13ea /src/js/index.js
parent5b689bd6e77f047eff37e43f0ffa487cb59edc45 (diff)
parent76120cb0b42530e3a40476272c1edbeac679db35 (diff)
downloadBIP39-bc32c841663821ba94c12afc5a7e73d689c7b153.tar.gz
BIP39-bc32c841663821ba94c12afc5a7e73d689c7b153.tar.zst
BIP39-bc32c841663821ba94c12afc5a7e73d689c7b153.zip
Merge pull request #353 from Groestlcoin/add-groestlcoin
Add Groestlcoin with Tests
Diffstat (limited to 'src/js/index.js')
-rw-r--r--src/js/index.js135
1 files changed, 132 insertions, 3 deletions
diff --git a/src/js/index.js b/src/js/index.js
index fff1e40..f3302a6 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -488,9 +488,16 @@
488 function calcBip32RootKeyFromSeed(phrase, passphrase) { 488 function calcBip32RootKeyFromSeed(phrase, passphrase) {
489 seed = mnemonic.toSeed(phrase, passphrase); 489 seed = mnemonic.toSeed(phrase, passphrase);
490 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromSeedHex(seed, network); 490 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromSeedHex(seed, network);
491 if(isGRS())
492 bip32RootKey = groestlcoinjs.HDNode.fromSeedHex(seed, network);
493
491 } 494 }
492 495
493 function calcBip32RootKeyFromBase58(rootKeyBase58) { 496 function calcBip32RootKeyFromBase58(rootKeyBase58) {
497 if(isGRS()) {
498 calcBip32RootKeyFromBase58GRS(rootKeyBase58);
499 return;
500 }
494 // try parsing with various segwit network params since this extended 501 // try parsing with various segwit network params since this extended
495 // key may be from any one of them. 502 // key may be from any one of them.
496 if (networkHasSegwit()) { 503 if (networkHasSegwit()) {
@@ -525,6 +532,41 @@
525 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, network); 532 bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, network);
526 } 533 }
527 534
535 function calcBip32RootKeyFromBase58GRS(rootKeyBase58) {
536 // try parsing with various segwit network params since this extended
537 // key may be from any one of them.
538 if (networkHasSegwit()) {
539 var n = network;
540 if ("baseNetwork" in n) {
541 n = bitcoinjs.bitcoin.networks[n.baseNetwork];
542 }
543 // try parsing using base network params
544 try {
545 bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n);
546 return;
547 }
548 catch (e) {}
549 // try parsing using p2wpkh params
550 if ("p2wpkh" in n) {
551 try {
552 bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkh);
553 return;
554 }
555 catch (e) {}
556 }
557 // try parsing using p2wpkh-in-p2sh network params
558 if ("p2wpkhInP2sh" in n) {
559 try {
560 bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkhInP2sh);
561 return;
562 }
563 catch (e) {}
564 }
565 }
566 // try the network params as currently specified
567 bip32RootKey = groestlcoinjs.HDNode.fromBase58(rootKeyBase58, network);
568 }
569
528 function calcBip32ExtendedKey(path) { 570 function calcBip32ExtendedKey(path) {
529 // Check there's a root key to derive from 571 // Check there's a root key to derive from
530 if (!bip32RootKey) { 572 if (!bip32RootKey) {
@@ -595,6 +637,9 @@
595 } 637 }
596 638
597 function validateRootKey(rootKeyBase58) { 639 function validateRootKey(rootKeyBase58) {
640 if(isGRS())
641 return validateRootKeyGRS(rootKeyBase58);
642
598 // try various segwit network params since this extended key may be from 643 // try various segwit network params since this extended key may be from
599 // any one of them. 644 // any one of them.
600 if (networkHasSegwit()) { 645 if (networkHasSegwit()) {
@@ -635,6 +680,47 @@
635 return ""; 680 return "";
636 } 681 }
637 682
683 function validateRootKeyGRS(rootKeyBase58) {
684 // try various segwit network params since this extended key may be from
685 // any one of them.
686 if (networkHasSegwit()) {
687 var n = network;
688 if ("baseNetwork" in n) {
689 n = bitcoinjs.bitcoin.networks[n.baseNetwork];
690 }
691 // try parsing using base network params
692 try {
693 groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n);
694 return "";
695 }
696 catch (e) {}
697 // try parsing using p2wpkh params
698 if ("p2wpkh" in n) {
699 try {
700 groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkh);
701 return "";
702 }
703 catch (e) {}
704 }
705 // try parsing using p2wpkh-in-p2sh network params
706 if ("p2wpkhInP2sh" in n) {
707 try {
708 groestlcoinjs.HDNode.fromBase58(rootKeyBase58, n.p2wpkhInP2sh);
709 return "";
710 }
711 catch (e) {}
712 }
713 }
714 // try the network params as currently specified
715 try {
716 groestlcoinjs.HDNode.fromBase58(rootKeyBase58, network);
717 }
718 catch (e) {
719 return "Invalid root key";
720 }
721 return "";
722 }
723
638 function getDerivationPath() { 724 function getDerivationPath() {
639 if (bip44TabSelected()) { 725 if (bip44TabSelected()) {
640 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44); 726 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
@@ -745,6 +831,10 @@
745 return false; 831 return false;
746 } 832 }
747 833
834 function isGRS() {
835 return networks[DOM.network.val()].name == "GRS - Groestlcoin" || networks[DOM.network.val()].name == "GRS - Groestlcoin Testnet";
836 }
837
748 function displayBip44Info() { 838 function displayBip44Info() {
749 // Get the derivation path for the account 839 // Get the derivation path for the account
750 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44); 840 var purpose = parseIntNoNaN(DOM.bip44purpose.val(), 44);
@@ -888,6 +978,9 @@
888 var useUncompressed = useBip38; 978 var useUncompressed = useBip38;
889 if (useUncompressed) { 979 if (useUncompressed) {
890 keyPair = new bitcoinjs.bitcoin.ECPair(keyPair.d, null, { network: network, compressed: false }); 980 keyPair = new bitcoinjs.bitcoin.ECPair(keyPair.d, null, { network: network, compressed: false });
981 if(isGRS())
982 keyPair = new groestlcoinjs.ECPair(keyPair.d, null, { network: network, compressed: false });
983
891 } 984 }
892 // get address 985 // get address
893 var address = keyPair.getAddress().toString(); 986 var address = keyPair.getAddress().toString();
@@ -898,9 +991,14 @@
898 privkey = keyPair.toWIF(); 991 privkey = keyPair.toWIF();
899 // BIP38 encode private key if required 992 // BIP38 encode private key if required
900 if (useBip38) { 993 if (useBip38) {
901 privkey = bitcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) { 994 if(isGRS())
902 console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index); 995 privkey = groestlcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) {
903 }); 996 console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index);
997 }, null, networks[DOM.network.val()].name.includes("Testnet"));
998 else
999 privkey = bitcoinjsBip38.encrypt(keyPair.d.toBuffer(), false, bip38password, function(p) {
1000 console.log("Progressed " + p.percent.toFixed(1) + "% for index " + index);
1001 });
904 } 1002 }
905 } 1003 }
906 // get pubkey 1004 // get pubkey
@@ -1010,6 +1108,23 @@
1010 privkey = eosUtil.bufferToPrivate(keyPair.d.toBuffer(32)); 1108 privkey = eosUtil.bufferToPrivate(keyPair.d.toBuffer(32));
1011 } 1109 }
1012 1110
1111 //Groestlcoin Addresses are different
1112 if(isGRS()) {
1113
1114 if (isSegwit) {
1115 if (!segwitAvailable) {
1116 return;
1117 }
1118 if (isP2wpkh) {
1119 address = groestlcoinjs.address.fromOutputScript(scriptpubkey, network)
1120 }
1121 else if (isP2wpkhInP2sh) {
1122 address = groestlcoinjs.address.fromOutputScript(scriptpubkey, network)
1123 }
1124 }
1125 //non-segwit addresses are handled by using groestlcoinjs for bip32RootKey
1126 }
1127
1013 addAddressToList(indexText, address, pubkey, privkey); 1128 addAddressToList(indexText, address, pubkey, privkey);
1014 if (isLast) { 1129 if (isLast) {
1015 hidePending(); 1130 hidePending();
@@ -2192,6 +2307,20 @@
2192 }, 2307 },
2193 }, 2308 },
2194 { 2309 {
2310 name: "GRS - Groestlcoin",
2311 onSelect: function() {
2312 network = bitcoinjs.bitcoin.networks.groestlcoin;
2313 setHdCoin(17);
2314 },
2315 },
2316 {
2317 name: "GRS - Groestlcoin Testnet",
2318 onSelect: function() {
2319 network = bitcoinjs.bitcoin.networks.groestlcointestnet;
2320 setHdCoin(1);
2321 },
2322 },
2323 {
2195 name: "HNC - Helleniccoin", 2324 name: "HNC - Helleniccoin",
2196 onSelect: function() { 2325 onSelect: function() {
2197 network = bitcoinjs.bitcoin.networks.helleniccoin; 2326 network = bitcoinjs.bitcoin.networks.helleniccoin;