@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/queries.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RAW_LAUNCHED_ESCROWS_FILTERED_QUERY = exports.RAW_LAUNCHED_ESCROWS_QUERY = exports.RAW_REWARDS_QUERY = void 0;
4
+ const types_1 = require("./types");
4
5
  const RAW_REWARDS_QUERY = (slasherAddress) => `{
5
6
  rewardAddedEvents(id: "${slasherAddress}") {
6
7
  escrow,
@@ -8,15 +9,11 @@ const RAW_REWARDS_QUERY = (slasherAddress) => `{
8
9
  }
9
10
  }`;
10
11
  exports.RAW_REWARDS_QUERY = RAW_REWARDS_QUERY;
11
- const RAW_LAUNCHED_ESCROWS_QUERY = () => `{
12
- launchedEscrows(where: { from: $address }) {
12
+ const RAW_LAUNCHED_ESCROWS_QUERY = (requesterAddress) => `{
13
+ launchedEscrows(where: { from: ${requesterAddress} }) {
13
14
  id
14
15
  }
15
16
  }`;
16
17
  exports.RAW_LAUNCHED_ESCROWS_QUERY = RAW_LAUNCHED_ESCROWS_QUERY;
17
- const RAW_LAUNCHED_ESCROWS_FILTERED_QUERY = () => `{
18
- launchedEscrows(where: { from: $address, status: $status, timestamp_gte: $from, timestamp_lte: $to }) {
19
- id
20
- }
21
- }`;
18
+ const RAW_LAUNCHED_ESCROWS_FILTERED_QUERY = (address, status, from, to) => `{ launchedEscrows(where: { ${address ? 'from: "' + address + '", ' : ''}${status ? 'status: "' + types_1.EscrowStatus[status] + '", ' : ''}${from ? 'timestamp_gte: "' + from?.valueOf() + '", ' : ''}${to ? 'timestamp_lte: "' + to?.valueOf() + '"' : ''}}) { id }}`;
22
19
  exports.RAW_LAUNCHED_ESCROWS_FILTERED_QUERY = RAW_LAUNCHED_ESCROWS_FILTERED_QUERY;
package/dist/staking.d.ts CHANGED
@@ -1,21 +1,30 @@
1
1
  import { Provider } from '@ethersproject/abstract-provider';
2
- import { HMToken, Staking, EscrowFactory } from '@human-protocol/core/typechain-types';
2
+ import { EscrowFactory, HMToken, Staking } from '@human-protocol/core/typechain-types';
3
3
  import { BigNumber, Signer } from 'ethers';
4
+ import { IAllocation, IReward, IStaker } from './interfaces';
4
5
  import { NetworkData } from './types';
5
- import { IAllocation, IClientParams, IReward, IStaker } from './interfaces';
6
- export default class StakingClient {
7
- readonly clientParams: IClientParams;
6
+ export declare class StakingClient {
8
7
  signerOrProvider: Signer | Provider;
9
8
  network: NetworkData;
10
9
  tokenContract: HMToken;
11
10
  stakingContract: Staking;
12
11
  escrowFactoryContract: EscrowFactory;
13
12
  /**
14
- * **Staking constructor**
13
+ * **StakingClient constructor**
15
14
  *
16
- * @param {IClientParams} clientParams - Init client parameters
15
+ * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
16
+ * @param {NetworkData} network - The network information required to connect to the Staking contract
17
17
  */
18
- constructor(clientParams: IClientParams);
18
+ constructor(signerOrProvider: Signer | Provider, network: NetworkData);
19
+ /**
20
+ * Creates an instance of StakingClient from a Signer or Provider.
21
+ *
22
+ * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
23
+ * @returns {Promise<StakingClient>} - An instance of StakingClient
24
+ * @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
25
+ * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
26
+ */
27
+ static build(signerOrProvider: Signer | Provider): Promise<StakingClient>;
19
28
  /**
20
29
  * **Approves the staking contract to transfer a specified amount of tokens when the user stakes.
21
30
  * **It increases the allowance for the staking contract.*
@@ -97,7 +106,7 @@ export default class StakingClient {
97
106
  /**
98
107
  * **Returns the staking information about all stakers of the protocol.*
99
108
  *
100
- * @returns {Promise<IStakerInfo>} - Return an array with all stakers information
109
+ * @returns {Promise<IStaker[]>} - Return an array with all stakers information
101
110
  * @throws {Error} - An error object if an error occurred, results otherwise
102
111
  */
103
112
  getAllStakers(): Promise<I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(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.StakingClient = void 0;
12
13
  const typechain_types_1 = require("@human-protocol/core/typechain-types");
13
14
  const ethers_1 = require("ethers");
15
+ const constants_1 = require("./constants");
16
+ const decorators_1 = require("./decorators");
14
17
  const error_1 = require("./error");
15
- const utils_1 = require("./utils");
16
18
  const queries_1 = require("./queries");
17
- const decorators_1 = require("./decorators");
19
+ const utils_1 = require("./utils");
18
20
  class StakingClient {
19
21
  /**
20
- * **Staking constructor**
22
+ * **StakingClient 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 Staking contract
26
+ */
27
+ constructor(signerOrProvider, network) {
28
+ this.stakingContract = typechain_types_1.Staking__factory.connect(network.stakingAddress, signerOrProvider);
29
+ this.escrowFactoryContract = typechain_types_1.EscrowFactory__factory.connect(network.factoryAddress, signerOrProvider);
30
+ this.tokenContract = typechain_types_1.HMToken__factory.connect(network.hmtAddress, signerOrProvider);
31
+ this.signerOrProvider = signerOrProvider;
32
+ this.network = network;
33
+ }
34
+ /**
35
+ * Creates an instance of StakingClient from a Signer or Provider.
21
36
  *
22
- * @param {IClientParams} clientParams - Init client parameters
37
+ * @param {Signer | Provider} signerOrProvider - The Signer or Provider object to interact with the Ethereum network
38
+ * @returns {Promise<StakingClient>} - An instance of StakingClient
39
+ * @throws {ErrorProviderDoesNotExist} - Thrown if the provider does not exist for the provided Signer
40
+ * @throws {ErrorUnsupportedChainID} - Thrown if the network's chainId is not supported
23
41
  */
24
- constructor(clientParams) {
25
- this.clientParams = clientParams;
26
- this.signerOrProvider = clientParams.signerOrProvider;
27
- this.network = clientParams.network;
28
- this.stakingContract = typechain_types_1.Staking__factory.connect(this.network.stakingAddress, this.signerOrProvider);
29
- this.escrowFactoryContract = typechain_types_1.EscrowFactory__factory.connect(this.network.factoryAddress, this.signerOrProvider);
30
- this.tokenContract = typechain_types_1.HMToken__factory.connect(this.network.hmtAddress, this.signerOrProvider);
42
+ static async build(signerOrProvider) {
43
+ let network;
44
+ if (ethers_1.Signer.isSigner(signerOrProvider)) {
45
+ if (!signerOrProvider.provider) {
46
+ throw error_1.ErrorProviderDoesNotExist;
47
+ }
48
+ network = await signerOrProvider.provider.getNetwork();
49
+ }
50
+ else {
51
+ network = await signerOrProvider.getNetwork();
52
+ }
53
+ const chainId = network.chainId;
54
+ const networkData = constants_1.NETWORKS[chainId];
55
+ if (!networkData) {
56
+ throw error_1.ErrorUnsupportedChainID;
57
+ }
58
+ return new StakingClient(signerOrProvider, networkData);
31
59
  }
32
60
  /**
33
61
  * **Approves the staking contract to transfer a specified amount of tokens when the user stakes.
@@ -242,6 +270,7 @@ class StakingClient {
242
270
  .sub(tokensAllocated)
243
271
  .sub(tokensLocked);
244
272
  return {
273
+ staker,
245
274
  tokensStaked,
246
275
  tokensAllocated,
247
276
  tokensLocked,
@@ -256,7 +285,7 @@ class StakingClient {
256
285
  /**
257
286
  * **Returns the staking information about all stakers of the protocol.*
258
287
  *
259
- * @returns {Promise<IStakerInfo>} - Return an array with all stakers information
288
+ * @returns {Promise<IStaker[]>} - Return an array with all stakers information
260
289
  * @throws {Error} - An error object if an error occurred, results otherwise
261
290
  */
262
291
  async getAllStakers() {
@@ -265,12 +294,13 @@ class StakingClient {
265
294
  if (result[1].length === 0) {
266
295
  throw error_1.ErrorStakingGetStakers;
267
296
  }
268
- return result[1].map((staker) => {
297
+ return result[1].map((staker, index) => {
269
298
  const tokensStaked = ethers_1.BigNumber.from(staker.tokensStaked), tokensAllocated = ethers_1.BigNumber.from(staker.tokensAllocated), tokensLocked = ethers_1.BigNumber.from(staker.tokensLocked), tokensLockedUntil = ethers_1.BigNumber.from(staker.tokensLockedUntil);
270
299
  const tokensAvailable = tokensStaked
271
300
  .sub(tokensAllocated)
272
301
  .sub(tokensLocked);
273
302
  return {
303
+ staker: result[0][index],
274
304
  tokensStaked,
275
305
  tokensAllocated,
276
306
  tokensLocked,
@@ -378,4 +408,4 @@ __decorate([
378
408
  __metadata("design:paramtypes", [String]),
379
409
  __metadata("design:returntype", Promise)
380
410
  ], StakingClient.prototype, "distributeRewards", null);
381
- exports.default = StakingClient;
411
+ exports.StakingClient = StakingClient;
package/dist/storage.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { UploadFile, StorageCredentials, StorageParams } from './types';
2
- export default class StorageClient {
2
+ export declare class StorageClient {
3
3
  private client;
4
+ private clientParams;
4
5
  /**
5
6
  * **Storage client constructor**
6
7
  *
@@ -1 +1 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxE,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,OAAO,CAAC,MAAM,CAAe;IAE7B;;;;;OAKG;gBACS,WAAW,EAAE,kBAAkB,EAAE,MAAM,EAAE,aAAa;IAYlE;;;;;OAKG;IACU,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAoB1E;;;;;OAKG;WACiB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAsBlE;;;;;;OAMG;IACU,WAAW,CACtB,KAAK,EAAE,GAAG,EAAE,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,EAAE,CAAC;IA0BxB;;;;;OAKG;IACU,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3D;;;;;OAKG;IACU,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAqB5D"}
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIxE,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,YAAY,CAAgB;IAEpC;;;;;OAKG;gBACS,WAAW,EAAE,kBAAkB,EAAE,MAAM,EAAE,aAAa;IAclE;;;;;OAKG;IACU,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAoB1E;;;;;OAKG;WACiB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAsBlE;;;;;;OAMG;IACU,WAAW,CACtB,KAAK,EAAE,GAAG,EAAE,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,EAAE,CAAC;IAkCxB;;;;;OAKG;IACU,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI3D;;;;;OAKG;IACU,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAqB5D"}
package/dist/storage.js CHANGED
@@ -26,6 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.StorageClient = void 0;
29
30
  /* eslint-disable @typescript-eslint/no-explicit-any */
30
31
  const axios_1 = __importDefault(require("axios"));
31
32
  const crypto_1 = __importDefault(require("crypto"));
@@ -42,6 +43,7 @@ class StorageClient {
42
43
  */
43
44
  constructor(credentials, params) {
44
45
  try {
46
+ this.clientParams = params;
45
47
  this.client = new Minio.Client({
46
48
  ...params,
47
49
  accessKey: credentials.accessKey,
@@ -114,12 +116,16 @@ class StorageClient {
114
116
  return Promise.all(files.map(async (file) => {
115
117
  const content = JSON.stringify(file);
116
118
  const hash = crypto_1.default.createHash('sha1').update(content).digest('hex');
117
- const key = hash;
119
+ const key = `s3${hash}.json`;
118
120
  try {
119
121
  await this.client.putObject(bucket, key, content, {
120
122
  'Content-Type': 'application/json',
121
123
  });
122
- return { key, hash };
124
+ return {
125
+ key,
126
+ url: `${this.clientParams.useSSL ? 'https' : 'http'}://${this.clientParams.endPoint}${this.clientParams.port ? `:${this.clientParams.port}` : ''}/${bucket}/${key}`,
127
+ hash,
128
+ };
123
129
  }
124
130
  catch (e) {
125
131
  throw error_1.ErrorStorageFileNotUploaded;
@@ -162,4 +168,4 @@ class StorageClient {
162
168
  }
163
169
  }
164
170
  }
165
- exports.default = StorageClient;
171
+ exports.StorageClient = StorageClient;
package/dist/types.d.ts CHANGED
@@ -70,6 +70,10 @@ export type UploadFile = {
70
70
  * Uploaded object key
71
71
  */
72
72
  key: string;
73
+ /**
74
+ * Uploaded object URL
75
+ */
76
+ url: string;
73
77
  /**
74
78
  * Hash of uploaded object key
75
79
  */
@@ -103,6 +107,10 @@ export type NetworkData = {
103
107
  * Staking contract address
104
108
  */
105
109
  stakingAddress: string;
110
+ /**
111
+ * RewardPool contract address
112
+ */
113
+ rewardPoolAddress: string;
106
114
  /**
107
115
  * KVStore contract address
108
116
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,oBAAY,YAAY;IACtB;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,OAAO,IAAA;IACP;;OAEG;IACH,IAAI,IAAA;IACJ;;OAEG;IACH,QAAQ,IAAA;IACR;;OAEG;IACH,SAAS,IAAA;CACV;AAED;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,SAAS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AAM,CAAC;IAClB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,MAAM,EAAE,OAAO,CAAC;IAChB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,cAAc,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC"}
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.5",
4
+ "version": "1.1.7",
5
5
  "files": [
6
6
  "src",
7
7
  "dist"
@@ -10,6 +10,7 @@
10
10
  "types": "dist/index.d.ts",
11
11
  "scripts": {
12
12
  "clean": "rm -rf ./dist",
13
+ "prebuild": "yarn workspace @human-protocol/core build",
13
14
  "build": "npm run clean && tsc",
14
15
  "prepublish": "npm run build",
15
16
  "test": "vitest -u",
package/src/constants.ts CHANGED
@@ -58,6 +58,7 @@ export const NETWORKS: {
58
58
  factoryAddress: '0xD9c75a1Aa4237BB72a41E5E26bd8384f10c1f55a',
59
59
  hmtAddress: '0xd1ba9BAC957322D6e8c07a160a3A8dA11A0d2867',
60
60
  stakingAddress: '0x05398211bA2046E296fBc9a9D3EB49e3F15C3123',
61
+ rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a',
61
62
  kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
62
63
  subgraphUrl:
63
64
  'https://api.thegraph.com/subgraphs/name/humanprotocol/mainnet-v1',
@@ -71,6 +72,7 @@ export const NETWORKS: {
71
72
  factoryAddress: '0x925B24444511c86F4d4E63141D8Be0A025E2dca4',
72
73
  hmtAddress: '0x4dCf5ac4509888714dd43A5cCc46d7ab389D9c23',
73
74
  stakingAddress: '',
75
+ rewardPoolAddress: '',
74
76
  kvstoreAddress: '',
75
77
  subgraphUrl: '',
76
78
  oldSubgraphUrl: '',
@@ -83,6 +85,7 @@ export const NETWORKS: {
83
85
  factoryAddress: '0x87469B4f2Fcf37cBd34E54244c0BD4Fa0603664c',
84
86
  hmtAddress: '0xd3A31D57FDD790725d0F6B78095F62E8CD4ab317',
85
87
  stakingAddress: '0xf46B45Df3d956369726d8Bd93Ba33963Ab692920',
88
+ rewardPoolAddress: '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4',
86
89
  kvstoreAddress: '0xc9Fe39c4b6e1d7A2991355Af159956982DADf842',
87
90
  subgraphUrl:
88
91
  'https://api.thegraph.com/subgraphs/name/humanprotocol/goerli-v1',
@@ -94,11 +97,11 @@ export const NETWORKS: {
94
97
  chainId: ChainId.BSC_MAINNET,
95
98
  title: 'Binance Smart Chain',
96
99
  scanUrl: 'https://bscscan.com',
97
- factoryAddress: '0xD9c75a1Aa4237BB72a41E5E26bd8384f10c1f55a',
98
- hmtAddress: '0x0d501B743F22b641B8C8dfe00F1AAb881D57DDC7',
99
- stakingAddress: '0xC2163A0928034e020f0d31e1171Ba0D6d9AfFB6c',
100
- kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
101
-
100
+ factoryAddress: '0x92FD968AcBd521c232f5fB8c33b342923cC72714',
101
+ hmtAddress: '0x711Fd6ab6d65A98904522d4e3586F492B989c527',
102
+ stakingAddress: '0xdFbB79dC35a3A53741be54a2C9b587d6BafAbd1C',
103
+ rewardPoolAddress: '0xf376443BCc6d4d4D63eeC086bc4A9E4a83878e0e',
104
+ kvstoreAddress: '0x2B95bEcb6EBC4589f64CB000dFCF716b4aeF8aA6',
102
105
  subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc-v1',
103
106
  oldSubgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/bsc',
104
107
  oldFactoryAddress: '0xc88bC422cAAb2ac8812de03176402dbcA09533f4',
@@ -110,6 +113,7 @@ export const NETWORKS: {
110
113
  factoryAddress: '0x2bfA592DBDaF434DDcbb893B1916120d181DAD18',
111
114
  hmtAddress: '0xE3D74BBFa45B4bCa69FF28891fBE392f4B4d4e4d',
112
115
  stakingAddress: '0x5517fE916Fe9F8dB15B0DDc76ebDf0BdDCd4ed18',
116
+ rewardPoolAddress: '0xB0A0500103eCEc431b73F6BAd923F0a2774E6e29',
113
117
  kvstoreAddress: '0x3aD4B091E054f192a822D1406f4535eAd38580e4',
114
118
  subgraphUrl:
115
119
  'https://api.thegraph.com/subgraphs/name/humanprotocol/bsctest-v1',
@@ -124,6 +128,7 @@ export const NETWORKS: {
124
128
  factoryAddress: '0xBDBfD2cC708199C5640C6ECdf3B0F4A4C67AdfcB',
125
129
  hmtAddress: '0xc748B2A084F8eFc47E086ccdDD9b7e67aEb571BF',
126
130
  stakingAddress: '0xcbAd56bE3f504E98bd70875823d3CC0242B7bB29',
131
+ rewardPoolAddress: '0xa8e32d777a3839440cc7c24D591A64B9481753B3',
127
132
  kvstoreAddress: '0x35Cf4beBD58F9C8D75B9eA2599479b6C173d406F',
128
133
  subgraphUrl:
129
134
  'https://api.thegraph.com/subgraphs/name/humanprotocol/polygon-v1',
@@ -138,6 +143,7 @@ export const NETWORKS: {
138
143
  factoryAddress: '0xA8D927C4DA17A6b71675d2D49dFda4E9eBE58f2d',
139
144
  hmtAddress: '0x0376D26246Eb35FF4F9924cF13E6C05fd0bD7Fb4',
140
145
  stakingAddress: '0x7Fd3dF914E7b6Bd96B4c744Df32183b51368Bfac',
146
+ rewardPoolAddress: '0xf0145eD99AC3c4f877aDa7dA4D1E059ec9116BAE',
141
147
  kvstoreAddress: '0xD7F61E812e139a5a02eDae9Dfec146E1b8eA3807',
142
148
  subgraphUrl:
143
149
  'https://api.thegraph.com/subgraphs/name/humanprotocol/mumbai-v1',
@@ -152,6 +158,7 @@ export const NETWORKS: {
152
158
  factoryAddress: '0xD9c75a1Aa4237BB72a41E5E26bd8384f10c1f55a',
153
159
  hmtAddress: '0x3b25BC1dC591D24d60560d0135D6750A561D4764',
154
160
  stakingAddress: '0x05398211bA2046E296fBc9a9D3EB49e3F15C3123',
161
+ rewardPoolAddress: '0x4A5963Dd6792692e9147EdC7659936b96251917a',
155
162
  kvstoreAddress: '0x70671167176C4934204B1C7e97F5e86695857ef2',
156
163
  subgraphUrl:
157
164
  'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbeam-v1',
@@ -166,6 +173,7 @@ export const NETWORKS: {
166
173
  factoryAddress: '0x5e622FF522D81aa426f082bDD95210BC25fCA7Ed',
167
174
  hmtAddress: '0x2dd72db2bBA65cE663e476bA8b84A1aAF802A8e3',
168
175
  stakingAddress: '0xBFC7009F3371F93F3B54DdC8caCd02914a37495c',
176
+ rewardPoolAddress: '0xf46B45Df3d956369726d8Bd93Ba33963Ab692920',
169
177
  kvstoreAddress: '0xE3D74BBFa45B4bCa69FF28891fBE392f4B4d4e4d',
170
178
  subgraphUrl:
171
179
  'https://api.thegraph.com/subgraphs/name/humanprotocol/moonbase-alpha-v1',
@@ -179,6 +187,7 @@ export const NETWORKS: {
179
187
  factoryAddress: '0xfb4469201951C3B9a7F1996c477cb7BDBEcE0A88',
180
188
  hmtAddress: '0x9406d5c635AD22b0d76c75E52De57A2177919ca3',
181
189
  stakingAddress: '',
190
+ rewardPoolAddress: '',
182
191
  kvstoreAddress: '0xd232c1426CF0653cE8a71DC98bCfDf10c471c114',
183
192
 
184
193
  subgraphUrl: 'https://api.thegraph.com/subgraphs/name/humanprotocol/fuji',
@@ -192,6 +201,7 @@ export const NETWORKS: {
192
201
  factoryAddress: '0x9767a578ba7a5FA1563c8229943cB01cd8446BB4',
193
202
  hmtAddress: '0x12365293cb6477d4fc2686e46BB97E3Fb64f1550',
194
203
  stakingAddress: '',
204
+ rewardPoolAddress: '',
195
205
  kvstoreAddress: '0x4B79eaD28F52eD5686bf0e379717e85fc7aD10Df',
196
206
  subgraphUrl:
197
207
  'https://api.thegraph.com/subgraphs/name/humanprotocol/avalanche',
@@ -205,6 +215,7 @@ export const NETWORKS: {
205
215
  factoryAddress: '0x319070b49C8d1cC015915D1E7Eb5fd8e22833885',
206
216
  hmtAddress: '0x6E5FF61Ea88270F6142E0E0eC8cbe9d67476CbCd',
207
217
  stakingAddress: '0x79F37FB9C210910733c16228AC4D14a8e32C11BD',
218
+ rewardPoolAddress: '0x881218246c25C6898aE96145259584340153aDA2',
208
219
  kvstoreAddress: '0xE1055607327b1be2080D31211dCDC4D9338CaF4A',
209
220
  subgraphUrl:
210
221
  'https://graph-skale.humanprotocol.org/subgraphs/name/skale-human',
@@ -218,9 +229,17 @@ export const NETWORKS: {
218
229
  factoryAddress: '0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9',
219
230
  hmtAddress: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
220
231
  stakingAddress: '0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0',
232
+ rewardPoolAddress: '0xa513E6E4b8f2a923D98304ec87F64353C4D5C853',
221
233
  kvstoreAddress: '0x5FC8d32690cc91D4c39d9d3abcBD16989F875707',
222
234
  subgraphUrl: '',
223
235
  oldSubgraphUrl: '',
224
236
  oldFactoryAddress: '',
225
237
  },
226
238
  };
239
+
240
+ export const KVStoreKeys = {
241
+ role: 'role',
242
+ webhook_url: 'webhook_url',
243
+ fee: 'fee',
244
+ public_key: 'public_key',
245
+ };
@@ -0,0 +1,223 @@
1
+ import * as openpgp from 'openpgp';
2
+ import { IKeyPair } from './interfaces';
3
+ /**
4
+ * Class for encryption and decryption operations.
5
+ */
6
+ export class Encryption {
7
+ private privateKey: openpgp.PrivateKey;
8
+
9
+ /**
10
+ * Constructor for the Encryption class.
11
+ *
12
+ * @param {PrivateKey} privateKey - The private key.
13
+ */
14
+ constructor(privateKey: openpgp.PrivateKey) {
15
+ this.privateKey = privateKey;
16
+ }
17
+
18
+ /**
19
+ * Builds an Encryption instance by decrypting the private key from an encrypted private key and passphrase.
20
+ *
21
+ * @param {string} privateKeyArmored - The encrypted private key in armored format.
22
+ * @param {string} passphrase - Optional: The passphrase for the private key.
23
+ * @returns {Promise<Encryption>} - The Encryption instance.
24
+ */
25
+ public static async build(
26
+ privateKeyArmored: string,
27
+ passphrase?: string
28
+ ): Promise<Encryption> {
29
+ const options = {
30
+ armoredKey: privateKeyArmored,
31
+ };
32
+
33
+ if (!passphrase) {
34
+ return new Encryption(await openpgp.readPrivateKey(options));
35
+ }
36
+
37
+ const privateKey = await openpgp.readPrivateKey(options);
38
+ return new Encryption(
39
+ await openpgp.decryptKey({
40
+ privateKey,
41
+ passphrase,
42
+ })
43
+ );
44
+ }
45
+
46
+ /**
47
+ * Signs and encrypts a message using the specified public keys.
48
+ *
49
+ * @param {string} message - The message to encrypt.
50
+ * @param {string[]} publicKeys - The public keys in armored format.
51
+ * @returns {Promise<string>} - The encrypted message.
52
+ */
53
+ public async signAndEncrypt(
54
+ message: string,
55
+ publicKeys: string[]
56
+ ): Promise<string> {
57
+ const plaintext = message;
58
+
59
+ const pgpPublicKeys = await Promise.all(
60
+ publicKeys.map((armoredKey) => openpgp.readKey({ armoredKey }))
61
+ );
62
+
63
+ const pgpMessage = await openpgp.createMessage({ text: plaintext });
64
+ const encrypted = await openpgp.encrypt({
65
+ message: pgpMessage,
66
+ encryptionKeys: pgpPublicKeys,
67
+ signingKeys: this.privateKey,
68
+ });
69
+
70
+ return encrypted as string;
71
+ }
72
+
73
+ /**
74
+ * Decrypts an encrypted message using the private key.
75
+ *
76
+ * @param {string} message - The encrypted message.
77
+ * @param {string} publicKey - Optional: The public key in armored format for signature verification.
78
+ * @returns {Promise<string>} - The decrypted message.
79
+ */
80
+ public async decrypt(message: string, publicKey?: string): Promise<string> {
81
+ const pgpMessage = await openpgp.readMessage({ armoredMessage: message });
82
+
83
+ const decryptionOptions: openpgp.DecryptOptions = {
84
+ message: pgpMessage,
85
+ decryptionKeys: this.privateKey,
86
+ expectSigned: !!publicKey,
87
+ };
88
+
89
+ if (publicKey) {
90
+ const pgpPublicKey = await openpgp.readKey({ armoredKey: publicKey });
91
+ decryptionOptions.verificationKeys = pgpPublicKey;
92
+ }
93
+
94
+ const { data: decrypted } = await openpgp.decrypt(decryptionOptions);
95
+
96
+ return decrypted as string;
97
+ }
98
+
99
+ /**
100
+ * Signs a message using the private key.
101
+ *
102
+ * @param {string} message - The message to sign.
103
+ * @returns {Promise<string>} - The signed message.
104
+ */
105
+ public async sign(message: string): Promise<string> {
106
+ const unsignedMessage = await openpgp.createCleartextMessage({
107
+ text: message,
108
+ });
109
+ const cleartextMessage = await openpgp.sign({
110
+ message: unsignedMessage,
111
+ signingKeys: this.privateKey,
112
+ format: 'armored',
113
+ });
114
+
115
+ return cleartextMessage;
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Utility class for encryption-related operations.
121
+ */
122
+ export class EncryptionUtils {
123
+ /**
124
+ * Verifies the signature of a signed message using the public key.
125
+ *
126
+ * @param {string} message - The signed message.
127
+ * @param {string} publicKey - The public key in armored format.
128
+ * @returns {Promise<boolean>} - A boolean indicating if the signature is valid.
129
+ */
130
+ public static async verify(
131
+ message: string,
132
+ publicKey: string
133
+ ): Promise<boolean> {
134
+ const pgpPublicKey = await openpgp.readKey({ armoredKey: publicKey });
135
+ const signedMessage = await openpgp.readCleartextMessage({
136
+ cleartextMessage: message,
137
+ });
138
+
139
+ const verificationResult = await signedMessage.verify([pgpPublicKey]);
140
+ const { verified } = verificationResult[0];
141
+
142
+ try {
143
+ return await verified;
144
+ } catch {
145
+ return false;
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Gets the signed data from a signed message.
151
+ *
152
+ * @param {string} message - The signed message.
153
+ * @returns {Promise<string>} - The signed data.
154
+ * @throws {Error} - An error object if an error occurred.
155
+ */
156
+ public static async getSignedData(message: string): Promise<string> {
157
+ const signedMessage = await openpgp.readCleartextMessage({
158
+ cleartextMessage: message,
159
+ });
160
+
161
+ try {
162
+ return signedMessage.getText();
163
+ } catch (e) {
164
+ throw new Error('Could not get data: ' + e.message);
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Generates a key pair for encryption and decryption.
170
+ *
171
+ * @param {string} name - The name for the key pair.
172
+ * @param {string} email - The email for the key pair.
173
+ * @param {string} passphrase - The passphrase used to encrypt the private key.
174
+ * @returns {Promise<IKeyPair>} - The generated key pair.
175
+ */
176
+ public static async generateKeyPair(
177
+ name: string,
178
+ email: string,
179
+ passphrase = ''
180
+ ): Promise<IKeyPair> {
181
+ const { privateKey, publicKey, revocationCertificate } =
182
+ await openpgp.generateKey({
183
+ type: 'ecc',
184
+ curve: 'ed25519',
185
+ userIDs: [{ name: name, email: email }],
186
+ passphrase: passphrase,
187
+ format: 'armored',
188
+ });
189
+
190
+ return {
191
+ passphrase: passphrase,
192
+ privateKey,
193
+ publicKey,
194
+ revocationCertificate,
195
+ };
196
+ }
197
+
198
+ /**
199
+ * Encrypts a message using the specified public keys.
200
+ *
201
+ * @param {string} message - The message to encrypt.
202
+ * @param {string[]} publicKeys - The public keys in armored format.
203
+ * @returns {Promise<string>} - The encrypted message.
204
+ */
205
+ public static async encrypt(
206
+ message: string,
207
+ publicKeys: string[]
208
+ ): Promise<string> {
209
+ const plaintext = message;
210
+
211
+ const pgpPublicKeys = await Promise.all(
212
+ publicKeys.map((armoredKey) => openpgp.readKey({ armoredKey }))
213
+ );
214
+
215
+ const pgpMessage = await openpgp.createMessage({ text: plaintext });
216
+ const encrypted = await openpgp.encrypt({
217
+ message: pgpMessage,
218
+ encryptionKeys: pgpPublicKeys,
219
+ });
220
+
221
+ return encrypted as string;
222
+ }
223
+ }
package/src/error.ts CHANGED
@@ -141,14 +141,12 @@ export const ErrorHMTokenAmountNotApproved = new Error('Amount not approved');
141
141
  /**
142
142
  * @constant {Error} - Init provider does not exists.
143
143
  */
144
- export const ErrorInitProviderDoesNotExist = new Error(
145
- 'Provider does not exist'
146
- );
144
+ export const ErrorProviderDoesNotExist = new Error('Provider does not exist');
147
145
 
148
146
  /**
149
147
  * @constant {Error} - Init with unsupported chain ID.
150
148
  */
151
- export const ErrorInitUnsupportedChainID = new Error('Unsupported chain ID');
149
+ export const ErrorUnsupportedChainID = new Error('Unsupported chain ID');
152
150
 
153
151
  /**
154
152
  * @constant {Error} - Sending a transaction requires a signer.