@human-protocol/sdk 1.0.1 → 1.0.3

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.
Files changed (71) hide show
  1. package/README.md +1 -1
  2. package/dist/constants.d.ts +46 -0
  3. package/dist/constants.d.ts.map +1 -0
  4. package/dist/constants.js +203 -0
  5. package/dist/decorators.d.ts +2 -0
  6. package/dist/decorators.d.ts.map +1 -0
  7. package/dist/decorators.js +17 -0
  8. package/dist/enums.d.ts +17 -0
  9. package/dist/enums.d.ts.map +1 -0
  10. package/dist/enums.js +20 -0
  11. package/dist/error.d.ts +196 -0
  12. package/dist/error.d.ts.map +1 -0
  13. package/dist/error.js +229 -0
  14. package/dist/escrow.d.ts +176 -0
  15. package/dist/escrow.d.ts.map +1 -0
  16. package/dist/escrow.js +590 -0
  17. package/dist/index.d.ts +10 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +33 -0
  20. package/dist/init.d.ts +13 -0
  21. package/dist/init.d.ts.map +1 -0
  22. package/dist/init.js +35 -0
  23. package/dist/interfaces.d.ts +44 -0
  24. package/dist/interfaces.d.ts.map +1 -0
  25. package/dist/interfaces.js +2 -0
  26. package/dist/kvstore.d.ts +40 -0
  27. package/dist/kvstore.d.ts.map +1 -0
  28. package/dist/kvstore.js +106 -0
  29. package/dist/queries.d.ts +4 -0
  30. package/dist/queries.d.ts.map +1 -0
  31. package/dist/queries.js +22 -0
  32. package/dist/staking.d.ts +121 -0
  33. package/dist/staking.d.ts.map +1 -0
  34. package/dist/staking.js +381 -0
  35. package/dist/storage.d.ts +48 -0
  36. package/dist/storage.d.ts.map +1 -0
  37. package/dist/storage.js +164 -0
  38. package/dist/types.d.ts +123 -0
  39. package/dist/types.d.ts.map +1 -0
  40. package/dist/types.js +35 -0
  41. package/dist/utils.d.ts +32 -0
  42. package/dist/utils.d.ts.map +1 -0
  43. package/dist/utils.js +99 -0
  44. package/package.json +4 -7
  45. package/src/constants.ts +221 -4
  46. package/src/decorators.ts +21 -0
  47. package/src/enums.ts +16 -0
  48. package/src/error.ts +298 -16
  49. package/src/escrow.ts +754 -0
  50. package/src/index.ts +14 -1
  51. package/src/init.ts +45 -0
  52. package/src/interfaces.ts +50 -0
  53. package/src/kvstore.ts +93 -0
  54. package/src/queries.ts +18 -0
  55. package/src/staking.ts +421 -0
  56. package/src/storage.ts +159 -130
  57. package/src/types.ts +37 -574
  58. package/src/utils.ts +80 -76
  59. package/test/escrow.test.ts +1339 -0
  60. package/test/init.test.ts +88 -0
  61. package/test/kvstore.test.ts +208 -0
  62. package/test/staking.test.ts +640 -0
  63. package/test/storage.test.ts +422 -0
  64. package/test/utils/constants.ts +40 -0
  65. package/example/simple-existing-job.ts +0 -86
  66. package/example/simple-new-job-public.ts +0 -74
  67. package/example/simple-new-job.ts +0 -72
  68. package/src/job.ts +0 -821
  69. package/src/logger.ts +0 -29
  70. package/test/job.test.ts +0 -753
  71. package/test/utils/manifest.ts +0 -33
package/src/error.ts CHANGED
@@ -1,38 +1,320 @@
1
1
  /**
2
- * @constant {Error} - The job is not initialized yet.
2
+ * @constant {Error} - The Staking contract is missing.
3
3
  */
4
- export const ErrorJobNotInitialized = new Error('Job is not initialized');
4
+ export const ErrorStakingMissing = new Error('Staking contract is missing');
5
5
 
