@human-protocol/sdk 1.1.18 → 2.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.
Files changed (61) hide show
  1. package/dist/base.d.ts +4 -13
  2. package/dist/base.d.ts.map +1 -1
  3. package/dist/base.js +3 -18
  4. package/dist/constants.d.ts +7 -0
  5. package/dist/constants.d.ts.map +1 -1
  6. package/dist/constants.js +18 -11
  7. package/dist/decorators.d.ts.map +1 -1
  8. package/dist/decorators.js +4 -2
  9. package/dist/encryption.d.ts +31 -0
  10. package/dist/encryption.d.ts.map +1 -1
  11. package/dist/encryption.js +37 -0
  12. package/dist/error.d.ts +0 -10
  13. package/dist/error.d.ts.map +1 -1
  14. package/dist/error.js +2 -18
  15. package/dist/escrow.d.ts +39 -33
  16. package/dist/escrow.d.ts.map +1 -1
  17. package/dist/escrow.js +121 -137
  18. package/dist/graphql/queries/{staking.d.ts → operator.d.ts} +2 -1
  19. package/dist/graphql/queries/operator.d.ts.map +1 -0
  20. package/dist/graphql/queries/{staking.js → operator.js} +24 -1
  21. package/dist/graphql/types.d.ts +5 -6
  22. package/dist/graphql/types.d.ts.map +1 -1
  23. package/dist/index.d.ts +2 -1
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +3 -1
  26. package/dist/interfaces.d.ts +28 -18
  27. package/dist/interfaces.d.ts.map +1 -1
  28. package/dist/kvstore.d.ts +14 -14
  29. package/dist/kvstore.d.ts.map +1 -1
  30. package/dist/kvstore.js +30 -48
  31. package/dist/operator.d.ts +68 -0
  32. package/dist/operator.d.ts.map +1 -0
  33. package/dist/operator.js +153 -0
  34. package/dist/staking.d.ts +35 -95
  35. package/dist/staking.d.ts.map +1 -1
  36. package/dist/staking.js +73 -201
  37. package/dist/statistics.d.ts.map +1 -1
  38. package/dist/statistics.js +7 -6
  39. package/dist/types.d.ts +1 -2
  40. package/dist/types.d.ts.map +1 -1
  41. package/dist/utils.d.ts +0 -15
  42. package/dist/utils.d.ts.map +1 -1
  43. package/dist/utils.js +9 -49
  44. package/package.json +4 -4
  45. package/src/base.ts +5 -30
  46. package/src/constants.ts +18 -10
  47. package/src/decorators.ts +3 -2
  48. package/src/encryption.ts +40 -0
  49. package/src/error.ts +0 -17
  50. package/src/escrow.ts +169 -178
  51. package/src/graphql/queries/{staking.ts → operator.ts} +24 -0
  52. package/src/graphql/types.ts +5 -7
  53. package/src/index.ts +2 -0
  54. package/src/interfaces.ts +30 -18
  55. package/src/kvstore.ts +47 -59
  56. package/src/operator.ts +192 -0
  57. package/src/staking.ts +101 -213
  58. package/src/statistics.ts +8 -9
  59. package/src/types.ts +1 -3
  60. package/src/utils.ts +8 -58
  61. package/dist/graphql/queries/staking.d.ts.map +0 -1
package/dist/utils.js CHANGED
@@ -1,21 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.gasPriceAdjusted = exports.isValidUrl = exports.throwError = exports.getRevertReason = void 0;
3
+ exports.isValidUrl = exports.throwError = void 0;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
4
5
  const ethers_1 = require("ethers");
5
6
  const error_1 = require("./error");
