diff --git a/hnt-scriptz-main/scripts/missing.js b/hnt-scriptz-main/scripts/missing.js new file mode 100644 index 0000000..a5760af --- /dev/null +++ b/hnt-scriptz-main/scripts/missing.js @@ -0,0 +1,43 @@ +import { Keypair, Address } from '@helium/crypto'; +import { prompt } from 'inquirer'; +import wordlist, { indexOf, length } from './wordlist/english.json'; +const { log } = console; +const ascii = +` _ + |_ __ _|_ _ _ __ o |_)_|_ _ + | || | |_ _> (_ | | | |_ /_ +`; +const INVALID_LENGTH = 'This script only allows for 11 or 23 words.'; +log(ascii); + +async function findWord() { + const questions = [ + { type: 'input', name: 'mnemonic', message: 'mnemonic (example: radio invite life ... cabbage)' }, + { type: 'input', name: 'missing', message: 'what address are you looking for?' }, + ]; + const { mnemonic, missing } = await prompt(questions); + const words = mnemonic.split(' '); + if (words.length !== 11 && words.length !== 23) throw new Error(INVALID_LENGTH); + words.map((word) => { + if (indexOf(word) === -1) throw new Error(`Invalid word: ${word}`); + }); + if (!Address.isValid(missing)) throw new Error(`Invalid address: ${missing}`); + for (let order = 0; order < (words.length + 1); order++) { + for (let i = 0; i < length; i++) { + words.splice(order, 0, wordlist[i]); + const keypair = await Keypair.fromWords(words).catch(() => {}); + keypair ? address = keypair.address.b58 : address = []; + if (address !== missing) { + words.splice(order, 1); + } else return log('\n', 'Address:', address, '\n', 'Words:', words); + } + } +} + +prompt({ + type: 'list', name: 'cmd', message: 'choose a command', choices: ['find missing word', 'exit'], +}) + .then(async (answer) => { + if (answer.cmd === 'find missing word') return findWord(); + if (answer.cmd === 'exit') return log('goodbye.'); + }); diff --git a/scripts/missing.js b/scripts/missing.js index 3847467..bb24829 100644 --- a/scripts/missing.js +++ b/scripts/missing.js @@ -7,7 +7,7 @@ const ascii = |_ __ _|_ _ _ __ o |_)_|_ _ | || | |_ _> (_ | | | |_ /_ `; -const INVALID_LENGTH = 'This script only allows for 11 or 23 words.'; +const INVALID_LENGTH = 'This script only allows for 10 or 22 words.'; log(ascii); async function findWord() { @@ -17,7 +17,7 @@ async function findWord() { ]; const { mnemonic, missing } = await inquirer.prompt(questions); const words = mnemonic.split(' '); - if (words.length !== 11 && words.length !== 23) throw new Error(INVALID_LENGTH); + if (words.length !== 10 && words.length !== 22) throw new Error(INVALID_LENGTH); words.map((word) => { if (wordlist.indexOf(word) === -1) throw new Error(`Invalid word: ${word}`); });