More notes

This commit is contained in:
Peter D. Gray 2019-11-20 18:58:03 -05:00
parent f4bca925e9
commit 4cbc62f753
No known key found for this signature in database
GPG Key ID: F0E6CC6AFC16CF7B
9 changed files with 3504 additions and 24 deletions

View File

@ -3,10 +3,22 @@
- an artist creates the PDF with background artwork, blank spots for QR's
- locations for pubkey, privkey QR's and text blocks are defined mm by mm
- run this program to add placeholders objects for the 2 QR codes, related variable text
- a template file, which looks and acts like a PDF is constructed
- use the resulting (pdf) file on Coldcard as a template
- a template file--which looks and acts like a PDF---is constructed, in `./templates`
- use the resulting (pdf) file on Coldcard via a MicroSD card
- the Coldcard can find what it needs inside the PDF template and will modify it with final values
# Design Tips
- you must include whitespace around the QR code: more the better, and should be fully 'quiet'
- QR will have background white / black pixels ... so do not place over gradient
# TODO
This project isn't done yet!
- make it easier to add new templates
- build a gallery of useful examples
- make many seasonal templates, starting with American Thanksgiving and Christmas.
# References
- [PDF 1.3?](https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/pdf_reference_archives/PDFReference.pdf)
@ -22,9 +34,3 @@
- Command to go from PNG with alpha and some text into simple PNM file:
`pngtopam -mix -background=#FFF qrsample-pk.png | pamditherbw -threshold | pamtopnm > qrsample-pk.pnm
# Design Tips
- you must include whitespace around the QR code: more the better, and should be fully 'quiet'
- QR will be background white / black pixels ... so do not place over gradient

View File

@ -76,7 +76,7 @@ class TemplateBuilder(object):
def insert_values(self, page_num, *values):
raise NotImplemented
def make_custom(self, *values):
def make_custom(self, template_name):
c = self.canvas
for page_num, xobjlist in enumerate(self.xobjs):
@ -97,7 +97,7 @@ class TemplateBuilder(object):
c.restoreState()
# put our data on "top"
self.insert_values(page_num, *values)
self.insert_values(page_num, template_name)
x += xobj.BBox[2]
@ -151,7 +151,27 @@ class TemplateBuilder(object):
class WalletBuilder(TemplateBuilder):
def insert_values(self, page_num, *unused):
def insert_values(self, page_num, template_name):
if template_name == 'placeholder':
self.add_qr_spot('addr', placeholders.addr, 1.5*inch, 3.75*inch)
self.add_qr_spot('pk', placeholders.privkey, 6.75*inch, 3.75*inch)
self.add_qr_spot('pk', placeholders.privkey, 6.75*inch, 1*inch, inch)
for i in range(3):
self.add_qr_spot('addr', None, (0.75*inch) + (1.5*i*inch), 1.25*inch, inch)
self.address_at(1.00*inch, 1.0*inch)
elif template_name == 'coldcard-paper':
x = 1.5*inch
self.addr_qr(x, 7.5*inch, 2*inch)
self.privkey_qr(x, 1.1*inch, 2*inch)
else:
print(f"\n\nDefine code for: {template_name}\n\n")
def XXX_insert_values(self, page_num, *unused):
c = self.canvas
if 0:
@ -169,14 +189,34 @@ class WalletBuilder(TemplateBuilder):
c.restoreState()
self.add_qr_spot('addr', placeholders.addr, 1.5*inch, 3.75*inch)
self.add_qr_spot('pk', placeholders.privkey, 6.75*inch, 3.75*inch)
self.add_qr_spot('pk', placeholders.privkey, 6.75*inch, 1*inch, inch)
for i in range(3):
self.add_qr_spot('addr', None, (0.75*inch) + (1.5*i*inch), 1.25*inch, inch)
def addr_qr(self, x,y, size=1*inch, no_text=False):
self.add_qr_spot('addr', placeholders.addr if not no_text else None, x,y, page_size=size)
c.drawString(1.00*inch, 1.0*inch, placeholders.addr)
def privkey_qr(self, x,y, size=1*inch, no_text=False):
self.add_qr_spot('pk', placeholders.privkey if not no_text else None, x,y, page_size=size)
def address_at(self, x,y, **kws):
self.add_text(placeholders.addr, x, y, **kws)
def privkey_at(self, x,y, **kws):
self.add_text(placeholders.privkey, x, y, **kws)
def add_text(self, msg, x,y, font_size=12, font_name='Courier'):
c = self.canvas
c.saveState()
# change color: black
c.setFillColorRGB(0,0,0)
c.setStrokeColorRGB(0,0,0)
# size and font name.
c.setFont(font_name, font_size)
c.drawString(x, y, msg)
c.restoreState()
def add_qr_spot(self, name, subtext, x,y, page_size=2.25*inch, SZ=33*8):
@ -238,8 +278,6 @@ class WalletBuilder(TemplateBuilder):
lines.append(sample[o:o+(SZ//8)])
lines[0] = fl
#ximg.streamContent = fl + '\n' + '\n'.join(('%02X'%(0xff if (i>>2)%2 else 0x00))*(SZ//8)
# for i in range(SZ-1)) + '\n'
ximg.streamContent = '\n'.join(ln.hex().upper() for ln in lines)
ximg.streamContent += '\n'
@ -287,12 +325,15 @@ def file_checker(fname):
if __name__ == '__main__':
foo = WalletBuilder('placeholder.pdf', 'output.pdf')
foo.make_custom()
foo.finalize()
for fn in [ 'coldcard-paper', 'placeholder']:
file_checker('output.pdf')
outfile = f'outputs/{fn}.pdf'
os.system('open output.pdf')
foo = WalletBuilder(f'templates/{fn}.pdf', outfile)
foo.make_custom(fn)
foo.finalize()
file_checker(outfile)
os.system(f'open {outfile}')
# EOF

7
outputs/README.md Normal file
View File

@ -0,0 +1,7 @@
# Outputs
These are the files that you would copy to a MicroSD and carry to your Coldcard.

BIN
outputs/coldcard-paper.pdf Normal file

Binary file not shown.

BIN
outputs/placeholder.pdf Normal file

Binary file not shown.

11
templates/README.md Normal file
View File

@ -0,0 +1,11 @@
# Templates
These are just regular PDF files, created by whatever programs.
Leave blank spaces for where the QR codes should go.
For now, the `../build.py` program must be changed to control where
the QR's end up on the page (and other text, if desired).

3415
templates/coldcard-paper.pdf Normal file

File diff suppressed because one or more lines are too long