dkg 8.0.3__tar.gz → 8.0.12__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.
Files changed (82) hide show
  1. {dkg-8.0.3 → dkg-8.0.12}/PKG-INFO +2 -2
  2. {dkg-8.0.3 → dkg-8.0.12}/dkg/constants.py +12 -21
  3. {dkg-8.0.3 → dkg-8.0.12}/dkg/modules/asset/asset.py +1 -0
  4. {dkg-8.0.3 → dkg-8.0.12}/dkg/modules/asset/async_asset.py +1 -0
  5. {dkg-8.0.3 → dkg-8.0.12}/dkg/modules/graph/async_graph.py +1 -0
  6. {dkg-8.0.3 → dkg-8.0.12}/dkg/modules/graph/graph.py +1 -0
  7. {dkg-8.0.3 → dkg-8.0.12}/dkg/providers/blockchain/async_blockchain.py +2 -3
  8. {dkg-8.0.3 → dkg-8.0.12}/dkg/providers/blockchain/base_blockchain.py +16 -17
  9. {dkg-8.0.3 → dkg-8.0.12}/dkg/providers/blockchain/blockchain.py +2 -3
  10. {dkg-8.0.3 → dkg-8.0.12}/dkg/types/blockchain.py +1 -1
  11. {dkg-8.0.3 → dkg-8.0.12}/dkg/utils/knowledge_collection_tools.py +22 -2
  12. {dkg-8.0.3 → dkg-8.0.12}/pyproject.toml +1 -1
  13. {dkg-8.0.3 → dkg-8.0.12}/LICENSE +0 -0
  14. {dkg-8.0.3 → dkg-8.0.12}/NOTICE +0 -0
  15. {dkg-8.0.3 → dkg-8.0.12}/README.md +0 -0
  16. {dkg-8.0.3 → dkg-8.0.12}/dkg/__init__.py +0 -0
  17. {dkg-8.0.3 → dkg-8.0.12}/dkg/assertion.py +0 -0
  18. {dkg-8.0.3 → dkg-8.0.12}/dkg/clients/__init__.py +0 -0
  19. {dkg-8.0.3 → dkg-8.0.12}/dkg/clients/async_dkg.py +0 -0
  20. {dkg-8.0.3 → dkg-8.0.12}/dkg/clients/dkg.py +0 -0
  21. {dkg-8.0.3 → dkg-8.0.12}/dkg/data/interfaces/AskStorage.json +0 -0
  22. {dkg-8.0.3 → dkg-8.0.12}/dkg/data/interfaces/Chronos.json +0 -0
  23. {dkg-8.0.3 → dkg-8.0.12}/dkg/data/interfaces/Hub.json +0 -0
  24. {dkg-8.0.3 → dkg-8.0.12}/dkg/data/interfaces/IdentityStorage.json +0 -0
  25. {dkg-8.0.3 → dkg-8.0.12}/dkg/data/interfaces/KnowledgeCollection.json +0 -0
  26. {dkg-8.0.3 → dkg-8.0.12}/dkg/data/interfaces/KnowledgeCollectionStorage.json +0 -0
  27. {dkg-8.0.3 → dkg-8.0.12}/dkg/data/interfaces/Paranet.json +0 -0
  28. {dkg-8.0.3 → dkg-8.0.12}/dkg/data/interfaces/ParanetIncentivesPoolFactory.json +0 -0
  29. {dkg-8.0.3 → dkg-8.0.12}/dkg/data/interfaces/ParanetKnowledgeMinersRegistry.json +0 -0
  30. {dkg-8.0.3 → dkg-8.0.12}/dkg/data/interfaces/ParanetNeuroIncentivesPool.json +0 -0
  31. {dkg-8.0.3 → dkg-8.0.12}/dkg/data/interfaces/ParanetsRegistry.json +0 -0
  32. {dkg-8.0.3 → dkg-8.0.12}/dkg/data/interfaces/Token.json +0 -0
  33. {dkg-8.0.3 → dkg-8.0.12}/dkg/dataclasses.py +0 -0
  34. {dkg-8.0.3 → dkg-8.0.12}/dkg/exceptions.py +0 -0
  35. {dkg-8.0.3 → dkg-8.0.12}/dkg/managers/__init__.py +0 -0
  36. {dkg-8.0.3 → dkg-8.0.12}/dkg/managers/async_manager.py +0 -0
  37. {dkg-8.0.3 → dkg-8.0.12}/dkg/managers/manager.py +0 -0
  38. {dkg-8.0.3 → dkg-8.0.12}/dkg/method.py +0 -0
  39. {dkg-8.0.3 → dkg-8.0.12}/dkg/modules/__init__.py +0 -0
  40. {dkg-8.0.3 → dkg-8.0.12}/dkg/modules/asset/__init__.py +0 -0
  41. {dkg-8.0.3 → dkg-8.0.12}/dkg/modules/async_module.py +0 -0
  42. {dkg-8.0.3 → dkg-8.0.12}/dkg/modules/graph/__init__.py +0 -0
  43. {dkg-8.0.3 → dkg-8.0.12}/dkg/modules/module.py +0 -0
  44. {dkg-8.0.3 → dkg-8.0.12}/dkg/modules/network/__init__.py +0 -0
  45. {dkg-8.0.3 → dkg-8.0.12}/dkg/modules/network/network.py +0 -0
  46. {dkg-8.0.3 → dkg-8.0.12}/dkg/modules/node/__init__.py +0 -0
  47. {dkg-8.0.3 → dkg-8.0.12}/dkg/modules/node/async_node.py +0 -0
  48. {dkg-8.0.3 → dkg-8.0.12}/dkg/modules/node/node.py +0 -0
  49. {dkg-8.0.3 → dkg-8.0.12}/dkg/modules/paranet/__init__.py +0 -0
  50. {dkg-8.0.3 → dkg-8.0.12}/dkg/modules/paranet/paranet.py +0 -0
  51. {dkg-8.0.3 → dkg-8.0.12}/dkg/providers/__init__.py +0 -0
  52. {dkg-8.0.3 → dkg-8.0.12}/dkg/providers/blockchain/__init__.py +0 -0
  53. {dkg-8.0.3 → dkg-8.0.12}/dkg/providers/node/__init__.py +0 -0
  54. {dkg-8.0.3 → dkg-8.0.12}/dkg/providers/node/async_node_http.py +0 -0
  55. {dkg-8.0.3 → dkg-8.0.12}/dkg/providers/node/base_node_http.py +0 -0
  56. {dkg-8.0.3 → dkg-8.0.12}/dkg/providers/node/node_http.py +0 -0
  57. {dkg-8.0.3 → dkg-8.0.12}/dkg/services/__init__.py +0 -0
  58. {dkg-8.0.3 → dkg-8.0.12}/dkg/services/blockchain_services/__init__.py +0 -0
  59. {dkg-8.0.3 → dkg-8.0.12}/dkg/services/blockchain_services/async_blockchain_service.py +0 -0
  60. {dkg-8.0.3 → dkg-8.0.12}/dkg/services/blockchain_services/blockchain_service.py +0 -0
  61. {dkg-8.0.3 → dkg-8.0.12}/dkg/services/input_service.py +0 -0
  62. {dkg-8.0.3 → dkg-8.0.12}/dkg/services/node_services/__init__.py +0 -0
  63. {dkg-8.0.3 → dkg-8.0.12}/dkg/services/node_services/async_node_service.py +0 -0
  64. {dkg-8.0.3 → dkg-8.0.12}/dkg/services/node_services/node_service.py +0 -0
  65. {dkg-8.0.3 → dkg-8.0.12}/dkg/types/__init__.py +0 -0
  66. {dkg-8.0.3 → dkg-8.0.12}/dkg/types/dkg_node.py +0 -0
  67. {dkg-8.0.3 → dkg-8.0.12}/dkg/types/encoding.py +0 -0
  68. {dkg-8.0.3 → dkg-8.0.12}/dkg/types/evm.py +0 -0
  69. {dkg-8.0.3 → dkg-8.0.12}/dkg/types/general.py +0 -0
  70. {dkg-8.0.3 → dkg-8.0.12}/dkg/types/generics.py +0 -0
  71. {dkg-8.0.3 → dkg-8.0.12}/dkg/types/network.py +0 -0
  72. {dkg-8.0.3 → dkg-8.0.12}/dkg/types/rdf.py +0 -0
  73. {dkg-8.0.3 → dkg-8.0.12}/dkg/utils/__init__.py +0 -0
  74. {dkg-8.0.3 → dkg-8.0.12}/dkg/utils/blockchain_request.py +0 -0
  75. {dkg-8.0.3 → dkg-8.0.12}/dkg/utils/decorators.py +0 -0
  76. {dkg-8.0.3 → dkg-8.0.12}/dkg/utils/knowledge_asset_tools.py +0 -0
  77. {dkg-8.0.3 → dkg-8.0.12}/dkg/utils/merkle.py +0 -0
  78. {dkg-8.0.3 → dkg-8.0.12}/dkg/utils/metadata.py +0 -0
  79. {dkg-8.0.3 → dkg-8.0.12}/dkg/utils/node_request.py +0 -0
  80. {dkg-8.0.3 → dkg-8.0.12}/dkg/utils/rdf.py +0 -0
  81. {dkg-8.0.3 → dkg-8.0.12}/dkg/utils/string_transformations.py +0 -0
  82. {dkg-8.0.3 → dkg-8.0.12}/dkg/utils/ual.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: dkg
