-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmnemonic_to_privatekey.py
More file actions
45 lines (33 loc) · 1.08 KB
/
Copy pathmnemonic_to_privatekey.py
File metadata and controls
45 lines (33 loc) · 1.08 KB
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
41
42
43
44
"""
Given first N mnemonic words return known privatekey bits (if all 24 words present, also compute checksum)
"""
import sys
import json
from checksum import checksum
from int_to_bitstr import int_to_bitstr
from pprint import pprint
words = json.loads(open("english.json").read())
words_rev = json.loads(open("english_reverse.json").read())
def main(words24):
bitstr = ""
ret = {
'decoded': [],
'checksum_ok': False,
'private_key_hex': None,
}
for i in range(24):
word = None
try:
word = words24[i]
bitstr += words[word]
ret['decoded'].append((words[word], word))
except:
ret['decoded'].append(("???????????", "[missing word #%s]" % (i+1)))
if (len(bitstr) == 264):
if checksum(bitstr[:256]) == int(bitstr[256:], 2):
ret['checksum_ok'] = True
private_key = "{0:064x}".format( int(bitstr[:256], 2) )
ret['privatekey_hex'] = private_key
return ret
if __name__ == '__main__':
pprint(main(sys.argv[1:]))