forked from PostNZT/HelixWalletRecovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelixWalletRecovery.py
55 lines (40 loc) · 1.11 KB
/
helixWalletRecovery.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def read_string(buffer, offset):
offset, string_len = read_size(buffer, offset)
return offset + string_len, buffer[offset: offset + string_len]
def b58_encode(d):
out = ""
p = 0
x = 0
while ord(d[0]) == 0:
out += "1"
d = d[1:]
for i, v in enumerate(d[::-1]):
x += ord(v)*(256**i)
while x > 58**(p+1):
p += 1
while p >= 0:
a, x = divmod(x, 58**p)
out += B58[a]
p -= 1
return out
def b58check_encode(d):
checksum = sha256(sha256(d).digest()).digest()[:4]
return b58_encode(d + checksum)
db = DB()
db.open(sys.argv[1], "main", DB_BTREE, DB_RDONLY)
items = db.items()
for item in items:
k, v = item
koff, voff = 0, 0
koff, item_type = read_string(k, koff)
if item_type == "key":
koff, pubkey = read_string(k, koff)
voff, privkey = read_string(v, voff)
if len(privkey) == 279:
secret = privkey[9:9+32]
else:
secret = privkey[8:8+32]
if pubkey[0] != "\x04":
secret += "\x01"
print(b58check_encode("\xD4" + secret))
db.close()