sgx.py 0.9.dev5__tar.gz → 0.9.dev6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sgx.py
3
- Version: 0.9.dev5
3
+ Version: 0.9.dev6
4
4
  Summary: SGX
5
5
  Home-page: http://github.com/skalenetwork/sgx.py
6
6
  Author: SKALE Labs
@@ -0,0 +1,39 @@
1
+ from setuptools import (
2
+ find_packages,
3
+ setup,
4
+ )
5
+
6
+ extras_require = {
7
+ 'linter': [
8
+ 'flake8==3.8.3',
9
+ ],
10
+ 'dev': [
11
+ 'coincurve==13.0.0',
12
+ 'python-dotenv==0.13.0',
13
+ 'twine==3.1.1',
14
+ 'pytest==7.3.1',
15
+ 'mock==4.0.2',
16
+ ],
17
+ }
18
+
19
+ extras_require['dev'] = extras_require['linter'] + extras_require['dev']
20
+
21
+ setup(
22
+ name='sgx.py',
23
+ version='0.9dev6',
24
+ description='SGX',
25
+ url='http://github.com/skalenetwork/sgx.py',
26
+ author='SKALE Labs',
27
+ author_email='support@skalelabs.com',
28
+ install_requires=[
29
+ 'web3>=6.20.2,<8.0.0',
30
+ 'pyzmq==25.0.2',
31
+ 'pem==21.2.0',
32
+ 'M2Crypto>=0.40.1,<1.0.0',
33
+ 'urllib3==1.26.0',
34
+ ],
35
+ packages=find_packages(exclude=['tests']),
36
+ python_requires='>=3.7,<4',
37
+ extras_require=extras_require,
38
+ package_data={'sgx': ['generate.sh']},
39
+ )
@@ -29,7 +29,7 @@ from sgx.sgx_zmq import SgxZmq
29
29
  from sgx.utils import public_key_to_address
30
30
  from eth_account._utils import signing
31
31
  from eth_account._utils.legacy_transactions import encode_transaction
32
- from eth_account._utils.typed_transactions import TypedTransaction
32
+ from eth_account.typed_transactions.typed_transaction import TypedTransaction
33
33
  from eth_utils.encoding import big_endian_to_int
34
34
  from eth_utils.conversions import add_0x_prefix, remove_0x_prefix
35
35
 
@@ -67,25 +67,17 @@ class SgxClient:
67
67
  key_name, public_key = self.sgx_rpc_server.generate_key()
68
68
  public_key = add_0x_prefix(public_key)
69
69
  address = public_key_to_address(public_key)
70
- return Account(
71
- name=key_name,
72
- address=address,
73
- public_key=public_key
74
- )
70
+ return Account(name=key_name, address=address, public_key=public_key)
75
71
 
76
72
  def get_account(self, key_name):
77
73
  key = self.sgx_rpc_server.get_public_key(key_name)
78
74
  key = add_0x_prefix(key)
79
75
  address = public_key_to_address(key)
80
- return Account(
81
- name=key_name,
82
- address=address,
83
- public_key=key
84
- )
76
+ return Account(name=key_name, address=address, public_key=key)
85
77
 
86
78
  def sign(self, transaction_dict, key_name):
87
79
  if not isinstance(transaction_dict, Mapping):
88
- raise TypeError("transaction_dict must be dict-like, got %r" % transaction_dict)
80
+ raise TypeError('transaction_dict must be dict-like, got %r' % transaction_dict)
89
81
 
90
82
  address = self.get_account(key_name).address
91
83
 
@@ -94,10 +86,13 @@ class SgxClient:
94
86
  if transaction_dict['from'] == address:
95
87
  sanitized_transaction = dissoc(transaction_dict, 'from')
96
88
  else:
97
- raise TypeError("from field must match key's %s, but it was %s" % (
98
- address,
99
- transaction_dict['from'],
100
- ))
89
+ raise TypeError(
90
+ "from field must match key's %s, but it was %s"
91
+ % (
92
+ address,
93
+ transaction_dict['from'],
94
+ )
95
+ )
101
96
  else:
102
97
  sanitized_transaction = transaction_dict
103
98
 
@@ -111,31 +106,18 @@ class SgxClient:
111
106
 
112
107
  transaction_hash = keccak(rlp_encoded)
113
108
  return SignedTransaction(
114
- rawTransaction=HexBytes(rlp_encoded),
115
- hash=HexBytes(transaction_hash),
116
- r=r,
117
- s=s,
118
- v=v
109
+ raw_transaction=HexBytes(rlp_encoded), hash=HexBytes(transaction_hash), r=r, s=s, v=v
119
110
  )
120
111
 
121
112
  def sign_hash(self, message, key_name, chain_id):
122
113
  msg_hash_bytes = HexBytes(message)
