1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 20:38:10 +00:00

nem: aggregate modification signing

This commit is contained in:
Tomas Susanka 2018-03-29 11:43:38 +02:00 committed by Jan Pochyla
parent d4b2bee47e
commit 52affe2897
2 changed files with 33 additions and 9 deletions

View File

@ -17,15 +17,14 @@ async def nem_sign_tx(ctx, msg: NEMSignTx):
if msg.transfer: if msg.transfer:
tx = await _transfer(ctx, node, msg) tx = await _transfer(ctx, node, msg)
# todo msg.transfer.mosaics = canonicalize_mosaics(msg.transfer.mosaics) # todo msg.transfer.mosaics = canonicalize_mosaics(msg.transfer.mosaics)
elif msg.provision_namespace:
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: elif msg.mosaic_creation:
tx = await _mosaic_creation(ctx, node, msg) tx = await _mosaic_creation(ctx, node, msg)
elif msg.supply_change: elif msg.supply_change:
tx = await _supply_change(ctx, node, msg) tx = await _supply_change(ctx, node, msg)
elif msg.aggregate_modification:
tx = await _aggregate_modification(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)
@ -35,6 +34,27 @@ async def nem_sign_tx(ctx, msg: NEMSignTx):
return resp return resp
async def _aggregate_modification(ctx, node, msg: NEMSignTx):
# todo confirms!
w = nem_transaction_create_aggregate_modification(
msg.transaction.network,
msg.transaction.timestamp,
_get_public_key(node),
msg.transaction.fee,
msg.transaction.deadline,
len(msg.aggregate_modification.modifications),
msg.aggregate_modification.relative_change
)
for m in msg.aggregate_modification.modifications:
nem_transaction_write_cosignatory_modification(w, m.type, m.public_key)
if msg.aggregate_modification.relative_change:
nem_transaction_write_minimum_cosignatories(w, msg.aggregate_modification.relative_change)
return w
async def _supply_change(ctx, node, msg: NEMSignTx): async def _supply_change(ctx, node, msg: NEMSignTx):
# todo confirms! # todo confirms!
return nem_transaction_create_mosaic_supply_change( return nem_transaction_create_mosaic_supply_change(

View File

@ -1,5 +1,5 @@
from apps.nem.helpers import * from apps.nem.helpers import *
from trezor.messages.NEMModificationType import CosignatoryModification_Delete from trezor.messages import NEMModificationType
from trezor.messages.NEMSignTx import NEMAggregateModification from trezor.messages.NEMSignTx import NEMAggregateModification
from trezor.messages.NEMSignTx import NEMImportanceTransfer from trezor.messages.NEMSignTx import NEMImportanceTransfer
from trezor.messages.NEMSignTx import NEMMosaicCreation from trezor.messages.NEMSignTx import NEMMosaicCreation
@ -16,8 +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.aggregate_modification \ if msg.importance_transfer:
or msg.importance_transfer:
raise ValueError('Not yet implemented') # todo raise ValueError('Not yet implemented') # todo
_validate_single_tx(msg) _validate_single_tx(msg)
@ -32,7 +31,7 @@ def validate(msg: NEMSignTx):
if msg.supply_change: if msg.supply_change:
_validate_supply_change(msg.supply_change) _validate_supply_change(msg.supply_change)
if msg.aggregate_modification: if msg.aggregate_modification:
_validate_aggregate_modification(msg.aggregate_modification, not len(msg.multisig)) _validate_aggregate_modification(msg.aggregate_modification, msg.multisig is not None)
if msg.importance_transfer: if msg.importance_transfer:
_validate_importance_transfer(msg.importance_transfer) _validate_importance_transfer(msg.importance_transfer)
@ -112,7 +111,12 @@ def _validate_aggregate_modification(aggregate_modification: NEMAggregateModific
for m in aggregate_modification.modifications: for m in aggregate_modification.modifications:
if not m.type: if not m.type:
raise ValueError('No modification type provided') raise ValueError('No modification type provided')
if creation and m.type == CosignatoryModification_Delete: if m.type not in [
NEMModificationType.CosignatoryModification_Add,
NEMModificationType.CosignatoryModification_Delete
]:
raise ValueError('Unknown aggregate modification ')
if creation and m.type == NEMModificationType.CosignatoryModification_Delete:
raise ValueError('Cannot remove cosignatory when converting account') raise ValueError('Cannot remove cosignatory when converting account')
_validate_public_key(m.public_key, 'Invalid cosignatory public key provided') _validate_public_key(m.public_key, 'Invalid cosignatory public key provided')