1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00

move protobuf to a single module

This commit is contained in:
Jan Pochyla 2016-09-28 18:01:23 +02:00
parent cb1dcc965d
commit fb7b85e479
71 changed files with 69 additions and 387 deletions

View File

@ -116,7 +116,7 @@ class EmbeddedMessage:
return self.message_type() return self.message_type()
def dump(self, target, value): def dump(self, target, value):
buf = self.message_type.dumps(value) buf = yield from self.message_type.dumps(value)
yield from BytesType.dump(target, buf) yield from BytesType.dump(target, buf)
def load(self, target, source): def load(self, target, source):

View File

@ -1,55 +0,0 @@
# Describing messages themselves. ----------------------------------------------
from . import protobuf
class TypeMetadataType:
WIRE_TYPE = 2
def __init__(self):
# Field description.
self.__field_metadata_type = protobuf.MessageType()
self.__field_metadata_type.add_field(1, 'tag', protobuf.UVarintType, flags=protobuf.Flags.REQUIRED)
self.__field_metadata_type.add_field(2, 'name', protobuf.BytesType, flags=protobuf.Flags.REQUIRED)
self.__field_metadata_type.add_field(3, 'type', protobuf.BytesType, flags=protobuf.Flags.REQUIRED)
self.__field_metadata_type.add_field(4, 'flags', protobuf.UVarintType, flags=protobuf.Flags.REQUIRED)
self.__field_metadata_type.add_field(5, 'embedded', protobuf.EmbeddedMessage(self)) # Used to describe embedded messages.
# Metadata message description.
self.__self_type = protobuf.EmbeddedMessage(protobuf.MessageType())
self.__self_type.message_type.add_field(1, 'fields', protobuf.EmbeddedMessage(self.__field_metadata_type), flags=(Flags.REPEATED | Flags.REQUIRED))
def __create_message(self, message_type):
# Creates a message that contains info about the message_type.
message, message.fields = self.__self_type(), list()
for field in iter(message_type):
field_meta = self.__field_metadata_type()
field_meta.tag, field_meta.name, field_type, field_meta.flags = field
field_meta.type = type_str = field_type.__class__.__name__
if isinstance(field_type, protobuf.EmbeddedMessage):
field_meta.flags |= protobuf.Flags.EMBEDDED
field_meta.embedded_metadata = self.__create_message(field_type.message_type)
elif not type_str.endswith('Type'):
raise TypeError('Type name of type singleton object should end with \'Type\'. Actual: \'%s\'.' % type_str)
else:
field_meta.type = type_str[:-4]
message.fields.append(field_meta)
return message
def dump(self, fp, message_type):
self.__self_type.dump(fp, self.__create_message(message_type))
def __restore_type(self, message):
# Restores a message type by the information in the message.
message_type, g = protobuf.MessageType(), globals()
for field in message.fields:
field_type = field['type']
if not field_type in g:
raise TypeError('Primitive type \'%s\' not found in this protobuf module.' % field_type)
field_info = (field.tag, field.name, g[field_type], field.flags)
if field.flags & protobuf.Flags.EMBEDDED_MASK == protobuf.Flags.EMBEDDED:
field_info[3] -= protobuf.Flags.EMBEDDED
field_info[2] = protobuf.EmbeddedMessage(self.__restore_type(field.embedded))
message_type.add_field(*field_info)
return message_type
def load(self, fp):
return self.__restore_type(self.__self_type.load(fp))

View File

