1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-19 12:58:13 +00:00

nem: mosaic creation signing

This commit is contained in:
Tomas Susanka 2018-03-28 11:53:47 +02:00 committed by Jan Pochyla
parent 381d2da1ea
commit 448ce35c2b
4 changed files with 53 additions and 11 deletions

View File

@ -15,17 +15,18 @@ async def require_confirm_tx(ctx, recipient, value):
await require_hold_to_confirm(ctx, content, ButtonRequestType.SignTx) # we use SignTx, not ConfirmOutput, for compatibility with T1
async def require_confirm_fee(ctx, fee):
content = Text('Confirm fee', ui.ICON_SEND,
'Pay ', ui.BOLD, format_amount(fee, NEM_MAX_DIVISIBILITY) + ' NEM',
ui.NORMAL, 'for transaction fee?',
async def require_confirm_action(ctx, action: str):
content = Text('Confirm sending', ui.ICON_SEND,
ui.NORMAL, *split_words(action, 18),
icon_color=ui.GREEN)
await require_confirm(ctx, content, ButtonRequestType.ConfirmOutput)
async def require_confirm_final(ctx, action: str):
async def require_confirm_final(ctx, action: str, fee: int):
content = Text('Confirm sending', ui.ICON_SEND,
ui.NORMAL, *split_words(action, 18),
ui.NORMAL, 'Create ', action,
ui.BOLD, 'paying ' + format_amount(fee, NEM_MAX_DIVISIBILITY) + ' NEM',
ui.NORMAL, 'for transaction fee?',
icon_color=ui.GREEN)
await require_hold_to_confirm(ctx, content, ButtonRequestType.SignTx) # we use SignTx, not ConfirmOutput, for compatibility with T1

View File

@ -21,6 +21,9 @@ async def nem_sign_tx(ctx, msg: NEMSignTx):
elif msg.provision_namespace: # todo are those disjunctive?
tx = await _provision_namespace(ctx, node, msg)
elif msg.mosaic_creation:
tx = await _mosaic_creation(ctx, node, msg)
signature = ed25519.sign(node.private_key(), tx, helpers.NEM_HASH_ALG)
resp = NEMSignedTx()
@ -29,9 +32,43 @@ async def nem_sign_tx(ctx, msg: NEMSignTx):
return resp
async def _mosaic_creation(ctx, node, msg: NEMSignTx) -> bytearray:
await require_confirm_action(ctx, 'Create mosaic "' + msg.mosaic_creation.definition.mosaic + '" under namespace "'
+ msg.mosaic_creation.definition.namespace + '"?')
if msg.mosaic_creation.definition.description:
await require_confirm_action(ctx, 'Create mosaic with description: '
+ msg.mosaic_creation.definition.description)
if msg.mosaic_creation.definition.mutable_supply:
await require_confirm_action(ctx, 'Create mosaic with mutable supply')
else:
await require_confirm_action(ctx, 'Create mosaic with immutable supply')
await require_confirm_final(ctx, 'mosaic', msg.transaction.fee)
return nem_transaction_create_mosaic_creation(
msg.transaction.network,
msg.transaction.timestamp,
_get_public_key(node),
msg.transaction.fee,
msg.transaction.deadline,
msg.mosaic_creation.definition.namespace,
msg.mosaic_creation.definition.mosaic,
msg.mosaic_creation.definition.description,
msg.mosaic_creation.definition.divisibility,
msg.mosaic_creation.definition.supply,
msg.mosaic_creation.definition.mutable_supply,
msg.mosaic_creation.definition.transferable,
msg.mosaic_creation.definition.levy,
msg.mosaic_creation.definition.fee,
msg.mosaic_creation.definition.levy_address,
msg.mosaic_creation.definition.levy_namespace,
msg.mosaic_creation.definition.levy_mosaic,
msg.mosaic_creation.sink,
msg.mosaic_creation.fee)
async def _provision_namespace(ctx, node, msg: NEMSignTx) -> bytearray:
await require_confirm_fee(ctx, msg.transaction.fee)
await require_confirm_final(ctx, 'Create provision namespace "' + msg.provision_namespace.namespace + '"?')
await require_confirm_action(ctx, 'Create provision namespace "' + msg.provision_namespace.namespace + '"?')
await require_confirm_final(ctx, 'provision namespace', msg.transaction.fee)
return nem_transaction_create_provision_namespace(
msg.transaction.network,
msg.transaction.timestamp,
@ -65,7 +102,7 @@ async def _transfer(ctx, node, msg: NEMSignTx) -> bytes:
if payload: # confirm unencrypted
await require_confirm_payload(ctx, msg.transfer.payload, encrypted)
await require_confirm_fee(ctx, msg.transaction.fee)
await require_confirm_action(ctx, 'todo') # todo!
await require_confirm_tx(ctx, msg.transfer.recipient, msg.transfer.amount)
return tx

View File

@ -165,13 +165,17 @@ def nem_transaction_write_minimum_cosignatories(w: bytearray, relative_change: i
def nem_write_mosaic(w: bytearray, name: str, value):
if value is None:
if name in ['divisibility', 'initialSupply']:
value = 0
elif name in ['supplyMutable', 'transferable']:
value = False
if type(value) == bool:
if value:
value = "true"
else:
value = "false"
elif type(value) == int:
# todo might need more formatting
value = str(value)
elif type(value) != str:
raise ValueError('Incompatible value type')

View File

@ -16,7 +16,7 @@ def validate(msg: NEMSignTx):
if msg.transaction is None:
raise ValueError('No common provided')
if msg.mosaic_creation or msg.supply_change or msg.aggregate_modification \
if msg.supply_change or msg.aggregate_modification \
or msg.importance_transfer:
raise ValueError('Not yet implemented') # todo