mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-06-15 04:28:46 +00:00
nem: mosaic creation signing
This commit is contained in:
parent
381d2da1ea
commit
448ce35c2b
@ -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
|
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):
|
async def require_confirm_action(ctx, action: str):
|
||||||
content = Text('Confirm fee', ui.ICON_SEND,
|
content = Text('Confirm sending', ui.ICON_SEND,
|
||||||
'Pay ', ui.BOLD, format_amount(fee, NEM_MAX_DIVISIBILITY) + ' NEM',
|
ui.NORMAL, *split_words(action, 18),
|
||||||
ui.NORMAL, 'for transaction fee?',
|
|
||||||
icon_color=ui.GREEN)
|
icon_color=ui.GREEN)
|
||||||
await require_confirm(ctx, content, ButtonRequestType.ConfirmOutput)
|
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,
|
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)
|
icon_color=ui.GREEN)
|
||||||
await require_hold_to_confirm(ctx, content, ButtonRequestType.SignTx) # we use SignTx, not ConfirmOutput, for compatibility with T1
|
await require_hold_to_confirm(ctx, content, ButtonRequestType.SignTx) # we use SignTx, not ConfirmOutput, for compatibility with T1
|
||||||
|
|
||||||
|
@ -21,6 +21,9 @@ async def nem_sign_tx(ctx, msg: NEMSignTx):
|
|||||||
elif msg.provision_namespace: # todo are those disjunctive?
|
elif msg.provision_namespace: # todo are those disjunctive?
|
||||||
tx = await _provision_namespace(ctx, node, msg)
|
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)
|
signature = ed25519.sign(node.private_key(), tx, helpers.NEM_HASH_ALG)
|
||||||
|
|
||||||
resp = NEMSignedTx()
|
resp = NEMSignedTx()
|
||||||
@ -29,9 +32,43 @@ async def nem_sign_tx(ctx, msg: NEMSignTx):
|
|||||||
return resp
|
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:
|
async def _provision_namespace(ctx, node, msg: NEMSignTx) -> bytearray:
|
||||||
await require_confirm_fee(ctx, msg.transaction.fee)
|
await require_confirm_action(ctx, 'Create provision namespace "' + msg.provision_namespace.namespace + '"?')
|
||||||
await require_confirm_final(ctx, 'Create provision namespace "' + msg.provision_namespace.namespace + '"?')
|
await require_confirm_final(ctx, 'provision namespace', msg.transaction.fee)
|
||||||
return nem_transaction_create_provision_namespace(
|
return nem_transaction_create_provision_namespace(
|
||||||
msg.transaction.network,
|
msg.transaction.network,
|
||||||
msg.transaction.timestamp,
|
msg.transaction.timestamp,
|
||||||
@ -65,7 +102,7 @@ async def _transfer(ctx, node, msg: NEMSignTx) -> bytes:
|
|||||||
if payload: # confirm unencrypted
|
if payload: # confirm unencrypted
|
||||||
await require_confirm_payload(ctx, msg.transfer.payload, encrypted)
|
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)
|
await require_confirm_tx(ctx, msg.transfer.recipient, msg.transfer.amount)
|
||||||
|
|
||||||
return tx
|
return tx
|
||||||
|
@ -165,13 +165,17 @@ def nem_transaction_write_minimum_cosignatories(w: bytearray, relative_change: i
|
|||||||
|
|
||||||
|
|
||||||
def nem_write_mosaic(w: bytearray, name: str, value):
|
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 type(value) == bool:
|
||||||
if value:
|
if value:
|
||||||
value = "true"
|
value = "true"
|
||||||
else:
|
else:
|
||||||
value = "false"
|
value = "false"
|
||||||
elif type(value) == int:
|
elif type(value) == int:
|
||||||
# todo might need more formatting
|
|
||||||
value = str(value)
|
value = str(value)
|
||||||
elif type(value) != str:
|
elif type(value) != str:
|
||||||
raise ValueError('Incompatible value type')
|
raise ValueError('Incompatible value type')
|
||||||
|
@ -16,7 +16,7 @@ def validate(msg: NEMSignTx):
|
|||||||
if msg.transaction is None:
|
if msg.transaction is None:
|
||||||
raise ValueError('No common provided')
|
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:
|
or msg.importance_transfer:
|
||||||
raise ValueError('Not yet implemented') # todo
|
raise ValueError('Not yet implemented') # todo
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user