forked from edenau/crypto-wallet-recovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
40 lines (32 loc) · 1.5 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from utils import phrase2ethaddr
def txt2list(fname):
with open(fname, 'r') as f:
return [line.strip() for line in f]
# Assumes BIP39 and BIP44
def main(phrase, extra_word, derivation_path, addr, missing_notation='?', verbose=True):
mnemonic_dictionary = txt2list('bip39_words_english.txt')
phrase_list = phrase.split(' ')
if verbose:
print('Phrase given:')
print(phrase)
num_missing_word = sum(1 if _ == missing_notation else 0 for _ in phrase_list)
if num_missing_word > 1:
raise Exception('Multiple missing words is not supported yet.')
pos_missing_word = phrase_list.index(missing_notation)
for guess_word in mnemonic_dictionary:
phrase_list[pos_missing_word] = guess_word
phrase_printable = ' '.join(phrase_list)
if phrase2ethaddr(phrase_printable, extra_word, derivation_path).lower() == addr.lower(): # Ethereum addr is case-insensitive
if verbose:
print('Found correct phrase:')
print(phrase_printable)
break
else:
if verbose:
print('Not found!')
if __name__ == '__main__':
phrase = 'school antique detect emotion pepper weasel topic arm shoulder ? chapter deny' # an example
extra_word = '' # empty string if no extra word
derivation_path = "m/44'/60'/0'/0/0" # the most common derivation path for generating Ethereum addresses
addr = '0x426D485C3116Ee7941aB83133D14cA1176Ec99b7'
main(phrase, extra_word, derivation_path, addr)