@ -1,263 +0,0 @@
# Implements the Google's protobuf encoding.
# eigenein (c) 2011
# http://eigenein.me/protobuf/
from uio import BytesIO
# Types. -----------------------------------------------------------------
class UVarintType:
# Represents an unsigned Varint type.
WIRE_TYPE = 0
@staticmethod
def dump(fp, value):
shifted_value = True
while shifted_value:
shifted_value = value >> 7
fp.write(chr((value & 0x7F) | (0x80 if shifted_value != 0 else 0x00)))
value = shifted_value
@staticmethod
def load(fp):
value, shift, quantum = 0, 0, 0x80
while (quantum & 0x80) == 0x80:
quantum = ord(fp.read(1))
value, shift = value + ((quantum & 0x7F) << shift), shift + 7
return value
class BoolType:
# Represents a boolean type.
# Encodes True as UVarint 1, and False as UVarint 0.
WIRE_TYPE = 0
@staticmethod
def dump(fp, value):
fp.write('\x01' if value else '\x00')
@staticmethod
def load(fp):
return UVarintType.load(fp) != 0
class BytesType:
# Represents a raw bytes type.
WIRE_TYPE = 2
@staticmethod
def dump(fp, value):
UVarintType.dump(fp, len(value))
fp.write(value)
@staticmethod
def load(fp):
return fp.read(UVarintType.load(fp))
class UnicodeType:
# Represents an unicode string type.
WIRE_TYPE = 2
@staticmethod
def dump(fp, value):
BytesType.dump(fp, bytes(value, 'utf-8'))
@staticmethod
def load(fp):
return BytesType.load(fp).decode('utf-8', 'strict')
# Messages. --------------------------------------------------------------
FLAG_SIMPLE = const(0)
FLAG_REQUIRED = const(1)
FLAG_REQUIRED_MASK = const(1)
FLAG_SINGLE = const(0)
FLAG_REPEATED = const(2)
FLAG_REPEATED_MASK = const(6)
class EofWrapper:
# Wraps a stream to raise EOFError instead of just returning of ''.
def __init__(self, fp, limit=None):
self.__fp = fp
self.__limit = limit
def read(self, size=None):
# Reads a string. Raises EOFError on end of stream.
if self.__limit is not None:
size = min(size, self.__limit)
self.__limit -= size
s = self.__fp.read(size)
if len(s) == 0:
raise EOFError()
return s
# Packs a tag and a wire_type into single int according to the protobuf spec.
_pack_key = lambda tag, wire_type: (tag << 3) | wire_type
# Unpacks a key into a tag and a wire_type according to the protobuf spec.
_unpack_key = lambda key: (key >> 3, key & 7)
class MessageType:
# Represents a message type.
def __init__(self, name=None):
# Creates a new message type.
self.__tags_to_types = {} # Maps a tag to a type instance.
self.__tags_to_names = {} # Maps a tag to a given field name.
self.__defaults = {} # Maps a tag to its default value.
self.__flags = {} # Maps a tag to FLAG_
self.__name = name
def add_field(self, tag, name, field_type, flags=FLAG_SIMPLE, default=None):
# Adds a field to the message type.
if tag in self.__tags_to_names or tag in self.__tags_to_types:
raise ValueError('The tag %s is already used.' % tag)
if default != None:
self.__defaults[tag] = default
self.__tags_to_names[tag] = name
self.__tags_to_types[tag] = field_type
self.__flags[tag] = flags
return self # Allow add_field chaining.
def __call__(self, **fields):
# Creates an instance of this message type.
return Message(self, **fields)
def __has_flag(self, tag, flag, mask):
# Checks whether the field with the specified tag has the specified
# flag.
return (self.__flags[tag] & mask) == flag
def dump(self, fp, value):
if self != value.message_type:
raise TypeError("Incompatible type")
for tag, field_type in iter(self.__tags_to_types.items()):
if self.__tags_to_names[tag] in value.__dict__:
if self.__has_flag(tag, FLAG_SINGLE, FLAG_REPEATED_MASK):
# Single value.
UVarintType.dump(fp, _pack_key(tag, field_type.WIRE_TYPE))
field_type.dump(fp, getattr(
value, self.__tags_to_names[tag]))
elif self.__has_flag(tag, FLAG_REPEATED, FLAG_REPEATED_MASK):
# Repeated value.
key = _pack_key(tag, field_type.WIRE_TYPE)
# Put it together sequently.
for single_value in getattr(value, self.__tags_to_names[tag]):
UVarintType.dump(fp, key)
field_type.dump(fp, single_value)
elif self.__has_flag(tag, FLAG_REQUIRED, FLAG_REQUIRED_MASK):
raise ValueError(
'The field with the tag %s is required but a value is missing.' % tag)
def load(self, fp):
fp = EofWrapper(fp)
message = self.__call__()
while True:
try:
tag, wire_type = _unpack_key(UVarintType.load(fp))
if tag in self.__tags_to_types:
field_type = self.__tags_to_types[tag]
field_name = self.__tags_to_names[tag]
if wire_type != field_type.WIRE_TYPE:
raise TypeError(
'Value of tag %s has incorrect wiretype %s, %s expected.' %
(tag, wire_type, field_type.WIRE_TYPE))
if self.__has_flag(tag, FLAG_SINGLE, FLAG_REPEATED_MASK):
# Single value.
setattr(message, field_name, field_type.load(fp))
elif self.__has_flag(tag, FLAG_REPEATED, FLAG_REPEATED_MASK):
# Repeated value.
if not field_name in message.__dict__:
setattr(message, field_name, [])
getattr(message, field_name).append(
field_type.load(fp))
else:
# Skip this field.
# This used to correctly determine the length of unknown
# tags when loading a message.
{0: UVarintType, 2: BytesType}[wire_type].load(fp)
except EOFError:
for tag, name in iter(self.__tags_to_names.items()):
# Fill in default value if value not set
if name not in message.__dict__ and tag in self.__defaults:
setattr(message, name, self.__defaults[tag])
# Check if all required fields are present.
if self.__has_flag(tag, FLAG_REQUIRED, FLAG_REQUIRED_MASK) and not name in message.__dict__:
if self.__has_flag(tag, FLAG_REPEATED, FLAG_REPEATED_MASK):
# Empty list (no values was in input stream). But
# required field.
setattr(message, name, [])
else:
raise ValueError(
'The field %s (\'%s\') is required but missing.' % (tag, name))
return message
def dumps(self, value):
fp = BytesIO()
self.dump(fp, value)
return fp.getvalue()
def loads(self, buf):
fp = BytesIO(buf)
return self.load(fp)
def __repr__(self):
return '<MessageType: %s>' % self.__name
class Message:
# Represents a message instance.
def __init__(self, message_type, **fields):
# Initializes a new instance of the specified message type.
self.message_type = message_type
# In micropython, we cannot use self.__dict__.update(fields),
# iterate fields and assign them directly.
for key in fields:
setattr(self, key, fields[key])
def dump(self, fp):
# Dumps the message into a write-like object.
return self.message_type.dump(fp, self)
def dumps(self):
# Dumps the message into bytes
return self.message_type.dumps(self)
def __repr__(self):
values = self.__dict__
values = {k: values[k] for k in values if k != 'message_type'}
return '<%s: %s>' % (self.message_type.__name, values)
# Embedded message. ------------------------------------------------------
class EmbeddedMessage:
# Represents an embedded message type.
WIRE_TYPE = 2
def __init__(self, message_type):
# Initializes a new instance. The argument is an underlying message
# type.
self.message_type = message_type
def __call__(self):
# Creates a message of the underlying message type.
return self.message_type()
def dump(self, fp, value):
BytesType.dump(fp, self.message_type.dumps(value))
def load(self, fp):
return self.message_type.load(EofWrapper(fp, UVarintType.load(fp)))

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('Address') t = p.MessageType('Address')
t.wire_type = 30 t.wire_type = 30
t.add_field(1, 'address', p.UnicodeType, flags=p.FLAG_REQUIRED) t.add_field(1, 'address', p.UnicodeType, flags=p.FLAG_REQUIRED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('ApplySettings') t = p.MessageType('ApplySettings')
t.wire_type = 25 t.wire_type = 25
t.add_field(1, 'language', p.UnicodeType) t.add_field(1, 'language', p.UnicodeType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('ButtonAck') t = p.MessageType('ButtonAck')
t.wire_type = 27 t.wire_type = 27
ButtonAck = t ButtonAck = t

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('ButtonRequest') t = p.MessageType('ButtonRequest')
t.wire_type = 26 t.wire_type = 26
t.add_field(1, 'code', p.UVarintType) t.add_field(1, 'code', p.UVarintType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('Cancel') t = p.MessageType('Cancel')
t.wire_type = 20 t.wire_type = 20
Cancel = t Cancel = t

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('ChangePin') t = p.MessageType('ChangePin')
t.wire_type = 4 t.wire_type = 4
t.add_field(1, 'remove', p.BoolType) t.add_field(1, 'remove', p.BoolType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('CipherKeyValue') t = p.MessageType('CipherKeyValue')
t.wire_type = 23 t.wire_type = 23
t.add_field(1, 'address_n', p.UVarintType, flags=p.FLAG_REPEATED) t.add_field(1, 'address_n', p.UVarintType, flags=p.FLAG_REPEATED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('CipheredKeyValue') t = p.MessageType('CipheredKeyValue')
t.wire_type = 48 t.wire_type = 48
t.add_field(1, 'value', p.BytesType) t.add_field(1, 'value', p.BytesType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('ClearSession') t = p.MessageType('ClearSession')
t.wire_type = 24 t.wire_type = 24
ClearSession = t ClearSession = t

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('CoinType') t = p.MessageType('CoinType')
t.add_field(1, 'coin_name', p.UnicodeType) t.add_field(1, 'coin_name', p.UnicodeType)
t.add_field(2, 'coin_shortcut', p.UnicodeType) t.add_field(2, 'coin_shortcut', p.UnicodeType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('DebugLinkDecision') t = p.MessageType('DebugLinkDecision')
t.wire_type = 100 t.wire_type = 100
t.add_field(1, 'yes_no', p.BoolType, flags=p.FLAG_REQUIRED) t.add_field(1, 'yes_no', p.BoolType, flags=p.FLAG_REQUIRED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('DebugLinkGetState') t = p.MessageType('DebugLinkGetState')
t.wire_type = 101 t.wire_type = 101
DebugLinkGetState = t DebugLinkGetState = t

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('DebugLinkLog') t = p.MessageType('DebugLinkLog')
t.wire_type = 104 t.wire_type = 104
t.add_field(1, 'level', p.UVarintType) t.add_field(1, 'level', p.UVarintType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
from .HDNodeType import HDNodeType from .HDNodeType import HDNodeType
t = p.MessageType('DebugLinkState') t = p.MessageType('DebugLinkState')
t.wire_type = 102 t.wire_type = 102

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('DebugLinkStop') t = p.MessageType('DebugLinkStop')
t.wire_type = 103 t.wire_type = 103
DebugLinkStop = t DebugLinkStop = t

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('DecryptMessage') t = p.MessageType('DecryptMessage')
t.wire_type = 51 t.wire_type = 51
t.add_field(1, 'address_n', p.UVarintType, flags=p.FLAG_REPEATED) t.add_field(1, 'address_n', p.UVarintType, flags=p.FLAG_REPEATED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('DecryptedMessage') t = p.MessageType('DecryptedMessage')
t.wire_type = 52 t.wire_type = 52
t.add_field(1, 'message', p.BytesType) t.add_field(1, 'message', p.BytesType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('EncryptMessage') t = p.MessageType('EncryptMessage')
t.wire_type = 49 t.wire_type = 49
t.add_field(1, 'pubkey', p.BytesType) t.add_field(1, 'pubkey', p.BytesType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('EncryptedMessage') t = p.MessageType('EncryptedMessage')
t.wire_type = 50 t.wire_type = 50
t.add_field(1, 'nonce', p.BytesType) t.add_field(1, 'nonce', p.BytesType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('Entropy') t = p.MessageType('Entropy')
t.wire_type = 10 t.wire_type = 10
t.add_field(1, 'entropy', p.BytesType, flags=p.FLAG_REQUIRED) t.add_field(1, 'entropy', p.BytesType, flags=p.FLAG_REQUIRED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('EntropyAck') t = p.MessageType('EntropyAck')
t.wire_type = 36 t.wire_type = 36
t.add_field(1, 'entropy', p.BytesType) t.add_field(1, 'entropy', p.BytesType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('EntropyRequest') t = p.MessageType('EntropyRequest')
t.wire_type = 35 t.wire_type = 35
EntropyRequest = t EntropyRequest = t

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('EstimateTxSize') t = p.MessageType('EstimateTxSize')
t.wire_type = 43 t.wire_type = 43
t.add_field(1, 'outputs_count', p.UVarintType, flags=p.FLAG_REQUIRED) t.add_field(1, 'outputs_count', p.UVarintType, flags=p.FLAG_REQUIRED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('Failure') t = p.MessageType('Failure')
t.wire_type = 3 t.wire_type = 3
t.add_field(1, 'code', p.UVarintType) t.add_field(1, 'code', p.UVarintType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
from .CoinType import CoinType from .CoinType import CoinType
t = p.MessageType('Features') t = p.MessageType('Features')
t.wire_type = 17 t.wire_type = 17

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('FirmwareErase') t = p.MessageType('FirmwareErase')
t.wire_type = 6 t.wire_type = 6
FirmwareErase = t FirmwareErase = t

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('FirmwareUpload') t = p.MessageType('FirmwareUpload')
t.wire_type = 7 t.wire_type = 7
t.add_field(1, 'payload', p.BytesType, flags=p.FLAG_REQUIRED) t.add_field(1, 'payload', p.BytesType, flags=p.FLAG_REQUIRED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
from .MultisigRedeemScriptType import MultisigRedeemScriptType from .MultisigRedeemScriptType import MultisigRedeemScriptType
t = p.MessageType('GetAddress') t = p.MessageType('GetAddress')
t.wire_type = 29 t.wire_type = 29

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('GetEntropy') t = p.MessageType('GetEntropy')
t.wire_type = 9 t.wire_type = 9
t.add_field(1, 'size', p.UVarintType, flags=p.FLAG_REQUIRED) t.add_field(1, 'size', p.UVarintType, flags=p.FLAG_REQUIRED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('GetFeatures') t = p.MessageType('GetFeatures')
t.wire_type = 55 t.wire_type = 55
GetFeatures = t GetFeatures = t

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('GetPublicKey') t = p.MessageType('GetPublicKey')
t.wire_type = 11 t.wire_type = 11
t.add_field(1, 'address_n', p.UVarintType, flags=p.FLAG_REPEATED) t.add_field(1, 'address_n', p.UVarintType, flags=p.FLAG_REPEATED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
from .HDNodeType import HDNodeType from .HDNodeType import HDNodeType
t = p.MessageType('HDNodePathType') t = p.MessageType('HDNodePathType')
t.add_field(1, 'node', p.EmbeddedMessage(HDNodeType), flags=p.FLAG_REQUIRED) t.add_field(1, 'node', p.EmbeddedMessage(HDNodeType), flags=p.FLAG_REQUIRED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('HDNodeType') t = p.MessageType('HDNodeType')
t.add_field(1, 'depth', p.UVarintType, flags=p.FLAG_REQUIRED) t.add_field(1, 'depth', p.UVarintType, flags=p.FLAG_REQUIRED)
t.add_field(2, 'fingerprint', p.UVarintType, flags=p.FLAG_REQUIRED) t.add_field(2, 'fingerprint', p.UVarintType, flags=p.FLAG_REQUIRED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('IdentityType') t = p.MessageType('IdentityType')
t.add_field(1, 'proto', p.UnicodeType) t.add_field(1, 'proto', p.UnicodeType)
t.add_field(2, 'user', p.UnicodeType) t.add_field(2, 'user', p.UnicodeType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('Initialize') t = p.MessageType('Initialize')
t.wire_type = 0 t.wire_type = 0
Initialize = t Initialize = t

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
from .HDNodeType import HDNodeType from .HDNodeType import HDNodeType
t = p.MessageType('LoadDevice') t = p.MessageType('LoadDevice')
t.wire_type = 13 t.wire_type = 13

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('MessageSignature') t = p.MessageType('MessageSignature')
t.wire_type = 40 t.wire_type = 40
t.add_field(1, 'address', p.UnicodeType) t.add_field(1, 'address', p.UnicodeType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
from .HDNodePathType import HDNodePathType from .HDNodePathType import HDNodePathType
t = p.MessageType('MultisigRedeemScriptType') t = p.MessageType('MultisigRedeemScriptType')
t.add_field(1, 'pubkeys', p.EmbeddedMessage(HDNodePathType), flags=p.FLAG_REPEATED) t.add_field(1, 'pubkeys', p.EmbeddedMessage(HDNodePathType), flags=p.FLAG_REPEATED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('PassphraseAck') t = p.MessageType('PassphraseAck')
t.wire_type = 42 t.wire_type = 42
t.add_field(1, 'passphrase', p.UnicodeType, flags=p.FLAG_REQUIRED) t.add_field(1, 'passphrase', p.UnicodeType, flags=p.FLAG_REQUIRED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('PassphraseRequest') t = p.MessageType('PassphraseRequest')
t.wire_type = 41 t.wire_type = 41
PassphraseRequest = t PassphraseRequest = t

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('PinMatrixAck') t = p.MessageType('PinMatrixAck')
t.wire_type = 19 t.wire_type = 19
t.add_field(1, 'pin', p.UnicodeType, flags=p.FLAG_REQUIRED) t.add_field(1, 'pin', p.UnicodeType, flags=p.FLAG_REQUIRED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('PinMatrixRequest') t = p.MessageType('PinMatrixRequest')
t.wire_type = 18 t.wire_type = 18
t.add_field(1, 'type', p.UVarintType) t.add_field(1, 'type', p.UVarintType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('Ping') t = p.MessageType('Ping')
t.wire_type = 1 t.wire_type = 1
t.add_field(1, 'message', p.UnicodeType) t.add_field(1, 'message', p.UnicodeType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
from .HDNodeType import HDNodeType from .HDNodeType import HDNodeType
t = p.MessageType('PublicKey') t = p.MessageType('PublicKey')
t.wire_type = 12 t.wire_type = 12

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('RecoveryDevice') t = p.MessageType('RecoveryDevice')
t.wire_type = 45 t.wire_type = 45
t.add_field(1, 'word_count', p.UVarintType) t.add_field(1, 'word_count', p.UVarintType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('ResetDevice') t = p.MessageType('ResetDevice')
t.wire_type = 14 t.wire_type = 14
t.add_field(1, 'display_random', p.BoolType) t.add_field(1, 'display_random', p.BoolType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
from .IdentityType import IdentityType from .IdentityType import IdentityType
t = p.MessageType('SignIdentity') t = p.MessageType('SignIdentity')
t.wire_type = 53 t.wire_type = 53

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('SignMessage') t = p.MessageType('SignMessage')
t.wire_type = 38 t.wire_type = 38
t.add_field(1, 'address_n', p.UVarintType, flags=p.FLAG_REPEATED) t.add_field(1, 'address_n', p.UVarintType, flags=p.FLAG_REPEATED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('SignTx') t = p.MessageType('SignTx')
t.wire_type = 15 t.wire_type = 15
t.add_field(1, 'outputs_count', p.UVarintType, flags=p.FLAG_REQUIRED) t.add_field(1, 'outputs_count', p.UVarintType, flags=p.FLAG_REQUIRED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('SignedIdentity') t = p.MessageType('SignedIdentity')
t.wire_type = 54 t.wire_type = 54
t.add_field(1, 'address', p.UnicodeType) t.add_field(1, 'address', p.UnicodeType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
from .TxInputType import TxInputType from .TxInputType import TxInputType
from .TxOutputType import TxOutputType from .TxOutputType import TxOutputType
from .TransactionType import TransactionType from .TransactionType import TransactionType

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
from .HDNodeType import HDNodeType from .HDNodeType import HDNodeType
t = p.MessageType('Storage') t = p.MessageType('Storage')
t.add_field(1, 'version', p.UVarintType, flags=p.FLAG_REQUIRED) t.add_field(1, 'version', p.UVarintType, flags=p.FLAG_REQUIRED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('Success') t = p.MessageType('Success')
t.wire_type = 2 t.wire_type = 2
t.add_field(1, 'message', p.UnicodeType) t.add_field(1, 'message', p.UnicodeType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
from .TxInputType import TxInputType from .TxInputType import TxInputType
from .TxOutputBinType import TxOutputBinType from .TxOutputBinType import TxOutputBinType
from .TxOutputType import TxOutputType from .TxOutputType import TxOutputType

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
from .TransactionType import TransactionType from .TransactionType import TransactionType
t = p.MessageType('TxAck') t = p.MessageType('TxAck')
t.wire_type = 22 t.wire_type = 22

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
from .MultisigRedeemScriptType import MultisigRedeemScriptType from .MultisigRedeemScriptType import MultisigRedeemScriptType
t = p.MessageType('TxInputType') t = p.MessageType('TxInputType')
t.add_field(1, 'address_n', p.UVarintType, flags=p.FLAG_REPEATED) t.add_field(1, 'address_n', p.UVarintType, flags=p.FLAG_REPEATED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('TxOutputBinType') t = p.MessageType('TxOutputBinType')
t.add_field(1, 'amount', p.UVarintType, flags=p.FLAG_REQUIRED) t.add_field(1, 'amount', p.UVarintType, flags=p.FLAG_REQUIRED)
t.add_field(2, 'script_pubkey', p.BytesType, flags=p.FLAG_REQUIRED) t.add_field(2, 'script_pubkey', p.BytesType, flags=p.FLAG_REQUIRED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
from .MultisigRedeemScriptType import MultisigRedeemScriptType from .MultisigRedeemScriptType import MultisigRedeemScriptType
t = p.MessageType('TxOutputType') t = p.MessageType('TxOutputType')
t.add_field(1, 'address', p.UnicodeType) t.add_field(1, 'address', p.UnicodeType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
from .TxRequestDetailsType import TxRequestDetailsType from .TxRequestDetailsType import TxRequestDetailsType
from .TxRequestSerializedType import TxRequestSerializedType from .TxRequestSerializedType import TxRequestSerializedType
t = p.MessageType('TxRequest') t = p.MessageType('TxRequest')

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('TxRequestDetailsType') t = p.MessageType('TxRequestDetailsType')
t.add_field(1, 'request_index', p.UVarintType) t.add_field(1, 'request_index', p.UVarintType)
t.add_field(2, 'tx_hash', p.BytesType) t.add_field(2, 'tx_hash', p.BytesType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('TxRequestSerializedType') t = p.MessageType('TxRequestSerializedType')
t.add_field(1, 'signature_index', p.UVarintType) t.add_field(1, 'signature_index', p.UVarintType)
t.add_field(2, 'signature', p.BytesType) t.add_field(2, 'signature', p.BytesType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('TxSize') t = p.MessageType('TxSize')
t.wire_type = 44 t.wire_type = 44
t.add_field(1, 'tx_size', p.UVarintType) t.add_field(1, 'tx_size', p.UVarintType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('VerifyMessage') t = p.MessageType('VerifyMessage')
t.wire_type = 39 t.wire_type = 39
t.add_field(1, 'address', p.UnicodeType) t.add_field(1, 'address', p.UnicodeType)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('WipeDevice') t = p.MessageType('WipeDevice')
t.wire_type = 5 t.wire_type = 5
WipeDevice = t WipeDevice = t

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('WordAck') t = p.MessageType('WordAck')
t.wire_type = 47 t.wire_type = 47
t.add_field(1, 'word', p.UnicodeType, flags=p.FLAG_REQUIRED) t.add_field(1, 'word', p.UnicodeType, flags=p.FLAG_REQUIRED)

View File

@ -1,5 +1,5 @@
# Automatically generated by pb2py # Automatically generated by pb2py
from protobuf import protobuf as p import protobuf as p
t = p.MessageType('WordRequest') t = p.MessageType('WordRequest')
t.wire_type = 46 t.wire_type = 46
WordRequest = t WordRequest = t

View File

@ -1,4 +1,4 @@
from protobuf.protobuf import build_protobuf_message from protobuf import build_protobuf_message
from trezor.loop import schedule_task, Future from trezor.loop import schedule_task, Future
from trezor.crypto import random from trezor.crypto import random

View File

@ -7,7 +7,7 @@ from google.protobuf.internal.enum_type_wrapper import EnumTypeWrapper
def process_type(t, cls, msg_id, indexfile): def process_type(t, cls, msg_id, indexfile):
imports = ["from protobuf import protobuf as p", ] imports = ["import protobuf as p", ]
out = ["t = p.MessageType('%s')" % t, ] out = ["t = p.MessageType('%s')" % t, ]