@human-protocol/sdk 5.2.0 → 6.1.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/CHANGELOG.md +13 -0
- package/dist/base.d.ts +8 -7
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +18 -5
- package/dist/constants.d.ts +0 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +7 -8
- 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 +438 -791
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +331 -705
- 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 +2 -2
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +124 -186
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +122 -185
- 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 +142 -141
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +140 -139
- 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 +38 -17
- package/dist/transaction.d.ts.map +1 -1
- package/dist/transaction.js +40 -19
- package/dist/types.d.ts +14 -55
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +32 -18
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +32 -19
- package/dist/worker.d.ts +35 -14
- package/dist/worker.d.ts.map +1 -1
- package/dist/worker.js +35 -14
- package/package.json +8 -25
- package/src/base.ts +42 -7
- package/src/constants.ts +6 -8
- package/src/encryption.ts +69 -203
- package/src/error.ts +0 -36
- package/src/escrow.ts +548 -891
- 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 +2 -2
- package/src/kvstore.ts +142 -197
- package/src/operator.ts +59 -30
- package/src/staking.ts +177 -160
- package/src/statistics.ts +125 -146
- package/src/transaction.ts +40 -19
- package/src/types.ts +16 -58
- package/src/utils.ts +33 -23
- 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
|
@@ -149,8 +149,8 @@ export interface ITransaction {
|
|
|
149
149
|
|
|
150
150
|
export interface ITransactionsFilter extends IPagination {
|
|
151
151
|
chainId: ChainId;
|
|
152
|
-
startBlock?: number;
|
|
153
|
-
endBlock?: number;
|
|
152
|
+
startBlock?: number | bigint;
|
|
153
|
+
endBlock?: number | bigint;
|
|
154
154
|
startDate?: Date;
|
|
155
155
|
endDate?: Date;
|
|
156
156
|
fromAddress?: string;
|
package/src/kvstore.ts
CHANGED
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
KVStore,
|
|
3
3
|
KVStore__factory,
|
|
4
4
|
} from '@human-protocol/core/typechain-types';
|
|
5
|
-
import { ContractRunner,
|
|
5
|
+
import { ContractRunner, ethers } from 'ethers';
|
|
6
6
|
import { BaseEthersClient } from './base';
|
|
7
7
|
import { KVStoreKeys, NETWORKS } from './constants';
|
|
8
8
|
import { requiresSigner } from './decorators';
|
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
ErrorUnsupportedChainID,
|
|
18
18
|
InvalidKeyError,
|
|
19
19
|
} from './error';
|
|
20
|
-
import { NetworkData } from './types';
|
|
20
|
+
import { NetworkData, TransactionOverrides } from './types';
|
|
21
21
|
import { getSubgraphUrl, customGqlFetch, isValidUrl } from './utils';
|
|
22
22
|
import {
|
|
23
23
|
GET_KVSTORE_BY_ADDRESS_AND_KEY_QUERY,
|
|
@@ -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
|
*/
|
|
@@ -170,11 +156,14 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
170
156
|
public async set(
|
|
171
157
|
key: string,
|
|
172
158
|
value: string,
|
|
173
|
-
txOptions:
|
|
159
|
+
txOptions: TransactionOverrides = {}
|
|
174
160
|
): Promise<void> {
|
|
175
161
|
if (key === '') throw ErrorKVStoreEmptyKey;
|
|
176
162
|
try {
|
|
177
|
-
await
|
|
163
|
+
await this.sendTxAndWait(
|
|
164
|
+
(overrides) => this.contract.set(key, value, overrides),
|
|
165
|
+
txOptions
|
|
166
|
+
);
|
|
178
167
|
} catch (e) {
|
|
179
168
|
if (e instanceof Error) throw Error(`Failed to set value: ${e.message}`);
|
|
180
169
|
}
|
|
@@ -183,27 +172,16 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
183
172
|
/**
|
|
184
173
|
* This function sets key-value pairs in bulk associated with the address that submits the transaction.
|
|
185
174
|
*
|
|
186
|
-
* @param
|
|
187
|
-
* @param
|
|
188
|
-
* @param
|
|
189
|
-
* @returns
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
* > Need to have available stake.
|
|
175
|
+
* @param keys - Array of keys (keys and value must have the same order)
|
|
176
|
+
* @param values - Array of values
|
|
177
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
178
|
+
* @returns -
|
|
179
|
+
* @throws ErrorKVStoreArrayLength If keys and values arrays have different lengths
|
|
180
|
+
* @throws ErrorKVStoreEmptyKey If any key is empty
|
|
181
|
+
* @throws Error If the transaction fails
|
|
195
182
|
*
|
|
183
|
+
* @example
|
|
196
184
|
* ```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
185
|
* const keys = ['role', 'webhook_url'];
|
|
208
186
|
* const values = ['RecordingOracle', 'http://localhost'];
|
|
209
187
|
* await kvstoreClient.setBulk(keys, values);
|
|
@@ -213,13 +191,16 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
213
191
|
public async setBulk(
|
|
214
192
|
keys: string[],
|
|
215
193
|
values: string[],
|
|
216
|
-
txOptions:
|
|
194
|
+
txOptions: TransactionOverrides = {}
|
|
217
195
|
): Promise<void> {
|
|
218
196
|
if (keys.length !== values.length) throw ErrorKVStoreArrayLength;
|
|
219
197
|
if (keys.includes('')) throw ErrorKVStoreEmptyKey;
|
|
220
198
|
|
|
221
199
|
try {
|
|
222
|
-
await
|
|
200
|
+
await this.sendTxAndWait(
|
|
201
|
+
(overrides) => this.contract.setBulk(keys, values, overrides),
|
|
202
|
+
txOptions
|
|
203
|
+
);
|
|
223
204
|
} catch (e) {
|
|
224
205
|
if (e instanceof Error)
|
|
225
206
|
throw Error(`Failed to set bulk values: ${e.message}`);
|
|
@@ -229,25 +210,15 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
229
210
|
/**
|
|
230
211
|
* Sets a URL value for the address that submits the transaction, and its hash.
|
|
231
212
|
*
|
|
232
|
-
* @param
|
|
233
|
-
* @param
|
|
234
|
-
* @param
|
|
235
|
-
* @returns
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
* **Code example**
|
|
213
|
+
* @param url - URL to set
|
|
214
|
+
* @param urlKey - Configurable URL key. `url` by default.
|
|
215
|
+
* @param txOptions - Additional transaction parameters (optional, defaults to an empty object).
|
|
216
|
+
* @returns -
|
|
217
|
+
* @throws ErrorInvalidUrl If the URL is invalid
|
|
218
|
+
* @throws Error If the transaction fails
|
|
239
219
|
*
|
|
220
|
+
* @example
|
|
240
221
|
* ```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
222
|
* await kvstoreClient.setFileUrlAndHash('example.com');
|
|
252
223
|
* await kvstoreClient.setFileUrlAndHash('linkedin.com/example', 'linkedin_url');
|
|
253
224
|
* ```
|
|
@@ -256,7 +227,7 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
256
227
|
public async setFileUrlAndHash(
|
|
257
228
|
url: string,
|
|
258
229
|
urlKey = 'url',
|
|
259
|
-
txOptions:
|
|
230
|
+
txOptions: TransactionOverrides = {}
|
|
260
231
|
): Promise<void> {
|
|
261
232
|
if (!isValidUrl(url)) {
|
|
262
233
|
throw ErrorInvalidUrl;
|
|
@@ -268,13 +239,15 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
268
239
|
const hashKey = urlKey + '_hash';
|
|
269
240
|
|
|
270
241
|
try {
|
|
271
|
-
await (
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
242
|
+
await this.sendTxAndWait(
|
|
243
|
+
(overrides) =>
|
|
244
|
+
this.contract.setBulk(
|
|
245
|
+
[urlKey, hashKey],
|
|
246
|
+
[url, contentHash],
|
|
247
|
+
overrides
|
|
248
|
+
),
|
|
249
|
+
txOptions
|
|
250
|
+
);
|
|
278
251
|
} catch (e) {
|
|
279
252
|
if (e instanceof Error)
|
|
280
253
|
throw Error(`Failed to set URL and hash: ${e.message}`);
|
|
@@ -283,26 +256,17 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
283
256
|
/**
|
|
284
257
|
* Gets the value of a key-value pair in the contract.
|
|
285
258
|
*
|
|
286
|
-
* @param
|
|
287
|
-
* @param
|
|
288
|
-
* @
|
|
289
|
-
* @
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
* **Code example**
|
|
293
|
-
*
|
|
294
|
-
* > Need to have available stake.
|
|
259
|
+
* @param address - Address from which to get the key value.
|
|
260
|
+
* @param key - Key to obtain the value.
|
|
261
|
+
* @returns Value of the key.
|
|
262
|
+
* @throws ErrorKVStoreEmptyKey If the key is empty
|
|
263
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
264
|
+
* @throws Error If the contract call fails
|
|
295
265
|
*
|
|
266
|
+
* @example
|
|
296
267
|
* ```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
268
|
* const value = await kvstoreClient.get('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', 'Role');
|
|
269
|
+
* console.log('Value:', value);
|
|
306
270
|
* ```
|
|
307
271
|
*/
|
|
308
272
|
public async get(address: string, key: string): Promise<string> {
|
|
@@ -320,55 +284,37 @@ export class KVStoreClient extends BaseEthersClient {
|
|
|
320
284
|
}
|
|
321
285
|
|
|
322
286
|
/**
|
|
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)**
|
|
287
|
+
* Utility helpers for KVStore-related queries.
|
|
344
288
|
*
|
|
289
|
+
* @example
|
|
345
290
|
* ```ts
|
|
346
291
|
* import { ChainId, KVStoreUtils } from '@human-protocol/sdk';
|
|
347
292
|
*
|
|
348
|
-
* const
|
|
293
|
+
* const kvStoreData = await KVStoreUtils.getKVStoreData(
|
|
349
294
|
* ChainId.POLYGON_AMOY,
|
|
350
295
|
* "0x1234567890123456789012345678901234567890"
|
|
351
296
|
* );
|
|
297
|
+
* console.log('KVStore data:', kvStoreData);
|
|
352
298
|
* ```
|
|
353
299
|
*/
|
|
354
300
|
export class KVStoreUtils {
|
|
355
301
|
/**
|
|
356
302
|
* This function returns the KVStore data for a given address.
|
|
357
303
|
*
|
|
358
|
-
* @param
|
|
359
|
-
* @param
|
|
360
|
-
* @param
|
|
361
|
-
* @returns
|
|
362
|
-
* @throws
|
|
363
|
-
* @throws
|
|
364
|
-
*
|
|
365
|
-
* **Code example**
|
|
304
|
+
* @param chainId - Network in which the KVStore is deployed
|
|
305
|
+
* @param address - Address of the KVStore
|
|
306
|
+
* @param options - Optional configuration for subgraph requests.
|
|
307
|
+
* @returns KVStore data
|
|
308
|
+
* @throws ErrorUnsupportedChainID If the network's chainId is not supported
|
|
309
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
366
310
|
*
|
|
311
|
+
* @example
|
|
367
312
|
* ```ts
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
313
|
+
* const kvStoreData = await KVStoreUtils.getKVStoreData(
|
|
314
|
+
* ChainId.POLYGON_AMOY,
|
|
315
|
+
* "0x1234567890123456789012345678901234567890"
|
|
316
|
+
* );
|
|
317
|
+
* console.log('KVStore data:', kvStoreData);
|
|
372
318
|
* ```
|
|
373
319
|
*/
|
|
374
320
|
public static async getKVStoreData(
|
|
@@ -404,26 +350,24 @@ export class KVStoreUtils {
|
|
|
404
350
|
/**
|
|
405
351
|
* Gets the value of a key-value pair in the KVStore using the subgraph.
|
|
406
352
|
*
|
|
407
|
-
* @param
|
|
408
|
-
* @param
|
|
409
|
-
* @param
|
|
410
|
-
* @param
|
|
411
|
-
* @returns
|
|
412
|
-
* @throws
|
|
413
|
-
* @throws
|
|
414
|
-
* @throws
|
|
415
|
-
*
|
|
416
|
-
*
|
|
417
|
-
*
|
|
353
|
+
* @param chainId - Network in which the KVStore is deployed
|
|
354
|
+
* @param address - Address from which to get the key value.
|
|
355
|
+
* @param key - Key to obtain the value.
|
|
356
|
+
* @param options - Optional configuration for subgraph requests.
|
|
357
|
+
* @returns Value of the key.
|
|
358
|
+
* @throws ErrorUnsupportedChainID If the network's chainId is not supported
|
|
359
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
360
|
+
* @throws ErrorKVStoreEmptyKey If the key is empty
|
|
361
|
+
* @throws InvalidKeyError If the key is not found
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
418
364
|
* ```ts
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
422
|
-
*
|
|
423
|
-
*
|
|
424
|
-
*
|
|
425
|
-
* const value = await KVStoreUtils.get(chainId, address, key);
|
|
426
|
-
* console.log(value);
|
|
365
|
+
* const value = await KVStoreUtils.get(
|
|
366
|
+
* ChainId.POLYGON_AMOY,
|
|
367
|
+
* '0x1234567890123456789012345678901234567890',
|
|
368
|
+
* 'role'
|
|
369
|
+
* );
|
|
370
|
+
* console.log('Value:', value);
|
|
427
371
|
* ```
|
|
428
372
|
*/
|
|
429
373
|
public static async get(
|
|
@@ -458,22 +402,22 @@ export class KVStoreUtils {
|
|
|
458
402
|
/**
|
|
459
403
|
* Gets the URL value of the given entity, and verifies its hash.
|
|
460
404
|
*
|
|
461
|
-
* @param
|
|
462
|
-
* @param
|
|
463
|
-
* @param
|
|
464
|
-
* @param
|
|
465
|
-
* @returns
|
|
466
|
-
*
|
|
467
|
-
*
|
|
405
|
+
* @param chainId - Network in which the KVStore is deployed
|
|
406
|
+
* @param address - Address from which to get the URL value.
|
|
407
|
+
* @param urlKey - Configurable URL key. `url` by default.
|
|
408
|
+
* @param options - Optional configuration for subgraph requests.
|
|
409
|
+
* @returns URL value for the given address if it exists, and the content is valid
|
|
410
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
411
|
+
* @throws ErrorInvalidHash If the hash verification fails
|
|
412
|
+
* @throws Error If fetching URL or hash fails
|
|
468
413
|
*
|
|
414
|
+
* @example
|
|
469
415
|
* ```ts
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
* const url = await KVStoreUtils.getFileUrlAndVerifyHash(chainId, address);
|
|
476
|
-
* console.log(url);
|
|
416
|
+
* const url = await KVStoreUtils.getFileUrlAndVerifyHash(
|
|
417
|
+
* ChainId.POLYGON_AMOY,
|
|
418
|
+
* '0x1234567890123456789012345678901234567890'
|
|
419
|
+
* );
|
|
420
|
+
* console.log('Verified URL:', url);
|
|
477
421
|
* ```
|
|
478
422
|
*/
|
|
479
423
|
public static async getFileUrlAndVerifyHash(
|
|
@@ -521,20 +465,21 @@ export class KVStoreUtils {
|
|
|
521
465
|
/**
|
|
522
466
|
* Gets the public key of the given entity, and verifies its hash.
|
|
523
467
|
*
|
|
524
|
-
* @param
|
|
525
|
-
* @param
|
|
526
|
-
* @
|
|
527
|
-
*
|
|
528
|
-
*
|
|
468
|
+
* @param chainId - Network in which the KVStore is deployed
|
|
469
|
+
* @param address - Address from which to get the public key.
|
|
470
|
+
* @param options - Optional configuration for subgraph requests.
|
|
471
|
+
* @returns Public key for the given address if it exists, and the content is valid
|
|
472
|
+
* @throws ErrorInvalidAddress If the address is invalid
|
|
473
|
+
* @throws ErrorInvalidHash If the hash verification fails
|
|
474
|
+
* @throws Error If fetching the public key fails
|
|
529
475
|
*
|
|
476
|
+
* @example
|
|
530
477
|
* ```ts
|
|
531
|
-
*
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
*
|
|
536
|
-
* const publicKey = await KVStoreUtils.getPublicKey(chainId, address);
|
|
537
|
-
* console.log(publicKey);
|
|
478
|
+
* const publicKey = await KVStoreUtils.getPublicKey(
|
|
479
|
+
* ChainId.POLYGON_AMOY,
|
|
480
|
+
* '0x1234567890123456789012345678901234567890'
|
|
481
|
+
* );
|
|
482
|
+
* console.log('Public key:', publicKey);
|
|
538
483
|
* ```
|
|
539
484
|
*/
|
|
540
485
|
public static async getPublicKey(
|