Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/embed/extmod/modtrezorconfig/modtrezorconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_unlock_obj, 2, 3,
mod_trezorconfig_unlock);

/// def check_pin(pin: str, ext_salt: bytes | None, pin_use_type: int = 0) ->
/// bool:
/// tuple[bool, int]:
/// """
/// Check the given PIN with the given external salt.
/// Returns True on success, False on failure.
Expand Down
2 changes: 1 addition & 1 deletion core/mocks/generated/trezorconfig.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def unlock(pin: str, ext_salt: bytes | None, pin_use_type: int = 0)

# extmod/modtrezorconfig/modtrezorconfig.c
def check_pin(pin: str, ext_salt: bytes | None, pin_use_type: int = 0) ->
bool:
tuple[bool, int]:
"""
Check the given PIN with the given external salt.
Returns True on success, False on failure.
Expand Down
2 changes: 2 additions & 0 deletions core/src/all_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
import storage.sd_salt
trezor
import trezor
trezor.config
import trezor.config
trezor.crypto
import trezor.crypto
trezor.crypto.base32
Expand Down
7 changes: 6 additions & 1 deletion core/src/apps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ async def handle_CancelAuthorization(
)


def set_homescreen() -> None:
def set_homescreen(show_app_guide: bool = False) -> None:
import lvgl as lv # type: ignore[Import "lvgl" could not be resolved]

from trezor.lvglui.scrs import fingerprints
Expand All @@ -483,6 +483,11 @@ def set_homescreen() -> None:

store_ble_name(ble_name)
screen = MainScreen(device_name, ble_name, dev_state)
if show_app_guide:
from trezor.lvglui.scrs import app_guide

app_guide.GuideAppDownload()

if not first_unlock:
first_unlock = True
if (
Expand Down
34 changes: 8 additions & 26 deletions core/src/apps/common/request_pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,7 @@ async def verify_user_pin(

if not config.is_unlocked():
try:
result = config.unlock(pin, salt, pin_use_type)
if isinstance(result, tuple):
verified, usertype = result
else:
verified = result
usertype = PinResult.USER_PIN_ENTERED
print("usertype", usertype)

verified, usertype = config.unlock(pin, salt, pin_use_type)
if verified:
if usertype == PinResult.PASSPHRASE_PIN_ENTERED:
device.set_passphrase_pin_enabled(True)
Expand All @@ -181,12 +174,9 @@ async def verify_user_pin(
raise wire.PinCancelled("cancle")
else:
try:
result = config.check_pin(pin, salt, pin_use_type)
if isinstance(result, tuple):
verified, usertype = result
else:
verified = result
usertype = PinResult.USER_PIN_ENTERED
verified, usertype = config.check_pin(
pin, salt, pin_use_type, auto_vibrate=True
)
if verified:
if usertype == PinResult.PASSPHRASE_PIN_ENTERED:
device.set_passphrase_pin_enabled(True)
Expand Down Expand Up @@ -224,19 +214,11 @@ async def verify_user_pin(

try:
if not config.is_unlocked():
result = config.unlock(pin, salt, pin_use_type)
if isinstance(result, tuple):
verified, usertype = result
else:
verified = result
usertype = PinResult.USER_PIN_ENTERED
else:
result = config.check_pin(pin, salt, pin_use_type)
if isinstance(result, tuple):
verified, usertype = result
verified, usertype = config.unlock(pin, salt, pin_use_type)
else:
verified = result
usertype = PinResult.USER_PIN_ENTERED
verified, usertype = config.check_pin(
pin, salt, pin_use_type, auto_vibrate=True
)
except Exception:
raise wire.PinCancelled("cal cale ..")

Expand Down
10 changes: 1 addition & 9 deletions core/src/apps/ethereum/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ async def require_confirm_safe_tx(
int.from_bytes(msg.safeTxGas, "big"),
int.from_bytes(msg.baseGas, "big"),
format_ethereum_amount(int.from_bytes(msg.gasPrice, "big"), None, msg.chain_id),
msg.gasToken if not is_native_token(msg.gasToken) else "ETH",
msg.gasToken,
msg.refundReceiver,
int.from_bytes(msg.nonce, "big"),
msg.verifyingContract,
Expand All @@ -625,14 +625,6 @@ async def require_confirm_safe_tx(
)


def is_native_token(token_address: str) -> bool:
token_address = token_address.lower()
return token_address in (
"0x0000000000000000000000000000000000000000",
"0000000000000000000000000000000000000000",
)


def format_approve_title(
approve_token: tokens.EthereumTokenInfo,
value: int,
Expand Down
6 changes: 5 additions & 1 deletion core/src/apps/ethereum/onekey/sign_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ async def sign_tx(

from trezor.ui.layouts.lvgl import confirm_turbo

await confirm_turbo(ctx, (_(i18n_keys.LIST_VALUE__SEND) + suffix), network.name)
if value == 0:
title = _(i18n_keys.TITLE_REQUEST_CONFIRMATION)
else:
title = _(i18n_keys.LIST_VALUE__SEND) + suffix
await confirm_turbo(ctx, title, network.name)

elif approve_info:
from .providers import provider_by_chain_address
Expand Down
14 changes: 2 additions & 12 deletions core/src/apps/management/change_pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,7 @@ async def change_pin(ctx: wire.Context, msg: ChangePin) -> Success:
from apps.common.pin_constants import PinType, PinResult

if curpin and not msg.remove:
result = config.check_pin(curpin, salt, PinType.USER_CHECK)
if isinstance(result, tuple):
verified, usertype = result
else:
verified = result
usertype = PinType.USER_CHECK
verified = config.check_pin(curpin, salt, PinType.USER_CHECK)[0]
if not verified:
await error_pin_invalid(ctx)

Expand All @@ -55,12 +50,7 @@ async def change_pin(ctx: wire.Context, msg: ChangePin) -> Success:
newpin = ""

if newpin:
result = config.check_pin(newpin, salt, PinType.PASSPHRASE_PIN)
if isinstance(result, tuple):
verified, usertype = result
else:
verified = result
usertype = PinResult.PASSPHRASE_PIN_ENTERED
verified, usertype = config.check_pin(newpin, salt, PinType.PASSPHRASE_PIN)
if usertype == PinResult.PASSPHRASE_PIN_ENTERED:
return await error_pin_used(ctx)

Expand Down
2 changes: 1 addition & 1 deletion core/src/apps/management/change_wipe_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async def change_wipe_code(ctx: wire.Context, msg: ChangeWipeCode) -> Success:

if not msg.remove:
# Pre-check the entered PIN.
if config.has_pin() and not config.check_pin(pin, salt):
if config.has_pin() and not config.check_pin(pin, salt)[0]:
await error_pin_invalid(ctx)

# Get new wipe code.
Expand Down
20 changes: 8 additions & 12 deletions core/src/apps/management/recovery_device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import storage.recovery
from trezor import config, loop, utils, wire
from trezor.enums import ButtonRequestType
from trezor.lvglui.i18n import gettext, i18n_refresh, keys as i18n_keys
from trezor.lvglui.i18n import gettext as _, i18n_refresh, keys as i18n_keys
from trezor.lvglui.scrs import fingerprints
from trezor.messages import Success
from trezor.ui.layouts import confirm_action, confirm_reset_device
Expand Down Expand Up @@ -44,7 +44,7 @@ async def recovery_device(

if msg.language is not None:
i18n_refresh(msg.language)
await show_popup(gettext(i18n_keys.TITLE__PLEASE_WAIT), None, timeout_ms=1000)
await show_popup(_(i18n_keys.TITLE__PLEASE_WAIT), None, timeout_ms=1000)
# wipe storage to make sure the device is in a clear state
storage.reset()
if msg.language is not None:
Expand All @@ -62,17 +62,13 @@ async def recovery_device(
if msg.dry_run:
curpin, salt = await request_pin_and_sd_salt(
ctx,
gettext(i18n_keys.TITLE__ENTER_PIN),
_(i18n_keys.TITLE__ENTER_PIN),
allow_fingerprint=False,
standy_wall_only=True,
)
from apps.common.pin_constants import PinType

result = config.check_pin(curpin, salt, PinType.USER_CHECK)
if isinstance(result, tuple):
verified, _ = result
else:
verified = result
verified = config.check_pin(curpin, salt, PinType.USER_CHECK)[0]
if not verified:
await error_pin_invalid(ctx)
newpin = None
Expand Down Expand Up @@ -131,18 +127,18 @@ async def _continue_dialog(ctx: wire.Context, msg: RecoveryDevice) -> None:
if not msg.dry_run:
await confirm_reset_device(
ctx,
gettext(i18n_keys.SUBTITLE__DEVICE_RECOVER_RESTORE_WALLET),
_(i18n_keys.SUBTITLE__DEVICE_RECOVER_RESTORE_WALLET),
recovery=True,
)
else:
await confirm_action(
ctx,
"confirm_seedcheck",
title=gettext(i18n_keys.TITLE__CHECK_RECOVERY_PHRASE),
description=gettext(
title=_(i18n_keys.TITLE__CHECK_RECOVERY_PHRASE),
description=_(
i18n_keys.SUBTITLE__DEVICE_RECOVER_CHECK_CHECK_RECOVERY_PHRASE
),
verb=gettext(i18n_keys.BUTTON__CONTINUE),
verb=_(i18n_keys.BUTTON__CONTINUE),
icon="A:/res/check-seed.png",
br_code=ButtonRequestType.ProtectCall,
anim_dir=2,
Expand Down
31 changes: 17 additions & 14 deletions core/src/apps/management/recovery_device/homescreen.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ async def _process_words(
)
if __debug__:
print(f"share.threshold: {share.threshold}")
await _request_share_next_screen(ctx, share.threshold)
await _request_share_next_screen(ctx, share.threshold, share.group_index)

return secret, backup_type

Expand All @@ -346,7 +346,9 @@ async def _request_share_first_screen(
await layout.homescreen_dialog(ctx, btn_text, title, f"({word_count} words)")


async def _request_share_next_screen(ctx: wire.GenericContext, threshold: int) -> None:
async def _request_share_next_screen(
ctx: wire.GenericContext, threshold: int, group_index: int
) -> None:
remaining = storage_recovery.fetch_slip39_remaining_shares()
group_count = storage_recovery.get_slip39_group_count()
if not remaining:
Expand All @@ -365,18 +367,19 @@ async def _request_share_next_screen(ctx: wire.GenericContext, threshold: int) -
# text = strings.format_plural("{count} more {plural}", remaining[0], "share")
# await layout.homescreen_dialog(ctx, "Enter share", text, "needed to enter")
if __debug__:
print(f"threshold: {threshold}, remaining[0]: {remaining[0]}")
await layout.show_success(
ctx,
"Enter share",
header=_(i18n_keys.TITLE__STR_OF_STR_SHARES_ENTERED).format(
num=threshold, total=threshold - remaining[0]
),
content=_(i18n_keys.TITLE__STR_OF_STR_SHARES_ENTERED_DESC).format(
num=remaining[0]
),
button=_(i18n_keys.BUTTON__CONTINUE),
)
print(f"threshold: {threshold}, remaining: {remaining[group_index]}")
if remaining[group_index] > 0:
await layout.show_success(
ctx,
"Enter share",
header=_(i18n_keys.TITLE__STR_OF_STR_SHARES_ENTERED).format(
num=threshold, total=threshold - remaining[group_index]
),
content=_(i18n_keys.TITLE__STR_OF_STR_SHARES_ENTERED_DESC).format(
num=remaining[group_index]
),
button=_(i18n_keys.BUTTON__CONTINUE),
)


async def _show_remaining_groups_and_shares(ctx: wire.GenericContext) -> None:
Expand Down
6 changes: 1 addition & 5 deletions core/src/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def handle_stop_mode():


# run main event loop and specify which screen is the default
apps.base.set_homescreen()
apps.base.set_homescreen(show_app_guide=utils.show_app_guide())

loop.schedule(handle_fingerprint_data_init())
loop.schedule(handle_fingerprint())
Expand All @@ -70,10 +70,6 @@ async def handle_stop_mode():
loop.schedule(handle_stop_mode())

utils.set_up()
if utils.show_app_guide():
from trezor.ui.layouts import show_onekey_app_guide

loop.schedule(show_onekey_app_guide())

loop.run()

Expand Down
4 changes: 2 additions & 2 deletions core/src/storage/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ def get_storage() -> str:
global _STORAGE_SIZE_VALUE
if _STORAGE_SIZE_VALUE is None:
_STORAGE_SIZE_VALUE = config.get_capacity()
return _STORAGE_SIZE_VALUE
return _STORAGE_SIZE_VALUE or ""


def set_ble_name(name: str) -> None:
Expand Down Expand Up @@ -506,7 +506,7 @@ def get_serial() -> str:
global _SERIAL_NUMBER_VALUE
if _SERIAL_NUMBER_VALUE is None:
_SERIAL_NUMBER_VALUE = config.get_serial()
return _SERIAL_NUMBER_VALUE
return _SERIAL_NUMBER_VALUE or ""


def set_brightness(brightness: int) -> None:
Expand Down
1 change: 0 additions & 1 deletion core/src/trezor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import trezorconfig as config # noqa: F401
import trezorio as io # noqa: F401
28 changes: 28 additions & 0 deletions core/src/trezor/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import trezorconfig as config
from typing import Any


def unlock(
pin: str, salt: bytes | None = None, pin_type: int = 0, auto_vibrate: bool = True
) -> tuple[bool, int]:
result = config.unlock(pin, salt, pin_type)
if auto_vibrate and not result[0]:
from trezor import motor

motor.vibrate(motor.ERROR)
return result


def check_pin(
pin: str, salt: bytes | None = None, pin_type: int = 0, auto_vibrate: bool = False
) -> tuple[bool, int]:
result = config.check_pin(pin, salt, pin_type)
if auto_vibrate and not result[0]:
from trezor import motor

motor.vibrate(motor.ERROR)
return result


def __getattr__(name: str) -> Any:
return getattr(config, name)
Loading
Loading