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:
parent
d4b2bee47e
commit
52affe2897
@ -17,15 +17,14 @@ async def nem_sign_tx(ctx, msg: NEMSignTx):
|
||||
if msg.transfer:
|
||||
tx = await _transfer(ctx, node, msg)
|
||||
# todo msg.transfer.mosaics = canonicalize_mosaics(msg.transfer.mosaics)
|
||||
|
||||
elif msg.provision_namespace: # todo are those disjunctive?
|
||||
elif msg.provision_namespace:
|
||||
tx = await _provision_namespace(ctx, node, msg)
|
||||
|
||||
elif msg.mosaic_creation:
|
||||
tx = await _mosaic_creation(ctx, node, msg)
|
||||
|
||||
elif msg.supply_change:
|
||||
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)
|
||||
|
||||
@ -35,6 +34,27 @@ async def nem_sign_tx(ctx, msg: NEMSignTx):
|
||||
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):
|
||||
# todo confirms!
|
||||
return nem_transaction_create_mosaic_supply_change(
|
||||
|
@ -1,5 +1,5 @@
|
||||
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 NEMImportanceTransfer
|
||||
from trezor.messages.NEMSignTx import NEMMosaicCreation
|
||||
@ -16,8 +16,7 @@ def validate(msg: NEMSignTx):
|
||||
if msg.transaction is None:
|
||||
raise ValueError('No common provided')
|
||||
|
||||
if msg.aggregate_modification \
|
||||
or msg.importance_transfer:
|
||||
if msg.importance_transfer:
|
||||
raise ValueError('Not yet implemented') # todo
|
||||
|
||||
_validate_single_tx(msg)
|
||||
@ -32,7 +31,7 @@ def validate(msg: NEMSignTx):
|
||||
if msg.supply_change:
|
||||
_validate_supply_change(msg.supply_change)
|
||||
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:
|
||||
_validate_importance_transfer(msg.importance_transfer)
|
||||
|
||||
@ -112,7 +111,12 @@ def _validate_aggregate_modification(aggregate_modification: NEMAggregateModific
|
||||
for m in aggregate_modification.modifications:
|
||||
if not m.type:
|
||||
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')
|
||||
_validate_public_key(m.public_key, 'Invalid cosignatory public key provided')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user