@human-protocol/sdk 5.1.0 → 6.0.0

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 (66) hide show
  1. package/dist/base.d.ts +4 -5
  2. package/dist/base.d.ts.map +1 -1
  3. package/dist/base.js +4 -5
  4. package/dist/constants.js +6 -6
  5. package/dist/encryption.d.ts +68 -203
  6. package/dist/encryption.d.ts.map +1 -1
  7. package/dist/encryption.js +67 -203
  8. package/dist/error.d.ts +4 -24
  9. package/dist/error.d.ts.map +1 -1
  10. package/dist/error.js +6 -26
  11. package/dist/escrow.d.ts +427 -780
  12. package/dist/escrow.d.ts.map +1 -1
  13. package/dist/escrow.js +314 -684
  14. package/dist/graphql/queries/operator.d.ts.map +1 -1
  15. package/dist/graphql/queries/operator.js +3 -1
  16. package/dist/graphql/types.d.ts.map +1 -1
  17. package/dist/index.d.ts +3 -4
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +2 -4
  20. package/dist/interfaces.d.ts +5 -0
  21. package/dist/interfaces.d.ts.map +1 -1
  22. package/dist/kvstore.d.ts +119 -181
  23. package/dist/kvstore.d.ts.map +1 -1
  24. package/dist/kvstore.js +119 -182
  25. package/dist/operator.d.ts +59 -30
  26. package/dist/operator.d.ts.map +1 -1
  27. package/dist/operator.js +59 -30
  28. package/dist/staking.d.ts +135 -134
  29. package/dist/staking.d.ts.map +1 -1
  30. package/dist/staking.js +135 -135
  31. package/dist/statistics.d.ts +104 -134
  32. package/dist/statistics.d.ts.map +1 -1
  33. package/dist/statistics.js +119 -144
  34. package/dist/transaction.d.ts +36 -15
  35. package/dist/transaction.d.ts.map +1 -1
  36. package/dist/transaction.js +36 -16
  37. package/dist/types.d.ts +0 -54
  38. package/dist/types.d.ts.map +1 -1
  39. package/dist/utils.d.ts +31 -17
  40. package/dist/utils.d.ts.map +1 -1
  41. package/dist/utils.js +57 -28
  42. package/dist/worker.d.ts +35 -14
  43. package/dist/worker.d.ts.map +1 -1
  44. package/dist/worker.js +35 -14
  45. package/package.json +13 -28
  46. package/src/base.ts +4 -5
  47. package/src/constants.ts +6 -6
  48. package/src/encryption.ts +70 -204
  49. package/src/error.ts +7 -36
  50. package/src/escrow.ts +426 -780
  51. package/src/graphql/queries/operator.ts +3 -1
  52. package/src/graphql/types.ts +4 -2
  53. package/src/index.ts +4 -5
  54. package/src/interfaces.ts +5 -0
  55. package/src/kvstore.ts +120 -183
  56. package/src/operator.ts +59 -30
  57. package/src/staking.ts +136 -135
  58. package/src/statistics.ts +125 -146
  59. package/src/transaction.ts +36 -16
  60. package/src/types.ts +0 -57
  61. package/src/utils.ts +62 -31
  62. package/src/worker.ts +35 -14
  63. package/dist/storage.d.ts +0 -186
  64. package/dist/storage.d.ts.map +0 -1
  65. package/dist/storage.js +0 -319
  66. package/src/storage.ts +0 -313
