@@ -74,7 +74,7 @@ def sender(self):
74
74
if not self ._sender :
75
75
# Determine sender
76
76
if self .v :
77
- if self .r >= N or self .s >= N or self .v not in (27 , 28 , 37 , 38 ) \
77
+ if self .r >= N or self .s >= N or self .v not in (27 , 28 , 37 , 38 , 41 , 42 ) \
78
78
or self .r == 0 or self .s == 0 :
79
79
raise InvalidTransaction ("Invalid signature values!" )
80
80
log .debug ('reco< 27 or self.v > 28 \v ering sender' )
@@ -86,6 +86,10 @@ def sender(self):
86
86
rlpdata = rlp .encode (rlp .infer_sedes (self ).serialize (self )[:- 3 ] + ['\x01 ' , '' , '' ])
87
87
rawhash = utils .sha3 (rlpdata )
88
88
v = self .v - 10
89
+ elif self .v in (41 , 42 ):
90
+ rlpdata = rlp .encode (rlp .infer_sedes (self ).serialize (self )[:- 3 ] + ['\x03 ' , '' , '' ])
91
+ rawhash = utils .sha3 (rlpdata )
92
+ v = self .v - 14
89
93
pub = ecrecover_to_pub (rawhash , v , self .r , self .s )
90
94
if pub == b"\x00 " * 64 :
91
95
raise InvalidTransaction ("Invalid signature (zero privkey cannot sign)" )
@@ -99,20 +103,27 @@ def sender(self):
99
103
def sender (self , value ):
100
104
self ._sender = value
101
105
102
- def sign (self , key ):
106
+ def sign (self , key , network_id = None ):
103
107
"""Sign this transaction with a private key.
104
108
105
109
A potentially already existing signature would be overridden.
106
110
"""
107
111
if key in (0 , '' , b'\x00 ' * 32 , '0' * 64 ):
108
112
raise InvalidTransaction ("Zero privkey cannot sign" )
109
- rawhash = utils .sha3 (rlp .encode (self , UnsignedTransaction ))
113
+ if network_id is None :
114
+ rawhash = utils .sha3 (rlp .encode (self , UnsignedTransaction ))
115
+ else :
116
+ assert 1 <= network_id < 2 ** 63 - 18
117
+ rlpdata = rlp .encode (rlp .infer_sedes (self ).serialize (self )[:- 3 ] + [big_endian_to_int (network_id ), '' , '' ])
118
+ rawhash = utils .sha3 (rlpdata )
110
119
111
120
if len (key ) == 64 :
112
121
# we need a binary key
113
122
key = encode_privkey (key , 'bin' )
114
123
115
124
self .v , self .r , self .s = ecsign (rawhash , key )
125
+ if network_id is not None :
126
+ self .v += 8 + network_id * 2
116
127
117
128
self .sender = utils .privtoaddr (key )
118
129
return self
0 commit comments