naeural-client 2.6.25__py3-none-any.whl → 2.6.27__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 CHANGED
@@ -1,4 +1,4 @@
1
- __VER__ = "2.6.25"
1
+ __VER__ = "2.6.27"
2
2
 
3
3
  if __name__ == "__main__":
4
4
  with open("pyproject.toml", "rt") as fd:
naeural_client/bc/base.py CHANGED
@@ -542,10 +542,63 @@ class BaseBlockEngine:
542
542
  except:
543
543
  result = False
544
544
  return result
545
-
546
545
 
547
- def _load_and_maybe_create_allowed(self):
546
+
547
+ def add_address_to_allowed(self, address : any):
548
+ """
549
+ Adds a new address or a list of addresses to the allowed list
550
+ """
551
+ changed = False
552
+ if isinstance(address, str):
553
+ address = [address]
554
+ #endif
555
+ if isinstance(address, list) and len(address) > 0:
556
+ # self.P(f"Adding addresses to the allowed list:\n{address}", verbosity=1)
557
+ # now check addresses
558
+ lst_addresses = []
559
+ lst_names = []
560
+ for addr in address:
561
+ addr = addr.strip()
562
+ parts = addr.split()
563
+ if len(parts) == 0:
564
+ continue
565
+ addr = parts[0]
566
+ name = parts[1] if len(parts) > 1 else ""
567
+ if not self.address_is_valid(addr):
568
+ self.P("WARNING: address <{}> is not valid. Ignoring.".format(addr), color='r')
569
+ else:
570
+ lst_addresses.append(self.maybe_add_prefix(addr))
571
+ lst_names.append(name)
572
+ #endif
573
+ #endfor
574
+ if len(lst_addresses) > 0:
575
+ existing_addrs, existing_names = self._load_and_maybe_create_allowed(return_names=True)
576
+ existing_addrs = [self.maybe_add_prefix(x) for x in existing_addrs]
577
+ for addr, name in zip(lst_addresses, lst_names):
578
+ if addr not in existing_addrs:
579
+ changed = True
580
+ existing_addrs.append(addr)
581
+ existing_names.append(name)
582
+ self.P("Address <{}{}> added to the allowed list.".format(addr, name), color='g')
583
+ #endif new address
584
+ #endfor
585
+ if changed:
586
+ with self._whitelist_lock:
587
+ fn = self._get_allowed_file()
588
+ with open(fn, 'wt') as fh:
589
+ for addr, name in zip(existing_addrs, existing_names):
590
+ fh.write("{}{}\n".format(addr, (" " + name) if len(name)>0 else ""))
591
+ #endfor each address in modified whitelist
592
+ #endwith open file
593
+ #endwith lock
594
+ #endif changed
595
+ #endif addresses received ok
596
+ return changed
597
+
598
+
599
+ def _load_and_maybe_create_allowed(self, return_names=False, return_prefix=False):
548
600
  lst_final = []
601
+ lst_names = []
549
602
  with self._whitelist_lock:
550
603
  try:
551
604
  fn = self._get_allowed_file()
@@ -563,16 +616,21 @@ class BaseBlockEngine:
563
616
  lst_lines = []
564
617
  errors = False
565
618
  for allowed_tuple in lst_allowed:
566
- allowed = allowed_tuple.split()[0]
619
+ parts = allowed_tuple.split()
620
+ if len(parts) == 0:
621
+ continue
622
+ allowed = parts[0]
567
623
  allowed = self._remove_prefix(allowed)
624
+ name = parts[1] if len(parts) > 1 else ""
568
625
  if not self.address_is_valid(allowed):
569
626
  self.P("WARNING: address <{}> is not valid. Removing {} from allowed list.".format(
570
627
  allowed, allowed_tuple), color='r'
571
628
  )
572
629
  errors = True
573
630
  else:
574
- lst_final.append(allowed)
631
+ lst_final.append(self.maybe_add_prefix(allowed))
575
632
  lst_lines.append(allowed_tuple)
633
+ lst_names.append(name)
576
634
  if errors:
577
635
  with open(fn, 'wt') as fh:
578
636
  for line in lst_lines:
@@ -581,6 +639,8 @@ class BaseBlockEngine:
581
639
  self.P(f"ERROR: failed to load the allowed list of addresses: {exc}", color='r')
582
640
  #endtry
583
641
  #endwith
642
+ if return_names:
643
+ return lst_final, lst_names
584
644
  return lst_final
585
645
 
586
646
 
@@ -900,6 +960,13 @@ class BaseBlockEngine:
900
960
  """Returns the allowed command senders for the current node"""
901
961
  return self.allowed_list
902
962
 
963
+ @property
964
+ def whitelist_with_names(self):
965
+ """
966
+ Returns a tuple with the allowed list (prefixed) and a list with names
967
+ """
968
+ return self._load_and_maybe_create_allowed(return_names=True, return_prefix=True)
969
+
903
970
 
904
971
  def maybe_remove_prefix(self, address):
905
972
  """
@@ -1253,6 +1320,52 @@ class BaseBlockEngine:
1253
1320
  def eth_account(self):
1254
1321
  return self.__eth_account
1255
1322
 
1323
+ @staticmethod
1324
+ def is_valid_evm_address(address: str) -> bool:
1325
+ """
1326
+ Check if the input string is a valid Ethereum (EVM) address using basic heuristics.
1327
+
1328
+ Parameters
1329
+ ----------
1330
+ address : str
1331
+ The address string to verify.
1332
+
1333
+ Returns
1334
+ -------
1335
+ bool
1336
+ True if `address` meets the basic criteria for an EVM address, False otherwise.
1337
+ """
1338
+ # Basic checks:
1339
+ # A) Must start with '0x'
1340
+ # B) Must be exactly 42 characters in total
1341
+ # C) All remaining characters must be valid hexadecimal digits
1342
+ if not address.startswith("0x"):
1343
+ return False
1344
+ if len(address) != 42:
1345
+ return False
1346
+
1347
+ hex_part = address[2:]
1348
+ # Ensure all characters in the hex part are valid hex digits
1349
+ return all(c in "0123456789abcdefABCDEF" for c in hex_part)
1350
+
1351
+ @staticmethod
1352
+ def is_valid_eth_address(address: str) -> bool:
1353
+ """
1354
+ Check if the input string is a valid Ethereum (EVM) address using basic heuristics.
1355
+
1356
+ Parameters
1357
+ ----------
1358
+ address : str
1359
+ The address string to verify.
1360
+
1361
+ Returns
1362
+ -------
1363
+ bool
1364
+ True if `address` meets the basic criteria for an EVM address, False otherwise.
1365
+ """
1366
+ return BaseBlockEngine.is_valid_evm_address(address)
1367
+
1368
+
1256
1369
  ### end Ethereum
1257
1370
 
1258
1371
 
@@ -1,3 +1,8 @@
1
+ """
2
+ TODO: add signature check for the oracle data
3
+
4
+ """
5
+
1
6
  import requests
2
7
  import time
3
8
  import json
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: naeural_client
3
- Version: 2.6.25
3
+ Version: 2.6.27
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/NaeuralEdgeProtocol/naeural_client
6
6
  Project-URL: Bug Tracker, https://github.com/NaeuralEdgeProtocol/naeural_client/issues
@@ -1,5 +1,5 @@
1
1
  naeural_client/__init__.py,sha256=YimqgDbjLuywsf8zCWE0EaUXH4MBUrqLxt0TDV558hQ,632
2
- naeural_client/_ver.py,sha256=VzTUOXifPU_gElHsx6mudwBFePv-yOYf47lefXA00DI,331
2
+ naeural_client/_ver.py,sha256=Yz-umaskmmy3SGQA4LtCO3eIsBcFLfPh9-24KjHp6hk,331
3
3
  naeural_client/base_decentra_object.py,sha256=C4iwZTkhKNBS4VHlJs5DfElRYLo4Q9l1V1DNVSk1fyQ,4412
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
@@ -14,7 +14,7 @@ naeural_client/base/webapp_pipeline.py,sha256=QmPLVmhP0CPdi0YuvbZEH4APYz2Amtw3gy
14
14
  naeural_client/base/payload/__init__.py,sha256=y8fBI8tG2ObNfaXFWjyWZXwu878FRYj_I8GIbHT4GKE,29
15
15
  naeural_client/base/payload/payload.py,sha256=x-au7l67Z_vfn_4R2C_pjZCaFuUVXHngJiGOfIAYVdE,2690
16
16
  naeural_client/bc/__init__.py,sha256=FQj23D1PrY06NUOARiKQi4cdj0-VxnoYgYDEht8lpr8,158
17
- naeural_client/bc/base.py,sha256=f6FbBIGhP_2siTNENVUp_RWKsECqXRq6xiQkgOPG_PA,36454
17
+ naeural_client/bc/base.py,sha256=FEzIterEL8ZOPO8cwlPQB0g16fY4q9fp8X8YtkJ8PpA,40169
18
18
  naeural_client/bc/chain.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  naeural_client/bc/ec.py,sha256=qI8l7YqiS4MNftlx-tF7IZUswrSeQc7KMn5OZ0fEaJs,23370
20
20
  naeural_client/certs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -82,9 +82,9 @@ naeural_client/utils/__init__.py,sha256=mAnke3-MeRzz3nhQvhuHqLnpaaCSmDxicd7Ck9uw
82
82
  naeural_client/utils/comm_utils.py,sha256=4cS9llRr_pK_3rNgDcRMCQwYPO0kcNU7AdWy_LtMyCY,1072
83
83
  naeural_client/utils/config.py,sha256=v7xHikr6Z5Sbvf3opYeMhYzGWD2pe0HlRwa-aGJzUh8,6323
84
84
  naeural_client/utils/dotenv.py,sha256=_AgSo35n7EnQv5yDyu7C7i0kHragLJoCGydHjvOkrYY,2008
85
- naeural_client/utils/oracle_sync/multiple_requests.py,sha256=SYzhC2mLnDBZ9cEJyLeljax8p8dQTFO3dWqGaUV4jvY,20836
86
- naeural_client-2.6.25.dist-info/METADATA,sha256=j7rLxmjqRSMSnSF7Q5HoAVQN1C6c1dRk-e1xj2KOaJ4,12354
87
- naeural_client-2.6.25.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
88
- naeural_client-2.6.25.dist-info/entry_points.txt,sha256=PNdyotDaQBAslZREx5luVyj0kqpQnwNACwkFNTPIHU4,55
89
- naeural_client-2.6.25.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
90
- naeural_client-2.6.25.dist-info/RECORD,,
85
+ naeural_client/utils/oracle_sync/multiple_requests.py,sha256=GLzROGZ0gI4d1PVWgW_JBUYZjEL4LqZvHvwelxDiPW4,20892
86
+ naeural_client-2.6.27.dist-info/METADATA,sha256=rde6sZu0nzqXIJHVbDh8ZNizuzjDhkdAl3TlzSj8BS0,12354
87
+ naeural_client-2.6.27.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
88
+ naeural_client-2.6.27.dist-info/entry_points.txt,sha256=PNdyotDaQBAslZREx5luVyj0kqpQnwNACwkFNTPIHU4,55
89
+ naeural_client-2.6.27.dist-info/licenses/LICENSE,sha256=cvOsJVslde4oIaTCadabXnPqZmzcBO2f2zwXZRmJEbE,11311
90
+ naeural_client-2.6.27.dist-info/RECORD,,