@human-protocol/sdk 1.1.5 → 1.1.7

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 (48) hide show
  1. package/README.md +80 -1
  2. package/dist/constants.d.ts +6 -0
  3. package/dist/constants.d.ts.map +1 -1
  4. package/dist/constants.js +24 -5
  5. package/dist/encryption.d.ts +84 -0
  6. package/dist/encryption.d.ts.map +1 -0
  7. package/dist/encryption.js +202 -0
  8. package/dist/error.d.ts +2 -2
  9. package/dist/error.d.ts.map +1 -1
  10. package/dist/error.js +3 -3
  11. package/dist/escrow.d.ts +48 -15
  12. package/dist/escrow.d.ts.map +1 -1
  13. package/dist/escrow.js +118 -37
  14. package/dist/index.d.ts +6 -6
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +10 -14
  17. package/dist/interfaces.d.ts +11 -12
  18. package/dist/interfaces.d.ts.map +1 -1
  19. package/dist/kvstore.d.ts +19 -8
  20. package/dist/kvstore.d.ts.map +1 -1
  21. package/dist/kvstore.js +38 -9
  22. package/dist/queries.d.ts +3 -2
  23. package/dist/queries.d.ts.map +1 -1
  24. package/dist/queries.js +4 -7
  25. package/dist/staking.d.ts +17 -8
  26. package/dist/staking.d.ts.map +1 -1
  27. package/dist/staking.js +44 -14
  28. package/dist/storage.d.ts +2 -1
  29. package/dist/storage.d.ts.map +1 -1
  30. package/dist/storage.js +9 -3
  31. package/dist/types.d.ts +8 -0
  32. package/dist/types.d.ts.map +1 -1
  33. package/package.json +2 -1
  34. package/src/constants.ts +24 -5
  35. package/src/encryption.ts +223 -0
  36. package/src/error.ts +2 -4
  37. package/src/escrow.ts +166 -70
  38. package/src/index.ts +6 -12
  39. package/src/interfaces.ts +11 -13
  40. package/src/kvstore.ts +51 -14
  41. package/src/queries.ts +15 -7
  42. package/src/staking.ts +64 -26
  43. package/src/storage.ts +14 -3
  44. package/src/types.ts +8 -0
  45. package/dist/init.d.ts +0 -13
  46. package/dist/init.d.ts.map +0 -1
  47. package/dist/init.js +0 -35
  48. package/src/init.ts +0 -45
package/dist/escrow.d.ts CHANGED
@@ -1,18 +1,28 @@
1
- import { BigNumber } from 'ethers';
2
- import { IClientParams, IEscrowConfig, IEscrowsFilter, ILauncherEscrowsResult } from './interfaces';
1
+ import { Provider } from '@ethersproject/abstract-provider';
2
+ import { BigNumber, Signer } from 'ethers';
3
+ import { IEscrowConfig, IEscrowsFilter } from './interfaces';
3
4
  import { EscrowStatus, NetworkData } from './types';
