dkg.js 8.0.10 → 8.0.12

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.
@@ -23,9 +23,6 @@ export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
23
23
  export const BLOCKCHAIN_IDS = {
24
24
  HARDHAT_1: 'hardhat1:31337',
25
25
  HARDHAT_2: 'hardhat2:31337',
26
- BASE_DEVNET: 'base:84532',
27
- GNOSIS_DEVNET: 'gnosis:10200',
28
- NEUROWEB_DEVNET: 'otp:2160',
29
26
  BASE_TESTNET: 'base:84532',
30
27
  GNOSIS_TESTNET: 'gnosis:10200',
31
28
  NEUROWEB_TESTNET: 'otp:20430',
@@ -33,12 +30,6 @@ export const BLOCKCHAIN_IDS = {
33
30
  GNOSIS_MAINNET: 'gnosis:100',
34
31
  NEUROWEB_MAINNET: 'otp:2043',
35
32
  };
36
- export const ENVIRONMENTS = {
37
- MAINNET: 'mainnet',
38
- TESTNET: 'testnet',
39
- DEVNET: 'devnet',
40
- DEVELOPMENT: 'development',
41
- };
42
33
  export const BLOCKCHAINS = {
43
34
  development: {
44
35
  'hardhat1:31337': {
@@ -50,24 +41,6 @@ export const BLOCKCHAINS = {
50
41
  hubContract: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
51
42
  },
52
43
  },
53
- devnet: {
54
- 'base:84532': {
55
- hubContract: '0xE043daF4cC8ae2c720ef95fc82574a37a429c40A',
56
- rpc: 'https://sepolia.base.org',
57
- },
58
- },
59
- stabledevnet_staging: {
60
- 'base:84532': {
61
- hubContract: '0xAB4A4794Fc1F415C24807B947280aCa8dC492238',
62
- rpc: 'https://sepolia.base.org',
63
- },
64
- },
65
- stabledevnet_prod: {
66
- 'base:84532': {
67
- hubContract: '0xaA849CAC4FA86f6b7484503f3c7a314772AED6d4',
68
- rpc: 'https://sepolia.base.org',
69
- },
70
- },
71
44
  testnet: {
72
45
  'base:84532': {
73
46
  hubContract: '0xf21CE8f8b01548D97DCFb36869f1ccB0814a4e05',
@@ -128,21 +101,12 @@ export const INCENTIVE_MULTIPLIER = {
128
101
  };
129
102
 
130
103
  export const NEUROWEB_INCENTIVE_TYPE_CHAINS = [
131
- BLOCKCHAIN_IDS.NEUROWEB_DEVNET,
132
104
  BLOCKCHAIN_IDS.NEUROWEB_TESTNET,
133
105
  BLOCKCHAIN_IDS.NEUROWEB_MAINNET,
134
106
  BLOCKCHAIN_IDS.HARDHAT_1,
135
107
  BLOCKCHAIN_IDS.HARDHAT_2,
136
108
  ];
137
109
 
138
- export const BLOCKCHAINS_RENAME_PAIRS = {
139
- hardhat1: 'hardhat1:31337',
140
- hardhat2: 'hardhat2:31337',
141
- 'otp::devnet': 'otp:2160',
142
- 'otp::testnet': 'otp:20430',
143
- 'otp::mainnet': 'otp:2043',
144
- };
145
-
146
110
  export const TRANSACTION_RETRY_ERRORS = [
147
111
  'transaction was not mined',
148
112
  'already known',
@@ -217,17 +181,6 @@ export const OPERATIONS_STEP_STATUS = {
217
181
 
218
182
  export const DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS = {
219
183
  development: { 'hardhat1:31337': 2, 'hardhat2:31337': 2, 'otp:2043': 2 },
220
- devnet: {
221
- 'otp:2160': 2,
222
- 'gnosis:10200': 2,
223
- 'base:84532': 2,
224
- },
225
- stabledevnet_staging: {
226
- 'base:84532': 2,
227
- },
228
- stabledevnet_prod: {
229
- 'base:84532': 2,
230
- },
231
184
  testnet: {
232
185
  'otp:20430': 2,
233
186
  'gnosis:10200': 2,
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * @constant {number} MAX_FILE_SIZE
5
+ * - Max file size for publish
6
+ */
7
+
8
+ const BLOCKCHAIN_IDS = {
9
+ HARDHAT_1: 'hardhat1:31337',
10
+ HARDHAT_2: 'hardhat2:31337',
11
+ BASE_TESTNET: 'base:84532',
12
+ GNOSIS_TESTNET: 'gnosis:10200',
13
+ NEUROWEB_TESTNET: 'otp:20430',
14
+ BASE_MAINNET: 'base:8453',
15
+ GNOSIS_MAINNET: 'gnosis:100',
16
+ NEUROWEB_MAINNET: 'otp:2043',
17
+ };
18
+
19
+ [
20
+ BLOCKCHAIN_IDS.NEUROWEB_TESTNET,
21
+ BLOCKCHAIN_IDS.NEUROWEB_MAINNET,
22
+ BLOCKCHAIN_IDS.HARDHAT_1,
23
+ BLOCKCHAIN_IDS.HARDHAT_2,
24
+ ];
25
+
26
+ exports.BLOCKCHAIN_IDS = BLOCKCHAIN_IDS;
@@ -0,0 +1,3 @@
1
+ import { BLOCKCHAIN_IDS } from './constants.js';
2
+
3
+ export { BLOCKCHAIN_IDS };
@@ -5,22 +5,18 @@ import {
5
5
  PARANET_NODES_ACCESS_POLICY,
6
6
  PARANET_MINERS_ACCESS_POLICY,
7
7
  PARANET_KC_SUBMISSION_POLICY,
8
- } from '../constants.js';
8
+ } from '../constants/constants.js';
9
9
 
10
- const ENVIRONMENT = 'development';
11
10
  const OT_NODE_HOSTNAME = 'http://localhost';
12
11
  const OT_NODE_PORT = '8900';
13
- const PUBLIC_KEY = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
14
- const PRIVATE_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';
12
+ const BLOCKCHAIN_NAME = BLOCKCHAIN_IDS.HARDHAT_1;
15
13
 
16
14
  const DkgClient = new DKG({
17
- environment: ENVIRONMENT,
18
15
  endpoint: OT_NODE_HOSTNAME,
19
16
  port: OT_NODE_PORT,
20
17
  blockchain: {
21
- name: 'hardhat1',
22
- publicKey: PUBLIC_KEY,
23
- privateKey: PRIVATE_KEY,
18
+ name: BLOCKCHAIN_NAME,
19
+ privateKey: process.env.PRIVATE_KEY,
24
20
  },
25
21
  maxNumberOfRetries: 30,
26
22
  frequency: 2,
@@ -1,19 +1,15 @@
1
1
  import DKG from '../index.js';
2
2
 
3
- const ENVIRONMENT = 'development';
4
3
  const OT_NODE_HOSTNAME = 'http://localhost';
5
4
  const OT_NODE_PORT = '8900';
6
- const PUBLIC_KEY = '0xBaF76aC0d0ef9a2FFF76884d54C9D3e270290a43';
7
- const PRIVATE_KEY = '0x9b9af041edc816692276ac3c8f1d5565e3c01ddff80ec982943a29bd8d1d8863';
5
+ const BLOCKCHAIN_NAME = BLOCKCHAIN_IDS.HARDHAT_1;
8
6
 
9
7
  const DkgClient = new DKG({
10
- environment: ENVIRONMENT,
11
8
  endpoint: OT_NODE_HOSTNAME,
12
9
  port: OT_NODE_PORT,
13
10
  blockchain: {
14
- name: 'hardhat1',
15
- publicKey: PUBLIC_KEY,
16
- privateKey: PRIVATE_KEY,
11
+ name: BLOCKCHAIN_NAME,
12
+ privateKey: process.env.PRIVATE_KEY,
17
13
  },
18
14
  maxNumberOfRetries: 60,
19
15
  frequency: 2,
package/examples/demo.js CHANGED
@@ -1,20 +1,17 @@
1
1
  import DKG from '../index.js';
2
- import { BLOCKCHAIN_IDS, ENVIRONMENTS } from '../constants.js';
2
+ import { BLOCKCHAIN_IDS } from '../constants/constants.js';
3
3
  import 'dotenv/config';
4
4
 
5
- const ENVIRONMENT = ENVIRONMENTS.DEVELOPMENT;
6
5
  const OT_NODE_HOSTNAME = 'http://localhost';
7
6
  const OT_NODE_PORT = '8900';
8
- const PUBLIC_KEY = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
7
+ const BLOCKCHAIN_NAME = BLOCKCHAIN_IDS.HARDHAT_1;
9
8
 
10
9
  // IMPORTANT: Don't forget to add your PRIVATE_KEY to the .env file.
11
10
  const DkgClient = new DKG({
12
- environment: ENVIRONMENT,
13
11
  endpoint: OT_NODE_HOSTNAME,
14
12
  port: OT_NODE_PORT,
15
13
  blockchain: {
16
- name: BLOCKCHAIN_IDS.HARDHAT_1,
17
- publicKey: PUBLIC_KEY,
14
+ name: BLOCKCHAIN_NAME,
18
15
  privateKey: process.env.PRIVATE_KEY,
19
16
  },
20
17
  maxNumberOfRetries: 300,
@@ -66,7 +63,7 @@ function divider() {
66
63
  minimumNumberOfNodeReplications: 1,
67
64
  });
68
65
 
69
- console.log(JSON.stringify(create_result));
66
+ console.log(create_result);
70
67
 
71
68
  divider();
72
69
 
@@ -6,23 +6,19 @@ import {
6
6
  PARANET_NODES_ACCESS_POLICY,
7
7
  PARANET_MINERS_ACCESS_POLICY,
8
8
  BLOCKCHAIN_IDS,
9
- ENVIRONMENTS,
10
9
  PARANET_KC_SUBMISSION_POLICY,
11
- } from '../constants.js';
10
+ } from '../constants/constants.js';
12
11
 
13
- const ENVIRONMENT = ENVIRONMENTS.DEVELOPMENT;
14
12
  const OT_NODE_HOSTNAME = 'http://localhost';
15
13
  const OT_NODE_PORT = '8900';
16
- const PUBLIC_KEY = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
14
+ const BLOCKCHAIN_NAME = BLOCKCHAIN_IDS.HARDHAT_1;
17
15
 
18
16
  // IMPORTANT: Don't forget to add your PRIVATE_KEY to the .env file.
19
17
  const DkgClient = new DKG({
20
- environment: ENVIRONMENT,
21
18
  endpoint: OT_NODE_HOSTNAME,
22
19
  port: OT_NODE_PORT,
23
20
  blockchain: {
24
- name: BLOCKCHAIN_IDS.HARDHAT_1,
25
- publicKey: PUBLIC_KEY,
21
+ name: BLOCKCHAIN_NAME,
26
22
  privateKey: process.env.PRIVATE_KEY,
27
23
  },
28
24
  maxNumberOfRetries: 30,
@@ -112,7 +108,7 @@ function divider() {
112
108
  const web3 = await DkgClient.blockchain.getWeb3Instance();
113
109
  const incentivesAmount = web3.utils.toWei('100', 'ether');
114
110
  const txHash = await web3.eth.sendTransaction({
115
- from: PUBLIC_KEY,
111
+ from: await DkgClient.blockchain.getWalletAddress(),
116
112
  to: incentivesPoolStorageAddressResult.incentivesPoolStorageAddress,
117
113
  value: incentivesAmount,
118
114
  });
@@ -5,23 +5,19 @@ import {
5
5
  PARANET_NODES_ACCESS_POLICY,
6
6
  PARANET_MINERS_ACCESS_POLICY,
7
7
  BLOCKCHAIN_IDS,
8
- ENVIRONMENTS,
9
8
  PARANET_KC_SUBMISSION_POLICY,
10
- } from '../constants.js';
9
+ } from '../constants/constants.js';
11
10
 
12
- const ENVIRONMENT = ENVIRONMENTS.DEVELOPMENT;
13
11
  const OT_NODE_HOSTNAME = 'http://localhost';
14
12
  const OT_NODE_PORT = '8900';
15
- const PUBLIC_KEY = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
13
+ const BLOCKCHAIN_NAME = BLOCKCHAIN_IDS.HARDHAT_1;
16
14
 
17
15
  // IMPORTANT: Don't forget to add your PRIVATE_KEY to the .env file.
18
16
  const DkgClient = new DKG({
19
- environment: ENVIRONMENT,
20
17
  endpoint: OT_NODE_HOSTNAME,
21
18
  port: OT_NODE_PORT,
22
19
  blockchain: {
23
- name: BLOCKCHAIN_IDS.HARDHAT_1,
24
- publicKey: PUBLIC_KEY,
20
+ name: BLOCKCHAIN_NAME,
25
21
  privateKey: process.env.PRIVATE_KEY,
26
22
  },
27
23
  maxNumberOfRetries: 30,
@@ -79,7 +75,10 @@ function divider() {
79
75
  divider();
80
76
 
81
77
  // ADD CURATOR TO PARANET
82
- const addCuratorResult = await DkgClient.paranet.addCurator(paranetUAL, PUBLIC_KEY);
78
+ const addCuratorResult = await DkgClient.paranet.addCurator(
79
+ paranetUAL,
80
+ await DkgClient.blockchain.getWalletAddress(),
81
+ );
83
82
  console.log('======================== CURATOR ADDED TO PARANET');
84
83
  console.log(addCuratorResult);
85
84
  divider();
@@ -209,7 +208,10 @@ function divider() {
209
208
  divider();
210
209
 
211
210
  // REMOVE CURATOR
212
- const removeCuratorResult = await DkgClient.paranet.removeCurator(paranetUAL, PUBLIC_KEY);
211
+ const removeCuratorResult = await DkgClient.paranet.removeCurator(
212
+ paranetUAL,
213
+ await DkgClient.blockchain.getWalletAddress(),
214
+ );
213
215
  console.log('======================== CURATOR REMOVED FROM PARANET');
214
216
  console.log(removeCuratorResult);
215
217
  divider();
package/index.cjs CHANGED
@@ -94,7 +94,6 @@ const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
94
94
  const BLOCKCHAIN_IDS = {
95
95
  HARDHAT_1: 'hardhat1:31337',
96
96
  HARDHAT_2: 'hardhat2:31337',
97
- NEUROWEB_DEVNET: 'otp:2160',
98
97
  NEUROWEB_TESTNET: 'otp:20430',
99
98
  NEUROWEB_MAINNET: 'otp:2043',
100
99
  };
@@ -109,24 +108,6 @@ const BLOCKCHAINS = {
109
108
  hubContract: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
110
109
  },
111
110
  },
112
- devnet: {
113
- 'base:84532': {
114
- hubContract: '0xE043daF4cC8ae2c720ef95fc82574a37a429c40A',
115
- rpc: 'https://sepolia.base.org',
116
- },
117
- },
118
- stabledevnet_staging: {
119
- 'base:84532': {
120
- hubContract: '0xAB4A4794Fc1F415C24807B947280aCa8dC492238',
121
- rpc: 'https://sepolia.base.org',
122
- },
123
- },
124
- stabledevnet_prod: {
125
- 'base:84532': {
126
- hubContract: '0xaA849CAC4FA86f6b7484503f3c7a314772AED6d4',
127
- rpc: 'https://sepolia.base.org',
128
- },
129
- },
130
111
  testnet: {
131
112
  'base:84532': {
132
113
  hubContract: '0xf21CE8f8b01548D97DCFb36869f1ccB0814a4e05',
@@ -182,21 +163,12 @@ const PARANET_KNOWLEDGE_COLLECTION_STATUS = {
182
163
  };
183
164
 
184
165
  const NEUROWEB_INCENTIVE_TYPE_CHAINS = [
185
- BLOCKCHAIN_IDS.NEUROWEB_DEVNET,
186
166
  BLOCKCHAIN_IDS.NEUROWEB_TESTNET,
187
167
  BLOCKCHAIN_IDS.NEUROWEB_MAINNET,
188
168
  BLOCKCHAIN_IDS.HARDHAT_1,
189
169
  BLOCKCHAIN_IDS.HARDHAT_2,
190
170
  ];
191
171
 
192
- const BLOCKCHAINS_RENAME_PAIRS = {
193
- hardhat1: 'hardhat1:31337',
194
- hardhat2: 'hardhat2:31337',
195
- 'otp::devnet': 'otp:2160',
196
- 'otp::testnet': 'otp:20430',
197
- 'otp::mainnet': 'otp:2043',
198
- };
199
-
200
172
  const TRANSACTION_RETRY_ERRORS = [
201
173
  'transaction was not mined',
202
174
  'already known',
@@ -260,17 +232,6 @@ const OPERATIONS_STEP_STATUS = {
260
232
 
261
233
  const DEFAULT_PROXIMITY_SCORE_FUNCTIONS_PAIR_IDS = {
262
234
  development: { 'hardhat1:31337': 2, 'hardhat2:31337': 2, 'otp:2043': 2 },
263
- devnet: {
264
- 'otp:2160': 2,
265
- 'gnosis:10200': 2,
266
- 'base:84532': 2,
267
- },
268
- stabledevnet_staging: {
269
- 'base:84532': 2,
270
- },
271
- stabledevnet_prod: {
272
- 'base:84532': 2,
273
- },
274
235
  testnet: {
275
236
  'otp:20430': 2,
276
237
  'gnosis:10200': 2,
@@ -1334,6 +1295,17 @@ class BlockchainOperationsManager {
1334
1295
  const blockchain = this.inputService.getBlockchain(options);
1335
1296
  return this.blockchainService.getWeb3Instance(blockchain);
1336
1297
  }
1298
+
1299
+ /**
1300
+ * Retrieve the wallet.
1301
+ * @async
1302
+ * @param {Object} [options={}] - Optional parameters for blockchain service.
1303
+ * @returns {Promise<Object>} - A promise that resolves to the wallet.
1304
+ */
1305
+ async getWalletAddress(options = {}) {
1306
+ const blockchain = this.inputService.getBlockchain(options);
1307
+ return blockchain.publicKey;
1308
+ }
1337
1309
  }
1338
1310
 
1339
1311
  class GraphOperationsManager {
@@ -6334,11 +6306,37 @@ class InputService {
6334
6306
  class BaseServiceManager {
6335
6307
  constructor(config) {
6336
6308
  const blockchainName = config.blockchain?.name;
6337
- const configWithNewBlockchainName = config;
6338
- if (blockchainName && Object.keys(BLOCKCHAINS_RENAME_PAIRS).includes(blockchainName))
6339
- configWithNewBlockchainName.blockchain.name = BLOCKCHAINS_RENAME_PAIRS[blockchainName];
6309
+ if (!blockchainName) {
6310
+ throw new Error('Blockchain name is required. Please set it manually.');
6311
+ }
6312
+
6313
+ for (const [env, chainsInEnv] of Object.entries(BLOCKCHAINS)) {
6314
+ if (Object.keys(chainsInEnv).includes(blockchainName)) {
6315
+ config.environment = env;
6316
+ break;
6317
+ }
6318
+ }
6319
+
6320
+ if (!config.environment) {
6321
+ throw new Error(
6322
+ `Could not derive environment from blockchain name: ${blockchainName}. Ensure it's defined in BLOCKCHAINS constant.`,
6323
+ );
6324
+ }
6325
+
6326
+ if (config.blockchain?.privateKey) {
6327
+ try {
6328
+ const wallet = new ethers.ethers.Wallet(config.blockchain.privateKey);
6329
+ config.blockchain.publicKey = wallet.address;
6330
+ } catch (error) {
6331
+ throw new Error(`Failed to derive public key from private key: ${error.message}`);
6332
+ }
6333
+ } else {
6334
+ throw new Error(
6335
+ 'Private key is required to derive public key. Please set it manually when creating the DKG instance.',
6336
+ );
6337
+ }
6340
6338
 
6341
- this.initializeServices(configWithNewBlockchainName);
6339
+ this.initializeServices(config);
6342
6340
  }
6343
6341
 
6344
6342
  initializeServices(config) {
@@ -15,7 +15,7 @@ import {
15
15
  PRIVATE_HASH_SUBJECT_PREFIX,
16
16
  PRIVATE_ASSERTION_PREDICATE,
17
17
  GET_OUTPUT_FORMATS,
18
- } from '../constants.js';
18
+ } from '../constants/constants.js';
19
19
  import emptyHooks from '../util/empty-hooks.js';
20
20
 
21
21
  export default class AssetOperationsManager {
@@ -46,4 +46,15 @@ export default class BlockchainOperationsManager {
46
46
  const blockchain = this.inputService.getBlockchain(options);
47
47
  return this.blockchainService.getWeb3Instance(blockchain);
48
48
  }
49
+
50
+ /**
51
+ * Retrieve the wallet.
52
+ * @async
53
+ * @param {Object} [options={}] - Optional parameters for blockchain service.
54
+ * @returns {Promise<Object>} - A promise that resolves to the wallet.
55
+ */
56
+ async getWalletAddress(options = {}) {
57
+ const blockchain = this.inputService.getBlockchain(options);
58
+ return blockchain.publicKey;
59
+ }
49
60
  }
@@ -4,7 +4,7 @@ import {
4
4
  OPERATIONS,
5
5
  PRIVATE_RESOURCE_PREDICATE,
6
6
  PRIVATE_HASH_SUBJECT_PREFIX,
7
- } from '../constants.js';
7
+ } from '../constants/constants.js';
8
8
  export default class GraphOperationsManager {
9
9
  constructor(services) {
10
10
  this.nodeApiService = services.nodeApiService;
@@ -1,5 +1,5 @@
1
1
  import { resolveUAL, getParanetId, getKnowledgeCollectionId } from '../services/utilities.js';
2
- import { PARANET_KNOWLEDGE_COLLECTION_STATUS } from '../constants.js';
2
+ import { PARANET_KNOWLEDGE_COLLECTION_STATUS } from '../constants/constants.js';
3
3
 
4
4
  export default class ParanetOperationsManager {
5
5
  constructor(services) {
package/package.json CHANGED
@@ -1,19 +1,27 @@
1
1
  {
2
2
  "name": "dkg.js",
3
- "version": "8.0.10",
3
+ "version": "8.0.12",
4
4
  "description": "Javascript library for interaction with the OriginTrail Decentralized Knowledge Graph",
5
5
  "main": "index.js",
6
6
  "exports": {
7
- "import": "./index.js",
8
- "require": "./index.cjs"
7
+ ".": {
8
+ "import": "./index.js",
9
+ "require": "./index.cjs"
10
+ },
11
+ "./constants": {
12
+ "import": "./constants/index.js",
13
+ "require": "./constants/index.cjs"
14
+ }
9
15
  },
10
16
  "type": "module",
11
17
  "scripts": {
12
18
  "compile-contracts": "cd ./node_modules/dkg-evm-module && npm run compile",
13
- "build": "npm run cjs-compat && npx webpack --config webpack.config.cjs",
14
- "watch": "npm run cjs-compat && npx webpack --config webpack.config.cjs --watch --progress",
19
+ "build": "npm run cjs-compat && webpack --config webpack.config.cjs",
20
+ "watch": "npm run cjs-compat && webpack --config webpack.config.cjs --watch --progress",
15
21
  "lint": "eslint .",
16
- "cjs-compat": "npx rollup index.js --file index.cjs --format cjs",
22
+ "cjs:main": "npx rollup index.js --file index.cjs --format cjs",
23
+ "cjs:constants": "npx rollup constants/index.js --file constants/index.cjs --format cjs",
24
+ "cjs-compat": "npm run cjs:main && npm run cjs:constants",
17
25
  "postinstall": "npm run cjs-compat"
18
26
  },
19
27
  "repository": {
@@ -36,7 +44,7 @@
36
44
  },
37
45
  "homepage": "https://github.com/OriginTrail/dkg.js/tree/main#readme",
38
46
  "dependencies": {
39
- "assertion-tools": "8.0.0-gamma.2",
47
+ "assertion-tools": "8.0.2",
40
48
  "axios": "^0.27.2",
41
49
  "dkg-evm-module": "8.0.4",
42
50
  "dotenv": "^16.4.7",
@@ -6,16 +6,43 @@ import ValidationService from './validation-service.js';
6
6
  import { nodeSupported } from './utilities.js';
7
7
  import InputService from './input-service.js';
8
8
 
9
- import { BLOCKCHAINS_RENAME_PAIRS } from '../constants.js';
9
+ import { BLOCKCHAINS } from '../constants/constants.js';
10
+ import { ethers } from 'ethers';
10
11
 
11
12
  export default class BaseServiceManager {
12
13
  constructor(config) {
13
14
  const blockchainName = config.blockchain?.name;
14
- const configWithNewBlockchainName = config;
15
- if (blockchainName && Object.keys(BLOCKCHAINS_RENAME_PAIRS).includes(blockchainName))
16
- configWithNewBlockchainName.blockchain.name = BLOCKCHAINS_RENAME_PAIRS[blockchainName];
15
+ if (!blockchainName) {
16
+ throw new Error('Blockchain name is required. Please set it manually.');
17
+ }
18
+
19
+ for (const [env, chainsInEnv] of Object.entries(BLOCKCHAINS)) {
20
+ if (Object.keys(chainsInEnv).includes(blockchainName)) {
21
+ config.environment = env;
22
+ break;
23
+ }
24
+ }
25
+
26
+ if (!config.environment) {
27
+ throw new Error(
28
+ `Could not derive environment from blockchain name: ${blockchainName}. Ensure it's defined in BLOCKCHAINS constant.`,
29
+ );
30
+ }
31
+
32
+ if (config.blockchain?.privateKey) {
33
+ try {
34
+ const wallet = new ethers.Wallet(config.blockchain.privateKey);
35
+ config.blockchain.publicKey = wallet.address;
36
+ } catch (error) {
37
+ throw new Error(`Failed to derive public key from private key: ${error.message}`);
38
+ }
39
+ } else {
40
+ throw new Error(
41
+ 'Private key is required to derive public key. Please set it manually when creating the DKG instance.',
42
+ );
43
+ }
17
44
 
18
- this.initializeServices(configWithNewBlockchainName);
45
+ this.initializeServices(config);
19
46
  }
20
47
 
21
48
  initializeServices(config) {
@@ -10,7 +10,7 @@ import {
10
10
  DEFAULT_GAS_PRICE_WEI,
11
11
  ZERO_ADDRESS,
12
12
  NEUROWEB_INCENTIVE_TYPE_CHAINS,
13
- } from '../../constants.js';
13
+ } from '../../constants/constants.js';
14
14
  import emptyHooks from '../../util/empty-hooks.js';
15
15
  import { sleepForMilliseconds } from '../utilities.js';
16
16
 
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-await-in-loop */
2
2
  import Web3 from 'web3';
3
3
  import BlockchainServiceBase from '../blockchain-service-base.js';
4
- import { WEBSOCKET_PROVIDER_OPTIONS } from '../../../constants.js';
4
+ import { WEBSOCKET_PROVIDER_OPTIONS } from '../../../constants/constants.js';
5
5
 
6
6
  export default class BrowserBlockchainService extends BlockchainServiceBase {
7
7
  constructor(config = {}) {
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-param-reassign */
2
2
  /* eslint-disable no-await-in-loop */
3
3
  import Web3 from 'web3';
4
- import { TRANSACTION_RETRY_ERRORS, WEBSOCKET_PROVIDER_OPTIONS } from '../../../constants.js';
4
+ import { TRANSACTION_RETRY_ERRORS, WEBSOCKET_PROVIDER_OPTIONS } from '../../../constants/constants.js';
5
5
  import BlockchainServiceBase from '../blockchain-service-base.js';
6
6
 
7
7
  export default class NodeBlockchainService extends BlockchainServiceBase {
@@ -7,7 +7,7 @@ import {
7
7
  PARANET_MINERS_ACCESS_POLICY,
8
8
  PARANET_KC_SUBMISSION_POLICY,
9
9
  ZERO_ADDRESS,
10
- } from '../constants.js';
10
+ } from '../constants/constants.js';
11
11
 
12
12
  export default class InputService {
13
13
  constructor(config = {}) {
@@ -1,5 +1,5 @@
1
1
  import axios from 'axios';
2
- import { OPERATION_STATUSES } from '../../../constants.js';
2
+ import { OPERATION_STATUSES } from '../../../constants/constants.js';
3
3
  import { sleepForMilliseconds } from '../../utilities.js';
4
4
 
5
5
  export default class HttpService {
@@ -1,5 +1,5 @@
1
1
  import jsonld from 'jsonld';
2
- import { GRAPH_LOCATIONS, GRAPH_STATES, OT_NODE_TRIPLE_STORE_REPOSITORIES } from '../constants.js';
2
+ import { GRAPH_LOCATIONS, GRAPH_STATES, OT_NODE_TRIPLE_STORE_REPOSITORIES } from '../constants/constants.js';
3
3
  import { ethers } from 'ethers';
4
4
 
5
5
  export function isEmptyObject(obj) {
@@ -10,7 +10,7 @@ import {
10
10
  PARANET_NODES_ACCESS_POLICY,
11
11
  PARANET_MINERS_ACCESS_POLICY,
12
12
  PARANET_KC_SUBMISSION_POLICY,
13
- } from '../constants.js';
13
+ } from '../constants/constants.js';
14
14
  import { nodeSupported } from './utilities.js';
15
15
 
16
16
  export default class ValidationService {
package/publish.js DELETED
@@ -1,267 +0,0 @@
1
- require('dotenv').config();
2
- const { setTimeout } = require('timers/promises');
3
- const OTNode = require('./src/apis/OTNode');
4
- const { getRandomEndpoints, getRandomV8TestnetEndpoints } = require('./src/util/Endpoint');
5
- const walletsV8TestnetBase = require('./walletsV8TestnetBase.json');
6
- const Logger = require('./src/util/logger');
7
- const { randomUUID } = require('crypto');
8
- const DKG = require('dkg.js');
9
-
10
- const CONCURRENCY = 25;
11
- const logger = new Logger('trace');
12
- const otnode = new OTNode(logger);
13
- const MAX_PUBLISHINGS = 100000;
14
- const PUBLISH_INTERVAL_V8_TESTNET = 5 * 60 * 1000;
15
- const psychohistory =
16
- "Psychohistory Psychohistory is a fictional science in Isaac Asimov's Foundation universe which combines history, sociology, and mathematical statistics to make general predictions about the future behavior of very large groups of people, such as the Galactic Empire. It was first introduced in the four short stories (1942–1944) which would later be collected as the 1951 novel Foundation. Psychohistory depends on the idea that, while one cannot foresee the actions of a particular individual, the laws of statistics as applied to large groups of people could predict the general flow of future events. Asimov used the analogy of a gas: An observer has great difficulty in predicting the motion of a single molecule in a gas, but with the kinetic theory can predict the mass action of the gas to a high level of accuracy. Asimov applied this concept to the population of his fictional Galactic Empire, which numbered one quintilli>";
17
- let counter = 0;
18
-
19
- (async () => {
20
- publishParanetV8TestnetBase();
21
- })();
22
-
23
- async function runLoadTest(clientOption, index) {
24
- while (true) {
25
- const { wallet, endpoint } = clientOption;
26
- const blockchain = 'blockchainOTP';
27
- const loadTestId = randomUUID();
28
- logger.info(`Starting load test ${index} with id: ${loadTestId}...`);
29
-
30
- let identifier = Math.floor(Math.random() * 1e10);
31
- const publishResult = await otnode.publish(
32
- {
33
- public: {
34
- '@context': 'https://schema.org',
35
- '@id': `uuid:${identifier}`,
36
- '@type': 'Person',
37
- name: 'John Doe',
38
- },
39
- private: {
40
- '@context': 'https://schema.org',
41
- '@id': `uuid:${identifier}`,
42
- bankAccount: `${identifier}`,
43
- },
44
- },
45
- endpoint,
46
- wallet,
47
- loadTestId,
48
- blockchain,
49
- );
50
- console.log(publishResult?.operation?.status);
51
- if (publishResult?.operation?.status === 'COMPLETED') {
52
- await otnode.get(publishResult.UAL, null, endpoint, wallet, loadTestId, blockchain);
53
- }
54
-
55
- await setTimeout(1 * 1000);
56
- }
57
- }
58
-
59
- async function publishV8TestnetBase() {
60
- const blockchain = 'V8TestnetBase';
61
-
62
- const publishPromises = walletsV8TestnetBase.map(async (wallet) => {
63
- while (true) {
64
- const v8TestnetEndpoints = getRandomV8TestnetEndpoints(1); // Get a new random endpoint for each wallet
65
- const endpoint = v8TestnetEndpoints[0];
66
- const loadTestId = randomUUID();
67
- logger.info(`Starting V8TestnetBase publishing with id: ${loadTestId}...`);
68
-
69
- let identifier = Math.floor(Math.random() * 1e10);
70
- const publishResult = await otnode.publish(
71
- {
72
- public: {
73
- '@context': 'https://schema.org',
74
- '@id': `uuid:${identifier}`,
75
- '@type': 'Person',
76
- name: 'Jane Doe',
77
- },
78
- private: {
79
- '@context': 'https://schema.org',
80
- '@id': `uuid:${identifier}`,
81
- bankAccount: `${identifier}`,
82
- },
83
- },
84
- endpoint,
85
- wallet,
86
- loadTestId,
87
- blockchain,
88
- );
89
- if (publishResult?.operation?.publish?.status === 'COMPLETED') {
90
- await otnode.get(publishResult.UAL, null, endpoint, wallet, loadTestId, blockchain);
91
- }
92
- }
93
- });
94
-
95
- await Promise.all(publishPromises); // Start publishing in parallel for all wallets
96
- await setTimeout(300 * 1000); // 300 seconds (5 minutes)
97
- }
98
-
99
- async function publishParanetV8TestnetBase() {
100
- logger.info('Starting paranet publishing on V8 Base Testnet');
101
- const paranetUAL = 'did:dkg:base:84532/0xd5550173b0f7b8766ab2770e4ba86caf714a5af5/10469';
102
-
103
- const publishPromises = walletsV8TestnetBase.map(async (wallet) => {
104
- while (true) {
105
- const v8TestnetEndpoints = getRandomEndpoints(1); // Get a new random endpoint for each wallet
106
- const endpoint = v8TestnetEndpoints[0];
107
- let identifier = Math.floor(Math.random() * 1e10);
108
-
109
- const content = {
110
- public: {
111
- '@context': 'https://schema.org',
112
- '@id': `uuid:${identifier}`,
113
- '@type': 'Person',
114
- name: 'Jane Doe',
115
- },
116
- private: {
117
- '@context': 'https://schema.org',
118
- '@id': `uuid:${identifier}`,
119
- bankAccount: `${identifier}`,
120
- },
121
- };
122
-
123
- const dkg = new DKG({
124
- environment: 'testnet',
125
- endpoint: endpoint,
126
- port: '8900',
127
- blockchain: {
128
- name: 'base:84532',
129
- publicKey: wallet.publicKey,
130
- privateKey: wallet.privateKey,
131
- },
132
- maxNumberOfRetries: 30,
133
- frequency: 2,
134
- contentType: 'all',
135
- nodeApiVersion: '/v1',
136
- });
137
-
138
- const createCollectionResult = await dkg.asset.create(content, { epochsNum: 2 });
139
- logger.info(`Created collection: ${createCollectionResult.UAL}`);
140
- //logger.info(JSON.stringify(createCollectionResult, null, 2));
141
- const submitToParanetResult = await dkg.asset.submitToParanet(
142
- createCollectionResult.UAL,
143
- paranetUAL,
144
- );
145
- //logger.info(JSON.stringify(submitToParanetResult, null, 2));
146
- if (createCollectionResult?.operation?.publish?.status === 'COMPLETED') {
147
- await dkg.asset.get(createCollectionResult.UAL, {
148
- paranetUAL,
149
- contentType: 'all',
150
- });
151
- }
152
- }
153
- });
154
-
155
- await Promise.all(publishPromises); // Start publishing in parallel for all wallets
156
- await setTimeout(300 * 1000); // 300 seconds (5 minutes)
157
- }
158
-
159
- async function publishParanetV8TestnetBase() {
160
- logger.info('Starting paranet publishing on V8 Base Testnet');
161
- const paranetUAL = 'did:dkg:base:84532/0xd5550173b0f7b8766ab2770e4ba86caf714a5af5/10469';
162
-
163
- // Settings per wallet
164
- const MAX_RETRIES = 5;
165
- const RETRY_DELAY = 10000; // 10 seconds initial retry delay
166
-
167
- async function processWalletContinuously(wallet) {
168
- while (true) {
169
- // Continuous processing for each wallet
170
- try {
171
- const v8TestnetEndpoints = getRandomEndpoints(1);
172
- const endpoint = v8TestnetEndpoints[0];
173
- let identifier = Math.floor(Math.random() * 1e10);
174
-
175
- const content = {
176
- public: {
177
- '@context': 'https://schema.org',
178
- '@id': `uuid:${identifier}`,
179
- '@type': 'Person',
180
- name: 'Jane Doe',
181
- },
182
- private: {
183
- '@context': 'https://schema.org',
184
- '@id': `uuid:${identifier}`,
185
- bankAccount: `${identifier}`,
186
- },
187
- };
188
-
189
- // Create DKG instance for this wallet
190
- const dkg = new DKG({
191
- environment: 'testnet',
192
- endpoint: endpoint,
193
- port: '8900',
194
- blockchain: {
195
- name: 'base:84532',
196
- publicKey: wallet.publicKey,
197
- privateKey: wallet.privateKey,
198
- },
199
- maxNumberOfRetries: 30,
200
- frequency: 2,
201
- contentType: 'all',
202
- nodeApiVersion: '/v1',
203
- });
204
-
205
- let retries = 0;
206
- while (retries < MAX_RETRIES) {
207
- try {
208
- const createCollectionResult = await dkg.asset.create(content, {
209
- epochsNum: 2,
210
- });
211
- logger.info(
212
- `Wallet ${wallet.publicKey.slice(0, 8)}: Created collection: ${
213
- createCollectionResult.UAL
214
- }`,
215
- );
216
-
217
- // await setTimeout(2000); // Small delay between operations
218
-
219
- const submitToParanetResult = await dkg.asset.submitToParanet(
220
- createCollectionResult.UAL,
221
- paranetUAL,
222
- );
223
-
224
- if (createCollectionResult?.operation?.publish?.status === 'COMPLETED') {
225
- await dkg.asset.get(createCollectionResult.UAL, {
226
- paranetUAL,
227
- contentType: 'all',
228
- });
229
- }
230
-
231
- // If successful, wait a bit before next iteration
232
- // await setTimeout(5000); // 5 seconds between successful iterations
233
- break; // Break retry loop on success
234
- } catch (error) {
235
- retries++;
236
- if (
237
- (error.message.includes('over rate limit') ||
238
- error.message.includes('execution reverted')) &&
239
- retries < MAX_RETRIES
240
- ) {
241
- logger.warn(
242
- `Wallet ${wallet.publicKey.slice(
243
- 0,
244
- 8,
245
- )}: Rate limit/execution error, retrying in ${
246
- RETRY_DELAY / 1000
247
- } seconds... (Attempt ${retries}/${MAX_RETRIES})`,
248
- );
249
- await setTimeout(RETRY_DELAY);
250
- continue;
251
- }
252
- throw error;
253
- }
254
- }
255
- } catch (error) {
256
- logger.error(`Wallet ${wallet.publicKey.slice(0, 8)} error: ${error.message}`);
257
- await setTimeout(RETRY_DELAY); // Wait before retrying the whole process
258
- }
259
- }
260
- }
261
-
262
- // Start processing for all wallets in parallel
263
- const walletProcesses = walletsV8TestnetBase.map((wallet) => processWalletContinuously(wallet));
264
-
265
- // Wait for all processes (they run indefinitely)
266
- await Promise.all(walletProcesses);
267
- }