naeural-client 2.1.3__tar.gz → 2.1.5__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.
- {naeural_client-2.1.3 → naeural_client-2.1.5}/.github/workflows/python-publish.yml +4 -1
- {naeural_client-2.1.3 → naeural_client-2.1.5}/PKG-INFO +1 -1
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/_ver.py +1 -1
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/base/generic_session.py +1 -6
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/bc/base.py +2 -1
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/bc/ec.py +52 -7
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/const/__init__.py +1 -1
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/const/base.py +23 -3
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/const/payload.py +4 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/pyproject.toml +1 -1
- {naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/.example_env +2 -0
- naeural_client-2.1.5/tutorials/ex11_telegram_blackjack_bot.py +203 -0
- naeural_client-2.1.5/xperimental/enc_dec_test.py +66 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/.devcontainer/Dockerfile +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/.devcontainer/devcontainer.json +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/.gitattributes +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/.gitignore +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/.vscode/launch.json +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/LICENSE +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/README.md +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/TODOs.md +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/__init__.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/__init__.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/base/__init__.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/base/distributed_custom_code_presets.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/base/instance.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/base/payload/__init__.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/base/payload/payload.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/base/pipeline.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/base/plugin_template.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/base/responses.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/base/transaction.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/base_decentra_object.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/bc/__init__.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/bc/chain.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/certs/__init__.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/certs/r9092118.ala.eu-central-1.emqxsl.com.crt +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/code_cheker/__init__.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/code_cheker/base.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/code_cheker/checker.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/comm/__init__.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/comm/amqp_wrapper.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/comm/mqtt_wrapper.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/const/README.md +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/const/apps.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/const/comms.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/const/environment.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/const/formatter.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/const/heartbeat.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/const/misc.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/default/__init__.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/default/instance/__init__.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/default/instance/chain_dist_custom_job_01_plugin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/default/instance/custom_web_app_01_plugin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/default/instance/net_mon_01_plugin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/default/instance/telegram_basic_bot_01_plugin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/default/instance/telegram_conversational_bot_01_plugin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/default/instance/view_scene_01_plugin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/default/session/mqtt_session.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/io_formatter/__init__.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/io_formatter/base/__init__.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/io_formatter/base/base_formatter.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/io_formatter/default/__init__.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/io_formatter/default/a_dummy.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/io_formatter/default/aixp1.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/io_formatter/default/default.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/io_formatter/io_formatter_manager.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/__init__.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/base_logger.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/__init__.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/class_instance_mixin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/computer_vision_mixin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/datetime_mixin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/download_mixin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/general_serialization_mixin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/json_serialization_mixin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/pickle_serialization_mixin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/process_mixin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/resource_size_mixin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/timers_mixin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/upload_mixin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/utils_mixin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/small_logger.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/tzlocal/__init__.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/tzlocal/unix.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/tzlocal/utils.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/tzlocal/win32.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/tzlocal/windows_tz.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/plugins_manager_mixin.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/utils/__init__.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/utils/comm_utils.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/utils/dotenv.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/requirements.txt +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/8. custom_code_fastapi_assets/index.html +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/9. code_sandbox_from_scratch_assets/index.html +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/_example_pk_sdk.pem +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/ex01_part1_connect.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/ex01_part2_filter.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/ex02_first_deploy.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/ex03_custom_code_on_one_remote__example_1.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/ex04_custom_code_on_one_remote__example_2.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/ex05_custom_code_on_one_remote__example_3.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/ex06_custom_code_on_multiple_remotes__example_1.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/ex07_custom_code_on_multiple_remotes__example_2.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/ex08_custom_web_app.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/ex09_code_sandbox_from_scratch.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/ex10_telegram_echo_bot.py +0 -0
- /naeural_client-2.1.3/tutorials/ex11_telegram_smart_bot.py → /naeural_client-2.1.5/tutorials/ex12_telegram_smart_bot.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/video_presentation/1. hello_world.ipynb +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/winrun.bat +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/xperimental/.example_env +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/xperimental/README.md +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/xperimental/_archive/test.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/xperimental/_tutorials/3. simple_real_time_custom_code.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/xperimental/_tutorials/4. real_time_custom_code_2.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/xperimental/_tutorials/8. chatbot.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/xperimental/attach_example.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/xperimental/decentralized/chain_dist_example.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/xperimental/decentralized/chain_dist_example_initiator.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/xperimental/decentralized/chain_dist_example_worker.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/xperimental/ex1.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/xperimental/hello.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/xperimental/remote_exec.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/xperimental/save_images.py +0 -0
- {naeural_client-2.1.3 → naeural_client-2.1.5}/xperimental/utils/get_documentation.py +0 -0
@@ -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
|
@@ -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,
|
@@ -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)
|
@@ -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
|
@@ -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
|
@@ -1,6 +1,22 @@
|
|
1
1
|
EE_ID = 'EE_ID'
|
2
2
|
SB_ID = 'SB_ID' # change to SB_ID = EE_ID post mod from sb to ee
|
3
3
|
|
4
|
+
BLOCKCHAIN_CONFIG = {
|
5
|
+
"PEM_FILE": "_pk_sdk.pem",
|
6
|
+
"PASSWORD": None,
|
7
|
+
"PEM_LOCATION": "data"
|
8
|
+
}
|
9
|
+
|
10
|
+
class DCT_TYPES:
|
11
|
+
VOID_PIPELINE = 'Void'
|
12
|
+
NETWORK_LISTENER = 'NetworkListener'
|
13
|
+
METASTREAM_PIPELINE = 'MetaStream'
|
14
|
+
|
15
|
+
|
16
|
+
class DCT_OPTIONS:
|
17
|
+
NETWORK_LISTENER_PATH_FILTER = "PATH_FILTER"
|
18
|
+
NETWORK_LISTENER_MESSAGE_FILTER = "MESSAGE_FILTER"
|
19
|
+
ADMIN_PIPELINE_VER = 'ADMIN_PIPELINE_VER'
|
4
20
|
|
5
21
|
class CONFIG_STREAM:
|
6
22
|
K_URL = 'URL'
|
@@ -22,7 +38,7 @@ class CONFIG_STREAM:
|
|
22
38
|
K_PIPELINE_COMMAND = 'PIPELINE_COMMAND'
|
23
39
|
K_USE_LOCAL_COMMS_ONLY = 'USE_LOCAL_COMMS_ONLY'
|
24
40
|
|
25
|
-
METASTREAM =
|
41
|
+
METASTREAM = DCT_TYPES.METASTREAM_PIPELINE
|
26
42
|
|
27
43
|
INITIATOR_ID = K_INITIATOR_ID
|
28
44
|
SESSION_ID = K_SESSION_ID
|
@@ -53,10 +69,14 @@ class CONFIG_STREAM:
|
|
53
69
|
|
54
70
|
MANDATORY = [K_NAME, K_TYPE]
|
55
71
|
|
56
|
-
VOID_STREAM =
|
72
|
+
VOID_STREAM = DCT_TYPES.VOID_PIPELINE
|
73
|
+
|
74
|
+
DEFAULT_ADMIN_PIPELINE_TYPE = DCT_TYPES.NETWORK_LISTENER
|
57
75
|
|
58
76
|
NO_DATA_STREAMS = [VOID_STREAM]
|
59
|
-
|
77
|
+
|
78
|
+
PIPELINE_OPTIONS = DCT_OPTIONS
|
79
|
+
PIPELINE_TYPES = DCT_TYPES
|
60
80
|
|
61
81
|
class BIZ_PLUGIN_DATA:
|
62
82
|
INSTANCE_ID = 'INSTANCE_ID'
|
@@ -181,6 +181,8 @@ class PAYLOAD_DATA:
|
|
181
181
|
EE_SENDER = BC_CT.SENDER
|
182
182
|
EE_HASH = BC_CT.HASH
|
183
183
|
EE_SIGN = BC_CT.SIGN
|
184
|
+
|
185
|
+
EE_DESTINATION = "EE_DEST"
|
184
186
|
|
185
187
|
NOTIFICATION = 'NOTIFICATION'
|
186
188
|
INFO = 'INFO'
|
@@ -188,3 +190,5 @@ class PAYLOAD_DATA:
|
|
188
190
|
TAGS = 'TAGS'
|
189
191
|
|
190
192
|
ID_TAGS = 'ID_TAGS'
|
193
|
+
|
194
|
+
|
@@ -0,0 +1,203 @@
|
|
1
|
+
import os
|
2
|
+
import time
|
3
|
+
|
4
|
+
from naeural_client import Session, CustomPluginTemplate
|
5
|
+
|
6
|
+
def reply(plugin, message: str, user: str):
|
7
|
+
# Define the deck of cards and their values
|
8
|
+
cards = ['2', '3', '4', '5', '6', '7', '8', '9', '10',
|
9
|
+
'Jack', 'Queen', 'King', 'Ace']
|
10
|
+
card_values = {
|
11
|
+
'2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7,
|
12
|
+
'8': 8, '9': 9, '10': 10,
|
13
|
+
'Jack': 10, 'Queen': 10, 'King': 10,
|
14
|
+
'Ace': 11 # Ace is treated as 11 initially; we'll adjust as needed
|
15
|
+
}
|
16
|
+
|
17
|
+
# Initialize user state if not already present
|
18
|
+
if user not in plugin.obj_cache or plugin.obj_cache[user] is None:
|
19
|
+
plugin.obj_cache[user] = {
|
20
|
+
'state': 'NOT_STARTED',
|
21
|
+
'wins': 0,
|
22
|
+
'losses': 0
|
23
|
+
}
|
24
|
+
|
25
|
+
# Retrieve the user's game state
|
26
|
+
user_cache = plugin.obj_cache[user]
|
27
|
+
message = message.strip().lower() # Normalize the input message
|
28
|
+
|
29
|
+
if user_cache.get('state') == 'NOT_STARTED':
|
30
|
+
if message == 'card' or message == 'start':
|
31
|
+
# Start a new game
|
32
|
+
user_cache['hand'] = [] # Initialize player's hand
|
33
|
+
user_cache['state'] = 'PLAYING'
|
34
|
+
|
35
|
+
# Deal the first card
|
36
|
+
card = plugin.np.random.choice(cards)
|
37
|
+
user_cache['hand'].append(card)
|
38
|
+
|
39
|
+
# Calculate hand value
|
40
|
+
total = 0
|
41
|
+
aces = 0 # Count of aces in hand
|
42
|
+
for c in user_cache['hand']:
|
43
|
+
if c == 'Ace':
|
44
|
+
aces += 1
|
45
|
+
else:
|
46
|
+
total += card_values[c]
|
47
|
+
# Adjust for aces
|
48
|
+
for _ in range(aces):
|
49
|
+
if total + 11 <= 21:
|
50
|
+
total += 11 # Count ace as 11 if it doesn't cause bust
|
51
|
+
else:
|
52
|
+
total += 1 # Otherwise, count ace as 1
|
53
|
+
|
54
|
+
# Return the initial game message
|
55
|
+
return (f"Welcome to a new game of Black Jack, you have a {card}. "
|
56
|
+
f"Your total is {total}. Type 'card' to get another card, or 'stop' to hold.")
|
57
|
+
else:
|
58
|
+
# Prompt user to start a new game
|
59
|
+
return "Welcome to Black Jack. Type 'card' to start a new game."
|
60
|
+
|
61
|
+
elif user_cache.get('state') == 'PLAYING':
|
62
|
+
if message == 'card':
|
63
|
+
# Player chooses to draw another card
|
64
|
+
card = plugin.np.random.choice(cards)
|
65
|
+
user_cache['hand'].append(card)
|
66
|
+
|
67
|
+
# Recalculate hand value
|
68
|
+
total = 0
|
69
|
+
aces = 0
|
70
|
+
for c in user_cache['hand']:
|
71
|
+
if c == 'Ace':
|
72
|
+
aces += 1
|
73
|
+
else:
|
74
|
+
total += card_values[c]
|
75
|
+
for _ in range(aces):
|
76
|
+
if total + 11 <= 21:
|
77
|
+
total += 11
|
78
|
+
else:
|
79
|
+
total += 1
|
80
|
+
|
81
|
+
hand_str = ', '.join(user_cache['hand']) # Format hand as a string
|
82
|
+
|
83
|
+
if total > 21:
|
84
|
+
# Player busts
|
85
|
+
user_cache['state'] = 'BUST'
|
86
|
+
user_cache['losses'] += 1 # Increment losses
|
87
|
+
return (f"You are given a {card}. Your hand: {hand_str}. "
|
88
|
+
f"Your total is {total}. Bust! You lose.\n"
|
89
|
+
f"Total Wins: {user_cache['wins']}, Total Losses: {user_cache['losses']}")
|
90
|
+
elif total == 21:
|
91
|
+
# Player hits Black Jack
|
92
|
+
user_cache['state'] = 'BLACKJACK'
|
93
|
+
user_cache['wins'] += 1 # Increment wins
|
94
|
+
return (f"You are given a {card}. Black Jack! Congratulations, you win! "
|
95
|
+
f"Your hand: {hand_str}.\n"
|
96
|
+
f"Total Wins: {user_cache['wins']}, Total Losses: {user_cache['losses']}")
|
97
|
+
else:
|
98
|
+
# Continue playing
|
99
|
+
return (f"You are given a {card}. Your hand: {hand_str}. "
|
100
|
+
f"Your total is {total}. Type 'card' to get another card, or 'stop' to hold.")
|
101
|
+
elif message == 'stop':
|
102
|
+
# Player chooses to hold; dealer's turn
|
103
|
+
dealer_hand = []
|
104
|
+
dealer_total = 0
|
105
|
+
dealer_aces = 0
|
106
|
+
|
107
|
+
# Dealer draws cards until total >= 17
|
108
|
+
while True:
|
109
|
+
dealer_card = plugin.np.random.choice(cards)
|
110
|
+
dealer_hand.append(dealer_card)
|
111
|
+
|
112
|
+
# Update dealer's total
|
113
|
+
if dealer_card == 'Ace':
|
114
|
+
dealer_aces += 1
|
115
|
+
else:
|
116
|
+
dealer_total += card_values[dealer_card]
|
117
|
+
|
118
|
+
# Calculate dealer's total considering aces
|
119
|
+
temp_total = dealer_total
|
120
|
+
aces = dealer_aces
|
121
|
+
for _ in range(aces):
|
122
|
+
if temp_total + 11 <= 21:
|
123
|
+
temp_total += 11
|
124
|
+
else:
|
125
|
+
temp_total += 1
|
126
|
+
|
127
|
+
dealer_total_with_aces = temp_total
|
128
|
+
|
129
|
+
# Dealer stops hitting when total >= 17
|
130
|
+
if dealer_total_with_aces >= 17:
|
131
|
+
dealer_total = dealer_total_with_aces
|
132
|
+
break
|
133
|
+
else:
|
134
|
+
dealer_total = dealer_total_with_aces
|
135
|
+
|
136
|
+
# Calculate player's total
|
137
|
+
player_total = 0
|
138
|
+
player_aces = 0
|
139
|
+
for c in user_cache['hand']:
|
140
|
+
if c == 'Ace':
|
141
|
+
player_aces += 1
|
142
|
+
else:
|
143
|
+
player_total += card_values[c]
|
144
|
+
for _ in range(player_aces):
|
145
|
+
if player_total + 11 <= 21:
|
146
|
+
player_total += 11
|
147
|
+
else:
|
148
|
+
player_total += 1
|
149
|
+
|
150
|
+
user_cache['state'] = 'GAME_OVER' # Update game state
|
151
|
+
|
152
|
+
# Determine the outcome
|
153
|
+
if dealer_total > 21:
|
154
|
+
result = "Dealer busts! You win!"
|
155
|
+
user_cache['wins'] += 1
|
156
|
+
elif player_total > dealer_total:
|
157
|
+
result = "You win!"
|
158
|
+
user_cache['wins'] += 1
|
159
|
+
elif player_total == dealer_total:
|
160
|
+
result = "It's a tie!"
|
161
|
+
# Ties are not counted as wins or losses
|
162
|
+
else:
|
163
|
+
result = "You lose!"
|
164
|
+
user_cache['losses'] += 1
|
165
|
+
|
166
|
+
player_hand_str = ', '.join(user_cache['hand'])
|
167
|
+
dealer_hand_str = ', '.join(dealer_hand)
|
168
|
+
|
169
|
+
# Return the game result with total wins and losses
|
170
|
+
return (f"You stopped with {player_total}. Your hand: {player_hand_str}.\n"
|
171
|
+
f"Dealer's hand: {dealer_hand_str} (Total: {dealer_total}).\n"
|
172
|
+
f"{result}\nTotal Wins: {user_cache['wins']}, Total Losses: {user_cache['losses']}")
|
173
|
+
else:
|
174
|
+
# Invalid input during playing
|
175
|
+
return "Invalid input. Please type 'card' to get another card, or 'stop' to hold."
|
176
|
+
|
177
|
+
elif user_cache.get('state') in ['BUST', 'BLACKJACK', 'GAME_OVER']:
|
178
|
+
# Game is over; reset state for a new game
|
179
|
+
user_cache['state'] = 'NOT_STARTED'
|
180
|
+
return "Game over. Type 'card' to start a new game."
|
181
|
+
|
182
|
+
else:
|
183
|
+
# Catch-all for unexpected state
|
184
|
+
return "An error occurred. Please start a new game."
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
if __name__ == "__main__":
|
189
|
+
my_node = os.getenv("TARGET_NODE") # we can specify a node here, if we want to connect to a specific
|
190
|
+
|
191
|
+
session = Session() # assume .env is available and will be used for the connection and tokens
|
192
|
+
session.wait_for_node(my_node) # wait for the node to be active
|
193
|
+
|
194
|
+
|
195
|
+
pipeline, _ = session.create_telegram_simple_bot(
|
196
|
+
node=my_node,
|
197
|
+
name="telegram_bot_blackjack",
|
198
|
+
message_handler=reply,
|
199
|
+
)
|
200
|
+
|
201
|
+
pipeline.deploy() # we deploy the pipeline
|
202
|
+
|
203
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import json
|
2
|
+
|
3
|
+
from naeural_client import Logger, const
|
4
|
+
from naeural_client.bc import DefaultBlockEngine
|
5
|
+
|
6
|
+
|
7
|
+
|
8
|
+
if __name__ == '__main__' :
|
9
|
+
l = Logger("ENC", base_folder=".", app_folder="_local_cache")
|
10
|
+
eng1 = DefaultBlockEngine(
|
11
|
+
log=l, name="test1",
|
12
|
+
config={
|
13
|
+
"PEM_FILE" : "test1.pem",
|
14
|
+
"PASSWORD" : None,
|
15
|
+
"PEM_LOCATION" : "data"
|
16
|
+
}
|
17
|
+
)
|
18
|
+
eng2 = DefaultBlockEngine(
|
19
|
+
log=l, name="test2",
|
20
|
+
config={
|
21
|
+
"PEM_FILE" : "test2.pem",
|
22
|
+
"PASSWORD" : None,
|
23
|
+
"PEM_LOCATION" : "data"
|
24
|
+
}
|
25
|
+
)
|
26
|
+
|
27
|
+
data = {
|
28
|
+
"test": "data1 data2 data3 data4 data5 data6 data7 data8 data9 data10",
|
29
|
+
"test2": "data21 data22 data23 data24 data25 data26 data27 data28 data29 data210",
|
30
|
+
"test3": "data31 data32 data33 data34 data35 data36 data37 data38 data39 data310",
|
31
|
+
"test4" : {
|
32
|
+
"test5": "data5 data6 data7 data8 data9 data10 data11 data12 data13 data14",
|
33
|
+
"test6": "data6 data7 data8 data9 data10 data11 data12 data13 data14 data15",
|
34
|
+
"test7": [
|
35
|
+
"data7",
|
36
|
+
{
|
37
|
+
"test9": "data91 data92 data93 data94 data95 data96 data97 data98 data99 data910",
|
38
|
+
"test10": "data10 data11 data12 data13 data14 data15 data16 data17 data18 data19 data110",
|
39
|
+
}
|
40
|
+
]
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
l.P("Non compressed test", color='g')
|
45
|
+
str_data = json.dumps(data)
|
46
|
+
l.P(f"Data size: {len(str_data)}")
|
47
|
+
encdata = eng1.encrypt(plaintext=str_data, receiver_address=eng2.address)
|
48
|
+
l.P(f"Encrypted data (size: {len(encdata)}): {encdata}")
|
49
|
+
decdata = eng2.decrypt(encrypted_data_b64=encdata, sender_address=eng1.address)
|
50
|
+
l.P(f"Decrypted data:\n {json.dumps(json.loads(decdata), indent=2)}")
|
51
|
+
|
52
|
+
l.P("Compressed test", color='g')
|
53
|
+
str_data = json.dumps(data)
|
54
|
+
l.P(f"Data size: {len(str_data)}")
|
55
|
+
encdata = eng1.encrypt(plaintext=str_data, receiver_address=eng2.address, compressed=True, embed_compressed=False)
|
56
|
+
l.P(f"Encrypted data (size: {len(encdata)}): {encdata}")
|
57
|
+
decdata = eng2.decrypt(encrypted_data_b64=encdata, sender_address=eng1.address, decompress=True, embed_compressed=False)
|
58
|
+
l.P(f"Decrypted data:\n {json.dumps(json.loads(decdata), indent=2)}")
|
59
|
+
|
60
|
+
l.P("Compressed test with embed", color='g')
|
61
|
+
str_data = json.dumps(data)
|
62
|
+
l.P(f"Data size: {len(str_data)}")
|
63
|
+
encdata = eng1.encrypt(plaintext=str_data, receiver_address=eng2.address, compressed=True, embed_compressed=True)
|
64
|
+
l.P(f"Encrypted data (size: {len(encdata)}): {encdata}")
|
65
|
+
decdata = eng2.decrypt(encrypted_data_b64=encdata, sender_address=eng1.address, embed_compressed=True) # decompress does not matter
|
66
|
+
l.P(f"Decrypted data:\n {json.dumps(json.loads(decdata), indent=2)}")
|
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
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/base/distributed_custom_code_presets.py
RENAMED
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
|
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
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/default/instance/net_mon_01_plugin.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/default/session/mqtt_session.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/io_formatter/base/base_formatter.py
RENAMED
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/io_formatter/default/__init__.py
RENAMED
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/io_formatter/default/a_dummy.py
RENAMED
File without changes
|
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/io_formatter/default/default.py
RENAMED
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/io_formatter/io_formatter_manager.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/datetime_mixin.py
RENAMED
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/download_mixin.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/process_mixin.py
RENAMED
File without changes
|
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/timers_mixin.py
RENAMED
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/upload_mixin.py
RENAMED
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/naeural_client/logging/logger_mixins/utils_mixin.py
RENAMED
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
|
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/8. custom_code_fastapi_assets/index.html
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/ex03_custom_code_on_one_remote__example_1.py
RENAMED
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/ex04_custom_code_on_one_remote__example_2.py
RENAMED
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/ex05_custom_code_on_one_remote__example_3.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/tutorials/video_presentation/1. hello_world.ipynb
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/xperimental/_tutorials/4. real_time_custom_code_2.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/xperimental/decentralized/chain_dist_example.py
RENAMED
File without changes
|
File without changes
|
{naeural_client-2.1.3 → naeural_client-2.1.5}/xperimental/decentralized/chain_dist_example_worker.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|