123
114
  if len(msg_hash_bytes) != 32:
124
- raise ValueError("The message hash must be exactly 32-bytes")
115
+ raise ValueError('The message hash must be exactly 32-bytes')
125
116
 
126
- (v, r, s) = self._sign_hash(
127
- key_name,
128
- msg_hash_bytes,
129
- chain_id,
130
- eip_1559_identifier=False
131
- )
117
+ (v, r, s) = self._sign_hash(key_name, msg_hash_bytes, chain_id, eip_1559_identifier=False)
132
118
  signature_bytes = signing.to_bytes32(r) + signing.to_bytes32(s) + signing.to_bytes(v)
133
119
  return SignedMessage(
134
- messageHash=msg_hash_bytes,
135
- r=r,
136
- s=s,
137
- v=v,
138
- signature=HexBytes(signature_bytes)
120
+ message_hash=msg_hash_bytes, r=r, s=s, v=v, signature=HexBytes(signature_bytes)
139
121
  )
140
122
 
141
123
  def generate_dkg_poly(self, poly_name):
@@ -164,39 +146,23 @@ class SgxClient:
164
146
 
165
147
  def verify_secret_share(self, public_shares, eth_key_name, secret_share, index):
166
148
  return self.sgx_rpc_server.verify_secret_share(
167
- public_shares,
168
- eth_key_name,
169
- secret_share,
170
- self.n,
171
- self.t,
172
- index)
149
+ public_shares, eth_key_name, secret_share, self.n, self.t, index
150
+ )
173
151
 
174
152
  def verify_secret_share_v2(self, public_shares, eth_key_name, secret_share, index):
175
153
  return self.sgx_rpc_server.verify_secret_share_v2(
176
- public_shares,
177
- eth_key_name,
178
- secret_share,
179
- self.n,
180
- self.t,
181
- index)
154
+ public_shares, eth_key_name, secret_share, self.n, self.t, index
155
+ )
182
156
 
183
157
  def create_bls_private_key(self, poly_name, bls_key_name, eth_key_name, secret_shares):
184
158
  return self.sgx_rpc_server.create_bls_private_key(
185
- poly_name,
186
- bls_key_name,
187
- eth_key_name,
188
- secret_shares,
189
- self.n,
190
- self.t)
159
+ poly_name, bls_key_name, eth_key_name, secret_shares, self.n, self.t
160
+ )
191
161
 
192
162
  def create_bls_private_key_v2(self, poly_name, bls_key_name, eth_key_name, secret_shares):
193
163
  return self.sgx_rpc_server.create_bls_private_key_v2(
194
- poly_name,
195
- bls_key_name,
196
- eth_key_name,
197
- secret_shares,
198
- self.n,
199
- self.t)
164
+ poly_name, bls_key_name, eth_key_name, secret_shares, self.n, self.t
165
+ )
200
166
 
201
167
  def get_bls_public_key(self, bls_key_name):
202
168
  return self.sgx_rpc_server.get_bls_public_key(bls_key_name)
@@ -206,9 +172,7 @@ class SgxClient:
206
172
  poly_name, self.n, self.t, idx
207
173
  )
208
174
  return ComplaintResponse(
209
- share=share,
210
- dh_key=dh_key,
211
- verification_vector_mult=verification_vector_mult
175
+ share=share, dh_key=dh_key, verification_vector_mult=verification_vector_mult
212
176
  )
213
177
 
214
178
  def mult_g2(self, to_mult):
@@ -236,9 +200,7 @@ class SgxClient:
236
200
 
237
201
  def _sign_transaction_dict(self, eth_key, transaction_dict):
238
202
  # generate RLP-serializable transaction, with defaults filled
239
- unsigned_tx = signing.serializable_unsigned_transaction_from_dict(
240
- transaction_dict
241
- )
203
+ unsigned_tx = signing.serializable_unsigned_transaction_from_dict(transaction_dict)
242
204
 
243
205
  transaction_hash = unsigned_tx.hash()
244
206
 
@@ -249,27 +211,14 @@ class SgxClient:
249
211
  if isinstance(unsigned_tx, TypedTransaction):
250
212
  eip_1559_identifier = True
251
213
 
252
- (v, r, s) = self._sign_hash(
253
- eth_key,
254
- transaction_hash,
255
- chain_id,
256
- eip_1559_identifier
257
- )
214
+ (v, r, s) = self._sign_hash(eth_key, transaction_hash, chain_id, eip_1559_identifier)
258
215
 
259
216
  # serialize transaction with rlp
260
- encoded_tx = encode_transaction(
261
- unsigned_tx,
262
- vrs=(v, r, s))
217
+ encoded_tx = encode_transaction(unsigned_tx, vrs=(v, r, s))
263
218
 
