naeural-client 2.1.4__py3-none-any.whl → 2.2.1__py3-none-any.whl
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.
- naeural_client/_ver.py +1 -1
- naeural_client/base/generic_session.py +1 -6
- naeural_client/bc/base.py +2 -1
- naeural_client/bc/ec.py +67 -7
- naeural_client/const/__init__.py +1 -1
- naeural_client/const/base.py +5 -0
- {naeural_client-2.1.4.dist-info → naeural_client-2.2.1.dist-info}/METADATA +1 -1
- {naeural_client-2.1.4.dist-info → naeural_client-2.2.1.dist-info}/RECORD +10 -10
- {naeural_client-2.1.4.dist-info → naeural_client-2.2.1.dist-info}/WHEEL +0 -0
- {naeural_client-2.1.4.dist-info → naeural_client-2.2.1.dist-info}/licenses/LICENSE +0 -0
naeural_client/_ver.py
CHANGED
@@ -9,7 +9,7 @@ from time import time as tm
|
|
9
9
|
|
10
10
|
from ..base_decentra_object import BaseDecentrAIObject
|
11
11
|
from ..bc import DefaultBlockEngine
|
12
|
-
from ..const import COMMANDS, ENVIRONMENT, HB, PAYLOAD_DATA, STATUS_TYPE, PLUGIN_SIGNATURES
|
12
|
+
from ..const import COMMANDS, ENVIRONMENT, HB, PAYLOAD_DATA, STATUS_TYPE, PLUGIN_SIGNATURES, BLOCKCHAIN_CONFIG
|
13
13
|
from ..const import comms as comm_ct
|
14
14
|
from ..io_formatter import IOFormatterWrapper
|
15
15
|
from ..logging import Logger
|
@@ -44,11 +44,6 @@ class GenericSession(BaseDecentrAIObject):
|
|
44
44
|
"CERT_PATH": None,
|
45
45
|
}
|
46
46
|
|
47
|
-
BLOCKCHAIN_CONFIG = {
|
48
|
-
"PEM_FILE": "_pk_sdk.pem",
|
49
|
-
"PASSWORD": None,
|
50
|
-
"PEM_LOCATION": "data"
|
51
|
-
}
|
52
47
|
|
53
48
|
def __init__(self, *,
|
54
49
|
host=None,
|
naeural_client/bc/base.py
CHANGED
@@ -39,6 +39,7 @@ class BCct:
|
|
39
39
|
DEFAULT_INFO = '0xai handshake data'
|
40
40
|
|
41
41
|
|
42
|
+
|
42
43
|
class _DotDict(dict):
|
43
44
|
__getattr__ = dict.__getitem__
|
44
45
|
__setattr__ = dict.__setitem__
|
@@ -269,7 +270,7 @@ class BaseBlockEngine:
|
|
269
270
|
_lock: Lock = Lock()
|
270
271
|
__instances = {}
|
271
272
|
|
272
|
-
def __new__(cls, name,
|
273
|
+
def __new__(cls, name, log, config, ensure_ascii_payloads=False, verbosity=1):
|
273
274
|
with cls._lock:
|
274
275
|
if name not in cls.__instances:
|
275
276
|
instance = super(BaseBlockEngine, cls).__new__(cls)
|
naeural_client/bc/ec.py
CHANGED
@@ -2,6 +2,7 @@ import base64
|
|
2
2
|
import hashlib
|
3
3
|
import os
|
4
4
|
import binascii
|
5
|
+
import zlib
|
5
6
|
|
6
7
|
from cryptography.hazmat.primitives import hashes
|
7
8
|
from cryptography.hazmat.primitives.asymmetric import ec
|
@@ -266,7 +267,15 @@ class BaseBCEllipticCurveEngine(BaseBlockEngine):
|
|
266
267
|
print('derived-shared_key: ', base64.b64encode(derived_key))
|
267
268
|
return derived_key
|
268
269
|
|
269
|
-
def encrypt(
|
270
|
+
def encrypt(
|
271
|
+
self,
|
272
|
+
plaintext: str,
|
273
|
+
receiver_address: str,
|
274
|
+
compressed: bool = True,
|
275
|
+
embed_compressed: bool = True,
|
276
|
+
info: str = BCct.DEFAULT_INFO,
|
277
|
+
debug: bool = False
|
278
|
+
):
|
270
279
|
"""
|
271
280
|
Encrypts plaintext using the sender's private key and receiver's public key,
|
272
281
|
then base64 encodes the output.
|
@@ -278,23 +287,53 @@ class BaseBCEllipticCurveEngine(BaseBlockEngine):
|
|
278
287
|
|
279
288
|
plaintext : str
|
280
289
|
The plaintext to encrypt.
|
290
|
+
|
291
|
+
compressed : bool, optional
|
292
|
+
Whether to compress the plaintext before encryption. The default is True.
|
293
|
+
|
294
|
+
embed_compressed : bool, optional
|
295
|
+
Whether to embed the compressed flag in the encrypted data. The default is True.
|
281
296
|
|
282
297
|
Returns
|
283
298
|
-------
|
284
299
|
str
|
285
300
|
The base64 encoded nonce and ciphertext.
|
286
301
|
"""
|
302
|
+
if compressed:
|
303
|
+
to_encrypt_data = zlib.compress(plaintext.encode())
|
304
|
+
compressed_flag = (1).to_bytes(1)
|
305
|
+
else:
|
306
|
+
to_encrypt_data = plaintext.encode()
|
307
|
+
compressed_flag = (0).to_bytes(1)
|
308
|
+
|
287
309
|
receiver_pk = self._address_to_pk(receiver_address)
|
288
310
|
shared_key = self.__derive_shared_key(receiver_pk, info=info, debug=debug)
|
289
311
|
aesgcm = AESGCM(shared_key)
|
290
312
|
nonce = os.urandom(12) # Generate a unique nonce for each encryption
|
291
|
-
ciphertext = aesgcm.encrypt(nonce,
|
292
|
-
|
313
|
+
ciphertext = aesgcm.encrypt(nonce, to_encrypt_data, None)
|
314
|
+
if embed_compressed:
|
315
|
+
encrypted_data = nonce + compressed_flag + ciphertext
|
316
|
+
else:
|
317
|
+
encrypted_data = nonce + ciphertext # Prepend the nonce to the ciphertext
|
318
|
+
#end if
|
293
319
|
return base64.b64encode(encrypted_data).decode() # Encode to base64
|
294
320
|
|
295
|
-
def decrypt(
|
321
|
+
def decrypt(
|
322
|
+
self,
|
323
|
+
encrypted_data_b64 : str,
|
324
|
+
sender_address : str,
|
325
|
+
decompress: bool = False, # decompress is only used if embed_compressed is False
|
326
|
+
embed_compressed: bool = True,
|
327
|
+
info: str = BCct.DEFAULT_INFO,
|
328
|
+
debug: bool = False
|
329
|
+
):
|
296
330
|
"""
|
297
331
|
Decrypts base64 encoded encrypted data using the receiver's private key.
|
332
|
+
|
333
|
+
The structure of the encrypted data is:
|
334
|
+
- 12 bytes nonce
|
335
|
+
- 1 byte compressed flag
|
336
|
+
- 13:... The ciphertext
|
298
337
|
|
299
338
|
Parameters
|
300
339
|
----------
|
@@ -303,7 +342,14 @@ class BaseBCEllipticCurveEngine(BaseBlockEngine):
|
|
303
342
|
|
304
343
|
sender_address : str
|
305
344
|
The sender's address.
|
306
|
-
|
345
|
+
|
346
|
+
decompress : bool, optional
|
347
|
+
Whether to decompress the plaintext after decryption. The default is False as the decompression flag is embedded in the encrypted data.
|
348
|
+
|
349
|
+
embed_compressed : bool, optional
|
350
|
+
Whether the compressed flag is embedded in the encrypted data. The default is True.
|
351
|
+
|
352
|
+
|
307
353
|
Returns
|
308
354
|
-------
|
309
355
|
str
|
@@ -311,13 +357,27 @@ class BaseBCEllipticCurveEngine(BaseBlockEngine):
|
|
311
357
|
|
312
358
|
"""
|
313
359
|
try:
|
360
|
+
|
314
361
|
sender_pk = self._address_to_pk(sender_address)
|
315
362
|
encrypted_data = base64.b64decode(encrypted_data_b64) # Decode from base64
|
316
|
-
nonce = encrypted_data[:12] # Extract the nonce
|
317
|
-
|
363
|
+
nonce = encrypted_data[:12] # Extract the nonce
|
364
|
+
|
365
|
+
if embed_compressed:
|
366
|
+
start_data = 13
|
367
|
+
compressed_flag_byte = encrypted_data[12:13]
|
368
|
+
compressed_flag = int.from_bytes(compressed_flag_byte, byteorder='big')
|
369
|
+
else:
|
370
|
+
start_data = 12
|
371
|
+
compressed_flag = None
|
372
|
+
|
373
|
+
ciphertext = encrypted_data[start_data:] # The rest is the ciphertext
|
318
374
|
shared_key = self.__derive_shared_key(sender_pk, info=info, debug=debug)
|
319
375
|
aesgcm = AESGCM(shared_key)
|
320
376
|
plaintext = aesgcm.decrypt(nonce, ciphertext, None)
|
377
|
+
|
378
|
+
if (embed_compressed and compressed_flag) or (not embed_compressed and decompress):
|
379
|
+
plaintext = zlib.decompress(plaintext)
|
380
|
+
|
321
381
|
result = plaintext.decode()
|
322
382
|
except Exception as exc:
|
323
383
|
result = None
|
naeural_client/const/__init__.py
CHANGED
@@ -4,7 +4,7 @@ from . import base as BASE_CT
|
|
4
4
|
from . import payload as PAYLOAD_CT
|
5
5
|
from .formatter import FORMATTER_DATA
|
6
6
|
from .payload import STATUS_TYPE, PAYLOAD_DATA, COMMANDS, NOTIFICATION_CODES
|
7
|
-
from .base import CONFIG_STREAM, BIZ_PLUGIN_DATA, PLUGIN_INFO
|
7
|
+
from .base import CONFIG_STREAM, BIZ_PLUGIN_DATA, PLUGIN_INFO, BLOCKCHAIN_CONFIG
|
8
8
|
from . import heartbeat as HB
|
9
9
|
from .environment import ENVIRONMENT
|
10
10
|
from .apps import PLUGIN_SIGNATURES
|
naeural_client/const/base.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: naeural_client
|
3
|
-
Version: 2.1
|
3
|
+
Version: 2.2.1
|
4
4
|
Summary: `naeural_client` is the Python SDK required for client app development for the Naeural Edge Protocol Edge Protocol framework
|
5
5
|
Project-URL: Homepage, https://github.com/Naeural Edge ProtocolEdgeProtocol/naeural_client
|
6
6
|
Project-URL: Bug Tracker, https://github.com/Naeural Edge ProtocolEdgeProtocol/naeural_client/issues
|
@@ -1,10 +1,10 @@
|
|
1
1
|
naeural_client/__init__.py,sha256=UKEDGS0wFYyxwmhEAKJGecO2vYbIfRYUP4SQgnK10IE,578
|
2
|
-
naeural_client/_ver.py,sha256=
|
2
|
+
naeural_client/_ver.py,sha256=Uvmgeu264AN0yopEhDq75F2YIR2-oX5FrZrNpQN9x6Q,330
|
3
3
|
naeural_client/base_decentra_object.py,sha256=qDBpitcyhr1eEXPD8cGFtcNPNf71fqNRsmOEcCpx4sM,4180
|
4
4
|
naeural_client/plugins_manager_mixin.py,sha256=X1JdGLDz0gN1rPnTN_5mJXR8JmqoBFQISJXmPR9yvCo,11106
|
5
5
|
naeural_client/base/__init__.py,sha256=hACh83_cIv7-PwYMM3bQm2IBmNqiHw-3PAfDfAEKz9A,259
|
6
6
|
naeural_client/base/distributed_custom_code_presets.py,sha256=cvz5R88P6Z5V61Ce1vHVVh8bOkgXd6gve_vdESDNAsg,2544
|
7
|
-
naeural_client/base/generic_session.py,sha256=
|
7
|
+
naeural_client/base/generic_session.py,sha256=QbaRWvC5XeWSdYWYg7kZXSYX4jUHH7aVcDcFLRQ9I5o,75834
|
8
8
|
naeural_client/base/instance.py,sha256=kcZJmjLBtx8Bjj_ysIOx1JmLA-qSpG7E28j5rq6IYus,20444
|
9
9
|
naeural_client/base/pipeline.py,sha256=KwcPWD2XMvHotWFMpcnIycFhqiNnZuyUTUWiLU0PM5Y,57519
|
10
10
|
naeural_client/base/plugin_template.py,sha256=qGaXByd_JZFpjvH9GXNbT7KaitRxIJB6-1IhbKrZjq4,138123
|
@@ -13,9 +13,9 @@ naeural_client/base/transaction.py,sha256=bfs6td5M0fINgPQNxhrl_AUjb1YiilLDQ-Cd_o
|
|
13
13
|
naeural_client/base/payload/__init__.py,sha256=y8fBI8tG2ObNfaXFWjyWZXwu878FRYj_I8GIbHT4GKE,29
|
14
14
|
naeural_client/base/payload/payload.py,sha256=v50D7mBBD2WwWzvpbRGMSr-X6vv5ie21IY1aDxTqe1c,2275
|
15
15
|
naeural_client/bc/__init__.py,sha256=FQj23D1PrY06NUOARiKQi4cdj0-VxnoYgYDEht8lpr8,158
|
16
|
-
naeural_client/bc/base.py,sha256=
|
16
|
+
naeural_client/bc/base.py,sha256=nAFL4z9kyFcmrilHWCia69xMWi65VzjoQ_mo-yCQhGA,28331
|
17
17
|
naeural_client/bc/chain.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
18
|
-
naeural_client/bc/ec.py,sha256=
|
18
|
+
naeural_client/bc/ec.py,sha256=rtIayhYle70HKznRkTdZf2aGzhzHSXGu_qA8IthZY6s,10336
|
19
19
|
naeural_client/certs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
20
20
|
naeural_client/certs/r9092118.ala.eu-central-1.emqxsl.com.crt,sha256=y-6io0tseyx9-a4Pmde1z1gPULtJNSYUpG_YFkYaMKU,1337
|
21
21
|
naeural_client/code_cheker/__init__.py,sha256=pwkdeZGVL16ZA4Qf2mRahEhoOvKhL7FyuQbMFLr1E5M,33
|
@@ -25,9 +25,9 @@ naeural_client/comm/__init__.py,sha256=za3B2HUKNXzYtjElMgGM9xbxNsdQfFY4JB_YzdyFk
|
|
25
25
|
naeural_client/comm/amqp_wrapper.py,sha256=hzj6ih07DnLQy2VSfA88giDIFHaCp9uSdGLTA-IFE4s,8535
|
26
26
|
naeural_client/comm/mqtt_wrapper.py,sha256=Ig3bFZkCbWd4y_Whn2PPa91Z3aLgNbNPau6Tn5yLPZ8,16167
|
27
27
|
naeural_client/const/README.md,sha256=6OHesr-f5NBuuJGryEoi_TCu2XdlhfQYlDKx_IJoXeg,177
|
28
|
-
naeural_client/const/__init__.py,sha256=
|
28
|
+
naeural_client/const/__init__.py,sha256=kpvYRwTmNol7cnFKWyzRQQ8pGvFYHUaODWAHQCMcB0Q,435
|
29
29
|
naeural_client/const/apps.py,sha256=TJpbD7-1tIKxMdpVgZMHOka1k7a6vtW45rQL87K-jvE,507
|
30
|
-
naeural_client/const/base.py,sha256
|
30
|
+
naeural_client/const/base.py,sha256=-NeZPwE0JrbTHmlI9BOmgzaGu5jUZHl9vOZ4hhh_QQo,3100
|
31
31
|
naeural_client/const/comms.py,sha256=La6JXWHexH8CfcBCKyT4fCIoeaoZlcm7KtZ57ab4ZgU,2201
|
32
32
|
naeural_client/const/environment.py,sha256=iytmTDgbOjvORPwHQmc0K0r-xJx7dnnzNnqAJJiFCDA,870
|
33
33
|
naeural_client/const/formatter.py,sha256=AW3bWlqf39uaqV4BBUuW95qKYfF2OkkU4f9hy3kSVhM,200
|
@@ -75,7 +75,7 @@ naeural_client/logging/tzlocal/windows_tz.py,sha256=Sv9okktjZJfRGGUOOppsvQuX_eXy
|
|
75
75
|
naeural_client/utils/__init__.py,sha256=mAnke3-MeRzz3nhQvhuHqLnpaaCSmDxicd7Ck9uwpmI,77
|
76
76
|
naeural_client/utils/comm_utils.py,sha256=4cS9llRr_pK_3rNgDcRMCQwYPO0kcNU7AdWy_LtMyCY,1072
|
77
77
|
naeural_client/utils/dotenv.py,sha256=_AgSo35n7EnQv5yDyu7C7i0kHragLJoCGydHjvOkrYY,2008
|
78
|
-
naeural_client-2.1.
|
79
|
-
naeural_client-2.1.
|
80
|
-
naeural_client-2.1.
|
81
|
-
naeural_client-2.1.
|
78
|
+
naeural_client-2.2.1.dist-info/METADATA,sha256=M74RRLcp_vKpKDJ8etHzvgOgR8LYMG2oheC8ynNMMg0,14457
|
79
|
+
naeural_client-2.2.1.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
80
|
+
naeural_client-2.2.1.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
|
81
|
+
naeural_client-2.2.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|