]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/blobdiff - src/js/index.js
Add P2WSH and P2WSH-P2SH for bitcoin and testnet
[perso/Immae/Projets/Cryptomonnaies/BIP39.git] / src / js / index.js
index 0b34ade3b2bf17c432a5d4a71895cd76384da629..db4741256e30ba66b0873800013db5333f364793 100644 (file)
                 }
                 catch (e) {}
             }
+            // try parsing using p2wsh network params
+            if ("p2wsh" in n) {
+                try {
+                    bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wsh);
+                    return;
+                }
+                catch (e) {}
+            }
+            // try parsing using p2wsh-in-p2sh network params
+            if ("p2wshInP2sh" in n) {
+                try {
+                    bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wshInP2sh);
+                    return;
+                }
+                catch (e) {}
+            }
         }
         // try the network params as currently specified
         bip32RootKey = bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, network);
                 }
                 catch (e) {}
             }
+            // try parsing using p2wsh network params
+            if ("p2wsh" in n) {
+                try {
+                    bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wsh);
+                    return "";
+                }
+                catch (e) {}
+            }
+            // try parsing using p2wsh-in-p2sh network params
+            if ("p2wshInP2sh" in n) {
+                try {
+                    bitcoinjs.bitcoin.HDNode.fromBase58(rootKeyBase58, n.p2wshInP2sh);
+                    return "";
+                }
+                catch (e) {}
+            }
         }
         // try the network params as currently specified
         try {
             (bip141TabSelected() && DOM.bip141semantics.val() == "p2wpkh-p2sh");
     }
 
+    function p2wshSelected() {
+        return bip141TabSelected() && DOM.bip141semantics.val() == "p2wsh";
+    }
+
+    function p2wshInP2shSelected() {
+        return (bip141TabSelected() && DOM.bip141semantics.val() == "p2wsh-p2sh");
+    }
+
     function TableRow(index, isLast) {
 
         var self = this;
         var segwitAvailable = networkHasSegwit();
         var isP2wpkh = p2wpkhSelected();
         var isP2wpkhInP2sh = p2wpkhInP2shSelected();
+        var isP2wsh = p2wshSelected();
+        var isP2wshInP2sh = p2wshInP2shSelected();
 
         function init() {
             calculateValues();
                         var scriptpubkey = bitcoinjs.bitcoin.script.scriptHash.output.encode(addressbytes);
                         address = bitcoinjs.bitcoin.address.fromOutputScript(scriptpubkey, network)
                     }
+                    else if (isP2wsh) {
+                        // TODO
+                        address = "";
+                    }
+                    else if (isP2wshInP2sh) {
+                        // TODO
+                        address = "";
+                    }
                 }
 
                 if ((networks[DOM.network.val()].name == "CRW - Crown")) {
         else if (p2wpkhInP2shSelected() && "p2wpkhInP2sh" in network) {
             network = network.p2wpkhInP2sh;
         }
+        else if (p2wshSelected() && "p2wsh" in network) {
+            network = network.p2wsh;
+        }
+        else if (p2wshInP2shSelected() && "p2wshInP2sh" in network) {
+            network = network.p2wshInP2sh;
+        }
     }
 
     function lastIndexInTable() {