1
- from bitcoin import encode_pubkey , N , P
2
- try :
3
- from c_secp256k1 import ecdsa_raw_sign , ecdsa_raw_recover
4
- except ImportError :
5
- from bitcoin import ecdsa_raw_sign , ecdsa_raw_recover
1
+ # -*- coding: utf8 -*-
6
2
import rlp
3
+ from bitcoin import encode_pubkey , N , P
7
4
from rlp .sedes import big_endian_int , binary
8
5
from rlp .utils import decode_hex , encode_hex , str_to_bytes , ascii_chr
6
+
7
+ from ethereum .exceptions import InvalidTransaction
9
8
from ethereum import bloom
9
+ from ethereum import opcodes
10
10
from ethereum import utils
11
- from ethereum .utils import TT256 , mk_contract_address
12
- from ethereum .exceptions import InvalidTransaction
13
11
from ethereum .slogging import get_logger
14
- from ethereum import opcodes
12
+ from ethereum .utils import TT256 , mk_contract_address
13
+
14
+ try :
15
+ from c_secp256k1 import ecdsa_sign_raw , ecdsa_recover_raw
16
+ except ImportError :
17
+ import warnings
18
+ warnings .warn ('missing c_secp256k1 falling back to pybitcointools' )
19
+
20
+ from bitcoin import ecdsa_raw_sign as ecdsa_sign_raw , ecdsa_raw_recover as ecdsa_recover_raw
21
+
15
22
log = get_logger ('eth.chain.tx' )
16
23
17
24
# in the yellow paper it is specified that s should be smaller than secpk1n (eq.205)
@@ -78,7 +85,7 @@ def sender(self):
78
85
log .debug ('recovering sender' )
79
86
rlpdata = rlp .encode (self , UnsignedTransaction )
80
87
rawhash = utils .sha3 (rlpdata )
81
- pub = ecdsa_raw_recover (rawhash , (self .v , self .r , self .s ))
88
+ pub = ecdsa_recover_raw (rawhash , (self .v , self .r , self .s ))
82
89
if pub is False :
83
90
raise InvalidTransaction ("Invalid signature values (x^3+7 is non-residue)" )
84
91
if pub == (0 , 0 ):
@@ -102,7 +109,7 @@ def sign(self, key):
102
109
if key in (0 , '' , '\x00 ' * 32 ):
103
110
raise InvalidTransaction ("Zero privkey cannot sign" )
104
111
rawhash = utils .sha3 (rlp .encode (self , UnsignedTransaction ))
105
- self .v , self .r , self .s = ecdsa_raw_sign (rawhash , key )
112
+ self .v , self .r , self .s = ecdsa_sign_raw (rawhash , key )
106
113
self .sender = utils .privtoaddr (key )
107
114
return self
108
115
0 commit comments