Skip to content

Commit

Permalink
xmr: reorganize module structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jpochyla committed Oct 22, 2018
1 parent cd9e5a5 commit abd27e6
Show file tree
Hide file tree
Showing 37 changed files with 289 additions and 314 deletions.
Empty file.
133 changes: 0 additions & 133 deletions src/apps/monero/controller/misc.py

This file was deleted.

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

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


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

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

from apps.monero.controller import misc
from apps.monero 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 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
)

creds = await misc.get_creds(ctx, msg.address_n, msg.network_type)
address = creds.address
watch_key = crypto.encodeint(creds.view_key_private)

return MoneroWatchKey(watch_key=watch_key, address=address)
6 changes: 3 additions & 3 deletions src/apps/monero/key_image_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
from trezor.messages.MoneroKeyImageSyncFinalAck import MoneroKeyImageSyncFinalAck
from trezor.messages.MoneroKeyImageSyncStepAck import MoneroKeyImageSyncStepAck

from apps.monero.controller import misc
from apps.monero import misc
from apps.monero.layout import confirms
from apps.monero.xmr import crypto, key_image, monero
from apps.monero.xmr.enc import chacha_poly
from apps.monero.xmr.crypto import chacha_poly


async def key_image_sync(ctx, msg):
Expand Down Expand Up @@ -46,7 +46,7 @@ def __init__(self):


async def _init_step(s, ctx, msg):
s.creds = await misc.monero_get_creds(ctx, msg.address_n, msg.network_type)
s.creds = await misc.get_creds(ctx, msg.address_n, msg.network_type)

await confirms.require_confirm_keyimage_sync(ctx)

Expand Down
6 changes: 3 additions & 3 deletions src/apps/monero/layout/confirms.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async def require_confirm_transaction(ctx, tsx_data, network_type):
"""
Ask for confirmation from user.
"""
from apps.monero.xmr.sub.addr import get_change_addr_idx
from apps.monero.xmr.addresses import get_change_addr_idx

outputs = tsx_data.outputs
change_idx = get_change_addr_idx(outputs, tsx_data.change_dts)
Expand Down Expand Up @@ -59,8 +59,8 @@ async def _require_confirm_output(ctx, dst, network_type, payment_id):
"""
Single transaction destination confirmation
"""
from apps.monero.xmr.sub.addr import encode_addr
from apps.monero.xmr.sub.xmr_net import net_version
from apps.monero.xmr.addresses import encode_addr
from apps.monero.xmr.networks import net_version

version = net_version(network_type, dst.is_subaddress, payment_id is not None)
addr = encode_addr(
Expand Down
21 changes: 21 additions & 0 deletions src/apps/monero/misc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
async def get_creds(ctx, address_n=None, network_type=None):
from apps.common import seed
from apps.monero.xmr import crypto, monero
from apps.monero.xmr.credentials import AccountCreds

use_slip0010 = 0 not in address_n # If path contains 0 it is not SLIP-0010

if use_slip0010:
curve = "ed25519"
else:
curve = "secp256k1"
node = await seed.derive_node(ctx, address_n, curve)

if use_slip0010:
key_seed = node.private_key()
else:
key_seed = crypto.cn_fast_hash(node.private_key())
spend_sec, _, view_sec, _ = monero.generate_monero_keys(key_seed)

creds = AccountCreds.new_wallet(view_sec, spend_sec, network_type)
return creds
Empty file.
13 changes: 0 additions & 13 deletions src/apps/monero/protocol/signing/rct_type.py

This file was deleted.

17 changes: 0 additions & 17 deletions src/apps/monero/protocol/signing/rsig_type.py

This file was deleted.

24 changes: 11 additions & 13 deletions src/apps/monero/sign_tx.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import gc

from trezor import log, utils
from trezor import log, utils, wire
from trezor.messages import MessageType

from apps.monero.protocol.signing.state import State
from apps.monero.signing.state import State


async def sign_tx(ctx, received_msg):
Expand Down Expand Up @@ -34,7 +34,7 @@ async def sign_tx(ctx, received_msg):

async def sign_tx_dispatch(state, msg):
if msg.MESSAGE_WIRE_TYPE == MessageType.MoneroTransactionInitRequest:
from apps.monero.protocol.signing import step_01_init_transaction
from apps.monero.signing import step_01_init_transaction

return (
await step_01_init_transaction.init_transaction(
Expand All @@ -44,7 +44,7 @@ async def sign_tx_dispatch(state, msg):
)

elif msg.MESSAGE_WIRE_TYPE == MessageType.MoneroTransactionSetInputRequest:
from apps.monero.protocol.signing import step_02_set_input
from apps.monero.signing import step_02_set_input

return (
await step_02_set_input.set_input(state, msg.src_entr),
Expand All @@ -55,15 +55,15 @@ async def sign_tx_dispatch(state, msg):
)

elif msg.MESSAGE_WIRE_TYPE == MessageType.MoneroTransactionInputsPermutationRequest:
from apps.monero.protocol.signing import step_03_inputs_permutation
from apps.monero.signing import step_03_inputs_permutation

return (
await step_03_inputs_permutation.tsx_inputs_permutation(state, msg.perm),
(MessageType.MoneroTransactionInputViniRequest,),
)

elif msg.MESSAGE_WIRE_TYPE == MessageType.MoneroTransactionInputViniRequest:
from apps.monero.protocol.signing import step_04_input_vini
from apps.monero.signing import step_04_input_vini

return (
await step_04_input_vini.input_vini(
Expand All @@ -81,15 +81,15 @@ async def sign_tx_dispatch(state, msg):
)

elif msg.MESSAGE_WIRE_TYPE == MessageType.MoneroTransactionAllInputsSetRequest:
from apps.monero.protocol.signing import step_05_all_inputs_set
from apps.monero.signing import step_05_all_inputs_set

return (
await step_05_all_inputs_set.all_inputs_set(state),
(MessageType.MoneroTransactionSetOutputRequest,),
)

elif msg.MESSAGE_WIRE_TYPE == MessageType.MoneroTransactionSetOutputRequest:
from apps.monero.protocol.signing import step_06_set_output
from apps.monero.signing import step_06_set_output

dst, dst_hmac, rsig_data = msg.dst_entr, msg.dst_entr_hmac, msg.rsig_data
del msg
Expand All @@ -103,15 +103,15 @@ async def sign_tx_dispatch(state, msg):
)

elif msg.MESSAGE_WIRE_TYPE == MessageType.MoneroTransactionAllOutSetRequest:
from apps.monero.protocol.signing import step_07_all_outputs_set
from apps.monero.signing import step_07_all_outputs_set

return (
await step_07_all_outputs_set.all_outputs_set(state),
(MessageType.MoneroTransactionSignInputRequest,),
)

elif msg.MESSAGE_WIRE_TYPE == MessageType.MoneroTransactionSignInputRequest:
from apps.monero.protocol.signing import step_09_sign_input
from apps.monero.signing import step_09_sign_input

return (
await step_09_sign_input.sign_input(
Expand All @@ -131,11 +131,9 @@ async def sign_tx_dispatch(state, msg):
)

elif msg.MESSAGE_WIRE_TYPE == MessageType.MoneroTransactionFinalRequest:
from apps.monero.protocol.signing import step_10_sign_final
from apps.monero.signing import step_10_sign_final

return await step_10_sign_final.final_msg(state), None

else:
from trezor import wire

raise wire.DataError("Unknown message")
Loading

0 comments on commit abd27e6

Please sign in to comment.