1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

apps: adjust to last commit

This commit is contained in:
Jan Pochyla 2016-11-23 14:51:05 +01:00
parent 065cbdbc3b
commit b400448b97
9 changed files with 65 additions and 76 deletions

View File

@ -101,11 +101,11 @@ def request_tx_finish(tx_req: TxRequest):
async def sign_tx(tx: SignTx, root):
tx_version = getattr(tx, 'version', 1)
tx_lock_time = getattr(tx, 'lock_time', 0)
tx_inputs_count = getattr(tx, 'inputs_count', 0)
tx_outputs_count = getattr(tx, 'outputs_count', 0)
coin_name = getattr(tx, 'coin_name', 'Bitcoin')
tx_version = tx.version if tx.version is not None else 1
tx_lock_time = tx.lock_time or 0
tx_inputs_count = tx.inputs_count or 0
tx_outputs_count = tx.outputs_count or 0
coin_name = tx.coin_name or 'Bitcoin'
coin = coins.by_name(coin_name)
@ -265,10 +265,10 @@ async def get_prevtx_output_value(tx_req: TxRequest, prev_hash: bytes, prev_inde
# STAGE_REQUEST_2_PREV_META
tx = await request_tx_meta(tx_req, prev_hash)
tx_version = getattr(tx, 'version', 0)
tx_lock_time = getattr(tx, 'lock_time', 1)
tx_inputs_count = getattr(tx, 'inputs_cnt', 0)
tx_outputs_count = getattr(tx, 'outputs_cnt', 0)
tx_version = tx.version if tx.version is not None else 1
tx_lock_time = tx.lock_time or 0
tx_inputs_count = tx.inputs_cnt or 0
tx_outputs_count = tx.outputs_cnt or 0
txh = HashWriter(sha256)
@ -339,17 +339,16 @@ def output_derive_script(o: TxOutputType, coin: CoinType, root) -> bytes:
'Invalid output script type')
def output_paytoaddress_extract_raw_address(o: TxOutputType, coin: CoinType, root, p2sh=False) -> bytes:
def output_paytoaddress_extract_raw_address(
o: TxOutputType, coin: CoinType, root, p2sh: bool=False) -> bytes:
addr_type = coin.address_type_p2sh if p2sh else coin.address_type
# TODO: dont encode/decode more then necessary
address_n = getattr(o, 'address_n', None)
if address_n is not None:
node = node_derive(root, address_n)
if o.address_n is not None:
node = node_derive(root, o.address_n)
address = node.address(addr_type)
return base58.decode_check(address)
address = getattr(o, 'address', None)
if address:
raw = base58.decode_check(address)
if o.address:
raw = base58.decode_check(o.address)
if not address_type.check(addr_type, raw):
raise SigningError(FailureType.SyntaxError,
'Invalid address type')
@ -358,9 +357,8 @@ def output_paytoaddress_extract_raw_address(o: TxOutputType, coin: CoinType, roo
'Missing address')
def output_is_change(o: TxOutputType):
address_n = getattr(o, 'address_n', None)
return bool(address_n)
def output_is_change(o: TxOutputType) -> bool:
return bool(o.address_n)
# Tx Inputs
@ -368,9 +366,9 @@ def output_is_change(o: TxOutputType):
def input_derive_script(i: TxInputType, pubkey: bytes, signature: bytes=None) -> bytes:
i_script_type = getattr(i, 'script_type', InputScriptType.SPENDADDRESS)
script_type = i.script_type if i.script_type is not None else InputScriptType.SPENDADDRESS
if i_script_type == InputScriptType.SPENDADDRESS:
if script_type == InputScriptType.SPENDADDRESS:
if signature is None:
return script_paytoaddress_new(ecdsa_hash_pubkey(pubkey))
else:
@ -452,7 +450,7 @@ def script_spendaddress_new(pubkey: bytes, signature: bytes) -> bytearray:
def write_tx_input(w, i: TxInputType):
i_sequence = getattr(i, 'sequence', 4294967295)
i_sequence = i.sequence if i.sequence is not None else 4294967295
write_bytes_rev(w, i.prev_hash)
write_uint32(w, i.prev_index)
write_varint(w, len(i.script_sig))
@ -461,7 +459,7 @@ def write_tx_input(w, i: TxInputType):
def write_tx_input_check(w, i: TxInputType):
i_sequence = getattr(i, 'sequence', 4294967295)
i_sequence = i.sequence if i.sequence is not None else 4294967295
write_bytes(w, i.prev_hash)
write_uint32(w, i.prev_index)
write_uint32(w, len(i.address_n))

