Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Update seed_phrase_to_qr.py; warnings, add Compact SeedQR #523

Merged
merged 2 commits into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions tools/seed_phrase_to_qr.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,44 @@
from seedsigner.models.encode_qr import CompactSeedQrEncoder, SeedQrEncoder
from seedsigner.models.seed import Seed
from seedsigner.models.settings_definition import SettingsConstants

"""
This is a utility for testing / dev purposes only.
"""

if __name__ == "__main__":
import qrcode
import sys
from embit import bip39

print(sys.argv)
seed_phrase = sys.argv[1:]
print(seed_phrase)
print("""
*******************************************************************************

This is a utility for testing / dev purposes ONLY.

A SeedQR for a real seed holding actual value should never be created
this way.

*******************************************************************************
""")

data = ""
for word in seed_phrase:
index = bip39.WORDLIST.index(word)
data += str("%04d" % index)
COMPACT = 1
STANDARD = 2
format = int(input("1. Compact SeedQR\n2. Standard SeedQR\nEnter 1 or 2: ").strip())
if format not in [COMPACT, STANDARD]:
print("Invalid option")
sys.exit(1)

seed_phrase = input("\nEnter 12- or 24-word test seed phrase: ").strip().split(" ")

if format == COMPACT:
encoder = CompactSeedQrEncoder(seed_phrase=seed_phrase, wordlist_language_code=SettingsConstants.WORDLIST_LANGUAGE__ENGLISH)
else:
encoder = SeedQrEncoder(seed_phrase=seed_phrase, wordlist_language_code=SettingsConstants.WORDLIST_LANGUAGE__ENGLISH)

qr = qrcode.QRCode( version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=5, border=3)
qr.add_data(data)
qr.add_data(encoder.next_part())
qr.make(fit=True)
qr.make_image(fill_color="black", back_color="white").resize((240,240)).convert('RGB').show()

seed = Seed(seed_phrase)
print(f"\nfingerprint: {seed.get_fingerprint()}\n")
Loading