dkg.js 8.0.7 → 8.0.8

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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  <a name="readme-top"></a>
2
2
 
3
- ___
3
+ ---
4
4
 
5
5
  <br />
6
6
  <div align="center">
@@ -15,7 +15,7 @@ ___
15
15
  </br>
16
16
  <a href="https://docs.origintrail.io/">OriginTrail Docs</a>
17
17
  ·
18
- <a href="https://github.com/OriginTrail/dkg.js/examples/demo.js">View Demo</a>
18
+ <a href="https://github.com/OriginTrail/dkg.js/blob/v8/develop/examples/demo.js">View Demo</a>
19
19
  ·
20
20
  <a href="https://github.com/OriginTrail/dkg.js/issues">Report Bug</a>
21
21
  ·
@@ -52,7 +52,7 @@ ___
52
52
  </ol>
53
53
  </details>
54
54
 
55
- ___
55
+ ---
56
56
 
57
57
  <br/>
58
58
 
@@ -62,6 +62,7 @@ ___
62
62
  <summary>
63
63
 
64
64
  ### **What is the Decentralized Knowledge Graph?**
65
+
65
66
  </summary>
66
67
 
67
68
  <br/>
@@ -71,17 +72,19 @@ ___
71
72
  </div>
72
73
 
73
74
  OriginTrail Decentralized Knowledge Graph (DKG), hosted on the OriginTrail Decentralized Network (ODN) as trusted knowledge infrastructure, is shared global Knowledge Graph of Knowledge Assets. Running on the basis of the permissionless multi-chain OriginTrail protocol, it combines blockchains and knowledge graph technology to enable trusted AI applications based on key W3C standards.
75
+
74
76
  </details>
75
77
 
76
78
  <details open>
77
79
  <summary>
78
80
 
79
81
  ### **The OriginTrail DKG Architecture**
82
+
80
83
  </summary>
81
84
 
82
85
  <br/>
83
86
 
84
- The OriginTrail tech stack is a three layer structure, consisting of the multi-chain consensus layer (OriginTrail layer 1, running on multiple blockchains), the Decentralized Knowledge Graph layer (OriginTrail Layer 2, hosted on the ODN) and Trusted Knowledge applications in the application layer.
87
+ The OriginTrail tech stack is a three layer structure, consisting of the multi-chain consensus layer (OriginTrail layer 1, running on multiple blockchains), the Decentralized Knowledge Graph layer (OriginTrail Layer 2, hosted on the ODN) and Trusted Knowledge applications in the application layer.
85
88
 
86
89
  <div align="center">
87
90
  <img src="images/dkg-architecture.png" alt="DKG Architecture" width="400">
@@ -89,13 +92,15 @@ The OriginTrail tech stack is a three layer structure, consisting of the multi-c
89
92
 
90
93
  Further, the architecture differentiates between **the public, replicated knowledge graph** shared by all network nodes according to the protocol, and **private Knowledge graphs** hosted separately by each of the OriginTrail nodes.
91
94
 
