From 84e957879c012155de1fe035ab0a9cb007daeb4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Degros?= <57880064+fdegros@users.noreply.github.com> Date: Fri, 23 Oct 2026 17:45:09 +1100 Subject: [PATCH] Print Paper Wallets for cryptocurrencies without a logo A Paper Wallet displays the cryptocurrency's logo in its center, loaded from slip39/layout/.png. Only a few cryptocurrencies (BNB, BTC, CRO, DOGE, ETH, LTC, XRP) have one, so eg. `slip39 -c DASH -w password` failed with FileNotFoundError: .../DASH.png, after the PDF was already partly written. Leave the center of the wallet blank when there is no logo. --- slip39/layout/pdf.py | 5 ++++- slip39/output_test.py | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/slip39/layout/pdf.py b/slip39/layout/pdf.py index d4b63d23..9859664c 100644 --- a/slip39/layout/pdf.py +++ b/slip39/layout/pdf.py @@ -603,7 +603,10 @@ def write_pdfs( wall_tpl[f"crypto-f{c_n}"] = account.crypto wall_tpl[f"crypto-b{c_n}"] = account.crypto - wall_tpl['center'] = os.path.join( images, account.crypto + '.png' ) + # Not every cryptocurrency has a logo; if not, leave the center of the wallet blank + logo = os.path.join( images, account.crypto + '.png' ) + if os.path.exists( logo ): + wall_tpl['center'] = logo wall_tpl['name-label'] = "Wallet:" wall_tpl['name-bg'] = os.path.join( images, '1x1-ffffff54.png' ) diff --git a/slip39/output_test.py b/slip39/output_test.py index 903c0b4e..63d38a6e 100644 --- a/slip39/output_test.py +++ b/slip39/output_test.py @@ -1,9 +1,10 @@ +import pytest import qrcode from pytest import approx from fpdf import FPDF, FlexTemplate -from .layout import Region, Text, Image, Box, Coordinate +from .layout import Region, Text, Image, Box, Coordinate, write_pdfs from .defaults import MM_IN @@ -73,3 +74,18 @@ def test_Region(): tpl.render( offsetx = card_size.x * MM_IN, offsety = card_size.y * MM_IN ) #pdf.output( "test.pdf" ) # To view results in test.pdf, uncomment + + +def test_wallet_without_logo( tmp_path ): + """A cryptocurrency without a logo image (eg. Dash) still gets a Paper Wallet, w/ a blank center.""" + pytest.importorskip( "Crypto.Protocol.KDF" ) # BIP-38 encrypted Paper Wallets require scrypt + results = write_pdfs( + names = [ "Test" ], + master_secret = bytes.fromhex( "ff" * 16 ), + cryptocurrency = [ "DASH" ], + filepath = str( tmp_path ), + filename = "wallet-dash", + wallet_pwd = "password", + ) + assert list( results ) == [ "wallet-dash.pdf" ] + assert ( tmp_path / "wallet-dash.pdf" ).stat().st_size > 0