naeural-client 2.1.4__py3-none-any.whl → 2.1.5__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 +52 -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.1.5.dist-info}/METADATA +1 -1
- {naeural_client-2.1.4.dist-info → naeural_client-2.1.5.dist-info}/RECORD +10 -10
- {naeural_client-2.1.4.dist-info → naeural_client-2.1.5.dist-info}/WHEEL +0 -0
- {naeural_client-2.1.4.dist-info → naeural_client-2.1.5.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 = False,
|
275
|
+
embed_compressed: bool = False,
|
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,21 +287,43 @@ 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 False.
|
281
293
|
|
282
294
|
Returns
|
283
295
|
-------
|
284
296
|
str
|
285
297
|
The base64 encoded nonce and ciphertext.
|
286
298
|
"""
|
299
|
+
if compressed:
|
300
|
+
to_encrypt_data = zlib.compress(plaintext.encode())
|
301
|
+
compressed_flag = (1).to_bytes(1)
|
302
|
+
else:
|
303
|
+
to_encrypt_data = plaintext.encode()
|
304
|
+
compressed_flag = (0).to_bytes(1)
|
305
|
+
|
287
306
|
receiver_pk = self._address_to_pk(receiver_address)
|
288
307
|
shared_key = self.__derive_shared_key(receiver_pk, info=info, debug=debug)
|
289
308
|
aesgcm = AESGCM(shared_key)
|
290
309
|
nonce = os.urandom(12) # Generate a unique nonce for each encryption
|
291
|
-
ciphertext = aesgcm.encrypt(nonce,
|
292
|
-
|
310
|
+
ciphertext = aesgcm.encrypt(nonce, to_encrypt_data, None)
|
311
|
+
if embed_compressed:
|
312
|
+
encrypted_data = nonce + compressed_flag + ciphertext
|
313
|
+
else:
|
314
|
+
encrypted_data = nonce + ciphertext # Prepend the nonce to the ciphertext
|
315
|
+
#end if
|
293
316
|
return base64.b64encode(encrypted_data).decode() # Encode to base64
|
294
317
|
|
295
|
-
def decrypt(
|
318
|
+
def decrypt(
|
319
|
+
self,
|
320
|
+
encrypted_data_b64 : str,
|
321
|
+
sender_address : str,
|
322
|
+
decompress: bool = False,
|
323
|
+
embed_compressed: bool = False,
|
324
|
+
info: str = BCct.DEFAULT_INFO,
|
325
|
+
debug: bool = False
|
326
|
+
):
|
296
327
|
"""
|
297
328
|
Decrypts base64 encoded encrypted data using the receiver's private key.
|
298
329
|
|
@@ -303,7 +334,7 @@ class BaseBCEllipticCurveEngine(BaseBlockEngine):
|
|
303
334
|
|
304
335
|
sender_address : str
|
305
336
|
The sender's address.
|
306
|
-
|
337
|
+
|
307
338
|
Returns
|
308
339
|
-------
|
309
340
|
str
|
@@ -311,13 +342,27 @@ class BaseBCEllipticCurveEngine(BaseBlockEngine):
|
|
311
342
|
|
312
343
|
"""
|
313
344
|
try:
|
345
|
+
|
314
346
|
sender_pk = self._address_to_pk(sender_address)
|
315
347
|
encrypted_data = base64.b64decode(encrypted_data_b64) # Decode from base64
|
316
|
-
nonce = encrypted_data[:12] # Extract the nonce
|
317
|
-
|
348
|
+
nonce = encrypted_data[:12] # Extract the nonce
|
349
|
+
|
350
|
+
if embed_compressed:
|
351
|
+
start_data = 13
|
352
|
+
compressed_flag_byte = encrypted_data[12:13]
|
353
|
+
compressed_flag = int.from_bytes(compressed_flag_byte, byteorder='big')
|
354
|
+
else:
|
355
|
+
start_data = 12
|
356
|
+
compressed_flag = None
|
357
|
+
|
358
|
+
ciphertext = encrypted_data[start_data:] # The rest is the ciphertext
|
318
359
|
shared_key = self.__derive_shared_key(sender_pk, info=info, debug=debug)
|
319
360
|
aesgcm = AESGCM(shared_key)
|
320
361
|
plaintext = aesgcm.decrypt(nonce, ciphertext, None)
|
362
|
+
|
363
|
+
if (embed_compressed and compressed_flag) or (not embed_compressed and decompress):
|
364
|
+
plaintext = zlib.decompress(plaintext)
|
365
|
+
|
321
366
|
result = plaintext.decode()
|
322
367
|
except Exception as exc:
|
323
368
|
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.1.5
|
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=R9gbAUavcjm9bXT99OTFSFCAgA9DEIx8kdVCFe6mu7c,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=Xyl_POZ2VSnVHHqNtZKhi7NSVwofDX9-fPQxOrY9erA,9688
|
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.1.5.dist-info/METADATA,sha256=4B88yFIzVtP9gFyR7dK3Vzj3co-3TU6aEWaG-J2yJJc,14457
|
79
|
+
naeural_client-2.1.5.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
|
80
|
+
naeural_client-2.1.5.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
|
81
|
+
naeural_client-2.1.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|