3
- Version: 8.0.3
3
+ Version: 8.0.12
4
4
  Summary: Python library for interacting with the OriginTrail Decentralized Knowledge Graph
5
5
  License: Apache-2.0
6
6
  Author: Uladzislau Hubar
@@ -35,6 +35,18 @@ CHUNK_BYTE_SIZE = 32
35
35
 
36
36
  MAX_FILE_SIZE = 10000000
37
37
 
38
+ ESCAPE_MAP = {
39
+ "\a": r"\a",
40
+ "\b": r"\b",
41
+ "\f": r"\f",
42
+ "\n": r"\n",
43
+ "\r": r"\r",
44
+ "\t": r"\t",
45
+ "\v": r"\v",
46
+ '"': r"\"",
47
+ "'": r"'",
48
+ }
49
+
38
50
 
39
51
  class DefaultParameters(Enum):
40
52
  ENVIRONMENT: str = "mainnet"
@@ -63,19 +75,9 @@ class OutputTypes(Enum):
63
75
  JSONLD: str = "JSON-LD"
64
76
 
65
77
 
66
- class Environments(Enum):
67
- DEVELOPMENT: str = "development"
68
- DEVNET: str = "devnet"
69
- TESTNET: str = "testnet"
70
- MAINNET: str = "mainnet"
71
-
72
-
73
78
  class BlockchainIds(Enum):