View File

@ -3,7 +3,7 @@ from trezor.utils import unimport
@unimport
async def layout_load_device(message, session_id):
async def layout_load_device(msg, session_id):
from trezor.crypto import bip39
from trezor.messages.Success import Success
from trezor.messages.FailureType import UnexpectedMessage, Other
@ -14,17 +14,10 @@ async def layout_load_device(message, session_id):
if storage.is_initialized():
raise wire.FailureError(UnexpectedMessage, 'Already initialized')
if hasattr(message, 'node'):
if msg.node is not None:
raise wire.FailureError(Other, 'LoadDevice.node is not supported')
skip_checksum = getattr(message, 'skip_checksum', False)
mnemonic = getattr(message, 'mnemonic')
pin = getattr(message, 'pin', None)
label = getattr(message, 'label', None)
language = getattr(message, 'language', None)
passphrase_protection = getattr(message, 'passphrase_protection', False)
if not skip_checksum and not bip39.check(mnemonic):
if not msg.skip_checksum and not bip39.check(msg.mnemonic):
raise wire.FailureError(Other, 'Mnemonic is not valid')
await require_confirm(session_id, Text(
@ -32,10 +25,10 @@ async def layout_load_device(message, session_id):
ui.BOLD, 'Loading private seed', 'is not recommended.',
ui.NORMAL, 'Continue only if you', 'know what you are doing!'))
storage.load_mnemonic(mnemonic)
storage.load_settings(pin=pin,
passphrase_protection=passphrase_protection,
language=language,
label=label)
storage.load_mnemonic(msg.mnemonic)
storage.load_settings(pin=msg.pin,
passphrase_protection=msg.passphrase_protection,
language=msg.language,
label=msg.label)
return Success(message='Device loaded')

View File

@ -4,7 +4,7 @@ from trezor.utils import unimport, chunks
@unimport
async def layout_reset_device(message, session_id):
async def layout_reset_device(msg, session_id):
from trezor.messages.Success import Success
from trezor.messages.FailureType import UnexpectedMessage
from ..common.request_pin import request_pin_twice
@ -14,20 +14,20 @@ async def layout_reset_device(message, session_id):
raise wire.FailureError(UnexpectedMessage, 'Already initialized')
mnemonic = await generate_mnemonic(
message.strength, message.display_random, session_id)
msg.strength, msg.display_random, session_id)
await show_mnemonic(mnemonic)
if message.pin_protection:
if msg.pin_protection:
pin = await request_pin_twice(session_id)
else:
pin = None
storage.load_mnemonic(mnemonic)
storage.load_settings(pin=pin,
passphrase_protection=message.passphrase_protection,
language=message.language,
label=message.label)
passphrase_protection=msg.passphrase_protection,
language=msg.language,
label=msg.label)
return Success(message='Initialized')

View File

@ -9,23 +9,18 @@ async def layout_get_address(msg, session_id):
from ..common.seed import get_node
from ..common import coins
address_n = getattr(msg, 'address_n', ())
coin_name = getattr(msg, 'coin_name', 'Bitcoin')
multisig = getattr(msg, 'multisig', None)
show_display = getattr(msg, 'show_display', False)
# TODO: support multisig addresses
if multisig:
if msg.multisig:
raise wire.FailureError(Other, 'GetAddress.multisig is unsupported')
address_n = msg.address_n or ()
coin_name = msg.coin_name or 'Bitcoin'
node = await get_node(session_id, address_n)
coin = coins.by_name(coin_name)
address = node.address(coin.address_type)
if show_display:
if msg.show_display:
await _show_address(session_id, address)
return Address(address=address)

View File

@ -7,8 +7,7 @@ async def layout_get_public_key(msg, session_id):
from trezor.messages.HDNodeType import HDNodeType
from trezor.messages.PublicKey import PublicKey
address_n = getattr(msg, 'address_n', ())
address_n = msg.address_n or ()
node = await seed.get_node(session_id, address_n)
node_xpub = node.serialize_public()

View File

