diff options
author | AndreasGassmann <andreas@andreasgassmann.ch> | 2020-11-07 16:58:08 +0100 |
---|---|---|
committer | AndreasGassmann <andreas@andreasgassmann.ch> | 2020-11-07 16:58:08 +0100 |
commit | 877b8bdfecabed14e8d5e8a84365743b81da0175 (patch) | |
tree | 83e2e58a1f12d26f66f077cc2b0c4a45e606bebf /src/js | |
parent | 5e211c695939870a782e97d50cec352c9d92d409 (diff) | |
download | BIP39-877b8bdfecabed14e8d5e8a84365743b81da0175.tar.gz BIP39-877b8bdfecabed14e8d5e8a84365743b81da0175.tar.zst BIP39-877b8bdfecabed14e8d5e8a84365743b81da0175.zip |
feat(bip85): add bip85 logic
Diffstat (limited to 'src/js')
-rw-r--r-- | src/js/index.js | 86 |
1 files changed, 86 insertions, 0 deletions
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(); |