mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-18 04:18:10 +00:00
chore(core): decrease eos size by 1kb
This commit is contained in:
parent
47b924cbec
commit
80ab7f1c29
@ -1,119 +1,125 @@
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from trezor.crypto.hashlib import sha256
|
|
||||||
from trezor.messages import EosTxActionAck, EosTxActionRequest
|
|
||||||
from trezor.utils import HashWriter
|
|
||||||
|
|
||||||
from .. import helpers, writers
|
|
||||||
from . import layout
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from trezor import wire
|
from trezor import wire
|
||||||
from trezor.utils import Writer
|
from trezor.utils import Writer, HashWriter
|
||||||
|
from trezor.messages import EosTxActionAck
|
||||||
|
|
||||||
|
|
||||||
async def process_action(
|
async def process_action(
|
||||||
ctx: wire.Context, sha: HashWriter, action: EosTxActionAck
|
ctx: wire.Context, sha: HashWriter, action: EosTxActionAck
|
||||||
) -> None:
|
) -> None:
|
||||||
|
from .. import helpers, writers
|
||||||
|
from . import layout
|
||||||
|
|
||||||
name = helpers.eos_name_to_string(action.common.name)
|
name = helpers.eos_name_to_string(action.common.name)
|
||||||
account = helpers.eos_name_to_string(action.common.account)
|
account = helpers.eos_name_to_string(action.common.account)
|
||||||
|
|
||||||
if not check_action(action, name, account):
|
if not _check_action(action, name, account):
|
||||||
raise ValueError("Invalid action")
|
raise ValueError("Invalid action")
|
||||||
|
|
||||||
w = bytearray()
|
w = bytearray()
|
||||||
if account == "eosio":
|
if account == "eosio":
|
||||||
if name == "buyram":
|
if name == "buyram":
|
||||||
assert action.buy_ram is not None # check_action
|
assert action.buy_ram is not None # _check_action
|
||||||
await layout.confirm_action_buyram(ctx, action.buy_ram)
|
await layout.confirm_action_buyram(ctx, action.buy_ram)
|
||||||
writers.write_action_buyram(w, action.buy_ram)
|
writers.write_action_buyram(w, action.buy_ram)
|
||||||
elif name == "buyrambytes":
|
elif name == "buyrambytes":
|
||||||
assert action.buy_ram_bytes is not None # check_action
|
assert action.buy_ram_bytes is not None # _check_action
|
||||||
await layout.confirm_action_buyrambytes(ctx, action.buy_ram_bytes)
|
await layout.confirm_action_buyrambytes(ctx, action.buy_ram_bytes)
|
||||||
writers.write_action_buyrambytes(w, action.buy_ram_bytes)
|
writers.write_action_buyrambytes(w, action.buy_ram_bytes)
|
||||||
elif name == "sellram":
|
elif name == "sellram":
|
||||||
assert action.sell_ram is not None # check_action
|
assert action.sell_ram is not None # _check_action
|
||||||
await layout.confirm_action_sellram(ctx, action.sell_ram)
|
await layout.confirm_action_sellram(ctx, action.sell_ram)
|
||||||
writers.write_action_sellram(w, action.sell_ram)
|
writers.write_action_sellram(w, action.sell_ram)
|
||||||
elif name == "delegatebw":
|
elif name == "delegatebw":
|
||||||
assert action.delegate is not None # check_action
|
assert action.delegate is not None # _check_action
|
||||||
await layout.confirm_action_delegate(ctx, action.delegate)
|
await layout.confirm_action_delegate(ctx, action.delegate)
|
||||||
writers.write_action_delegate(w, action.delegate)
|
writers.write_action_delegate(w, action.delegate)
|
||||||
elif name == "undelegatebw":
|
elif name == "undelegatebw":
|
||||||
assert action.undelegate is not None # check_action
|
assert action.undelegate is not None # _check_action
|
||||||
await layout.confirm_action_undelegate(ctx, action.undelegate)
|
await layout.confirm_action_undelegate(ctx, action.undelegate)
|
||||||
writers.write_action_undelegate(w, action.undelegate)
|
writers.write_action_undelegate(w, action.undelegate)
|
||||||
elif name == "refund":
|
elif name == "refund":
|
||||||
assert action.refund is not None # check_action
|
assert action.refund is not None # _check_action
|
||||||
await layout.confirm_action_refund(ctx, action.refund)
|
await layout.confirm_action_refund(ctx, action.refund)
|
||||||
writers.write_action_refund(w, action.refund)
|
writers.write_action_refund(w, action.refund)
|
||||||
elif name == "voteproducer":
|
elif name == "voteproducer":
|
||||||
assert action.vote_producer is not None # check_action
|
assert action.vote_producer is not None # _check_action
|
||||||
await layout.confirm_action_voteproducer(ctx, action.vote_producer)
|
await layout.confirm_action_voteproducer(ctx, action.vote_producer)
|
||||||
writers.write_action_voteproducer(w, action.vote_producer)
|
writers.write_action_voteproducer(w, action.vote_producer)
|
||||||
elif name == "updateauth":
|
elif name == "updateauth":
|
||||||
assert action.update_auth is not None # check_action
|
assert action.update_auth is not None # _check_action
|
||||||
await layout.confirm_action_updateauth(ctx, action.update_auth)
|
await layout.confirm_action_updateauth(ctx, action.update_auth)
|
||||||
writers.write_action_updateauth(w, action.update_auth)
|
writers.write_action_updateauth(w, action.update_auth)
|
||||||
elif name == "deleteauth":
|
elif name == "deleteauth":
|
||||||
assert action.delete_auth is not None # check_action
|
assert action.delete_auth is not None # _check_action
|
||||||
await layout.confirm_action_deleteauth(ctx, action.delete_auth)
|
await layout.confirm_action_deleteauth(ctx, action.delete_auth)
|
||||||
writers.write_action_deleteauth(w, action.delete_auth)
|
writers.write_action_deleteauth(w, action.delete_auth)
|
||||||
elif name == "linkauth":
|
elif name == "linkauth":
|
||||||
assert action.link_auth is not None # check_action
|
assert action.link_auth is not None # _check_action
|
||||||
await layout.confirm_action_linkauth(ctx, action.link_auth)
|
await layout.confirm_action_linkauth(ctx, action.link_auth)
|
||||||
writers.write_action_linkauth(w, action.link_auth)
|
writers.write_action_linkauth(w, action.link_auth)
|
||||||
elif name == "unlinkauth":
|
elif name == "unlinkauth":
|
||||||
assert action.unlink_auth is not None # check_action
|
assert action.unlink_auth is not None # _check_action
|
||||||
await layout.confirm_action_unlinkauth(ctx, action.unlink_auth)
|
await layout.confirm_action_unlinkauth(ctx, action.unlink_auth)
|
||||||
writers.write_action_unlinkauth(w, action.unlink_auth)
|
writers.write_action_unlinkauth(w, action.unlink_auth)
|
||||||
elif name == "newaccount":
|
elif name == "newaccount":
|
||||||
assert action.new_account is not None # check_action
|
assert action.new_account is not None # _check_action
|
||||||
await layout.confirm_action_newaccount(ctx, action.new_account)
|
await layout.confirm_action_newaccount(ctx, action.new_account)
|
||||||
writers.write_action_newaccount(w, action.new_account)
|
writers.write_action_newaccount(w, action.new_account)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Unrecognized action type for eosio")
|
raise ValueError("Unrecognized action type for eosio")
|
||||||
elif name == "transfer":
|
elif name == "transfer":
|
||||||
assert action.transfer is not None # check_action
|
assert action.transfer is not None # _check_action
|
||||||
await layout.confirm_action_transfer(ctx, action.transfer, account)
|
await layout.confirm_action_transfer(ctx, action.transfer, account)
|
||||||
writers.write_action_transfer(w, action.transfer)
|
writers.write_action_transfer(w, action.transfer)
|
||||||
else:
|
else:
|
||||||
await process_unknown_action(ctx, w, action)
|
await _process_unknown_action(ctx, w, action)
|
||||||
|
|
||||||
writers.write_action_common(sha, action.common)
|
writers.write_action_common(sha, action.common)
|
||||||
writers.write_bytes_prefixed(sha, w)
|
writers.write_bytes_prefixed(sha, w)
|
||||||
|
|
||||||
|
|
||||||
async def process_unknown_action(
|
async def _process_unknown_action(
|
||||||
ctx: wire.Context, w: Writer, action: EosTxActionAck
|
ctx: wire.Context, w: Writer, action: EosTxActionAck
|
||||||
) -> None:
|
) -> None:
|
||||||
assert action.unknown is not None
|
from trezor.crypto.hashlib import sha256
|
||||||
checksum = HashWriter(sha256())
|
from trezor.utils import HashWriter
|
||||||
writers.write_uvarint(checksum, action.unknown.data_size)
|
from trezor.messages import EosTxActionAck, EosTxActionRequest
|
||||||
checksum.extend(action.unknown.data_chunk)
|
from .. import writers
|
||||||
|
from . import layout
|
||||||
|
|
||||||
writers.write_bytes_unchecked(w, action.unknown.data_chunk)
|
unknown = action.unknown # local_cache_attribute
|
||||||
bytes_left = action.unknown.data_size - len(action.unknown.data_chunk)
|
assert unknown is not None
|
||||||
|
data_chunk = unknown.data_chunk # local_cache_attribute
|
||||||
|
|
||||||
|
checksum = HashWriter(sha256())
|
||||||
|
writers.write_uvarint(checksum, unknown.data_size)
|
||||||
|
checksum.extend(data_chunk)
|
||||||
|
|
||||||
|
writers.write_bytes_unchecked(w, data_chunk)
|
||||||
|
bytes_left = unknown.data_size - len(data_chunk)
|
||||||
|
|
||||||
while bytes_left != 0:
|
while bytes_left != 0:
|
||||||
action = await ctx.call(
|
action = await ctx.call(
|
||||||
EosTxActionRequest(data_size=bytes_left), EosTxActionAck
|
EosTxActionRequest(data_size=bytes_left), EosTxActionAck
|
||||||
)
|
)
|
||||||
|
|
||||||
if action.unknown is None:
|
if unknown is None:
|
||||||
raise ValueError("Bad response. Unknown struct expected.")
|
raise ValueError("Bad response. Unknown struct expected.")
|
||||||
|
|
||||||
checksum.extend(action.unknown.data_chunk)
|
checksum.extend(data_chunk)
|
||||||
writers.write_bytes_unchecked(w, action.unknown.data_chunk)
|
writers.write_bytes_unchecked(w, data_chunk)
|
||||||
|
|
||||||
bytes_left -= len(action.unknown.data_chunk)
|
bytes_left -= len(data_chunk)
|
||||||
if bytes_left < 0:
|
if bytes_left < 0:
|
||||||
raise ValueError("Bad response. Buffer overflow.")
|
raise ValueError("Bad response. Buffer overflow.")
|
||||||
|
|
||||||
await layout.confirm_action_unknown(ctx, action.common, checksum.get_digest())
|
await layout.confirm_action_unknown(ctx, action.common, checksum.get_digest())
|
||||||
|
|
||||||
|
|
||||||
def check_action(action: EosTxActionAck, name: str, account: str) -> bool:
|
def _check_action(action: EosTxActionAck, name: str, account: str) -> bool:
|
||||||
if account == "eosio":
|
if account == "eosio":
|
||||||
return (
|
return (
|
||||||
(name == "buyram" and action.buy_ram is not None)
|
(name == "buyram" and action.buy_ram is not None)
|
||||||
|
@ -1,12 +1,14 @@
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from trezor import ui, wire
|
from trezor import ui
|
||||||
from trezor.enums import ButtonRequestType
|
from trezor.enums import ButtonRequestType
|
||||||
from trezor.ui.layouts import confirm_properties
|
from trezor.ui.layouts import confirm_properties
|
||||||
|
|
||||||
from .. import helpers
|
from ..helpers import eos_asset_to_string, eos_name_to_string
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
from typing import Iterable
|
||||||
|
from trezor.wire import Context
|
||||||
from trezor.messages import (
|
from trezor.messages import (
|
||||||
EosActionBuyRam,
|
EosActionBuyRam,
|
||||||
EosActionBuyRamBytes,
|
EosActionBuyRamBytes,
|
||||||
@ -27,313 +29,294 @@ if TYPE_CHECKING:
|
|||||||
from trezor.ui.layouts import PropertyType
|
from trezor.ui.layouts import PropertyType
|
||||||
|
|
||||||
|
|
||||||
async def confirm_action_buyram(ctx: wire.Context, msg: EosActionBuyRam) -> None:
|
# Because icon and br_code are almost always the same
|
||||||
|
# (and also calling with positional arguments takes less space)
|
||||||
|
async def _confirm_properties(
|
||||||
|
ctx: Context,
|
||||||
|
br_type: str,
|
||||||
|
title: str,
|
||||||
|
props: Iterable[PropertyType],
|
||||||
|
) -> None:
|
||||||
await confirm_properties(
|
await confirm_properties(
|
||||||
|
ctx,
|
||||||
|
br_type,
|
||||||
|
title,
|
||||||
|
props,
|
||||||
|
icon=ui.ICON_CONFIRM,
|
||||||
|
br_code=ButtonRequestType.ConfirmOutput,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def confirm_action_buyram(ctx: Context, msg: EosActionBuyRam) -> None:
|
||||||
|
await _confirm_properties(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_buyram",
|
"confirm_buyram",
|
||||||
title="Buy RAM",
|
"Buy RAM",
|
||||||
props=[
|
(
|
||||||
("Payer:", helpers.eos_name_to_string(msg.payer)),
|
("Payer:", eos_name_to_string(msg.payer)),
|
||||||
("Receiver:", helpers.eos_name_to_string(msg.receiver)),
|
("Receiver:", eos_name_to_string(msg.receiver)),
|
||||||
("Amount:", helpers.eos_asset_to_string(msg.quantity)),
|
("Amount:", eos_asset_to_string(msg.quantity)),
|
||||||
],
|
),
|
||||||
icon=ui.ICON_CONFIRM,
|
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def confirm_action_buyrambytes(
|
async def confirm_action_buyrambytes(ctx: Context, msg: EosActionBuyRamBytes) -> None:
|
||||||
ctx: wire.Context, msg: EosActionBuyRamBytes
|
await _confirm_properties(
|
||||||
) -> None:
|
|
||||||
await confirm_properties(
|
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_buyrambytes",
|
"confirm_buyrambytes",
|
||||||
title="Buy RAM",
|
"Buy RAM",
|
||||||
props=[
|
(
|
||||||
("Payer:", helpers.eos_name_to_string(msg.payer)),
|
("Payer:", eos_name_to_string(msg.payer)),
|
||||||
("Receiver:", helpers.eos_name_to_string(msg.receiver)),
|
("Receiver:", eos_name_to_string(msg.receiver)),
|
||||||
("Bytes:", str(msg.bytes)),
|
("Bytes:", str(msg.bytes)),
|
||||||
],
|
),
|
||||||
icon=ui.ICON_CONFIRM,
|
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def confirm_action_delegate(ctx: wire.Context, msg: EosActionDelegate) -> None:
|
async def confirm_action_delegate(ctx: Context, msg: EosActionDelegate) -> None:
|
||||||
props = [
|
props = [
|
||||||
("Sender:", helpers.eos_name_to_string(msg.sender)),
|
("Sender:", eos_name_to_string(msg.sender)),
|
||||||
("Receiver:", helpers.eos_name_to_string(msg.receiver)),
|
("Receiver:", eos_name_to_string(msg.receiver)),
|
||||||
("CPU:", helpers.eos_asset_to_string(msg.cpu_quantity)),
|
("CPU:", eos_asset_to_string(msg.cpu_quantity)),
|
||||||
("NET:", helpers.eos_asset_to_string(msg.net_quantity)),
|
("NET:", eos_asset_to_string(msg.net_quantity)),
|
||||||
]
|
]
|
||||||
|
append = props.append # local_cache_attribute
|
||||||
if msg.transfer:
|
if msg.transfer:
|
||||||
props.append(("Transfer:", "Yes"))
|
append(("Transfer:", "Yes"))
|
||||||
props.append(("Receiver:", helpers.eos_name_to_string(msg.receiver)))
|
append(("Receiver:", eos_name_to_string(msg.receiver)))
|
||||||
else:
|
else:
|
||||||
props.append(("Transfer:", "No"))
|
append(("Transfer:", "No"))
|
||||||
|
|
||||||
await confirm_properties(
|
await _confirm_properties(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_delegate",
|
"confirm_delegate",
|
||||||
title="Delegate",
|
"Delegate",
|
||||||
props=props,
|
props,
|
||||||
icon=ui.ICON_CONFIRM,
|
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def confirm_action_sellram(ctx: wire.Context, msg: EosActionSellRam) -> None:
|
async def confirm_action_sellram(ctx: Context, msg: EosActionSellRam) -> None:
|
||||||
await confirm_properties(
|
await _confirm_properties(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_sellram",
|
"confirm_sellram",
|
||||||
title="Sell RAM",
|
"Sell RAM",
|
||||||
props=[
|
(
|
||||||
("Receiver:", helpers.eos_name_to_string(msg.account)),
|
("Receiver:", eos_name_to_string(msg.account)),
|
||||||
("Bytes:", str(msg.bytes)),
|
("Bytes:", str(msg.bytes)),
|
||||||
],
|
),
|
||||||
icon=ui.ICON_CONFIRM,
|
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def confirm_action_undelegate(
|
async def confirm_action_undelegate(ctx: Context, msg: EosActionUndelegate) -> None:
|
||||||
ctx: wire.Context, msg: EosActionUndelegate
|
await _confirm_properties(
|
||||||
) -> None:
|
|
||||||
await confirm_properties(
|
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_undelegate",
|
"confirm_undelegate",
|
||||||
title="Undelegate",
|
"Undelegate",
|
||||||
props=[
|
(
|
||||||
("Sender:", helpers.eos_name_to_string(msg.sender)),
|
("Sender:", eos_name_to_string(msg.sender)),
|
||||||
("Receiver:", helpers.eos_name_to_string(msg.receiver)),
|
("Receiver:", eos_name_to_string(msg.receiver)),
|
||||||
("CPU:", helpers.eos_asset_to_string(msg.cpu_quantity)),
|
("CPU:", eos_asset_to_string(msg.cpu_quantity)),
|
||||||
("NET:", helpers.eos_asset_to_string(msg.net_quantity)),
|
("NET:", eos_asset_to_string(msg.net_quantity)),
|
||||||
],
|
),
|
||||||
icon=ui.ICON_CONFIRM,
|
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def confirm_action_refund(ctx: wire.Context, msg: EosActionRefund) -> None:
|
async def confirm_action_refund(ctx: Context, msg: EosActionRefund) -> None:
|
||||||
await confirm_properties(
|
await _confirm_properties(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_refund",
|
"confirm_refund",
|
||||||
title="Refund",
|
"Refund",
|
||||||
props=[
|
(("Owner:", eos_name_to_string(msg.owner)),),
|
||||||
("Owner:", helpers.eos_name_to_string(msg.owner)),
|
|
||||||
],
|
|
||||||
icon=ui.ICON_CONFIRM,
|
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def confirm_action_voteproducer(
|
async def confirm_action_voteproducer(ctx: Context, msg: EosActionVoteProducer) -> None:
|
||||||
ctx: wire.Context, msg: EosActionVoteProducer
|
producers = msg.producers # local_cache_attribute
|
||||||
) -> None:
|
|
||||||
if msg.proxy and not msg.producers:
|
if msg.proxy and not producers:
|
||||||
# PROXY
|
# PROXY
|
||||||
await confirm_properties(
|
await _confirm_properties(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_voteproducer",
|
"confirm_voteproducer",
|
||||||
title="Vote for proxy",
|
"Vote for proxy",
|
||||||
props=[
|
(
|
||||||
("Voter:", helpers.eos_name_to_string(msg.voter)),
|
("Voter:", eos_name_to_string(msg.voter)),
|
||||||
("Proxy:", helpers.eos_name_to_string(msg.proxy)),
|
("Proxy:", eos_name_to_string(msg.proxy)),
|
||||||
],
|
),
|
||||||
icon=ui.ICON_CONFIRM,
|
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
elif msg.producers:
|
elif producers:
|
||||||
# PRODUCERS
|
# PRODUCERS
|
||||||
await confirm_properties(
|
await _confirm_properties(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_voteproducer",
|
"confirm_voteproducer",
|
||||||
title="Vote for producers",
|
"Vote for producers",
|
||||||
props=(
|
(
|
||||||
(f"{wi:2d}. {helpers.eos_name_to_string(producer)}", None)
|
(f"{wi:2d}. {eos_name_to_string(producer)}", None)
|
||||||
for wi, producer in enumerate(msg.producers, 1)
|
for wi, producer in enumerate(producers, 1)
|
||||||
),
|
),
|
||||||
icon=ui.ICON_CONFIRM,
|
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# Cancel vote
|
# Cancel vote
|
||||||
await confirm_properties(
|
await _confirm_properties(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_voteproducer",
|
"confirm_voteproducer",
|
||||||
title="Cancel vote",
|
"Cancel vote",
|
||||||
props=[
|
(("Voter:", eos_name_to_string(msg.voter)),),
|
||||||
("Voter:", helpers.eos_name_to_string(msg.voter)),
|
|
||||||
],
|
|
||||||
icon=ui.ICON_CONFIRM,
|
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def confirm_action_transfer(
|
async def confirm_action_transfer(
|
||||||
ctx: wire.Context, msg: EosActionTransfer, account: str
|
ctx: Context, msg: EosActionTransfer, account: str
|
||||||
) -> None:
|
) -> None:
|
||||||
props = [
|
props = [
|
||||||
("From:", helpers.eos_name_to_string(msg.sender)),
|
("From:", eos_name_to_string(msg.sender)),
|
||||||
("To:", helpers.eos_name_to_string(msg.receiver)),
|
("To:", eos_name_to_string(msg.receiver)),
|
||||||
("Amount:", helpers.eos_asset_to_string(msg.quantity)),
|
("Amount:", eos_asset_to_string(msg.quantity)),
|
||||||
("Contract:", account),
|
("Contract:", account),
|
||||||
]
|
]
|
||||||
if msg.memo is not None:
|
if msg.memo is not None:
|
||||||
props.append(("Memo", msg.memo[:512]))
|
props.append(("Memo", msg.memo[:512]))
|
||||||
await confirm_properties(
|
await _confirm_properties(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_transfer",
|
"confirm_transfer",
|
||||||
title="Transfer",
|
"Transfer",
|
||||||
props=props,
|
props,
|
||||||
icon=ui.ICON_CONFIRM,
|
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def confirm_action_updateauth(
|
async def confirm_action_updateauth(ctx: Context, msg: EosActionUpdateAuth) -> None:
|
||||||
ctx: wire.Context, msg: EosActionUpdateAuth
|
|
||||||
) -> None:
|
|
||||||
props: list[PropertyType] = [
|
props: list[PropertyType] = [
|
||||||
("Account:", helpers.eos_name_to_string(msg.account)),
|
("Account:", eos_name_to_string(msg.account)),
|
||||||
("Permission:", helpers.eos_name_to_string(msg.permission)),
|
("Permission:", eos_name_to_string(msg.permission)),
|
||||||
("Parent:", helpers.eos_name_to_string(msg.parent)),
|
("Parent:", eos_name_to_string(msg.parent)),
|
||||||
]
|
]
|
||||||
props.extend(authorization_fields(msg.auth))
|
props.extend(authorization_fields(msg.auth))
|
||||||
await confirm_properties(
|
await _confirm_properties(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_updateauth",
|
"confirm_updateauth",
|
||||||
title="Update Auth",
|
"Update Auth",
|
||||||
props=props,
|
props,
|
||||||
icon=ui.ICON_CONFIRM,
|
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def confirm_action_deleteauth(
|
async def confirm_action_deleteauth(ctx: Context, msg: EosActionDeleteAuth) -> None:
|
||||||
ctx: wire.Context, msg: EosActionDeleteAuth
|
await _confirm_properties(
|
||||||
) -> None:
|
|
||||||
await confirm_properties(
|
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_deleteauth",
|
"confirm_deleteauth",
|
||||||
title="Delete Auth",
|
"Delete Auth",
|
||||||
props=[
|
(
|
||||||
("Account:", helpers.eos_name_to_string(msg.account)),
|
("Account:", eos_name_to_string(msg.account)),
|
||||||
("Permission:", helpers.eos_name_to_string(msg.permission)),
|
("Permission:", eos_name_to_string(msg.permission)),
|
||||||
],
|
),
|
||||||
icon=ui.ICON_CONFIRM,
|
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def confirm_action_linkauth(ctx: wire.Context, msg: EosActionLinkAuth) -> None:
|
async def confirm_action_linkauth(ctx: Context, msg: EosActionLinkAuth) -> None:
|
||||||
await confirm_properties(
|
await _confirm_properties(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_linkauth",
|
"confirm_linkauth",
|
||||||
title="Link Auth",
|
"Link Auth",
|
||||||
props=[
|
(
|
||||||
("Account:", helpers.eos_name_to_string(msg.account)),
|
("Account:", eos_name_to_string(msg.account)),
|
||||||
("Code:", helpers.eos_name_to_string(msg.code)),
|
("Code:", eos_name_to_string(msg.code)),
|
||||||
("Type:", helpers.eos_name_to_string(msg.type)),
|
("Type:", eos_name_to_string(msg.type)),
|
||||||
("Requirement:", helpers.eos_name_to_string(msg.requirement)),
|
("Requirement:", eos_name_to_string(msg.requirement)),
|
||||||
],
|
),
|
||||||
icon=ui.ICON_CONFIRM,
|
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def confirm_action_unlinkauth(
|
async def confirm_action_unlinkauth(ctx: Context, msg: EosActionUnlinkAuth) -> None:
|
||||||
ctx: wire.Context, msg: EosActionUnlinkAuth
|
await _confirm_properties(
|
||||||
) -> None:
|
|
||||||
await confirm_properties(
|
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_unlinkauth",
|
"confirm_unlinkauth",
|
||||||
title="Unlink Auth",
|
"Unlink Auth",
|
||||||
props=[
|
(
|
||||||
("Account:", helpers.eos_name_to_string(msg.account)),
|
("Account:", eos_name_to_string(msg.account)),
|
||||||
("Code:", helpers.eos_name_to_string(msg.code)),
|
("Code:", eos_name_to_string(msg.code)),
|
||||||
("Type:", helpers.eos_name_to_string(msg.type)),
|
("Type:", eos_name_to_string(msg.type)),
|
||||||
],
|
),
|
||||||
icon=ui.ICON_CONFIRM,
|
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def confirm_action_newaccount(
|
async def confirm_action_newaccount(ctx: Context, msg: EosActionNewAccount) -> None:
|
||||||
ctx: wire.Context, msg: EosActionNewAccount
|
|
||||||
) -> None:
|
|
||||||
props: list[PropertyType] = [
|
props: list[PropertyType] = [
|
||||||
("Creator:", helpers.eos_name_to_string(msg.creator)),
|
("Creator:", eos_name_to_string(msg.creator)),
|
||||||
("Name:", helpers.eos_name_to_string(msg.name)),
|
("Name:", eos_name_to_string(msg.name)),
|
||||||
]
|
]
|
||||||
props.extend(authorization_fields(msg.owner))
|
props.extend(authorization_fields(msg.owner))
|
||||||
props.extend(authorization_fields(msg.active))
|
props.extend(authorization_fields(msg.active))
|
||||||
await confirm_properties(
|
await _confirm_properties(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_newaccount",
|
"confirm_newaccount",
|
||||||
title="New Account",
|
"New Account",
|
||||||
props=props,
|
props,
|
||||||
icon=ui.ICON_CONFIRM,
|
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def confirm_action_unknown(
|
async def confirm_action_unknown(
|
||||||
ctx: wire.Context, action: EosActionCommon, checksum: bytes
|
ctx: Context, action: EosActionCommon, checksum: bytes
|
||||||
) -> None:
|
) -> None:
|
||||||
await confirm_properties(
|
await confirm_properties(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_unknown",
|
"confirm_unknown",
|
||||||
title="Arbitrary data",
|
"Arbitrary data",
|
||||||
props=[
|
(
|
||||||
("Contract:", helpers.eos_name_to_string(action.account)),
|
("Contract:", eos_name_to_string(action.account)),
|
||||||
("Action Name:", helpers.eos_name_to_string(action.name)),
|
("Action Name:", eos_name_to_string(action.name)),
|
||||||
("Checksum:", checksum),
|
("Checksum:", checksum),
|
||||||
],
|
),
|
||||||
icon=ui.ICON_WIPE,
|
ui.ICON_WIPE,
|
||||||
icon_color=ui.RED,
|
ui.RED,
|
||||||
br_code=ButtonRequestType.ConfirmOutput,
|
br_code=ButtonRequestType.ConfirmOutput,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def authorization_fields(auth: EosAuthorization) -> list[PropertyType]:
|
def authorization_fields(auth: EosAuthorization) -> list[PropertyType]:
|
||||||
|
from trezor.wire import DataError
|
||||||
|
from ..helpers import public_key_to_wif
|
||||||
|
|
||||||
fields: list[PropertyType] = []
|
fields: list[PropertyType] = []
|
||||||
fields.append(("Threshold:", str(auth.threshold)))
|
append = fields.append # local_cache_attribute
|
||||||
|
|
||||||
|
append(("Threshold:", str(auth.threshold)))
|
||||||
|
|
||||||
|
# NOTE: getting rid of f-strings saved almost 100 bytes
|
||||||
|
|
||||||
for i, key in enumerate(auth.keys, 1):
|
for i, key in enumerate(auth.keys, 1):
|
||||||
if key.key is None:
|
if key.key is None:
|
||||||
raise wire.DataError("Key must be provided explicitly.")
|
raise DataError("Key must be provided explicitly.")
|
||||||
|
|
||||||
_key = helpers.public_key_to_wif(bytes(key.key))
|
_key = public_key_to_wif(bytes(key.key))
|
||||||
_weight = str(key.weight)
|
_weight = str(key.weight)
|
||||||
|
|
||||||
header = f"Key #{i}:"
|
header = "Key #" + str(i) + ":"
|
||||||
w_header = f"Key #{i} Weight:"
|
w_header = "Key #" + str(i) + " Weight:"
|
||||||
|
|
||||||
fields.append((header, _key))
|
append((header, _key))
|
||||||
fields.append((w_header, _weight))
|
append((w_header, _weight))
|
||||||
|
|
||||||
for i, account in enumerate(auth.accounts, 1):
|
for i, account in enumerate(auth.accounts, 1):
|
||||||
_account = helpers.eos_name_to_string(account.account.actor)
|
_account = eos_name_to_string(account.account.actor)
|
||||||
_permission = helpers.eos_name_to_string(account.account.permission)
|
_permission = eos_name_to_string(account.account.permission)
|
||||||
|
|
||||||
a_header = f"Account #{i}:"
|
i = str(i)
|
||||||
p_header = f"Acc Permission #{i}:"
|
a_header = "Account #" + i + ":"
|
||||||
w_header = f"Account #{i} weight:"
|
p_header = "Acc Permission #" + i + ":"
|
||||||
|
w_header = "Account #" + i + " weight:"
|
||||||
|
|
||||||
fields.append((a_header, _account))
|
append((a_header, _account))
|
||||||
fields.append((p_header, _permission))
|
append((p_header, _permission))
|
||||||
fields.append((w_header, str(account.weight)))
|
append((w_header, str(account.weight)))
|
||||||
|
|
||||||
for i, wait in enumerate(auth.waits, 1):
|
for i, wait in enumerate(auth.waits, 1):
|
||||||
_wait = str(wait.wait_sec)
|
_wait = str(wait.wait_sec)
|
||||||
_weight = str(wait.weight)
|
_weight = str(wait.weight)
|
||||||
|
|
||||||
header = f"Delay #{i}"
|
header = "Delay #" + str(i)
|
||||||
w_header = f"Delay #{i} weight:"
|
w_header = header + " weight:"
|
||||||
fields.append((header, f"{_wait} sec"))
|
append((header, _wait + " sec"))
|
||||||
fields.append((w_header, _weight))
|
append((w_header, _weight))
|
||||||
|
|
||||||
return fields
|
return fields
|
||||||
|
@ -1,35 +1,30 @@
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from trezor import wire
|
from apps.common.keychain import auto_keychain
|
||||||
from trezor.crypto.curve import secp256k1
|
|
||||||
from trezor.messages import EosPublicKey
|
|
||||||
|
|
||||||
from apps.common import paths
|
|
||||||
from apps.common.keychain import Keychain, auto_keychain
|
|
||||||
|
|
||||||
from .helpers import public_key_to_wif
|
|
||||||
from .layout import require_get_public_key
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from trezor.messages import EosGetPublicKey
|
from trezor.messages import EosGetPublicKey, EosPublicKey
|
||||||
from trezor.crypto import bip32
|
from apps.common.keychain import Keychain
|
||||||
|
from trezor.wire import Context
|
||||||
|
|
||||||
def _get_public_key(node: bip32.HDNode) -> tuple[str, bytes]:
|
|
||||||
seckey = node.private_key()
|
|
||||||
public_key = secp256k1.publickey(seckey, True)
|
|
||||||
wif = public_key_to_wif(public_key)
|
|
||||||
return wif, public_key
|
|
||||||
|
|
||||||
|
|
||||||
@auto_keychain(__name__)
|
@auto_keychain(__name__)
|
||||||
async def get_public_key(
|
async def get_public_key(
|
||||||
ctx: wire.Context, msg: EosGetPublicKey, keychain: Keychain
|
ctx: Context, msg: EosGetPublicKey, keychain: Keychain
|
||||||
) -> EosPublicKey:
|
) -> EosPublicKey:
|
||||||
|
from trezor.crypto.curve import secp256k1
|
||||||
|
from trezor.messages import EosPublicKey
|
||||||
|
from apps.common import paths
|
||||||
|
from .helpers import public_key_to_wif
|
||||||
|
from .layout import require_get_public_key
|
||||||
|
|
||||||
await paths.validate_path(ctx, keychain, msg.address_n)
|
await paths.validate_path(ctx, keychain, msg.address_n)
|
||||||
|
|
||||||
node = keychain.derive(msg.address_n)
|
node = keychain.derive(msg.address_n)
|
||||||
wif, public_key = _get_public_key(node)
|
|
||||||
|
public_key = secp256k1.publickey(node.private_key(), True)
|
||||||
|
wif = public_key_to_wif(public_key)
|
||||||
|
|
||||||
if msg.show_display:
|
if msg.show_display:
|
||||||
await require_get_public_key(ctx, wif)
|
await require_get_public_key(ctx, wif)
|
||||||
return EosPublicKey(wif_public_key=wif, raw_public_key=public_key)
|
return EosPublicKey(wif_public_key=wif, raw_public_key=public_key)
|
||||||
|
@ -1,13 +1,12 @@
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from trezor import wire
|
|
||||||
from trezor.crypto import base58
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from trezor.messages import EosAsset
|
from trezor.messages import EosAsset
|
||||||
|
|
||||||
|
|
||||||
def base58_encode(prefix: str, sig_prefix: str, data: bytes) -> str:
|
def base58_encode(prefix: str, sig_prefix: str, data: bytes) -> str:
|
||||||
|
from trezor.crypto import base58
|
||||||
|
|
||||||
b58 = base58.encode(data + base58.ripemd160_32(data + sig_prefix.encode()))
|
b58 = base58.encode(data + base58.ripemd160_32(data + sig_prefix.encode()))
|
||||||
if sig_prefix:
|
if sig_prefix:
|
||||||
return prefix + sig_prefix + "_" + b58
|
return prefix + sig_prefix + "_" + b58
|
||||||
@ -45,11 +44,13 @@ def eos_asset_to_string(asset: EosAsset) -> str:
|
|||||||
|
|
||||||
|
|
||||||
def public_key_to_wif(pub_key: bytes) -> str:
|
def public_key_to_wif(pub_key: bytes) -> str:
|
||||||
|
from trezor.wire import DataError
|
||||||
|
|
||||||
if pub_key[0] == 0x04 and len(pub_key) == 65:
|
if pub_key[0] == 0x04 and len(pub_key) == 65:
|
||||||
head = b"\x03" if pub_key[64] & 0x01 else b"\x02"
|
head = b"\x03" if pub_key[64] & 0x01 else b"\x02"
|
||||||
compressed_pub_key = head + pub_key[1:33]
|
compressed_pub_key = head + pub_key[1:33]
|
||||||
elif pub_key[0] in [0x02, 0x03] and len(pub_key) == 33:
|
elif pub_key[0] in [0x02, 0x03] and len(pub_key) == 33:
|
||||||
compressed_pub_key = pub_key
|
compressed_pub_key = pub_key
|
||||||
else:
|
else:
|
||||||
raise wire.DataError("invalid public key")
|
raise DataError("invalid public key")
|
||||||
return base58_encode("EOS", "", compressed_pub_key)
|
return base58_encode("EOS", "", compressed_pub_key)
|
||||||
|
@ -1,18 +1,25 @@
|
|||||||
from trezor import ui, wire
|
from typing import TYPE_CHECKING
|
||||||
from trezor.enums import ButtonRequestType
|
|
||||||
from trezor.strings import format_plural
|
if TYPE_CHECKING:
|
||||||
from trezor.ui.layouts import confirm_action, show_pubkey
|
from trezor.wire import Context
|
||||||
|
|
||||||
|
|
||||||
async def require_get_public_key(ctx: wire.Context, public_key: str) -> None:
|
async def require_get_public_key(ctx: Context, public_key: str) -> None:
|
||||||
|
from trezor.ui.layouts import show_pubkey
|
||||||
|
|
||||||
await show_pubkey(ctx, public_key)
|
await show_pubkey(ctx, public_key)
|
||||||
|
|
||||||
|
|
||||||
async def require_sign_tx(ctx: wire.Context, num_actions: int) -> None:
|
async def require_sign_tx(ctx: Context, num_actions: int) -> None:
|
||||||
|
from trezor import ui
|
||||||
|
from trezor.enums import ButtonRequestType
|
||||||
|
from trezor.strings import format_plural
|
||||||
|
from trezor.ui.layouts import confirm_action
|
||||||
|
|
||||||
await confirm_action(
|
await confirm_action(
|
||||||
ctx,
|
ctx,
|
||||||
"confirm_tx",
|
"confirm_tx",
|
||||||
title="Sign transaction",
|
"Sign transaction",
|
||||||
description="You are about to sign {}.",
|
description="You are about to sign {}.",
|
||||||
description_param=format_plural("{count} {plural}", num_actions, "action"),
|
description_param=format_plural("{count} {plural}", num_actions, "action"),
|
||||||
icon=ui.ICON_SEND,
|
icon=ui.ICON_SEND,
|
||||||
|
@ -1,36 +1,50 @@
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from trezor import wire
|
from apps.common.keychain import auto_keychain
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from trezor.wire import Context
|
||||||
|
from trezor.messages import EosSignTx, EosSignedTx
|
||||||
|
from apps.common.keychain import Keychain
|
||||||
|
|
||||||
|
|
||||||
|
@auto_keychain(__name__)
|
||||||
|
async def sign_tx(ctx: Context, msg: EosSignTx, keychain: Keychain) -> EosSignedTx:
|
||||||
|
from trezor.wire import DataError
|
||||||
from trezor.crypto.curve import secp256k1
|
from trezor.crypto.curve import secp256k1
|
||||||
from trezor.crypto.hashlib import sha256
|
from trezor.crypto.hashlib import sha256
|
||||||
from trezor.messages import EosSignedTx, EosTxActionAck, EosTxActionRequest
|
from trezor.messages import EosSignedTx, EosTxActionAck, EosTxActionRequest
|
||||||
from trezor.utils import HashWriter
|
from trezor.utils import HashWriter
|
||||||
|
|
||||||
from apps.common import paths
|
from apps.common import paths
|
||||||
from apps.common.keychain import Keychain, auto_keychain
|
from .writers import write_uvarint, write_header, write_bytes_fixed
|
||||||
|
|
||||||
from . import writers
|
|
||||||
from .actions import process_action
|
from .actions import process_action
|
||||||
from .helpers import base58_encode
|
from .helpers import base58_encode
|
||||||
from .layout import require_sign_tx
|
from .layout import require_sign_tx
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
num_actions = msg.num_actions # local_cache_attribute
|
||||||
from trezor.messages import EosSignTx
|
|
||||||
|
|
||||||
|
if not num_actions:
|
||||||
@auto_keychain(__name__)
|
raise DataError("No actions")
|
||||||
async def sign_tx(ctx: wire.Context, msg: EosSignTx, keychain: Keychain) -> EosSignedTx:
|
|
||||||
if not msg.num_actions:
|
|
||||||
raise wire.DataError("No actions")
|
|
||||||
|
|
||||||
await paths.validate_path(ctx, keychain, msg.address_n)
|
await paths.validate_path(ctx, keychain, msg.address_n)
|
||||||
|
|
||||||
node = keychain.derive(msg.address_n)
|
node = keychain.derive(msg.address_n)
|
||||||
sha = HashWriter(sha256())
|
sha = HashWriter(sha256())
|
||||||
await _init(ctx, sha, msg)
|
|
||||||
await _actions(ctx, sha, msg.num_actions)
|
# init
|
||||||
writers.write_uvarint(sha, 0)
|
write_bytes_fixed(sha, msg.chain_id, 32)
|
||||||
writers.write_bytes_fixed(sha, bytearray(32), 32)
|
write_header(sha, msg.header)
|
||||||
|
write_uvarint(sha, 0)
|
||||||
|
write_uvarint(sha, num_actions)
|
||||||
|
await require_sign_tx(ctx, num_actions)
|
||||||
|
|
||||||
|
# actions
|
||||||
|
for _ in range(num_actions):
|
||||||
|
action = await ctx.call(EosTxActionRequest(), EosTxActionAck)
|
||||||
|
await process_action(ctx, sha, action)
|
||||||
|
|
||||||
|
write_uvarint(sha, 0)
|
||||||
|
write_bytes_fixed(sha, bytearray(32), 32)
|
||||||
|
|
||||||
digest = sha.get_digest()
|
digest = sha.get_digest()
|
||||||
signature = secp256k1.sign(
|
signature = secp256k1.sign(
|
||||||
@ -38,18 +52,3 @@ async def sign_tx(ctx: wire.Context, msg: EosSignTx, keychain: Keychain) -> EosS
|
|||||||
)
|
)
|
||||||
|
|
||||||
return EosSignedTx(signature=base58_encode("SIG_", "K1", signature))
|
return EosSignedTx(signature=base58_encode("SIG_", "K1", signature))
|
||||||
|
|
||||||
|
|
||||||
async def _init(ctx: wire.Context, sha: HashWriter, msg: EosSignTx) -> None:
|
|
||||||
writers.write_bytes_fixed(sha, msg.chain_id, 32)
|
|
||||||
writers.write_header(sha, msg.header)
|
|
||||||
writers.write_uvarint(sha, 0)
|
|
||||||
writers.write_uvarint(sha, msg.num_actions)
|
|
||||||
|
|
||||||
await require_sign_tx(ctx, msg.num_actions)
|
|
||||||
|
|
||||||
|
|
||||||
async def _actions(ctx: wire.Context, sha: HashWriter, num_actions: int) -> None:
|
|
||||||
for _ in range(num_actions):
|
|
||||||
action = await ctx.call(EosTxActionRequest(), EosTxActionAck)
|
|
||||||
await process_action(ctx, sha, action)
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from trezor import wire
|
|
||||||
|
|
||||||
from apps.common.writers import (
|
from apps.common.writers import (
|
||||||
write_bytes_fixed,
|
write_bytes_fixed,
|
||||||
write_bytes_unchecked,
|
write_bytes_unchecked,
|
||||||
@ -36,11 +34,13 @@ if TYPE_CHECKING:
|
|||||||
|
|
||||||
|
|
||||||
def write_auth(w: Writer, auth: EosAuthorization) -> None:
|
def write_auth(w: Writer, auth: EosAuthorization) -> None:
|
||||||
|
from trezor.wire import DataError
|
||||||
|
|
||||||
write_uint32_le(w, auth.threshold)
|
write_uint32_le(w, auth.threshold)
|
||||||
write_uvarint(w, len(auth.keys))
|
write_uvarint(w, len(auth.keys))
|
||||||
for key in auth.keys:
|
for key in auth.keys:
|
||||||
if key.key is None:
|
if key.key is None:
|
||||||
raise wire.DataError("Key must be provided explicitly.")
|
raise DataError("Key must be provided explicitly.")
|
||||||
write_uvarint(w, key.type)
|
write_uvarint(w, key.type)
|
||||||
write_bytes_fixed(w, key.key, 33)
|
write_bytes_fixed(w, key.key, 33)
|
||||||
write_uint16_le(w, key.weight)
|
write_uint16_le(w, key.weight)
|
||||||
@ -91,14 +91,13 @@ def write_action_sellram(w: Writer, msg: EosActionSellRam) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def write_action_delegate(w: Writer, msg: EosActionDelegate) -> None:
|
def write_action_delegate(w: Writer, msg: EosActionDelegate) -> None:
|
||||||
write_uint64_le(w, msg.sender)
|
write_action_undelegate(w, msg)
|
||||||
write_uint64_le(w, msg.receiver)
|
|
||||||
write_asset(w, msg.net_quantity)
|
|
||||||
write_asset(w, msg.cpu_quantity)
|
|
||||||
write_uint8(w, 1 if msg.transfer else 0)
|
write_uint8(w, 1 if msg.transfer else 0)
|
||||||
|
|
||||||
|
|
||||||
def write_action_undelegate(w: Writer, msg: EosActionUndelegate) -> None:
|
def write_action_undelegate(
|
||||||
|
w: Writer, msg: EosActionUndelegate | EosActionDelegate
|
||||||
|
) -> None:
|
||||||
write_uint64_le(w, msg.sender)
|
write_uint64_le(w, msg.sender)
|
||||||
write_uint64_le(w, msg.receiver)
|
write_uint64_le(w, msg.receiver)
|
||||||
write_asset(w, msg.net_quantity)
|
write_asset(w, msg.net_quantity)
|
||||||
@ -118,25 +117,26 @@ def write_action_voteproducer(w: Writer, msg: EosActionVoteProducer) -> None:
|
|||||||
|
|
||||||
|
|
||||||
def write_action_updateauth(w: Writer, msg: EosActionUpdateAuth) -> None:
|
def write_action_updateauth(w: Writer, msg: EosActionUpdateAuth) -> None:
|
||||||
write_uint64_le(w, msg.account)
|
write_action_deleteauth(w, msg)
|
||||||
write_uint64_le(w, msg.permission)
|
|
||||||
write_uint64_le(w, msg.parent)
|
write_uint64_le(w, msg.parent)
|
||||||
write_auth(w, msg.auth)
|
write_auth(w, msg.auth)
|
||||||
|
|
||||||
|
|
||||||
def write_action_deleteauth(w: Writer, msg: EosActionDeleteAuth) -> None:
|
def write_action_deleteauth(
|
||||||
|
w: Writer, msg: EosActionDeleteAuth | EosActionUpdateAuth
|
||||||
|
) -> None:
|
||||||
write_uint64_le(w, msg.account)
|
write_uint64_le(w, msg.account)
|
||||||
write_uint64_le(w, msg.permission)
|
write_uint64_le(w, msg.permission)
|
||||||
|
|
||||||
|
|
||||||
def write_action_linkauth(w: Writer, msg: EosActionLinkAuth) -> None:
|
def write_action_linkauth(w: Writer, msg: EosActionLinkAuth) -> None:
|
||||||
write_uint64_le(w, msg.account)
|
write_action_unlinkauth(w, msg)
|
||||||
write_uint64_le(w, msg.code)
|
|
||||||
write_uint64_le(w, msg.type)
|
|
||||||
write_uint64_le(w, msg.requirement)
|
write_uint64_le(w, msg.requirement)
|
||||||
|
|
||||||
|
|
||||||
def write_action_unlinkauth(w: Writer, msg: EosActionUnlinkAuth) -> None:
|
def write_action_unlinkauth(
|
||||||
|
w: Writer, msg: EosActionUnlinkAuth | EosActionLinkAuth
|
||||||
|
) -> None:
|
||||||
write_uint64_le(w, msg.account)
|
write_uint64_le(w, msg.account)
|
||||||
write_uint64_le(w, msg.code)
|
write_uint64_le(w, msg.code)
|
||||||
write_uint64_le(w, msg.type)
|
write_uint64_le(w, msg.type)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
from common import *
|
from common import *
|
||||||
|
|
||||||
if not utils.BITCOIN_ONLY:
|
if not utils.BITCOIN_ONLY:
|
||||||
from apps.eos.actions import check_action
|
from apps.eos.actions import _check_action
|
||||||
from trezor.messages import EosTxActionAck
|
from trezor.messages import EosTxActionAck
|
||||||
|
|
||||||
|
|
||||||
@ -9,43 +9,43 @@ if not utils.BITCOIN_ONLY:
|
|||||||
class TestEosActions(unittest.TestCase):
|
class TestEosActions(unittest.TestCase):
|
||||||
def test_check_action(self):
|
def test_check_action(self):
|
||||||
# return True
|
# return True
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), buy_ram=object()), 'buyram', 'eosio'), True)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), buy_ram=object()), 'buyram', 'eosio'), True)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), buy_ram_bytes=object()), 'buyrambytes', 'eosio'), True)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), buy_ram_bytes=object()), 'buyrambytes', 'eosio'), True)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), sell_ram=object()), 'sellram', 'eosio'), True)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), sell_ram=object()), 'sellram', 'eosio'), True)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), delegate=object()), 'delegatebw', 'eosio'), True)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), delegate=object()), 'delegatebw', 'eosio'), True)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), undelegate=object()), 'undelegatebw', 'eosio'), True)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), undelegate=object()), 'undelegatebw', 'eosio'), True)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), refund=object()), 'refund', 'eosio'), True)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), refund=object()), 'refund', 'eosio'), True)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), vote_producer=object()), 'voteproducer', 'eosio'), True)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), vote_producer=object()), 'voteproducer', 'eosio'), True)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), update_auth=object()), 'updateauth', 'eosio'), True)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), update_auth=object()), 'updateauth', 'eosio'), True)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), delete_auth=object()), 'deleteauth', 'eosio'), True)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), delete_auth=object()), 'deleteauth', 'eosio'), True)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), link_auth=object()), 'linkauth', 'eosio'), True)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), link_auth=object()), 'linkauth', 'eosio'), True)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), unlink_auth=object()), 'unlinkauth', 'eosio'), True)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), unlink_auth=object()), 'unlinkauth', 'eosio'), True)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), new_account=object()), 'newaccount', 'eosio'), True)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), new_account=object()), 'newaccount', 'eosio'), True)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), transfer=object()), 'transfer', 'not_eosio'), True)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), transfer=object()), 'transfer', 'not_eosio'), True)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), unknown=[]), 'unknown', 'not_eosio'), True)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), unknown=[]), 'unknown', 'not_eosio'), True)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), unknown=[]), 'buyram', 'buygoods'), True)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), unknown=[]), 'buyram', 'buygoods'), True)
|
||||||
|
|
||||||
# returns False
|
# returns False
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), buy_ram=object()), 'buyram', 'not_eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), buy_ram=object()), 'buyram', 'not_eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object()), 'buyram', 'eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object()), 'buyram', 'eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), buy_ram_bytes=object()), 'buyrambytes', 'not_eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), buy_ram_bytes=object()), 'buyrambytes', 'not_eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), sell_ram=object()), 'sellram', 'not_eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), sell_ram=object()), 'sellram', 'not_eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), delegate=object()), 'delegatebw', 'not_eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), delegate=object()), 'delegatebw', 'not_eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), undelegate=object()), 'undelegatebw', 'not_eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), undelegate=object()), 'undelegatebw', 'not_eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), refund=object()), 'refund', 'not_eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), refund=object()), 'refund', 'not_eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object()), 'refund', 'eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object()), 'refund', 'eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), vote_producer=object()), 'voteproducer', 'not_eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), vote_producer=object()), 'voteproducer', 'not_eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), update_auth=object()), 'updateauth', 'not_eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), update_auth=object()), 'updateauth', 'not_eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), delete_auth=object()), 'deleteauth', 'not_eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), delete_auth=object()), 'deleteauth', 'not_eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), link_auth=object()), 'linkauth', 'not_eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), link_auth=object()), 'linkauth', 'not_eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), unlink_auth=object()), 'unlinkauth', 'not_eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), unlink_auth=object()), 'unlinkauth', 'not_eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object()), 'unlinkauth', 'eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object()), 'unlinkauth', 'eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), new_account=object()), 'newaccount', 'not_eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), new_account=object()), 'newaccount', 'not_eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), transfer=object()), 'transfer', 'eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), transfer=object()), 'transfer', 'eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object()), 'unknown', 'not_eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object()), 'unknown', 'not_eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), buy_ram=object()), 'test', 'eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), buy_ram=object()), 'test', 'eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), unknown=[]), 'buyram', 'eosio'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), unknown=[]), 'buyram', 'eosio'), False)
|
||||||
self.assertEqual(check_action(EosTxActionAck(common=object(), unknown=[]), 'transfer', 'loveme'), False)
|
self.assertEqual(_check_action(EosTxActionAck(common=object(), unknown=[]), 'transfer', 'loveme'), False)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
@ -1,13 +1,20 @@
|
|||||||
from common import *
|
from common import *
|
||||||
|
|
||||||
from trezor.crypto import bip32, bip39
|
from trezor.crypto import bip32, bip39
|
||||||
from apps.common.paths import HARDENED
|
from trezor.crypto.curve import secp256k1
|
||||||
|
|
||||||
if not utils.BITCOIN_ONLY:
|
if not utils.BITCOIN_ONLY:
|
||||||
from apps.eos.get_public_key import _get_public_key
|
|
||||||
from apps.eos.helpers import public_key_to_wif
|
from apps.eos.helpers import public_key_to_wif
|
||||||
|
|
||||||
|
|
||||||
|
# NOTE: copy-pasted from apps.eos.get_public_key
|
||||||
|
def _get_public_key(node: bip32.HDNode) -> tuple[str, bytes]:
|
||||||
|
seckey = node.private_key()
|
||||||
|
public_key = secp256k1.publickey(seckey, True)
|
||||||
|
wif = public_key_to_wif(public_key)
|
||||||
|
return wif, public_key
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
|
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
|
||||||
class TestEosGetPublicKey(unittest.TestCase):
|
class TestEosGetPublicKey(unittest.TestCase):
|
||||||
def test_get_public_key_scheme(self):
|
def test_get_public_key_scheme(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user