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:
parent
d7584533ce
commit
baa9f37a6c
@ -690,6 +690,7 @@ static void _librust_qstrs(void) {
|
|||||||
MP_QSTR_time_ms;
|
MP_QSTR_time_ms;
|
||||||
MP_QSTR_timer;
|
MP_QSTR_timer;
|
||||||
MP_QSTR_title;
|
MP_QSTR_title;
|
||||||
|
MP_QSTR_title_success;
|
||||||
MP_QSTR_total_amount;
|
MP_QSTR_total_amount;
|
||||||
MP_QSTR_total_fee_new;
|
MP_QSTR_total_fee_new;
|
||||||
MP_QSTR_total_len;
|
MP_QSTR_total_len;
|
||||||
|
@ -96,6 +96,7 @@ pub fn new_get_address(
|
|||||||
account: Option<TString<'static>>,
|
account: Option<TString<'static>>,
|
||||||
path: Option<TString<'static>>,
|
path: Option<TString<'static>>,
|
||||||
xpubs: Obj, // TODO: get rid of Obj
|
xpubs: Obj, // TODO: get rid of Obj
|
||||||
|
title_success: TString<'static>,
|
||||||
br_code: u16,
|
br_code: u16,
|
||||||
br_name: TString<'static>,
|
br_name: TString<'static>,
|
||||||
) -> Result<SwipeFlow, error::Error> {
|
) -> Result<SwipeFlow, error::Error> {
|
||||||
@ -141,7 +142,7 @@ pub fn new_get_address(
|
|||||||
|
|
||||||
let content_confirmed = Frame::left_aligned(
|
let content_confirmed = Frame::left_aligned(
|
||||||
TR::words__title_success.into(),
|
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_footer(TR::instructions__continue_in_app.into(), None)
|
||||||
.with_result_icon(theme::ICON_BULLET_CHECKMARK, theme::GREEN_LIGHT)
|
.with_result_icon(theme::ICON_BULLET_CHECKMARK, theme::GREEN_LIGHT)
|
||||||
@ -156,7 +157,7 @@ pub fn new_get_address(
|
|||||||
theme::ICON_CHEVRON_RIGHT,
|
theme::ICON_CHEVRON_RIGHT,
|
||||||
TR::address_details__account_info.into(),
|
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_cancel_button()
|
||||||
.with_swipe(Direction::Right, SwipeSettings::immediate())
|
.with_swipe(Direction::Right, SwipeSettings::immediate())
|
||||||
|
@ -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 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 path: Option<TString> = kwargs.get(Qstr::MP_QSTR_path)?.try_into_option()?;
|
||||||
let xpubs: Obj = kwargs.get(Qstr::MP_QSTR_xpubs)?;
|
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_name: TString = kwargs.get(Qstr::MP_QSTR_br_name)?.try_into()?;
|
||||||
let br_code: u16 = kwargs.get(Qstr::MP_QSTR_br_code)?.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,
|
account,
|
||||||
path,
|
path,
|
||||||
xpubs,
|
xpubs,
|
||||||
|
title_success,
|
||||||
br_code,
|
br_code,
|
||||||
br_name,
|
br_name,
|
||||||
)?;
|
)?;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from apps.common.keychain import auto_keychain
|
from apps.common.keychain import auto_keychain
|
||||||
|
from apps.common.signverify import decode_message
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from trezor.messages import NostrGetPubkey, NostrPubkey
|
from trezor.messages import NostrGetPubkey, NostrPubkey
|
||||||
@ -10,11 +11,25 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
@auto_keychain(__name__)
|
@auto_keychain(__name__)
|
||||||
async def get_pubkey(msg: NostrGetPubkey, keychain: Keychain) -> NostrPubkey:
|
async def get_pubkey(msg: NostrGetPubkey, keychain: Keychain) -> NostrPubkey:
|
||||||
|
from ubinascii import hexlify
|
||||||
from trezor.messages import NostrPubkey
|
from trezor.messages import NostrPubkey
|
||||||
|
|
||||||
address_n = msg.address_n
|
address_n = msg.address_n
|
||||||
|
show_display = msg.show_display
|
||||||
|
|
||||||
node = keychain.derive(address_n)
|
node = keychain.derive(address_n)
|
||||||
pk = node.public_key()[-32:]
|
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)
|
return NostrPubkey(pubkey=pk)
|
||||||
|
@ -275,11 +275,12 @@ async def show_address(
|
|||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
title_success = (
|
if title in ("XPUB", TR.address__public_key):
|
||||||
TR.address__public_key_confirmed
|
title_success="address__public_key_confirmed"
|
||||||
if title in ("XPUB", TR.address__public_key)
|
elif title in ("npub", ):
|
||||||
else TR.address__confirmed
|
title_success = "npub confirmed"
|
||||||
)
|
else:
|
||||||
|
title_success = TR.address__confirmed
|
||||||
|
|
||||||
await raise_if_not_confirmed(
|
await raise_if_not_confirmed(
|
||||||
trezorui2.flow_get_address(
|
trezorui2.flow_get_address(
|
||||||
|
@ -33,10 +33,12 @@ def cli() -> None:
|
|||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@click.option("-n", "--address", default="m/44'/1237'/0'/0/0", help="BIP-32 path")
|
@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
|
@with_client
|
||||||
def get_pubkey(
|
def get_pubkey(
|
||||||
client: "TrezorClient",
|
client: "TrezorClient",
|
||||||
address: str,
|
address: str,
|
||||||
|
show_display: bool,
|
||||||
) -> Dict[str, str]:
|
) -> Dict[str, str]:
|
||||||
"""Derive the pubkey from the seed."""
|
"""Derive the pubkey from the seed."""
|
||||||
|
|
||||||
@ -45,6 +47,7 @@ def get_pubkey(
|
|||||||
res = nostr.get_pubkey(
|
res = nostr.get_pubkey(
|
||||||
client,
|
client,
|
||||||
address_n,
|
address_n,
|
||||||
|
show_display=show_display,
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -31,10 +31,12 @@ if TYPE_CHECKING:
|
|||||||
def get_pubkey(
|
def get_pubkey(
|
||||||
client: "TrezorClient",
|
client: "TrezorClient",
|
||||||
n: "Address",
|
n: "Address",
|
||||||
|
show_display: bool = False,
|
||||||
) -> "MessageType":
|
) -> "MessageType":
|
||||||
return client.call(
|
return client.call(
|
||||||
messages.NostrGetPubkey(
|
messages.NostrGetPubkey(
|
||||||
address_n=n,
|
address_n=n,
|
||||||
|
show_display=show_display,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user