dkg.js 8.0.4 → 8.0.6

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/.env.example ADDED
@@ -0,0 +1 @@
1
+ PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
package/constants.js CHANGED
@@ -20,8 +20,25 @@ export const PRIVATE_HASH_SUBJECT_PREFIX = 'https://ontology.origintrail.io/dkg/
20
20
 
21
21
  export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
22
22
 
23
- export const LABEL_PREFIX = '<http://example.org/label>';
24
-
23
+ export const BLOCKCHAIN_IDS = {
24
+ HARDHAT_1: 'hardhat1:31337',
25
+ HARDHAT_2: 'hardhat2:31337',
26
+ BASE_DEVNET: 'base:84532',
27
+ GNOSIS_DEVNET: 'gnosis:10200',
28
+ NEUROWEB_DEVNET: 'otp:2160',
29
+ BASE_TESTNET: 'base:84532',
30
+ GNOSIS_TESTNET: 'gnosis:10200',
31
+ NEUROWEB_TESTNET: 'otp:20430',
32
+ BASE_MAINNET: 'base:8453',
33
+ GNOSIS_MAINNET: 'gnosis:100',
34
+ NEUROWEB_MAINNET: 'otp:2043',
35
+ };
36
+ export const ENVIRONMENTS = {
37
+ MAINNET: 'mainnet',
38
+ TESTNET: 'testnet',
39
+ DEVNET: 'devnet',
40
+ DEVELOPMENT: 'development',
41
+ };
25
42
  export const BLOCKCHAINS = {
26
43
  development: {
27
44
  'hardhat1:31337': {
@@ -105,8 +122,6 @@ export const BLOCKCHAINS_RENAME_PAIRS = {
105
122
  'otp::mainnet': 'otp:2043',
106
123
  };
107
124
 
108
- export const MAX_BLOCKCHAIN_CALL_RETRIES = 3;
109
-
110
125
  export const TRANSACTION_RETRY_ERRORS = [
111
126
  'transaction was not mined',
112
127
  'already known',
@@ -140,15 +155,6 @@ export const OPERATION_STATUSES = {
140
155
  FAILED: 'FAILED',
141
156
  };
142
157
 
143
- export const OPERATION_DELAYS = {
144
- FINALITY: 5000,
145
- };
146
-
147
- export const ASSERTION_STATES = {
148
- LATEST: 'latest',
149
- LATEST_FINALIZED: 'latest_finalized',
150
- };
151
-
152
158
  export const CONTENT_TYPES = {
153
159
  PRIVATE: 'private',
154
160
  PUBLIC: 'public',
@@ -160,12 +166,6 @@ export const GET_OUTPUT_FORMATS = {
160
166
  JSON_LD: 'json-ld',
161
167
  };
162
168
 
163
- export const STORE_TYPES = {
164
- TRIPLE: 'TRIPLE',
165
- TRIPLE_PARANET: 'TRIPLE_PARANET',
166
- PENDING: 'PENDING',
167
- };
168
-
169
169
  export const GRAPH_LOCATIONS = {
170
170
  PUBLIC_KG: 'PUBLIC_KG',
171
171
  LOCAL_KG: 'LOCAL_KG',
@@ -194,8 +194,6 @@ export const OPERATIONS_STEP_STATUS = {
194
194
  NETWORK_PUBLISH_COMPLETED: 'NETWORK_PUBLISH_COMPLETED',
195
195
  };
196
196
 
197
- export const DEFAULT_GET_LOCAL_STORE_RESULT_FREQUENCY = 0.5;
198
-
199
197
  export const DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS = {
200
198
  development: { 'hardhat1:31337': 2, 'hardhat2:31337': 2, 'otp:2043': 2 },
201
199
  devnet: {
@@ -259,17 +257,6 @@ export const DEFAULT_GAS_PRICE_WEI = {
259
257
  GNOSIS: '6000000000',
260
258
  };
261
259
 
262
- export const LOW_BID_SUGGESTION = 'low';
263
- export const MED_BID_SUGGESTION = 'med';
264
- export const HIGH_BID_SUGGESTION = 'high';
265
- export const ALL_BID_SUGGESTION = 'all';
266
- export const BID_SUGGESTION_RANGE_ENUM = [
267
- LOW_BID_SUGGESTION,
268
- MED_BID_SUGGESTION,
269
- HIGH_BID_SUGGESTION,
270
- ALL_BID_SUGGESTION,
271
- ];
272
-
273
260
  export const PARANET_KNOWLEDGE_ASSET_ACCESS_POLICY = {
274
261
  OPEN: 0,
275
262
  };
package/examples/demo.js CHANGED
@@ -1,21 +1,22 @@
1
- import jsonld from 'jsonld';
2
1
  import DKG from '../index.js';
3
- import { sleepForMilliseconds } from '../services/utilities.js';
2
+ import { BLOCKCHAIN_IDS, ENVIRONMENTS } from '../constants.js';
3
+ import dotenv from 'dotenv';
4
4
 
5
- const ENVIRONMENT = 'development';
5
+ dotenv.config();
6
+
7
+ const ENVIRONMENT = ENVIRONMENTS.DEVELOPMENT;
6
8
  const OT_NODE_HOSTNAME = 'http://localhost';
7
9
  const OT_NODE_PORT = '8900';
8
10
  const PUBLIC_KEY = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
9
- const PRIVATE_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';
10
11
 
11
12
  const DkgClient = new DKG({
12
13
  environment: ENVIRONMENT,
13
14
  endpoint: OT_NODE_HOSTNAME,
14
15
  port: OT_NODE_PORT,
15
16
  blockchain: {
16
- name: 'hardhat1',
17
+ name: BLOCKCHAIN_IDS.HARDHAT_1,
17
18
  publicKey: PUBLIC_KEY,
18
- privateKey: PRIVATE_KEY,
19
+ privateKey: process.env.PRIVATE_KEY,
19
20
  },
20
21
  maxNumberOfRetries: 300,
21
22
  frequency: 2,
@@ -30,175 +31,74 @@ function divider() {
30
31
  }
31
32
 
32
33
  (async () => {
33
- // const content = {
34
- // private: ``,
35
- // };
36
-
37
- // const privatePart = [];
38
-
39
- // for (let i = 0; i < 1000; i++) {
40
- // privatePart.push(`<uuid:${i}> <http://schema.org/company> "OT" .`);
41
- // }
42
-
43
- // content.private = privatePart.join('\n');
44
-
45
34
  const content = {
35
+ public: {
36
+ '@context': 'https://www.schema.org',
37
+ '@id': 'urn:us-cities:info:new-york',
38
+ '@type': 'City',
39
+ name: 'New York',
40
+ state: 'New York',
41
+ population: '8,336,817',
42
+ area: '468.9 sq mi',
43
+ },
46
44
  private: {
47
45
  '@context': 'https://www.schema.org',
48
- '@id': 'urn:eu-pp:safety-test:3oRIwPtUOJapwNSAGZTzCOWR9bEo',
49
- '@type': 'ProductSafetyTest',
50
- testType: 'Functional Safety Test',
51
- testResults: 'Fail',
52
- relatedProduct: [
53
- {
54
- '@id': 'urn:epc:id:sgtin:59G1yu8uivSRKLLu',
55
- name: '59G1yu8uivSRKLLu',
56
- },
46
+ '@id': 'urn:us-cities:data:new-york',
47
+ '@type': 'CityPrivateData',
48
+ crimeRate: 'Low',
49
+ averageIncome: '$63,998',
50
+ infrastructureScore: '8.5',
51
+ relatedCities: [
52
+ { '@id': 'urn:us-cities:info:los-angeles', name: 'Los Angeles' },
53
+ { '@id': 'urn:us-cities:info:chicago', name: 'Chicago' },
57
54
  ],
58
55
  },
59
56
  };
60
57
 
61
- // divider();
62
-
63
58
  const nodeInfo = await DkgClient.node.info();
64
59
  console.log('======================== NODE INFO RECEIVED');
65
60
  console.log(nodeInfo);
66
61
 
67
62
  divider();
68
63
 
69
- // console.time('Publish (1 replication, 3 finalizations)')
70
- // const result0 = await DkgClient.asset.create(content, {
71
- // epochsNum: 2,
72
- // tokenAmount: '100',
73
- // minimumNumberOfFinalizationConfirmations: 3,
74
- // minimumNumberOfNodeReplications: 1,
75
- // });
76
- // console.timeEnd('Publish (1 replication, 3 finalizations)')
77
-
78
- // console.log(JSON.stringify(result0));
79
-
80
- // divider();
81
-
82
- // console.time('Publish (1 replication, 1 finalization)');
83
- // const result1 = await DkgClient.asset.create(content, {
84
- // epochsNum: 2,
85
- // tokenAmount: '100',
86
- // minimumNumberOfFinalizationConfirmations: 1,
87
- // minimumNumberOfNodeReplications: 1,
88
- // });
89
- // console.timeEnd('Publish (1 replication, 1 finalization)');
90
-
91
- // console.log(JSON.stringify(result1));
92
-
93
- // divider();
94
-
95
- // console.time('Publish (3 replications, 1 finalizations)');
96
- // const result2 = await DkgClient.asset.create(content, {
97
- // epochsNum: 2,
98
- // minimumNumberOfFinalizationConfirmations: 1,
99
- // minimumNumberOfNodeReplications: 3,
100
- // });
101
- // console.timeEnd('Publish (3 replications, 1 finalizations)');
102
-
103
- // console.log(result2);
104
-
105
- // await sleepForMilliseconds(15000);
106
-
107
- // console.time('aaaaa');
108
- // const result3 = await DkgClient.asset.get(
109
- // 'did:dkg:otp/0x1a061136ed9f5ed69395f18961a0a535ef4b3e5f/243039',
110
- // {
111
- // contentType: 'all',
112
- // },
113
- // );
114
- // console.timeEnd('aaaa');
64
+ console.time('Publish (1 replication, 3 finalizations)');
65
+ const create_result = await DkgClient.asset.create(content, {
66
+ epochsNum: 2,
67
+ minimumNumberOfFinalizationConfirmations: 3,
68
+ minimumNumberOfNodeReplications: 1,
69
+ });
70
+ console.timeEnd('Publish (1 replication, 3 finalizations)');
115
71
 
116
- // console.log(result3);
72
+ console.log(JSON.stringify(create_result));
117
73
 
118
- // divider();
119
-
120
- // console.time('Publish (5 replications, 5 finalizations)');
121
- // const result3 = await DkgClient.asset.create(content, {
122
- // epochsNum: 2,
123
- // minimumNumberOfFinalizationConfirmations: 3,
124
- // minimumNumberOfNodeReplications: 3,
125
- // });
126
- // console.timeEnd('Publish (5 replications, 5 finalizations)');
127
-
128
- // console.log(JSON.stringify(result3, null, 2));
129
-
130
- // divider();
131
-
132
- // const createCollectionResult = await DkgClient.graph.create(content, {
133
- // epochsNum: 2,
134
- // tokenAmount: '100',
135
- // minimumNumberOfFinalizationConfirmations: 1,
136
- // });
137
- // console.log('======================== ASSET CREATED');
138
- // console.log(createCollectionResult);
139
-
140
- // divider();
74
+ divider();
141
75
 
142
- // const publishFinalityResult = await DkgClient.graph.publishFinality(createAssetResult.UAL);
143
- // console.log('======================== ASSET FINALITY');
144
- // console.log(publishFinalityResult);
145
76
  console.time('get');
146
- const getOperationResult = await DkgClient.graph.get(
147
- 'did:dkg:base:84532/0xd5550173b0f7b8766ab2770e4ba86caf714a5af5/2',
148
- );
77
+ const get_result = await DkgClient.asset.get(create_result.UAL, {
78
+ contentType: 'all',
79
+ });
149
80
  console.log('======================== ASSET GET');
150
- console.log(getOperationResult);
81
+ console.log(get_result);
151
82
  console.timeEnd('get');
152
83
 
153
- // divider();
154
-
155
- // const queryOperationResult = await DkgClient.graph.query(
156
- // `PREFIX gs1: <https://gs1.org/voc/>
157
- // PREFIX schema: <http://schema.org/>
158
-
159
- // SELECT ?recipeNameRaw ?baseUal
160
- // WHERE {
161
- // ?recipe a schema:Recipe ;
162
- // GRAPH ?ual {
163
- // ?recipe schema:name ?recipeNameRaw ;
164
- // }
165
- // FILTER (STRSTARTS(STR(?ual), "did:dkg:base:84532/0x4e8ebfce9a0f4be374709f1ef2791e8ca6371ecb/"))
166
- // BIND (REPLACE(STR(?ual), "(did:dkg:base:[^/]+/[^/]+/[^/]+)(/.*)?", "$1") AS ?baseUal)
167
- // }`,
168
- // 'SELECT',
169
- // {
170
- // graphLocation: 'LOCAL_KG',
171
- // graphState: 'CURRENT',
172
- // },
173
- // );
174
- // console.log('======================== ASSET QUERY');
175
- // console.log(queryOperationResult);
176
-
177
- // console.time('Publish (3 replications, 1 finalizations)');
178
-
179
- // const queryOperationResult1 = await DkgClient.graph.query(
180
- // `CONSTRUCT { ?s ?p ?o .}WHERE { GRAPH ?g { ?s ?p ?o . } VALUES ?g { <did:dkg:gnosis:10200/0xcdd5ce31fe2181490348ef6fd9f782d575776e5b/4/1/public> <did:dkg:gnosis:10200/0xcdd5ce31fe2181490348ef6fd9f782d575776e5b/4/2/public> }}`,
181
- // 'CONSTRUCT',
182
- // );
183
- // console.log('======================== ASSET QUERY');
184
- // console.log(JSON.stringify(queryOperationResult1));
185
-
186
- // divider();
187
-
188
- // console.timeEnd('Publish (3 replications, 1 finalizations)');
189
- // console.time('aaaa');
190
-
191
- // console.time('Query (3 replications, 1 finalizations)');
84
+ divider();
192
85
 
193
- // const queryOperationResult = await DkgClient.graph.query(
194
- // `CONSTRUCT { ?s ?p ?o .} WHERE { { GRAPH <did:dkg:gnosis:10200/0xcdd5ce31fe2181490348ef6fd9f782d575776e5b/4/1/public> { ?s ?p ?o . } } UNION { GRAPH <did:dkg:gnosis:10200/0xcdd5ce31fe2181490348ef6fd9f782d575776e5b/4/2/public> { ?s ?p ?o . } } }`,
195
- // 'CONSTRUCT',
196
- // );
197
- // console.log('======================== ASSET QUERY');
198
- // console.log(JSON.stringify(queryOperationResult));
86
+ const publishFinalityResult = await DkgClient.graph.publishFinality(create_result.UAL);
87
+ console.log('======================== ASSET FINALITY');
88
+ console.log(publishFinalityResult);
199
89
 
200
- // // divider();
90
+ divider();
201
91
 
202
- // console.timeEnd('Query (3 replications, 1 finalizations)');
203
- // console.time('aaaa');
92
+ const queryOperationResult = await DkgClient.graph.query(
93
+ `
94
+ PREFIX SCHEMA: <http://schema.org/>
95
+ SELECT ?s ?stateName
96
+ WHERE {
97
+ ?s schema:state ?stateName .
98
+ }
99
+ `,
100
+ 'SELECT',
101
+ );
102
+ console.log('======================== ASSET QUERY');
103
+ console.log(queryOperationResult);
204
104
  })();