6
6
  /**
7
- * @constant {Error} - The job is not launched yet.
7
+ * @constant {Error} - The Storage client not initialised.
8
8
  */
9
- export const ErrorJobNotLaunched = new Error('Job is not launched');
9
+ export const ErrorStorageClientNotInitialized = new Error(
10
+ 'Storage client not initialized'
11
+ );
12
+
13
+ /**
14
+ * @constant {Error} - The Storage does not exists.
15
+ */
16
+ export const ErrorStorageClientNotExists = new Error(
17
+ 'Storage client does not exists'
18
+ );
19
+
20
+ /**
21
+ * @constant {Error} - The Storage credentials is missing.
22
+ */
23
+ export const ErrorStorageCredentialsMissing = new Error(
24
+ 'Storage credentials is missing'
25
+ );
26
+
27
+ /**
28
+ * @constant {Error} - The Storage bucket not found.
29
+ */
30
+ export const ErrorStorageBucketNotFound = new Error('Bucket not found');
31
+
32
+ /**
33
+ * @constant {Error} - The Storage file not found.
34
+ */
35
+ export const ErrorStorageFileNotFound = new Error('File not found');
36
+
37
+ /**
38
+ * @constant {Error} - The Storage file not uploaded.
39
+ */
40
+ export const ErrorStorageFileNotUploaded = new Error('File not uploaded');
41
+
42
+ /**
43
+ * @constant {Error} - The KVStore key can not be empty.
44
+ */
45
+ export const ErrorKVStoreEmptyKey = new Error('Key can not be empty');
46
+
47
+ /**
48
+ * @constant {Error} - The KVStore arrays must have the same length.
49
+ */
50
+ export const ErrorKVStoreArrayLength = new Error(
51
+ 'Arrays must have the same length'
52
+ );
53
+
54
+ /**
55
+ * @constant {Error} - The Address sent is invalid.
56
+ */
57
+ export const ErrorInvalidAddress = new Error('Invalid address');
58
+
59
+ /**
60
+ * @constant {Error} - The token address sent is invalid.
61
+ */
62
+ export const ErrorInvalidTokenAddress = new Error('Invalid token address');
63
+
64
+ /**
65
+ * @constant {Error} - Invalid recording oracle address provided.
66
+ */
67
+ export const ErrorInvalidRecordingOracleAddressProvided = new Error(
68
+ 'Invalid recording oracle address provided'
69
+ );
70
+
71
+ /**
72
+ * @constant {Error} - Invalid reputation oracle address provided.
73
+ */
74
+ export const ErrorInvalidReputationOracleAddressProvided = new Error(
75
+ 'Invalid reputation oracle address provided'
76
+ );
77
+
78
+ /**
79
+ * @constant {Error} - The Staking value must be positive.
80
+ */
81
+ export const ErrorStakingValueMustBePositive = new Error(
82
+ 'Value must be positive'
83
+ );
84
+
85
+ /**
86
+ * @constant {Error} - Invalid staking value: amount must be a BigNumber.
87
+ */
88
+ export const ErrorInvalidStakingValueType = new Error(
89
+ 'Invalid staking value: amount must be a BigNumber'
90
+ );
91
+
92
+ /**
93
+ * @constant {Error} - Invalid staking value: amount must be positive.
94
+ */
95
+ export const ErrorInvalidStakingValueSign = new Error(
96
+ 'Invalid staking value: amount must be positive'
97
+ );
98
+
99
+ /**
100
+ * @constant {Error} - Invalid slasher address provided.
101
+ */
102
+ export const ErrorInvalidSlasherAddressProvided = new Error(
103
+ 'Invalid slasher address provided'
104
+ );
105
+
106
+ /**
107
+ * @constant {Error} - Invalid staker address provided.
108
+ */
109
+ export const ErrorInvalidStakerAddressProvided = new Error(
110
+ 'Invalid staker address provided'
111
+ );
112
+
113
+ /**
114
+ * @constant {Error} - Invalid escrow address provided.
115
+ */
116
+ export const ErrorInvalidEscrowAddressProvided = new Error(
117
+ 'Invalid escrow address provided'
118
+ );
119
+
120
+ /**
121
+ * @constant {Error} - Error getting stakers data.
122
+ */
123
+ export const ErrorStakingGetStakers = new Error('Error getting stakers data');
124
+
125
+ /**
126
+ * @constant {Error} - Failed to approve staking amount: signerOrProvider is not a Signer instance.
127
+ */
128
+ export const ErrorFailedToApproveStakingAmountSignerDoesNotExist = new Error(
129
+ 'Failed to approve staking amount: signerOrProvider is not a Signer instance'
130
+ );
131
+
132
+ export const ErrorFailedToCheckAllowance = new Error(
133
+ 'Failed to check allowance'
134
+ );
10
135
 
