core/stellar: add screen for timebounds

pull/742/head
Tomas Susanka 4 years ago
parent 3d50bb5ed8
commit 61430d800e

@ -25,6 +25,23 @@ async def require_confirm_init(
await require_confirm(ctx, text, ButtonRequestType.ConfirmOutput)
async def require_confirm_timebounds(ctx, start: int, end: int):
text = Text("Confirm timebounds", ui.ICON_SEND, ui.GREEN)
text.bold("Valid from (UTC):")
if start:
text.normal(str(start))
else:
text.mono("[no restriction]")
text.bold("Valid to (UTC):")
if end:
text.normal(str(end))
else:
text.mono("[no restriction]")
await require_confirm(ctx, text, ButtonRequestType.ConfirmOutput)
async def require_confirm_memo(ctx, memo_type: int, memo_text: str):
text = Text("Confirm memo", ui.ICON_CONFIRM, ui.GREEN)
if memo_type == consts.MEMO_TYPE_TEXT:

@ -25,7 +25,7 @@ async def sign_tx(ctx, msg: StellarSignTx, keychain):
w = bytearray()
await _init(ctx, w, pubkey, msg)
_timebounds(w, msg.timebounds_start, msg.timebounds_end)
await _timebounds(ctx, w, msg.timebounds_start, msg.timebounds_end)
await _memo(ctx, w, msg)
await _operations(ctx, w, msg.num_operations)
await _final(ctx, w, msg)
@ -63,13 +63,16 @@ async def _init(ctx, w: bytearray, pubkey: bytes, msg: StellarSignTx):
)
def _timebounds(w: bytearray, start: int, end: int):
def _timebounds(ctx, w: bytearray, start: int, end: int):
# timebounds are only present if timebounds_start or timebounds_end is non-zero
if start or end:
# confirm dialog
await layout.require_confirm_timebounds(ctx, start, end)
writers.write_bool(w, True)
# timebounds are sent as uint32s since that's all we can display, but they must be hashed as 64bit
writers.write_uint64(w, start)
writers.write_uint64(w, end)
writers.write_uint64(w, start or 0)
writers.write_uint64(w, end or 0)
else:
writers.write_bool(w, False)

@ -275,6 +275,37 @@ def test_sign_tx_set_options(client):
)
def test_sign_tx_timebounds(client):
op = messages.StellarSetOptionsOp()
tx = _create_msg()
tx.timebounds_start = 1577836800
tx.timebounds_end = 1577839000
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"KkZSQxXxEwfeGuFEHD7e93hei34rwK7VB79udYzileg6P/QEzK+lKyB9blUy+dPV3e7PvlHMj1FKXOsrgj/uCA=="
# 2a46524315f11307de1ae1441c3edef7785e8b7e2bc0aed507bf6e758ce295e83a3ff404ccafa52b207d6e5532f9d3d5ddeecfbe51cc8f514a5ceb2b823fee08
)
tx.timebounds_start = 100
tx.timebounds_end = None
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"ukpdaMwe6wdNnbVnOl0ZDvU1dde7Mtnjzy2IhjeZAjk8Ze+52WCv4M8IFjLoNF5c0aB847XYozFj8AsZ/k5fDQ=="
# ba4a5d68cc1eeb074d9db5673a5d190ef53575d7bb32d9e3cf2d8886379902393c65efb9d960afe0cf081632e8345e5cd1a07ce3b5d8a33163f00b19fe4e5f0d
)
tx.timebounds_start = None
tx.timebounds_end = 111111111
response = stellar.sign_tx(client, tx, [op], ADDRESS_N, NETWORK_PASSPHRASE)
assert (
b64encode(response.signature)
== b"9sFE/EC+zYlYC2t7R33HsI540nOmJi/aHruu2qG+RW4FEvhKLybLS5pRRhSb0IP3comcv1Q3e2Glvis6PgVICQ=="
# f6c144fc40becd89580b6b7b477dc7b08e78d273a6262fda1ebbaedaa1be456e0512f84a2f26cb4b9a5146149bd083f772899cbf54377b61a5be2b3a3e054809
)
def test_manage_data(client):
tx = _create_msg()

Loading…
Cancel
Save