diff --git a/src/apps/nem/mosaic/serialize.py b/src/apps/nem/mosaic/serialize.py index 2300923a0d..0eeb340123 100644 --- a/src/apps/nem/mosaic/serialize.py +++ b/src/apps/nem/mosaic/serialize.py @@ -4,7 +4,10 @@ from trezor.messages.NEMSignTx import NEMSignTx def serialize_mosaic_creation(msg: NEMSignTx, public_key: bytes): - w = write_common(msg.transaction, bytearray(public_key), NEM_TRANSACTION_TYPE_MOSAIC_CREATION) + common = msg.transaction + if msg.multisig: + common = msg.multisig + w = write_common(common, bytearray(public_key), NEM_TRANSACTION_TYPE_MOSAIC_CREATION) mosaics_w = bytearray() write_bytes_with_length(mosaics_w, bytearray(public_key)) @@ -42,7 +45,10 @@ def serialize_mosaic_creation(msg: NEMSignTx, public_key: bytes): def serialize_mosaic_supply_change(msg: NEMSignTx, public_key: bytes): - w = write_common(msg.transaction, bytearray(public_key), NEM_TRANSACTION_TYPE_MOSAIC_SUPPLY_CHANGE) + common = msg.transaction + if msg.multisig: + common = msg.multisig + w = write_common(common, bytearray(public_key), NEM_TRANSACTION_TYPE_MOSAIC_SUPPLY_CHANGE) identifier_length = 4 + len(msg.supply_change.namespace) + 4 + len(msg.supply_change.mosaic) write_uint32(w, identifier_length) diff --git a/src/apps/nem/multisig/__init__.py b/src/apps/nem/multisig/__init__.py index d31fd25a54..bbcde9cc03 100644 --- a/src/apps/nem/multisig/__init__.py +++ b/src/apps/nem/multisig/__init__.py @@ -6,15 +6,15 @@ async def ask(ctx, msg: NEMSignTx): await ask_multisig(ctx, msg) -def initiate(public_key, msg: NEMSignTx, inner_tx: bytes) -> bytes: - return serialize_multisig(msg.multisig, public_key, inner_tx) +def initiate(public_key, common: NEMTransactionCommon, inner_tx: bytes) -> bytes: + return serialize_multisig(common, public_key, inner_tx) -def cosign(public_key, msg: NEMSignTx, inner_tx: bytes) -> bytes: - return serialize_multisig_signature(msg.multisig, +def cosign(public_key, common: NEMTransactionCommon, inner_tx: bytes, signer: bytes) -> bytes: + return serialize_multisig_signature(common, public_key, inner_tx, - msg.multisig.signer) + signer) async def aggregate_modification(ctx, public_key: bytes, msg: NEMSignTx): diff --git a/src/apps/nem/multisig/layout.py b/src/apps/nem/multisig/layout.py index 1615866b67..f7251f4e8b 100644 --- a/src/apps/nem/multisig/layout.py +++ b/src/apps/nem/multisig/layout.py @@ -10,7 +10,7 @@ async def ask_multisig(ctx, msg: NEMSignTx): await _require_confirm_address(ctx, 'Cosign transaction for', address) else: await _require_confirm_address(ctx, 'Initiate transaction for', address) - await require_confirm_fee(ctx, 'Confirm multisig fee', msg.multisig.fee) + await require_confirm_fee(ctx, 'Confirm multisig fee', msg.transaction.fee) async def ask_aggregate_modification(ctx, msg: NEMSignTx): diff --git a/src/apps/nem/multisig/serialize.py b/src/apps/nem/multisig/serialize.py index 6ba49336dd..ca23ae5d50 100644 --- a/src/apps/nem/multisig/serialize.py +++ b/src/apps/nem/multisig/serialize.py @@ -5,8 +5,8 @@ from trezor.crypto import hashlib from trezor.crypto import nem -def serialize_multisig(msg: NEMTransactionCommon, public_key: bytes, inner: bytes): - w = write_common(msg, bytearray(public_key), NEM_TRANSACTION_TYPE_MULTISIG) +def serialize_multisig(common: NEMTransactionCommon, public_key: bytes, inner: bytes): + w = write_common(common, bytearray(public_key), NEM_TRANSACTION_TYPE_MULTISIG) write_bytes_with_length(w, bytearray(inner)) return w @@ -24,11 +24,14 @@ def serialize_multisig_signature(common: NEMTransactionCommon, public_key: bytes def serialize_aggregate_modification(msg: NEMSignTx, public_key: bytes): - version = msg.transaction.network << 24 | 1 + common = msg.transaction + if msg.multisig: + common = msg.multisig + version = common.network << 24 | 1 if msg.aggregate_modification.relative_change: - version = msg.transaction.network << 24 | 2 + version = common.network << 24 | 2 - w = write_common(msg.transaction, + w = write_common(common, bytearray(public_key), NEM_TRANSACTION_TYPE_AGGREGATE_MODIFICATION, version) diff --git a/src/apps/nem/namespace/serialize.py b/src/apps/nem/namespace/serialize.py index 9deeddf330..a60c1e106e 100644 --- a/src/apps/nem/namespace/serialize.py +++ b/src/apps/nem/namespace/serialize.py @@ -4,7 +4,10 @@ from trezor.messages.NEMSignTx import NEMSignTx def serialize_provision_namespace(msg: NEMSignTx, public_key: bytes) -> bytearray: - tx = write_common(msg.transaction, + common = msg.transaction + if msg.multisig: + common = msg.multisig + tx = write_common(common, bytearray(public_key), NEM_TRANSACTION_TYPE_PROVISION_NAMESPACE) diff --git a/src/apps/nem/signing.py b/src/apps/nem/signing.py index d96b49456c..9395bc6782 100644 --- a/src/apps/nem/signing.py +++ b/src/apps/nem/signing.py @@ -38,9 +38,9 @@ async def sign_tx(ctx, msg: NEMSignTx): if msg.multisig: # wrap transaction in multisig wrapper if msg.cosigning: - tx = multisig.cosign(_get_public_key(node), msg, tx) + tx = multisig.cosign(_get_public_key(node), msg.transaction, tx, msg.multisig.signer) else: - tx = multisig.initiate(_get_public_key(node), msg, tx) + tx = multisig.initiate(_get_public_key(node), msg.transaction, tx) signature = ed25519.sign(node.private_key(), tx, NEM_HASH_ALG) diff --git a/src/apps/nem/transfer/serialize.py b/src/apps/nem/transfer/serialize.py index 6bc7986cf1..9002a9ffd4 100644 --- a/src/apps/nem/transfer/serialize.py +++ b/src/apps/nem/transfer/serialize.py @@ -6,10 +6,13 @@ from trezor.crypto import random def serialize_transfer(msg: NEMSignTx, public_key: bytes, payload: bytes=None, encrypted: bool=False) -> bytearray: - tx = write_common(msg.transaction, + common = msg.transaction + if msg.multisig: + common = msg.multisig + tx = write_common(common, bytearray(public_key), NEM_TRANSACTION_TYPE_TRANSFER, - _get_version(msg.transaction.network, msg.transfer.mosaics)) + _get_version(common.network, msg.transfer.mosaics)) write_bytes_with_length(tx, bytearray(msg.transfer.recipient)) write_uint64(tx, msg.transfer.amount) @@ -42,7 +45,10 @@ def serialize_mosaic(w: bytearray, namespace: str, mosaic: str, quantity: int): def serialize_importance_transfer(msg: NEMSignTx, public_key: bytes) -> bytearray: - w = write_common(msg.transaction, bytearray(public_key), NEM_TRANSACTION_TYPE_IMPORTANCE_TRANSFER) + common = msg.transaction + if msg.multisig: + common = msg.multisig + w = write_common(common, bytearray(public_key), NEM_TRANSACTION_TYPE_IMPORTANCE_TRANSFER) write_uint32(w, msg.importance_transfer.mode) write_bytes_with_length(w, bytearray(msg.importance_transfer.public_key)) diff --git a/src/apps/nem/validators.py b/src/apps/nem/validators.py index 1ac4502e50..e7f8cc439d 100644 --- a/src/apps/nem/validators.py +++ b/src/apps/nem/validators.py @@ -20,6 +20,7 @@ def validate(msg: NEMSignTx): _validate_common(msg.transaction) if msg.multisig: + _validate_common(msg.multisig, True) _validate_multisig(msg.multisig, msg.transaction.network) if not msg.multisig and msg.cosigning: raise ValueError('No multisig transaction to cosign') @@ -76,12 +77,12 @@ def _validate_common(common: NEMTransactionCommon, inner: bool=False): if common.deadline is None: err = 'deadline' - # is_signer = common.signer is not None todo !! - # if inner != is_signer: - # if not inner: - # raise ValueError('Signer not allowed in outer transaction') - # err = 'signer' - # + if not inner and common.signer: + raise ValueError('Signer not allowed in outer transaction') + + if inner and common.signer is None: + err = 'signer' + if err: if inner: raise ValueError('No ' + err + ' provided in inner transaction') @@ -106,7 +107,6 @@ def _validate_importance_transfer(importance_transfer: NEMImportanceTransfer): def _validate_multisig(multisig: NEMTransactionCommon, network: int): - _validate_common(multisig) _validate_public_key(multisig.signer, 'Invalid multisig signer public key provided') if multisig.network != network: raise ValueError('Inner transaction network is different')