sutterseba

Source of Checksum Calculator

Jun 6th, 2022 (edited)
649
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*This is the "not-yet-browserified" source code of the mnemonic checksum tool found on my website: suttersebastian.com*/
  2.  
  3. const bitcoin = require('bip39');
  4.  
  5. window.onload = function () {
  6.  
  7.     let output = document.getElementById("output");
  8.  
  9.     document.getElementById("button").addEventListener("click", function () {
  10.  
  11.         output.innerHTML = "";
  12.  
  13.         let shortened = false, actual;
  14.         let valid = [];
  15.         let input = document.getElementById("input").value.trim().toLowerCase();
  16.  
  17.         if (input.length == 0) {
  18.             output.innerHTML = "<p id='red'>NO INPUT GIVEN</p><p id='note'>Please enter a incomplete mnemonic phrase in the gray input field.</p>";
  19.             return;
  20.         }
  21.  
  22.         for (const word of bitcoin.wordlists.english) {
  23.             if (bitcoin.validateMnemonic((input + " " + word), bitcoin.wordlists.english)) {
  24.                 valid.push(word);
  25.             }
  26.         }
  27.  
  28.         if (valid.length > 0) {
  29.  
  30.             output.innerHTML = "<p id='green'>Any of these words will work:</p>";
  31.  
  32.             for (const word of valid) {
  33.                 output.innerHTML += word + ", ";
  34.             }
  35.  
  36.             output.innerHTML = output.innerHTML.slice(0, -2);
  37.         }
  38.         else {
  39.             output.innerHTML = "<p id='red'>INVALID INPUT</p><p id='note'>Check for spelling mistakes and/or incorrect amount of words.<br>Trailing white space and case sensitivity are taken care of.</p>";
  40.         }
  41.     });
  42. }
  43.  
Add Comment
Please, Sign In to add comment