11
136
  /**
12
- * @constant {Error} - The job is already launched.
137
+ * @constant {Error} - The HMToken amount not approved.
13
138
  */
14
- export const ErrorJobAlreadyLaunched = new Error('Job is already launched');
139
+ export const ErrorHMTokenAmountNotApproved = new Error('Amount not approved');
15
140
 
16
141
  /**
17
- * @constant {Error} - The reputation oracle is missing.
142
+ * @constant {Error} - Init provider does not exists.
18
143
  */
19
- export const ErrorReputationOracleMissing = new Error(
20
- 'Reputation oracle is missing'
144
+ export const ErrorInitProviderDoesNotExist = new Error(
145
+ 'Provider does not exist'
21
146
  );
22
147
 
23
148
  /**
24
- * @constant {Error} - The manifest is missing.
149
+ * @constant {Error} - Init with unsupported chain ID.
150
+ */
151
+ export const ErrorInitUnsupportedChainID = new Error('Unsupported chain ID');
152
+
153
+ /**
154
+ * @constant {Error} - Sending a transaction requires a signer.
155
+ */
156
+ export const ErrorSigner = new Error('Signer required');
157
+
158
+ /**
159
+ * @constant {Error} - Escrow address is not provided by the factory.
25
160
  */
26
- export const ErrorManifestMissing = new Error('Manifest is missing');
161
+ export const ErrorEscrowAddressIsNotProvidedByFactory = new Error(
162
+ 'Escrow address is not provided by the factory'
163
+ );
27
164
 
28
165
  /**
29
- * @constant {Error} - The HMToken is missing.
166
+ * @constant {Error} - Manifest file does not exist.
30
167
  */
31
- export const ErrorHMTokenMissing = new Error('HMToken is missing');
168
+ export const ErrorManifestFileDoesNotExist = new Error(
169
+ 'Manifest file does not exist'
170
+ );
32
171
 
33
172
  /**
34
- * @constant {Error} - The Storage access data is missing.
173
+ * @constant {Error} - Storage client does not exist.
35
174
  */
36
- export const ErrorStorageAccessDataMissing = new Error(
37
- 'Storage access data is missing'
175
+ export const ErrorStorageClientDoesNotExist = new Error(
176
+ 'Storage client does not exist'
38
177
  );
178
+
179
+ /**
180
+ * @constant {Error} - Invalid URL string.
181
+ */
182
+ export const ErrorInvalidUrl = new Error('Invalid URL string');
183
+
184
+ /**
185
+ * @constant {Error} - URL is an empty string.
186
+ */
187
+ export const ErrorUrlIsEmptyString = new Error('URL is an empty string');
188
+
189
+ /**
190
+ * @constant {Error} - List of handlers cannot be empty.
191
+ */
192
+ export const ErrorListOfHandlersCannotBeEmpty = new Error(
193
+ 'List of handlers cannot be empty'
194
+ );
195
+
196
+ /**
197
+ * @constant {Error} - No URL provided.
198
+ */
199
+ export const ErrorNoURLprovided = new Error('No URL provided');
200
+
201
+ /**
202
+ * @constant {Error} - Fee must be between 0 and 100.
203
+ */
204
+ export const ErrorFeeMustBeBetweenZeroAndHundred = new Error(
205
+ 'Fee must be between 0 and 100'
206
+ );
207
+
208
+ /**
209
+ * @constant {Error} - Total fee must be less than 100.
210
+ */
211
+ export const ErrorTotalFeeMustBeLessThanHundred = new Error(
212
+ 'Total fee must be less than 100'
213
+ );
214
+
215
+ /**
216
+ * @constant {Error} - Recipient cannot be an empty array.
217
+ */
218
+ export const ErrorRecipientCannotBeEmptyArray = new Error(
219
+ 'Recipient cannot be an empty array'
220
+ );
221
+
222
+ /**
223
+ * @constant {Error} - Amount must be greater than zero..
224
+ */
225
+ export const ErrorAmountMustBeGreaterThanZero = new Error(
226
+ 'Amount must be greater than zero'
227
+ );
228
+
229
+ /**
230
+ * @constant {Error} - Escrow does not have enough balance.
231
+ */
232
+ export const ErrorEscrowDoesNotHaveEnoughBalance = new Error(
233
+ 'Escrow does not have enough balance'
234
+ );
235
+
236
+ /**
237
+ * @constant {Error} - Amounts cannot be an empty array.
238
+ */
239
+ export const ErrorAmountsCannotBeEmptyArray = new Error(
240
+ 'Amounts cannot be an empty array'
241
+ );
242
+
243
+ /**
244
+ * @constant {Error} - Recipient and amounts must be the same length.
245
+ */
246
+ export const ErrorRecipientAndAmountsMustBeSameLength = new Error(
247
+ 'Recipient and amounts must be the same length'
248
+ );
249
+
250
+ /**
251
+ * @constant {Error} - Launched event is not emitted.
252
+ */
253
+ export const ErrorLaunchedEventIsNotEmitted = new Error(
254
+ 'Launched event is not emitted'
255
+ );
256
+
257
+ /**
258
+ * @constant {Error} - Hash is an empty string.
259
+ */
260
+ export const ErrorHashIsEmptyString = new Error('Hash is an empty string');
261
+
262
+ export class EthereumError extends Error {
263
+ constructor(message: string) {
264
+ super(`An error occurred while interacting with Ethereum: ${message}`);
265
+ }
266
+ }
267
+
268
+ export class InvalidArgumentError extends EthereumError {
269
+ constructor(message: string) {
270
+ super(`Invalid argument: ${message}`);
271
+ }
272
+ }
273
+
274
+ export class OutOfGasError extends EthereumError {
275
+ constructor(message: string) {
276
+ super(`Out of gas: ${message}`);
277
+ }
278
+ }
279
+
280
+ export class UnpredictableGasLimit extends EthereumError {
281
+ constructor(message: string) {
282
+ super(`Unpredictable gas limit: ${message}`);
283
+ }
284
+ }
285
+
286
+ export class ReplacementUnderpriced extends EthereumError {
287
+ constructor(message: string) {
288
+ super(`Replacement underpriced: ${message}`);
289
+ }
290
+ }
291
+
292
+ export class NumericFault extends EthereumError {
293
+ constructor(message: string) {
294
+ super(`Numeric fault: ${message}`);
295
+ }
296
+ }
297
+
298
+ export class NonceExpired extends EthereumError {
299
+ constructor(message: string) {
300
+ super(`Nonce expired: ${message}`);
301
+ }
302
+ }
303
+
304
+ export class TransactionReplaced extends EthereumError {
305
+ constructor(message: string) {
306
+ super(`Transaction replaced: ${message}`);
307
+ }
308
+ }
309
+
310
+ export class ContractExecutionError extends EthereumError {
311
+ constructor(reason: string) {
312
+ super(`Contract execution error: ${reason}`);
313
+ }
314
+ }
315
+
316
+ export class InvalidEthereumAddressError extends Error {
317
+ constructor(address: string) {
318
+ super(`Invalid ethereum address error: ${address}`);
319
+ }
320
+ }