Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
xmr: iface modified to layout
Browse files Browse the repository at this point in the history
  • Loading branch information
tsusanka authored and ph4r05 committed Sep 21, 2018
1 parent 27d568e commit 14b0a85
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 293 deletions.
179 changes: 0 additions & 179 deletions src/apps/monero/controller/iface.py

This file was deleted.

23 changes: 23 additions & 0 deletions src/apps/monero/controller/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@ def compute_tx_key(spend_key_private, tx_prefix_hash, salt=None, rand_mult=None)
return tx_key, salt, rand_mult


async def monero_get_creds(ctx, address_n=None, network_type=None):
from apps.common import seed
from apps.monero.xmr import crypto
from apps.monero.xmr import monero
from apps.monero.xmr.sub.creds import AccountCreds

# If path contains 0 it is not SLIP-0010
address_n = address_n or ()
use_slip0010 = 0 not in address_n
curve = "ed25519" if use_slip0010 else "secp256k1"

node = await seed.derive_node(ctx, address_n, curve)
pre_key = node.private_key()

key_seed = pre_key if use_slip0010 else crypto.cn_fast_hash(node.private_key())
keys = monero.generate_monero_keys(
key_seed
) # spend_sec, spend_pub, view_sec, view_pub

creds = AccountCreds.new_wallet(keys[2], keys[0], network_type)
return creds


def parse_msg(bts, msg):
from apps.monero.xmr.serialize import xmrserialize
from apps.monero.xmr.serialize.readwriter import MemoryReaderWriter
Expand Down
27 changes: 0 additions & 27 deletions src/apps/monero/controller/wrapper.py

This file was deleted.

4 changes: 2 additions & 2 deletions src/apps/monero/get_address.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from trezor.messages.MoneroAddress import MoneroAddress

from apps.common.layout import show_address, show_qr
from apps.monero.controller import wrapper
from apps.monero.controller import misc


async def get_address(ctx, msg):
address_n = msg.address_n or ()
creds = await wrapper.monero_get_creds(ctx, address_n, msg.network_type)
creds = await misc.monero_get_creds(ctx, address_n, msg.network_type)

if msg.show_display:
while True:
Expand Down
8 changes: 4 additions & 4 deletions src/apps/monero/get_watch_only.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from trezor.messages.MoneroGetWatchKey import MoneroGetWatchKey
from trezor.messages.MoneroWatchKey import MoneroWatchKey

from apps.monero import layout
from apps.monero.controller import wrapper
from apps.monero.controller import misc
from apps.monero.layout import confirms
from apps.monero.xmr import crypto


async def get_watch_only(ctx, msg: MoneroGetWatchKey):
address_n = msg.address_n or ()
await layout.require_confirm_watchkey(ctx)
creds = await wrapper.monero_get_creds(ctx, address_n, msg.network_type)
await confirms.require_confirm_watchkey(ctx)
creds = await misc.monero_get_creds(ctx, address_n, msg.network_type)
return MoneroWatchKey(
watch_key=crypto.encodeint(creds.view_key_private), address=creds.address
)
4 changes: 1 addition & 3 deletions src/apps/monero/key_image_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ async def key_image_sync_step(ctx, msg, state):
gc.collect()

if msg.MESSAGE_WIRE_TYPE == MessageType.MoneroKeyImageExportInitRequest:
from apps.monero.controller import iface

state = key_image_sync.KeyImageSync(ctx=ctx, iface=iface.get_iface(ctx))
state = key_image_sync.KeyImageSync(ctx=ctx)
return (
await state.init(ctx, msg),
state,
Expand Down
44 changes: 0 additions & 44 deletions src/apps/monero/layout.py → src/apps/monero/layout/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from trezor.ui.text import Text
from trezor.utils import chunks

from apps.common.confirm import require_confirm, require_hold_to_confirm


def paginate_lines(lines, lines_per_page=5):
pages = []
Expand Down Expand Up @@ -116,48 +114,6 @@ async def naive_pagination(
cur_step += 1


async def require_confirm_watchkey(ctx):
content = Text("Confirm export", ui.ICON_SEND, icon_color=ui.GREEN)
content.normal(*["Do you really want to", "export watch-only", "credentials?"])
return await require_confirm(ctx, content, ButtonRequestType.SignTx)


async def require_confirm_keyimage_sync(ctx):
content = Text("Confirm ki sync", ui.ICON_SEND, icon_color=ui.GREEN)
content.normal(*["Do you really want to", "sync key images?"])
return await require_confirm(ctx, content, ButtonRequestType.SignTx)


async def require_confirm_payment_id(ctx, payment_id):
from ubinascii import hexlify
from trezor import wire

if not await naive_pagination(
ctx,
[ui.MONO] + list(chunks(hexlify((payment_id)), 16)),
"Payment ID",
ui.ICON_SEND,
ui.GREEN,
):
raise wire.ActionCancelled("Cancelled")


async def require_confirm_tx(ctx, to, value, is_change=False):
from trezor import wire

to_chunks = list(split_address(to))
text = [ui.BOLD, format_amount(value), ui.MONO] + to_chunks
conf_text = "Confirm send" if not is_change else "Con. change"
if not await naive_pagination(ctx, text, conf_text, ui.ICON_SEND, ui.GREEN, 4):
raise wire.ActionCancelled("Cancelled")


async def require_confirm_fee(ctx, fee):
content = Text("Confirm fee", ui.ICON_SEND, icon_color=ui.GREEN)
content.bold(format_amount(fee))
await require_hold_to_confirm(ctx, content, ButtonRequestType.ConfirmOutput)


@ui.layout
async def ui_text(text, tm=None) -> None:
from trezor import loop
Expand Down
Loading

0 comments on commit 14b0a85

Please sign in to comment.