@ -1,4 +1,4 @@
from trezor import wire, ui
from trezor import ui
from trezor.utils import unimport
@unimport
@ -12,18 +12,18 @@ async def layout_sign_identity(msg, session_id):
from ..common.signverify import message_digest
identity = ''
if hasattr(msg.identity, 'proto') and msg.identity.proto:
if msg.identity.proto:
identity += msg.identity.proto + '://'
if hasattr(msg.identity, 'user') and msg.identity.user:
if msg.identity.user:
identity += msg.identity.user + '@'
if hasattr(msg.identity, 'host') and msg.identity.host:
if msg.identity.host:
identity += msg.identity.host
if hasattr(msg.identity, 'port') and msg.identity.port:
if msg.identity.port:
identity += ':' + msg.identity.port
if hasattr(msg.identity, 'path') and msg.identity.path:
if msg.identity.path:
identity += msg.identity.path
index = getattr(msg.identity, 'index', 0)
index = msg.identity.index or 0
identity_hash = sha256(pack('<I', index) + identity).digest()
address_n = (13, ) + unpack('<IIII', identity_hash[:16])

View File

@ -1,4 +1,4 @@
from trezor import wire, ui
from trezor import ui
from trezor.utils import unimport
@ -15,7 +15,7 @@ async def layout_sign_message(msg, session_id):
ui.BOLD, ui.LIGHT_GREEN, ui.BLACK)
ui.display.text(10, 60, msg.message, ui.MONO, ui.WHITE, ui.BLACK)
coin_name = getattr(msg, 'coin_name', 'Bitcoin')
coin_name = msg.coin_name or 'Bitcoin'
coin = coins.by_name(coin_name)
node = await get_node(session_id, msg.address_n)

View File

@ -6,6 +6,11 @@ def format_amount(amount, coin):
return '%s %s' % (amount / 1e8, coin.coin_shortcut)
def split_address(address):
from trezor.utils import chunks
return chunks(address, 17)
async def confirm_output(session_id, output, coin):
from trezor import ui
from trezor.ui.text import Text
@ -15,8 +20,7 @@ async def confirm_output(session_id, output, coin):
content = Text('Confirm output', ui.ICON_RESET,
ui.BOLD, format_amount(output.amount, coin),
ui.NORMAL, 'to',
ui.MONO, output.address[0:17],
ui.MONO, output.address[17:])
ui.MONO, *split_address(output.address))
return await confirm(session_id, content, ConfirmOutput)
@ -44,17 +48,16 @@ async def confirm_feeoverthreshold(session_id, fee, coin):
@unimport
async def layout_sign_tx(message, session_id):
async def layout_sign_tx(msg, session_id):
from ..common.seed import get_root_node
from ..common import signtx
from trezor.messages import RequestType
from trezor.messages.TxRequest import TxRequest
from trezor.messages.RequestType import TXFINISHED
from trezor.messages.wire_types import TxAck
root = await get_root_node(session_id)
signer = signtx.sign_tx(message, root)
signer = signtx.sign_tx(msg, root)
res = None
while True:
try:
@ -62,7 +65,7 @@ async def layout_sign_tx(message, session_id):
except signtx.SigningError as e:
raise wire.FailureError(*e.args)
if req.__qualname__ == 'TxRequest':
if req.request_type == RequestType.TXFINISHED:
if req.request_type == TXFINISHED:
break
res = await wire.reply_message(session_id, req, TxAck)
elif req.__qualname__ == 'UiConfirmOutput':
@ -72,5 +75,5 @@ async def layout_sign_tx(message, session_id):
elif req.__qualname__ == 'UiConfirmFeeOverThreshold':
res = await confirm_feeoverthreshold(session_id, req.fee, req.coin)
else:
raise ValueError('Invalid signing instruction')
raise TypeError('Invalid signing instruction')
return req

View File

@ -1,6 +1,7 @@
from trezor import wire, ui
from trezor import ui
from trezor.utils import unimport
@unimport
async def layout_verify_message(msg, session_id):
from trezor.messages.Success import Success
@ -11,7 +12,7 @@ async def layout_verify_message(msg, session_id):
from ..common import coins
from ..common.signverify import message_digest
coin_name = getattr(msg, 'coin_name', 'Bitcoin')
coin_name = msg.coin_name or 'Bitcoin'
coin = coins.by_name(coin_name)
digest = message_digest(coin, msg.message)