Skip to content

Commit

Permalink
xmr: serialization schemes simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed Oct 2, 2018
1 parent a59dbb8 commit b9a5698
Show file tree
Hide file tree
Showing 11 changed files with 2 additions and 255 deletions.
19 changes: 0 additions & 19 deletions src/apps/monero/xmr/serialize_messages/addr.py

This file was deleted.

2 changes: 0 additions & 2 deletions src/apps/monero/xmr/serialize_messages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,5 @@ class ECKey(BlobType):


ECPoint = Hash
SecretKey = ECKey
ECPublicKey = ECPoint
KeyImage = ECPoint
KeyDerivation = ECPoint
29 changes: 0 additions & 29 deletions src/apps/monero/xmr/serialize_messages/ct_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@
from apps.monero.xmr.serialize_messages.base import ECKey

_c0 = const(0)
_c1 = const(1)
_c32 = const(32)
_c64 = const(64)


class Key64(ContainerType):
FIX_SIZE = _c1
SIZE = _c64
ELEM_TYPE = ECKey


class KeyV(ContainerType):
Expand All @@ -25,29 +16,9 @@ class KeyM(ContainerType):
ELEM_TYPE = KeyV


class KeyVFix(ContainerType):
FIX_SIZE = _c1
ELEM_TYPE = ECKey


class KeyMFix(ContainerType):
FIX_SIZE = _c1
ELEM_TYPE = KeyVFix


class CtKey(MessageType):
__slots__ = ("dest", "mask")

@classmethod
def f_specs(cls):
return (("dest", ECKey), ("mask", ECKey))


class CtkeyV(ContainerType):
FIX_SIZE = 0
ELEM_TYPE = CtKey


class CtkeyM(ContainerType):
FIX_SIZE = 0
ELEM_TYPE = CtkeyV
15 changes: 0 additions & 15 deletions src/apps/monero/xmr/serialize_messages/tx_dest_entry.py

This file was deleted.

11 changes: 1 addition & 10 deletions src/apps/monero/xmr/serialize_messages/tx_ecdh.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
from apps.monero.xmr.serialize.message_types import ContainerType, MessageType
from apps.monero.xmr.serialize_messages.base import ECKey
from apps.monero.xmr.serialize.message_types import MessageType


class EcdhTuple(MessageType):
__slots__ = ("mask", "amount")

@classmethod
def f_specs(cls):
return (("mask", ECKey), ("amount", ECKey))


class EcdhInfo(ContainerType):
ELEM_TYPE = EcdhTuple
4 changes: 0 additions & 4 deletions src/apps/monero/xmr/serialize_messages/tx_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,3 @@ def f_specs(cls):
("tx_extra_nonce", TxExtraNonce),
("tx_extra_additional_pub_keys", TxExtraAdditionalPubKeys),
)


class TxExtraFields(ContainerType):
ELEM_TYPE = TxExtraField
66 changes: 1 addition & 65 deletions src/apps/monero/xmr/serialize_messages/tx_full.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@

from apps.monero.xmr.serialize.base_types import UInt8, UVarintType
from apps.monero.xmr.serialize.erefs import eref
from apps.monero.xmr.serialize.message_types import MessageType
from apps.monero.xmr.serialize_messages.base import ECKey
from apps.monero.xmr.serialize_messages.ct_keys import CtKey, CtkeyM, CtkeyV, KeyM, KeyV
from apps.monero.xmr.serialize_messages.tx_ecdh import EcdhInfo, EcdhTuple
from apps.monero.xmr.serialize_messages.tx_rsig import RctType
from apps.monero.xmr.serialize_messages.ct_keys import KeyM


class MgSig(MessageType):
Expand All @@ -14,62 +9,3 @@ class MgSig(MessageType):
@classmethod
def f_specs(cls):
return (("ss", KeyM), ("cc", ECKey))


class RctSigBase(MessageType):
__slots__ = (
"type",
"txnFee",
"message",
"mixRing",
"pseudoOuts",
"ecdhInfo",
"outPk",
)

@classmethod
def f_specs(cls):
return (
("type", UInt8),
("txnFee", UVarintType),
("message", ECKey),
("mixRing", CtkeyM),
("pseudoOuts", KeyV),
("ecdhInfo", EcdhInfo),
("outPk", CtkeyV),
)

def serialize_rctsig_base(self, ar, inputs, outputs):
self._msg_field(ar, idx=0)
if self.type == RctType.Null:
return
if (
self.type != RctType.Full
and self.type != RctType.FullBulletproof
and self.type != RctType.Simple
and self.type != RctType.SimpleBulletproof
):
raise ValueError("Unknown type")

self._msg_field(ar, idx=1)
if self.type == RctType.Simple:
ar.prepare_container(inputs, eref(self, "pseudoOuts"), KeyV)
if ar.writing and len(self.pseudoOuts) != inputs:
raise ValueError("pseudoOuts size mismatch")

for i in range(inputs):
ar.field(eref(self.pseudoOuts, i), KeyV.ELEM_TYPE)

ar.prepare_container(outputs, eref(self, "ecdhInfo"), EcdhTuple)
if ar.writing and len(self.ecdhInfo) != outputs:
raise ValueError("EcdhInfo size mismatch")

for i in range(outputs):
ar.field(eref(self.ecdhInfo, i), EcdhInfo.ELEM_TYPE)

ar.prepare_container((outputs), eref(self, "outPk"), CtKey)
if ar.writing and len(self.outPk) != outputs:
raise ValueError("outPk size mismatch")

for i in range(outputs):
ar.field(eref(self.outPk[i], "mask"), ECKey)
20 changes: 0 additions & 20 deletions src/apps/monero/xmr/serialize_messages/tx_prefix.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from apps.monero.xmr.serialize.base_types import UInt8, UVarintType
from apps.monero.xmr.serialize.message_types import (
BlobType,
ContainerType,
MessageType,
VariantType,
Expand Down Expand Up @@ -101,22 +100,3 @@ class TxOut(MessageType):
@classmethod
def f_specs(cls):
return (("amount", UVarintType), ("target", TxoutTargetV))


class TransactionPrefix(MessageType):
@classmethod
def f_specs(cls):
return (
("version", UVarintType),
("unlock_time", UVarintType),
("vin", ContainerType, TxInV),
("vout", ContainerType, TxOut),
("extra", ContainerType, UInt8),
)


class TransactionPrefixExtraBlob(TransactionPrefix):
# noinspection PyTypeChecker
@classmethod
def f_specs(cls):
return TransactionPrefix.f_specs()[:-1] + (("extra", BlobType),)
19 changes: 0 additions & 19 deletions src/apps/monero/xmr/serialize_messages/tx_rsig_boro.py

This file was deleted.

36 changes: 0 additions & 36 deletions src/apps/monero/xmr/serialize_messages/tx_sig.py

This file was deleted.

36 changes: 0 additions & 36 deletions src/apps/monero/xmr/serialize_messages/tx_src_entry.py

This file was deleted.

0 comments on commit b9a5698

Please sign in to comment.