From 775b7c83b814694b16e7a72c8b4d87323351d4f4 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Wed, 21 Jan 2026 21:26:57 +0100 Subject: [PATCH] Nostr: show QR of npub --- .../assets/fullscreen_qr.py | 21 +++++++- .../assets/nostr_app.py | 54 +++++++++++++++++++ .../assets/nostr_client.py | 2 +- .../lib/mpos/ui/settings_activity.py | 4 +- 4 files changed, 77 insertions(+), 4 deletions(-) diff --git a/internal_filesystem/apps/com.micropythonos.nostr/assets/fullscreen_qr.py b/internal_filesystem/apps/com.micropythonos.nostr/assets/fullscreen_qr.py index 0941c855..f13022b2 100644 --- a/internal_filesystem/apps/com.micropythonos.nostr/assets/fullscreen_qr.py +++ b/internal_filesystem/apps/com.micropythonos.nostr/assets/fullscreen_qr.py @@ -6,7 +6,23 @@ class FullscreenQR(Activity): # No __init__() so super.__init__() will be called automatically def onCreate(self): - receive_qr_data = self.getIntent().extras.get("receive_qr_data") + print("FullscreenQR.onCreate() called") + intent = self.getIntent() + print(f"Got intent: {intent}") + extras = intent.extras + print(f"Got extras: {extras}") + receive_qr_data = extras.get("receive_qr_data") + print(f"Got receive_qr_data: {receive_qr_data}") + + if not receive_qr_data: + print("ERROR: receive_qr_data is None or empty!") + error_screen = lv.obj() + error_label = lv.label(error_screen) + error_label.set_text("No QR data") + error_label.center() + self.setContentView(error_screen) + return + qr_screen = lv.obj() qr_screen.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF) qr_screen.set_scroll_dir(lv.DIR.NONE) @@ -18,5 +34,8 @@ class FullscreenQR(Activity): big_receive_qr.center() big_receive_qr.set_style_border_color(lv.color_white(), 0) big_receive_qr.set_style_border_width(0, 0); + print(f"Updating QR code with data: {receive_qr_data[:20]}...") big_receive_qr.update(receive_qr_data, len(receive_qr_data)) + print("QR code updated, setting content view") self.setContentView(qr_screen) + print("Content view set") diff --git a/internal_filesystem/apps/com.micropythonos.nostr/assets/nostr_app.py b/internal_filesystem/apps/com.micropythonos.nostr/assets/nostr_app.py index 83a63eab..ccc0603d 100644 --- a/internal_filesystem/apps/com.micropythonos.nostr/assets/nostr_app.py +++ b/internal_filesystem/apps/com.micropythonos.nostr/assets/nostr_app.py @@ -1,6 +1,59 @@ import lvgl as lv from mpos import Activity, Intent, ConnectivityManager, pct_of_display_width, pct_of_display_height, SharedPreferences, SettingsActivity +from fullscreen_qr import FullscreenQR + +class ShowNpubQRActivity(Activity): + """Activity that computes npub from nsec and displays it as a QR code""" + + def onCreate(self): + try: + print("ShowNpubQRActivity.onCreate() called") + prefs = self.getIntent().extras.get("prefs") + print(f"Got prefs: {prefs}") + nsec = prefs.get_string("nostr_nsec") + print(f"Got nsec: {nsec[:20] if nsec else 'None'}...") + + if not nsec: + print("ERROR: No nsec configured") + # Show error screen + error_screen = lv.obj() + error_label = lv.label(error_screen) + error_label.set_text("No nsec configured") + error_label.center() + self.setContentView(error_screen) + return + + # Compute npub from nsec + print("Importing PrivateKey...") + from nostr.key import PrivateKey + print("Computing npub from nsec...") + if nsec.startswith("nsec1"): + print("Using from_nsec()") + private_key = PrivateKey.from_nsec(nsec) + else: + print("Using hex format") + private_key = PrivateKey(bytes.fromhex(nsec)) + + npub = private_key.public_key.bech32() + print(f"Computed npub: {npub[:20]}...") + + # Launch FullscreenQR activity with npub as QR data + print("Creating FullscreenQR intent...") + intent = Intent(activity_class=FullscreenQR) + intent.putExtra("receive_qr_data", npub) + print(f"Starting FullscreenQR activity with npub: {npub[:20]}...") + self.startActivity(intent) + except Exception as e: + print(f"ShowNpubQRActivity exception: {e}") + # Show error screen + error_screen = lv.obj() + error_label = lv.label(error_screen) + error_label.set_text(f"Error: {e}") + error_label.center() + self.setContentView(error_screen) + import sys + sys.print_exception(e) class NostrApp(Activity): @@ -133,6 +186,7 @@ class NostrApp(Activity): {"title": "Nostr Private Key (nsec)", "key": "nostr_nsec", "placeholder": "nsec1...", "should_show": self.should_show_setting}, {"title": "Nostr Follow Public Key (npub)", "key": "nostr_follow_npub", "placeholder": "npub1...", "should_show": self.should_show_setting}, {"title": "Nostr Relay", "key": "nostr_relay", "placeholder": "wss://relay.example.com", "should_show": self.should_show_setting}, + {"title": "Show My Public Key (npub)", "key": "show_npub_qr", "ui": "activity", "activity_class": ShowNpubQRActivity, "dont_persist": True, "should_show": self.should_show_setting}, ]) self.startActivity(intent) diff --git a/internal_filesystem/apps/com.micropythonos.nostr/assets/nostr_client.py b/internal_filesystem/apps/com.micropythonos.nostr/assets/nostr_client.py index 51ad7ff0..6280d327 100644 --- a/internal_filesystem/apps/com.micropythonos.nostr/assets/nostr_client.py +++ b/internal_filesystem/apps/com.micropythonos.nostr/assets/nostr_client.py @@ -23,7 +23,7 @@ class NostrEvent: class NostrClient(): """Simple Nostr event subscriber that connects to a relay and subscribes to a public key's events""" - EVENTS_TO_SHOW = 10 + EVENTS_TO_SHOW = 50 relay = None nsec = None diff --git a/internal_filesystem/lib/mpos/ui/settings_activity.py b/internal_filesystem/lib/mpos/ui/settings_activity.py index 13254e5d..6c760edd 100644 --- a/internal_filesystem/lib/mpos/ui/settings_activity.py +++ b/internal_filesystem/lib/mpos/ui/settings_activity.py @@ -67,13 +67,13 @@ class SettingsActivity(Activity): focusgroup.add_obj(setting_cont) def focus_container(self, container): - print(f"container {container} focused, setting border...") + #print(f"container {container} focused, setting border...") container.set_style_border_color(lv.theme_get_color_primary(None),lv.PART.MAIN) container.set_style_border_width(1, lv.PART.MAIN) container.scroll_to_view(True) # scroll to bring it into view def defocus_container(self, container): - print(f"container {container} defocused, unsetting border...") + #print(f"container {container} defocused, unsetting border...") container.set_style_border_width(0, lv.PART.MAIN) def startSettingActivity(self, setting):