@@ -15,7 +15,9 @@ const LEADER_FRAGMENT = gql`
15
15
  jobTypes
16
16
  registrationNeeded
17
17
  registrationInstructions
18
- reputationNetworks
18
+ reputationNetworks {
19
+ address
20
+ }
19
21
  name
20
22
  category
21
23
  staker {
@@ -166,8 +166,10 @@ export interface IOperatorSubgraph {
166
166
  } | null;
167
167
  }
168
168
 
169
- export interface IReputationNetworkSubgraph
170
- extends Omit<IReputationNetwork, 'operators'> {
169
+ export interface IReputationNetworkSubgraph extends Omit<
170
+ IReputationNetwork,
171
+ 'operators'
172
+ > {
171
173
  operators: IOperatorSubgraph[];
172
174
  }
173
175
 
package/src/index.ts CHANGED
@@ -1,9 +1,8 @@
1
1
  import { StakingClient, StakingUtils } from './staking';
2
- import { StorageClient } from './storage';
3
2
  import { KVStoreClient, KVStoreUtils } from './kvstore';
4
3
  import { EscrowClient, EscrowUtils } from './escrow';
5
- import { StatisticsClient } from './statistics';
6
- import { Encryption, EncryptionUtils } from './encryption';
4
+ import { StatisticsUtils } from './statistics';
5
+ import { Encryption, EncryptionUtils, MessageDataType } from './encryption';
7
6
  import { OperatorUtils } from './operator';
8
7
  import { TransactionUtils } from './transaction';
9
8
  import { WorkerUtils } from './worker';
@@ -27,16 +26,16 @@ export {
27
26
 
28
27
  export {
29
28
  StakingClient,
30
- StorageClient,
31
29
  KVStoreClient,
32
30
  KVStoreUtils,
33
31
  EscrowClient,
34
32
  EscrowUtils,
35
- StatisticsClient,
33
+ StatisticsUtils,
36
34
  Encryption,
37
35
  EncryptionUtils,
38
36
  OperatorUtils,
39
37
  TransactionUtils,
40
38
  WorkerUtils,
41
39
  StakingUtils,
40
+ MessageDataType,
42
41
  };
package/src/interfaces.ts CHANGED
@@ -321,4 +321,9 @@ export interface SubgraphOptions {
321
321
  maxRetries?: number;
322
322
  /** Base delay between retries in milliseconds */
323
323
  baseDelay?: number;
324
+ /**
325
+ * Optional indexer identifier. When provided, requests target
326
+ * `{gateway}/deployments/id/<DEPLOYMENT_ID>/indexers/id/<INDEXER_ID>`.
327
+ */
328
+ indexerId?: string;
324
329
  }
package/src/kvstore.ts CHANGED
@@ -26,12 +26,10 @@ import {
26
26
  import { KVStoreData } from './graphql';
27
27
  import { IKVStore, SubgraphOptions } from './interfaces';
28
28
  /**
29
- * ## Introduction
30
- *
31
- * This client enables performing actions on KVStore contract and obtaining information from both the contracts and subgraph.
29
+ * Client for interacting with the KVStore contract.
32
30
  *
33
31
  * Internally, the SDK will use one network or another according to the network ID of the `runner`.
34
- * To use this client, it is recommended to initialize it using the static `build` method.
32
+ * To use this client, it is recommended to initialize it using the static [`build`](/ts/classes/KVStoreClient/#build) method.
35
33
  *
36
34
  * ```ts
37
35
  * static async build(runner: ContractRunner): Promise<KVStoreClient>;
@@ -42,37 +40,25 @@ import { IKVStore, SubgraphOptions } from './interfaces';
42
40
  * - **Signer**: when the user wants to use this model to send transactions calling the contract functions.
43
41
  * - **Provider**: when the user wants to use this model to get information from the contracts or subgraph.
44
42
  *
45
- * ## Installation
46
- *
47
- * ### npm
48
- * ```bash
49
- * npm install @human-protocol/sdk
50
- * ```
51
- *
52
- * ### yarn
53
- * ```bash
54
- * yarn install @human-protocol/sdk
55
- * ```
56
- *
57
- * ## Code example
43
+ * @example
58
44
  *
59
- * ### Signer
45
+ * ###Using Signer
60
46
  *
61
- * **Using private key (backend)**
47
+ * ####Using private key (backend)
62
48
  *
