@human-protocol/sdk 1.0.2 → 1.0.4

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 +295 -18
  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 -131
  57. package/src/types.ts +36 -586
  58. package/src/utils.ts +80 -142
  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 +38 -1
  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 -977
  69. package/src/logger.ts +0 -29
  70. package/test/job.test.ts +0 -716
  71. package/test/utils/manifest.ts +0 -33
package/src/types.ts CHANGED
@@ -1,11 +1,3 @@
1
- import {
2
- Escrow,
3
- EscrowFactory,
4
- HMToken,
5
- Staking,
6
- } from '@human-protocol/core/typechain-types';
7
- import { ethers } from 'ethers';
8
-
9
1
  /**
10
2
  * Enum for escrow statuses.
11
3
  * @readonly
@@ -39,557 +31,44 @@ export enum EscrowStatus {
39
31
  }
40
32
 
41
33
  /**
42
- * Payout item
43
- * @readonly
44
- */
45
- export type Payout = {
46
- /**
47
- * Payout address
48
- */
49
- address: string;
50
- /**
51
- * Payout amount
52
- */
53
- amount: number;
54
- };
55
-
56
- /**
57
- * Job mode
58
- */
59
- export type JobMode = 'batch' | 'online' | 'instance_delivery';
60
-
61
- /**
62
- * Base job types
63
- */
64
- export type BaseJobTypes =
65
- | 'image_label_binary'
66
- | 'image_label_multiple_choice'
67
- | 'text_free_entry'
68
- | 'text_multiple_choice_one_option'
69
- | 'text_multiple_choice_multiple_options'
70
- | 'image_label_area_adjust'
71
- | 'image_label_area_select'
72
- | 'image_label_single_polygon'
73
- | 'image_label_multiple_polygons'
74
- | 'image_label_semantic_segmentation_one_option'
75
- | 'image_label_semantic_segmentation_multiple_options'
76
- | 'image_label_text';
77
-
78
- /**
79
- * Shape type of request config
80
- */
81
- export type ShapeType = 'point' | 'bounding_box' | 'polygon';
82
-
83
- /**
84
- * Request config item
85
- */
86
- export type RequestConfig = {
87
- /**
88
- * Version
89
- */
90
- version?: number;
91
- /**
92
- * Shape type
93
- */
94
- shape_type?: ShapeType;
95
- /**
96
- * Minimum points
97
- */
98
- min_points?: number;
99
- /**
100
- * Maximum points
101
- */
102
- max_points?: number;
103
- /**
104
- * Minimum shapes per image
105
- */
106
- min_shapes_per_image?: number;
107
- /**
108
- * Maximum shapes per image
109
- */
110
- max_shapes_per_image?: number;
111
- /**
112
- * Restrict to coordinates
113
- */
114
- restrict_to_coords?: boolean;
115
- /**
116
- * Minimum selection area per shape
117
- */
118
- minimum_selection_area_per_shape?: number;
119
- /**
120
- * Maximum choices for multiple choice
121
- */
122
- multiple_choice_max_choices?: number;
123
- /**
124
- * Minimum choices for multiple choice
125
- */
126
- multiple_choice_min_choices?: number;
127
- };
128
-
129
- /**
130
- * Webhook item
131
- */
132
- export type Webhook = {
133
- /**
134
- * Webhook id
135
- */
136
- webhook_id: string;
137
- /**
138
- * Completed chunks
139
- */
140
- chunk_completed?: string[];
141
- /**
142
- * Completed jobs
143
- */
144
- job_completed?: string[];
145
- };
146
-
147
- /**
148
- * Task data item
149
- */
150
- export type TaskData = {
151
- /**
152
- * Task key
153
- */
154
- task_key: string;
155
- /**
156
- * Datapoint URI
157
- */
158
- datapoint_uri: string;
159
- /**
160
- * Datapoint hash
161
- */
162
- datapoint_hash: string;
163
- };
164
-
165
- /**
166
- * Internal config item
167
- */
168
- export type InternalConfig = {
169
- /**
170
- * Exchange Oracle
171
- */
172
- exchange?: Record<string, string | number>;
173
- /**
174
- * Recording Oracle
175
- */
176
- reco?: Record<string, string | number>;
177
- /**
178
- * Reputation Oracle
179
- */
180
- repo?: Record<string, string | number>;
181
- /**
182
- * Other trusted handlers
183
- */
184
- other?: Record<string, string | number>;
185
- /**
186
- * MITL???
187
- */
188
- mitl?: string | number | Record<string, string | number>;
189
- };
190
-
191
- /**
192
- * Score item
193
- */
194
- export type Score = {
195
- /**
196
- * Score
197
- */
198
- score: number;
199
- };
200
-
201
- /**
202
- * Restricted audience item
203
- */
204
- export type RestrictedAudience = {
205
- /**
206
- * Lang score
207
- */
208
- lang?: Score[];
209
- /**
210
- * Country score
211
- */
212
- country?: Score[];
213
- /**
214
- * Browser score
215
- */
216
- browser?: Score[];
217
- /**
218
- * Sitekey Score
219
- */
220
- sitekey?: Score[];
221
- /**
222
- * Server domain score
223
- */
224
- serverdomain?: Score[];
225
- /**
226
- * Confidence score
227
- */
228
- confidence?: Score[];
229
-
230
- /**
231
- * Minimum difficulty
232
- */
233
- min_difficulty?: number;
234
- /**
235
- * Minimum user score
236
- */
237
- min_user_score?: number;
238
- /**
239
- * Maximum user score
240
- */
241
- max_user_score?: number;
242
-
243
- /**
244
- * Launch group ID
245
- */
246
- launch_group_id?: number;
247
- };
248
-
249
- /**
250
- * Nested manifest item
251
- */
252
- export type NestedManifest = Pick<
253
- Manifest,
254
- | 'job_id'
255
- | 'requester_restricted_answer_set'
256
- | 'requester_description'
257
- | 'requester_max_repeats'
258
- | 'requester_min_repeats'
259
- | 'requester_question'
260
- | 'requester_question_example'
261
- | 'unsafe_content'
262
- | 'requester_accuracy_target'
263
- | 'request_type'
264
- | 'request_config'
265
- | 'groundtruth_uri'
266
- | 'groundtruth'
267
- | 'confcalc_configuration_id'
268
- | 'webhook'
269
- >;
270
-
271
- /**
272
- * Manifest item
273
- * @readonly
274
- * @todo Confirm data type
275
- */
276
- export type Manifest = {
277
- /**
278
- * Job Mode
279
- */
280
- job_mode: JobMode;
281
- /**
282
- * Job API Key
283
- */
284
- job_api_key?: string;
285
- /**
286
- * Job ID
287
- */
288
- job_id?: string;
289
- /**
290
- * Total tasks in the job
291
- */
292
- job_total_tasks: number;
293
- /**
294
- * Requester's restricted answer set
295
- */
296
- requester_restricted_answer_set?: Record<string, Record<string, string>>;
297
- /**
298
- * Requester's description
299
- */
300
- requester_description?: string;
301
- /**
302
- * Maximum repeat count of the requester
303
- */
304
- requester_max_repeats?: number;
305
- /**
306
- * Minimum repeat count of the requester
307
- */
308
- requester_min_repeats?: number;
309
- /**
310
- * Requester's question
311
- */
312
- requester_question?: Record<string, string>;
313
- /**
314
- * Requester's question example
315
- */
316
- requester_question_example?: string | string[];
317
- /**
318
- * Flag for unsafe content
319
- */
320
- unsafe_content?: boolean;
321
- /**
322
- * Bid price for the task
323
- */
324
- task_bid_price: number;
325
- /**
326
- * Staking amount for oracles
327
- */
328
- oracle_stake: number;
329
- /**
330
- * Job expiration date
331
- */
332
- expiration_date?: number;
333
- /**
334
- * Requester's accuracy target
335
- */
336
- requester_accuracy_target?: number;
337
- /**
338
- * Smart bounty address
339
- */
340
- manifest_smart_bounty_addr?: string;
341
- /**
342
- * HMT token address
343
- */
344
- hmtoken_addr?: string;
345
- /**
346
- * Minimum trust of the server
347
- */
348
- minimum_trust_server?: number;
349
- /**
350
- * Minimum trust of the client
351
- */
352
- minimum_trust_client?: number;
353
- /**
354
- * Recording oracle address
355
- */
356
- recording_oracle_addr: string;
357
- /**
358
- * Reputation oracle address
359
- */
360
- reputation_oracle_addr: string;
361
- /**
362
- * Reputation agent address
363
- */
364
- reputation_agent_addr: string;
365
- /**
366
- * Requester's PGP public key
367
- */
368
- requester_pgp_public_key?: string;
369
- /**
370
- * RO URI
371
- */
372
- ro_uri?: string;
373
- /**
374
- * Repo URI
375
- */
376
- repo_uri?: string;
377
-
378
- /**
379
- * Batch result delivery webhook
380
- */
381
- batch_result_delivery_webhook?: string;
382
- /**
383
- * Online result delivery webhook
384
- */
385
- online_result_delivery_webhook?: string;
386
- /**
387
- * Instant result delivery webhook
388
- */
389
- instant_result_delivery_webhook?: string;
390
-
391
- /**
392
- * Multi challenge manifests
393
- */
394
- multi_challenge_manifests?: NestedManifest[];
395
-
396
- /**
397
- * Request type
398
- */
399
- request_type: BaseJobTypes | 'multi_challenge';
400
-
401
- /**
402
- * Request config
403
- */
404
- request_config?: RequestConfig;
405
-
406
- /**
407
- * Task data
408
- */
409
- taskdata?: TaskData[];
410
-
411
- /**
412
- * Task data URI for external task
413
- */
414
- taskdata_uri?: string;
415
-
416
- /**
417
- * Groundtruth URI
418
- * Groundtruth data is stored as a URL or optionally as an inline json-serialized string
419
- */
420
- groundtruth_uri?: string;
421
- /**
422
- * Groundtruth
423
- */
424
- groundtruth?: string;
425
-
426
- /**
427
- * Rejected URI
428
- */
429
- rejected_uri?: string;
430
- /**
431
- * Rejected count
432
- */
433
- rejected_count?: number;
434
-
435
- /**
436
- * Internal config
437
- */
438
- internal_config?: InternalConfig;
439
-
440
- /**
441
- * Confcalc configuratoin ID
442
- */
443
- confcalc_configuration_id?: string;
444
-
445
- /**
446
- * Restricted audience
447
- */
448
- restricted_audience?: RestrictedAudience;
449
-
450
- /**
451
- * Webhook
452
- */
453
- webhook?: Webhook;
454
- };
455
-
456
- /**
457
- * Cloud storage object link
458
- * @readonly
459
- */
460
- export type StorageObjectLink = {
461
- /**
462
- * Storage object URL
463
- */
464
- url: string;
465
- /**
466
- * Storage object content hash
467
- */
468
- hash: string;
469
- };
470
-
471
- /**
472
- * Ethers provider data
34
+ * AWS/GCP cloud storage access data
473
35
  * @readonly
474
36
  */
