]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/commitdiff
Merge pull request #368 from johnnynanjiang/elastos-pr
authoriancoleman <1281387+iancoleman@users.noreply.github.com>
Sun, 10 Nov 2019 22:47:35 +0000 (09:47 +1100)
committerGitHub <noreply@github.com>
Sun, 10 Nov 2019 22:47:35 +0000 (09:47 +1100)
Add Elastos

src/css/app.css
src/index.html
src/js/index.js
src/js/jsbip39.js
src/js/segwit-parameters.js

index 576b7d7685ab5da8bc0c5ab26f1a80ef0ae3d87b..c2a0294236825e6c78b27c6c5da4d4573ad490de 100644 (file)
@@ -31,6 +31,10 @@ body {
 .phrase {
     word-break: keep-all;
 }
+.phraseSplitWarn {
+       text-align: right;
+       color: red;
+}
 .generate-container .strength {
     /* override mobile width from bootstrap */
     width: auto!important;
index c0b58479e7144a027fb17537e0e94e577c30bf0d..2684c9f6e99dccb14584564f6013b56f8a85bca1 100644 (file)
                                 <textarea id="phrase" class="phrase private-data form-control" data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
                             </div>
                         </div>
+                        <div class="form-group">
+                            <label for="phrase" class="col-sm-2 control-label">BIP39 Split Mnemonic</label>
+                            <div class="col-sm-10">
+                                <textarea id="phraseSplit" class="phraseSplit private-data form-control" title="Only 2 of 3 cards needed to recover."></textarea>
+                            </div>
+                                                       <div id="phraseSplitWarn" class="phraseSplitWarn"></div>
+                        </div>
                         <div class="form-group">
                             <label for="passphrase" class="col-sm-2 control-label">BIP39 Passphrase (optional)</label>
                             <div class="col-sm-10">
index 52fb3ff94d32f94e739b794d501d03c8162b2e09..9ace962612267c779c264895031634ae3ca9ee74 100644 (file)
@@ -44,6 +44,8 @@
     DOM.entropyWeakEntropyOverrideWarning = DOM.entropyContainer.find(".weak-entropy-override-warning");
     DOM.entropyFilterWarning = DOM.entropyContainer.find(".filter-warning");
     DOM.phrase = $(".phrase");
+       DOM.splitPhrase = $(".phraseSplit");
+       DOM.phraseSplitWarn = $(".phraseSplitWarn");
     DOM.passphrase = $(".passphrase");
     DOM.generateContainer = $(".generate-container");
     DOM.generate = $(".generate");
         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() {
             clearDisplay();
             clearEntropyFeedback();
             DOM.phrase.val("");
+                       DOM.phraseSplit.val("");
             showValidationError("Blank entropy");
             return;
         }
         showPending();
         // Clear existing mnemonic and passphrase
         DOM.phrase.val("");
+               DOM.phraseSplit.val("");
         DOM.passphrase.val("");
         seed = null;
         if (rootKeyChangedTimeoutEvent != null) {
             if (DOM.phrase.val().length > 0) {
                 var newPhrase = convertPhraseToNewLanguage();
                 DOM.phrase.val(newPhrase);
+                               writeSplitPhrase(newPhrase);
                 phraseChanged();
             }
             else {
         // show the words
         var words = mnemonic.toMnemonic(data);
         DOM.phrase.val(words);
+               writeSplitPhrase(words);
         // show the entropy
         var entropyHex = uint8ArrayToHex(data);
         DOM.entropy.val(entropyHex);
                 // Ethereum values are different
                 if ((networks[DOM.network.val()].name == "ETH - Ethereum")
                     || (networks[DOM.network.val()].name == "ETC - Ethereum Classic")
+                    || (networks[DOM.network.val()].name == "EWT - EnergyWeb")
                     || (networks[DOM.network.val()].name == "PIRL - Pirl")
                     || (networks[DOM.network.val()].name == "MIX - MIX")
                     || (networks[DOM.network.val()].name == "MUSIC - Musicoin")
         }
         return phrase;
     }
+       
+       function writeSplitPhrase(phrase) {
+               var wordCount = phrase.split(/\s/g).length;                                                             //get number of words in phrase       
+               var left=[];                                                                                                                    //initialize array of indexs
+               for (var i=0;i<wordCount;i++) left.push(i);                                                             //add all indexs to array
+               var group=[[],[],[]],                                                                                                   //make array for 3 groups
+                       groupI=-1;                                                                                                                      //initialize group index
+               var seed = Math.abs(sjcl.hash.sha256.hash(phrase)[0])% 2147483647;              //start seed at sudo random value based on hash of words
+               while (left.length>0) {                                                                                                 //while indexs left
+                       groupI=(groupI+1)%3;                                                                                            //get next group to insert index into
+                       seed = seed * 16807 % 2147483647;                                                                       //change random value.(simple predicatable random number generator works well for this use)
+                       var selected=Math.floor(left.length*(seed - 1) / 2147483646);           //get index in left we will use for this group
+                       group[groupI].push(left[selected]);                                                                     //add index to group
+                       left.splice(selected,1);                                                                                        //remove selected index
+               }
+               var cards=[phrase.split(/\s/g),phrase.split(/\s/g),phrase.split(/\s/g)];//make array of cards
+               for (var i=0;i<3;i++) {                                                                                                 //go through each card
+                       for (var ii=0;ii<wordCount/3;ii++) cards[i][group[i][ii]]='XXXX';       //erase words listed in the group
+                       cards[i]='Card '+(i+1)+': '+wordArrayToPhrase(cards[i]);                                                                //combine words on card back to string
+               }
+               DOM.splitPhrase.val(cards.join("\r\n"));                                                                //make words visible
+               var triesPerSecond=10000000000;                                                                                 //assumed number of tries per second
+               var hackTime=Math.pow(2,wordCount*10/3)/triesPerSecond;                                 //get number of bits of unknown data per card
+               if (hackTime<1) {
+                       hackTime="<1 second";
+               } else if (hackTime<86400) {
+                       hackTime=Math.floor(hackTime)+" seconds";
+               } else if(hackTime<31557600) {
+                       hackTime=Math.floor(hackTime/86400)+" days";
+               } else {
+                       hackTime=Math.floor(hackTime/31557600)+" years";
+               }
+               DOM.phraseSplitWarn.html("Time to hack with only one card: "+hackTime);
+       }
 
     function isUsingOwnEntropy() {
         return DOM.useEntropy.prop("checked");
         var phrase = mnemonic.toMnemonic(entropyArr);
         // Set the mnemonic in the UI
         DOM.phrase.val(phrase);
+               writeSplitPhrase(phrase);
         // Show the word indexes
         showWordIndexes();
         // Show the checksum
                 network = bitcoinjs.bitcoin.networks.bitcoin;
                 setHdCoin(60);
             },
-        },
+          },
+        {
+            name: "EWT - EnergyWeb",
+            onSelect: function() {
+                network = bitcoinjs.bitcoin.networks.bitcoin;
+                setHdCoin(246);
+            },
+          },
         {
             name: "EXCL - Exclusivecoin",
             onSelect: function() {
index 3230e3bb46f275356bf3db523d85f66f36d65f3e..9a6e7ec696b3122a7d73ebf4ec070f7621d4c6e8 100644 (file)
@@ -97,22 +97,10 @@ var Mnemonic = function(language) {
     }
 
     self.check = function(mnemonic) {
-        var mnemonic = self.splitWords(mnemonic);
-        if (mnemonic.length == 0 || mnemonic.length % 3 > 0) {
-            return false
-        }
-        // idx = map(lambda x: bin(self.wordlist.index(x))[2:].zfill(11), mnemonic)
-        var idx = [];
-        for (var i=0; i<mnemonic.length; i++) {
-            var word = mnemonic[i];
-            var wordIndex = wordlist.indexOf(word);
-            if (wordIndex == -1) {
-                return false;
-            }
-            var binaryIndex = zfill(wordIndex.toString(2), 11);
-            idx.push(binaryIndex);
+        var b = mnemonicToBinaryString(mnemonic);
+        if (b === null) {
+            return false;
         }
-        var b = idx.join('');
         var l = b.length;
         //d = b[:l / 33 * 32]
         //h = b[-l / 33:]
@@ -128,6 +116,20 @@ var Mnemonic = function(language) {
         return h == nh;
     }
 
+    self.toRawEntropyHex = function(mnemonic) {
+        var b = mnemonicToBinaryString(mnemonic);
+        if (b === null)
+            return null;
+        var d = b.substring(0, b.length / 33 * 32);
+        var nd = binaryStringToWordArray(d);
+
+        var h = "";
+        for (var i=0; i<nd.length; i++) {
+            h += ('0000000' + nd[i].toString(16)).slice(-8);
+        }
+        return h;
+    }
+
     self.toSeed = function(mnemonic, passphrase) {
         passphrase = passphrase || '';
         mnemonic = self.joinWords(self.splitWords(mnemonic)); // removes duplicate blanks
@@ -200,6 +202,25 @@ var Mnemonic = function(language) {
         return a;
     }
 
+    function mnemonicToBinaryString(mnemonic) {
+        var mnemonic = self.splitWords(mnemonic);
+        if (mnemonic.length == 0 || mnemonic.length % 3 > 0) {
+            return null;
+        }
+        // idx = map(lambda x: bin(self.wordlist.index(x))[2:].zfill(11), mnemonic)
+        var idx = [];
+        for (var i=0; i<mnemonic.length; i++) {
+            var word = mnemonic[i];
+            var wordIndex = wordlist.indexOf(word);
+            if (wordIndex == -1) {
+                return null;
+            }
+            var binaryIndex = zfill(wordIndex.toString(2), 11);
+            idx.push(binaryIndex);
+        }
+        return idx.join('');
+    }
+
     // Pad a numeric string on the left with zero digits until the given width
     // is reached.
     // Note this differs to the python implementation because it does not
index 58c9f9528806952d6e7ee83a51364e7a28c8a761..de4d63495ebd40ff0eecfd15514087e6628a9019 100644 (file)
@@ -263,6 +263,240 @@ bitcoinjs.bitcoin.networks.cpuchain.p2wpkhInP2sh = {
     wif: 0x80,
 };
 
+bitcoinjs.bitcoin.networks.monkeyproject.p2wpkh = {
+    baseNetwork: "monkeyproject",
+       messagePrefix: 'Monkey Signed Message:\n',
+       bech32: 'monkey',
+       bip32: {
+               public: 0x0488b21e,
+               private: 0x0488dde4
+       },
+       pubKeyHash: 0x33,
+       scriptHash: 0x1c,
+       wif: 0x37
+};
+
+bitcoinjs.bitcoin.networks.monkeyproject.p2wpkhInP2sh = {
+       baseNetwork: "monkeyproject",
+       messagePrefix: 'Monkey Signed Message:\n',
+       bech32: 'monkey',
+       bip32: {
+               public: 0x0488b21e,
+               private: 0x0488dde4
+       },
+       pubKeyHash: 0x33,
+       scriptHash: 0x1c,
+       wif: 0x37
+};
+
+bitcoinjs.bitcoin.networks.atom.p2wpkh = {
+    baseNetwork: "atom",
+       messagePrefix: '\x18Bitcoin Atom Signed Message:\n',
+       bech32: 'atom',
+       bip32: {
+               public: 0x0488B21E,
+               private: 0x0488ADE4
+       },
+       pubKeyHash: 0x17,
+       scriptHash: 0x0a,
+       wif: 0x80
+};
+
+bitcoinjs.bitcoin.networks.atom.p2wpkhInP2sh = {
+       baseNetwork: "atom",
+       messagePrefix: '\x18Bitcoin Atom Signed Message:\n',
+       bech32: 'atom',
+       bip32: {
+               public: 0x0488B21E,
+               private: 0x0488ADE4
+       },
+       pubKeyHash: 0x17,
+       scriptHash: 0x0a,
+       wif: 0x80
+};
+
+bitcoinjs.bitcoin.networks.bitcore.p2wpkh = {
+    baseNetwork: "bitcore",
+       messagePrefix: '\x18BitCore Signed Message:\n',
+       bech32: 'bitcore',
+       bip32: {
+               public: 0x0488B21E,
+               private: 0x0488ADE4
+       },
+       pubKeyHash: 0x03,
+       scriptHash: 0x7D,
+       wif: 0x80
+};
+
+bitcoinjs.bitcoin.networks.bitcore.p2wpkhInP2sh = {
+       baseNetwork: "bitcore",
+       messagePrefix: '\x18BitCore Signed Message:\n',
+       bech32: 'bitcore',
+       bip32: {
+               public: 0x0488B21E,
+               private: 0x0488ADE4
+       },
+       pubKeyHash: 0x03,
+       scriptHash: 0x7D,
+       wif: 0x80
+};
+
+bitcoinjs.bitcoin.networks.monacoin.p2wpkh = {
+    baseNetwork: "monacoin",
+       messagePrefix: '\x18Monacoin Signed Message:\n',
+       bech32: 'monacoin',
+       bip32: {
+               public: 0x0488b21e,
+               private: 0x0488ade4
+       },
+       pubKeyHash: 0x32,
+       scriptHash: 0x37,
+       wif: 0xb0
+};
+
+bitcoinjs.bitcoin.networks.monacoin.p2wpkhInP2sh = {
+       baseNetwork: "monacoin",
+       messagePrefix: '\x18Monacoin Signed Message:\n',
+       bech32: 'monacoin',
+       bip32: {
+               public: 0x0488b21e,
+               private: 0x0488ade4
+       },
+       pubKeyHash: 0x32,
+       scriptHash: 0x37,
+       wif: 0xb0
+};
+
+bitcoinjs.bitcoin.networks.syscoin.p2wpkh = {
+    baseNetwork: "syscoin",
+       messagePrefix: '\x18Syscoin Signed Message:\n',
+       bech32: 'sys',
+       bip32: {
+               public: 0x04b24746,
+               private: 0x04b2430c
+       },
+       pubKeyHash: 0x3f,
+       scriptHash: 0x05,
+       wif: 0x80
+};
+
+bitcoinjs.bitcoin.networks.syscoin.p2wpkhInP2sh = {
+       baseNetwork: "syscoin",
+       messagePrefix: '\x18Syscoin Signed Message:\n',
+       bech32: 'sys',
+       bip32: {
+               public: 0x049d7cb2,
+               private: 0x049d7878
+       },
+       pubKeyHash: 0x3f,
+       scriptHash: 0x05,
+       wif: 0x80
+};
+
+bitcoinjs.bitcoin.networks.viacoin.p2wpkh = {
+    baseNetwork: "viacoin",
+       messagePrefix: '\x18Viacoin Signed Message:\n',
+       bech32: 'viacoin',
+       bip32: {
+               public: 0x0488b21e,
+               private: 0x0488ade4
+       },
+       pubKeyHash: 0x47,
+       scriptHash: 0x21,
+       wif: 0xc7
+};
+
+bitcoinjs.bitcoin.networks.viacoin.p2wpkhInP2sh = {
+       baseNetwork: "viacoin",
+       messagePrefix: '\x18Viacoin Signed Message:\n',
+       bech32: 'viacoin',
+       bip32: {
+               public: 0x0488b21e,
+               private: 0x0488ade4
+       },
+       pubKeyHash: 0x47,
+       scriptHash: 0x21,
+       wif: 0xc7
+};
+
+bitcoinjs.bitcoin.networks.dogecointestnet.p2wpkh = {
+    baseNetwork: "dogecointestnet",
+       messagePrefix: '\x19Dogecoin Signed Message:\n',
+       bech32: 'dogecointestnet',
+       bip32: {
+               public: 0x043587cf,
+               private: 0x04358394
+       },
+       pubKeyHash: 0x71,
+       scriptHash: 0xc4,
+       wif: 0xf1
+};
+
+bitcoinjs.bitcoin.networks.dogecointestnet.p2wpkhInP2sh = {
+       baseNetwork: "dogecointestnet",
+       messagePrefix: '\x19Dogecoin Signed Message:\n',
+       bech32: 'dogecointestnet',
+       bip32: {
+               public: 0x043587cf,
+               private: 0x04358394
+       },
+       pubKeyHash: 0x71,
+       scriptHash: 0xc4,
+       wif: 0xf1
+};
+
+bitcoinjs.bitcoin.networks.dogecointestnet.p2wpkh = {
+    baseNetwork: "dogecointestnet",
+       messagePrefix: '\x19Dogecoin Signed Message:\n',
+       bech32: 'dogecointestnet',
+       bip32: {
+               public: 0x043587cf,
+               private: 0x04358394
+       },
+       pubKeyHash: 0x71,
+       scriptHash: 0xc4,
+       wif: 0xf1
+};
+
+bitcoinjs.bitcoin.networks.dogecointestnet.p2wpkhInP2sh = {
+       baseNetwork: "dogecointestnet",
+       messagePrefix: '\x19Dogecoin Signed Message:\n',
+       bech32: 'dogecointestnet',
+       bip32: {
+               public: 0x043587cf,
+               private: 0x04358394
+       },
+       pubKeyHash: 0x71,
+       scriptHash: 0xc4,
+       wif: 0xf1
+};
+
+bitcoinjs.bitcoin.networks.litecointestnet.p2wpkh = {
+    baseNetwork: "litecointestnet",
+       messagePrefix: '\x18Litecoin Signed Message:\n',
+       bech32: 'litecointestnet',
+       bip32: {
+               public: 0x043587cf,
+               private: 0x04358394
+       },
+       pubKeyHash: 0x6f,
+       scriptHash: 0xc4,
+       wif: 0xef
+};
+
+bitcoinjs.bitcoin.networks.litecointestnet.p2wpkhInP2sh = {
+       baseNetwork: "litecointestnet",
+       messagePrefix: '\x18Litecoin Signed Message:\n',
+       bech32: 'litecointestnet',
+       bip32: {
+               public: 0x043587cf,
+               private: 0x04358394
+       },
+       pubKeyHash: 0x6f,
+       scriptHash: 0xc4,
+       wif: 0xef
+};
+
 bitcoinjs.bitcoin.networks.groestlcoin.p2wpkh = {
     baseNetwork: "groestlcoin",
     messagePrefix: '\x19GroestlCoin Signed Message:\n',