@human-protocol/sdk 1.1.13 → 1.1.15
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/encryption.d.ts +245 -29
- package/dist/encryption.d.ts.map +1 -1
- package/dist/encryption.js +245 -29
- package/dist/escrow.d.ts +731 -117
- package/dist/escrow.d.ts.map +1 -1
- package/dist/escrow.js +734 -120
- package/dist/kvstore.d.ts +138 -15
- package/dist/kvstore.d.ts.map +1 -1
- package/dist/kvstore.js +138 -15
- package/dist/staking.d.ts +324 -54
- package/dist/staking.d.ts.map +1 -1
- package/dist/staking.js +324 -54
- package/dist/statistics.d.ts +266 -16
- package/dist/statistics.d.ts.map +1 -1
- package/dist/statistics.js +266 -16
- package/dist/storage.d.ts +155 -16
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +155 -16
- package/package.json +17 -1
- package/src/encryption.ts +246 -29
- package/src/escrow.ts +734 -120
- package/src/kvstore.ts +138 -15
- package/src/staking.ts +324 -54
- package/src/statistics.ts +266 -16
- package/src/storage.ts +156 -17
package/dist/kvstore.d.ts
CHANGED
|
@@ -1,6 +1,75 @@
|
|
|
1
1
|
import { Provider } from '@ethersproject/abstract-provider';
|
|
2
2
|
import { Signer } from 'ethers';
|
|
3
3
|
import { NetworkData } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* ## Introduction
|
|
6
|
+
*
|
|
7
|
+
* This client enables to perform actions on KVStore contract and obtain information from both the contracts and subgraph.
|
|
8
|
+
*
|
|
9
|
+
* Internally, the SDK will use one network or another according to the network ID of the `signerOrProvider`.
|
|
10
|
+
* To use this client, it is recommended to initialize it using the static `build` method.
|
|
11
|
+
*
|
|
12
|
+
* ```ts
|
|
13
|
+
* static async build(signerOrProvider: Signer | Provider);
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* A `Signer` or a `Provider` should be passed depending on the use case of this module:
|
|
17
|
+
*
|
|
18
|
+
* - **Signer**: when the user wants to use this model in order to send transactions caling the contract functions.
|
|
19
|
+
* - **Provider**: when the user wants to use this model in order to get information from the contracts or subgraph.
|
|
20
|
+
*
|
|
21
|
+
* ## Installation
|
|
22
|
+
*
|
|
23
|
+
* ### npm
|
|
24
|
+
* ```bash
|
|
25
|
+
* npm install @human-protocol/sdk
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* ### yarn
|
|
29
|
+
* ```bash
|
|
30
|
+
* yarn install @human-protocol/sdk
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* ## Code example
|
|
34
|
+
*
|
|
35
|
+
* ### Signer
|
|
36
|
+
*
|
|
37
|
+
* **Using private key(backend)**
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
41
|
+
* import { Wallet, providers } from 'ethers';
|
|
42
|
+
*
|
|
43
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
44
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
45
|
+
*
|
|
46
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
47
|
+
* const signer = new Wallet(privateKey, provider);
|
|
48
|
+
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* **Using Wagmi(frontend)**
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { useSigner, useChainId } from 'wagmi';
|
|
55
|
+
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
56
|
+
*
|
|
57
|
+
* const { data: signer } = useSigner();
|
|
58
|
+
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* ### Provider
|
|
62
|
+
*
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
65
|
+
* import { providers } from 'ethers';
|
|
66
|
+
*
|
|
67
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
68
|
+
*
|
|
69
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
70
|
+
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
4
73
|
export declare class KVStoreClient {
|
|
5
74
|
private contract;
|
|
6
75
|
private signerOrProvider;
|
|
@@ -21,30 +90,84 @@ export declare class KVStoreClient {
|
|
|
21
90
|
*/
|
|
22
91
|
static build(signerOrProvider: Signer | Provider): Promise<KVStoreClient>;
|
|
23
92
|
/**
|
|
24
|
-
*
|
|
93
|
+
* This function sets a key-value pair associated with the address that submits the transaction.
|
|
25
94
|
*
|
|
26
|
-
* @param {string} key
|
|
27
|
-
* @param {string} value
|
|
28
|
-
* @returns
|
|
29
|
-
*
|
|
95
|
+
* @param {string} key Key of the key-value pair
|
|
96
|
+
* @param {string} value Value of the key-value pair
|
|
97
|
+
* @returns Returns void if successful. Throws error if any.
|
|
98
|
+
*
|
|
99
|
+
*
|
|
100
|
+
* **Code example**
|
|
101
|
+
*
|
|
102
|
+
* > Need to have available stake.
|
|
103
|
+
*
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { Wallet, providers } from 'ethers';
|
|
106
|
+
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
107
|
+
*
|
|
108
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
109
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
110
|
+
*
|
|
111
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
112
|
+
* const signer = new Wallet(privateKey, provider);
|
|
113
|
+
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
114
|
+
*
|
|
115
|
+
* await kvstoreClient.set('Role', 'RecordingOracle');
|
|
116
|
+
* ```
|
|
30
117
|
*/
|
|
31
118
|
set(key: string, value: string): Promise<void>;
|
|
32
119
|
/**
|
|
33
|
-
*
|
|
120
|
+
* This function sets key-value pairs in bulk associated with the address that submits the transaction.
|
|
121
|
+
*
|
|
122
|
+
* @param {string[]} keys Array of keys (keys and value must have the same order)
|
|
123
|
+
* @param {string[]} values Array of values
|
|
124
|
+
* @returns Returns void if successful. Throws error if any.
|
|
125
|
+
*
|
|
126
|
+
*
|
|
127
|
+
* **Code example**
|
|
128
|
+
*
|
|
129
|
+
* > Need to have available stake.
|
|
34
130
|
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
131
|
+
* ```ts
|
|
132
|
+
* import { Wallet, providers } from 'ethers';
|
|
133
|
+
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
134
|
+
*
|
|
135
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
136
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
137
|
+
*
|
|
138
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
139
|
+
* const signer = new Wallet(privateKey, provider);
|
|
140
|
+
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
141
|
+
*
|
|
142
|
+
* const keys = ['Role', 'Webhook_url'];
|
|
143
|
+
* const values = ['RecordingOracle', 'http://localhost'];
|
|
144
|
+
* await kvstoreClient.set(keys, values);
|
|
145
|
+
* ```
|
|
39
146
|
*/
|
|
40
147
|
setBulk(keys: string[], values: string[]): Promise<void>;
|
|
41
148
|
/**
|
|
42
|
-
*
|
|
149
|
+
* This function returns the value for a specified key and address.
|
|
150
|
+
*
|
|
151
|
+
* @param {string} address Address from which to get the key value.
|
|
152
|
+
* @param {string} key Key to obtain the value.
|
|
153
|
+
* @returns {string} Value of the key.
|
|
154
|
+
*
|
|
155
|
+
*
|
|
156
|
+
* **Code example**
|
|
157
|
+
*
|
|
158
|
+
* > Need to have available stake.
|
|
159
|
+
*
|
|
160
|
+
* ```ts
|
|
161
|
+
* import { providers } from 'ethers';
|
|
162
|
+
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
163
|
+
*
|
|
164
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
165
|
+
*
|
|
166
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
167
|
+
* const kvstoreClient = await KVStoreClient.build(provider);
|
|
43
168
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* @returns {Promise<string>} - The value of the key-value pair if it exists
|
|
47
|
-
* @throws {Error} - An error object if an error occurred
|
|
169
|
+
* const value = await kvstoreClient.get('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', 'Role');
|
|
170
|
+
* ```
|
|
48
171
|
*/
|
|
49
172
|
get(address: string, key: string): Promise<string>;
|
|
50
173
|
}
|
package/dist/kvstore.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"kvstore.d.ts","sourceRoot":"","sources":["../src/kvstore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAM5D,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAYxC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,gBAAgB,CAAoB;IAE5C;;;;;OAKG;gBACS,gBAAgB,EAAE,MAAM,GAAG,QAAQ,EAAE,OAAO,EAAE,WAAW;IAQrE;;;;;;;OAOG;WACiB,KAAK,CAAC,gBAAgB,EAAE,MAAM,GAAG,QAAQ;IAsB7D
|
|
1
|
+
{"version":3,"file":"kvstore.d.ts","sourceRoot":"","sources":["../src/kvstore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAM5D,OAAO,EAAE,MAAM,EAAU,MAAM,QAAQ,CAAC;AAYxC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,gBAAgB,CAAoB;IAE5C;;;;;OAKG;gBACS,gBAAgB,EAAE,MAAM,GAAG,QAAQ,EAAE,OAAO,EAAE,WAAW;IAQrE;;;;;;;OAOG;WACiB,KAAK,CAAC,gBAAgB,EAAE,MAAM,GAAG,QAAQ;IAsB7D;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IAEU,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU3D;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IAEU,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAarE;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACU,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAYhE"}
|
package/dist/kvstore.js
CHANGED
|
@@ -15,6 +15,75 @@ const ethers_1 = require("ethers");
|
|
|
15
15
|
const constants_1 = require("./constants");
|
|
16
16
|
const decorators_1 = require("./decorators");
|
|
17
17
|
const error_1 = require("./error");
|
|
18
|
+
/**
|
|
19
|
+
* ## Introduction
|
|
20
|
+
*
|
|
21
|
+
* This client enables to perform actions on KVStore contract and obtain information from both the contracts and subgraph.
|
|
22
|
+
*
|
|
23
|
+
* Internally, the SDK will use one network or another according to the network ID of the `signerOrProvider`.
|
|
24
|
+
* To use this client, it is recommended to initialize it using the static `build` method.
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* static async build(signerOrProvider: Signer | Provider);
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* A `Signer` or a `Provider` should be passed depending on the use case of this module:
|
|
31
|
+
*
|
|
32
|
+
* - **Signer**: when the user wants to use this model in order to send transactions caling the contract functions.
|
|
33
|
+
* - **Provider**: when the user wants to use this model in order to get information from the contracts or subgraph.
|
|
34
|
+
*
|
|
35
|
+
* ## Installation
|
|
36
|
+
*
|
|
37
|
+
* ### npm
|
|
38
|
+
* ```bash
|
|
39
|
+
* npm install @human-protocol/sdk
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* ### yarn
|
|
43
|
+
* ```bash
|
|
44
|
+
* yarn install @human-protocol/sdk
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* ## Code example
|
|
48
|
+
*
|
|
49
|
+
* ### Signer
|
|
50
|
+
*
|
|
51
|
+
* **Using private key(backend)**
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
55
|
+
* import { Wallet, providers } from 'ethers';
|
|
56
|
+
*
|
|
57
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
58
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
59
|
+
*
|
|
60
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
61
|
+
* const signer = new Wallet(privateKey, provider);
|
|
62
|
+
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* **Using Wagmi(frontend)**
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* import { useSigner, useChainId } from 'wagmi';
|
|
69
|
+
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
70
|
+
*
|
|
71
|
+
* const { data: signer } = useSigner();
|
|
72
|
+
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* ### Provider
|
|
76
|
+
*
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
79
|
+
* import { providers } from 'ethers';
|
|
80
|
+
*
|
|
81
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
82
|
+
*
|
|
83
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
84
|
+
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
18
87
|
class KVStoreClient {
|
|
19
88
|
/**
|
|
20
89
|
* **KVStoreClient constructor**
|
|
@@ -53,12 +122,30 @@ class KVStoreClient {
|
|
|
53
122
|
return new KVStoreClient(signerOrProvider, networkData);
|
|
54
123
|
}
|
|
55
124
|
/**
|
|
56
|
-
*
|
|
125
|
+
* This function sets a key-value pair associated with the address that submits the transaction.
|
|
57
126
|
*
|
|
58
|
-
* @param {string} key
|
|
59
|
-
* @param {string} value
|
|
60
|
-
* @returns
|
|
61
|
-
*
|
|
127
|
+
* @param {string} key Key of the key-value pair
|
|
128
|
+
* @param {string} value Value of the key-value pair
|
|
129
|
+
* @returns Returns void if successful. Throws error if any.
|
|
130
|
+
*
|
|
131
|
+
*
|
|
132
|
+
* **Code example**
|
|
133
|
+
*
|
|
134
|
+
* > Need to have available stake.
|
|
135
|
+
*
|
|
136
|
+
* ```ts
|
|
137
|
+
* import { Wallet, providers } from 'ethers';
|
|
138
|
+
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
139
|
+
*
|
|
140
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
141
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
142
|
+
*
|
|
143
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
144
|
+
* const signer = new Wallet(privateKey, provider);
|
|
145
|
+
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
146
|
+
*
|
|
147
|
+
* await kvstoreClient.set('Role', 'RecordingOracle');
|
|
148
|
+
* ```
|
|
62
149
|
*/
|
|
63
150
|
async set(key, value) {
|
|
64
151
|
if (!ethers_1.Signer.isSigner(this.signerOrProvider))
|
|
@@ -74,12 +161,32 @@ class KVStoreClient {
|
|
|
74
161
|
}
|
|
75
162
|
}
|
|
76
163
|
/**
|
|
77
|
-
*
|
|
164
|
+
* This function sets key-value pairs in bulk associated with the address that submits the transaction.
|
|
165
|
+
*
|
|
166
|
+
* @param {string[]} keys Array of keys (keys and value must have the same order)
|
|
167
|
+
* @param {string[]} values Array of values
|
|
168
|
+
* @returns Returns void if successful. Throws error if any.
|
|
169
|
+
*
|
|
170
|
+
*
|
|
171
|
+
* **Code example**
|
|
172
|
+
*
|
|
173
|
+
* > Need to have available stake.
|
|
78
174
|
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
175
|
+
* ```ts
|
|
176
|
+
* import { Wallet, providers } from 'ethers';
|
|
177
|
+
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
178
|
+
*
|
|
179
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
180
|
+
* const privateKey = 'YOUR_PRIVATE_KEY'
|
|
181
|
+
*
|
|
182
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
183
|
+
* const signer = new Wallet(privateKey, provider);
|
|
184
|
+
* const kvstoreClient = await KVStoreClient.build(signer);
|
|
185
|
+
*
|
|
186
|
+
* const keys = ['Role', 'Webhook_url'];
|
|
187
|
+
* const values = ['RecordingOracle', 'http://localhost'];
|
|
188
|
+
* await kvstoreClient.set(keys, values);
|
|
189
|
+
* ```
|
|
83
190
|
*/
|
|
84
191
|
async setBulk(keys, values) {
|
|
85
192
|
if (!ethers_1.Signer.isSigner(this.signerOrProvider))
|
|
@@ -97,12 +204,28 @@ class KVStoreClient {
|
|
|
97
204
|
}
|
|
98
205
|
}
|
|
99
206
|
/**
|
|
100
|
-
*
|
|
207
|
+
* This function returns the value for a specified key and address.
|
|
208
|
+
*
|
|
209
|
+
* @param {string} address Address from which to get the key value.
|
|
210
|
+
* @param {string} key Key to obtain the value.
|
|
211
|
+
* @returns {string} Value of the key.
|
|
212
|
+
*
|
|
213
|
+
*
|
|
214
|
+
* **Code example**
|
|
215
|
+
*
|
|
216
|
+
* > Need to have available stake.
|
|
217
|
+
*
|
|
218
|
+
* ```ts
|
|
219
|
+
* import { providers } from 'ethers';
|
|
220
|
+
* import { KVStoreClient } from '@human-protocol/sdk';
|
|
221
|
+
*
|
|
222
|
+
* const rpcUrl = 'YOUR_RPC_URL';
|
|
223
|
+
*
|
|
224
|
+
* const provider = new providers.JsonRpcProvider(rpcUrl);
|
|
225
|
+
* const kvstoreClient = await KVStoreClient.build(provider);
|
|
101
226
|
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* @returns {Promise<string>} - The value of the key-value pair if it exists
|
|
105
|
-
* @throws {Error} - An error object if an error occurred
|
|
227
|
+
* const value = await kvstoreClient.get('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', 'Role');
|
|
228
|
+
* ```
|
|
106
229
|
*/
|
|
107
230
|
async get(address, key) {
|
|
108
231
|
if (key === '')
|