@human-protocol/sdk 1.0.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/src/types.ts ADDED
@@ -0,0 +1,663 @@
1
+ import {
2
+ Escrow,
3
+ EscrowFactory,
4
+ HMToken,
5
+ } from '@human-protocol/core/typechain-types';
6
+ import { ethers } from 'ethers';
7
+
8
+ /**
9
+ * Enum for escrow statuses.
10
+ * @readonly
11
+ * @enum {number}
12
+ */
13
+ export enum EscrowStatus {
14
+ /**
15
+ * Escrow is launched.
16
+ */
17
+ Launched,
18
+ /**
19
+ * Escrow is funded, and waiting for the results to be submitted.
20
+ */
21
+ Pending,
22
+ /**
23
+ * Escrow is partially paid out.
24
+ */
25
+ Partial,
26
+ /**
27
+ * Escrow is fully paid.
28
+ */
29
+ Paid,
30
+ /**
31
+ * Escrow is finished..
32
+ */
33
+ Complete,
34
+ /**
35
+ * Escrow is cancelled.
36
+ */
37
+ Cancelled,
38
+ }
39
+
40
+ /**
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
457
+ * @readonly
458
+ */
459
+ export type StorageObjectLink = {
460
+ /**
461
+ * Storage object URL
462
+ */
463
+ url: string;
464
+ /**
465
+ * Storage object content hash
466
+ */
467
+ hash: string;
468
+ };
469
+
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;
483
+ /**
484
+ * Reputation oracle wallet
485
+ */
486
+ reputationOracle?: ethers.Wallet;
487
+ /**
488
+ * Other trusted handlers for the job
489
+ */
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;
506
+ /**
507
+ * Region
508
+ */
509
+ region?: string;
510
+ /**
511
+ * Request endpoint
512
+ */
513
+ endpoint?: string;
514
+ /**
515
+ * Storage bucket (private)
516
+ */
517
+ bucket: string;
518
+ /**
519
+ * Storage bucket (public)
520
+ */
521
+ publicBucket: string;
522
+ };
523
+
524
+ /**
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
574
+ * @readonly
575
+ */
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 = {
584
+ /**
585
+ * Uploaded object key
586
+ */
587
+ key: string;
588
+ /**
589
+ * Hash of uploaded object key
590
+ */
591
+ hash: string;
592
+ };
593
+
594
+ /**
595
+ * Job arguments
596
+ * @readonly
597
+ */
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>;
623
+ /**
624
+ * HMToken address
625
+ */
626
+ hmTokenAddr: string;
627
+ /**
628
+ * Factory contract address
629
+ */
630
+ factoryAddr?: string;
631
+ /**
632
+ * Escrow contract address
633
+ */
634
+ escrowAddr?: string;
635
+ /**
636
+ * Job manifest
637
+ */
638
+ manifest?: Manifest;
639
+ /**
640
+ * AWS/GCP Access Key ID
641
+ */
642
+ storageAccessKeyId?: string;
643
+ /**
644
+ * AWS/GCP Secret Access Key
645
+ */
646
+ storageSecretAccessKey?: string;
647
+ /**
648
+ * AWS/GCP bucket endpoint
649
+ */
650
+ storageEndpoint?: string;
651
+ /**
652
+ * AWS/GCP public bucket name
653
+ */
654
+ storagePublicBucket?: string;
655
+ /**
656
+ * AWS/GCP private bucket name
657
+ */
658
+ storageBucket?: string;
659
+ /**
660
+ * Log level
661
+ */
662
+ logLevel?: 'debug' | 'info' | 'warn' | 'error';
663
+ };