From d74cce35acc50bd8bbdd8e1544d665b7b143e84e Mon Sep 17 00:00:00 2001 From: Rocket Sloth Date: Sat, 20 Nov 2021 18:03:39 -0600 Subject: [PATCH 1/3] commit --- hnt-scriptz-main/scripts/missing.js | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 hnt-scriptz-main/scripts/missing.js 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.'); + }); From 6f96dbd211c576bf0c4705242ae322845be4761a Mon Sep 17 00:00:00 2001 From: Rocket Sloth <87209309+RocketSloth@users.noreply.github.com> Date: Tue, 23 Nov 2021 14:35:35 -0600 Subject: [PATCH 2/3] Update missing.js --- scripts/missing.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/missing.js b/scripts/missing.js index 3847467..4a5c6cc 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,18 +17,18 @@ 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}`); }); if (!Address.isValid(missing)) throw new Error(`Invalid address: ${missing}`); - for (let order = 0; order < (words.length + 1); order++) { + for (let order = 0; order < (words.length + 2); order++) { for (let i = 0; i < wordlist.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); + words.splice(order, 2); } else return log('\n', 'Address:', address, '\n', 'Words:', words); } } From e3e9b56d1952f3fdb81e2ff01571ac54911c999e Mon Sep 17 00:00:00 2001 From: Rocket Sloth <87209309+RocketSloth@users.noreply.github.com> Date: Tue, 23 Nov 2021 22:10:18 -0600 Subject: [PATCH 3/3] Update missing.js --- scripts/missing.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/missing.js b/scripts/missing.js index 4a5c6cc..bb24829 100644 --- a/scripts/missing.js +++ b/scripts/missing.js @@ -22,13 +22,13 @@ async function findWord() { if (wordlist.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 + 2); order++) { + for (let order = 0; order < (words.length + 1); order++) { for (let i = 0; i < wordlist.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, 2); + words.splice(order, 1); } else return log('\n', 'Address:', address, '\n', 'Words:', words); } }