63
49
  * ```ts
64
50
  * import { KVStoreClient } from '@human-protocol/sdk';
65
- * import { Wallet, providers } from 'ethers';
51
+ * import { Wallet, JsonRpcProvider } from 'ethers';
66
52
  *
67
53
  * const rpcUrl = 'YOUR_RPC_URL';
68
54
  * const privateKey = 'YOUR_PRIVATE_KEY';
69
55
  *
70
- * const provider = new providers.JsonRpcProvider(rpcUrl);
56
+ * const provider = new JsonRpcProvider(rpcUrl);
71
57
  * const signer = new Wallet(privateKey, provider);
72
58
  * const kvstoreClient = await KVStoreClient.build(signer);
73
59
  * ```
74
60
  *
75
- * **Using Wagmi (frontend)**
61
+ * ####Using Wagmi (frontend)
76
62
  *
77
63
  * ```ts
78
64
  * import { useSigner, useChainId } from 'wagmi';
@@ -82,27 +68,27 @@ import { IKVStore, SubgraphOptions } from './interfaces';
82
68
  * const kvstoreClient = await KVStoreClient.build(signer);
83
69
  * ```
84
70
  *
85
- * ### Provider
71
+ * ###Using Provider
86
72
  *
87
73
  * ```ts
88
74
  * import { KVStoreClient } from '@human-protocol/sdk';
89
- * import { providers } from 'ethers';
75
+ * import { JsonRpcProvider } from 'ethers';
90
76
  *
91
77
  * const rpcUrl = 'YOUR_RPC_URL';
92
78
  *
93
- * const provider = new providers.JsonRpcProvider(rpcUrl);
79
+ * const provider = new JsonRpcProvider(rpcUrl);
94
80
  * const kvstoreClient = await KVStoreClient.build(provider);
95
81
  * ```
96
82
  */
97
83
 
