@human-protocol/sdk 1.1.19 → 2.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/dist/base.d.ts +4 -5
- package/dist/base.d.ts.map +1 -1
- package/dist/base.js +3 -3
- package/dist/constants.js +3 -3
- package/dist/decorators.d.ts.map +1 -1
- package/dist/decorators.js +4 -2
- package/dist/error.d.ts +0 -6
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +2 -14
- package/dist/escrow.d.ts +23 -24
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +86 -90
- package/dist/graphql/queries/{staking.d.ts → operator.d.ts} +2 -1
- package/dist/graphql/queries/operator.d.ts.map +1 -0
- package/dist/graphql/queries/{staking.js → operator.js} +24 -1
- package/dist/graphql/types.d.ts +5 -6
- package/dist/graphql/types.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/interfaces.d.ts +28 -18
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/kvstore.d.ts +41 -20
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +61 -45
- package/dist/operator.d.ts +68 -0
- package/dist/operator.d.ts.map +1 -0
- package/dist/operator.js +153 -0
- package/dist/staking.d.ts +24 -91
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +47 -166
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +7 -6
- package/dist/types.d.ts +1 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +0 -7
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +8 -28
- package/package.json +4 -4
- package/src/base.ts +5 -6
- package/src/constants.ts +3 -3
- package/src/decorators.ts +3 -2
- package/src/error.ts +0 -12
- package/src/escrow.ts +101 -114
- package/src/graphql/queries/{staking.ts → operator.ts} +24 -0
- package/src/graphql/types.ts +5 -7
- package/src/index.ts +2 -0
- package/src/interfaces.ts +30 -18
- package/src/kvstore.ts +73 -52
- package/src/operator.ts +192 -0
- package/src/staking.ts +49 -182
- package/src/statistics.ts +8 -9
- package/src/types.ts +1 -3
- package/src/utils.ts +7 -29
- package/dist/graphql/queries/staking.d.ts.map +0 -1
package/dist/interfaces.d.ts
CHANGED
|
@@ -1,36 +1,46 @@
|
|
|
1
|
-
import { BigNumber } from 'ethers';
|
|
2
1
|
import { EscrowStatus } from './types';
|
|
3
2
|
import { ChainId } from './enums';
|
|
4
3
|
export interface IAllocation {
|
|
5
4
|
escrowAddress: string;
|
|
6
5
|
staker: string;
|
|
7
|
-
tokens:
|
|
8
|
-
createdAt:
|
|
9
|
-
closedAt:
|
|
6
|
+
tokens: bigint;
|
|
7
|
+
createdAt: bigint;
|
|
8
|
+
closedAt: bigint;
|
|
10
9
|
}
|
|
11
10
|
export interface IReward {
|
|
12
11
|
escrowAddress: string;
|
|
13
|
-
amount:
|
|
12
|
+
amount: bigint;
|
|
14
13
|
}
|
|
15
14
|
export interface ILeader {
|
|
16
15
|
id: string;
|
|
16
|
+
chainId: ChainId;
|
|
17
17
|
address: string;
|
|
18
|
-
amountStaked:
|
|
19
|
-
amountAllocated:
|
|
20
|
-
amountLocked:
|
|
21
|
-
lockedUntilTimestamp:
|
|
22
|
-
amountWithdrawn:
|
|
23
|
-
amountSlashed:
|
|
24
|
-
reputation:
|
|
25
|
-
reward:
|
|
26
|
-
amountJobsLaunched:
|
|
18
|
+
amountStaked: bigint;
|
|
19
|
+
amountAllocated: bigint;
|
|
20
|
+
amountLocked: bigint;
|
|
21
|
+
lockedUntilTimestamp: bigint;
|
|
22
|
+
amountWithdrawn: bigint;
|
|
23
|
+
amountSlashed: bigint;
|
|
24
|
+
reputation: bigint;
|
|
25
|
+
reward: bigint;
|
|
26
|
+
amountJobsLaunched: bigint;
|
|
27
27
|
role?: string;
|
|
28
|
-
fee?:
|
|
28
|
+
fee?: bigint;
|
|
29
29
|
publicKey?: string;
|
|
30
30
|
webhookUrl?: string;
|
|
31
31
|
url?: string;
|
|
32
32
|
}
|
|
33
33
|
export interface ILeadersFilter {
|
|
34
|
+
networks: ChainId[];
|
|
35
|
+
role?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface IReputationNetwork {
|
|
38
|
+
id: string;
|
|
39
|
+
address: string;
|
|
40
|
+
operators: IOperator[];
|
|
41
|
+
}
|
|
42
|
+
export interface IOperator {
|
|
43
|
+
address: string;
|
|
34
44
|
role?: string;
|
|
35
45
|
}
|
|
36
46
|
export interface IEscrowsFilter {
|
|
@@ -48,9 +58,9 @@ export interface IEscrowConfig {
|
|
|
48
58
|
recordingOracle: string;
|
|
49
59
|
reputationOracle: string;
|
|
50
60
|
exchangeOracle: string;
|
|
51
|
-
recordingOracleFee:
|
|
52
|
-
reputationOracleFee:
|
|
53
|
-
exchangeOracleFee:
|
|
61
|
+
recordingOracleFee: bigint;
|
|
62
|
+
reputationOracleFee: bigint;
|
|
63
|
+
exchangeOracleFee: bigint;
|
|
54
64
|
manifestUrl: string;
|
|
55
65
|
manifestHash: string;
|
|
56
66
|
}
|
package/dist/interfaces.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,OAAO;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,MA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,CAAC;IACV,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,QAAQ;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,EAAE,CAAC,EAAE,IAAI,CAAC;IACV,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,aAAa;IAC5B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,EAAE,CAAC,EAAE,IAAI,CAAC;CACX"}
|
package/dist/kvstore.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Overrides, Signer } from 'ethers';
|
|
1
|
+
import { ContractRunner, Overrides } from 'ethers';
|
|
3
2
|
import { BaseEthersClient } from './base';
|
|
4
3
|
import { NetworkData } from './types';
|
|
5
4
|
/**
|
|
@@ -7,11 +6,11 @@ import { NetworkData } from './types';
|
|
|
7
6
|
*
|
|
8
7
|
* This client enables to perform actions on KVStore contract and obtain information from both the contracts and subgraph.
|
|
9
8
|
*
|
|
10
|
-
* Internally, the SDK will use one network or another according to the network ID of the `
|
|
9
|
+
* Internally, the SDK will use one network or another according to the network ID of the `runner`.
|
|
11
10
|
* To use this client, it is recommended to initialize it using the static `build` method.
|
|
12
11
|
*
|
|
13
12
|
* ```ts
|
|
14
|
-
* static async build(
|
|
13
|
+
* static async build(runner: ContractRunner);
|
|
15
14
|
* ```
|
|
16
15
|
*
|
|
17
16
|
* A `Signer` or a `Provider` should be passed depending on the use case of this module:
|
|
@@ -76,20 +75,20 @@ export declare class KVStoreClient extends BaseEthersClient {
|
|
|
76
75
|
/**
|
|
77
76
|
* **KVStoreClient constructor**
|
|
78
77
|
*
|
|
79
|
-
* @param {
|
|
78
|
+
* @param {ContractRunner} runner - The Runner object to interact with the Ethereum network
|
|
80
79
|
* @param {NetworkData} network - The network information required to connect to the KVStore contract
|
|
81
80
|
*/
|
|
82
|
-
constructor(
|
|
81
|
+
constructor(runner: ContractRunner, networkData: NetworkData);
|
|
83
82
|
/**
|
|
84
|
-
* Creates an instance of KVStoreClient from a
|
|
83
|
+
* Creates an instance of KVStoreClient from a runner.
|
|
85
84
|
*
|
|
86
|
-
* @param {
|
|
85
|
+
* @param {ContractRunner} runner - The Runner object to interact with the Ethereum network
|
|
87
86
|
*
|
|
88
87
|
* @returns {Promise<KVStoreClient>} - An instance of KVStoreClient
|
|
89
88
|
* @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
|
|
90
89
|
* @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
|
|
91
90
|
*/
|
|
92
|
-
static build(
|
|
91
|
+
static build(runner: ContractRunner): Promise<KVStoreClient>;
|
|
93
92
|
/**
|
|
94
93
|
* This function sets a key-value pair associated with the address that submits the transaction.
|
|
95
94
|
*
|
|
@@ -142,14 +141,14 @@ export declare class KVStoreClient extends BaseEthersClient {
|
|
|
142
141
|
* const signer = new Wallet(privateKey, provider);
|
|
143
142
|
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
144
143
|
*
|
|
145
|
-
* const keys = ['role', '
|
|
144
|
+
* const keys = ['role', 'webhook_url'];
|
|
146
145
|
* const values = ['RecordingOracle', 'http://localhost'];
|
|
147
146
|
* await kvstoreClient.set(keys, values);
|
|
148
147
|
* ```
|
|
149
148
|
*/
|
|
150
149
|
setBulk(keys: string[], values: string[], txOptions?: Overrides): Promise<void>;
|
|
151
150
|
/**
|
|
152
|
-
*
|
|
151
|
+
* Sets a URL value for the address that submits the transaction, and its hash.
|
|
153
152
|
*
|
|
154
153
|
* @param {string} url URL to set
|
|
155
154
|
* @param {string | undefined} urlKey Configurable URL key. `url` by default.
|
|
@@ -170,13 +169,13 @@ export declare class KVStoreClient extends BaseEthersClient {
|
|
|
170
169
|
* const signer = new Wallet(privateKey, provider);
|
|
171
170
|
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
172
171
|
*
|
|
173
|
-
* await kvstoreClient.
|
|
174
|
-
* await kvstoreClient.
|
|
172
|
+
* await kvstoreClient.setFileUrlAndHash('example.com');
|
|
173
|
+
* await kvstoreClient.setFileUrlAndHash('linkedin.com/example', 'linkedin_url);
|
|
175
174
|
* ```
|
|
176
175
|
*/
|
|
177
|
-
|
|
176
|
+
setFileUrlAndHash(url: string, urlKey?: string, txOptions?: Overrides): Promise<void>;
|
|
178
177
|
/**
|
|
179
|
-
*
|
|
178
|
+
* Gets the value of a key-value pair in the contract.
|
|
180
179
|
*
|
|
181
180
|
* @param {string} address Address from which to get the key value.
|
|
182
181
|
* @param {string} key Key to obtain the value.
|
|
@@ -201,7 +200,7 @@ export declare class KVStoreClient extends BaseEthersClient {
|
|
|
201
200
|
*/
|
|
202
201
|
get(address: string, key: string): Promise<string>;
|
|
203
202
|
/**
|
|
204
|
-
*
|
|
203
|
+
* Gets the URL value of the given entity, and verify its hash.
|
|
205
204
|
*
|
|
206
205
|
* @param {string} address Address from which to get the URL value.
|
|
207
206
|
* @param {string} urlKey Configurable URL key. `url` by default.
|
|
@@ -219,13 +218,35 @@ export declare class KVStoreClient extends BaseEthersClient {
|
|
|
219
218
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
220
219
|
* const kvstoreClient = await KVStoreClient.build(provider);
|
|
221
220
|
*
|
|
222
|
-
* const url = await kvstoreClient.
|
|
223
|
-
* const linkedinUrl = await kvstoreClient.
|
|
221
|
+
* const url = await kvstoreClient.getFileUrlAndVerifyHash('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
|
|
222
|
+
* const linkedinUrl = await kvstoreClient.getFileUrlAndVerifyHash(
|
|
224
223
|
* '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
225
|
-
* '
|
|
224
|
+
* 'linkedin_url'
|
|
226
225
|
* );
|
|
227
226
|
* ```
|
|
228
227
|
*/
|
|
229
|
-
|
|
228
|
+
getFileUrlAndVerifyHash(address: string, urlKey?: string): Promise<string>;
|
|
229
|
+
/**
|
|
230
|
+
* Gets the public key of the given entity, and verify its hash.
|
|
231
|
+
*
|
|
232
|
+
* @param {string} address Address from which to get the public key.
|
|
233
|
+
* @returns {string} Public key for the given address if exists, and the content is valid
|
|
234
|
+
*
|
|
235
|
+
*
|
|
236
|
+
* **Code example**
|
|
237
|
+
*
|
|
238
|
+
* ```ts
|
|
239
|
+
* import { providers } from 'ethers';
|
|
240
|
+
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
241
|
+
*
|
|
242
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
243
|
+
*
|
|
244
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
245
|
+
* const kvstoreClient = await KVStoreClient.build(provider);
|
|
246
|
+
*
|
|
247
|
+
* const publicKey = await kvstoreClient.getPublicKey('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
|
|
248
|
+
* ```
|
|
249
|
+
*/
|
|
250
|
+
getPublicKey(address: string): Promise<string>;
|
|
230
251
|
}
|
|
231
252
|
//# sourceMappingURL=kvstore.d.ts.map
|
package/dist/kvstore.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kvstore.d.ts","sourceRoot":"","sources":["../src/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,EAAE,MAAM,EACf,MAAM,SAAQ,GACb,OAAO,CAAC,MAAM,CAAC;IAkClB;;;;;;;;;;;;;;;;;;;;OAoBG;IACU,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAc5D"}
|
package/dist/kvstore.js
CHANGED
|
@@ -22,11 +22,11 @@ const utils_1 = require("./utils");
|
|
|
22
22
|
*
|
|
23
23
|
* This client enables to perform actions on KVStore contract and obtain information from both the contracts and subgraph.
|
|
24
24
|
*
|
|
25
|
-
* Internally, the SDK will use one network or another according to the network ID of the `
|
|
25
|
+
* Internally, the SDK will use one network or another according to the network ID of the `runner`.
|
|
26
26
|
* To use this client, it is recommended to initialize it using the static `build` method.
|
|
27
27
|
*
|
|
28
28
|
* ```ts
|
|
29
|
-
* static async build(
|
|
29
|
+
* static async build(runner: ContractRunner);
|
|
30
30
|
* ```
|
|
31
31
|
*
|
|
32
32
|
* A `Signer` or a `Provider` should be passed depending on the use case of this module:
|
|
@@ -90,39 +90,33 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
90
90
|
/**
|
|
91
91
|
* **KVStoreClient constructor**
|
|
92
92
|
*
|
|
93
|
-
* @param {
|
|
93
|
+
* @param {ContractRunner} runner - The Runner object to interact with the Ethereum network
|
|
94
94
|
* @param {NetworkData} network - The network information required to connect to the KVStore contract
|
|
95
95
|
*/
|
|
96
|
-
constructor(
|
|
97
|
-
super(
|
|
98
|
-
this.contract = typechain_types_1.KVStore__factory.connect(networkData.kvstoreAddress,
|
|
96
|
+
constructor(runner, networkData) {
|
|
97
|
+
super(runner, networkData);
|
|
98
|
+
this.contract = typechain_types_1.KVStore__factory.connect(networkData.kvstoreAddress, runner);
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
|
-
* Creates an instance of KVStoreClient from a
|
|
101
|
+
* Creates an instance of KVStoreClient from a runner.
|
|
102
102
|
*
|
|
103
|
-
* @param {
|
|
103
|
+
* @param {ContractRunner} runner - The Runner object to interact with the Ethereum network
|
|
104
104
|
*
|
|
105
105
|
* @returns {Promise<KVStoreClient>} - An instance of KVStoreClient
|
|
106
106
|
* @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
|
|
107
107
|
* @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
|
|
108
108
|
*/
|
|
109
|
-
static async build(
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (!signerOrProvider.provider) {
|
|
113
|
-
throw error_1.ErrorProviderDoesNotExist;
|
|
114
|
-
}
|
|
115
|
-
network = await signerOrProvider.provider.getNetwork();
|
|
109
|
+
static async build(runner) {
|
|
110
|
+
if (!runner.provider) {
|
|
111
|
+
throw error_1.ErrorProviderDoesNotExist;
|
|
116
112
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
const chainId = network.chainId;
|
|
113
|
+
const network = await runner.provider?.getNetwork();
|
|
114
|
+
const chainId = Number(network?.chainId);
|
|
121
115
|
const networkData = constants_1.NETWORKS[chainId];
|
|
122
116
|
if (!networkData) {
|
|
123
117
|
throw error_1.ErrorUnsupportedChainID;
|
|
124
118
|
}
|
|
125
|
-
return new KVStoreClient(
|
|
119
|
+
return new KVStoreClient(runner, networkData);
|
|
126
120
|
}
|
|
127
121
|
/**
|
|
128
122
|
* This function sets a key-value pair associated with the address that submits the transaction.
|
|
@@ -152,8 +146,6 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
152
146
|
* ```
|
|
153
147
|
*/
|
|
154
148
|
async set(key, value, txOptions = {}) {
|
|
155
|
-
if (!ethers_1.Signer.isSigner(this.signerOrProvider))
|
|
156
|
-
throw error_1.ErrorSigner;
|
|
157
149
|
if (key === '')
|
|
158
150
|
throw error_1.ErrorKVStoreEmptyKey;
|
|
159
151
|
try {
|
|
@@ -188,14 +180,12 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
188
180
|
* const signer = new Wallet(privateKey, provider);
|
|
189
181
|
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
190
182
|
*
|
|
191
|
-
* const keys = ['role', '
|
|
183
|
+
* const keys = ['role', 'webhook_url'];
|
|
192
184
|
* const values = ['RecordingOracle', 'http://localhost'];
|
|
193
185
|
* await kvstoreClient.set(keys, values);
|
|
194
186
|
* ```
|
|
195
187
|
*/
|
|
196
188
|
async setBulk(keys, values, txOptions = {}) {
|
|
197
|
-
if (!ethers_1.Signer.isSigner(this.signerOrProvider))
|
|
198
|
-
throw error_1.ErrorSigner;
|
|
199
189
|
if (keys.length !== values.length)
|
|
200
190
|
throw error_1.ErrorKVStoreArrayLength;
|
|
201
191
|
if (keys.includes(''))
|
|
@@ -209,7 +199,7 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
209
199
|
}
|
|
210
200
|
}
|
|
211
201
|
/**
|
|
212
|
-
*
|
|
202
|
+
* Sets a URL value for the address that submits the transaction, and its hash.
|
|
213
203
|
*
|
|
214
204
|
* @param {string} url URL to set
|
|
215
205
|
* @param {string | undefined} urlKey Configurable URL key. `url` by default.
|
|
@@ -230,20 +220,17 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
230
220
|
* const signer = new Wallet(privateKey, provider);
|
|
231
221
|
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
232
222
|
*
|
|
233
|
-
* await kvstoreClient.
|
|
234
|
-
* await kvstoreClient.
|
|
223
|
+
* await kvstoreClient.setFileUrlAndHash('example.com');
|
|
224
|
+
* await kvstoreClient.setFileUrlAndHash('linkedin.com/example', 'linkedin_url);
|
|
235
225
|
* ```
|
|
236
226
|
*/
|
|
237
|
-
async
|
|
238
|
-
if (!ethers_1.Signer.isSigner(this.signerOrProvider)) {
|
|
239
|
-
throw error_1.ErrorSigner;
|
|
240
|
-
}
|
|
227
|
+
async setFileUrlAndHash(url, urlKey = 'url', txOptions = {}) {
|
|
241
228
|
if (!(0, utils_1.isValidUrl)(url)) {
|
|
242
229
|
throw error_1.ErrorInvalidUrl;
|
|
243
230
|
}
|
|
244
231
|
const content = await fetch(url).then((res) => res.text());
|
|
245
|
-
const contentHash = ethers_1.ethers.
|
|
246
|
-
const hashKey = urlKey + '
|
|
232
|
+
const contentHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(content));
|
|
233
|
+
const hashKey = urlKey + '_hash';
|
|
247
234
|
try {
|
|
248
235
|
await (await this.contract.setBulk([urlKey, hashKey], [url, contentHash], txOptions)).wait();
|
|
249
236
|
}
|
|
@@ -253,7 +240,7 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
253
240
|
}
|
|
254
241
|
}
|
|
255
242
|
/**
|
|
256
|
-
*
|
|
243
|
+
* Gets the value of a key-value pair in the contract.
|
|
257
244
|
*
|
|
258
245
|
* @param {string} address Address from which to get the key value.
|
|
259
246
|
* @param {string} key Key to obtain the value.
|
|
@@ -279,7 +266,7 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
279
266
|
async get(address, key) {
|
|
280
267
|
if (key === '')
|
|
281
268
|
throw error_1.ErrorKVStoreEmptyKey;
|
|
282
|
-
if (!ethers_1.ethers.
|
|
269
|
+
if (!ethers_1.ethers.isAddress(address))
|
|
283
270
|
throw error_1.ErrorInvalidAddress;
|
|
284
271
|
try {
|
|
285
272
|
const result = await this.contract?.get(address, key);
|
|
@@ -292,7 +279,7 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
292
279
|
}
|
|
293
280
|
}
|
|
294
281
|
/**
|
|
295
|
-
*
|
|
282
|
+
* Gets the URL value of the given entity, and verify its hash.
|
|
296
283
|
*
|
|
297
284
|
* @param {string} address Address from which to get the URL value.
|
|
298
285
|
* @param {string} urlKey Configurable URL key. `url` by default.
|
|
@@ -310,17 +297,17 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
310
297
|
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
311
298
|
* const kvstoreClient = await KVStoreClient.build(provider);
|
|
312
299
|
*
|
|
313
|
-
* const url = await kvstoreClient.
|
|
314
|
-
* const linkedinUrl = await kvstoreClient.
|
|
300
|
+
* const url = await kvstoreClient.getFileUrlAndVerifyHash('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
|
|
301
|
+
* const linkedinUrl = await kvstoreClient.getFileUrlAndVerifyHash(
|
|
315
302
|
* '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266',
|
|
316
|
-
* '
|
|
303
|
+
* 'linkedin_url'
|
|
317
304
|
* );
|
|
318
305
|
* ```
|
|
319
306
|
*/
|
|
320
|
-
async
|
|
321
|
-
if (!ethers_1.ethers.
|
|
307
|
+
async getFileUrlAndVerifyHash(address, urlKey = 'url') {
|
|
308
|
+
if (!ethers_1.ethers.isAddress(address))
|
|
322
309
|
throw error_1.ErrorInvalidAddress;
|
|
323
|
-
const hashKey = urlKey + '
|
|
310
|
+
const hashKey = urlKey + '_hash';
|
|
324
311
|
let url = '', hash = '';
|
|
325
312
|
try {
|
|
326
313
|
url = await this.contract?.get(address, urlKey);
|
|
@@ -341,12 +328,41 @@ class KVStoreClient extends base_1.BaseEthersClient {
|
|
|
341
328
|
throw Error(`Failed to get Hash: ${e.message}`);
|
|
342
329
|
}
|
|
343
330
|
const content = await fetch(url).then((res) => res.text());
|
|
344
|
-
const contentHash = ethers_1.ethers.
|
|
331
|
+
const contentHash = ethers_1.ethers.keccak256(ethers_1.ethers.toUtf8Bytes(content));
|
|
345
332
|
if (hash !== contentHash) {
|
|
346
333
|
throw error_1.ErrorInvalidHash;
|
|
347
334
|
}
|
|
348
335
|
return url;
|
|
349
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* Gets the public key of the given entity, and verify its hash.
|
|
339
|
+
*
|
|
340
|
+
* @param {string} address Address from which to get the public key.
|
|
341
|
+
* @returns {string} Public key for the given address if exists, and the content is valid
|
|
342
|
+
*
|
|
343
|
+
*
|
|
344
|
+
* **Code example**
|
|
345
|
+
*
|
|
346
|
+
* ```ts
|
|
347
|
+
* import { providers } from 'ethers';
|
|
348
|
+
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
349
|
+
*
|
|
350
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
351
|
+
*
|
|
352
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
353
|
+
* const kvstoreClient = await KVStoreClient.build(provider);
|
|
354
|
+
*
|
|
355
|
+
* const publicKey = await kvstoreClient.getPublicKey('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266');
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
async getPublicKey(address) {
|
|
359
|
+
const publicKeyUrl = await this.getFileUrlAndVerifyHash(address, constants_1.KVStoreKeys.publicKey);
|
|
360
|
+
if (publicKeyUrl === '') {
|
|
361
|
+
return '';
|
|
362
|
+
}
|
|
363
|
+
const publicKey = await fetch(publicKeyUrl).then((res) => res.text());
|
|
364
|
+
return publicKey;
|
|
365
|
+
}
|
|
350
366
|
}
|
|
351
367
|
__decorate([
|
|
352
368
|
decorators_1.requiresSigner,
|
|
@@ -365,5 +381,5 @@ __decorate([
|
|
|
365
381
|
__metadata("design:type", Function),
|
|
366
382
|
__metadata("design:paramtypes", [String, Object, Object]),
|
|
367
383
|
__metadata("design:returntype", Promise)
|
|
368
|
-
], KVStoreClient.prototype, "
|
|
384
|
+
], KVStoreClient.prototype, "setFileUrlAndHash", null);
|
|
369
385
|
exports.KVStoreClient = KVStoreClient;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ILeader, ILeadersFilter, IOperator, IReward } from './interfaces';
|
|
2
|
+
import { ChainId } from './enums';
|
|
3
|
+
export declare class OperatorUtils {
|
|
4
|
+
/**
|
|
5
|
+
* This function returns the leader data for the given address.
|
|
6
|
+
*
|
|
7
|
+
* @param {string} address Leader address.
|
|
8
|
+
* @returns {ILeader} Returns the leader details.
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
* **Code example**
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
15
|
+
*
|
|
16
|
+
* const leader = await OperatorUtils.getLeader(ChainId.POLYGON_MUMBAI, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
static getLeader(chainId: ChainId, address: string): Promise<ILeader>;
|
|
20
|
+
/**
|
|
21
|
+
* This function returns all the leader details of the protocol.
|
|
22
|
+
*
|
|
23
|
+
* @param {ILeadersFilter} filter Filter for the leaders.
|
|
24
|
+
* @returns {ILeader[]} Returns an array with all the leader details.
|
|
25
|
+
*
|
|
26
|
+
*
|
|
27
|
+
* **Code example**
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* import { OperatorUtils } from '@human-protocol/sdk';
|
|
31
|
+
*
|
|
32
|
+
* const leaders = await OperatorUtils.getLeaders();
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
static getLeaders(filter?: ILeadersFilter): Promise<ILeader[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Retrieves the reputation network operators of the specified address.
|
|
38
|
+
*
|
|
39
|
+
* @param {string} address - Address of the reputation oracle.
|
|
40
|
+
* @param {string} [role] - (Optional) Role of the operator.
|
|
41
|
+
* @returns {Promise<IOperator[]>} - Returns an array of operator details.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
46
|
+
*
|
|
47
|
+
* const operators = await OperatorUtils.getReputationNetworkOperators(ChainId.POLYGON_MUMBAI, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
static getReputationNetworkOperators(chainId: ChainId, address: string, role?: string): Promise<IOperator[]>;
|
|
51
|
+
/**
|
|
52
|
+
* This function returns information about the rewards for a given slasher address.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} slasherAddress Slasher address.
|
|
55
|
+
* @returns {IReward[]} Returns an array of Reward objects that contain the rewards earned by the user through slashing other users.
|
|
56
|
+
*
|
|
57
|
+
*
|
|
58
|
+
* **Code example**
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { OperatorUtils, ChainId } from '@human-protocol/sdk';
|
|
62
|
+
*
|
|
63
|
+
* const rewards = await OperatorUtils.getRewards(ChainId.POLYGON_MUMBAI, '0x62dD51230A30401C455c8398d06F85e4EaB6309f');
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
static getRewards(chainId: ChainId, slasherAddress: string): Promise<IReward[]>;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=operator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operator.d.ts","sourceRoot":"","sources":["../src/operator.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,OAAO,EACP,cAAc,EACd,SAAS,EAET,OAAO,EACR,MAAM,cAAc,CAAC;AAetB,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAGlC,qBAAa,aAAa;IACxB;;;;;;;;;;;;;;OAcG;WACiB,SAAS,CAC3B,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,OAAO,CAAC;IAuBnB;;;;;;;;;;;;;;OAcG;WACiB,UAAU,CAC5B,MAAM,GAAE,cAAuD,GAC9D,OAAO,CAAC,OAAO,EAAE,CAAC;IAuBrB;;;;;;;;;;;;;OAaG;WACiB,6BAA6B,CAC/C,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,SAAS,EAAE,CAAC;IAoBvB;;;;;;;;;;;;;;OAcG;WACiB,UAAU,CAC5B,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,OAAO,EAAE,CAAC;CA2BtB"}
|