mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-16 03:18:09 +00:00
nem: multisig correct serialization fix
This commit is contained in:
parent
9a52039b25
commit
1355b19c77
@ -4,7 +4,10 @@ from trezor.messages.NEMSignTx import NEMSignTx
|
|||||||
|
|
||||||
|
|
||||||
def serialize_mosaic_creation(msg: NEMSignTx, public_key: bytes):
|
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()
|
mosaics_w = bytearray()
|
||||||
write_bytes_with_length(mosaics_w, bytearray(public_key))
|
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):
|
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)
|
identifier_length = 4 + len(msg.supply_change.namespace) + 4 + len(msg.supply_change.mosaic)
|
||||||
write_uint32(w, identifier_length)
|
write_uint32(w, identifier_length)
|
||||||
|
@ -6,15 +6,15 @@ async def ask(ctx, msg: NEMSignTx):
|
|||||||
await ask_multisig(ctx, msg)
|
await ask_multisig(ctx, msg)
|
||||||
|
|
||||||
|
|
||||||
def initiate(public_key, msg: NEMSignTx, inner_tx: bytes) -> bytes:
|
def initiate(public_key, common: NEMTransactionCommon, inner_tx: bytes) -> bytes:
|
||||||
return serialize_multisig(msg.multisig, public_key, inner_tx)
|
return serialize_multisig(common, public_key, inner_tx)
|
||||||
|
|
||||||
|
|
||||||
def cosign(public_key, msg: NEMSignTx, inner_tx: bytes) -> bytes:
|
def cosign(public_key, common: NEMTransactionCommon, inner_tx: bytes, signer: bytes) -> bytes:
|
||||||
return serialize_multisig_signature(msg.multisig,
|
return serialize_multisig_signature(common,
|
||||||
public_key,
|
public_key,
|
||||||
inner_tx,
|
inner_tx,
|
||||||
msg.multisig.signer)
|
signer)
|
||||||
|
|
||||||
|
|
||||||
async def aggregate_modification(ctx, public_key: bytes, msg: NEMSignTx):
|
async def aggregate_modification(ctx, public_key: bytes, msg: NEMSignTx):
|
||||||
|
@ -10,7 +10,7 @@ async def ask_multisig(ctx, msg: NEMSignTx):
|
|||||||
await _require_confirm_address(ctx, 'Cosign transaction for', address)
|
await _require_confirm_address(ctx, 'Cosign transaction for', address)
|
||||||
else:
|
else:
|
||||||
await _require_confirm_address(ctx, 'Initiate transaction for', address)
|
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):
|
async def ask_aggregate_modification(ctx, msg: NEMSignTx):
|
||||||
|
@ -5,8 +5,8 @@ from trezor.crypto import hashlib
|
|||||||
from trezor.crypto import nem
|
from trezor.crypto import nem
|
||||||
|
|
||||||
|
|
||||||
def serialize_multisig(msg: NEMTransactionCommon, public_key: bytes, inner: bytes):
|
def serialize_multisig(common: NEMTransactionCommon, public_key: bytes, inner: bytes):
|
||||||
w = write_common(msg, bytearray(public_key), NEM_TRANSACTION_TYPE_MULTISIG)
|
w = write_common(common, bytearray(public_key), NEM_TRANSACTION_TYPE_MULTISIG)
|
||||||
write_bytes_with_length(w, bytearray(inner))
|
write_bytes_with_length(w, bytearray(inner))
|
||||||
return w
|
return w
|
||||||
|
|
||||||
@ -24,11 +24,14 @@ def serialize_multisig_signature(common: NEMTransactionCommon, public_key: bytes
|
|||||||
|
|
||||||
|
|
||||||
def serialize_aggregate_modification(msg: NEMSignTx, 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:
|
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),
|
bytearray(public_key),
|
||||||
NEM_TRANSACTION_TYPE_AGGREGATE_MODIFICATION,
|
NEM_TRANSACTION_TYPE_AGGREGATE_MODIFICATION,
|
||||||
version)
|
version)
|
||||||
|
@ -4,7 +4,10 @@ from trezor.messages.NEMSignTx import NEMSignTx
|
|||||||
|
|
||||||
|
|
||||||
def serialize_provision_namespace(msg: NEMSignTx, public_key: bytes) -> bytearray:
|
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),
|
bytearray(public_key),
|
||||||
NEM_TRANSACTION_TYPE_PROVISION_NAMESPACE)
|
NEM_TRANSACTION_TYPE_PROVISION_NAMESPACE)
|
||||||
|
|
||||||
|
@ -38,9 +38,9 @@ async def sign_tx(ctx, msg: NEMSignTx):
|
|||||||
if msg.multisig:
|
if msg.multisig:
|
||||||
# wrap transaction in multisig wrapper
|
# wrap transaction in multisig wrapper
|
||||||
if msg.cosigning:
|
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:
|
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)
|
signature = ed25519.sign(node.private_key(), tx, NEM_HASH_ALG)
|
||||||
|
|
||||||
|
@ -6,10 +6,13 @@ from trezor.crypto import random
|
|||||||
|
|
||||||
|
|
||||||
def serialize_transfer(msg: NEMSignTx, public_key: bytes, payload: bytes=None, encrypted: bool=False) -> bytearray:
|
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),
|
bytearray(public_key),
|
||||||
NEM_TRANSACTION_TYPE_TRANSFER,
|
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_bytes_with_length(tx, bytearray(msg.transfer.recipient))
|
||||||
write_uint64(tx, msg.transfer.amount)
|
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:
|
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_uint32(w, msg.importance_transfer.mode)
|
||||||
write_bytes_with_length(w, bytearray(msg.importance_transfer.public_key))
|
write_bytes_with_length(w, bytearray(msg.importance_transfer.public_key))
|
||||||
|
@ -20,6 +20,7 @@ def validate(msg: NEMSignTx):
|
|||||||
_validate_common(msg.transaction)
|
_validate_common(msg.transaction)
|
||||||
|
|
||||||
if msg.multisig:
|
if msg.multisig:
|
||||||
|
_validate_common(msg.multisig, True)
|
||||||
_validate_multisig(msg.multisig, msg.transaction.network)
|
_validate_multisig(msg.multisig, msg.transaction.network)
|
||||||
if not msg.multisig and msg.cosigning:
|
if not msg.multisig and msg.cosigning:
|
||||||
raise ValueError('No multisig transaction to cosign')
|
raise ValueError('No multisig transaction to cosign')
|
||||||
@ -76,12 +77,12 @@ def _validate_common(common: NEMTransactionCommon, inner: bool=False):
|
|||||||
if common.deadline is None:
|
if common.deadline is None:
|
||||||
err = 'deadline'
|
err = 'deadline'
|
||||||
|
|
||||||
# is_signer = common.signer is not None todo !!
|
if not inner and common.signer:
|
||||||
# if inner != is_signer:
|
raise ValueError('Signer not allowed in outer transaction')
|
||||||
# if not inner:
|
|
||||||
# raise ValueError('Signer not allowed in outer transaction')
|
if inner and common.signer is None:
|
||||||
# err = 'signer'
|
err = 'signer'
|
||||||
#
|
|
||||||
if err:
|
if err:
|
||||||
if inner:
|
if inner:
|
||||||
raise ValueError('No ' + err + ' provided in inner transaction')
|
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):
|
def _validate_multisig(multisig: NEMTransactionCommon, network: int):
|
||||||
_validate_common(multisig)
|
|
||||||
_validate_public_key(multisig.signer, 'Invalid multisig signer public key provided')
|
_validate_public_key(multisig.signer, 'Invalid multisig signer public key provided')
|
||||||
if multisig.network != network:
|
if multisig.network != network:
|
||||||
raise ValueError('Inner transaction network is different')
|
raise ValueError('Inner transaction network is different')
|
||||||
|
Loading…
Reference in New Issue
Block a user