aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreasGassmann <andreas@andreasgassmann.ch>2020-11-07 16:58:08 +0100
committerAndreasGassmann <andreas@andreasgassmann.ch>2020-11-07 16:58:08 +0100
commit877b8bdfecabed14e8d5e8a84365743b81da0175 (patch)
tree83e2e58a1f12d26f66f077cc2b0c4a45e606bebf /src
parent5e211c695939870a782e97d50cec352c9d92d409 (diff)
downloadBIP39-877b8bdfecabed14e8d5e8a84365743b81da0175.tar.gz
BIP39-877b8bdfecabed14e8d5e8a84365743b81da0175.tar.zst
BIP39-877b8bdfecabed14e8d5e8a84365743b81da0175.zip
feat(bip85): add bip85 logic
Diffstat (limited to 'src')
-rw-r--r--src/index.html80
-rw-r--r--src/js/index.js86
2 files changed, 166 insertions, 0 deletions
diff --git a/src/index.html b/src/index.html
index b73bf50..fa04fce 100644
--- a/src/index.html
+++ b/src/index.html
@@ -248,6 +248,86 @@
248 <textarea id="root-key" class="root-key private-data form-control" data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea> 248 <textarea id="root-key" class="root-key private-data form-control" data-show-qr autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"></textarea>
249 </div> 249 </div>
250 </div> 250 </div>
251
252 <div class="form-group">
253 <div class="col-sm-2"></div>
254 <div class="col-sm-10">
255 <label class="control-label text-weight-normal">
256 <input type="checkbox" class="showBip85" />
257 Show BIP85
258 </label>
259 </div>
260 </div>
261
262 <div class="form-group bip85 hidden">
263 <label for="bip85-application" class="col-sm-2 control-label">BIP85 Application</label>
264 <div class="col-sm-10">
265 <select id="bip85-application" class="form-control">
266 <option value="bip39" selected>BIP39</option>
267 <option value="wif">WIF</option>
268 <option value="xprv">Xprv</option>
269 <option value="hex">Hex</option>
270 </select>
271 </div>
272 </div>
273
274 <div class="form-group bip85 bip85-mnemonic-language-input hidden">
275 <label for="bip85-mnemonic-language" class="col-sm-2 control-label">BIP85 Mnemonic Language</label>
276 <div class="col-sm-10 languages">
277 <select id="bip85-mnemonic-language" class="strength form-control">
278 <option value="0" selected>English</option>
279 <option value="1">日本語</option>
280 <option value="2">한국어</option>
281 <option value="3">Español</option>
282 <option value="4">中文(简体)</option>
283 <option value="5">中文(繁體)</option>
284 <option value="6">Français</option>
285 <option value="7">Italiano</option>
286 <option value="8">Čeština</option>
287 </select>
288 </div>
289 </div>
290
291 <div class="form-group bip85 bip85-mnemonic-length-input hidden">
292 <label for="bip85-mnemonic-length" class="col-sm-2 control-label">BIP85 Mnemonic Length</label>
293 <div class="col-sm-10">
294 <select id="bip85-mnemonic-length" class="strength form-control">
295 <option value="12" selected>12</option>
296 <option value="18">18</option>
297 <option value="24">24</option>
298 </select>
299 </div>
300 </div>
301
302 <div class="form-group bip85 hidden">
303 <span class="bip85-bytes-input">
304 <label for="bip85-bytes" class="col-sm-2 control-label">BIP85 Bytes</label>
305 <div class="col-sm-10">
306 <input id="bip85-bytes" type="text" class="change form-control" value="64" />
307 </div>
308 </span>
309 </div>
310
311 <div class="form-group bip85 bip85-index-input hidden">
312 <label for="bip85-index" class="col-sm-2 control-label">BIP85 Index</label>
313 <div class="col-sm-10">
314 <input id="bip85-index" type="text" class="change form-control" value="0" />
315 </div>
316 </div>
317
318 <div class="form-group bip85 hidden">
319 <label for="phrase" class="col-sm-2 control-label">BIP85 Child Key</label>
320 <div class="col-sm-10">
321 <textarea
322 id="bip85Field"
323 data-show-qr
324 class="bip85Field private-data form-control"
325 title="BIP85 Child Key"
326 rows="3"
327 ></textarea>
328 </div>
329 </div>
330
251 <div class="form-group litecoin-ltub-container hidden"> 331 <div class="form-group litecoin-ltub-container hidden">
252 <label for="litecoin-use-ltub" class="col-sm-2 control-label">Prefixes</label> 332 <label for="litecoin-use-ltub" class="col-sm-2 control-label">Prefixes</label>
253 <div class="col-sm-10 checkbox"> 333 <div class="col-sm-10 checkbox">
diff --git a/src/js/index.js b/src/js/index.js
index 7e67327..80b78bc 100644
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -94,6 +94,18 @@
94 DOM.bip84accountXprv = $("#bip84 .account-xprv"); 94 DOM.bip84accountXprv = $("#bip84 .account-xprv");
95 DOM.bip84accountXpub = $("#bip84 .account-xpub"); 95 DOM.bip84accountXpub = $("#bip84 .account-xpub");
96 DOM.bip84change = $("#bip84 .change"); 96 DOM.bip84change = $("#bip84 .change");
97 DOM.bip85 = $('.bip85');
98 DOM.showBip85 = $('.showBip85');
99 DOM.bip85Field = $('.bip85Field');
100 DOM.bip85application = $('#bip85-application');
101 DOM.bip85mnemonicLanguage = $('#bip85-mnemonic-language');
102 DOM.bip85mnemonicLanguageInput = $('.bip85-mnemonic-language-input');
103 DOM.bip85mnemonicLength = $('#bip85-mnemonic-length');
104 DOM.bip85mnemonicLengthInput = $('.bip85-mnemonic-length-input');
105 DOM.bip85index = $('#bip85-index');
106 DOM.bip85indexInput = $('.bip85-index-input');
107 DOM.bip85bytes = $('#bip85-bytes');
108 DOM.bip85bytesInput = $('.bip85-bytes-input');
97 DOM.bip141unavailable = $("#bip141 .unavailable"); 109 DOM.bip141unavailable = $("#bip141 .unavailable");
98 DOM.bip141available = $("#bip141 .available"); 110 DOM.bip141available = $("#bip141 .available");
99 DOM.bip141path = $("#bip141-path"); 111 DOM.bip141path = $("#bip141-path");
@@ -141,6 +153,7 @@
141 DOM.more.on("click", showMore); 153 DOM.more.on("click", showMore);
142 DOM.seed.on("input", delayedSeedChanged); 154 DOM.seed.on("input", delayedSeedChanged);
143 DOM.rootKey.on("input", delayedRootKeyChanged); 155 DOM.rootKey.on("input", delayedRootKeyChanged);
156 DOM.showBip85.on('change', toggleBip85);
144 DOM.litecoinUseLtub.on("change", litecoinUseLtubChanged); 157 DOM.litecoinUseLtub.on("change", litecoinUseLtubChanged);
145 DOM.bip32path.on("input", calcForDerivationPath); 158 DOM.bip32path.on("input", calcForDerivationPath);
146 DOM.bip44account.on("input", calcForDerivationPath); 159 DOM.bip44account.on("input", calcForDerivationPath);
@@ -149,6 +162,11 @@
149 DOM.bip49change.on("input", calcForDerivationPath); 162 DOM.bip49change.on("input", calcForDerivationPath);
150 DOM.bip84account.on("input", calcForDerivationPath); 163 DOM.bip84account.on("input", calcForDerivationPath);
151 DOM.bip84change.on("input", calcForDerivationPath); 164 DOM.bip84change.on("input", calcForDerivationPath);
165 DOM.bip85application.on('input', calcBip85);
166 DOM.bip85mnemonicLanguage.on('change', calcBip85);
167 DOM.bip85mnemonicLength.on('change', calcBip85);
168 DOM.bip85index.on('input', calcBip85);
169 DOM.bip85bytes.on('input', calcBip85);
152 DOM.bip141path.on("input", calcForDerivationPath); 170 DOM.bip141path.on("input", calcForDerivationPath);
153 DOM.bip141semantics.on("change", tabChanged); 171 DOM.bip141semantics.on("change", tabChanged);
154 DOM.tab.on("shown.bs.tab", tabChanged); 172 DOM.tab.on("shown.bs.tab", tabChanged);
@@ -268,6 +286,7 @@
268 var passphrase = DOM.passphrase.val(); 286 var passphrase = DOM.passphrase.val();
269 calcBip32RootKeyFromSeed(phrase, passphrase); 287 calcBip32RootKeyFromSeed(phrase, passphrase);
270 calcForDerivationPath(); 288 calcForDerivationPath();
289 calcBip85();
271 // Show the word indexes 290 // Show the word indexes
272 showWordIndexes(); 291 showWordIndexes();
273 writeSplitPhrase(phrase); 292 writeSplitPhrase(phrase);
@@ -404,6 +423,7 @@
404 } 423 }
405 // Calculate and display 424 // Calculate and display
406 calcForDerivationPath(); 425 calcForDerivationPath();
426 calcBip85();
407 } 427 }
408 428
409 function rootKeyChanged() { 429 function rootKeyChanged() {
@@ -418,6 +438,7 @@
418 // Calculate and display 438 // Calculate and display
419 calcBip32RootKeyFromBase58(rootKeyBase58); 439 calcBip32RootKeyFromBase58(rootKeyBase58);
420 calcForDerivationPath(); 440 calcForDerivationPath();
441 calcBip85();
421 } 442 }
422 443
423 function litecoinUseLtubChanged() { 444 function litecoinUseLtubChanged() {
@@ -440,6 +461,71 @@
440 } 461 }
441 } 462 }
442 463
464 function toggleBip85() {
465 if (DOM.showBip85.prop('checked')) {
466 DOM.bip85.removeClass('hidden');
467 toggleBip85Fields();
468 } else {
469 DOM.bip85.addClass('hidden');
470 }
471 }
472
473 function toggleBip85Fields() {
474 if (DOM.showBip85.prop('checked')) {
475 DOM.bip85mnemonicLanguageInput.addClass('hidden');
476 DOM.bip85mnemonicLengthInput.addClass('hidden');
477 DOM.bip85bytesInput.addClass('hidden');
478
479 var app = DOM.bip85application.val();
480 if (app === 'bip39') {
481 DOM.bip85mnemonicLanguageInput.removeClass('hidden');
482 DOM.bip85mnemonicLengthInput.removeClass('hidden');
483 } else if (app === 'hex') {
484 DOM.bip85bytesInput.removeClass('hidden');
485 }
486 }
487 }
488
489 function calcBip85() {
490 toggleBip85Fields();
491
492 var app = DOM.bip85application.val();
493
494 var phrase = DOM.phrase.val();
495 var passphrase = DOM.passphrase.val();
496 if (!phrase) {
497 return;
498 }
499 try {
500 var master = libs.bip85.BIP85.fromMnemonic(phrase, passphrase);
501
502 var result;
503
504 const index = parseInt(DOM.bip85index.val(), 10);
505
506 if (app === 'bip39') {
507 const language = parseInt(DOM.bip85mnemonicLanguage.val(), 10);
508 const length = parseInt(DOM.bip85mnemonicLength.val(), 10);
509
510 result = master.deriveBIP39(language, length, index).toMnemonic();
511 } else if (app === 'wif') {
512 result = master.deriveWIF(index).toWIF();
513 } else if (app === 'xprv') {
514 result = master.deriveXPRV(index).toXPRV();
515 } else if (app === 'hex') {
516 const bytes = parseInt(DOM.bip85bytes.val(), 10);
517
518 result = master.deriveHex(bytes, index).toEntropy();
519 }
520
521 hideValidationError();
522 DOM.bip85Field.val(result);
523 } catch (e) {
524 showValidationError('BIP85: ' + e.message);
525 DOM.bip85Field.val('');
526 }
527 }
528
443 function calcForDerivationPath() { 529 function calcForDerivationPath() {
444 clearDerivedKeys(); 530 clearDerivedKeys();
445 clearAddressesList(); 531 clearAddressesList();