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