74
79
  HARDHAT_1: str = "hardhat1:31337"
75
80
  HARDHAT_2: str = "hardhat2:31337"
76
- BASE_DEVNET: str = "base:84532"
77
- GNOSIS_DEVNET: str = "gnosis:10200"
78
- NEUROWEB_DEVNET: str = "otp:2160"
79
81
  BASE_TESTNET: str = "base:84532"
80
82
  GNOSIS_TESTNET: str = "gnosis:10200"
81
83
  NEUROWEB_TESTNET: str = "otp:20430"
@@ -102,12 +104,6 @@ BLOCKCHAINS = {
102
104
  "rpc": "http://localhost:9545",
103
105
  },
104
106
  },
105
- "devnet": {
106
- "base:84532": {
107
- "hub": "0xE043daF4cC8ae2c720ef95fc82574a37a429c40A",
108
- "rpc": "https://sepolia.base.org",
109
- }
110
- },
111
107
  "testnet": {
112
108
  "base:84532": {
113
109
  "hub": "0xf21CE8f8b01548D97DCFb36869f1ccB0814a4e05",
@@ -140,11 +136,6 @@ BLOCKCHAINS = {
140
136
 
141
137
  DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS = {
142
138
  "development": {"hardhat1:31337": 2, "hardhat2:31337": 2, "otp:2043": 2},
143
- "devnet": {
144
- "otp:2160": 2,
145
- "gnosis:10200": 2,
146
- "base:84532": 2,
147
- },
148
139
  "testnet": {
149
140
  "otp:20430": 2,
150
141
  "gnosis:10200": 2,
@@ -209,6 +209,7 @@ class KnowledgeAsset(Module):
209
209
  blockchain_id = self.manager.blockchain_provider.blockchain_id
210
210
 
211
211
  dataset = {}
212
+ content = kc_tools.escape_literal_dict(content)
212
213
  public_content = dataset.get("public")
213
214
  private_content = dataset.get("private")
214
215
  if isinstance(content, str):
@@ -240,6 +240,7 @@ class AsyncKnowledgeAsset(AsyncModule):
240
240
  blockchain_id = self.manager.blockchain_provider.blockchain_id
241
241
 
242
242
  dataset = {}
243
+ content = kc_tools.escape_literal_dict(content)
243
244
  public_content = dataset.get("public")
244
245
  private_content = dataset.get("private")
245
246
  if isinstance(content, str):
@@ -57,6 +57,7 @@ class AsyncGraph(AsyncModule):
57
57
  result = await self.node_service.query(
58
58
  query, query_type, repository, paranet_ual
59
59
  )
60
+ result.encoding = "utf-8"
60
61
 
61
62
  return result.get("data")
62
63
 
@@ -50,6 +50,7 @@ class Graph(Module):
50
50
  query_type = parsed_query[1].name.replace("Query", "").upper()
51
51
 
52
52
  result = self.node_service.query(query, query_type, repository, paranet_ual)
53
+ result.encoding = "utf-8"
53
54
 
54
55
  return result.get("data")
55
56
 
@@ -27,7 +27,7 @@ from dkg.exceptions import (
27
27
  AccountMissing,
28
28
  NetworkNotSupported,
29
29
  )
30
- from dkg.types import URI, Address, Environment, Wei
30
+ from dkg.types import URI, Address, Wei
31
31
  from web3.contract import Contract
32
32
  from web3.contract.contract import ContractFunction
33
33
  from web3.types import TxReceipt
@@ -39,13 +39,12 @@ from dkg.providers.blockchain.base_blockchain import BaseBlockchainProvider
39
39
  class AsyncBlockchainProvider(BaseBlockchainProvider):
40
40
  def __init__(
41
41
  self,
42
- environment: Environment,
43
42
  blockchain_id: str,
44
43
  rpc_uri: URI | None = None,
45
44
  gas_price: Wei | None = None,
46
45
  verify: bool = True,
47
46
  ):
48
- super().__init__(environment, blockchain_id, rpc_uri, gas_price)
47
+ super().__init__(blockchain_id, rpc_uri, gas_price)
49
48
 
50
49
  ssl_context = None if verify else False
51
50
  self.w3 = AsyncWeb3(
@@ -8,7 +8,7 @@ from dkg.exceptions import (
8
8
  EnvironmentNotSupported,
9
9
  RPCURINotDefined,
10
10
  )
11
- from dkg.types import URI, DataHexStr, Environment, Wei
11
+ from dkg.types import URI, DataHexStr, Wei
12
12
  from eth_account.signers.local import LocalAccount
13
13
  from eth_typing import ABI, ABIFunction
14
14
  from web3.logs import DISCARD
@@ -21,27 +21,26 @@ class BaseBlockchainProvider:
21
21
 
22
22
  def __init__(
23
23
  self,
24
- environment: Environment,
25
24
  blockchain_id: str,
26
25
  rpc_uri: URI | None = None,
27
26
  gas_price: Wei | None = None,
28
27
  ):
29
- if environment not in BLOCKCHAINS.keys():
30
- raise EnvironmentNotSupported(f"Environment {environment} isn't supported!")
31
-
32
- self.environment = environment
33
- self.rpc_uri = rpc_uri
34
- self.blockchain_id = (
35
- blockchain_id
36
- if blockchain_id in BLOCKCHAINS[self.environment].keys()
37
- else None
38
- )
28
+ self.environment = None
29
+ for env_name, chains_in_env in BLOCKCHAINS.items():
30
+ if blockchain_id in chains_in_env:
31
+ self.environment = env_name
32
+ break
33
+
34
+ if self.environment is None:
35
+ raise EnvironmentNotSupported(
36
+ f"Could not derive environment for blockchain_id: {blockchain_id}. "
37
+ "Ensure it's defined in BLOCKCHAINS constant."
38
+ )
39
39
 
40
- if self.rpc_uri is None and self.blockchain_id is not None:
41
- self.blockchain_id = blockchain_id
42
- self.rpc_uri = self.rpc_uri or BLOCKCHAINS[self.environment][
43
- self.blockchain_id
44
- ].get("rpc", None)
40
+ self.blockchain_id = blockchain_id
41
+ self.rpc_uri = rpc_uri or BLOCKCHAINS[self.environment][self.blockchain_id].get(
42
+ "rpc", None
43
+ )
45
44
 
46
45
  if self.rpc_uri is None:
47
46
  raise RPCURINotDefined(
@@ -26,7 +26,7 @@ from dkg.exceptions import (
26
26
  AccountMissing,
27
27
  NetworkNotSupported,
28
28
  )
29
- from dkg.types import URI, Address, Environment, Wei
29
+ from dkg.types import URI, Address, Wei
30
30
  from web3 import Web3
31
31
  from web3.contract import Contract
32
32
  from web3.contract.contract import ContractFunction
@@ -37,13 +37,12 @@ from dkg.providers.blockchain.base_blockchain import BaseBlockchainProvider
37
37
  class BlockchainProvider(BaseBlockchainProvider):
38
38
  def __init__(
39
39
  self,
40
- environment: Environment,
41
40
  blockchain_id: str,
42
41
  rpc_uri: URI | None = None,
43
42
  gas_price: Wei | None = None,
44
43
  verify: bool = True,
45
44
  ):
46
- super().__init__(environment, blockchain_id, rpc_uri, gas_price)
45
+ super().__init__(blockchain_id, rpc_uri, gas_price)
47
46
 
48
47
  self.w3 = Web3(
49
48
  Web3.HTTPProvider(self.rpc_uri, request_kwargs={"verify": verify})
@@ -50,7 +50,7 @@ ABIElement = ABIFunction | ABIEvent | ABIError
50
50
  ABI = list[ABIElement]
51
51
 
52
52
 
53
- Environment = Literal["development", "devnet", "testnet", "mainnet"]
53
+ Environment = Literal["development", "testnet", "mainnet"]
54
54
 
55
55
 
56
56
  class AgreementData(NamedTuple):
@@ -1,9 +1,10 @@
1
1
  from typing import Literal
2
+ import codecs
2
3
  from dkg.constants import CHUNK_BYTE_SIZE
3
4
  from dkg.exceptions import DatasetInputFormatNotSupported, InvalidDataset
4
5
  from dkg.types import JSONLD, NQuads
5
6
  from pyld import jsonld
6
- from dkg.constants import DEFAULT_RDF_FORMAT, DEFAULT_CANON_ALGORITHM
7
+ from dkg.constants import DEFAULT_RDF_FORMAT, DEFAULT_CANON_ALGORITHM, ESCAPE_MAP
7
8
  from rdflib import Graph, BNode, URIRef, Literal as RDFLiteral
8
9
  from uuid import uuid4
9
10
  from web3 import Web3
@@ -96,7 +97,9 @@ def split_into_chunks(quads, chunk_size_bytes=32):
96
97
  while start < len(encoded_bytes):
97
98
  end = min(start + chunk_size_bytes, len(encoded_bytes))
98
99
  chunk = encoded_bytes[start:end]
99
- chunks.append(chunk.decode("utf-8")) # Decode bytes back to string
100
+ chunks.append(
101
+ codecs.decode(chunk, "utf-8", errors="replace")
102
+ ) # Decode bytes back to string
100
103
  start = end
101
104
 
102
105
  return chunks
@@ -246,3 +249,20 @@ def solidity_packed_sha256(types: list[str], values: list) -> str:
246
249
  sha256_hash = hashlib.sha256(packed_data).hexdigest()
247
250
 
248
251
  return f"0x{sha256_hash}"
252
+
253
+
254
+ def escape_literal_string(s):
255
+ for char, replacement in ESCAPE_MAP.items():
256
+ s = s.replace(char, replacement)
257
+ return s
258
+
259
+
260
+ def escape_literal_dict(obj):
261
+ if isinstance(obj, dict):
262
+ return {k: escape_literal_dict(v) for k, v in obj.items()}
263
+ elif isinstance(obj, list):
264
+ return [escape_literal_dict(i) for i in obj]
265
+ elif isinstance(obj, str):
266
+ return escape_literal_string(s=obj)
267
+ else:
268
+ return obj
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "dkg"
3
- version = "8.0.3"
3
+ version = "8.0.12"
4
4
  description = "Python library for interacting with the OriginTrail Decentralized Knowledge Graph"
5
5
  authors = ["Uladzislau Hubar <hubar.uladzislau@gmail.com>, Zvonimir Sculac <zvonimir.sculac@origin-trail.com>"]
6
6
  license = "Apache-2.0"
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
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