]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blobdiff - src/js/index.js
Make CSS and JS path relative
[perso/Immae/Projets/Cryptomonnaies/BIP39.git] / src / js / index.js
index e5e45937ab05a602ec30c39722f1ad77c95cb131..9dabe9534677e37c56985a6bfc43366f2c289695 100644 (file)
@@ -3,7 +3,7 @@
     var mnemonic = new Mnemonic("english");
     var bip32RootKey = null;
     var bip32ExtendedKey = null;
-    var network = Bitcoin.networks.bitcoin;
+    var network = bitcoin.networks.bitcoin;
     var addressRowTemplate = $("#address-row-template");
 
     var showIndex = true;
@@ -40,7 +40,6 @@
     DOM.indexToggle = $(".index-toggle");
     DOM.addressToggle = $(".address-toggle");
     DOM.privateKeyToggle = $(".private-key-toggle");
-    DOM.myceliumPath = $("#mycelium-path");
 
     var derivationPath = $(".tab-pane.active .path").val();
 
         disableForms();
         hidePending();
         hideValidationError();
+        populateNetworkSelect();
     }
 
     // Event handlers
 
     function networkChanged(e) {
         var network = e.target.value;
-        if (network in networks) {
-            networks[network].onSelect();
-        }
-        else {
-            // TODO
-        }
+        networks[network].onSelect();
         setBip44DerivationPath();
         delayedPhraseChanged();
     }
 
     function bip44Changed() {
         setBip44DerivationPath();
-        derivationPath = DOM.bip44path.val();
         derivationChanged();
     }
 
             return;
         }
         var numWords = parseInt(DOM.strength.val());
-        // Check strength is an integer
-        if (isNaN(numWords)) {
-            DOM.strength.val("12");
-            numWords = 12;
-        }
-        // Check strength is a multiple of 32, if not round it down
-        if (numWords % 3 != 0) {
-            numWords = Math.floor(numWords / 3) * 3;
-            DOM.strength.val(numWords);
-        }
-        // Check strength is at least 32
-        if (numWords == 0) {
-            numWords = 3;
-            DOM.strength.val(numWords);
-        }
         var strength = numWords / 3 * 32;
         var words = mnemonic.generate(strength);
         DOM.phrase.val(words);
 
     function calcBip32Seed(phrase, passphrase, path) {
         var seed = mnemonic.toSeed(phrase, passphrase);
-        bip32RootKey = Bitcoin.HDNode.fromSeedHex(seed, network);
+        bip32RootKey = bitcoin.HDNode.fromSeedHex(seed, network);
         bip32ExtendedKey = bip32RootKey;
         // Derive the key from the path
         var pathBits = path.split("/");
         var addressCell = row.find(".address span");
         var privkeyCell = row.find(".privkey span");
         // Content
-        indexCell.text(index);
+        var indexText = derivationPath + "/" + index;
+        indexCell.text(indexText);
         addressCell.text(address);
         privkeyCell.text(privkey);
         // Visibility
             addressCell.addClass("invisible");
         }
         if (!showPrivKey) {
-            privkeCell.addClass("invisible");
+            privkeyCell.addClass("invisible");
         }
         DOM.addresses.append(row);
     }
         path += account + "'/";
         path += change;
         DOM.bip44path.val(path);
+        derivationPath = DOM.bip44path.val();
     }
 
     function parseIntNoNaN(val, defaultVal) {
             .hide();
     }
 
-    var networks = {
-        "bitcoin": {
+    function populateNetworkSelect() {
+        for (var i=0; i<networks.length; i++) {
+            var network = networks[i];
+            var option = $("<option>");
+            option.attr("value", i);
+            option.text(network.name);
+            DOM.phraseNetwork.append(option);
+        }
+    }
+
+    var networks = [
+        {
             name: "Bitcoin",
             onSelect: function() {
-                network = Bitcoin.networks.bitcoin;
+                network = bitcoin.networks.bitcoin;
                 DOM.bip44coin.val(0);
-                DOM.myceliumPath.val("m/44'/0'/0'/0");
             },
         },
-        "bitcoin-testnet": {
+        {
             name: "Bitcoin Testnet",
             onSelect: function() {
-                network = Bitcoin.networks.testnet;
+                network = bitcoin.networks.testnet;
                 DOM.bip44coin.val(1);
-                DOM.myceliumPath.val("m/44'/1'/0'/0");
             },
         },
-        "litecoin": {
+        {
             name: "Litecoin",
             onSelect: function() {
-                network = Bitcoin.networks.litecoin;
+                network = bitcoin.networks.litecoin;
                 DOM.bip44coin.val(2);
             },
         },
-        "dogecoin": {
+        {
             name: "Dogecoin",
             onSelect: function() {
-                network = Bitcoin.networks.dogecoin;
+                network = bitcoin.networks.dogecoin;
                 DOM.bip44coin.val(3);
             },
         },
-    }
+        {
+            name: "ShadowCash",
+            onSelect: function() {
+                network = bitcoin.networks.shadow;
+                DOM.bip44coin.val(35);
+            },
+        },
+        {
+            name: "ShadowCash Testnet",
+            onSelect: function() {
+                network = bitcoin.networks.shadowtn;
+                DOM.bip44coin.val(1);
+            },
+        },
+        {
+            name: "Viacoin",
+            onSelect: function() {
+                network = bitcoin.networks.viacoin;
+                DOM.bip44coin.val(14);
+            },
+        },
+        {
+            name: "Viacoin Testnet",
+            onSelect: function() {
+                network = bitcoin.networks.viacointestnet;
+                DOM.bip44coin.val(1);
+            },
+        },
+        {
+            name: "Jumbucks",
+            onSelect: function() {
+                network = bitcoin.networks.jumbucks;
+                DOM.bip44coin.val(26);
+            },
+        },
+        {
+            name: "CLAM",
+            onSelect: function() {
+                network = bitcoin.networks.clam;
+                DOM.bip44coin.val(23);
+            },
+        },
+    ]
 
     init();