mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-23 14:58:09 +00:00
wallet: add layout_sign_tx
It's now possible to sign transactions through myTREZOR.
This commit is contained in:
parent
2e4c63f836
commit
710cb09663
@ -1,7 +1,7 @@
|
|||||||
from trezor.wire import register_type, protobuf_handler
|
from trezor.wire import register_type, protobuf_handler
|
||||||
from trezor.utils import unimport
|
from trezor.utils import unimport
|
||||||
from trezor.messages.wire_types import \
|
from trezor.messages.wire_types import \
|
||||||
GetPublicKey, GetAddress, SignMessage
|
GetPublicKey, GetAddress, SignTx, SignMessage
|
||||||
|
|
||||||
|
|
||||||
@unimport
|
@unimport
|
||||||
@ -16,6 +16,12 @@ def dispatch_GetAddress(*args, **kwargs):
|
|||||||
return layout_get_address(*args, **kwargs)
|
return layout_get_address(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@unimport
|
||||||
|
def dispatch_SignTx(*args, **kwargs):
|
||||||
|
from .layout_sign_tx import layout_sign_tx
|
||||||
|
return layout_sign_tx(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
@unimport
|
@unimport
|
||||||
def dispatch_SignMessage(*args, **kwargs):
|
def dispatch_SignMessage(*args, **kwargs):
|
||||||
from .layout_sign_message import layout_sign_message
|
from .layout_sign_message import layout_sign_message
|
||||||
@ -25,4 +31,5 @@ def dispatch_SignMessage(*args, **kwargs):
|
|||||||
def boot():
|
def boot():
|
||||||
register_type(GetPublicKey, protobuf_handler, dispatch_GetPublicKey)
|
register_type(GetPublicKey, protobuf_handler, dispatch_GetPublicKey)
|
||||||
register_type(GetAddress, protobuf_handler, dispatch_GetAddress)
|
register_type(GetAddress, protobuf_handler, dispatch_GetAddress)
|
||||||
|
register_type(SignTx, protobuf_handler, dispatch_SignTx)
|
||||||
register_type(SignMessage, protobuf_handler, dispatch_SignMessage)
|
register_type(SignMessage, protobuf_handler, dispatch_SignMessage)
|
||||||
|
41
src/apps/wallet/layout_sign_tx.py
Normal file
41
src/apps/wallet/layout_sign_tx.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
from trezor.utils import unimport
|
||||||
|
from trezor import wire
|
||||||
|
|
||||||
|
|
||||||
|
async def confirm_output(output):
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
async def confirm_total(total_out, fee):
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
@unimport
|
||||||
|
async def layout_sign_tx(message, 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.wire_types import TxAck
|
||||||
|
|
||||||
|
root = await get_root_node(session_id)
|
||||||
|
|
||||||
|
signer = signtx.sign_tx(message, root)
|
||||||
|
res = None
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
req = signer.send(res)
|
||||||
|
except signtx.SigningError as e:
|
||||||
|
raise wire.FailureError(*e.args)
|
||||||
|
if isinstance(req, TxRequest):
|
||||||
|
if req.request_type == RequestType.TXFINISHED:
|
||||||
|
break
|
||||||
|
res = await wire.reply_message(session_id, req, TxAck)
|
||||||
|
elif isinstance(req, signtx.UiConfirmOutput):
|
||||||
|
res = await confirm_output(req.output)
|
||||||
|
elif isinstance(req, signtx.UiConfirmTotal):
|
||||||
|
res = await confirm_total(req.total_out, req.fee)
|
||||||
|
else:
|
||||||
|
raise ValueError('Invalid signing instruction')
|
||||||
|
return req
|
Loading…
Reference in New Issue
Block a user