Skip to content
This repository was archived by the owner on Apr 15, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions hnt-scriptz-main/scripts/missing.js
Original file line number Diff line number Diff line change
@@ -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.');
});
4 changes: 2 additions & 2 deletions scripts/missing.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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}`);
});
Expand Down