1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-02-03 03:11:17 +00:00

apps: move ed25519 prefix common function

This commit is contained in:
Tomas Susanka 2018-06-18 14:23:33 +02:00
parent 7f767eec46
commit 96a91b56e9
5 changed files with 12 additions and 12 deletions

View File

@ -45,6 +45,6 @@ def derive_node_without_passphrase(
return node return node
def remove_ed25519_public_key_prefix(pubkey: bytes) -> bytes: def remove_ed25519_prefix(pubkey: bytes) -> bytes:
# 0x01 prefix is not part of the actual public key, hence removed # 0x01 prefix is not part of the actual public key, hence removed
return pubkey[1:] return pubkey[1:]

View File

@ -18,7 +18,7 @@ async def sign_tx(ctx, msg: NEMSignTx):
await multisig.ask(ctx, msg) await multisig.ask(ctx, msg)
common = msg.multisig common = msg.multisig
else: else:
public_key = _get_public_key(node) public_key = seed.remove_ed25519_prefix(node.public_key())
common = msg.transaction common = msg.transaction
if msg.transfer: if msg.transfer:
@ -48,10 +48,15 @@ async def sign_tx(ctx, msg: NEMSignTx):
# wrap transaction in multisig wrapper # wrap transaction in multisig wrapper
if msg.cosigning: if msg.cosigning:
tx = multisig.cosign( tx = multisig.cosign(
_get_public_key(node), msg.transaction, tx, msg.multisig.signer seed.remove_ed25519_prefix(node.public_key()),
msg.transaction,
tx,
msg.multisig.signer,
) )
else: else:
tx = multisig.initiate(_get_public_key(node), msg.transaction, tx) tx = multisig.initiate(
seed.remove_ed25519_prefix(node.public_key()), msg.transaction, tx
)
signature = ed25519.sign(node.private_key(), tx, NEM_HASH_ALG) signature = ed25519.sign(node.private_key(), tx, NEM_HASH_ALG)
@ -59,8 +64,3 @@ async def sign_tx(ctx, msg: NEMSignTx):
resp.data = tx resp.data = tx
resp.signature = signature resp.signature = signature
return resp return resp
def _get_public_key(node) -> bytes:
# 0x01 prefix is not part of the actual public key, hence removed
return node.public_key()[1:]

View File

@ -7,7 +7,7 @@ from trezor.messages.StellarGetAddress import StellarGetAddress
async def get_address(ctx, msg: StellarGetAddress): async def get_address(ctx, msg: StellarGetAddress):
node = await seed.derive_node(ctx, msg.address_n, helpers.STELLAR_CURVE) node = await seed.derive_node(ctx, msg.address_n, helpers.STELLAR_CURVE)
pubkey = seed.remove_ed25519_public_key_prefix(node.public_key()) # todo better? pubkey = seed.remove_ed25519_prefix(node.public_key())
address = helpers.address_from_public_key(pubkey) address = helpers.address_from_public_key(pubkey)
if msg.show_display: if msg.show_display:

View File

@ -12,7 +12,7 @@ from ubinascii import hexlify
async def get_public_key(ctx, msg: StellarGetPublicKey): async def get_public_key(ctx, msg: StellarGetPublicKey):
node = await seed.derive_node(ctx, msg.address_n, helpers.STELLAR_CURVE) node = await seed.derive_node(ctx, msg.address_n, helpers.STELLAR_CURVE)
pubkey = seed.remove_ed25519_public_key_prefix(node.public_key()) # todo better? pubkey = seed.remove_ed25519_prefix(node.public_key())
if msg.show_display: if msg.show_display:
while True: while True:

View File

@ -18,7 +18,7 @@ async def sign_tx(ctx, msg: StellarSignTx):
raise ValueError('Stellar: At least one operation is required') raise ValueError('Stellar: At least one operation is required')
node = await seed.derive_node(ctx, msg.address_n, consts.STELLAR_CURVE) node = await seed.derive_node(ctx, msg.address_n, consts.STELLAR_CURVE)
pubkey = seed.remove_ed25519_public_key_prefix(node.public_key()) pubkey = seed.remove_ed25519_prefix(node.public_key())
w = bytearray() w = bytearray()
await _init(ctx, w, pubkey, msg) await _init(ctx, w, pubkey, msg)