92
- **Anyone can run an OriginTrail node and become part of the ODN, contributing to the network capacity and hosting the OriginTrail DKG. The OriginTrail node is the ultimate data service for data and knowledge intensive Web3 applications and is used as the key backbone for trusted AI applications (see https://chatdkg.ai)**
95
+ **Anyone can run an OriginTrail node and become part of the ODN, contributing to the network capacity and hosting the OriginTrail DKG. The OriginTrail node is the ultimate data service for data and knowledge intensive Web3 applications and is used as the key backbone for trusted AI applications (see https://chatdkg.ai)**
96
+
93
97
  </details>
94
98
 
95
99
  <details open>
96
100
  <summary>
97
101
 
98
102
  ### **What is a Knowledge Asset?**
103
+
99
104
  </summary>
100
105
 
101
106
  <br/>
@@ -107,15 +112,16 @@ Further, the architecture differentiates between **the public, replicated knowle
107
112
  **Knowledge Asset is the new, AI‑ready resource for the Internet**
108
113
 
109
114
  Knowledge Assets are verifiable containers of structured knowledge that live on the OriginTrail DKG and provide:
110
- - **Discoverability - UAL is the new URL**. Uniform Asset Locators (UALs, based on the W3C Decentralized Identifiers) are a new Web3 knowledge identifier (extensions of the Uniform Resource Locators - URLs) which identify a specific piece of knowledge and make it easy to find and connect with other Knowledge Assets.
111
- - **Ownership - NFTs enable ownership**. Each Knowledge Asset contains an NFT token that enables ownership, knowledge asset administration and market mechanisms.
112
- - **Verifiability - On-chain information origin and verifiable trail**. The blockchain tech increases trust, security, transparency, and the traceability of information.
113
115
 
116
+ - **Discoverability - UAL is the new URL**. Uniform Asset Locators (UALs, based on the W3C Decentralized Identifiers) are a new Web3 knowledge identifier (extensions of the Uniform Resource Locators - URLs) which identify a specific piece of knowledge and make it easy to find and connect with other Knowledge Assets.
117
+ - **Ownership - NFTs enable ownership**. Each Knowledge Asset contains an NFT token that enables ownership, knowledge asset administration and market mechanisms.
118
+ - **Verifiability - On-chain information origin and verifiable trail**. The blockchain tech increases trust, security, transparency, and the traceability of information.
114
119
 
115
120
  By their nature, Knowledge Assets are semantic resources (following the W3C Semantic Web set of standards), and through their symbolic representations inherently AI ready. See more at https://chatdkg.ai
116
121
  <br/>
117
122
 
118
123
  **Discover Knowledge Assets with the DKG Explorer:**
124
+
119
125
  <div align="center">
120
126
  <table>
121
127
  <tr>
@@ -147,7 +153,6 @@ By their nature, Knowledge Assets are semantic resources (following the W3C Sema
147
153
  </table>
148
154
  </div>
149
155
 
150
-
151
156
  </details>
152
157
 
153
158
  <p align="right">(<a href="#readme-top">back to top</a>)</p>
@@ -155,16 +160,17 @@ By their nature, Knowledge Assets are semantic resources (following the W3C Sema
155
160
 
156
161
  ## 🚀 Getting Started
157
162
 
158
- ___
163
+ ---
159
164
 
160
165
  ### Prerequisites
161
166
 
162
- - **Node.js** >= 16.0.0
163
- - **npm** >= 8.0.0
167
+ - **Node.js** >= 16.0.0
168
+ - **npm** >= 8.0.0
164
169
 
165
170
  In order to use in the local environment, make sure to [run the local DKG network](https://github.com/OriginTrail/ot-node?tab=readme-ov-file#local-network-setup).
166
171
 
167
- ___
172
+ ---
173
+
168
174
  <br/>
169
175
 
170
176
  ### Installation
@@ -172,11 +178,13 @@ ___
172
178
  <br/>
173
179
 
174
180
  Install the SDK:
181
+
175
182
  ```bash
176
183
  npm install dkg.js
177
184
  ```
178
185
 
179
- Now you can run a demo example file (requires the local DKG network running):
186
+ Now you can run a demo example file (requires the local DKG network running):
187
+
180
188
  ```bash
181
189
  node examples/demo.js
182
190
  ```
@@ -246,4 +254,4 @@ Don't forget to give the project a star! Thanks again!
246
254
  </a>
247
255
  </div>
248
256
 
249
- ___
257
+ ---
package/examples/demo.js CHANGED
@@ -60,25 +60,21 @@ function divider() {
60
60
 
61
61
  divider();
62
62
 
63
- console.time('Publish (1 replication, 3 finalizations)');
64
63
  const create_result = await DkgClient.asset.create(content, {
65
64
  epochsNum: 2,
66
65
  minimumNumberOfFinalizationConfirmations: 3,
67
66
  minimumNumberOfNodeReplications: 1,
68
67
  });
69
- console.timeEnd('Publish (1 replication, 3 finalizations)');
70
68
 
71
69
  console.log(JSON.stringify(create_result));
72
70
 
73
71
  divider();
74
72
 
75
- console.time('get');
76
73
  const get_result = await DkgClient.asset.get(create_result.UAL, {
77
74
  contentType: 'all',
78
75
  });
79
76
  console.log('======================== ASSET GET');
80
77
  console.log(get_result);
81
- console.timeEnd('get');
82
78
 
83
79
  divider();
84
80
 
@@ -87,15 +83,14 @@ function divider() {
87
83
  console.log(publishFinalityResult);
88
84
 
89
85
  divider();
90
-
91
86
  const queryOperationResult = await DkgClient.graph.query(
92
87
  `
93
- PREFIX SCHEMA: <http://schema.org/>
88
+ PREFIX schema: <http://schema.org/>
94
89
  SELECT ?s ?stateName
95
- WHERE {
96
- ?s schema:state ?stateName .
90
+ WHERE {
91
+ ?s schema:state ?stateName .
97
92
  }
98
- `,
93
+ `,
99
94
  'SELECT',
100
95
  );
101
96
  console.log('======================== ASSET QUERY');
@@ -108,7 +108,7 @@ function divider() {
108
108
  console.log(incentivesPoolStorageAddressResult);
109
109
  divider();
110
110
 
111
- // Fund the incentives pool storage contract
111
+ // Fund the incentives pool storage contract - Works on DEVELOPMENT ONLY
112
112
  const web3 = await DkgClient.blockchain.getWeb3Instance();
113
113
  const incentivesAmount = web3.utils.toWei('100', 'ether');
114
114
  const txHash = await web3.eth.sendTransaction({
@@ -251,7 +251,6 @@ function divider() {
251
251
  console.log(
252
252
  '======================== IS MINER : ',
253
253
  await DkgClient.paranet.isKnowledgeMiner(paranetUAL, {
254
- roleAddress: '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
255
254
  incentivesPoolName: incentivesPoolOptions.incentivesPoolName,
256
255
  }),
257
256
  );
@@ -1,15 +1,10 @@
1
- import { kaTools, kcTools } from 'assertion-tools';
1
+ import { kaTools } from 'assertion-tools';
2
2
  import { ethers } from 'ethers';
3
3
  import {
4
4
  OPERATIONS,
5
- CHUNK_BYTE_SIZE,
6
- OPERATION_STATUSES,
7
5
  PRIVATE_RESOURCE_PREDICATE,
8
6
  PRIVATE_HASH_SUBJECT_PREFIX,
9
7
  } from '../constants.js';
10
- import { getOperationStatusObject, deriveUAL } from '../services/utilities.js';
11
- import emptyHooks from '../util/empty-hooks.js';
12
-
13
8
  export default class GraphOperationsManager {
14
9
  constructor(services) {
15
10
  this.nodeApiService = services.nodeApiService;
@@ -41,7 +36,7 @@ export default class GraphOperationsManager {
41
36
  repository,
42
37
  );
43
38
 
44
- const operationId = await this.nodeApiService.query(
39
+ return this.nodeApiService.query(
45
40
  endpoint,
46
41
  port,
47
42
  authToken,
@@ -50,16 +45,6 @@ export default class GraphOperationsManager {
50
45
  paranetUAL,
51
46
  repository,
52
47
  );
53
-
54
- return this.nodeApiService.getOperationResult(
55
- endpoint,
56
- port,
57
- authToken,
58
- OPERATIONS.QUERY,
59
- maxNumberOfRetries,
60
- frequency,
61
- operationId,
62
- );
63
48
  }
64
49
 
65
50
  generatePrivateRepresentation(privateSubject) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dkg.js",
3
- "version": "8.0.7",
3
+ "version": "8.0.8",
4
4
  "description": "Javascript library for interaction with the OriginTrail Decentralized Knowledge Graph",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -30,6 +30,7 @@ const KnowledgeCollectionAbi = require('dkg-evm-module/abi/KnowledgeCollection.j
30
30
  const KnowledgeCollectionStorageAbi = require('dkg-evm-module/abi/KnowledgeCollectionStorage.json');
31
31
  const AskStorageAbi = require('dkg-evm-module/abi/AskStorage.json');
32
32
  const ChronosAbi = require('dkg-evm-module/abi/Chronos.json');
33
+ const IERC20ExtendedAbi = require('dkg-evm-module/abi/IERC20Extended.json');
33
34
 
34
35
  export default class BlockchainServiceBase {
35
36
  constructor(config = {}) {
@@ -50,6 +51,7 @@ export default class BlockchainServiceBase {
50
51
  this.abis.AskStorage = AskStorageAbi;
51
52
  this.abis.Chronos = ChronosAbi;
52
53
  this.abis.ParanetStagingRegistry = ParanetStagingRegistryAbi;
54
+ this.abis.IERC20Extended = IERC20ExtendedAbi;
53
55
  this.abis.KnowledgeCollectionStorage.filter((obj) => obj.type === 'event').forEach(
54
56
  (event) => {
55
57
  const concatInputs = event.inputs.map((input) => input.internalType);
@@ -1073,7 +1075,7 @@ export default class BlockchainServiceBase {
1073
1075
 
1074
1076
  await this.setIncentivesPool(incentivesPoolAddress, blockchain);
1075
1077
 
1076
- return this.executeContractFunction(
1078
+ return this.callContractFunction(
1077
1079
  'ParanetIncentivesPool',
1078
1080
  'paranetIncentivesPoolStorage',
1079
1081
  [],
@@ -1215,18 +1217,8 @@ export default class BlockchainServiceBase {
1215
1217
  incentivesPoolStorageAddress: options.incentivesPoolStorageAddress,
1216
1218
  });
1217
1219
 
1218
- console.log('Incentives Pool Address:', incentivesPoolAddress);
1219
-
1220
1220
  await this.setIncentivesPool(incentivesPoolAddress, blockchain);
1221
1221
 
1222
- // Add debug logs for contract instance
1223
- const contractInstance = await this.getContractInstance(
1224
- 'ParanetIncentivesPool',
1225
- blockchain,
1226
- );
1227
- console.log('Contract Instance Address:', contractInstance.options.address);
1228
- console.log('Available Methods:', Object.keys(contractInstance.methods));
1229
-
1230
1222
  return this.callContractFunction(
1231
1223
  'ParanetIncentivesPool',
1232
1224
  'isKnowledgeMiner',
@@ -1401,16 +1393,21 @@ export default class BlockchainServiceBase {
1401
1393
  async adjustEmissionMultiplier(rewardTokenAddress, tracToTokenEmissionMultiplier, blockchain) {
1402
1394
  if (rewardTokenAddress !== ZERO_ADDRESS) {
1403
1395
  // Create contract instance for ERC20 token
1404
- const tokenContract = new blockchain.web3.eth.Contract(
1396
+ await this.ensureBlockchainInfo(blockchain);
1397
+ const web3Instance = await this.getWeb3Instance(blockchain);
1398
+ const tokenContract = new web3Instance.eth.Contract(
1405
1399
  this.abis.IERC20Extended,
1406
1400
  rewardTokenAddress,
1407
1401
  );
1408
1402
 
1409
1403
  try {
1410
1404
  const decimals = await tokenContract.methods.decimals().call();
1411
- return (BigInt(tracToTokenEmissionMultiplier) * BigInt(10)) ** BigInt(decimals);
1405
+ return BigInt(tracToTokenEmissionMultiplier) * BigInt(10) ** BigInt(decimals);
1412
1406
  } catch (error) {
1413
- throw new Error('ERC20 token is missing decimals function');
1407
+ console.log(
1408
+ 'ERC20 token is missing decimals function, adding 18 decimals as default',
1409
+ );
1410
+ return BigInt(tracToTokenEmissionMultiplier) * BigInt(10) ** BigInt(18);
1414
1411
  }
1415
1412
  } else {
1416
1413
  // Neuroweb chains use 12 decimals
@@ -130,11 +130,11 @@ export default class HttpService {
130
130
  try {
131
131
  const response = await axios({
132
132
  method: 'post',
133
- url: `${this.getBaseUrl(endpoint, port)}/query`,
133
+ url: `${this.getBaseUrl(endpoint, port)}/direct-query`,
134
134
  data: { query, type, repository, paranetUAL },
135
135
  headers: this.prepareRequestConfig(authToken),
136
136
  });
137
- return response.data.operationId;
137
+ return response.data;
138
138
  } catch (error) {
139
139
  throw Error(`Unable to query: ${error.message}`);
140
140
  }