From 5f0bf64bfa0685ca63070ba79283478f6bb3fe7b Mon Sep 17 00:00:00 2001 From: slush Date: Thu, 24 Jan 2013 21:19:54 +0100 Subject: [PATCH] Messages TxInput and TxOutput refactored to TxRequest --- bitkeylib/bitkey_pb2.py | 120 +++++++++++++++++++++------------------- bitkeylib/mapping.py | 4 +- protobuf/bitkey.proto | 35 ++++++------ 3 files changed, 83 insertions(+), 76 deletions(-) diff --git a/bitkeylib/bitkey_pb2.py b/bitkeylib/bitkey_pb2.py index 6fe3f227f0..a998fcb0c6 100644 --- a/bitkeylib/bitkey_pb2.py +++ b/bitkeylib/bitkey_pb2.py @@ -11,7 +11,7 @@ from google.protobuf import descriptor_pb2 DESCRIPTOR = descriptor.FileDescriptor( name='bitkey.proto', package='', - serialized_pb='\n\x0c\x62itkey.proto\" \n\nInitialize\x12\x12\n\nsession_id\x18\x01 \x02(\x0c\"\xc4\x01\n\x08\x46\x65\x61tures\x12\x12\n\nsession_id\x18\x01 \x02(\x0c\x12\x0e\n\x06vendor\x18\x02 \x01(\t\x12\x15\n\rmajor_version\x18\x03 \x01(\r\x12\x15\n\rminor_version\x18\x04 \x01(\r\x12\x0b\n\x03otp\x18\x05 \x01(\x08\x12\x0b\n\x03pin\x18\x06 \x01(\x08\x12\x0b\n\x03spv\x18\x07 \x01(\x08\x12\x11\n\tmaxfee_kb\x18\x08 \x01(\x04\x12\x18\n\x04\x61lgo\x18\t \x03(\x0e\x32\n.Algorithm\x12\x12\n\ndebug_link\x18\n \x01(\x08\"\x17\n\x04Ping\x12\x0f\n\x07message\x18\x01 \x01(\t\"#\n\x11\x44\x65\x62ugLinkDecision\x12\x0e\n\x06yes_no\x18\x01 \x02(\x08\"K\n\x11\x44\x65\x62ugLinkGetState\x12\x0e\n\x06layout\x18\x01 \x01(\x08\x12\x0b\n\x03otp\x18\x02 \x01(\x08\x12\x0b\n\x03pin\x18\x03 \x01(\x08\x12\x0c\n\x04seed\x18\x04 \x01(\x08\"Z\n\x0e\x44\x65\x62ugLinkState\x12\x0e\n\x06layout\x18\x01 \x01(\x0c\x12\x14\n\x03otp\x18\x02 \x01(\x0b\x32\x07.OtpAck\x12\x14\n\x03pin\x18\x03 \x01(\x0b\x32\x07.PinAck\x12\x0c\n\x04seed\x18\x04 \x01(\t\"\x1a\n\x07Success\x12\x0f\n\x07message\x18\x01 \x01(\t\"(\n\x07\x46\x61ilure\x12\x0c\n\x04\x63ode\x18\x01 \x01(\x05\x12\x0f\n\x07message\x18\x02 \x01(\t\"\t\n\x07GetUUID\"\x14\n\x04UUID\x12\x0c\n\x04UUID\x18\x01 \x02(\x0c\"\x0f\n\rButtonRequest\"\x0b\n\tButtonAck\"\x0e\n\x0c\x42uttonCancel\"\x1d\n\nOtpRequest\x12\x0f\n\x07message\x18\x01 \x01(\t\"\x15\n\x06OtpAck\x12\x0b\n\x03otp\x18\x01 \x02(\t\"\x0b\n\tOtpCancel\"\x1d\n\nPinRequest\x12\x0f\n\x07message\x18\x01 \x01(\t\"\x15\n\x06PinAck\x12\x0b\n\x03pin\x18\x01 \x02(\t\"\x0b\n\tPinCancel\"\x1a\n\nGetEntropy\x12\x0c\n\x04size\x18\x01 \x02(\r\"\x1a\n\x07\x45ntropy\x12\x0f\n\x07\x65ntropy\x18\x01 \x02(\x0c\" \n\x0bSetMaxFeeKb\x12\x11\n\tmaxfee_kb\x18\x01 \x02(\x04\"5\n\x12GetMasterPublicKey\x12\x1f\n\x04\x61lgo\x18\x01 \x02(\x0e\x32\n.Algorithm:\x05\x42IP32\"\x1e\n\x0fMasterPublicKey\x12\x0b\n\x03key\x18\x01 \x02(\x0c\"@\n\nGetAddress\x12\x1f\n\x04\x61lgo\x18\x01 \x02(\x0e\x32\n.Algorithm:\x05\x42IP32\x12\x11\n\taddress_n\x18\x02 \x03(\r\"\x1a\n\x07\x41\x64\x64ress\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x02(\t\"M\n\nLoadDevice\x12\x0c\n\x04seed\x18\x01 \x02(\t\x12\x11\n\x03otp\x18\x02 \x01(\x08:\x04true\x12\x0b\n\x03pin\x18\x03 \x01(\t\x12\x11\n\x03spv\x18\x04 \x01(\x08:\x04true\"\x1d\n\x0bResetDevice\x12\x0e\n\x06random\x18\x07 \x01(\x0c\"f\n\x06SignTx\x12\x1f\n\x04\x61lgo\x18\x01 \x02(\x0e\x32\n.Algorithm:\x05\x42IP32\x12\x15\n\routputs_count\x18\x03 \x02(\r\x12\x14\n\x0cinputs_count\x18\x05 \x02(\r\x12\x0e\n\x06random\x18\x06 \x01(\x0c\"N\n\x0cInputRequest\x12\x15\n\rrequest_index\x18\x01 \x01(\x05\x12\x14\n\x0csigned_index\x18\x02 \x01(\x05\x12\x11\n\tsignature\x18\x03 \x01(\x0c\"&\n\rOutputRequest\x12\x15\n\rrequest_index\x18\x01 \x02(\r\"v\n\x07TxInput\x12\r\n\x05index\x18\x01 \x02(\r\x12\x11\n\taddress_n\x18\x02 \x03(\r\x12\x0e\n\x06\x61mount\x18\x03 \x02(\x04\x12\x11\n\tprev_hash\x18\x04 \x02(\x0c\x12\x12\n\nprev_index\x18\x05 \x02(\r\x12\x12\n\nscript_sig\x18\x06 \x01(\x0c\"\x84\x01\n\x08TxOutput\x12\r\n\x05index\x18\x01 \x02(\r\x12\x0f\n\x07\x61\x64\x64ress\x18\x02 \x02(\t\x12\x11\n\taddress_n\x18\x03 \x03(\r\x12\x0e\n\x06\x61mount\x18\x04 \x02(\x04\x12 \n\x0bscript_type\x18\x05 \x02(\x0e\x32\x0b.ScriptType\x12\x13\n\x0bscript_args\x18\x06 \x03(\x0c*$\n\tAlgorithm\x12\t\n\x05\x42IP32\x10\x00\x12\x0c\n\x08\x45LECTRUM\x10\x01*3\n\nScriptType\x12\x10\n\x0cPAYTOADDRESS\x10\x00\x12\x13\n\x0fPAYTOSCRIPTHASH\x10\x01') + serialized_pb='\n\x0c\x62itkey.proto\" \n\nInitialize\x12\x12\n\nsession_id\x18\x01 \x02(\x0c\"\xc4\x01\n\x08\x46\x65\x61tures\x12\x12\n\nsession_id\x18\x01 \x02(\x0c\x12\x0e\n\x06vendor\x18\x02 \x01(\t\x12\x15\n\rmajor_version\x18\x03 \x01(\r\x12\x15\n\rminor_version\x18\x04 \x01(\r\x12\x0b\n\x03otp\x18\x05 \x01(\x08\x12\x0b\n\x03pin\x18\x06 \x01(\x08\x12\x0b\n\x03spv\x18\x07 \x01(\x08\x12\x11\n\tmaxfee_kb\x18\x08 \x01(\x04\x12\x18\n\x04\x61lgo\x18\t \x03(\x0e\x32\n.Algorithm\x12\x12\n\ndebug_link\x18\n \x01(\x08\"\x17\n\x04Ping\x12\x0f\n\x07message\x18\x01 \x01(\t\"#\n\x11\x44\x65\x62ugLinkDecision\x12\x0e\n\x06yes_no\x18\x01 \x02(\x08\"K\n\x11\x44\x65\x62ugLinkGetState\x12\x0e\n\x06layout\x18\x01 \x01(\x08\x12\x0b\n\x03otp\x18\x02 \x01(\x08\x12\x0b\n\x03pin\x18\x03 \x01(\x08\x12\x0c\n\x04seed\x18\x04 \x01(\x08\"Z\n\x0e\x44\x65\x62ugLinkState\x12\x0e\n\x06layout\x18\x01 \x01(\x0c\x12\x14\n\x03otp\x18\x02 \x01(\x0b\x32\x07.OtpAck\x12\x14\n\x03pin\x18\x03 \x01(\x0b\x32\x07.PinAck\x12\x0c\n\x04seed\x18\x04 \x01(\t\"\x1a\n\x07Success\x12\x0f\n\x07message\x18\x01 \x01(\t\"(\n\x07\x46\x61ilure\x12\x0c\n\x04\x63ode\x18\x01 \x01(\x05\x12\x0f\n\x07message\x18\x02 \x01(\t\"\t\n\x07GetUUID\"\x14\n\x04UUID\x12\x0c\n\x04UUID\x18\x01 \x02(\x0c\"\x0f\n\rButtonRequest\"\x0b\n\tButtonAck\"\x0e\n\x0c\x42uttonCancel\"\x1d\n\nOtpRequest\x12\x0f\n\x07message\x18\x01 \x01(\t\"\x15\n\x06OtpAck\x12\x0b\n\x03otp\x18\x01 \x02(\t\"\x0b\n\tOtpCancel\"\x1d\n\nPinRequest\x12\x0f\n\x07message\x18\x01 \x01(\t\"\x15\n\x06PinAck\x12\x0b\n\x03pin\x18\x01 \x02(\t\"\x0b\n\tPinCancel\"\x1a\n\nGetEntropy\x12\x0c\n\x04size\x18\x01 \x02(\r\"\x1a\n\x07\x45ntropy\x12\x0f\n\x07\x65ntropy\x18\x01 \x02(\x0c\" \n\x0bSetMaxFeeKb\x12\x11\n\tmaxfee_kb\x18\x01 \x02(\x04\"5\n\x12GetMasterPublicKey\x12\x1f\n\x04\x61lgo\x18\x01 \x02(\x0e\x32\n.Algorithm:\x05\x42IP32\"\x1e\n\x0fMasterPublicKey\x12\x0b\n\x03key\x18\x01 \x02(\x0c\"@\n\nGetAddress\x12\x1f\n\x04\x61lgo\x18\x01 \x02(\x0e\x32\n.Algorithm:\x05\x42IP32\x12\x11\n\taddress_n\x18\x02 \x03(\r\"\x1a\n\x07\x41\x64\x64ress\x12\x0f\n\x07\x61\x64\x64ress\x18\x01 \x02(\t\"M\n\nLoadDevice\x12\x0c\n\x04seed\x18\x01 \x02(\t\x12\x11\n\x03otp\x18\x02 \x01(\x08:\x04true\x12\x0b\n\x03pin\x18\x03 \x01(\t\x12\x11\n\x03spv\x18\x04 \x01(\x08:\x04true\"\x1d\n\x0bResetDevice\x12\x0e\n\x06random\x18\x07 \x01(\x0c\"f\n\x06SignTx\x12\x1f\n\x04\x61lgo\x18\x01 \x02(\x0e\x32\n.Algorithm:\x05\x42IP32\x12\x15\n\routputs_count\x18\x03 \x02(\r\x12\x14\n\x0cinputs_count\x18\x05 \x02(\r\x12\x0e\n\x06random\x18\x06 \x01(\x0c\"\x86\x01\n\tTxRequest\x12\x15\n\rrequest_index\x18\x01 \x01(\x05\x12\"\n\x0crequest_type\x18\x02 \x01(\x0e\x32\x0c.RequestType\x12\x14\n\x0csigned_index\x18\x03 \x01(\x05\x12\x11\n\tsignature\x18\x04 \x01(\x0c\x12\x15\n\rserialized_tx\x18\x05 \x01(\x0c\"v\n\x07TxInput\x12\r\n\x05index\x18\x01 \x02(\r\x12\x11\n\taddress_n\x18\x02 \x03(\r\x12\x0e\n\x06\x61mount\x18\x03 \x02(\x04\x12\x11\n\tprev_hash\x18\x04 \x02(\x0c\x12\x12\n\nprev_index\x18\x05 \x02(\r\x12\x12\n\nscript_sig\x18\x06 \x01(\x0c\"\x84\x01\n\x08TxOutput\x12\r\n\x05index\x18\x01 \x02(\r\x12\x0f\n\x07\x61\x64\x64ress\x18\x02 \x02(\t\x12\x11\n\taddress_n\x18\x03 \x03(\r\x12\x0e\n\x06\x61mount\x18\x04 \x02(\x04\x12 \n\x0bscript_type\x18\x05 \x02(\x0e\x32\x0b.ScriptType\x12\x13\n\x0bscript_args\x18\x06 \x03(\x0c*$\n\tAlgorithm\x12\t\n\x05\x42IP32\x10\x00\x12\x0c\n\x08\x45LECTRUM\x10\x01*3\n\nScriptType\x12\x10\n\x0cPAYTOADDRESS\x10\x00\x12\x13\n\x0fPAYTOSCRIPTHASH\x10\x01*(\n\x0bRequestType\x12\x0b\n\x07TXINPUT\x10\x00\x12\x0c\n\x08TXOUTPUT\x10\x01') _ALGORITHM = descriptor.EnumDescriptor( name='Algorithm', @@ -30,8 +30,8 @@ _ALGORITHM = descriptor.EnumDescriptor( ], containing_type=None, options=None, - serialized_start=1623, - serialized_end=1659, + serialized_start=1640, + serialized_end=1676, ) @@ -52,8 +52,30 @@ _SCRIPTTYPE = descriptor.EnumDescriptor( ], containing_type=None, options=None, - serialized_start=1661, - serialized_end=1712, + serialized_start=1678, + serialized_end=1729, +) + + +_REQUESTTYPE = descriptor.EnumDescriptor( + name='RequestType', + full_name='RequestType', + filename=None, + file=DESCRIPTOR, + values=[ + descriptor.EnumValueDescriptor( + name='TXINPUT', index=0, number=0, + options=None, + type=None), + descriptor.EnumValueDescriptor( + name='TXOUTPUT', index=1, number=1, + options=None, + type=None), + ], + containing_type=None, + options=None, + serialized_start=1731, + serialized_end=1771, ) @@ -61,6 +83,8 @@ BIP32 = 0 ELECTRUM = 1 PAYTOADDRESS = 0 PAYTOSCRIPTHASH = 1 +TXINPUT = 0 +TXOUTPUT = 1 @@ -995,30 +1019,44 @@ _SIGNTX = descriptor.Descriptor( ) -_INPUTREQUEST = descriptor.Descriptor( - name='InputRequest', - full_name='InputRequest', +_TXREQUEST = descriptor.Descriptor( + name='TxRequest', + full_name='TxRequest', filename=None, file=DESCRIPTOR, containing_type=None, fields=[ descriptor.FieldDescriptor( - name='request_index', full_name='InputRequest.request_index', index=0, + name='request_index', full_name='TxRequest.request_index', index=0, number=1, type=5, cpp_type=1, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), descriptor.FieldDescriptor( - name='signed_index', full_name='InputRequest.signed_index', index=1, - number=2, type=5, cpp_type=1, label=1, + name='request_type', full_name='TxRequest.request_type', index=1, + number=2, type=14, cpp_type=8, label=1, has_default_value=False, default_value=0, message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, options=None), descriptor.FieldDescriptor( - name='signature', full_name='InputRequest.signature', index=2, - number=3, type=12, cpp_type=9, label=1, + name='signed_index', full_name='TxRequest.signed_index', index=2, + number=3, type=5, cpp_type=1, label=1, + has_default_value=False, default_value=0, + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + descriptor.FieldDescriptor( + name='signature', full_name='TxRequest.signature', index=3, + number=4, type=12, cpp_type=9, label=1, + has_default_value=False, default_value="", + message_type=None, enum_type=None, containing_type=None, + is_extension=False, extension_scope=None, + options=None), + descriptor.FieldDescriptor( + name='serialized_tx', full_name='TxRequest.serialized_tx', index=4, + number=5, type=12, cpp_type=9, label=1, has_default_value=False, default_value="", message_type=None, enum_type=None, containing_type=None, is_extension=False, extension_scope=None, @@ -1032,36 +1070,8 @@ _INPUTREQUEST = descriptor.Descriptor( options=None, is_extendable=False, extension_ranges=[], - serialized_start=1248, - serialized_end=1326, -) - - -_OUTPUTREQUEST = descriptor.Descriptor( - name='OutputRequest', - full_name='OutputRequest', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - descriptor.FieldDescriptor( - name='request_index', full_name='OutputRequest.request_index', index=0, - number=1, type=13, cpp_type=3, label=2, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - extension_ranges=[], - serialized_start=1328, - serialized_end=1366, + serialized_start=1249, + serialized_end=1383, ) @@ -1123,8 +1133,8 @@ _TXINPUT = descriptor.Descriptor( options=None, is_extendable=False, extension_ranges=[], - serialized_start=1368, - serialized_end=1486, + serialized_start=1385, + serialized_end=1503, ) @@ -1186,8 +1196,8 @@ _TXOUTPUT = descriptor.Descriptor( options=None, is_extendable=False, extension_ranges=[], - serialized_start=1489, - serialized_end=1621, + serialized_start=1506, + serialized_end=1638, ) _FEATURES.fields_by_name['algo'].enum_type = _ALGORITHM @@ -1196,6 +1206,7 @@ _DEBUGLINKSTATE.fields_by_name['pin'].message_type = _PINACK _GETMASTERPUBLICKEY.fields_by_name['algo'].enum_type = _ALGORITHM _GETADDRESS.fields_by_name['algo'].enum_type = _ALGORITHM _SIGNTX.fields_by_name['algo'].enum_type = _ALGORITHM +_TXREQUEST.fields_by_name['request_type'].enum_type = _REQUESTTYPE _TXOUTPUT.fields_by_name['script_type'].enum_type = _SCRIPTTYPE DESCRIPTOR.message_types_by_name['Initialize'] = _INITIALIZE DESCRIPTOR.message_types_by_name['Features'] = _FEATURES @@ -1226,8 +1237,7 @@ DESCRIPTOR.message_types_by_name['Address'] = _ADDRESS DESCRIPTOR.message_types_by_name['LoadDevice'] = _LOADDEVICE DESCRIPTOR.message_types_by_name['ResetDevice'] = _RESETDEVICE DESCRIPTOR.message_types_by_name['SignTx'] = _SIGNTX -DESCRIPTOR.message_types_by_name['InputRequest'] = _INPUTREQUEST -DESCRIPTOR.message_types_by_name['OutputRequest'] = _OUTPUTREQUEST +DESCRIPTOR.message_types_by_name['TxRequest'] = _TXREQUEST DESCRIPTOR.message_types_by_name['TxInput'] = _TXINPUT DESCRIPTOR.message_types_by_name['TxOutput'] = _TXOUTPUT @@ -1405,17 +1415,11 @@ class SignTx(message.Message): # @@protoc_insertion_point(class_scope:SignTx) -class InputRequest(message.Message): +class TxRequest(message.Message): __metaclass__ = reflection.GeneratedProtocolMessageType - DESCRIPTOR = _INPUTREQUEST + DESCRIPTOR = _TXREQUEST - # @@protoc_insertion_point(class_scope:InputRequest) - -class OutputRequest(message.Message): - __metaclass__ = reflection.GeneratedProtocolMessageType - DESCRIPTOR = _OUTPUTREQUEST - - # @@protoc_insertion_point(class_scope:OutputRequest) + # @@protoc_insertion_point(class_scope:TxRequest) class TxInput(message.Message): __metaclass__ = reflection.GeneratedProtocolMessageType diff --git a/bitkeylib/mapping.py b/bitkeylib/mapping.py index 6a8419eb3d..19969b3cf6 100644 --- a/bitkeylib/mapping.py +++ b/bitkeylib/mapping.py @@ -22,8 +22,8 @@ map_type_to_class = { 18: proto.PinRequest, 19: proto.PinAck, 20: proto.PinCancel, - 21: proto.InputRequest, - 22: proto.OutputRequest, + 21: proto.TxRequest, + #22: proto.OutputRequest, 23: proto.TxInput, 24: proto.TxOutput, 25: proto.SetMaxFeeKb, diff --git a/protobuf/bitkey.proto b/protobuf/bitkey.proto index 8b8d23afd1..8364a4f04d 100644 --- a/protobuf/bitkey.proto +++ b/protobuf/bitkey.proto @@ -16,6 +16,12 @@ enum ScriptType { PAYTOSCRIPTHASH = 1; } +// Specifies which kind of information is required by transaction signing process +enum RequestType { + TXINPUT = 0; + TXOUTPUT = 1; +} + // Reset device's internal state // // Response: Features @@ -212,7 +218,7 @@ message ResetDevice { // Request the device to sign the transaction // -// Response: InputRequest, OutputRequest, OtpRequest, PinRequest, Failure +// Response: TxRequest, OtpRequest, PinRequest, Failure message SignTx { required Algorithm algo = 1 [default=BIP32]; // Algorithm using for key generation algorithm required uint32 outputs_count = 3; // Count of outputs of the transaction @@ -221,24 +227,21 @@ message SignTx { // Recommended to provide 256 bytes of random data. } -// Sent by the device as a response for SignTx. -// If request_index is set, device asks for TxInput message with details of index's input. +// Sent by the device as a response for SignTx. Device asks for information for signing transaction. +// If request_index is set, device asks for TxInput/TxOutput message (depends on request_type) +// with details of index's input. // If signed_index is set, 'signature' contains signed input of signed_index's input. -message InputRequest { - optional int32 request_index = 1; // If >=0, device expects TxInput message from the computer - optional int32 signed_index = 2; // If >=0, 'signature' contains signed input of this input - optional bytes signature = 3; // If signed_index>=0, represent signature of the signed_index input +message TxRequest { + optional int32 request_index = 1; // If >=0, device expects TxInput/TxOutput message from the computer + optional RequestType request_type = 2; // Ask for TxInput or TxOutput? + optional int32 signed_index = 3 [default=-1]; // If >=0, 'signature' contains signed input of this input + optional bytes signature = 4; // If signed_index>=0, represent signature of the signed_index input + optional bytes serialized_tx = 5; // Part of serialized and signed transaction } -// Sent by the device as a response for SignTx or TxInput. -// Device asks for Tx -message OutputRequest { - required uint32 request_index = 1; // Device expects TxOutput message from the computer -} - -// Transaction onput for SignTx workflow. It is response to InputRequest message sent by device. +// Transaction onput for SignTx workflow. It is response to TxRequest message sent by device. // -// Response: InputRequest, OutputRequest, Failure +// Response: TxRequest, Failure message TxInput { required uint32 index = 1; // Position of input in proposed transaction repeated uint32 address_n = 2; // Parameter for address generation algorithm to derive the address from the master public key @@ -248,7 +251,7 @@ message TxInput { optional bytes script_sig = 6; // Script signature } -// Transaction output for SignTx workflow. It is response to OutputRequest message sent by the device. +// Transaction output for SignTx workflow. It is response to TxRequest message sent by the device. message TxOutput { required uint32 index = 1; // Position of output in proposed transaction required string address = 2; // Target bitcoin address in base58 encoding