475
- export type ProviderData = {
37
+ export type StorageCredentials = {
476
38
  /**
477
- * Ethers provider
39
+ * Access Key
478
40
  */
479
- provider: ethers.providers.BaseProvider;
41
+ accessKey: string;
480
42
  /**
481
- * Gas payer wallet
43
+ * Secret Key
482
44
  */
483
- gasPayer?: ethers.Wallet;
484
- /**
485
- * Reputation oracle wallet
486
- */
487
- reputationOracle?: ethers.Wallet;
488
- /**
489
- * Other trusted handlers for the job
490
- */
491
- trustedHandlers?: Array<ethers.Wallet>;
45
+ secretKey: string;
492
46
  };
493
47
 
494
- /**
495
- * AWS/GCP cloud storage access data
496
- * @readonly
497
- */
498
- export type StorageAccessData = {
48
+ export type StorageParams = {
499
49
  /**
500
- * Access Key ID
50
+ * Request endPoint
501
51
  */
502
- accessKeyId: string;
52
+ endPoint: string;
503
53
  /**
504
- * Secret Access Key
54
+ * Enable secure (HTTPS) access. Default value set to false
505
55
  */
506
- secretAccessKey: string;
56
+ useSSL: boolean;
507
57
  /**
508
58
  * Region
509
59
  */
510
60
  region?: string;
511
61
  /**
512
- * Request endpoint
513
- */
514
- endpoint?: string;
515
- /**
516
- * Storage bucket (private)
517
- */
518
- bucket: string;
519
- /**
520
- * Storage bucket (public)
521
- */
522
- publicBucket: string;
523
- };
524
-
525
- /**
526
- * Manifest data
527
- */
528
- export type ManifestData = {
529
- /**
530
- * Manifest
62
+ * TCP/IP port number. Default value set to 80 for HTTP and 443 for HTTPs
531
63
  */
532
- manifest?: Manifest;
533
- /**
534
- * Manifest link
535
- */
536
- manifestlink?: StorageObjectLink;
537
- /**
538
- * Intermediate result link
539
- */
540
- intermediateResultLink?: StorageObjectLink;
64
+ port?: number;
541
65
  };
542
66
 
543
67
  /**
544
- * Contract data
545
- */
546
- export type ContractData = {
547
- /**
548
- * Factory contract address
549
- */
550
- factoryAddr?: string;
551
- /**
552
- * Factory contract instance
553
- */
554
- factory?: EscrowFactory;
555
- /**
556
- * Escrow contract address
557
- */
558
- escrowAddr?: string;
559
- /**
560
- * Escrow contract instance
561
- */
562
- escrow?: Escrow;
563
- /**
564
- * HMToken contract address
565
- */
566
- hmTokenAddr: string;
567
- /**
568
- * HMToken contract instance
569
- */
570
- hmToken?: HMToken;
571
- /**
572
- * Staking contract address
573
- */
574
- stakingAddr?: string;
575
- /**
576
- * Staking contract instance
577
- */
578
- staking?: Staking;
579
- };
580
-
581
- /**
582
- * Generic result data
68
+ * Upload file data
583
69
  * @readonly
584
70
  */
585
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
586
- export type Result = Record<string, any>;
587
-
588
- /**
589
- * Upload result data
590
- * @readonly
591
- */
592
- export type UploadResult = {
71
+ export type UploadFile = {
593
72
  /**
594
73
  * Uploaded object key
595
74
  */
@@ -601,76 +80,47 @@ export type UploadResult = {
601
80
  };
602
81
 
603
82
  /**
604
- * Job arguments
605
- * @readonly
83
+ * Network data
606
84
  */
607
- export type JobArguments = {
608
- /**
609
- * Network
610
- */
611
- network?: string;
612
- /**
613
- * Infura project id
614
- */
615
- infuraKey?: string;
616
- /**
617
- * Alchemy API token
618
- */
619
- alchemyKey?: string;
85
+ export type NetworkData = {
620
86
  /**
621
- * Gas payer wallet / private key
87
+ * Network chain id
622
88
  */
623
- gasPayer: ethers.Wallet | string;
89
+ chainId: number;
624
90
  /**
625
- * Reputation oracle wallet / private key
91
+ * Network title
626
92
  */
627
- reputationOracle: ethers.Wallet | string;
93
+ title: string;
628
94
  /**
629
- * Trusted handlers wallet / private key
95
+ * Network scanner URL
630
96
  */
631
- trustedHandlers?: Array<ethers.Wallet | string>;
97
+ scanUrl: string;
632
98
  /**
633
- * HMToken address
99
+ * HMT Token contract address
634
100
  */
635
- hmTokenAddr: string;
101
+ hmtAddress: string;
636
102
  /**
637
- * Factory contract address
103
+ * Escrow Factory contract address
638
104
  */
639
- stakingAddr?: string;
105
+ factoryAddress: string;
640
106
  /**
641
107
  * Staking contract address
642
108
  */
643
- factoryAddr?: string;
644
- /**
645
- * Escrow contract address
646
- */
647
- escrowAddr?: string;
648
- /**
649
- * Job manifest
650
- */
651
- manifest?: Manifest;
652
- /**
653
- * AWS/GCP Access Key ID
654
- */
655
- storageAccessKeyId?: string;
656
- /**
657
- * AWS/GCP Secret Access Key
658
- */
659
- storageSecretAccessKey?: string;
109
+ stakingAddress: string;
660
110
  /**
661
- * AWS/GCP bucket endpoint
111
+ * KVStore contract address
662
112
  */
663
- storageEndpoint?: string;
113
+ kvstoreAddress: string;
664
114
  /**
665
- * AWS/GCP public bucket name
115
+ * Subgraph URL
666
116
  */
667
- storagePublicBucket?: string;
117
+ subgraphUrl: string;
668
118
  /**
669
- * AWS/GCP private bucket name
119
+ * Old subgraph URL
670
120
  */
671
- storageBucket?: string;
121
+ oldSubgraphUrl: string;
672
122
  /**
673
- * Log level
123
+ * Old Escrow Factory contract address
674
124
  */
675
- logLevel?: 'debug' | 'info' | 'warn' | 'error';
125
+ oldFactoryAddress: string;
676
126
  };