@human-protocol/sdk 5.2.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 +66 -202
- package/dist/error.d.ts +0 -24
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +2 -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/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 -134
- 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 -15
- 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 +31 -17
- package/dist/worker.d.ts +35 -14
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +35 -14
- package/package.json +7 -24
- package/src/base.ts +4 -5
- package/src/constants.ts +6 -6
- package/src/encryption.ts +69 -203
- package/src/error.ts +0 -36
- package/src/escrow.ts +425 -780
- package/src/graphql/queries/operator.ts +3 -1
- package/src/graphql/types.ts +4 -2
- package/src/index.ts +4 -5
- package/src/kvstore.ts +120 -183
- package/src/operator.ts +59 -30
- package/src/staking.ts +135 -134
- package/src/statistics.ts +125 -146
- package/src/transaction.ts +36 -15
- package/src/types.ts +0 -57
- package/src/utils.ts +31 -17
- 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/dist/kvstore.js
CHANGED
|
@@ -19,12 +19,10 @@ const error_1 = require("./error");
|
|
|
19
19
|
const utils_1 = require("./utils");
|
|
20
20
|
const kvstore_1 = require("./graphql/queries/kvstore");
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* This client enables performing actions on KVStore contract and obtaining information from both the contracts and subgraph.
|
|
22
|
+
* Client for interacting with the KVStore contract.
|
|
25
23
|
*
|
|
26
24
|
* Internally, the SDK will use one network or another according to the network ID of the `runner`.
|
|
27
|
-
* To use this client, it is recommended to initialize it using the static `build` method.
|
|
25
|
+
* To use this client, it is recommended to initialize it using the static [`build`](/ts/classes/KVStoreClient/#build) method.
|
|
28
26
|
*
|
|
29
27
|
* ```ts
|
|
30
28
|
* static async build(runner: ContractRunner): Promise<KVStoreClient>;
|
|
@@ -35,37 +33,25 @@ const kvstore_1 = require("./graphql/queries/kvstore");
|
|
|
35
33
|
* - **Signer**: when the user wants to use this model to send transactions calling the contract functions.
|
|
36
34
|
* - **Provider**: when the user wants to use this model to get information from the contracts or subgraph.
|
|
37
35
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* ### npm
|
|
41
|
-
* ```bash
|
|
42
|
-
* npm install @human-protocol/sdk
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* ### yarn
|
|
46
|
-
* ```bash
|
|
47
|
-
* yarn install @human-protocol/sdk
|
|
48
|
-
* ```
|
|
49
|
-
*
|
|
50
|
-
* ## Code example
|
|
36
|
+
* @example
|
|
51
37
|
*
|
|
52
|
-
* ### Signer
|
|
38
|
+
* ###Using Signer
|
|
53
39
|
*
|
|
54
|
-
*
|
|
40
|
+
* ####Using private key (backend)
|
|
55
41
|
*
|
|
56
42
|
* ```ts
|
|
57
43
|
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
58
|
-
* import { Wallet,
|
|
44
|
+
* import { Wallet, JsonRpcProvider } from 'ethers';
|
|
59
45
|
*
|
|
60
46
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
61
47
|
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
62
48
|
*
|
|
63
|
-
* const provider = new
|
|
49
|
+
* const provider = new JsonRpcProvider(rpcUrl);
|
|
64
50
|
* const signer = new Wallet(privateKey, provider);
|
|
65
51
|
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
66
52
|
* ```
|
|
67
53
|
*
|
|
68
|
-
*
|
|
54
|
+
* ####Using Wagmi (frontend)
|
|
69
55
|
*
|
|
70
56
|
* ```ts
|
|
71
57
|
* import { useSigner, useChainId } from 'wagmi';
|
|
@@ -75,15 +61,15 @@ const kvstore_1 = require("./graphql/queries/kvstore");
|
|
|
75
61
|
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
76
62
|
* ```
|
|
77
63
|
*
|
|
78
|
-
* ### Provider
|
|
64
|
+
* ###Using Provider
|
|
79
65
|
*
|
|
80
66
|
* ```ts
|
|
81
67
|
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
82
|
-
* import {
|
|
68
|
+
* import { JsonRpcProvider } from 'ethers';
|
|
83
69
|
*
|
|
84
70
|
* const rpcUrl = 'YOUR_RPC_URL';
|
|
85
71
|
*
|
|
86
|
-
* const provider = new
|
|
72
|
+
* const provider = new JsonRpcProvider(rpcUrl);
|
|
87
73
|
* const kvstoreClient = await KVStoreClient.build(provider);
|
|
88
74
|
* ```
|
|
89
75
|
*/
|
|
@@ -91,8 +77,8 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
91
77
|
/**
|
|
92
78
|
* **KVStoreClient constructor**
|
|
93
79
|
*
|
|
94
|
-
* @param
|
|
95
|
-
* @param
|
|
80
|
+
* @param runner - The Runner object to interact with the Ethereum network
|
|
81
|
+
* @param networkData - The network information required to connect to the KVStore contract
|
|
96
82
|
*/
|
|
97
83
|
constructor(runner, networkData) {
|
|
98
84
|
super(runner, networkData);
|
|
@@ -101,11 +87,23 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
101
87
|
/**
|
|
102
88
|
* Creates an instance of KVStoreClient from a runner.
|
|
103
89
|
*
|
|
104
|
-
* @param
|
|
90
|
+
* @param runner - The Runner object to interact with the Ethereum network
|
|
91
|
+
* @returns An instance of KVStoreClient
|
|
92
|
+
* @throws ErrorProviderDoesNotExist If the provider does not exist for the provided Signer
|
|
93
|
+
* @throws ErrorUnsupportedChainID If the network's chainId is not supported
|
|
105
94
|
*
|
|
106
|
-
* @
|
|
107
|
-
*
|
|
108
|
-
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```ts
|
|
97
|
+
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
98
|
+
* import { Wallet, JsonRpcProvider } from 'ethers';
|
|
99
|
+
*
|
|
100
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
101
|
+
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
102
|
+
*
|
|
103
|
+
* const provider = new JsonRpcProvider(rpcUrl);
|
|
104
|
+
* const signer = new Wallet(privateKey, provider);
|
|
105
|
+
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
106
|
+
* ```
|
|
109
107
|
*/
|
|
110
108
|
static async build(runner) {
|
|
111
109
|
if (!runner.provider) {
|
|
@@ -122,27 +120,15 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
122
120
|
/**
|
|
123
121
|
* This function sets a key-value pair associated with the address that submits the transaction.
|
|
124
122
|
*
|
|
125
|
-
* @param
|
|
126
|
-
* @param
|
|
127
|
-
* @param
|
|
128
|
-
* @returns
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* **Code example**
|
|
132
|
-
*
|
|
133
|
-
* > Need to have available stake.
|
|
123
|
+
* @param key - Key of the key-value pair
|
|
124
|
+
* @param value - Value of the key-value pair
|
|
125
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
126
|
+
* @returns -
|
|
127
|
+
* @throws ErrorKVStoreEmptyKey If the key is empty
|
|
128
|
+
* @throws Error If the transaction fails
|
|
134
129
|
*
|
|
130
|
+
* @example
|
|
135
131
|
* ```ts
|
|
136
|
-
* import { Wallet, providers } from 'ethers';
|
|
137
|
-
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
138
|
-
*
|
|
139
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
140
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
141
|
-
*
|
|
142
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
143
|
-
* const signer = new Wallet(privateKey, provider);
|
|
144
|
-
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
145
|
-
*
|
|
146
132
|
* await kvstoreClient.set('Role', 'RecordingOracle');
|
|
147
133
|
* ```
|
|
148
134
|
*/
|
|
@@ -160,27 +146,16 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
160
146
|
/**
|
|
161
147
|
* This function sets key-value pairs in bulk associated with the address that submits the transaction.
|
|
162
148
|
*
|
|
163
|
-
* @param
|
|
164
|
-
* @param
|
|
165
|
-
* @param
|
|
166
|
-
* @returns
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
* > Need to have available stake.
|
|
149
|
+
* @param keys - Array of keys (keys and value must have the same order)
|
|
150
|
+
* @param values - Array of values
|
|
151
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
152
|
+
* @returns -
|
|
153
|
+
* @throws ErrorKVStoreArrayLength If keys and values arrays have different lengths
|
|
154
|
+
* @throws ErrorKVStoreEmptyKey If any key is empty
|
|
155
|
+
* @throws Error If the transaction fails
|
|
172
156
|
*
|
|
157
|
+
* @example
|
|
173
158
|
* ```ts
|
|
174
|
-
* import { Wallet, providers } from 'ethers';
|
|
175
|
-
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
176
|
-
*
|
|
177
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
178
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
179
|
-
*
|
|
180
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
181
|
-
* const signer = new Wallet(privateKey, provider);
|
|
182
|
-
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
183
|
-
*
|
|
184
159
|
* const keys = ['role', 'webhook_url'];
|
|
185
160
|
* const values = ['RecordingOracle', 'http://localhost'];
|
|
186
161
|
* await kvstoreClient.setBulk(keys, values);
|
|
@@ -202,25 +177,15 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
202
177
|
/**
|
|
203
178
|
* Sets a URL value for the address that submits the transaction, and its hash.
|
|
204
179
|
*
|
|
205
|
-
* @param
|
|
206
|
-
* @param
|
|
207
|
-
* @param
|
|
208
|
-
* @returns
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
* **Code example**
|
|
180
|
+
* @param url - URL to set
|
|
181
|
+
* @param urlKey - Configurable URL key. `url` by default.
|
|
182
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
183
|
+
* @returns -
|
|
184
|
+
* @throws ErrorInvalidUrl If the URL is invalid
|
|
185
|
+
* @throws Error If the transaction fails
|
|
212
186
|
*
|
|
187
|
+
* @example
|
|
213
188
|
* ```ts
|
|
214
|
-
* import { Wallet, providers } from 'ethers';
|
|
215
|
-
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
216
|
-
*
|
|
217
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
218
|
-
* const privateKey = 'YOUR_PRIVATE_KEY';
|
|
219
|
-
*
|
|
220
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
221
|
-
* const signer = new Wallet(privateKey, provider);
|
|
222
|
-
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
223
|
-
*
|
|
224
189
|
* await kvstoreClient.setFileUrlAndHash('example.com');
|
|
225
190
|
* await kvstoreClient.setFileUrlAndHash('linkedin.com/example', 'linkedin_url');
|
|
226
191
|
* ```
|
|
@@ -243,26 +208,17 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
243
208
|
/**
|
|
244
209
|
* Gets the value of a key-value pair in the contract.
|
|
245
210
|
*
|
|
246
|
-
* @param
|
|
247
|
-
* @param
|
|
248
|
-
* @
|
|
249
|
-
* @
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
* **Code example**
|
|
253
|
-
*
|
|
254
|
-
* > Need to have available stake.
|
|
211
|
+
* @param address - Address from which to get the key value.
|
|
212
|
+
* @param key - Key to obtain the value.
|
|
213
|
+
* @returns Value of the key.
|
|
214
|
+
* @throws ErrorKVStoreEmptyKey If the key is empty
|
|
215
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
216
|
+
* @throws Error If the contract call fails
|
|
255
217
|
*
|
|
218
|
+
* @example
|
|
256
219
|
* ```ts
|
|
257
|
-
* import { providers } from 'ethers';
|
|
258
|
-
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
259
|
-
*
|
|
260
|
-
* const rpcUrl = 'YOUR_RPC_URL';
|
|
261
|
-
*
|
|
262
|
-
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
263
|
-
* const kvstoreClient = await KVStoreClient.build(provider);
|
|
264
|
-
*
|
|
265
220
|
* const value = await kvstoreClient.get('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', 'Role');
|
|
221
|
+
* console.log('Value:', value);
|
|
266
222
|
* ```
|
|
267
223
|
*/
|
|
268
224
|
async get(address, key) {
|
|
@@ -301,55 +257,37 @@ __decorate([
|
|
|
301
257
|
__metadata("design:returntype", Promise)
|
|
302
258
|
], KVStoreClient.prototype, "setFileUrlAndHash", null);
|
|
303
259
|
/**
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
* Utility class for KVStore-related operations.
|
|
307
|
-
*
|
|
308
|
-
* ## Installation
|
|
309
|
-
*
|
|
310
|
-
* ### npm
|
|
311
|
-
* ```bash
|
|
312
|
-
* npm install @human-protocol/sdk
|
|
313
|
-
* ```
|
|
314
|
-
*
|
|
315
|
-
* ### yarn
|
|
316
|
-
* ```bash
|
|
317
|
-
* yarn install @human-protocol/sdk
|
|
318
|
-
* ```
|
|
319
|
-
*
|
|
320
|
-
* ## Code example
|
|
321
|
-
*
|
|
322
|
-
* ### Signer
|
|
323
|
-
*
|
|
324
|
-
* **Using private key (backend)**
|
|
260
|
+
* Utility helpers for KVStore-related queries.
|
|
325
261
|
*
|
|
262
|
+
* @example
|
|
326
263
|
* ```ts
|
|
327
264
|
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
328
265
|
*
|
|
329
|
-
* const
|
|
266
|
+
* const kvStoreData = await KVStoreUtils.getKVStoreData(
|
|
330
267
|
* ChainId.POLYGON_AMOY,
|
|
331
268
|
* "0x1234567890123456789012345678901234567890"
|
|
332
269
|
* );
|
|
270
|
+
* console.log('KVStore data:', kvStoreData);
|
|
333
271
|
* ```
|
|
334
272
|
*/
|
|
335
273
|
class KVStoreUtils {
|
|
336
274
|
/**
|
|
337
275
|
* This function returns the KVStore data for a given address.
|
|
338
276
|
*
|
|
339
|
-
* @param
|
|
340
|
-
* @param
|
|
341
|
-
* @param
|
|
342
|
-
* @returns
|
|
343
|
-
* @throws
|
|
344
|
-
* @throws
|
|
345
|
-
*
|
|
346
|
-
* **Code example**
|
|
277
|
+
* @param chainId - Network in which the KVStore is deployed
|
|
278
|
+
* @param address - Address of the KVStore
|
|
279
|
+
* @param options - Optional configuration for subgraph requests.
|
|
280
|
+
* @returns KVStore data
|
|
281
|
+
* @throws ErrorUnsupportedChainID If the network's chainId is not supported
|
|
282
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
347
283
|
*
|
|
284
|
+
* @example
|
|
348
285
|
* ```ts
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
286
|
+
* const kvStoreData = await KVStoreUtils.getKVStoreData(
|
|
287
|
+
* ChainId.POLYGON_AMOY,
|
|
288
|
+
* "0x1234567890123456789012345678901234567890"
|
|
289
|
+
* );
|
|
290
|
+
* console.log('KVStore data:', kvStoreData);
|
|
353
291
|
* ```
|
|
354
292
|
*/
|
|
355
293
|
static async getKVStoreData(chainId, address, options) {
|
|
@@ -370,26 +308,24 @@ class KVStoreUtils {
|
|
|
370
308
|
/**
|
|
371
309
|
* Gets the value of a key-value pair in the KVStore using the subgraph.
|
|
372
310
|
*
|
|
373
|
-
* @param
|
|
374
|
-
* @param
|
|
375
|
-
* @param
|
|
376
|
-
* @param
|
|
377
|
-
* @returns
|
|
378
|
-
* @throws
|
|
379
|
-
* @throws
|
|
380
|
-
* @throws
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
311
|
+
* @param chainId - Network in which the KVStore is deployed
|
|
312
|
+
* @param address - Address from which to get the key value.
|
|
313
|
+
* @param key - Key to obtain the value.
|
|
314
|
+
* @param options - Optional configuration for subgraph requests.
|
|
315
|
+
* @returns Value of the key.
|
|
316
|
+
* @throws ErrorUnsupportedChainID If the network's chainId is not supported
|
|
317
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
318
|
+
* @throws ErrorKVStoreEmptyKey If the key is empty
|
|
319
|
+
* @throws InvalidKeyError If the key is not found
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
384
322
|
* ```ts
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
*
|
|
390
|
-
*
|
|
391
|
-
* const value = await KVStoreUtils.get(chainId, address, key);
|
|
392
|
-
* console.log(value);
|
|
323
|
+
* const value = await KVStoreUtils.get(
|
|
324
|
+
* ChainId.POLYGON_AMOY,
|
|
325
|
+
* '0x1234567890123456789012345678901234567890',
|
|
326
|
+
* 'role'
|
|
327
|
+
* );
|
|
328
|
+
* console.log('Value:', value);
|
|
393
329
|
* ```
|
|
394
330
|
*/
|
|
395
331
|
static async get(chainId, address, key, options) {
|
|
@@ -410,22 +346,22 @@ class KVStoreUtils {
|
|
|
410
346
|
/**
|
|
411
347
|
* Gets the URL value of the given entity, and verifies its hash.
|
|
412
348
|
*
|
|
413
|
-
* @param
|
|
414
|
-
* @param
|
|
415
|
-
* @param
|
|
416
|
-
* @param
|
|
417
|
-
* @returns
|
|
418
|
-
*
|
|
419
|
-
*
|
|
349
|
+
* @param chainId - Network in which the KVStore is deployed
|
|
350
|
+
* @param address - Address from which to get the URL value.
|
|
351
|
+
* @param urlKey - Configurable URL key. `url` by default.
|
|
352
|
+
* @param options - Optional configuration for subgraph requests.
|
|
353
|
+
* @returns URL value for the given address if it exists, and the content is valid
|
|
354
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
355
|
+
* @throws ErrorInvalidHash If the hash verification fails
|
|
356
|
+
* @throws Error If fetching URL or hash fails
|
|
420
357
|
*
|
|
358
|
+
* @example
|
|
421
359
|
* ```ts
|
|
422
|
-
*
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
* const url = await KVStoreUtils.getFileUrlAndVerifyHash(chainId, address);
|
|
428
|
-
* console.log(url);
|
|
360
|
+
* const url = await KVStoreUtils.getFileUrlAndVerifyHash(
|
|
361
|
+
* ChainId.POLYGON_AMOY,
|
|
362
|
+
* '0x1234567890123456789012345678901234567890'
|
|
363
|
+
* );
|
|
364
|
+
* console.log('Verified URL:', url);
|
|
429
365
|
* ```
|
|
430
366
|
*/
|
|
431
367
|
static async getFileUrlAndVerifyHash(chainId, address, urlKey = 'url', options) {
|
|
@@ -463,20 +399,21 @@ class KVStoreUtils {
|
|
|
463
399
|
/**
|
|
464
400
|
* Gets the public key of the given entity, and verifies its hash.
|
|
465
401
|
*
|
|
466
|
-
* @param
|
|
467
|
-
* @param
|
|
468
|
-
* @
|
|
469
|
-
*
|
|
470
|
-
*
|
|
402
|
+
* @param chainId - Network in which the KVStore is deployed
|
|
403
|
+
* @param address - Address from which to get the public key.
|
|
404
|
+
* @param options - Optional configuration for subgraph requests.
|
|
405
|
+
* @returns Public key for the given address if it exists, and the content is valid
|
|
406
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
407
|
+
* @throws ErrorInvalidHash If the hash verification fails
|
|
408
|
+
* @throws Error If fetching the public key fails
|
|
471
409
|
*
|
|
410
|
+
* @example
|
|
472
411
|
* ```ts
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
* const publicKey = await KVStoreUtils.getPublicKey(chainId, address);
|
|
479
|
-
* console.log(publicKey);
|
|
412
|
+
* const publicKey = await KVStoreUtils.getPublicKey(
|
|
413
|
+
* ChainId.POLYGON_AMOY,
|
|
414
|
+
* '0x1234567890123456789012345678901234567890'
|
|
415
|
+
* );
|
|
416
|
+
* console.log('Public key:', publicKey);
|
|
480
417
|
* ```
|
|
481
418
|
*/
|
|
482
419
|
static async getPublicKey(chainId, address, options) {
|
package/dist/operator.d.ts
CHANGED
|
@@ -1,74 +1,103 @@
|
|
|
1
1
|
import { IOperator, IOperatorsFilter, IReward, SubgraphOptions } from './interfaces';
|
|
2
2
|
import { ChainId } from './enums';
|
|
3
|
+
/**
|
|
4
|
+
* Utility helpers for operator-related queries.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
9
|
+
*
|
|
10
|
+
* const operator = await OperatorUtils.getOperator(
|
|
11
|
+
* ChainId.POLYGON_AMOY,
|
|
12
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
|
|
13
|
+
* );
|
|
14
|
+
* console.log('Operator:', operator);
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
3
17
|
export declare class OperatorUtils {
|
|
4
18
|
/**
|
|
5
19
|
* This function returns the operator data for the given address.
|
|
6
20
|
*
|
|
7
|
-
* @param
|
|
8
|
-
* @param
|
|
9
|
-
* @param
|
|
10
|
-
* @returns
|
|
11
|
-
*
|
|
12
|
-
*
|
|
21
|
+
* @param chainId - Network in which the operator is deployed
|
|
22
|
+
* @param address - Operator address.
|
|
23
|
+
* @param options - Optional configuration for subgraph requests.
|
|
24
|
+
* @returns Returns the operator details or null if not found.
|
|
25
|
+
* @throws ErrorInvalidStakerAddressProvided If the address is invalid
|
|
26
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
13
27
|
*
|
|
28
|
+
* @example
|
|
14
29
|
* ```ts
|
|
15
30
|
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
16
31
|
*
|
|
17
|
-
* const operator = await OperatorUtils.getOperator(
|
|
32
|
+
* const operator = await OperatorUtils.getOperator(
|
|
33
|
+
* ChainId.POLYGON_AMOY,
|
|
34
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
|
|
35
|
+
* );
|
|
36
|
+
* console.log('Operator:', operator);
|
|
18
37
|
* ```
|
|
19
38
|
*/
|
|
20
39
|
static getOperator(chainId: ChainId, address: string, options?: SubgraphOptions): Promise<IOperator | null>;
|
|
21
40
|
/**
|
|
22
41
|
* This function returns all the operator details of the protocol.
|
|
23
42
|
*
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @returns
|
|
27
|
-
*
|
|
28
|
-
* **Code example**
|
|
43
|
+
* @param filter - Filter for the operators.
|
|
44
|
+
* @param options - Optional configuration for subgraph requests.
|
|
45
|
+
* @returns Returns an array with all the operator details.
|
|
46
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
29
47
|
*
|
|
48
|
+
* @example
|
|
30
49
|
* ```ts
|
|
31
|
-
* import {
|
|
50
|
+
* import { ChainId } from '@human-protocol/sdk';
|
|
32
51
|
*
|
|
33
|
-
* const filter
|
|
34
|
-
*
|
|
52
|
+
* const filter = {
|
|
53
|
+
* chainId: ChainId.POLYGON_AMOY
|
|
35
54
|
* };
|
|
36
55
|
* const operators = await OperatorUtils.getOperators(filter);
|
|
56
|
+
* console.log('Operators:', operators.length);
|
|
37
57
|
* ```
|
|
38
58
|
*/
|
|
39
59
|
static getOperators(filter: IOperatorsFilter, options?: SubgraphOptions): Promise<IOperator[]>;
|
|
40
60
|
/**
|
|
41
61
|
* Retrieves the reputation network operators of the specified address.
|
|
42
62
|
*
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
45
|
-
* @param
|
|
46
|
-
* @param
|
|
47
|
-
* @returns
|
|
48
|
-
*
|
|
49
|
-
* **Code example**
|
|
63
|
+
* @param chainId - Network in which the reputation network is deployed
|
|
64
|
+
* @param address - Address of the reputation oracle.
|
|
65
|
+
* @param role - Role of the operator (optional).
|
|
66
|
+
* @param options - Optional configuration for subgraph requests.
|
|
67
|
+
* @returns Returns an array of operator details.
|
|
68
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
50
69
|
*
|
|
70
|
+
* @example
|
|
51
71
|
* ```ts
|
|
52
72
|
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
53
73
|
*
|
|
54
|
-
* const operators = await OperatorUtils.getReputationNetworkOperators(
|
|
74
|
+
* const operators = await OperatorUtils.getReputationNetworkOperators(
|
|
75
|
+
* ChainId.POLYGON_AMOY,
|
|
76
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
|
|
77
|
+
* );
|
|
78
|
+
* console.log('Operators:', operators.length);
|
|
55
79
|
* ```
|
|
56
80
|
*/
|
|
57
81
|
static getReputationNetworkOperators(chainId: ChainId, address: string, role?: string, options?: SubgraphOptions): Promise<IOperator[]>;
|
|
58
82
|
/**
|
|
59
83
|
* This function returns information about the rewards for a given slasher address.
|
|
60
84
|
*
|
|
61
|
-
* @param
|
|
62
|
-
* @param
|
|
63
|
-
* @param
|
|
64
|
-
* @returns
|
|
65
|
-
*
|
|
66
|
-
*
|
|
85
|
+
* @param chainId - Network in which the rewards are deployed
|
|
86
|
+
* @param slasherAddress - Slasher address.
|
|
87
|
+
* @param options - Optional configuration for subgraph requests.
|
|
88
|
+
* @returns Returns an array of Reward objects that contain the rewards earned by the user through slashing other users.
|
|
89
|
+
* @throws ErrorInvalidSlasherAddressProvided If the slasher address is invalid
|
|
90
|
+
* @throws ErrorUnsupportedChainID If the chain ID is not supported
|
|
67
91
|
*
|
|
92
|
+
* @example
|
|
68
93
|
* ```ts
|
|
69
94
|
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
70
95
|
*
|
|
71
|
-
* const rewards = await OperatorUtils.getRewards(
|
|
96
|
+
* const rewards = await OperatorUtils.getRewards(
|
|
97
|
+
* ChainId.POLYGON_AMOY,
|
|
98
|
+
* '0x62dD51230A30401C455c8398d06F85e4EaB6309f'
|
|
99
|
+
* );
|
|
100
|
+
* console.log('Rewards:', rewards.length);
|
|
72
101
|
* ```
|
|
73
102
|
*/
|
|
74
103
|
static getRewards(chainId: ChainId, slasherAddress: string, options?: SubgraphOptions): Promise<IReward[]>;
|
package/dist/operator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operator.d.ts","sourceRoot":"","sources":["../src/operator.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,OAAO,EACP,eAAe,EAChB,MAAM,cAAc,CAAC;AAmBtB,OAAO,EAAE,OAAO,EAAkB,MAAM,SAAS,CAAC;AAGlD,qBAAa,aAAa;IACxB
|
|
1
|
+
{"version":3,"file":"operator.d.ts","sourceRoot":"","sources":["../src/operator.ts"],"names":[],"mappings":"AACA,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,OAAO,EACP,eAAe,EAChB,MAAM,cAAc,CAAC;AAmBtB,OAAO,EAAE,OAAO,EAAkB,MAAM,SAAS,CAAC;AAGlD;;;;;;;;;;;;;GAaG;AACH,qBAAa,aAAa;IACxB;;;;;;;;;;;;;;;;;;;;OAoBG;WACiB,WAAW,CAC7B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAwB5B;;;;;;;;;;;;;;;;;;OAkBG;WACiB,YAAY,CAC9B,MAAM,EAAE,gBAAgB,EACxB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,SAAS,EAAE,CAAC;IA+CvB;;;;;;;;;;;;;;;;;;;;OAoBG;WACiB,6BAA6B,CAC/C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,SAAS,EAAE,CAAC;IAyBvB;;;;;;;;;;;;;;;;;;;;OAoBG;WACiB,UAAU,CAC5B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,eAAe,GACxB,OAAO,CAAC,OAAO,EAAE,CAAC;CA8BtB"}
|