mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-18 13:38:12 +00:00
nem: provision namespace signing
This commit is contained in:
parent
105ba853af
commit
381d2da1ea
@ -23,7 +23,14 @@ async def require_confirm_fee(ctx, fee):
|
||||
await require_confirm(ctx, content, ButtonRequestType.ConfirmOutput)
|
||||
|
||||
|
||||
async def require_confirm_action(ctx, payload: bytes, encrypt=False):
|
||||
async def require_confirm_final(ctx, action: str):
|
||||
content = Text('Confirm sending', ui.ICON_SEND,
|
||||
ui.NORMAL, *split_words(action, 18),
|
||||
icon_color=ui.GREEN)
|
||||
await require_hold_to_confirm(ctx, content, ButtonRequestType.SignTx) # we use SignTx, not ConfirmOutput, for compatibility with T1
|
||||
|
||||
|
||||
async def require_confirm_payload(ctx, payload: bytes, encrypt=False):
|
||||
payload = str(payload, 'utf-8')
|
||||
if encrypt:
|
||||
content = Text('Send encrypted?', ui.ICON_SEND,
|
||||
|
@ -10,17 +10,46 @@ from trezor.crypto import random
|
||||
|
||||
|
||||
async def nem_sign_tx(ctx, msg: NEMSignTx):
|
||||
|
||||
validate(msg)
|
||||
|
||||
node = await seed.derive_node(ctx, msg.transaction.address_n, NEM_CURVE)
|
||||
payload, encrypted = _get_payload(msg, node)
|
||||
public_key = _get_public_key(node)
|
||||
tx = bytearray()
|
||||
|
||||
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?
|
||||
tx = await _provision_namespace(ctx, node, msg)
|
||||
|
||||
signature = ed25519.sign(node.private_key(), tx, helpers.NEM_HASH_ALG)
|
||||
|
||||
resp = NEMSignedTx()
|
||||
resp.data = tx
|
||||
resp.signature = signature
|
||||
return resp
|
||||
|
||||
|
||||
async def _provision_namespace(ctx, node, msg: NEMSignTx) -> bytearray:
|
||||
await require_confirm_fee(ctx, msg.transaction.fee)
|
||||
await require_confirm_final(ctx, 'Create provision namespace "' + msg.provision_namespace.namespace + '"?')
|
||||
return nem_transaction_create_provision_namespace(
|
||||
msg.transaction.network,
|
||||
msg.transaction.timestamp,
|
||||
_get_public_key(node),
|
||||
msg.transaction.fee,
|
||||
msg.transaction.deadline,
|
||||
msg.provision_namespace.namespace,
|
||||
msg.provision_namespace.parent,
|
||||
msg.provision_namespace.sink,
|
||||
msg.provision_namespace.fee)
|
||||
|
||||
|
||||
async def _transfer(ctx, node, msg: NEMSignTx) -> bytes:
|
||||
payload, encrypted = _get_payload(msg, node)
|
||||
tx = nem_transaction_create_transfer(
|
||||
msg.transaction.network,
|
||||
msg.transaction.timestamp,
|
||||
public_key,
|
||||
_get_public_key(node),
|
||||
msg.transaction.fee,
|
||||
msg.transaction.deadline,
|
||||
msg.transfer.recipient,
|
||||
@ -34,17 +63,12 @@ async def nem_sign_tx(ctx, msg: NEMSignTx):
|
||||
nem_transaction_write_mosaic(tx, mosaic.namespace, mosaic.mosaic, mosaic.quantity)
|
||||
|
||||
if payload: # confirm unencrypted
|
||||
await require_confirm_action(ctx, msg.transfer.payload, encrypted)
|
||||
await require_confirm_payload(ctx, msg.transfer.payload, encrypted)
|
||||
|
||||
await require_confirm_fee(ctx, msg.transaction.fee)
|
||||
await require_confirm_tx(ctx, msg.transfer.recipient, msg.transfer.amount)
|
||||
|
||||
signature = ed25519.sign(node.private_key(), tx, helpers.NEM_HASH_ALG)
|
||||
|
||||
resp = NEMSignedTx()
|
||||
resp.data = tx
|
||||
resp.signature = signature
|
||||
return resp
|
||||
return tx
|
||||
|
||||
|
||||
def _get_payload(msg: NEMSignTx, node) -> [bytes, bool]:
|
||||
|
@ -16,7 +16,7 @@ def validate(msg: NEMSignTx):
|
||||
if msg.transaction is None:
|
||||
raise ValueError('No common provided')
|
||||
|
||||
if msg.provision_namespace or msg.mosaic_creation or msg.supply_change or msg.aggregate_modification \
|
||||
if msg.mosaic_creation or msg.supply_change or msg.aggregate_modification \
|
||||
or msg.importance_transfer:
|
||||
raise ValueError('Not yet implemented') # todo
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user