@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.
- package/dist/base.d.ts +4 -5
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +4 -5
- package/dist/constants.js +6 -6
- package/dist/encryption.d.ts +68 -203
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +67 -203
- package/dist/error.d.ts +4 -24
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +6 -26
- package/dist/escrow.d.ts +427 -780
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +314 -684
- package/dist/graphql/queries/operator.d.ts.map +1 -1
- package/dist/graphql/queries/operator.js +3 -1
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/interfaces.d.ts +5 -0
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +119 -181
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +119 -182
- package/dist/operator.d.ts +59 -30
- package/dist/operator.d.ts.map +1 -1
- package/dist/operator.js +59 -30
- package/dist/staking.d.ts +135 -134
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +135 -135
- package/dist/statistics.d.ts +104 -134
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +119 -144
- package/dist/transaction.d.ts +36 -15
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +36 -16
- package/dist/types.d.ts +0 -54
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +31 -17
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +57 -28
- package/dist/worker.d.ts +35 -14
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +35 -14
- package/package.json +13 -28
- package/src/base.ts +4 -5
- package/src/constants.ts +6 -6
- package/src/encryption.ts +70 -204
- package/src/error.ts +7 -36
- package/src/escrow.ts +426 -780
- package/src/graphql/queries/operator.ts +3 -1
- package/src/graphql/types.ts +4 -2
- package/src/index.ts +4 -5
- package/src/interfaces.ts +5 -0
- package/src/kvstore.ts +120 -183
- package/src/operator.ts +59 -30
- package/src/staking.ts +136 -135
- package/src/statistics.ts +125 -146
- package/src/transaction.ts +36 -16
- package/src/types.ts +0 -57
- package/src/utils.ts +62 -31
- package/src/worker.ts +35 -14
- package/dist/storage.d.ts +0 -186
- package/dist/storage.d.ts.map +0 -1
- package/dist/storage.js +0 -319
- package/src/storage.ts +0 -313
package/src/graphql/types.ts
CHANGED
|
@@ -166,8 +166,10 @@ export interface IOperatorSubgraph {
|
|
|
166
166
|
} | null;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
export interface IReputationNetworkSubgraph
|
|
170
|
-
|
|
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 {
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
47
|
+
* ####Using private key (backend)
|
|
62
48
|
*
|
|
63
49
|
* ```ts
|
|
64
50
|
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
65
|
-
* import { Wallet,
|
|
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
|
|
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
|
-
*
|
|
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 {
|
|
75
|
+
* import { JsonRpcProvider } from 'ethers';
|
|
90
76
|
*
|
|
91
77
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
92
78
|
*
|
|
93
|
-
* const provider = new
|
|
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
|
-
|
|
85
|
+
public contract: KVStore;
|
|
100
86
|
|
|
101
87
|
/**
|
|
102
88
|
* **KVStoreClient constructor**
|
|
103
89
|
*
|
|
104
|
-
* @param
|
|
105
|
-
* @param
|
|
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
|
|
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
|
-
* @
|
|
122
|
-
*
|
|
123
|
-
*
|
|
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
|
|
146
|
-
* @param
|
|
147
|
-
* @param
|
|
148
|
-
* @returns
|
|
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
|
|
187
|
-
* @param
|
|
188
|
-
* @param
|
|
189
|
-
* @returns
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
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
|
|
233
|
-
* @param
|
|
234
|
-
* @param
|
|
235
|
-
* @returns
|
|
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
|
|
287
|
-
* @param
|
|
288
|
-
* @
|
|
289
|
-
* @
|
|
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
|
-
*
|
|
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
|
|
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
|
|
359
|
-
* @param
|
|
360
|
-
* @param
|
|
361
|
-
* @returns
|
|
362
|
-
* @throws
|
|
363
|
-
* @throws
|
|
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
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
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
|
|
408
|
-
* @param
|
|
409
|
-
* @param
|
|
410
|
-
* @param
|
|
411
|
-
* @returns
|
|
412
|
-
* @throws
|
|
413
|
-
* @throws
|
|
414
|
-
* @throws
|
|
415
|
-
*
|
|
416
|
-
*
|
|
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
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
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
|
|
462
|
-
* @param
|
|
463
|
-
* @param
|
|
464
|
-
* @param
|
|
465
|
-
* @returns
|
|
466
|
-
*
|
|
467
|
-
*
|
|
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
|
-
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
473
|
-
*
|
|
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
|
|
525
|
-
* @param
|
|
526
|
-
* @
|
|
527
|
-
*
|
|
528
|
-
*
|
|
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
|
-
*
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
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
|
|
34
|
-
* @param
|
|
35
|
-
* @param
|
|
36
|
-
* @returns
|
|
37
|
-
*
|
|
38
|
-
*
|
|
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(
|
|
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
|
|
78
|
-
* @param
|
|
79
|
-
* @returns
|
|
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 {
|
|
103
|
+
* import { ChainId } from '@human-protocol/sdk';
|
|
85
104
|
*
|
|
86
|
-
* const filter
|
|
87
|
-
*
|
|
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
|
|
146
|
-
* @param
|
|
147
|
-
* @param
|
|
148
|
-
* @param
|
|
149
|
-
* @returns
|
|
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(
|
|
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
|
|
193
|
-
* @param
|
|
194
|
-
* @param
|
|
195
|
-
* @returns
|
|
196
|
-
*
|
|
197
|
-
*
|
|
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(
|
|
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(
|