]> git.immae.eu Git - perso/Immae/Projets/Cryptomonnaies/BIP39.git/commitdiff
feat(bip85): add bip85 logic
authorAndreasGassmann <andreas@andreasgassmann.ch>
Sat, 7 Nov 2020 15:58:08 +0000 (16:58 +0100)
committerAndreasGassmann <andreas@andreasgassmann.ch>
Sat, 7 Nov 2020 15:58:08 +0000 (16:58 +0100)
src/index.html
src/js/index.js

index b73bf5090d5649157e5741762e82c7126af0f0fd..fa04fce99a1857e64d57091817938d3e59984dfc 100644 (file)
                                 <textarea id="root-key" class="root-key private-data form-control" data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
                             </div>
                         </div>
+
+                        <div class="form-group">
+                            <div class="col-sm-2"></div>
+                            <div class="col-sm-10">
+                                <label class="control-label text-weight-normal">
+                                    <input type="checkbox" class="showBip85" />
+                                    Show BIP85
+                                </label>
+                            </div>
+                        </div>
+
+                        <div class="form-group bip85 hidden">
+                            <label for="bip85-application" class="col-sm-2 control-label">BIP85 Application</label>
+                            <div class="col-sm-10">
+                                <select id="bip85-application" class="form-control">
+                                    <option value="bip39" selected>BIP39</option>
+                                    <option value="wif">WIF</option>
+                                    <option value="xprv">Xprv</option>
+                                    <option value="hex">Hex</option>
+                                </select>
+                            </div>
+                        </div>
+
+                        <div class="form-group bip85 bip85-mnemonic-language-input hidden">
+                            <label for="bip85-mnemonic-language" class="col-sm-2 control-label">BIP85 Mnemonic Language</label>
+                            <div class="col-sm-10 languages">
+                                <select id="bip85-mnemonic-language" class="strength form-control">
+                                    <option value="0" selected>English</option>
+                                    <option value="1">日本語</option>
+                                    <option value="2">한국어</option>
+                                    <option value="3">Español</option>
+                                    <option value="4">中文(简体)</option>
+                                    <option value="5">中文(繁體)</option>
+                                    <option value="6">Français</option>
+                                    <option value="7">Italiano</option>
+                                    <option value="8">Čeština</option>
+                                </select>
+                            </div>
+                        </div>
+
+                        <div class="form-group bip85 bip85-mnemonic-length-input hidden">
+                            <label for="bip85-mnemonic-length" class="col-sm-2 control-label">BIP85 Mnemonic Length</label>
+                            <div class="col-sm-10">
+                                <select id="bip85-mnemonic-length" class="strength form-control">
+                                    <option value="12" selected>12</option>
+                                    <option value="18">18</option>
+                                    <option value="24">24</option>
+                                </select>
+                            </div>
+                        </div>
+
+                        <div class="form-group bip85 hidden">
+                            <span class="bip85-bytes-input">
+                                <label for="bip85-bytes" class="col-sm-2 control-label">BIP85 Bytes</label>
+                                <div class="col-sm-10">
+                                    <input id="bip85-bytes" type="text" class="change form-control" value="64" />
+                                </div>
+                            </span>
+                        </div>
+
+                        <div class="form-group bip85 bip85-index-input hidden">
+                            <label for="bip85-index" class="col-sm-2 control-label">BIP85 Index</label>
+                            <div class="col-sm-10">
+                                <input id="bip85-index" type="text" class="change form-control" value="0" />
+                            </div>
+                        </div>
+
+                        <div class="form-group bip85 hidden">
+                            <label for="phrase" class="col-sm-2 control-label">BIP85 Child Key</label>
+                            <div class="col-sm-10">
+                                <textarea
+                                    id="bip85Field"
+                                    data-show-qr
+                                    class="bip85Field private-data form-control"
+                                    title="BIP85 Child Key"
+                                    rows="3"
+                                ></textarea>
+                            </div>
+                        </div>
+
                         <div class="form-group litecoin-ltub-container hidden">
                             <label for="litecoin-use-ltub" class="col-sm-2 control-label">Prefixes</label>
                             <div class="col-sm-10 checkbox">
index 7e6732783006208ed0c2cd93487ee52b2273d4ff..80b78bca7f42065f53f9bbf1c8c2069f74e41c58 100644 (file)
     DOM.bip84accountXprv = $("#bip84 .account-xprv");
     DOM.bip84accountXpub = $("#bip84 .account-xpub");
     DOM.bip84change = $("#bip84 .change");