6
- /**
7
- * **Get specific error text.*
8
- *
9
- * @param {any} error - An error message.
10
- * @returns
11
- */
12
- const getRevertReason = (error) => {
13
- const prefix = "reverted with reason string '";
14
- const suffix = "'";
15
- const message = error.data.substring(error.data.indexOf(prefix) + prefix.length);
16
- return message.substring(0, message.indexOf(suffix));
17
- };
18
- exports.getRevertReason = getRevertReason;
19
7
  /**
20
8
  * **Handle and throw the error.*
21
9
  *
@@ -23,29 +11,22 @@ exports.getRevertReason = getRevertReason;
23
11
  * @returns
24
12
  */
25
13
  const throwError = (e) => {
26
- if (e.code === ethers_1.ethers.utils.Logger.errors.INVALID_ARGUMENT) {
14
+ if (ethers_1.ethers.isError(e, 'INVALID_ARGUMENT')) {
27
15
  throw new error_1.InvalidArgumentError(e.message);
28
16
  }
29
- else if (e.code === 'OUT_OF_GAS') {
30
- throw new error_1.OutOfGasError(e.message);
31
- }
32
- else if (e.code === ethers_1.ethers.utils.Logger.errors.CALL_EXCEPTION) {
33
- const reason = (0, exports.getRevertReason)(e.data);
34
- throw new error_1.ContractExecutionError(reason);
17
+ else if (ethers_1.ethers.isError(e, 'CALL_EXCEPTION')) {
18
+ throw new error_1.ContractExecutionError(e.reason);
35
19
  }
36
- else if (e.code === ethers_1.ethers.utils.Logger.errors.UNPREDICTABLE_GAS_LIMIT) {
37
- throw new error_1.UnpredictableGasLimit(e.message);
38
- }
39
- else if (e.code === ethers_1.ethers.utils.Logger.errors.TRANSACTION_REPLACED) {
20
+ else if (ethers_1.ethers.isError(e, 'TRANSACTION_REPLACED')) {
40
21
  throw new error_1.TransactionReplaced(e.message);
41
22
  }
42
- else if (e.code === ethers_1.ethers.utils.Logger.errors.REPLACEMENT_UNDERPRICED) {
23
+ else if (ethers_1.ethers.isError(e, 'REPLACEMENT_UNDERPRICED')) {
43
24
  throw new error_1.ReplacementUnderpriced(e.message);
44
25
  }
45
- else if (e.code === ethers_1.ethers.utils.Logger.errors.NUMERIC_FAULT) {
26
+ else if (ethers_1.ethers.isError(e, 'NUMERIC_FAULT')) {
46
27
  throw new error_1.NumericFault(e.message);
47
28
  }
48
- else if (e.code === ethers_1.ethers.utils.Logger.errors.NONCE_EXPIRED) {
29
+ else if (ethers_1.ethers.isError(e, 'NONCE_EXPIRED')) {
49
30
  throw new error_1.NonceExpired(e.message);
50
31
  }
51
32
  else {
@@ -69,24 +50,3 @@ const isValidUrl = (url) => {
69
50
  }
70
51
  };
71
52
  exports.isValidUrl = isValidUrl;
72
- /**
73
- * Increase/Decrease gas price
74
- *
75
- * @returns {Promise<BigNumber>} Returns the adjusted gas price
76
- */
77
- const gasPriceAdjusted = async (signerOrProvider, gasPriceMultiplier) => {
78
- let gasPrice;
79
- if (ethers_1.Signer.isSigner(signerOrProvider)) {
80
- gasPrice = (await signerOrProvider.provider?.getFeeData())?.gasPrice;
81
- }
82
- else {
83
- gasPrice = (await signerOrProvider.getFeeData()).gasPrice;
84
- }
85
- if (!gasPrice) {
86
- throw error_1.ErrorMissingGasPrice;
87
- }
88
- return gasPrice
89
- .mul(ethers_1.ethers.utils.parseEther(gasPriceMultiplier.toString()))
90
- .div(ethers_1.ethers.utils.parseEther('1'));
91
- };
92
- exports.gasPriceAdjusted = gasPriceAdjusted;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@human-protocol/sdk",
3
3
  "description": "Human Protocol SDK",
4
- "version": "1.1.18",
4
+ "version": "2.0.0",
5
5
  "files": [
6
6
  "src",
7
7
  "dist"
@@ -40,11 +40,10 @@
40
40
  },
41
41
  "dependencies": {
42
42
  "@human-protocol/core": "*",
43
- "aws-sdk": "^2.1255.0",
43
+ "aws-sdk": "^2.1528.0",
44
44
  "axios": "^1.4.0",
45
45
  "crypto": "^1.0.1",
46
- "ethers": "^5.7.2",
47
- "graphql": "^16.7.1",
46
+ "graphql": "^16.8.1",
48
47
  "graphql-request": "^6.1.0",
49
48
  "graphql-tag": "^2.12.6",
50
49
  "minio": "^7.0.32",
@@ -63,6 +62,7 @@
63
62
  "./src/encryption.ts",
64
63
  "./src/escrow.ts",
65
64
  "./src/kvstore.ts",
65
+ "./src/operator.ts",
66
66
  "./src/staking.ts",
67
67
  "./src/storage.ts",
68
68
  "./src/statistics.ts"
package/src/base.ts CHANGED
@@ -1,7 +1,5 @@
1
- import { Provider } from '@ethersproject/abstract-provider';
2
- import { Signer, ethers } from 'ethers';
1
+ import { ContractRunner } from 'ethers';
3
2
  import { NetworkData } from './types';
4
- import { gasPriceAdjusted } from './utils';
5
3
 
6
4
  /**
7
5
  * ## Introduction
@@ -10,40 +8,17 @@ import { gasPriceAdjusted } from './utils';
10
8
  *
11
9
  */
12
10
  export abstract class BaseEthersClient {
13
- protected signerOrProvider: Signer | Provider;
14
- protected gasPriceMultiplier?: number;
11
+ protected runner: ContractRunner;
15
12
  public networkData: NetworkData;
16
13
 
17
14
  /**
18
15
  * **BaseClient constructor**
19
16
  *
20
- * @param {Signer | Provider} signerOrProvider The Signer or Provider object to interact with the Ethereum network
17
+ * @param {ContractRunner} runner The Signer or Provider object to interact with the Ethereum network
21
18
  * @param {NetworkData} networkData The network information required to connect to the contracts
22
- * @param {number | undefined} gasPriceMultiplier The multiplier to apply to the gas price
23
19
  */
24
- constructor(
25
- signerOrProvider: Signer | Provider,
26
- networkData: NetworkData,
27
- gasPriceMultiplier?: number
28
- ) {
20
+ constructor(runner: ContractRunner, networkData: NetworkData) {
29
21
  this.networkData = networkData;
30
- this.signerOrProvider = signerOrProvider;
31
- this.gasPriceMultiplier = gasPriceMultiplier;
32
- }
33
-
34
- /**
35
- * Adjust the gas price, and return as an option to be passed to a transaction
36
- *
37
- * @returns {Promise<{ gasPrice: BigNumber }>} Returns the gas price options
38
- */
39
- protected async gasPriceOptions(): Promise<Partial<ethers.Overrides>> {
40
- return this.gasPriceMultiplier
41
- ? {
42
- gasPrice: await gasPriceAdjusted(
43
- this.signerOrProvider,
44
- this.gasPriceMultiplier
45
- ),
46
- }
47
- : {};
22
+ this.runner = runner;
48
23
  }
49
24
  }
package/src/constants.ts CHANGED
@@ -59,7 +59,7 @@ export const NETWORKS: {
59
59
  hmtAddress: '0xd1ba9BAC957322D6e8c07a160a3A8dA11A0d2867',
60
60
  stakingAddress: '0x05398211bA2046E296fBc9a9D3EB49e3F15C3123',
61
61
  rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a',
62
- kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
62
+ kvstoreAddress: '0xB6d36B1CDaD50302BCB3DB43bAb0D349458e1b8D',
63
63
  subgraphUrl:
64
64
  'https://api.thegraph.com/subgraphs/name/humanprotocol/mainnet-v2',
65
65
  oldSubgraphUrl: '',
@@ -86,7 +86,7 @@ export const NETWORKS: {
86
86
  hmtAddress: '0xd3A31D57FDD790725d0F6B78095F62E8CD4ab317',
87
87
  stakingAddress: '0xf46B45Df3d956369726d8Bd93Ba33963Ab692920',
88
88
  rewardPoolAddress: '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4',
89
- kvstoreAddress: '0xc9Fe39c4b6e1d7A2991355Af159956982DADf842',
89
+ kvstoreAddress: '0x19Fc3e859C1813ac9427a7a78BeB9ae102CE96d3',
90
90
  subgraphUrl:
91
91
  'https://api.thegraph.com/subgraphs/name/humanprotocol/goerli-v2',
92
92
  oldSubgraphUrl:
@@ -101,7 +101,7 @@ export const NETWORKS: {
101
101
  hmtAddress: '0x711Fd6ab6d65A98904522d4e3586F492B989c527',
102
102
  stakingAddress: '0xdFbB79dC35a3A53741be54a2C9b587d6BafAbd1C',
103
103
  rewardPoolAddress: '0xf376443BCc6d4d4D63eeC086bc4A9E4a83878e0e',
104
- kvstoreAddress: '0x2B95bEcb6EBC4589f64CB000dFCF716b4aeF8aA6',
104
+ kvstoreAddress: '0x21A0C4CED7aE447fCf87D9FE3A29FA9B3AB20Ff1',
105
105
  subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc-v2',
106
106
  oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc',
107
107
  oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4',
@@ -114,7 +114,7 @@ export const NETWORKS: {
114
114
  hmtAddress: '0xE3D74BBFa45B4bCa69FF28891fBE392f4B4d4e4d',
115
115
  stakingAddress: '0x5517fE916Fe9F8dB15B0DDc76ebDf0BdDCd4ed18',
116
116
  rewardPoolAddress: '0xB0A0500103eCEc431b73F6BAd923F0a2774E6e29',
117
- kvstoreAddress: '0x3aD4B091E054f192a822D1406f4535eAd38580e4',
117
+ kvstoreAddress: '0x32e27177BA6Ea91cf28dfd91a0Da9822A4b74EcF',
118
118
  subgraphUrl:
119
119
  'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest-v2',
120
120
  oldSubgraphUrl:
@@ -129,7 +129,7 @@ export const NETWORKS: {
129
129
  hmtAddress: '0xc748B2A084F8eFc47E086ccdDD9b7e67aEb571BF',
130
130
  stakingAddress: '0xcbAd56bE3f504E98bd70875823d3CC0242B7bB29',
131
131
  rewardPoolAddress: '0xa8e32d777a3839440cc7c24D591A64B9481753B3',
132
- kvstoreAddress: '0x35Cf4beBD58F9C8D75B9eA2599479b6C173d406F',
132
+ kvstoreAddress: '0xbcB28672F826a50B03EE91B28145EAbddA73B2eD',
133
133
  subgraphUrl:
134
134
  'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon-v2',
135
135
  oldSubgraphUrl:
@@ -144,7 +144,7 @@ export const NETWORKS: {
144
144
  hmtAddress: '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4',
145
145
  stakingAddress: '0x7Fd3dF914E7b6Bd96B4c744Df32183b51368Bfac',
146
146
  rewardPoolAddress: '0xf0145eD99AC3c4f877aDa7dA4D1E059ec9116BAE',
147
- kvstoreAddress: '0xD7F61E812e139a5a02eDae9Dfec146E1b8eA3807',
147
+ kvstoreAddress: '0xD96158c7267Ea658a4688F4aEf1c85659851625d',
148
148
  subgraphUrl:
149
149
  'https://api.thegraph.com/subgraphs/name/humanprotocol/mumbai-v2',
150
150
  oldSubgraphUrl:
@@ -159,7 +159,7 @@ export const NETWORKS: {
159
159
  hmtAddress: '0x3b25BC1dC591D24d60560d0135D6750A561D4764',
160
160
  stakingAddress: '0x05398211bA2046E296fBc9a9D3EB49e3F15C3123',
161
161
  rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a',
162
- kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
162
+ kvstoreAddress: '0x2B95bEcb6EBC4589f64CB000dFCF716b4aeF8aA6',
163
163
  subgraphUrl:
164
164
  'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbeam-v2',
165
165
  oldSubgraphUrl:
@@ -174,7 +174,7 @@ export const NETWORKS: {
174
174
  hmtAddress: '0x2dd72db2bBA65cE663e476bA8b84A1aAF802A8e3',
175
175
  stakingAddress: '0xBFC7009F3371F93F3B54DdC8caCd02914a37495c',
176
176
  rewardPoolAddress: '0xf46B45Df3d956369726d8Bd93Ba33963Ab692920',
177
- kvstoreAddress: '0xE3D74BBFa45B4bCa69FF28891fBE392f4B4d4e4d',
177
+ kvstoreAddress: '0xcC561f4482f4Ff051D2Dcc65c2cE1A0f291bbA46',
178
178
  subgraphUrl:
179
179
  'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbase-alpha-v2',
180
180
  oldSubgraphUrl: '',
@@ -188,7 +188,7 @@ export const NETWORKS: {
188
188
  hmtAddress: '0x9406d5c635AD22b0d76c75E52De57A2177919ca3',
189
189
  stakingAddress: '0x9890473B0b93E24d6D1a8Dfb739D577C6f25FFd3',
190
190
  rewardPoolAddress: '0x5517fE916Fe9F8dB15B0DDc76ebDf0BdDCd4ed18',
191
- kvstoreAddress: '0x707fb5A5d36BC15275Af3f73262bf9a1D8C470EB',
191
+ kvstoreAddress: '0x3aD4B091E054f192a822D1406f4535eAd38580e4',
192
192
  subgraphUrl:
193
193
  'https://api.thegraph.com/subgraphs/name/humanprotocol/fuji-v2',
194
194
  oldSubgraphUrl:
@@ -203,7 +203,7 @@ export const NETWORKS: {
203
203
  hmtAddress: '0x12365293cb6477d4fc2686e46BB97E3Fb64f1550',
204
204
  stakingAddress: '0x05398211bA2046E296fBc9a9D3EB49e3F15C3123',
205
205
  rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a',
206
- kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
206
+ kvstoreAddress: '0x9Bc7bff35B2Be2413708d48c3B0aEF5c43646728',
207
207
  subgraphUrl:
208
208
  'https://api.thegraph.com/subgraphs/name/humanprotocol/avalanche-v2',
209
209
  oldSubgraphUrl:
@@ -273,3 +273,11 @@ export const KVStoreKeys = {
273
273
  webhookUrl: 'webhookUrl',
274
274
  url: 'url',
275
275
  };
276
+
277
+ export const Role = {
278
+ Validator: 'Validator',
279
+ JobLauncher: 'Job Launcher',
280
+ ExchangeOracle: 'Exchange Oracle',
281
+ ReputationOracle: 'Reputation Oracle',
282
+ RecordingOracle: 'Recording Oracle',
283
+ };
package/src/decorators.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { Signer } from 'ethers';
3
2
  import { ErrorSigner } from './error';
4
3
 
5
4
  export function requiresSigner(
@@ -10,7 +9,9 @@ export function requiresSigner(
10
9
  const originalMethod = descriptor.value;
11
10
 
12
11
  descriptor.value = async function (this: any, ...args: any[]) {
13
- if (!Signer.isSigner(this.signerOrProvider)) {
12
+ try {
13
+ !this.runner.getAddress();
14
+ } catch {
14
15
  throw ErrorSigner;
15
16
  }
16
17
 
package/src/encryption.ts CHANGED
@@ -437,4 +437,44 @@ export class EncryptionUtils {
437
437
 
438
438
  return encrypted as string;
439
439
  }
440
+
441
+ /**
442
+ * Verifies if a message appears to be encrypted with OpenPGP.
443
+ *
444
+ * @param {string} message Message to verify.
445
+ * @returns {Promise<boolean>} `true` if the message appears to be encrypted, `false` if not.
446
+ *
447
+ * **Code example:**
448
+ *
449
+ * ```ts
450
+ * const message = `-----BEGIN PGP MESSAGE-----
451
+ *
452
+ * wV4DqdeRpqH+jaISAQdAsvBFxikvjxRqC7ZlDe98cLd7/aeCEI/AcL8PpVKK
453
+ * mC0wKlwxNg/ADi55z9jcYFuMC4kKE+C/teM+JqiI8DO9AwassQUvKFtULnpx
454
+ * h2jaOjC/0sAQASjUsIFK8zbuDgk/P8T9Npn6px+GlJPg9K90iwtPWiIp0eyW
455
+ * 4zXamJZT51k2DyaUX/Rsc6P4PYhQRKjt0yxtH0jHPmKkLC/9eBeFf4GP0zlZ
456
+ * 18xMZ8uCpQCma708Gz0sJYxEz3u/eZdHD7Mc7tWQKyJG8MsTwM1P+fdK1X75
457
+ * L9UryJG2AY+6kKZhG4dqjNxiO4fWluiB2u7iMF+iLEyE3SQCEYorWMC+NDWi
458
+ * QIJZ7oQ2w7BaPo1a991gvTOSNm5v2x44KfqPI1uj859BjsQTCA==
459
+ * =tsmI
460
+ * -----END PGP MESSAGE-----`;
461
+ *
462
+ * const isEncrypted = await EncriptionUtils.isEncrypted(message);
463
+ *
464
+ * if (isEncrypted) {
465
+ * console.log('The message is encrypted with OpenPGP.');
466
+ * } else {
467
+ * console.log('The message is not encrypted with OpenPGP.');
468
+ * }
469
+ * ```
470
+ */
471
+ public static isEncrypted(message: string): boolean {
472
+ const startMarker = '-----BEGIN PGP MESSAGE-----';
473
+ const endMarker = '-----END PGP MESSAGE-----';
474
+
475
+ const hasStartMarker = message.includes(startMarker);
476
+ const hasEndMarker = message.includes(endMarker);
477
+
478
+ return hasStartMarker && hasEndMarker;
479
+ }
440
480
  }
package/src/error.ts CHANGED
@@ -283,18 +283,6 @@ export class InvalidArgumentError extends EthereumError {
283
283
  }
284
284
  }
285
285
 
286
- export class OutOfGasError extends EthereumError {
287
- constructor(message: string) {
288
- super(`Out of gas: ${message}`);
289
- }
290
- }
291
-
292
- export class UnpredictableGasLimit extends EthereumError {
293
- constructor(message: string) {
294
- super(`Unpredictable gas limit: ${message}`);
295
- }
296
- }
297
-
298
286
  export class ReplacementUnderpriced extends EthereumError {
299
287
  constructor(message: string) {
300
288
  super(`Replacement underpriced: ${message}`);
@@ -334,8 +322,3 @@ export class InvalidEthereumAddressError extends Error {
334
322
  * @constant {Error} - The Hash does not match
335
323
  */
336
324
  export const ErrorInvalidHash = new Error('Invalid hash');
337
-
338
- /**
339
- * @constant {Error} - The Hash does not match
340
- */
341
- export const ErrorMissingGasPrice = new Error('Missing gas price');