From baa9f37a6c6d8da7e2658678672196cb41c1d288 Mon Sep 17 00:00:00 2001 From: obrusvit Date: Wed, 11 Dec 2024 17:31:12 +0100 Subject: [PATCH] feat(nostr): UI for get_pubkey --- core/embed/rust/librust_qstr.h | 1 + .../rust/src/ui/model_mercury/flow/get_address.rs | 5 +++-- core/embed/rust/src/ui/model_mercury/layout.rs | 2 ++ core/src/apps/nostr/get_pubkey.py | 15 +++++++++++++++ core/src/trezor/ui/layouts/mercury/__init__.py | 11 ++++++----- python/src/trezorlib/cli/nostr.py | 3 +++ python/src/trezorlib/nostr.py | 2 ++ 7 files changed, 32 insertions(+), 7 deletions(-) diff --git a/core/embed/rust/librust_qstr.h b/core/embed/rust/librust_qstr.h index 440dac4555..eefe1918bc 100644 --- a/core/embed/rust/librust_qstr.h +++ b/core/embed/rust/librust_qstr.h @@ -690,6 +690,7 @@ static void _librust_qstrs(void) { MP_QSTR_time_ms; MP_QSTR_timer; MP_QSTR_title; + MP_QSTR_title_success; MP_QSTR_total_amount; MP_QSTR_total_fee_new; MP_QSTR_total_len; diff --git a/core/embed/rust/src/ui/model_mercury/flow/get_address.rs b/core/embed/rust/src/ui/model_mercury/flow/get_address.rs index c81b28a109..8209c6def8 100644 --- a/core/embed/rust/src/ui/model_mercury/flow/get_address.rs +++ b/core/embed/rust/src/ui/model_mercury/flow/get_address.rs @@ -96,6 +96,7 @@ pub fn new_get_address( account: Option>, path: Option>, xpubs: Obj, // TODO: get rid of Obj + title_success: TString<'static>, br_code: u16, br_name: TString<'static>, ) -> Result { @@ -141,7 +142,7 @@ pub fn new_get_address( let content_confirmed = Frame::left_aligned( TR::words__title_success.into(), - StatusScreen::new_success_timeout(TR::address__confirmed.into()), + StatusScreen::new_success_timeout(title_success), ) .with_footer(TR::instructions__continue_in_app.into(), None) .with_result_icon(theme::ICON_BULLET_CHECKMARK, theme::GREEN_LIGHT) @@ -156,7 +157,7 @@ pub fn new_get_address( theme::ICON_CHEVRON_RIGHT, TR::address_details__account_info.into(), ) - .danger(theme::ICON_CANCEL, TR::address__cancel_receive.into()), + .danger(theme::ICON_CANCEL, TR::buttons__cancel.into()), ) .with_cancel_button() .with_swipe(Direction::Right, SwipeSettings::immediate()) diff --git a/core/embed/rust/src/ui/model_mercury/layout.rs b/core/embed/rust/src/ui/model_mercury/layout.rs index 4838aeb503..8582889c14 100644 --- a/core/embed/rust/src/ui/model_mercury/layout.rs +++ b/core/embed/rust/src/ui/model_mercury/layout.rs @@ -1177,6 +1177,7 @@ extern "C" fn new_get_address(n_args: usize, args: *const Obj, kwargs: *mut Map) let account: Option = kwargs.get(Qstr::MP_QSTR_account)?.try_into_option()?; let path: Option = kwargs.get(Qstr::MP_QSTR_path)?.try_into_option()?; let xpubs: Obj = kwargs.get(Qstr::MP_QSTR_xpubs)?; + let title_success: TString = kwargs.get(Qstr::MP_QSTR_title_success)?.try_into()?; let br_name: TString = kwargs.get(Qstr::MP_QSTR_br_name)?.try_into()?; let br_code: u16 = kwargs.get(Qstr::MP_QSTR_br_code)?.try_into()?; @@ -1191,6 +1192,7 @@ extern "C" fn new_get_address(n_args: usize, args: *const Obj, kwargs: *mut Map) account, path, xpubs, + title_success, br_code, br_name, )?; diff --git a/core/src/apps/nostr/get_pubkey.py b/core/src/apps/nostr/get_pubkey.py index 00ec73ab56..bfb6e2f9a3 100644 --- a/core/src/apps/nostr/get_pubkey.py +++ b/core/src/apps/nostr/get_pubkey.py @@ -1,6 +1,7 @@ from typing import TYPE_CHECKING from apps.common.keychain import auto_keychain +from apps.common.signverify import decode_message if TYPE_CHECKING: from trezor.messages import NostrGetPubkey, NostrPubkey @@ -10,11 +11,25 @@ if TYPE_CHECKING: @auto_keychain(__name__) async def get_pubkey(msg: NostrGetPubkey, keychain: Keychain) -> NostrPubkey: + from ubinascii import hexlify from trezor.messages import NostrPubkey address_n = msg.address_n + show_display = msg.show_display node = keychain.derive(address_n) pk = node.public_key()[-32:] + if show_display: + from trezor.ui.layouts import show_pubkey + + await show_pubkey( + decode_message(hexlify(pk)), + title="npub", + account=None, + path=None, + mismatch_title="npub mismatch?", + br_name="show_npub", + ) + return NostrPubkey(pubkey=pk) diff --git a/core/src/trezor/ui/layouts/mercury/__init__.py b/core/src/trezor/ui/layouts/mercury/__init__.py index aab3205d59..e11e29a1ba 100644 --- a/core/src/trezor/ui/layouts/mercury/__init__.py +++ b/core/src/trezor/ui/layouts/mercury/__init__.py @@ -275,11 +275,12 @@ async def show_address( ) return result - title_success = ( - TR.address__public_key_confirmed - if title in ("XPUB", TR.address__public_key) - else TR.address__confirmed - ) + if title in ("XPUB", TR.address__public_key): + title_success="address__public_key_confirmed" + elif title in ("npub", ): + title_success = "npub confirmed" + else: + title_success = TR.address__confirmed await raise_if_not_confirmed( trezorui2.flow_get_address( diff --git a/python/src/trezorlib/cli/nostr.py b/python/src/trezorlib/cli/nostr.py index 864490bbad..02cef2caa5 100644 --- a/python/src/trezorlib/cli/nostr.py +++ b/python/src/trezorlib/cli/nostr.py @@ -33,10 +33,12 @@ def cli() -> None: @cli.command() @click.option("-n", "--address", default="m/44'/1237'/0'/0/0", help="BIP-32 path") +@click.option("-d", "--show-display", is_flag=True) @with_client def get_pubkey( client: "TrezorClient", address: str, + show_display: bool, ) -> Dict[str, str]: """Derive the pubkey from the seed.""" @@ -45,6 +47,7 @@ def get_pubkey( res = nostr.get_pubkey( client, address_n, + show_display=show_display, ) return { diff --git a/python/src/trezorlib/nostr.py b/python/src/trezorlib/nostr.py index 41c56047b4..31d4ab8484 100644 --- a/python/src/trezorlib/nostr.py +++ b/python/src/trezorlib/nostr.py @@ -31,10 +31,12 @@ if TYPE_CHECKING: def get_pubkey( client: "TrezorClient", n: "Address", + show_display: bool = False, ) -> "MessageType": return client.call( messages.NostrGetPubkey( address_n=n, + show_display=show_display, ) )