-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcreate-bip38.py
More file actions
164 lines (128 loc) · 4.54 KB
/
create-bip38.py
File metadata and controls
164 lines (128 loc) · 4.54 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import os
from bip38 import encrypt
from bitcoin import encode_privkey, random_key
from qrcode import QRCode, ERROR_CORRECT_Q, ERROR_CORRECT_M
from PIL import Image, ImageFont, ImageDraw
import getpass
from cryptos import Bitcoin, Litecoin, Doge
verbose = 0
print("===============================================================")
print(" BIP38 generator: Create paper wallet, encrypted with passphrase.")
print("===============================================================")
check = 0
while check == 0:
print(" ")
print("Enter crypto currency (BTC, LTC, DOGE) you want to choose (BTC/ltc/doge):")
currency = input().upper()
if currency in ["BTC", "LTC", "DOGE", ""]:
check = 1
else:
print("The currency \"" + currency +
"\" wasn't found. Please use BTC, LTC or DOGE")
if currency == "":
currency = "BTC"
print(" ")
print("Do you want to use the testnet? (N/y):")
testnet = input().upper()
#print(" ")
print("Enter description for this wallet (optional):")
name = input()
if currency == "":
currency = "no"
# should be before that currency shit?
print(" ")
print("Enter a WIF format private key (optional):")
wif = input()
backgroundJPG = "assets/background.jpg"
# randomkey = binascii.hexlify(os.urandom(32)).decode()
if currency == "BTC" and testnet[:1] != "N":
c = Bitcoin(testnet=True)
backgroundJPG = "assets/backgroundBTC.jpg"
if currency == "BTC" and testnet[:1] != "Y":
c = Bitcoin(testnet=False)
backgroundJPG = "assets/backgroundBTC.jpg"
if currency == "LTC" and testnet[:1] != "N":
c = Litecoin(testnet=True)
backgroundJPG = "assets/backgroundLTC.jpg"
if currency == "LTC" and testnet[:1] != "Y":
c = Litecoin(testnet=False)
backgroundJPG = "assets/backgroundLTC.jpg"
if currency == "DOGE" and testnet[:1] != "N":
c = Doge(testnet=True)
if currency == "DOGE" and testnet[:1] != "Y":
c = Doge(testnet=False)
if not wif:
wif = encode_privkey(random_key(), "wif") # private key (WIF)
print("* generated new key *")
# addr = privtoaddr(wif)
addr = c.privtoaddr(wif)
print(" ")
print("Enter a secret passphrase:")
pasw = getpass.getpass()
if not pasw:
print("you must enter a passphrase")
exit()
print(" ")
print("Re-enter the passphrase:")
pasw2 = getpass.getpass()
if pasw != pasw2:
print("passphrase does not match")
exit()
# encrypt
bip = encrypt(wif, pasw)
# if verbose: print ("bip: "+ str(bip))
print(" ")
print("Enter passphrase hint (recommended):")
hint = input()
# image...
img = Image.open(backgroundJPG) # around 1000 x 500
# img = Image.new("RGB", (1000, 500), color = "red")
img_w, img_h = img.size
# QR image for addr
qr = QRCode(box_size=8, border=3, error_correction=ERROR_CORRECT_Q)
qr.add_data(addr)
im = qr.make_image()
im_w, im_h = im.size
# QR image for key
qr2 = QRCode(box_size=6, border=3, error_correction=ERROR_CORRECT_M)
qr2.add_data(bip)
im2 = qr2.make_image()
im2_w, im2_h = im2.size
# draw QRs
offs = (img_w - im_w - im2_w) / 4
img.paste(im, (int(offs*0.6), int((img_h-im_h)/2)))
img.paste(im2, (int(im_w+(3.5*offs)), int((img_h-im2_h)/2)))
# draw labels
draw = ImageDraw.Draw(img)
# font from https://www.dafont.com/de/monkey.font (marked as 100% free)
font = ImageFont.truetype(os.path.join("assets", "monkey.ttf"), 26)
fcolor = (0, 0, 0)
# print("fcolor: " + str(type(fcolor)))
# print("font: " + str(type(font)))
# draw.text((im_w+(3*offs),(img_h-im_h)/2-10), "BIP38 Key", fcolor, font)
draw.text((20, 20), name, fcolor, font)
draw.text((20, 70), "ADDRESS: " + addr, fcolor, font)
# print("bip: " + str(type(bip)))
# print("fcolor: " + str(type(fcolor)))
# print("font: " + str(type(font)))
draw.text((20, (img_h - 100)), "BIP38 KEY: " +
bip, fcolor, font)
if len(hint) > 0:
draw.text((20, (img_h - 50)), "PASSPHRASE HINT: " + hint, fcolor, font)
os.makedirs("out", exist_ok=True)
#print (os.path.join("out", f"{currency}_{addr}.jpg"))
img.save(os.path.join("out", f"{currency}_{addr}.jpg"), "JPEG")
print(" ")
print("===============================================================")
print(" Encrypted paper wallet (image file) created.")
print(" ")
text = currency
if testnet[:1] == "Y":
text = text + " (testnet)"
print(text + " address: " + addr)
print("Encrypted key: " + bip)
if verbose:
print("WIF: " + wif)
print(" ")
print(" (To decrypt, run \"python unlock-bip38.py\")")
print("===============================================================")