From 4350b0d31dc52faf1c6021a94e2e6f68f6e82ee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ioan=20Biz=C4=83u?= Date: Tue, 17 Dec 2024 18:08:07 +0100 Subject: [PATCH] feat(core/ui): add basic confirmation for Nostr signing [no changelog] --- core/embed/rust/librust_qstr.h | 1 + .../translations/generated/translated_string.rs | 6 ++++++ core/mocks/trezortranslate_keys.pyi | 1 + core/src/apps/nostr/sign_event.py | 15 +++++++++++++++ core/src/trezor/ui/layouts/caesar/__init__.py | 1 + core/translations/en.json | 1 + core/translations/order.json | 3 ++- core/translations/signatures.json | 6 +++--- 8 files changed, 30 insertions(+), 4 deletions(-) diff --git a/core/embed/rust/librust_qstr.h b/core/embed/rust/librust_qstr.h index 00b6fb1642..622ff3c297 100644 --- a/core/embed/rust/librust_qstr.h +++ b/core/embed/rust/librust_qstr.h @@ -339,6 +339,7 @@ static void _librust_qstrs(void) { MP_QSTR_modify_fee__transaction_fee; MP_QSTR_more_info_callback; MP_QSTR_multiple_pages_texts; + MP_QSTR_nostr__event_kind_template; MP_QSTR_notification; MP_QSTR_notification_level; MP_QSTR_page_count; diff --git a/core/embed/rust/src/translations/generated/translated_string.rs b/core/embed/rust/src/translations/generated/translated_string.rs index 708fb751bb..c383e180ea 100644 --- a/core/embed/rust/src/translations/generated/translated_string.rs +++ b/core/embed/rust/src/translations/generated/translated_string.rs @@ -1402,6 +1402,8 @@ pub enum TranslatedString { solana__stake_on_question = 989, // "Stake SOL on {0}?" sign_message__confirm_without_review = 990, // "Confirm without review" instructions__tap_to_continue = 991, // "Tap to continue" + #[cfg(feature = "universal_fw")] + nostr__event_kind_template = 992, // "Event kind: {0}" } impl TranslatedString { @@ -2800,6 +2802,8 @@ impl TranslatedString { Self::solana__stake_on_question => "Stake SOL on {0}?", Self::sign_message__confirm_without_review => "Confirm without review", Self::instructions__tap_to_continue => "Tap to continue", + #[cfg(feature = "universal_fw")] + Self::nostr__event_kind_template => "Event kind: {0}", } } @@ -4197,6 +4201,8 @@ impl TranslatedString { Qstr::MP_QSTR_solana__stake_on_question => Some(Self::solana__stake_on_question), Qstr::MP_QSTR_sign_message__confirm_without_review => Some(Self::sign_message__confirm_without_review), Qstr::MP_QSTR_instructions__tap_to_continue => Some(Self::instructions__tap_to_continue), + #[cfg(feature = "universal_fw")] + Qstr::MP_QSTR_nostr__event_kind_template => Some(Self::nostr__event_kind_template), _ => None, } } diff --git a/core/mocks/trezortranslate_keys.pyi b/core/mocks/trezortranslate_keys.pyi index 251abf39fe..8a7a9c7e42 100644 --- a/core/mocks/trezortranslate_keys.pyi +++ b/core/mocks/trezortranslate_keys.pyi @@ -497,6 +497,7 @@ class TR: nem__under_namespace: str = "under namespace" nem__unencrypted: str = "Unencrypted" nem__unknown_mosaic: str = "Unknown mosaic!" + nostr__event_kind_template: str = "Event kind: {0}" passphrase__access_wallet: str = "Access passphrase wallet?" passphrase__always_on_device: str = "Always enter your passphrase on Trezor?" passphrase__continue_with_empty_passphrase: str = "Continue with empty passphrase?" diff --git a/core/src/apps/nostr/sign_event.py b/core/src/apps/nostr/sign_event.py index 26a2f5e0f6..95d02b8a6c 100644 --- a/core/src/apps/nostr/sign_event.py +++ b/core/src/apps/nostr/sign_event.py @@ -12,9 +12,11 @@ if TYPE_CHECKING: async def sign_event(msg: NostrSignEvent, keychain: Keychain) -> NostrEventSignature: from ubinascii import hexlify + from trezor import TR from trezor.crypto.curve import secp256k1 from trezor.crypto.hashlib import sha256 from trezor.messages import NostrEventSignature + from trezor.ui.layouts import confirm_value from apps.common import paths @@ -29,6 +31,19 @@ async def sign_event(msg: NostrSignEvent, keychain: Keychain) -> NostrEventSigna node = keychain.derive(address_n) pk = node.public_key()[-32:] + title = TR.nostr__event_kind_template.format(kind) + + # confirm_value on TR only accepts one single info item + # which is why we concatenate all of them here. + # This is not great, but it gets the job done for now. + tags_str = f"created_at: {created_at}" + for t in tags: + tags_str += f"\n\n{t[0]}: " + (f" {' '.join(t[1:])}" if len(t) > 1 else "") + + await confirm_value( + title, content, "", "nostr_sign_event", info_items=[("", tags_str)] + ) + # The event ID is obtained by serializing the event in a specific way: # "[0,pubkey,created_at,kind,tags,content]" # See NIP-01: https://github.com/nostr-protocol/nips/blob/master/01.md diff --git a/core/src/trezor/ui/layouts/caesar/__init__.py b/core/src/trezor/ui/layouts/caesar/__init__.py index ad150ace98..78649ee02c 100644 --- a/core/src/trezor/ui/layouts/caesar/__init__.py +++ b/core/src/trezor/ui/layouts/caesar/__init__.py @@ -792,6 +792,7 @@ async def confirm_value( else: info_items_list = list(info_items) if len(info_items_list) > 1: + # TODO: Support more than one info item! raise NotImplementedError("Only one info item is supported") send_button_request = True diff --git a/core/translations/en.json b/core/translations/en.json index 5bf97e8726..1ff68b19bf 100644 --- a/core/translations/en.json +++ b/core/translations/en.json @@ -499,6 +499,7 @@ "nem__under_namespace": "under namespace", "nem__unencrypted": "Unencrypted", "nem__unknown_mosaic": "Unknown mosaic!", + "nostr__event_kind_template": "Event kind: {0}", "passphrase__access_wallet": "Access passphrase wallet?", "passphrase__always_on_device": "Always enter your passphrase on Trezor?", "passphrase__continue_with_empty_passphrase": "Continue with empty passphrase?", diff --git a/core/translations/order.json b/core/translations/order.json index 0277b416a4..409080d865 100644 --- a/core/translations/order.json +++ b/core/translations/order.json @@ -990,5 +990,6 @@ "988": "solana__vote_account", "989": "solana__stake_on_question", "990": "sign_message__confirm_without_review", - "991": "instructions__tap_to_continue" + "991": "instructions__tap_to_continue", + "992": "nostr__event_kind_template" } diff --git a/core/translations/signatures.json b/core/translations/signatures.json index ab8022461c..2d89bc3912 100644 --- a/core/translations/signatures.json +++ b/core/translations/signatures.json @@ -1,8 +1,8 @@ { "current": { - "merkle_root": "1754d367a3f9796a460e21677a38465ac51110a5abaae96a8977e64cd3d35e27", - "datetime": "2025-02-25T22:15:23.529862", - "commit": "ba8a64d3e42febd344f60f039b6ac21ffb36aa9c" + "merkle_root": "6684203c68c3a64d607c948fac5eeaa9f349f0e81cf54c8dfc662d5a8d3662e8", + "datetime": "2025-02-27T10:39:27.809453", + "commit": "3dd1b0c026405da729821b8130baa7bfff432121" }, "history": [ {