+    DOM.bip85 = $('.bip85');
+    DOM.showBip85 = $('.showBip85');
+    DOM.bip85Field = $('.bip85Field'); 
+    DOM.bip85application = $('#bip85-application');
+    DOM.bip85mnemonicLanguage = $('#bip85-mnemonic-language');
+    DOM.bip85mnemonicLanguageInput = $('.bip85-mnemonic-language-input');
+    DOM.bip85mnemonicLength = $('#bip85-mnemonic-length');
+    DOM.bip85mnemonicLengthInput = $('.bip85-mnemonic-length-input');
+    DOM.bip85index = $('#bip85-index');
+    DOM.bip85indexInput = $('.bip85-index-input');
+    DOM.bip85bytes = $('#bip85-bytes');
+    DOM.bip85bytesInput = $('.bip85-bytes-input');     
     DOM.bip141unavailable = $("#bip141 .unavailable");
     DOM.bip141available = $("#bip141 .available");
     DOM.bip141path = $("#bip141-path");
         DOM.more.on("click", showMore);
         DOM.seed.on("input", delayedSeedChanged);
         DOM.rootKey.on("input", delayedRootKeyChanged);
+        DOM.showBip85.on('change', toggleBip85);
         DOM.litecoinUseLtub.on("change", litecoinUseLtubChanged);
         DOM.bip32path.on("input", calcForDerivationPath);
         DOM.bip44account.on("input", calcForDerivationPath);
         DOM.bip49change.on("input", calcForDerivationPath);
         DOM.bip84account.on("input", calcForDerivationPath);
         DOM.bip84change.on("input", calcForDerivationPath);
+        DOM.bip85application.on('input', calcBip85);
+        DOM.bip85mnemonicLanguage.on('change', calcBip85);
+        DOM.bip85mnemonicLength.on('change', calcBip85);
+        DOM.bip85index.on('input', calcBip85);
+        DOM.bip85bytes.on('input', calcBip85);         
         DOM.bip141path.on("input", calcForDerivationPath);
         DOM.bip141semantics.on("change", tabChanged);
         DOM.tab.on("shown.bs.tab", tabChanged);
         var passphrase = DOM.passphrase.val();
         calcBip32RootKeyFromSeed(phrase, passphrase);
         calcForDerivationPath();
+        calcBip85();
         // Show the word indexes
         showWordIndexes();
         writeSplitPhrase(phrase);
         }
         // Calculate and display
         calcForDerivationPath();
+        calcBip85();
     }
 
     function rootKeyChanged() {
         // Calculate and display
         calcBip32RootKeyFromBase58(rootKeyBase58);
         calcForDerivationPath();
+        calcBip85();
     }
 
     function litecoinUseLtubChanged() {
         }
     }
 
+    function toggleBip85() {
+      if (DOM.showBip85.prop('checked')) {
+        DOM.bip85.removeClass('hidden');
+        toggleBip85Fields();
+      } else {
+        DOM.bip85.addClass('hidden');
+      }
+    }
+  
+    function toggleBip85Fields() {
+      if (DOM.showBip85.prop('checked')) {
+        DOM.bip85mnemonicLanguageInput.addClass('hidden');
+        DOM.bip85mnemonicLengthInput.addClass('hidden');
+        DOM.bip85bytesInput.addClass('hidden');
+  
+        var app = DOM.bip85application.val();
+        if (app === 'bip39') {
+          DOM.bip85mnemonicLanguageInput.removeClass('hidden');
+          DOM.bip85mnemonicLengthInput.removeClass('hidden');
+        } else if (app === 'hex') {
+          DOM.bip85bytesInput.removeClass('hidden');
+        }
+      }
+    }
+  
+    function calcBip85() {
+      toggleBip85Fields();
+  
+      var app = DOM.bip85application.val();
+  
+      var phrase = DOM.phrase.val();
+      var passphrase = DOM.passphrase.val();
+      if (!phrase) {
+        return;
+      }
+      try {
+        var master = libs.bip85.BIP85.fromMnemonic(phrase, passphrase);
+  
+        var result;
+  
+        const index = parseInt(DOM.bip85index.val(), 10);
+  
+        if (app === 'bip39') {
+          const language = parseInt(DOM.bip85mnemonicLanguage.val(), 10);
+          const length = parseInt(DOM.bip85mnemonicLength.val(), 10);
+  
+          result = master.deriveBIP39(language, length, index).toMnemonic();
+        } else if (app === 'wif') {
+          result = master.deriveWIF(index).toWIF();
+        } else if (app === 'xprv') {
+          result = master.deriveXPRV(index).toXPRV();
+        } else if (app === 'hex') {
+          const bytes = parseInt(DOM.bip85bytes.val(), 10);
+  
+          result = master.deriveHex(bytes, index).toEntropy();
+        }
+  
+        hideValidationError();
+        DOM.bip85Field.val(result);
+      } catch (e) {
+        showValidationError('BIP85: ' + e.message);
+        DOM.bip85Field.val('');
+      }
+    }
+
     function calcForDerivationPath() {
         clearDerivedKeys();
         clearAddressesList();