You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.4 KiB
77 lines
2.4 KiB
![]()
6 years ago
|
from trezor.crypto.curve import ed25519
|
||
![]()
6 years ago
|
from trezor.messages.NEMSignedTx import NEMSignedTx
|
||
|
from trezor.messages.NEMSignTx import NEMSignTx
|
||
|
|
||
![]()
6 years ago
|
from apps.common import seed
|
||
![]()
6 years ago
|
from apps.common.paths import validate_path
|
||
![]()
5 years ago
|
from apps.nem import CURVE, mosaic, multisig, namespace, transfer
|
||
|
from apps.nem.helpers import NEM_HASH_ALG, check_path
|
||
![]()
6 years ago
|
from apps.nem.validators import validate
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
async def sign_tx(ctx, msg: NEMSignTx, keychain):
|
||
![]()
6 years ago
|
validate(msg)
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
await validate_path(
|
||
![]()
5 years ago
|
ctx,
|
||
|
check_path,
|
||
|
keychain,
|
||
|
msg.transaction.address_n,
|
||
![]()
5 years ago
|
CURVE,
|
||
![]()
5 years ago
|
network=msg.transaction.network,
|
||
![]()
6 years ago
|
)
|
||
|
|
||
![]()
5 years ago
|
node = keychain.derive(msg.transaction.address_n, CURVE)
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
if msg.multisig:
|
||
|
public_key = msg.multisig.signer
|
||
![]()
6 years ago
|
common = msg.multisig
|
||
![]()
6 years ago
|
await multisig.ask(ctx, msg)
|
||
![]()
6 years ago
|
else:
|
||
![]()
6 years ago
|
public_key = seed.remove_ed25519_prefix(node.public_key())
|
||
![]()
6 years ago
|
common = msg.transaction
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
if msg.transfer:
|
||
![]()
6 years ago
|
tx = await transfer.transfer(ctx, public_key, common, msg.transfer, node)
|
||
![]()
6 years ago
|
elif msg.provision_namespace:
|
||
![]()
6 years ago
|
tx = await namespace.namespace(ctx, public_key, common, msg.provision_namespace)
|
||
![]()
6 years ago
|
elif msg.mosaic_creation:
|
||
![]()
6 years ago
|
tx = await mosaic.mosaic_creation(ctx, public_key, common, msg.mosaic_creation)
|
||
![]()
6 years ago
|
elif msg.supply_change:
|
||
![]()
6 years ago
|
tx = await mosaic.supply_change(ctx, public_key, common, msg.supply_change)
|
||
![]()
6 years ago
|
elif msg.aggregate_modification:
|
||
![]()
6 years ago
|
tx = await multisig.aggregate_modification(
|
||
|
ctx,
|
||
|
public_key,
|
||
|
common,
|
||
|
msg.aggregate_modification,
|
||
|
msg.multisig is not None,
|
||
|
)
|
||
![]()
6 years ago
|
elif msg.importance_transfer:
|
||
![]()
6 years ago
|
tx = await transfer.importance_transfer(
|
||
|
ctx, public_key, common, msg.importance_transfer
|
||
|
)
|
||
![]()
6 years ago
|
else:
|
||
![]()
6 years ago
|
raise ValueError("No transaction provided")
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
if msg.multisig:
|
||
|
# wrap transaction in multisig wrapper
|
||
![]()
6 years ago
|
if msg.cosigning:
|
||
![]()
6 years ago
|
tx = multisig.cosign(
|
||
![]()
6 years ago
|
seed.remove_ed25519_prefix(node.public_key()),
|
||
|
msg.transaction,
|
||
|
tx,
|
||
|
msg.multisig.signer,
|
||
![]()
6 years ago
|
)
|
||
![]()
6 years ago
|
else:
|
||
![]()
6 years ago
|
tx = multisig.initiate(
|
||
|
seed.remove_ed25519_prefix(node.public_key()), msg.transaction, tx
|
||
|
)
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
signature = ed25519.sign(node.private_key(), tx, NEM_HASH_ALG)
|
||
![]()
6 years ago
|
|
||
![]()
6 years ago
|
resp = NEMSignedTx()
|
||
|
resp.data = tx
|
||
|
resp.signature = signature
|
||
|
return resp
|