264
219
  return v, r, s, encoded_tx
265
220
 
266
- def _sign_hash(
267
- self,
268
- eth_key,
269
- transaction_hash,
270
- chain_id,
271
- eip_1559_identifier=False
272
- ):
221
+ def _sign_hash(self, eth_key, transaction_hash, chain_id, eip_1559_identifier=False):
273
222
  hash_in_hex = hex(big_endian_to_int(transaction_hash))
274
223
  (v_raw, r_raw, s_raw) = self.sgx_rpc_server.ecdsa_sign(eth_key, hash_in_hex)
275
224
  if eip_1559_identifier:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sgx.py
3
- Version: 0.9.dev5
3
+ Version: 0.9.dev6
4
4
  Summary: SGX
5
5
  Home-page: http://github.com/skalenetwork/sgx.py
6
6
  Author: SKALE Labs
@@ -1,7 +1,7 @@
1
- web3==6.20.2
1
+ web3<8.0.0,>=6.20.2
2
2
  pyzmq==25.0.2
3
3
  pem==21.2.0
4
- M2Crypto==0.40.1
4
+ M2Crypto<1.0.0,>=0.40.1
5
5
  urllib3==1.26.0
6
6
 
7
7
  [dev]
@@ -23,7 +23,7 @@ SGX_URL = os.getenv('SERVER')
23
23
  GETH_URL = os.getenv('GETH')
24
24
  ETH_PRIVATE_KEY = os.getenv('ETH_PRIVATE_KEY')
25
25
 
26
- ETH_VALUE_FOR_TESTS = 5 * 10 ** 18
26
+ ETH_VALUE_FOR_TESTS = 5 * 10**18
27
27
 
28
28
 
29
29
  def private_key_to_public(pr):
@@ -55,13 +55,13 @@ def send_eth_w3(web3, to, value):
55
55
  'to': to,
56
56
  'value': value,
57
57
  'gas': 21000,
58
- 'maxFeePerGas': 10 ** 9,
58
+ 'maxFeePerGas': 10**9,
59
59
  'maxPriorityFeePerGas': 10,
60
60
  'nonce': nonce,
61
- 'chainId': web3.eth.chain_id
61
+ 'chainId': web3.eth.chain_id,
62
62
  }
63
63
  signed = web3.eth.account.sign_transaction(tx, private_key=ETH_PRIVATE_KEY)
64
- tx_hash = web3.eth.send_raw_transaction(signed.rawTransaction)
64
+ tx_hash = web3.eth.send_raw_transaction(signed.raw_transaction)
65
65
  web3.eth.wait_for_transaction_receipt(tx_hash)
66
66
 
67
67
 
@@ -86,16 +86,13 @@ def generate_tx(web3, tx_type=None, no_fee=False):
86
86
  'value': 0,
87
87
  'gas': 200000,
88
88
  'gasPrice': web3.eth.gas_price,
89
- 'chainId': web3.eth.chain_id
89
+ 'chainId': web3.eth.chain_id,
90
90
  }
91
91
  if tx_type:
92
92
  txn['type'] = tx_type
93
93
  if tx_type == 2:
94
94
  txn.pop('gasPrice', None)
95
- txn.update({
96
- 'maxFeePerGas': 10 ** 9,
97
- 'maxPriorityFeePerGas': 10
98
- })
95
+ txn.update({'maxFeePerGas': 10**9, 'maxPriorityFeePerGas': 10})
99
96
 
100
97
  return txn
101
98
 
@@ -111,7 +108,7 @@ def test_sign_and_send(sgx, account, w3):
111
108
  txn = generate_tx(w3)
112
109
  txn['nonce'] = w3.eth.get_transaction_count(address)
113
110
  signed_txn = sgx.sign(txn, key)
114
- tx_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
111
+ tx_hash = w3.eth.send_raw_transaction(signed_txn.raw_transaction)
115
112
  w3.eth.wait_for_transaction_receipt(tx_hash)
116
113
  assert isinstance(tx_hash, HexBytes)
117
114
  assert tx_hash != HexBytes('0x')
@@ -119,7 +116,7 @@ def test_sign_and_send(sgx, account, w3):
119
116
  txn_v1 = generate_tx(w3, 1)
120
117
  txn_v1['nonce'] = w3.eth.get_transaction_count(address)
121
118
  signed_txn = sgx.sign(txn_v1, key)
122
- tx_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
119
+ tx_hash = w3.eth.send_raw_transaction(signed_txn.raw_transaction)
123
120
  w3.eth.wait_for_transaction_receipt(tx_hash)
124
121
  assert isinstance(tx_hash, HexBytes)
125
122
  assert tx_hash != HexBytes('0x')
@@ -130,14 +127,14 @@ def test_sign_and_send_second_type(sgx, account, w3):
130
127
  txn_v2 = generate_tx(w3, 2)
