sgx.py 0.9.dev6__tar.gz → 0.11.dev0__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.
@@ -0,0 +1,30 @@
1
+ Metadata-Version: 2.4
2
+ Name: sgx.py
3
+ Version: 0.11.dev0
4
+ Summary: SGX
5
+ Home-page: http://github.com/skalenetwork/sgx.py
6
+ Author: SKALE Labs
7
+ Author-email: support@skalelabs.com
8
+ Requires-Python: >=3.11,<4
9
+ License-File: LICENSE
10
+ Requires-Dist: web3<8.0.0,>=6.20.2
11
+ Requires-Dist: pyzmq==27.1.0
12
+ Requires-Dist: pem==23.1.0
13
+ Requires-Dist: cryptography<47.0.0,>=46.0.1
14
+ Provides-Extra: linter
15
+ Requires-Dist: ruff==0.13.2; extra == "linter"
16
+ Provides-Extra: dev
17
+ Requires-Dist: ruff==0.13.2; extra == "dev"
18
+ Requires-Dist: coincurve==13.0.0; extra == "dev"
19
+ Requires-Dist: python-dotenv==0.13.0; extra == "dev"
20
+ Requires-Dist: twine==6.2.0; extra == "dev"
21
+ Requires-Dist: pytest==8.4.2; extra == "dev"
22
+ Requires-Dist: mock==5.2.0; extra == "dev"
23
+ Dynamic: author
24
+ Dynamic: author-email
25
+ Dynamic: home-page
26
+ Dynamic: license-file
27
+ Dynamic: provides-extra
28
+ Dynamic: requires-dist
29
+ Dynamic: requires-python
30
+ Dynamic: summary
@@ -5,14 +5,14 @@ from setuptools import (
5
5
 
6
6
  extras_require = {
7
7
  'linter': [
8
- 'flake8==3.8.3',
8
+ 'ruff==0.13.2',
9
9
  ],
10
10
  'dev': [
11
11
  'coincurve==13.0.0',
12
12
  'python-dotenv==0.13.0',
13
- 'twine==3.1.1',
14
- 'pytest==7.3.1',
15
- 'mock==4.0.2',
13
+ 'twine==6.2.0',
14
+ 'pytest==8.4.2',
15
+ 'mock==5.2.0',
16
16
  ],
17
17
  }
18
18
 
@@ -20,20 +20,19 @@ extras_require['dev'] = extras_require['linter'] + extras_require['dev']
20
20
 
21
21
  setup(
22
22
  name='sgx.py',
23
- version='0.9dev6',
23
+ version='0.11dev0',
24
24
  description='SGX',
25
25
  url='http://github.com/skalenetwork/sgx.py',
26
26
  author='SKALE Labs',
27
27
  author_email='support@skalelabs.com',
28
28
  install_requires=[
29
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',
30
+ 'pyzmq==27.1.0',
31
+ 'pem==23.1.0',
32
+ 'cryptography>=46.0.1,<47.0.0',
34
33
  ],
35
34
  packages=find_packages(exclude=['tests']),
36
- python_requires='>=3.7,<4',
35
+ python_requires='>=3.11,<4',
37
36
  extras_require=extras_require,
38
37
  package_data={'sgx': ['generate.sh']},
39
38
  )
@@ -29,16 +29,13 @@ from sgx.utils import public_key_to_address
29
29
  from eth_utils.conversions import add_0x_prefix, remove_0x_prefix
30
30
  import pem
31
31
  import zmq
32
- from M2Crypto import EVP
32
+ from cryptography.hazmat.primitives import hashes
33
+ from cryptography.hazmat.primitives.asymmetric import ec, rsa, padding
34
+ from cryptography.hazmat.primitives.serialization import load_pem_private_key
33
35
 
34
36
  from urllib.parse import urlparse
35
37
 
36
- from sgx.constants import (
37
- DEFAULT_TIMEOUT,
38
- SGX_ZMQ_RESPONSE_TIMEOUT_MS,
39
- CRT_FILENAME,
40
- KEY_FILENAME
41
- )
38
+ from sgx.constants import DEFAULT_TIMEOUT, SGX_ZMQ_RESPONSE_TIMEOUT_MS, CRT_FILENAME, KEY_FILENAME
42
39
  from sgx.utils import SgxError
43
40
 
44
41
 
@@ -107,21 +104,17 @@ class SgxZmq:
107
104
 
108
105
  def generate_key(self):
109
106
  params = dict()
110
- response = self.__send_request("generateECDSAKey", params)
107
+ response = self.__send_request('generateECDSAKey', params)
111
108
  key_name = response['keyName']
112
109
  public_key = response['publicKey']
113
110
  public_key = add_0x_prefix(public_key)
114
111
  address = public_key_to_address(public_key)
115
- return Account(
116
- name=key_name,
117
- address=address,
118
- public_key=public_key
119
- )
112
+ return Account(name=key_name, address=address, public_key=public_key)
120
113
 
121
114
  def get_public_key(self, keyName):
122
115
  params = dict()
123
116
  params['keyName'] = keyName
124
- response = self.__send_request("getPublicECDSAKey", params)
117
+ response = self.__send_request('getPublicECDSAKey', params)
125
118
  publicKey = response['publicKey']
126
119
  return publicKey
127
120
 
@@ -131,7 +124,7 @@ class SgxZmq:
131
124
  params = dict()
132
125
  params['polyName'] = poly_name
133
126
  params['t'] = self.t
134
- response = self.__send_request("generateDKGPoly", params)
127
+ response = self.__send_request('generateDKGPoly', params)
135
128
  if response['status'] == 0:
136
129
  return DkgPolyStatus.NEW_GENERATED
137
130
  else:
@@ -142,7 +135,7 @@ class SgxZmq:
142
135
  params['polyName'] = poly_name
143
136
  params['n'] = self.n
144
137
  params['t'] = self.t
145
- response = self.__send_request("getVerificationVector", params)
138
+ response = self.__send_request('getVerificationVector', params)
146
139
  verification_vector = response['verificationVector']
147
140
  return verification_vector
148
141
 
@@ -153,16 +146,16 @@ class SgxZmq:
153
146
  params['n'] = self.n
154
147
  params['t'] = self.t
155
148
  params['publicKeys'] = public_keys
156
- response = self.__send_request("getSecretShare", params)
149
+ response = self.__send_request('getSecretShare', params)
157
150
  secret_key_contribution = response['secretShare']
158
151
  return secret_key_contribution
159
152
 
160
153
  def get_server_status(self):
161
- response = self.__send_request("getServerStatus")
154
+ response = self.__send_request('getServerStatus')
162
155
  return response['status']
163
156
 
164
157
  def get_server_version(self):
165
- response = self.__send_request("getServerVersion")
158
+ response = self.__send_request('getServerVersion')
166
159
  return response['version']
167
160
 
168
161
  def verify_secret_share(self, public_shares, eth_key_name, secret_share, index):
@@ -173,7 +166,7 @@ class SgxZmq:
173
166
  params['n'] = self.n
174
167
  params['t'] = self.t
175
168
  params['index'] = index
176
- response = self.__send_request("dkgVerification", params)
169
+ response = self.__send_request('dkgVerification', params)
177
170
  result = response['result']
178
171
  return result
179
172
 
@@ -185,13 +178,13 @@ class SgxZmq:
185
178
  params['secretShare'] = secret_shares
186
179
  params['n'] = self.n
187
180
  params['t'] = self.t
188
- response = self.__send_request("createBLSPrivateKey", params)
181
+ response = self.__send_request('createBLSPrivateKey', params)
189
182
  return response['status'] == 0
190
183
 
191
184
  def get_bls_public_key(self, bls_key_name):
192
185
  params = dict()
193
- params["blsKeyName"] = bls_key_name
194
- response = self.__send_request("getBLSPublicKeyShare", params)
186
+ params['blsKeyName'] = bls_key_name
187
+ response = self.__send_request('getBLSPublicKeyShare', params)
195
188
  return response['blsPublicKeyShare']
196
189
 
197
190
  def complaint_response(self, poly_name, idx):
@@ -200,39 +193,39 @@ class SgxZmq:
200
193
  params['n'] = self.n
201
194
  params['t'] = self.t
202
195
  params['ind'] = idx
203
- response = self.__send_request("complaintResponse", params)
196
+ response = self.__send_request('complaintResponse', params)
204
197
  return ComplaintResponse(
205
198
  share=response['share*G2'],
206
199
  dh_key=response['dhKey'],
207
- verification_vector_mult=response['verificationVectorMult']
200
+ verification_vector_mult=response['verificationVectorMult'],
208
201
  )
209
202
 
210
203
  def mult_g2(self, to_mult):
211
204
  params = dict()
212
205
  params['x'] = to_mult
213
- response = self.__send_request("multG2", params)
206
+ response = self.__send_request('multG2', params)
214
207
  return response['x*G2']
215
208
 
216
209
  def import_bls_private_key(self, key_share_name, key_share):
217
210
  params = dict()
218
211
  params['keyShareName'] = key_share_name
219
212
  params['keyShare'] = key_share
220
- response = self.__send_request("importBLSKeyShare", params)
213
+ response = self.__send_request('importBLSKeyShare', params)
221
214
  encrypted_key = response['encryptedKeyShare']
222
215
  return encrypted_key
223
216
 
224
217
  def is_poly_exists(self, poly_name):
225
218
  params = dict()
226
219
  params['polyName'] = poly_name
227
- response = self.__send_request("isPolyExists", params)
228
- is_exists = response["IsExist"]
220
+ response = self.__send_request('isPolyExists', params)
221
+ is_exists = response['IsExist']
229
222
  return is_exists
230
223
 
231
224
  def delete_bls_key(self, bls_key_name):
232
225
  params = dict()
233
226
  params['blsKeyName'] = bls_key_name
234
- response = self.__send_request("deleteBlsKey", params)
235
- result = response["deleted"]
227
+ response = self.__send_request('deleteBlsKey', params)
228
+ result = response['deleted']
236
229
 
237
230
  return result
238
231
 
@@ -241,8 +234,8 @@ class SgxZmq:
241
234
  params['t'] = self.t
242
235
  params['n'] = self.n
243
236
  params['publicShares'] = verification_vectors
244
- response = self.__send_request("calculateAllBLSPublicKeys", params)
245
- result = response["publicKeys"]
237
+ response = self.__send_request('calculateAllBLSPublicKeys', params)
238
+ result = response['publicKeys']
246
239
 
247
240
  return result
248
241
 
@@ -252,24 +245,24 @@ class SgxZmq:
252
245
  params['messageHash'] = message_hash
253
246
  params['t'] = self.t
254
247
  params['n'] = self.n
255
- response = self.__send_request("blsSignMessageHash", params)
256
- result = response["signatureShare"]
248
+ response = self.__send_request('blsSignMessageHash', params)
249
+ result = response['signatureShare']
257
250
 
258
251
  return result
259
252
 
260
253
  def __send_request(self, method, params=None):
261
254
  if not params:
262
255
  params = dict()
263
- params["type"] = self.method_to_type[method]
256
+ params['type'] = self.method_to_type[method]
264
257
  if self.path_to_cert:
265
- params["cert"] = self.cert
258
+ params['cert'] = self.cert
266
259
  msgSig = self.__sign_msg(params)
267
- params["msgSig"] = msgSig
260
+ params['msgSig'] = msgSig
268
261
  msg = json.dumps(params, separators=(',', ':'))
269
262
  p_id = os.getpid()
270
263
  if not self.sockets.get(p_id):
271
264
  socket_p_id = self.ctx.socket(zmq.DEALER)
272
- socket_p_id.setsockopt_string(zmq.IDENTITY, "135:14603077656239261618")
265
+ socket_p_id.setsockopt_string(zmq.IDENTITY, '135:14603077656239261618')
273
266
  socket_p_id.setsockopt(zmq.LINGER, 0)
274
267
  socket_p_id.setsockopt(zmq.SNDTIMEO, SGX_ZMQ_RESPONSE_TIMEOUT_MS)
275
268
  socket_p_id.setsockopt(zmq.RCVTIMEO, SGX_ZMQ_RESPONSE_TIMEOUT_MS)
@@ -290,22 +283,27 @@ class SgxZmq:
290
283
  if not response_str:
291
284
  raise SgxZmqUnreachableError('Max retries exceeded for sgx connection')
292
285
  response = json.loads(response_str)
293
- if (response.get('errorMessage') is not None and
294
- len(response.get('errorMessage'))) or response['status']:
286
+ if (
287
+ response.get('errorMessage') is not None and len(response.get('errorMessage'))
288
+ ) or response['status']:
295
289
  raise SgxZmqServerError(response['errorMessage'])
296
290
  return response
297
291
 
298
292
  def __sign_msg(self, to_sign):
299
293
  msg = json.dumps(to_sign, separators=(',', ':'))
300
- msg = msg.replace(" ", "")
294
+ msg = msg.replace(' ', '')
301
295
  key_path = os.path.join(self.path_to_cert, KEY_FILENAME)
302
- with open(key_path, "r") as key_file:
303
- private_key = key_file.read()
304
- key = EVP.load_key_string(private_key.encode())
305
- key.reset_context(md='sha256')
306
- key.sign_init()
307
- key.sign_update(msg.encode())
308
- return binascii.hexlify(key.sign_final()).decode()
296
+ with open(key_path, 'rb') as key_file:
297
+ private_key_bytes = key_file.read()
298
+ private_key = load_pem_private_key(private_key_bytes, password=None)
299
+ data = msg.encode()
300
+ if isinstance(private_key, ec.EllipticCurvePrivateKey):
301
+ signature = private_key.sign(data, ec.ECDSA(hashes.SHA256()))
302
+ elif isinstance(private_key, rsa.RSAPrivateKey):
303
+ signature = private_key.sign(data, padding.PKCS1v15(), hashes.SHA256())
304
+ else:
305
+ raise TypeError('Unsupported private key type for signing')
306
+ return binascii.hexlify(signature).decode()
309
307
 
310
308
  def __read_cert(self):
311
309
  crt_path = os.path.join(self.path_to_cert, CRT_FILENAME)
@@ -314,24 +312,24 @@ class SgxZmq:
314
312
 
315
313
  def __init_method_types(self):
316
314
  self.method_to_type = dict()
317
- self.method_to_type["ecdsaSignMessageHash"] = "ECDSASignReq"
318
- self.method_to_type["generateECDSAKey"] = "generateECDSAReq"
319
- self.method_to_type["getPublicECDSAKey"] = "getPublicECDSAReq"
320
- self.method_to_type["generateDKGPoly"] = "generateDKGPolyReq"
321
- self.method_to_type["getVerificationVector"] = "getVerificationVectorReq"
322
- self.method_to_type["getSecretShare"] = "getSecretShareReq"
323
- self.method_to_type["getServerStatus"] = "getServerStatusReq"
324
- self.method_to_type["getServerVersion"] = "getServerVersionReq"
325
- self.method_to_type["dkgVerification"] = "dkgVerificationReq"
326
- self.method_to_type["createBLSPrivateKey"] = "createBLSPrivateReq"
327
- self.method_to_type["getBLSPublicKeyShare"] = "getBLSPublicReq"
328
- self.method_to_type["complaintResponse"] = "complaintResponseReq"
329
- self.method_to_type["importBLSKeyShare"] = "importBLSReq"
330
- self.method_to_type["isPolyExists"] = "isPolyExistsReq"
331
- self.method_to_type["deleteBlsKey"] = "deleteBLSKeyReq"
332
- self.method_to_type["calculateAllBLSPublicKeys"] = "getAllBLSPublicReq"
333
- self.method_to_type["blsSignMessageHash"] = "BLSSignReq"
334
- self.method_to_type["multG2"] = "multG2Req"
315
+ self.method_to_type['ecdsaSignMessageHash'] = 'ECDSASignReq'
316
+ self.method_to_type['generateECDSAKey'] = 'generateECDSAReq'
317
+ self.method_to_type['getPublicECDSAKey'] = 'getPublicECDSAReq'
318
+ self.method_to_type['generateDKGPoly'] = 'generateDKGPolyReq'
319
+ self.method_to_type['getVerificationVector'] = 'getVerificationVectorReq'
320
+ self.method_to_type['getSecretShare'] = 'getSecretShareReq'
321
+ self.method_to_type['getServerStatus'] = 'getServerStatusReq'
322
+ self.method_to_type['getServerVersion'] = 'getServerVersionReq'
323
+ self.method_to_type['dkgVerification'] = 'dkgVerificationReq'
324
+ self.method_to_type['createBLSPrivateKey'] = 'createBLSPrivateReq'
325
+ self.method_to_type['getBLSPublicKeyShare'] = 'getBLSPublicReq'
326
+ self.method_to_type['complaintResponse'] = 'complaintResponseReq'
327
+ self.method_to_type['importBLSKeyShare'] = 'importBLSReq'
328
+ self.method_to_type['isPolyExists'] = 'isPolyExistsReq'
329
+ self.method_to_type['deleteBlsKey'] = 'deleteBLSKeyReq'
330
+ self.method_to_type['calculateAllBLSPublicKeys'] = 'getAllBLSPublicReq'
331
+ self.method_to_type['blsSignMessageHash'] = 'BLSSignReq'
332
+ self.method_to_type['multG2'] = 'multG2Req'
335
333
 
336
334
 
337
335
  def get_provider(endpoint):
@@ -0,0 +1,30 @@
1
+ Metadata-Version: 2.4
2
+ Name: sgx.py
3
+ Version: 0.11.dev0
4
+ Summary: SGX
5
+ Home-page: http://github.com/skalenetwork/sgx.py
6
+ Author: SKALE Labs
7
+ Author-email: support@skalelabs.com
8
+ Requires-Python: >=3.11,<4
9
+ License-File: LICENSE
10
+ Requires-Dist: web3<8.0.0,>=6.20.2
11
+ Requires-Dist: pyzmq==27.1.0
12
+ Requires-Dist: pem==23.1.0
13
+ Requires-Dist: cryptography<47.0.0,>=46.0.1
14
+ Provides-Extra: linter
15
+ Requires-Dist: ruff==0.13.2; extra == "linter"
16
+ Provides-Extra: dev
17
+ Requires-Dist: ruff==0.13.2; extra == "dev"
18
+ Requires-Dist: coincurve==13.0.0; extra == "dev"
19
+ Requires-Dist: python-dotenv==0.13.0; extra == "dev"
20
+ Requires-Dist: twine==6.2.0; extra == "dev"
21
+ Requires-Dist: pytest==8.4.2; extra == "dev"
22
+ Requires-Dist: mock==5.2.0; extra == "dev"
23
+ Dynamic: author
24
+ Dynamic: author-email
25
+ Dynamic: home-page
26
+ Dynamic: license-file
27
+ Dynamic: provides-extra
28
+ Dynamic: requires-dist
29
+ Dynamic: requires-python
30
+ Dynamic: summary
@@ -0,0 +1,15 @@
1
+ web3<8.0.0,>=6.20.2
2
+ pyzmq==27.1.0
3
+ pem==23.1.0
4
+ cryptography<47.0.0,>=46.0.1
5
+
6
+ [dev]
7
+ ruff==0.13.2
8
+ coincurve==13.0.0
9
+ python-dotenv==0.13.0
10
+ twine==6.2.0
11
+ pytest==8.4.2
12
+ mock==5.2.0
13
+
14
+ [linter]
15
+ ruff==0.13.2
@@ -10,7 +10,7 @@ from eth_account.messages import defunct_hash_message, encode_defunct
10
10
  from dotenv import load_dotenv
11
11
  from eth_keys import keys
12
12
  from hexbytes import HexBytes
13
- from telnetlib import Telnet
13
+ import socket
14
14
  from web3 import Web3
15
15
 
16
16
 
@@ -99,8 +99,8 @@ def generate_tx(web3, tx_type=None, no_fee=False):
99
99
 
100
100
  def test_server_connection():
101
101
  parsed_url = urllib.parse.urlparse(SGX_URL)
102
- with Telnet(parsed_url.hostname, parsed_url.port, timeout=5) as tn:
103
- tn.msg('Test')
102
+ with socket.create_connection((parsed_url.hostname, parsed_url.port), timeout=5) as s:
103
+ s.sendall(b'\n')
104
104
 
105
105
 
106
106
  def test_sign_and_send(sgx, account, w3):
@@ -163,7 +163,7 @@ def test_sign_message(sgx, account, w3):
163
163
  signed_message = sgx.sign_hash(message, key, None)
164
164
  assert signed_message.message_hash == HexBytes(message)
165
165
  assert len(signed_message.signature) > 2
166
- assert type(signed_message.signature) == HexBytes
166
+ assert type(signed_message.signature) is HexBytes
167
167
 
168
168
  recover_account = w3.eth.account.recover_message(
169
169
  encode_defunct(transaction_hash), signature=signed_message.signature
@@ -198,7 +198,7 @@ def test_import_ecdsa(sgx, w3):
198
198
  signed_message = sgx.sign_hash(message, ecdsa_key_name, None)
199
199
  assert signed_message.message_hash == HexBytes(message)
200
200
  assert len(signed_message.signature) > 2
201
- assert type(signed_message.signature) == HexBytes
201
+ assert type(signed_message.signature) is HexBytes
202
202
 
203
203
  recover_account = w3.eth.account.recover_message(
204
204
  encode_defunct(transaction_hash), signature=signed_message.signature
sgx.py-0.9.dev6/PKG-INFO DELETED
@@ -1,11 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: sgx.py
3
- Version: 0.9.dev6
4
- Summary: SGX
5
- Home-page: http://github.com/skalenetwork/sgx.py
6
- Author: SKALE Labs
7
- Author-email: support@skalelabs.com
8
- Requires-Python: >=3.7,<4
9
- Provides-Extra: linter
10
- Provides-Extra: dev
11
- License-File: LICENSE
@@ -1,11 +0,0 @@
1
- Metadata-Version: 2.1
2
- Name: sgx.py
3
- Version: 0.9.dev6
4
- Summary: SGX
5
- Home-page: http://github.com/skalenetwork/sgx.py
6
- Author: SKALE Labs
7
- Author-email: support@skalelabs.com
8
- Requires-Python: >=3.7,<4
9
- Provides-Extra: linter
10
- Provides-Extra: dev
11
- License-File: LICENSE
@@ -1,16 +0,0 @@
1
- web3<8.0.0,>=6.20.2
2
- pyzmq==25.0.2
3
- pem==21.2.0
4
- M2Crypto<1.0.0,>=0.40.1
5
- urllib3==1.26.0
6
-
7
- [dev]
8
- flake8==3.8.3
9
- coincurve==13.0.0
10
- python-dotenv==0.13.0
11
- twine==3.1.1
12
- pytest==7.3.1
13
- mock==4.0.2
14
-
15
- [linter]
16
- flake8==3.8.3
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