-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_wallets
executable file
·188 lines (155 loc) · 7.05 KB
/
make_wallets
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env python3
######################################################################
#
# Copyright 2021 Bryan Murdock
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see
# <https://www.gnu.org/licenses/>.
######################################################################
import math
import textwrap
from pathlib import Path
import qrcode
from bitcoinlib.mnemonic import Mnemonic
from bitcoinlib.wallets import Wallet
from PIL import Image, ImageDraw, ImageFont
def inc_tuple(tup, val):
"""increments every value in a tuple by the given amount, returns a
new tuple
"""
return tuple([x + val for x in tup])
def text_wrap(txt, width):
"""Dumb text wrapper. Does not consider word boundaries at all."""
wrapped = ''
for char in txt:
wrapped += char
if len(wrapped) % width == 0:
wrapped += '\n'
return wrapped
class PaperWallet:
def __init__(self, wallet, wallet_back):
self.front = wallet
self.back = wallet_back
def gen_paper_wallet(name, zpub, zprv, seed_phrase):
wallet = Image.open('BTC_PaperWallet_Design_blank.psd')
wallet_back = Image.new(mode='RGB', size=(wallet.size[1], wallet.size[0]), color='white')
pubkey_qr_pos = (35, 469)
key_qr_size = (285, 285)
pubkey_txt_pos = (350, 700)
pubkey_txt_size = (708, 58)
pubkey_txt_char_width = 58
privkey_qr_pos = (1524, 40)
privkey_txt_pos = (1031, 45)
privkey_txt_size = (485, 88)
privkey_txt_char_width = 39
name_pos = (1213,560)
name_size= (142, 36)
# get a font
fnt = ImageFont.truetype("/usr/share/fonts/TTF/DejaVuSansCondensed.ttf", size=20)
fnt_bigger = ImageFont.truetype("/usr/share/fonts/TTF/DejaVuSansCondensed.ttf", size=22)
fnt_mono = ImageFont.truetype("/usr/share/fonts/TTF/DejaVuSansMono.ttf", size=20)
# get a drawing context
wallet_draw = ImageDraw.Draw(wallet)
# as far as I can tell, the data, version, and box_size together
# determine the final size of the qr code. This combo creates 265
# pixel square, which fits inside the square on this particular
# template, and with the -10 crop offsets it is centered.
zpub_qr = qrcode.make(zpub, version=1, box_size=5)
zpub_qr = zpub_qr.crop(inc_tuple((0, 0), -10) + inc_tuple(key_qr_size, -10))
zprv_qr = qrcode.make(zprv, version=1, box_size=5)
zprv_qr = zprv_qr.crop(inc_tuple((0, 0), -10) + inc_tuple(key_qr_size, -10))
wallet.paste(zpub_qr, pubkey_qr_pos + inc_tuple(pubkey_qr_pos, key_qr_size[0]))
wallet.paste(zprv_qr, privkey_qr_pos + inc_tuple(privkey_qr_pos, key_qr_size[0]))
wallet_draw.multiline_text(pubkey_txt_pos, text_wrap(zpub, pubkey_txt_char_width),
font=fnt_mono, fill=(0, 0, 0))
wallet_draw.multiline_text(privkey_txt_pos, text_wrap(zprv, privkey_txt_char_width),
font=fnt_mono, fill=(0, 0, 0))
wallet_draw.multiline_text(name_pos, name, font=fnt, fill=(0, 0, 0))
wallet = wallet.crop((0, 0) + wallet.size)
seed_phrase = textwrap.fill(seed_phrase, 70)
# back page
text_first = """Merry Christmas! These codes are the keys to your new bitcoin
wallet. Keep them secret and safe (but I have kept a copy just in
case you lose them)! Here is the "seed phrase" version of your
Private Key that could come in handy (keep this secret and safe too!):
"""
text_second = f"""{seed_phrase}
----------
I recommend the BlueWallet phone app for doing anything with your
bitcoin, but there are others you could choose.
- To see how much bitcoin is in your wallet, scan the Public Key with
the BlueWallet app
- To add bitcoin to your wallet, scan the Public Key with the
BlueWallet app and tap Receive to get an address to send bitcoin too
- To send your bitcoin somewhere (I don't recommend this, try hanging
on to it for a while and watch its value grow!), scan the Private
Key or seed phrase with the Blue Wallet app, tap Send, and enter the
address you want to send the bitcoin to
To get more bitcoin, I highly recommend using Swan Bitcoin. If you
sign up with this URL (or qrcode), Swan will give you $10 in bitcoin
(full disclosure: I'll get some bitcoin from Swan too).
"""
swan_url = 'https://www.swanbitcoin.com/bdmurdock/'
text_third = f"""{swan_url}
If you have any other questions feel free to ask me:
[email protected] or 801-739-5754
"""
seed_qr = qrcode.make(seed_phrase, version=1, box_size=5)
swan_qr = qrcode.make(swan_url, version=1, box_size=5)
wallet_back_draw = ImageDraw.Draw(wallet_back)
wallet_back_draw.multiline_text((35, 70), text_first, font=fnt_bigger, fill=(0, 0, 0))
wallet_back.paste(seed_qr, (35, 170))
wallet_back_draw.multiline_text((35, 450), text_second, font=fnt_bigger, fill=(0, 0, 0))
wallet_back.paste(swan_qr, (35, 1030))
wallet_back_draw.multiline_text((35, 1210), text_third, font=fnt_bigger, fill=(0, 0, 0))
# TODO: add debug mode that does this:
# wallet_back.save('wallet_back.png')
wallet_back = wallet_back.rotate(90, expand=True)
return PaperWallet(wallet, wallet_back)
def gen_pages(wallets, output):
# letter paper: 8.5" x 11"
page_aspect_ratio = 11/8.5
x_size = wallets[0].front.size[0] + 200
y_size = round(x_size * page_aspect_ratio)
# TODO: calculate this based on wallet's y dimension:
num_wallets_per_page = 3
Path(output).unlink(missing_ok=True)
first_page = True
while wallets:
page = Image.new(mode='RGB', size=(x_size, y_size), color='white')
page_back = Image.new(mode='RGB', size=(x_size, y_size), color='white')
wallets_added = 0
while wallets:
wallet = wallets.pop()
page.paste(wallet.front, (100, 100 + wallet.front.size[1] * wallets_added))
page_back.paste(wallet.back, (100, 100 + wallet.back.size[1] * wallets_added))
wallets_added += 1
if wallets_added % num_wallets_per_page == 0:
break
if first_page:
page.save(output)
first_page = False
else:
page.save(output, append=True)
page_back.save(output, append=True)
with open('names') as names:
wallets = []
for name in names:
name = name.rstrip()
seed_phrase = Mnemonic('english').generate(256)
w = Wallet.create(name, keys=seed_phrase, network='bitcoin', witness_type='segwit')
zprv = w.get_key().wif
zpub = w.wif()
wallets.append(gen_paper_wallet(name=name, zpub=zpub, zprv=zprv, seed_phrase=seed_phrase))
gen_pages(wallets, output='BTC_PaperWallet_Design.pdf')