diff --git a/src/apps/monero/protocol/signing/step_07_all_out1_set.py b/src/apps/monero/protocol/signing/step_07_all_out1_set.py index b5d5b180a..437bbfbb6 100644 --- a/src/apps/monero/protocol/signing/step_07_all_out1_set.py +++ b/src/apps/monero/protocol/signing/step_07_all_out1_set.py @@ -93,11 +93,9 @@ def _set_tx_extra(state: State): state.tx.extra = tsx_helper.add_tx_pub_key_to_extra(state.tx.extra, state.tx_pub) - # Not needed to remove - extra is clean - # state.tx.extra = await monero.remove_field_from_tx_extra(state.tx.extra, xmrtypes.TxExtraAdditionalPubKeys) if state.need_additional_txkeys: state.tx.extra = tsx_helper.add_additional_tx_pub_keys_to_extra( - state.tx.extra, pub_enc=state.additional_tx_public_keys + state.tx.extra, state.additional_tx_public_keys ) diff --git a/src/apps/monero/xmr/serialize_messages/tx_extra.py b/src/apps/monero/xmr/serialize_messages/tx_extra.py deleted file mode 100644 index ac438d608..000000000 --- a/src/apps/monero/xmr/serialize_messages/tx_extra.py +++ /dev/null @@ -1,35 +0,0 @@ - -from apps.monero.xmr.serialize.message_types import ( - BlobType, - ContainerType, - MessageType, - VariantType, -) -from apps.monero.xmr.serialize_messages.base import ECPublicKey - - -class TxExtraNonce(MessageType): - __slots__ = ("nonce",) - VARIANT_CODE = 0x2 - - @classmethod - def f_specs(cls): - return (("nonce", BlobType),) - - -class TxExtraAdditionalPubKeys(MessageType): - __slots__ = ("data",) - VARIANT_CODE = 0x4 - - @classmethod - def f_specs(cls): - return (("data", ContainerType, ECPublicKey),) - - -class TxExtraField(VariantType): - @classmethod - def f_specs(cls): - return ( - ("tx_extra_nonce", TxExtraNonce), - ("tx_extra_additional_pub_keys", TxExtraAdditionalPubKeys), - ) diff --git a/src/apps/monero/xmr/sub/tsx_helper.py b/src/apps/monero/xmr/sub/tsx_helper.py index a0152749f..f8c7b8d54 100644 --- a/src/apps/monero/xmr/sub/tsx_helper.py +++ b/src/apps/monero/xmr/sub/tsx_helper.py @@ -1,10 +1,5 @@ from apps.monero.xmr import crypto -from apps.monero.xmr.serialize import xmrserialize -from apps.monero.xmr.serialize.readwriter import MemoryReaderWriter -from apps.monero.xmr.serialize_messages.tx_extra import ( - TxExtraAdditionalPubKeys, - TxExtraField, -) +from apps.monero.xmr.serialize import int_serialize def absolute_output_offsets_to_relative(off): @@ -25,27 +20,27 @@ def add_tx_pub_key_to_extra(tx_extra, pub_key): Adds public key to the extra """ to_add = bytearray(33) - to_add[0] = 1 - crypto.encodepoint_into(memoryview(to_add)[1:], pub_key) # TX_EXTRA_TAG_PUBKEY + to_add[0] = 1 # TX_EXTRA_TAG_PUBKEY + crypto.encodepoint_into(memoryview(to_add)[1:], pub_key) return tx_extra + to_add -def add_additional_tx_pub_keys_to_extra( - tx_extra, additional_pub_keys=None, pub_enc=None -): +def add_additional_tx_pub_keys_to_extra(tx_extra, pub_enc): """ - Adds all pubkeys to the extra + Adds all additional tx public keys to the extra buffer """ - pubs_msg = TxExtraAdditionalPubKeys( - data=pub_enc - if pub_enc - else [crypto.encodepoint(x) for x in additional_pub_keys] - ) + # format: variant_tag (0x4) | array len varint | 32B | 32B | ... + num_keys = len(pub_enc) + len_size = int_serialize.uvarint_size(num_keys) + buffer = bytearray(1 + len_size + 32 * num_keys) - rw = MemoryReaderWriter() - ar = xmrserialize.Archive(rw, True) + buffer[0] = 0x4 # TX_EXTRA_TAG_ADDITIONAL_PUBKEYS + int_serialize.dump_uvarint_b_into(num_keys, buffer, 1) # uvarint(num_keys) + offset = 1 + len_size - # format: variant_tag (0x4) | array len varint | 32B | 32B | ... - ar.variant(pubs_msg, TxExtraField) - tx_extra += rw.get_buffer() + for idx in range(num_keys): + buffer[offset : offset + 32] = pub_enc[idx] + offset += 32 + + tx_extra += buffer return tx_extra