98
84
  export class KVStoreClient extends BaseEthersClient {
99
- private contract: KVStore;
85
+ public contract: KVStore;
100
86
 
101
87
  /**
102
88
  * **KVStoreClient constructor**
103
89
  *
104
- * @param {ContractRunner} runner - The Runner object to interact with the Ethereum network
105
- * @param {NetworkData} networkData - The network information required to connect to the KVStore contract
90
+ * @param runner - The Runner object to interact with the Ethereum network
91
+ * @param networkData - The network information required to connect to the KVStore contract
106
92
  */
107
93
  constructor(runner: ContractRunner, networkData: NetworkData) {
108
94
  super(runner, networkData);
@@ -116,11 +102,23 @@ export class KVStoreClient extends BaseEthersClient {
116
102
  /**
117
103
  * Creates an instance of KVStoreClient from a runner.
118
104
  *
119
- * @param {ContractRunner} runner - The Runner object to interact with the Ethereum network
105
+ * @param runner - The Runner object to interact with the Ethereum network
106
+ * @returns An instance of KVStoreClient
107
+ * @throws ErrorProviderDoesNotExist If the provider does not exist for the provided Signer
108
+ * @throws ErrorUnsupportedChainID If the network's chainId is not supported
120
109
  *
121
- * @returns {Promise<KVStoreClient>} - An instance of KVStoreClient
122
- * @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
123
- * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
110
+ * @example
111
+ * ```ts
112
+ * import { KVStoreClient } from '@human-protocol/sdk';
113
+ * import { Wallet, JsonRpcProvider } from 'ethers';
114
+ *
115
+ * const rpcUrl = 'YOUR_RPC_URL';
116
+ * const privateKey = 'YOUR_PRIVATE_KEY';
117
+ *
118
+ * const provider = new JsonRpcProvider(rpcUrl);
119
+ * const signer = new Wallet(privateKey, provider);
120
+ * const kvstoreClient = await KVStoreClient.build(signer);
121
+ * ```
124
122
  */
125
123
  public static async build(runner: ContractRunner): Promise<KVStoreClient> {
126
124
  if (!runner.provider) {
@@ -142,27 +140,15 @@ export class KVStoreClient extends BaseEthersClient {
142
140
  /**
143
141
  * This function sets a key-value pair associated with the address that submits the transaction.
144
142
  *
145
- * @param {string} key Key of the key-value pair
146
- * @param {string} value Value of the key-value pair
147
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
148
- * @returns Returns void if successful. Throws error if any.
149
- *
150
- *
151
- * **Code example**
152
- *
153
- * > Need to have available stake.
143
+ * @param key - Key of the key-value pair
144
+ * @param value - Value of the key-value pair
145
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
146
+ * @returns -
147
+ * @throws ErrorKVStoreEmptyKey If the key is empty
148
+ * @throws Error If the transaction fails
154
149
  *
150
+ * @example
155
151
  * ```ts
156
- * import { Wallet, providers } from 'ethers';
157
- * import { KVStoreClient } from '@human-protocol/sdk';
158
- *
159
- * const rpcUrl = 'YOUR_RPC_URL';
160
- * const privateKey = 'YOUR_PRIVATE_KEY';
161
- *
162
- * const provider = new providers.JsonRpcProvider(rpcUrl);
163
- * const signer = new Wallet(privateKey, provider);
164
- * const kvstoreClient = await KVStoreClient.build(signer);
165
- *
166
152
  * await kvstoreClient.set('Role', 'RecordingOracle');
167
153
  * ```
168
154
  */
@@ -183,27 +169,16 @@ export class KVStoreClient extends BaseEthersClient {
183
169
  /**
184
170
  * This function sets key-value pairs in bulk associated with the address that submits the transaction.
185
171
  *
186
- * @param {string[]} keys Array of keys (keys and value must have the same order)
187
- * @param {string[]} values Array of values
188
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
189
- * @returns Returns void if successful. Throws error if any.
190
- *
191
- *
192
- * **Code example**
193
- *
194
- * > Need to have available stake.
172
+ * @param keys - Array of keys (keys and value must have the same order)
173
+ * @param values - Array of values
174
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
175
+ * @returns -
176
+ * @throws ErrorKVStoreArrayLength If keys and values arrays have different lengths
177
+ * @throws ErrorKVStoreEmptyKey If any key is empty
178
+ * @throws Error If the transaction fails
195
179
  *
180
+ * @example
196
181
  * ```ts
197
- * import { Wallet, providers } from 'ethers';
198
- * import { KVStoreClient } from '@human-protocol/sdk';
199
- *
200
- * const rpcUrl = 'YOUR_RPC_URL';
201
- * const privateKey = 'YOUR_PRIVATE_KEY';
202
- *
203
- * const provider = new providers.JsonRpcProvider(rpcUrl);
204
- * const signer = new Wallet(privateKey, provider);
205
- * const kvstoreClient = await KVStoreClient.build(signer);
206
- *
207
182
  * const keys = ['role', 'webhook_url'];
208
183
  * const values = ['RecordingOracle', 'http://localhost'];
209
184
  * await kvstoreClient.setBulk(keys, values);
@@ -229,25 +204,15 @@ export class KVStoreClient extends BaseEthersClient {
229
204
  /**
230
205
  * Sets a URL value for the address that submits the transaction, and its hash.
231
206
  *
232
- * @param {string} url URL to set
233
- * @param {string | undefined} urlKey Configurable URL key. `url` by default.
234
- * @param {Overrides} [txOptions] - Additional transaction parameters (optional, defaults to an empty object).
235
- * @returns Returns void if successful. Throws error if any.
236
- *
237
- *
238
- * **Code example**
207
+ * @param url - URL to set
208
+ * @param urlKey - Configurable URL key. `url` by default.
209
+ * @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
210
+ * @returns -
211
+ * @throws ErrorInvalidUrl If the URL is invalid
212
+ * @throws Error If the transaction fails
239
213
  *
214
+ * @example
240
215
  * ```ts
241
- * import { Wallet, providers } from 'ethers';
242
- * import { KVStoreClient } from '@human-protocol/sdk';
243
- *
244
- * const rpcUrl = 'YOUR_RPC_URL';
245
- * const privateKey = 'YOUR_PRIVATE_KEY';
246
- *
247
- * const provider = new providers.JsonRpcProvider(rpcUrl);
248
- * const signer = new Wallet(privateKey, provider);
249
- * const kvstoreClient = await KVStoreClient.build(signer);
250
- *
251
216
  * await kvstoreClient.setFileUrlAndHash('example.com');
252
217
  * await kvstoreClient.setFileUrlAndHash('linkedin.com/example', 'linkedin_url');
253
218
  * ```
@@ -283,26 +248,17 @@ export class KVStoreClient extends BaseEthersClient {
283
248
  /**
284
249
  * Gets the value of a key-value pair in the contract.
285
250
  *
286
- * @param {string} address Address from which to get the key value.
287
- * @param {string} key Key to obtain the value.
288
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
289
- * @returns {string} Value of the key.
290
- *
291
- *
292
- * **Code example**
293
- *
294
- * > Need to have available stake.
251
+ * @param address - Address from which to get the key value.
252
+ * @param key - Key to obtain the value.
253
+ * @returns Value of the key.
254
+ * @throws ErrorKVStoreEmptyKey If the key is empty
255
+ * @throws ErrorInvalidAddress If the address is invalid
256
+ * @throws Error If the contract call fails
295
257
  *
258
+ * @example
296
259
  * ```ts
297
- * import { providers } from 'ethers';
298
- * import { KVStoreClient } from '@human-protocol/sdk';
299
- *
300
- * const rpcUrl = 'YOUR_RPC_URL';
301
- *
302
- * const provider = new providers.JsonRpcProvider(rpcUrl);
303
- * const kvstoreClient = await KVStoreClient.build(provider);
304
- *
305
260
  * const value = await kvstoreClient.get('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', 'Role');
261
+ * console.log('Value:', value);
306
262
  * ```
307
263
  */
308
264
  public async get(address: string, key: string): Promise<string> {
@@ -320,55 +276,37 @@ export class KVStoreClient extends BaseEthersClient {
320
276
  }
321
277
 
322
278
  /**
323
- * ## Introduction
324
- *
325
- * Utility class for KVStore-related operations.
326
- *
327
- * ## Installation
328
- *
329
- * ### npm
330
- * ```bash
331
- * npm install @human-protocol/sdk
332
- * ```
333
- *
334
- * ### yarn
335
- * ```bash
336
- * yarn install @human-protocol/sdk
337
- * ```
338
- *
339
- * ## Code example
340
- *
341
- * ### Signer
342
- *
343
- * **Using private key (backend)**
279
+ * Utility helpers for KVStore-related queries.
344
280
  *
281
+ * @example
345
282
  * ```ts
346
283
  * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
347
284
  *
348
- * const KVStoreAddresses = await KVStoreUtils.getKVStoreData(
285
+ * const kvStoreData = await KVStoreUtils.getKVStoreData(
349
286
  * ChainId.POLYGON_AMOY,
350
287
  * "0x1234567890123456789012345678901234567890"
351
288
  * );
289
+ * console.log('KVStore data:', kvStoreData);
352
290
  * ```
353
291
  */
354
292
  export class KVStoreUtils {
355
293
  /**
356
294
  * This function returns the KVStore data for a given address.
357
295
  *
358
- * @param {ChainId} chainId Network in which the KVStore is deployed
359
- * @param {string} address Address of the KVStore
360
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
361
- * @returns {Promise<IKVStore[]>} KVStore data
362
- * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
363
- * @throws {ErrorInvalidAddress} - Thrown if the Address sent is invalid
364
- *
365
- * **Code example**
296
+ * @param chainId - Network in which the KVStore is deployed
297
+ * @param address - Address of the KVStore
298
+ * @param options - Optional configuration for subgraph requests.
299
+ * @returns KVStore data
300
+ * @throws ErrorUnsupportedChainID If the network's chainId is not supported
301
+ * @throws ErrorInvalidAddress If the address is invalid
366
302
  *
303
+ * @example
367
304
  * ```ts
368
- * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
369
- *
370
- * const kvStoreData = await KVStoreUtils.getKVStoreData(ChainId.POLYGON_AMOY, "0x1234567890123456789012345678901234567890");
371
- * console.log(kvStoreData);
305
+ * const kvStoreData = await KVStoreUtils.getKVStoreData(
306
+ * ChainId.POLYGON_AMOY,
307
+ * "0x1234567890123456789012345678901234567890"
308
+ * );
309
+ * console.log('KVStore data:', kvStoreData);
372
310
  * ```
373
311
  */
374
312
  public static async getKVStoreData(
@@ -404,26 +342,24 @@ export class KVStoreUtils {
404
342
  /**
405
343
  * Gets the value of a key-value pair in the KVStore using the subgraph.
406
344
  *
407
- * @param {ChainId} chainId Network in which the KVStore is deployed
408
- * @param {string} address Address from which to get the key value.
409
- * @param {string} key Key to obtain the value.
410
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
411
- * @returns {Promise<string>} Value of the key.
412
- * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
413
- * @throws {ErrorInvalidAddress} - Thrown if the Address sent is invalid
414
- * @throws {ErrorKVStoreEmptyKey} - Thrown if the key is empty
415
- *
416
- * **Code example**
417
- *
345
+ * @param chainId - Network in which the KVStore is deployed
346
+ * @param address - Address from which to get the key value.
347
+ * @param key - Key to obtain the value.
348
+ * @param options - Optional configuration for subgraph requests.
349
+ * @returns Value of the key.
350
+ * @throws ErrorUnsupportedChainID If the network's chainId is not supported
351
+ * @throws ErrorInvalidAddress If the address is invalid
352
+ * @throws ErrorKVStoreEmptyKey If the key is empty
353
+ * @throws InvalidKeyError If the key is not found
354
+ *
355
+ * @example
418
356
  * ```ts
419
- * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
420
- *
421
- * const chainId = ChainId.POLYGON_AMOY;
422
- * const address = '0x1234567890123456789012345678901234567890';
423
- * const key = 'role';
424
- *
425
- * const value = await KVStoreUtils.get(chainId, address, key);
426
- * console.log(value);
357
+ * const value = await KVStoreUtils.get(
358
+ * ChainId.POLYGON_AMOY,
359
+ * '0x1234567890123456789012345678901234567890',
360
+ * 'role'
361
+ * );
362
+ * console.log('Value:', value);
427
363
  * ```
428
364
  */
429
365
  public static async get(
@@ -458,22 +394,22 @@ export class KVStoreUtils {
458
394
  /**
459
395
  * Gets the URL value of the given entity, and verifies its hash.
460
396
  *
461
- * @param {ChainId} chainId Network in which the KVStore is deployed
462
- * @param {string} address Address from which to get the URL value.
463
- * @param {string} urlKey Configurable URL key. `url` by default.
464
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
465
- * @returns {Promise<string>} URL value for the given address if it exists, and the content is valid
466
- *
467
- * **Code example**
397
+ * @param chainId - Network in which the KVStore is deployed
398
+ * @param address - Address from which to get the URL value.
399
+ * @param urlKey - Configurable URL key. `url` by default.
400
+ * @param options - Optional configuration for subgraph requests.
401
+ * @returns URL value for the given address if it exists, and the content is valid
402
+ * @throws ErrorInvalidAddress If the address is invalid
403
+ * @throws ErrorInvalidHash If the hash verification fails
404
+ * @throws Error If fetching URL or hash fails
468
405
  *
406
+ * @example
469
407
  * ```ts
470
- * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
471
- *
472
- * const chainId = ChainId.POLYGON_AMOY;
473
- * const address = '0x1234567890123456789012345678901234567890';
474
- *
475
- * const url = await KVStoreUtils.getFileUrlAndVerifyHash(chainId, address);
476
- * console.log(url);
408
+ * const url = await KVStoreUtils.getFileUrlAndVerifyHash(
409
+ * ChainId.POLYGON_AMOY,
410
+ * '0x1234567890123456789012345678901234567890'
411
+ * );
412
+ * console.log('Verified URL:', url);
477
413
  * ```
478
414
  */
479
415
  public static async getFileUrlAndVerifyHash(
@@ -521,20 +457,21 @@ export class KVStoreUtils {
521
457
  /**
522
458
  * Gets the public key of the given entity, and verifies its hash.
523
459
  *
524
- * @param {ChainId} chainId Network in which the KVStore is deployed
525
- * @param {string} address Address from which to get the public key.
526
- * @returns {Promise<string>} Public key for the given address if it exists, and the content is valid
527
- *
528
- * **Code example**
460
+ * @param chainId - Network in which the KVStore is deployed
461
+ * @param address - Address from which to get the public key.
462
+ * @param options - Optional configuration for subgraph requests.
463
+ * @returns Public key for the given address if it exists, and the content is valid
464
+ * @throws ErrorInvalidAddress If the address is invalid
465
+ * @throws ErrorInvalidHash If the hash verification fails
466
+ * @throws Error If fetching the public key fails
529
467
  *
468
+ * @example
530
469
  * ```ts
531
- * import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
532
- *
533
- * const chainId = ChainId.POLYGON_AMOY;
534
- * const address = '0x1234567890123456789012345678901234567890';
535
- *
536
- * const publicKey = await KVStoreUtils.getPublicKey(chainId, address);
537
- * console.log(publicKey);
470
+ * const publicKey = await KVStoreUtils.getPublicKey(
471
+ * ChainId.POLYGON_AMOY,
472
+ * '0x1234567890123456789012345678901234567890'
473
+ * );
474
+ * console.log('Public key:', publicKey);
538
475
  * ```
539
476
  */
540
477
  public static async getPublicKey(
package/src/operator.ts CHANGED
@@ -26,21 +26,40 @@ import { getSubgraphUrl, customGqlFetch } from './utils';
26
26
  import { ChainId, OrderDirection } from './enums';
27
27
  import { NETWORKS } from './constants';
28
28
 
29
+ /**
30
+ * Utility helpers for operator-related queries.
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * import { OperatorUtils, ChainId } from '@human-protocol/sdk';
35
+ *
36
+ * const operator = await OperatorUtils.getOperator(
37
+ * ChainId.POLYGON_AMOY,
38
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
39
+ * );
40
+ * console.log('Operator:', operator);
41
+ * ```
42
+ */
29
43
  export class OperatorUtils {
30
44
  /**
31
45
  * This function returns the operator data for the given address.
32
46
  *
33
- * @param {ChainId} chainId Network in which the operator is deployed
34
- * @param {string} address Operator address.
35
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
36
- * @returns {Promise<IOperator | null>} - Returns the operator details or null if not found.
37
- *
38
- * **Code example**
47
+ * @param chainId - Network in which the operator is deployed
48
+ * @param address - Operator address.
49
+ * @param options - Optional configuration for subgraph requests.
50
+ * @returns Returns the operator details or null if not found.
51
+ * @throws ErrorInvalidStakerAddressProvided If the address is invalid
52
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
39
53
  *
54
+ * @example
40
55
  * ```ts
41
56
  * import { OperatorUtils, ChainId } from '@human-protocol/sdk';
42
57
  *
43
- * const operator = await OperatorUtils.getOperator(ChainId.POLYGON_AMOY, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
58
+ * const operator = await OperatorUtils.getOperator(
59
+ * ChainId.POLYGON_AMOY,
60
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
61
+ * );
62
+ * console.log('Operator:', operator);
44
63
  * ```
45
64
  */
46
65
  public static async getOperator(
@@ -74,19 +93,20 @@ export class OperatorUtils {
74
93
  /**
75
94
  * This function returns all the operator details of the protocol.
76
95
  *
77
- * @param {IOperatorsFilter} filter Filter for the operators.
78
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
79
- * @returns {Promise<IOperator[]>} Returns an array with all the operator details.
80
- *
81
- * **Code example**
96
+ * @param filter - Filter for the operators.
97
+ * @param options - Optional configuration for subgraph requests.
98
+ * @returns Returns an array with all the operator details.
99
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
82
100
  *
101
+ * @example
83
102
  * ```ts
84
- * import { OperatorUtils, ChainId } from '@human-protocol/sdk';
103
+ * import { ChainId } from '@human-protocol/sdk';
85
104
  *
86
- * const filter: IOperatorsFilter = {
87
- * chainId: ChainId.POLYGON
105
+ * const filter = {
106
+ * chainId: ChainId.POLYGON_AMOY
88
107
  * };
89
108
  * const operators = await OperatorUtils.getOperators(filter);
109
+ * console.log('Operators:', operators.length);
90
110
  * ```
91
111
  */
92
112
  public static async getOperators(
@@ -142,18 +162,22 @@ export class OperatorUtils {
142
162
  /**
143
163
  * Retrieves the reputation network operators of the specified address.
144
164
  *
145
- * @param {ChainId} chainId Network in which the reputation network is deployed
146
- * @param {string} address Address of the reputation oracle.
147
- * @param {string} [role] - (Optional) Role of the operator.
148
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
149
- * @returns {Promise<IOperator[]>} - Returns an array of operator details.
150
- *
151
- * **Code example**
165
+ * @param chainId - Network in which the reputation network is deployed
166
+ * @param address - Address of the reputation oracle.
167
+ * @param role - Role of the operator (optional).
168
+ * @param options - Optional configuration for subgraph requests.
169
+ * @returns Returns an array of operator details.
170
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
152
171
  *
172
+ * @example
153
173
  * ```ts
154
174
  * import { OperatorUtils, ChainId } from '@human-protocol/sdk';
155
175
  *
156
- * const operators = await OperatorUtils.getReputationNetworkOperators(ChainId.POLYGON_AMOY, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
176
+ * const operators = await OperatorUtils.getReputationNetworkOperators(
177
+ * ChainId.POLYGON_AMOY,
178
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
179
+ * );
180
+ * console.log('Operators:', operators.length);
157
181
  * ```
158
182
  */
159
183
  public static async getReputationNetworkOperators(
@@ -189,17 +213,22 @@ export class OperatorUtils {
189
213
  /**
190
214
  * This function returns information about the rewards for a given slasher address.
191
215
  *
192
- * @param {ChainId} chainId Network in which the rewards are deployed
193
- * @param {string} slasherAddress Slasher address.
194
- * @param {SubgraphOptions} options Optional configuration for subgraph requests.
195
- * @returns {Promise<IReward[]>} Returns an array of Reward objects that contain the rewards earned by the user through slashing other users.
196
- *
197
- * **Code example**
216
+ * @param chainId - Network in which the rewards are deployed
217
+ * @param slasherAddress - Slasher address.
218
+ * @param options - Optional configuration for subgraph requests.
219
+ * @returns Returns an array of Reward objects that contain the rewards earned by the user through slashing other users.
220
+ * @throws ErrorInvalidSlasherAddressProvided If the slasher address is invalid
221
+ * @throws ErrorUnsupportedChainID If the chain ID is not supported
198
222
  *
223
+ * @example
199
224
  * ```ts
200
225
  * import { OperatorUtils, ChainId } from '@human-protocol/sdk';
201
226
  *
202
- * const rewards = await OperatorUtils.getRewards(ChainId.POLYGON_AMOY, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
227
+ * const rewards = await OperatorUtils.getRewards(
228
+ * ChainId.POLYGON_AMOY,
229
+ * '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
230
+ * );
231
+ * console.log('Rewards:', rewards.length);
203
232
  * ```
204
233
  */
205
234
  public static async getRewards(