1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-12 09:28:10 +00:00

feat(nostr): UI for get_pubkey

This commit is contained in:
obrusvit 2024-12-11 17:31:12 +01:00
parent d7584533ce
commit baa9f37a6c
7 changed files with 32 additions and 7 deletions

View File

@ -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;

View File

@ -96,6 +96,7 @@ pub fn new_get_address(
account: Option<TString<'static>>,
path: Option<TString<'static>>,
xpubs: Obj, // TODO: get rid of Obj
title_success: TString<'static>,
br_code: u16,
br_name: TString<'static>,
) -> Result<SwipeFlow, error::Error> {
@ -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())

View File

@ -1177,6 +1177,7 @@ extern "C" fn new_get_address(n_args: usize, args: *const Obj, kwargs: *mut Map)
let account: Option<TString> = kwargs.get(Qstr::MP_QSTR_account)?.try_into_option()?;
let path: Option<TString> = 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,
)?;

View File

@ -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)

View File

@ -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(

View File

@ -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 {

View File

@ -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,
)
)