4
- export default class EscrowClient {
5
- readonly clientParams: IClientParams;
5
+ export declare class EscrowClient {
6
6
  private escrowFactoryContract;
7
7
  private escrowContract?;
8
8
  private signerOrProvider;
9
9
  network: NetworkData;
10
10
  /**
11
- * **Escrow constructor**
11
+ * **EscrowClient constructor**
12
12
  *
13
- * * @param {IClientParams} clientParams - Init client parameters
13
+ * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
14
+ * @param {NetworkData} network - The network information required to connect to the Escrow contract
14
15
  */
15
- constructor(clientParams: IClientParams);
16
+ constructor(signerOrProvider: Signer | Provider, network: NetworkData);
17
+ /**
18
+ * Creates an instance of EscrowClient from a Signer or Provider.
19
+ *
20
+ * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
21
+ * @returns {Promise<EscrowClient>} - An instance of EscrowClient
22
+ * @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
23
+ * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
24
+ */
25
+ static build(signerOrProvider: Signer | Provider): Promise<EscrowClient>;
16
26
  /**
17
27
  * Creates an escrow contract that uses the token passed to pay oracle fees and reward workers.
18
28
  *
@@ -131,6 +141,14 @@ export default class EscrowClient {
131
141
  * @throws {Error} - An error object if an error occurred.
132
142
  */
133
143
  getResultsUrl(escrowAddress: string): Promise<string>;
144
+ /**
145
+ * Returns the intermediate results file URL.
146
+ *
147
+ * @param {string} escrowAddress - Address of the escrow.
148
+ * @returns {Promise<void>}
149
+ * @throws {Error} - An error object if an error occurred.
150
+ */
151
+ getIntermediateResultsUrl(escrowAddress: string): Promise<string>;
134
152
  /**
135
153
  * Returns the value for a specified key and address
136
154
  *
@@ -148,22 +166,21 @@ export default class EscrowClient {
148
166
  */
149
167
  getStatus(escrowAddress: string): Promise<EscrowStatus>;
150
168
  /**
151
- * Returns the current status of the escrow.
169
+ * Returns the escrow addresses created by a job requester.
152
170
  *
153
171
  * @param {IEscrowsFilter} requesterAddress - Address of the requester.
154
- * @returns {Promise<void>}
172
+ * @returns {Promise<string[]>}
155
173
  * @throws {Error} - An error object if an error occurred.
156
174
  */
157
- getLaunchedEscrows(requesterAddress: string): Promise<ILauncherEscrowsResult[]>;
175
+ getLaunchedEscrows(requesterAddress: string): Promise<string[]>;
158
176
  /**
159
- * Returns the escrows addresses created by a job requester.
177
+ * Returns the escrow addresses based on a specified filter.
160
178
  *
161
- * @param {string} escrowAddress - Address of the escrow.
162
- * @param {IEscrowsFilter} filer - Filter parameters.
163
- * @returns {Promise<void>}
179
+ * @param {IEscrowsFilter} filter - Filter parameters.
180
+ * @returns {Promise<string[]>}
164
181
  * @throws {Error} - An error object if an error occurred.
165
182
  */
166
- getEscrowsFiltered(escrowAddress: string, filter: IEscrowsFilter): Promise<ILauncherEscrowsResult[]>;
183
+ getEscrowsFiltered(filter: IEscrowsFilter): Promise<string[]>;
167
184
  /**
168
185
  * Returns the recording oracle address of given escrow
169
186
  *
@@ -172,6 +189,14 @@ export default class EscrowClient {
172
189
  * @throws {Error} - An error object if an error occurred.
173
190
  */
174
191
  getRecordingOracleAddress(escrowAddress: string): Promise<string>;
192
+ /**
193
+ * Returns the job launcher address of given escrow
194
+ *
195
+ * @param {string} escrowAddress - Address of the escrow.
196
+ * @returns {Promise<string>} - Address of the job launcher.
197
+ * @throws {Error} - An error object if an error occurred.
198
+ */
199
+ getJobLauncherAddress(escrowAddress: string): Promise<string>;
175
200
  /**
176
201
  * Returns the reputation oracle address of given escrow
177
202
  *
@@ -180,5 +205,13 @@ export default class EscrowClient {
180
205
  * @throws {Error} - An error object if an error occurred.
181
206
  */
182
207
  getReputationOracleAddress(escrowAddress: string): Promise<string>;
208
+ /**
209
+ * Returns the escrow factory address of given escrow
210
+ *
211
+ * @param {string} escrowAddress - Address of the escrow.
212
+ * @returns {Promise<string>} - Address of the escrow factory.
213
+ * @throws {Error} - An error object if an error occurred.
214
+ */
215
+ getFactoryAddress(escrowAddress: string): Promise<string>;
183
216
  }
184
217
  //# sourceMappingURL=escrow.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"escrow.d.ts","sourceRoot":"","sources":["../src/escrow.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,SAAS,EAAmC,MAAM,QAAQ,CAAC;AAsBpE,OAAO,EACL,aAAa,EACb,aAAa,EACb,cAAc,EACd,sBAAsB,EACvB,MAAM,cAAc,CAAC;AAOtB,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGpD,MAAM,CAAC,OAAO,OAAO,YAAY;IAWnB,QAAQ,CAAC,YAAY,EAAE,aAAa;IAVhD,OAAO,CAAC,qBAAqB,CAAgB;IAC7C,OAAO,CAAC,cAAc,CAAC,CAAS;IAChC,OAAO,CAAC,gBAAgB,CAAoB;IACrC,OAAO,EAAE,WAAW,CAAC;IAE5B;;;;OAIG;gBACkB,YAAY,EAAE,aAAa;IAUhD;;;;;;;OAOG;IAEU,YAAY,CACvB,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,MAAM,EAAE,GACxB,OAAO,CAAC,MAAM,CAAC;IAiClB;;;;;;;OAOG;IAEG,KAAK,CACT,aAAa,EAAE,MAAM,EACrB,YAAY,EAAE,aAAa,GAC1B,OAAO,CAAC,IAAI,CAAC;IAkEhB;;;;;;;;;OASG;IAEG,oBAAoB,CACxB,YAAY,EAAE,MAAM,EACpB,eAAe,EAAE,MAAM,EAAE,EACzB,YAAY,EAAE,aAAa,GAC1B,OAAO,CAAC,M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AAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoB3D;;;;;;OAMG;IACG,yBAAyB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBvE;;;;;;OAMG;IACG,eAAe,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoB7D;;;;;;OAMG;IACG,SAAS,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAoB7D;;;;;;OAMG;IACG,kBAAkB,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAiBrE;;;;;;OAMG;IACG,kBAAkB,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAsBnE;;;;;;OAMG;IACG,yBAAyB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBvE;;;;;;OAMG;IACG,qBAAqB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBnE;;;;;;OAMG;IACG,0BAA0B,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBxE;;;;;;OAMG;IACG,iBAAiB,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAmBhE"}
package/dist/escrow.js CHANGED
@@ -9,25 +9,51 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- /* eslint-disable @typescript-eslint/no-explicit-any */
12
+ exports.EscrowClient = void 0;
13
13
  const typechain_types_1 = require("@human-protocol/core/typechain-types");
14
14
  const ethers_1 = require("ethers");
15
- const error_1 = require("./error");
16
- const utils_1 = require("./utils");
17
15
  const constants_1 = require("./constants");
18
- const queries_1 = require("./queries");
19
16
  const decorators_1 = require("./decorators");
17
+ const error_1 = require("./error");
18
+ const queries_1 = require("./queries");
19
+ const utils_1 = require("./utils");
20
20
  class EscrowClient {
21
21
  /**
22
- * **Escrow constructor**
22
+ * **EscrowClient constructor**
23
+ *
24
+ * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
25
+ * @param {NetworkData} network - The network information required to connect to the Escrow contract
26
+ */
27
+ constructor(signerOrProvider, network) {
28
+ this.escrowFactoryContract = typechain_types_1.EscrowFactory__factory.connect(network.factoryAddress, signerOrProvider);
29
+ this.network = network;
30
+ this.signerOrProvider = signerOrProvider;
31
+ }
32
+ /**
33
+ * Creates an instance of EscrowClient from a Signer or Provider.
23
34
  *
24
- * * @param {IClientParams} clientParams - Init client parameters
35
+ * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
36
+ * @returns {Promise<EscrowClient>} - An instance of EscrowClient
37
+ * @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
38
+ * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
25
39
  */
26
- constructor(clientParams) {
27
- this.clientParams = clientParams;
28
- this.network = clientParams.network;
29
- this.escrowFactoryContract = typechain_types_1.EscrowFactory__factory.connect(clientParams.network.factoryAddress, clientParams.signerOrProvider);
30
- this.signerOrProvider = clientParams.signerOrProvider;
40
+ static async build(signerOrProvider) {
41
+ let network;
42
+ if (ethers_1.Signer.isSigner(signerOrProvider)) {
43
+ if (!signerOrProvider.provider) {
44
+ throw error_1.ErrorProviderDoesNotExist;
45
+ }
46
+ network = await signerOrProvider.provider.getNetwork();
47
+ }
48
+ else {
49
+ network = await signerOrProvider.getNetwork();
50
+ }
51
+ const chainId = network.chainId;
52
+ const networkData = constants_1.NETWORKS[chainId];
53
+ if (!networkData) {
54
+ throw error_1.ErrorUnsupportedChainID;
55
+ }
56
+ return new EscrowClient(signerOrProvider, networkData);
31
57
  }
32
58
  /**
33
59
  * Creates an escrow contract that uses the token passed to pay oracle fees and reward workers.
@@ -67,7 +93,7 @@ class EscrowClient {
67
93
  * @throws {Error} - An error object if an error occurred.
68
94
  */
69
95
  async setup(escrowAddress, escrowConfig) {
70
- const { recordingOracle, reputationOracle, recordingOracleFee, reputationOracleFee, manifestUrl, hash, } = escrowConfig;
96
+ const { recordingOracle, reputationOracle, recordingOracleFee, reputationOracleFee, manifestUrl, manifestHash, } = escrowConfig;
71
97
  if (!ethers_1.ethers.utils.isAddress(recordingOracle)) {
72
98
  throw error_1.ErrorInvalidRecordingOracleAddressProvided;
73
99
  }
@@ -89,7 +115,7 @@ class EscrowClient {
89
115
  if (!(0, utils_1.isValidUrl)(manifestUrl)) {
90
116
  throw error_1.ErrorInvalidUrl;
91
117
  }
92
- if (!hash) {
118
+ if (!manifestHash) {
93
119
  throw error_1.ErrorHashIsEmptyString;
94
120
  }
95
121
  if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
@@ -97,7 +123,7 @@ class EscrowClient {
97
123
  }
98
124
  try {
99
125
  this.escrowContract = typechain_types_1.Escrow__factory.connect(escrowAddress, this.signerOrProvider);
100
- await this.escrowContract.setup(recordingOracle, reputationOracle, recordingOracleFee, reputationOracleFee, manifestUrl, hash);
126
+ await this.escrowContract.setup(reputationOracle, recordingOracle, reputationOracleFee, recordingOracleFee, manifestUrl, manifestHash);
101
127
  return;
102
128
  }
103
129
  catch (e) {
@@ -413,6 +439,28 @@ class EscrowClient {
413
439
  return (0, utils_1.throwError)(e);
414
440
  }
415
441
  }
442
+ /**
443
+ * Returns the intermediate results file URL.
444
+ *
445
+ * @param {string} escrowAddress - Address of the escrow.
446
+ * @returns {Promise<void>}
447
+ * @throws {Error} - An error object if an error occurred.
448
+ */
449
+ async getIntermediateResultsUrl(escrowAddress) {
450
+ if (!ethers_1.ethers.utils.isAddress(escrowAddress)) {
451
+ throw error_1.ErrorInvalidEscrowAddressProvided;
452
+ }
453
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
454
+ throw error_1.ErrorEscrowAddressIsNotProvidedByFactory;
455
+ }
456
+ try {
457
+ this.escrowContract = typechain_types_1.Escrow__factory.connect(escrowAddress, this.signerOrProvider);
458
+ return this.escrowContract.intermediateResultsUrl();
459
+ }
460
+ catch (e) {
461
+ return (0, utils_1.throwError)(e);
462
+ }
463
+ }
416
464
  /**
417
465
  * Returns the value for a specified key and address
418
466
  *
@@ -458,10 +506,10 @@ class EscrowClient {
458
506
  }
459
507
  }
460
508
  /**
461
- * Returns the current status of the escrow.
509
+ * Returns the escrow addresses created by a job requester.
462
510
  *
463
511
  * @param {IEscrowsFilter} requesterAddress - Address of the requester.
464
- * @returns {Promise<void>}
512
+ * @returns {Promise<string[]>}
465
513
  * @throws {Error} - An error object if an error occurred.
466
514
  */
467
515
  async getLaunchedEscrows(requesterAddress) {
@@ -469,38 +517,27 @@ class EscrowClient {
469
517
  throw error_1.ErrorInvalidAddress;
470
518
  }
471
519
  try {
472
- const { data } = await (0, utils_1.gqlFetch)(this.network.subgraphUrl, (0, queries_1.RAW_LAUNCHED_ESCROWS_QUERY)(), {
473
- address: requesterAddress,
474
- });
475
- return data;
520
+ const { data } = await (0, utils_1.gqlFetch)(this.network.subgraphUrl, (0, queries_1.RAW_LAUNCHED_ESCROWS_QUERY)(requesterAddress));
521
+ return data.data.launchedEscrows.map((escrow) => escrow.id);
476
522
  }
477
523
  catch (e) {
478
524
  return (0, utils_1.throwError)(e);
479
525
  }
480
526
  }
481
527
  /**
482
- * Returns the escrows addresses created by a job requester.
528
+ * Returns the escrow addresses based on a specified filter.
483
529
  *
484
- * @param {string} escrowAddress - Address of the escrow.
485
- * @param {IEscrowsFilter} filer - Filter parameters.
486
- * @returns {Promise<void>}
530
+ * @param {IEscrowsFilter} filter - Filter parameters.
531
+ * @returns {Promise<string[]>}
487
532
  * @throws {Error} - An error object if an error occurred.
488
533
  */
489
- async getEscrowsFiltered(escrowAddress, filter) {
490
- if (!ethers_1.ethers.utils.isAddress(escrowAddress)) {
534
+ async getEscrowsFiltered(filter) {
535
+ if (filter?.address && !ethers_1.ethers.utils.isAddress(filter?.address)) {
491
536
  throw error_1.ErrorInvalidAddress;
492
537
  }
493
- if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
494
- throw error_1.ErrorEscrowAddressIsNotProvidedByFactory;
495
- }
496
538
  try {
497
- const { data } = await (0, utils_1.gqlFetch)(this.network.subgraphUrl, (0, queries_1.RAW_LAUNCHED_ESCROWS_FILTERED_QUERY)(), {
498
- address: filter.address,
499
- status: filter.status,
500
- from: filter.from,
501
- tro: filter.to,
502
- });
503
- return data;
539
+ const { data } = await (0, utils_1.gqlFetch)(this.network.subgraphUrl, (0, queries_1.RAW_LAUNCHED_ESCROWS_FILTERED_QUERY)(filter.address, filter.status, filter.from, filter.to));
540
+ return data.data.launchedEscrows.map((escrow) => escrow.id);
504
541
  }
505
542
  catch (e) {
506
543
  return (0, utils_1.throwError)(e);
@@ -528,6 +565,28 @@ class EscrowClient {
528
565
  return (0, utils_1.throwError)(e);
529
566
  }
530
567
  }
568
+ /**
569
+ * Returns the job launcher address of given escrow
570
+ *
571
+ * @param {string} escrowAddress - Address of the escrow.
572
+ * @returns {Promise<string>} - Address of the job launcher.
573
+ * @throws {Error} - An error object if an error occurred.
574
+ */
575
+ async getJobLauncherAddress(escrowAddress) {
576
+ if (!ethers_1.ethers.utils.isAddress(escrowAddress)) {
577
+ throw error_1.ErrorInvalidEscrowAddressProvided;
578
+ }
579
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
580
+ throw error_1.ErrorEscrowAddressIsNotProvidedByFactory;
581
+ }
582
+ try {
583
+ this.escrowContract = typechain_types_1.Escrow__factory.connect(escrowAddress, this.signerOrProvider);
584
+ return this.escrowContract.launcher();
585
+ }
586
+ catch (e) {
587
+ return (0, utils_1.throwError)(e);
588
+ }
589
+ }
531
590
  /**
532
591
  * Returns the reputation oracle address of given escrow
533
592
  *
@@ -550,6 +609,28 @@ class EscrowClient {
550
609
  return (0, utils_1.throwError)(e);
551
610
  }
552
611
  }
612
+ /**
613
+ * Returns the escrow factory address of given escrow
614
+ *
615
+ * @param {string} escrowAddress - Address of the escrow.
616
+ * @returns {Promise<string>} - Address of the escrow factory.
617
+ * @throws {Error} - An error object if an error occurred.
618
+ */
619
+ async getFactoryAddress(escrowAddress) {
620
+ if (!ethers_1.ethers.utils.isAddress(escrowAddress)) {
621
+ throw error_1.ErrorInvalidEscrowAddressProvided;
622
+ }
623
+ if (!(await this.escrowFactoryContract.hasEscrow(escrowAddress))) {
624
+ throw error_1.ErrorEscrowAddressIsNotProvidedByFactory;
625
+ }
626
+ try {
627
+ this.escrowContract = typechain_types_1.Escrow__factory.connect(escrowAddress, this.signerOrProvider);
628
+ return this.escrowContract.escrowFactory();
629
+ }
630
+ catch (e) {
631
+ return (0, utils_1.throwError)(e);
632
+ }
633
+ }
553
634
  }
554
635
  __decorate([
555
636
  decorators_1.requiresSigner,
@@ -611,4 +692,4 @@ __decorate([
611
692
  __metadata("design:paramtypes", [String, Array]),
612
693
  __metadata("design:returntype", Promise)
613
694
  ], EscrowClient.prototype, "addTrustedHandlers", null);
614
- exports.default = EscrowClient;
695
+ exports.EscrowClient = EscrowClient;
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import InitClient from './init';
2
- import StakingClient from './staking';
3
- import StorageClient from './storage';
4
- import KVStoreClient from './kvstore';
5
- import EscrowClient from './escrow';
1
+ import { StakingClient } from './staking';
2
+ import { StorageClient } from './storage';
3
+ import { KVStoreClient } from './kvstore';
4
+ import { EscrowClient } from './escrow';
6
5
  export * from './constants';
7
6
  export * from './types';
8
7
  export * from './enums';
9
- export { InitClient, StakingClient, StorageClient, KVStoreClient, EscrowClient, };
8
+ export * from './interfaces';
9
+ export { StakingClient, StorageClient, KVStoreClient, EscrowClient };
10
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,QAAQ,CAAC;AAChC,OAAO,aAAa,MAAM,WAAW,CAAC;AACtC,OAAO,aAAa,MAAM,WAAW,CAAC;AACtC,OAAO,aAAa,MAAM,WAAW,CAAC;AACtC,OAAO,YAAY,MAAM,UAAU,CAAC;AAEpC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AAExB,OAAO,EACL,UAAU,EACV,aAAa,EACb,aAAa,EACb,aAAa,EACb,YAAY,GACb,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,CAAC"}
package/dist/index.js CHANGED
@@ -13,21 +13,17 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
13
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
16
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.EscrowClient = exports.KVStoreClient = exports.StorageClient = exports.StakingClient = exports.InitClient = void 0;
21
- const init_1 = __importDefault(require("./init"));
22
- exports.InitClient = init_1.default;
23
- const staking_1 = __importDefault(require("./staking"));
24
- exports.StakingClient = staking_1.default;
25
- const storage_1 = __importDefault(require("./storage"));
26
- exports.StorageClient = storage_1.default;
27
- const kvstore_1 = __importDefault(require("./kvstore"));
28
- exports.KVStoreClient = kvstore_1.default;
29
- const escrow_1 = __importDefault(require("./escrow"));
30
- exports.EscrowClient = escrow_1.default;
17
+ exports.EscrowClient = exports.KVStoreClient = exports.StorageClient = exports.StakingClient = void 0;
18
+ const staking_1 = require("./staking");
19
+ Object.defineProperty(exports, "StakingClient", { enumerable: true, get: function () { return staking_1.StakingClient; } });
20
+ const storage_1 = require("./storage");
21
+ Object.defineProperty(exports, "StorageClient", { enumerable: true, get: function () { return storage_1.StorageClient; } });
22
+ const kvstore_1 = require("./kvstore");
23
+ Object.defineProperty(exports, "KVStoreClient", { enumerable: true, get: function () { return kvstore_1.KVStoreClient; } });
24
+ const escrow_1 = require("./escrow");
25
+ Object.defineProperty(exports, "EscrowClient", { enumerable: true, get: function () { return escrow_1.EscrowClient; } });
31
26
  __exportStar(require("./constants"), exports);
32
27
  __exportStar(require("./types"), exports);
33
28
  __exportStar(require("./enums"), exports);
29
+ __exportStar(require("./interfaces"), exports);
@@ -1,10 +1,5 @@
1
- import { BigNumber, Signer } from 'ethers';
2
- import { Provider } from '@ethersproject/abstract-provider';
3
- import { NetworkData } from './types';
4
- export interface IClientParams {
5
- signerOrProvider: Signer | Provider;
6
- network: NetworkData;
7
- }
1
+ import { BigNumber } from 'ethers';
2
+ import { EscrowStatus } from './types';
8
3
  export interface IAllocation {
9
4
  escrowAddress: string;
10
5
  staker: string;
@@ -17,6 +12,7 @@ export interface IReward {
17
12
  amount: BigNumber;
18
13
  }
19
14
  export interface IStaker {
15
+ staker: string;
20
16
  tokensStaked: BigNumber;
21
17
  tokensAllocated: BigNumber;
22
18
  tokensLocked: BigNumber;
@@ -24,9 +20,9 @@ export interface IStaker {
24
20
  tokensAvailable: BigNumber;
25
21
  }
26
22
  export interface IEscrowsFilter {
27
- address: string;
23
+ address?: string;
28
24
  role?: number;
29
- status?: number;
25
+ status?: EscrowStatus;
30
26
  from?: Date;
31
27
  to?: Date;
32
28
  }
@@ -36,9 +32,12 @@ export interface IEscrowConfig {
36
32
  recordingOracleFee: BigNumber;
37
33
  reputationOracleFee: BigNumber;
38
34
  manifestUrl: string;
39
- hash: string;
35
+ manifestHash: string;
40
36
  }
41
- export interface ILauncherEscrowsResult {
42
- id: string;
37
+ export interface IKeyPair {
38
+ privateKey: string;
39
+ publicKey: string;
40
+ passphrase: string;
41
+ revocationCertificate?: string;
43
42
  }
44
43
  //# sourceMappingURL=interfaces.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAEtC,MAAM,WAAW,aAAa;IAC5B,gBAAgB,EAAE,MAAM,GAAG,QAAQ,CAAC;IACpC,OAAO,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,SAAS,CAAC;IAClB,SAAS,EAAE,SAAS,CAAC;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,MAAM,WAAW,OAAO;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,SAAS,CAAC;CACnB;AAED,MAAM,WAAW,OAAO;IACtB,YAAY,EAAE,SAAS,CAAC;IACxB,eAAe,EAAE,SAAS,CAAC;IAC3B,YAAY,EAAE,SAAS,CAAC;IACxB,iBAAiB,EAAE,SAAS,CAAC;IAC7B,eAAe,EAAE,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAA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CAAC,EAAE,IAAI,CAAC;IACZ,EAAE,CAAC,EAAE,IAAI,CAAC;CACX;AAED,MAAM,WAAW,aAAa;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,SAAS,CAAC;IAC9B,mBAAmB,EAAE,SAAS,CAAC;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,QAAQ;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC"}
package/dist/kvstore.d.ts CHANGED
@@ -1,14 +1,25 @@
1
- import { IClientParams } from './interfaces';
2
- export default class KVStoreClient {
3
- readonly clientParams: IClientParams;
1
+ import { Provider } from '@ethersproject/abstract-provider';
2
+ import { Signer } from 'ethers';
3
+ import { NetworkData } from './types';
4
+ export declare class KVStoreClient {
4
5
  private contract;
5
6
  private signerOrProvider;
6
7
  /**
7
- * **KVStore constructor**
8
+ * **KVStoreClient constructor**
8
9
  *
9
- * * @param {IClientParams} clientParams - Init client parameters
10
+ * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
11
+ * @param {NetworkData} network - The network information required to connect to the KVStore contract
10
12
  */
11
- constructor(clientParams: IClientParams);
13
+ constructor(signerOrProvider: Signer | Provider, network: NetworkData);
14
+ /**
15
+ * Creates an instance of KVStoreClient from a Signer or Provider.
16
+ *
17
+ * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
18
+ * @returns {Promise<KVStoreClient>} - An instance of KVStoreClient
19
+ * @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
20
+ * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
21
+ */
22
+ static build(signerOrProvider: Signer | Provider): Promise<KVStoreClient>;
12
23
  /**
13
24
  * Sets a key-value pair in the contract
14
25
  *
@@ -32,9 +43,9 @@ export default class KVStoreClient {
32
43
  *
33
44
  * @param {string} address - The Ethereum address associated with the key-value pair
34
45
  * @param {string} key - The key of the key-value pair to get
35
- * @returns {string} - The value of the key-value pair if it exists
46
+ * @returns {Promise<string>} - The value of the key-value pair if it exists
36
47
  * @throws {Error} - An error object if an error occurred
37
48
  */
38
- get(address: string, key: string): Promise<string | undefined>;
49
+ get(address: string, key: string): Promise<string>;
39
50
  }
40
51
  //# sourceMappingURL=kvstore.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"kvstore.d.ts","sourceRoot":"","sources":["../src/kvstore.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,MAAM,CAAC,OAAO,OAAO,aAAa;IASpB,QAAQ,CAAC,YAAY,EAAE,aAAa;IARhD,OAAO,CAAC,QAAQ,CAAU;IAC1B,OAAO,CAAC,gBAAgB,CAAoB;IAE5C;;;;OAIG;gBACkB,YAAY,EAAE,aAAa;IAQhD;;;;;;;OAOG;IAEU,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAU3C;;;;;;;OAOG;IAEU,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;IAarD;;;;;;;OAOG;IACU,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;CAW9C"}
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;;;;;;;OAOG;IAEU,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU3D;;;;;;;OAOG;IAEU,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAarE;;;;;;;OAOG;IACU,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAYhE"}
package/dist/kvstore.js CHANGED
@@ -9,20 +9,48 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.KVStoreClient = void 0;
12
13
  const typechain_types_1 = require("@human-protocol/core/typechain-types");
13
14
  const ethers_1 = require("ethers");
14
- const error_1 = require("./error");
15
+ const constants_1 = require("./constants");
15
16
  const decorators_1 = require("./decorators");
17
+ const error_1 = require("./error");
16
18
  class KVStoreClient {
17
19
  /**
18
- * **KVStore constructor**
20
+ * **KVStoreClient constructor**
19
21
  *
20
- * * @param {IClientParams} clientParams - Init client parameters
22
+ * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
23
+ * @param {NetworkData} network - The network information required to connect to the KVStore contract
21
24
  */
22
- constructor(clientParams) {
23
- this.clientParams = clientParams;
24
- this.contract = typechain_types_1.KVStore__factory.connect(clientParams.network.kvstoreAddress, clientParams.signerOrProvider);
25
- this.signerOrProvider = clientParams.signerOrProvider;
25
+ constructor(signerOrProvider, network) {
26
+ this.contract = typechain_types_1.KVStore__factory.connect(network.factoryAddress, signerOrProvider);
27
+ this.signerOrProvider = signerOrProvider;
28
+ }
29
+ /**
30
+ * Creates an instance of KVStoreClient from a Signer or Provider.
31
+ *
32
+ * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
33
+ * @returns {Promise<KVStoreClient>} - An instance of KVStoreClient
34
+ * @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
35
+ * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
36
+ */
37
+ static async build(signerOrProvider) {
38
+ let network;
39
+ if (ethers_1.Signer.isSigner(signerOrProvider)) {
40
+ if (!signerOrProvider.provider) {
41
+ throw error_1.ErrorProviderDoesNotExist;
42
+ }
43
+ network = await signerOrProvider.provider.getNetwork();
44
+ }
45
+ else {
46
+ network = await signerOrProvider.getNetwork();
47
+ }
48
+ const chainId = network.chainId;
49
+ const networkData = constants_1.NETWORKS[chainId];
50
+ if (!networkData) {
51
+ throw error_1.ErrorUnsupportedChainID;
52
+ }
53
+ return new KVStoreClient(signerOrProvider, networkData);
26
54
  }
27
55
  /**
28
56
  * Sets a key-value pair in the contract
@@ -73,7 +101,7 @@ class KVStoreClient {
73
101
  *
74
102
  * @param {string} address - The Ethereum address associated with the key-value pair
75
103
  * @param {string} key - The key of the key-value pair to get
76
- * @returns {string} - The value of the key-value pair if it exists
104
+ * @returns {Promise<string>} - The value of the key-value pair if it exists
77
105
  * @throws {Error} - An error object if an error occurred
78
106
  */
79
107
  async get(address, key) {
@@ -88,6 +116,7 @@ class KVStoreClient {
88
116
  catch (e) {
89
117
  if (e instanceof Error)
90
118
  throw Error(`Failed to get value: ${e.message}`);
119
+ return e;
91
120
  }
92
121
  }
93
122
  }
@@ -103,4 +132,4 @@ __decorate([
103
132
  __metadata("design:paramtypes", [Array, Array]),
104
133
  __metadata("design:returntype", Promise)
105
134
  ], KVStoreClient.prototype, "setBulk", null);
106
- exports.default = KVStoreClient;
135
+ exports.KVStoreClient = KVStoreClient;
package/dist/queries.d.ts CHANGED
@@ -1,4 +1,5 @@
1
+ import { EscrowStatus } from './types';
1
2
  export declare const RAW_REWARDS_QUERY: (slasherAddress: string) => string;
2
- export declare const RAW_LAUNCHED_ESCROWS_QUERY: () => string;
3
- export declare const RAW_LAUNCHED_ESCROWS_FILTERED_QUERY: () => string;
3
+ export declare const RAW_LAUNCHED_ESCROWS_QUERY: (requesterAddress: string) => string;
4
+ export declare const RAW_LAUNCHED_ESCROWS_FILTERED_QUERY: (address?: string, status?: EscrowStatus, from?: Date, to?: Date) => string;
4
5
  //# sourceMappingURL=queries.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,iBAAiB,mBAAoB,MAAM,WAKpD,CAAC;AAEL,eAAO,MAAM,0BAA0B,cAInC,CAAC;AAEL,eAAO,MAAM,mCAAmC,cAI5C,CAAC"}
1
+ {"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../src/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,eAAO,MAAM,iBAAiB,mBAAoB,MAAM,WAKpD,CAAC;AAEL,eAAO,MAAM,0BAA0B,qBAAsB,MAAM,WAI/D,CAAC;AAEL,eAAO,MAAM,mCAAmC,aACpC,MAAM,WACP,YAAY,SACd,IAAI,OACN,IAAI,WAMG,CAAC"}