131
128
  txn_v2['nonce'] = w3.eth.get_transaction_count(address)
132
129
  signed_txn = sgx.sign(txn_v2, key)
133
- tx_hash = w3.eth.send_raw_transaction(signed_txn.rawTransaction)
130
+ tx_hash = w3.eth.send_raw_transaction(signed_txn.raw_transaction)
134
131
  assert isinstance(tx_hash, HexBytes)
135
132
  assert tx_hash != HexBytes('0x')
136
133
 
137
134
 
138
135
  def test_get_info(sgx):
139
136
  generated_key = sgx.generate_key()
140
- assert generated_key.name and generated_key.name[:3] == "NEK"
137
+ assert generated_key.name and generated_key.name[:3] == 'NEK'
141
138
  assert generated_key.address and len(generated_key.address) == 42
142
139
  assert generated_key.public_key and len(generated_key.public_key) == 130
143
140
  key = generated_key.name
@@ -164,25 +161,23 @@ def test_sign_message(sgx, account, w3):
164
161
 
165
162
  message = defunct_hash_message(transaction_hash).hex()
166
163
  signed_message = sgx.sign_hash(message, key, None)
167
- assert signed_message.messageHash == HexBytes(message)
164
+ assert signed_message.message_hash == HexBytes(message)
168
165
  assert len(signed_message.signature) > 2
169
166
  assert type(signed_message.signature) == HexBytes
170
167
 
171
168
  recover_account = w3.eth.account.recover_message(
172
- encode_defunct(transaction_hash),
173
- signature=signed_message.signature
169
+ encode_defunct(transaction_hash), signature=signed_message.signature
174
170
  )
175
171
 
176
172
  assert recover_account == address
177
173
 
178
174
 
179
175
  def test_import_ecdsa(sgx, w3):
180
-
181
176
  random_key_name = secrets.token_hex(32)
182
177
 
183
- ecdsa_key_name = "NEK:" + random_key_name
178
+ ecdsa_key_name = 'NEK:' + random_key_name
184
179
 
185
- insecure_ecdsa_private_key = "f253bad7b1f62b8ff60bbf451cf2e8e9ebb5d6e9bff450c55b8d5504b8c63d3"
180
+ insecure_ecdsa_private_key = 'f253bad7b1f62b8ff60bbf451cf2e8e9ebb5d6e9bff450c55b8d5504b8c63d3'
186
181
 
187
182
  public_key = sgx.import_ecdsa_private_key(ecdsa_key_name, insecure_ecdsa_private_key)
188
183
 
@@ -201,12 +196,11 @@ def test_import_ecdsa(sgx, w3):
201
196
  message = defunct_hash_message(transaction_hash).hex()
202
197
 
203
198
  signed_message = sgx.sign_hash(message, ecdsa_key_name, None)
204
- assert signed_message.messageHash == HexBytes(message)
199
+ assert signed_message.message_hash == HexBytes(message)
205
200
  assert len(signed_message.signature) > 2
206
201
  assert type(signed_message.signature) == HexBytes
207
202
 
208
203
  recover_account = w3.eth.account.recover_message(
209
- encode_defunct(transaction_hash),
210
- signature=signed_message.signature
204
+ encode_defunct(transaction_hash), signature=signed_message.signature
211
205
  )
212
206
  assert recover_account == account
sgx.py-0.9.dev5/setup.py DELETED
@@ -1,43 +0,0 @@
1
- from setuptools import (
2
- find_packages,
3
- setup,
4
- )
5
-
6
- extras_require = {
7
- 'linter': [
8
- "flake8==3.8.3",
9
- ],
10
- 'dev': [
11
- "coincurve==13.0.0",
12
- "python-dotenv==0.13.0",
13
- "twine==3.1.1",
14
- "pytest==7.3.1",
15
- "mock==4.0.2"
16
- ]
17
- }
18
-
19
- extras_require['dev'] = (
20
- extras_require['linter'] + extras_require['dev']
21
- )
22
-
23
- setup(
24
- name='sgx.py',
25
- version='0.9dev5',
26
- description='SGX',
27
- url='http://github.com/skalenetwork/sgx.py',
28
- author='SKALE Labs',
29
- author_email='support@skalelabs.com',
30
- install_requires=[
31
- 'web3==6.20.2',
32
- 'pyzmq==25.0.2',
33
- 'pem==21.2.0',
34
- 'M2Crypto==0.40.1',
35
- 'urllib3==1.26.0'
36
- ],
37
- packages=find_packages(exclude=['tests']),
38
- python_requires='>=3.7,<4',
39
- extras_require=extras_require,
40
- package_data={
41
- 'sgx': ['generate.sh']
42
- }
43
- )
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes